using System;
|
using System.Collections.Generic;
|
using System.Text;
|
using ZigBee.Device;
|
|
namespace Shared.Phone.UserCenter
|
{
|
/// <summary>
|
/// 设备功能类型的自定义行控件
|
/// </summary>
|
public class DeviceFunctionTypeRowControl : FrameCaptionViewControl
|
{
|
#region ■ 变量声明___________________________
|
|
/// <summary>
|
/// 判断该控件能否显示(最好确保设备对象不为null)
|
/// </summary>
|
public bool CanShowRow
|
{
|
get { return this.CheckCanShowRow(); }
|
}
|
/// <summary>
|
/// 设备对象
|
/// </summary>
|
private CommonDevice device = null;
|
/// <summary>
|
/// 当前选择的功能类型索引
|
/// </summary>
|
private int nowSelectNo = -1;
|
|
#endregion
|
|
#region ■ 初始化_____________________________
|
|
/// <summary>
|
/// 设备功能类型的自定义行控件(此方法选择之后,无条件直接变更类型)
|
/// </summary>
|
/// <param name="i_device">设备的对象</param>
|
/// <param name="i_ChidrenYaxis">子控件Y轴偏移量(真实值,有些界面需要这种特殊操作)</param>
|
public DeviceFunctionTypeRowControl(CommonDevice i_device, int i_ChidrenYaxis = 0) : base("", "", i_ChidrenYaxis)
|
{
|
this.device = i_device;
|
this.UseClickStatu = false;
|
}
|
|
/// <summary>
|
/// 初始化
|
/// </summary>
|
public override void InitControl()
|
{
|
//初始化初始数据
|
this.InitDefultData();
|
//初始化底层数据
|
base.InitControl();
|
|
if (this.device == null)
|
{
|
//此控件采用的是另外一种初始化方式
|
return;
|
}
|
|
//空气开关和继电器可以选择功能类型
|
if (this.device.Type == DeviceType.AirSwitch
|
|| this.device.Type == DeviceType.OnOffOutput)
|
{
|
this.UseClickStatu = true;
|
//右箭头
|
this.AddRightArrow();
|
|
this.ButtonClickEvent += (sender, e) =>
|
{
|
//显示选择设备功能类型的界面
|
this.ShowSelectDeviceFunctionListForm();
|
};
|
}
|
}
|
|
#endregion
|
|
#region ■ 显示选择设备功能类型_______________
|
|
/// <summary>
|
/// 显示选择设备功能类型的界面
|
/// </summary>
|
private void ShowSelectDeviceFunctionListForm()
|
{
|
//显示列表
|
var listText = new List<string>();
|
listText.Add(Language.StringByID(R.MyInternationalizationString.uSwitch));//开关
|
listText.Add(Language.StringByID(R.MyInternationalizationString.uLight));//灯光
|
listText.Add(Language.StringByID(R.MyInternationalizationString.uSocket1));//插座
|
//标题:选择功能类型
|
var title = Language.StringByID(R.MyInternationalizationString.uSelectFunctionType);
|
|
var form = new BottomItemSelectForm();
|
form.CancelCallEvent = true;//允许取消
|
form.AddForm(title, listText, nowSelectNo);
|
form.FinishSelectEvent += (selectNo) =>
|
{
|
//-1:选择取消
|
this.Text = selectNo == -1 ? string.Empty : listText[selectNo];
|
nowSelectNo = selectNo;
|
|
//记录起当前选择的功能类型
|
this.RefreshDfunctionType();
|
};
|
}
|
#endregion
|
|
#region ■ 初始化初始数据_____________________
|
|
/// <summary>
|
/// 初始化初始数据
|
/// </summary>
|
private void InitDefultData()
|
{
|
//标题:功能类型
|
this.btnCaption.Text = Language.StringByID(R.MyInternationalizationString.uFunctionType);
|
|
var myFunType = DeviceFunctionType.A未定义;
|
if (this.device != null)
|
{
|
myFunType = this.device.DfunctionType;
|
}
|
|
//功能类型的翻译名字
|
string strType = string.Empty;
|
if (myFunType == DeviceFunctionType.A灯光)
|
{
|
strType = Language.StringByID(R.MyInternationalizationString.uLight);
|
nowSelectNo = 1;
|
}
|
else if (this.device.DfunctionType == DeviceFunctionType.A开关)
|
{
|
strType = Language.StringByID(R.MyInternationalizationString.uSwitch);
|
nowSelectNo = 0;
|
}
|
else if (this.device.DfunctionType == DeviceFunctionType.A插座)
|
{
|
strType = Language.StringByID(R.MyInternationalizationString.uSocket1);
|
nowSelectNo = 2;
|
}
|
|
//如果设备不为null
|
if (this.device != null)
|
{
|
if (this.device.Type == DeviceType.ColorDimmableLight
|
|| this.device.Type == DeviceType.DimmableLight)
|
{
|
//灯光类固定为 灯光
|
strType = Language.StringByID(R.MyInternationalizationString.uLight);
|
nowSelectNo = 1;
|
}
|
else if (this.device.Type == DeviceType.WindowCoveringDevice)
|
{
|
//窗帘固定为 遮阳
|
strType = Language.StringByID(R.MyInternationalizationString.uDeviceBelongId100);
|
nowSelectNo = -1;
|
}
|
else if (this.device.Type == DeviceType.Thermostat)
|
{
|
//空调固定为 空调
|
strType = Language.StringByID(R.MyInternationalizationString.uDeviceBelongId3600);
|
nowSelectNo = -1;
|
}
|
else if (this.device.Type == DeviceType.DoorLock)
|
{
|
//门锁固定为 门锁
|
strType = Language.StringByID(R.MyInternationalizationString.uDeviceBelongId2800);
|
nowSelectNo = -1;
|
}
|
}
|
//显示文本
|
this.txtView.Text = strType;
|
}
|
|
#endregion
|
|
#region ■ 检测能否显示_______________________
|
|
/// <summary>
|
/// 检测能否显示
|
/// </summary>
|
/// <returns></returns>
|
private bool CheckCanShowRow()
|
{
|
if (this.device == null) { return true; }
|
|
if (this.device.Type == DeviceType.AirSwitch//空气开关
|
|| this.device.Type == DeviceType.ColorDimmableLight//彩灯
|
|| this.device.Type == DeviceType.DimmableLight//调光灯
|
|| this.device.Type == DeviceType.DoorLock//门锁
|
|| this.device.Type == DeviceType.OnOffOutput//继电器
|
|| this.device.Type == DeviceType.Thermostat//空调
|
|| this.device.Type == DeviceType.WindowCoveringDevice)//窗帘
|
{
|
return true;
|
}
|
return false;
|
}
|
|
#endregion
|
|
#region ■ 一般方法___________________________
|
|
/// <summary>
|
/// 刷新设备功能类型
|
/// </summary>
|
private void RefreshDfunctionType()
|
{
|
if (this.nowSelectNo == 0)
|
{
|
this.device.DfunctionType = DeviceFunctionType.A开关;
|
if (this.device.IsCustomizeImage == false)
|
{
|
//重新设置图片
|
this.device.IconPath = "Device/Switch.png";
|
}
|
}
|
else if (this.nowSelectNo == 1)
|
{
|
this.device.DfunctionType = DeviceFunctionType.A灯光;
|
if (this.device.IsCustomizeImage == false)
|
{
|
//重新设置图片
|
this.device.IconPath = "Device/Light.png";
|
}
|
}
|
else if (this.nowSelectNo == 2)
|
{
|
this.device.DfunctionType = DeviceFunctionType.A插座;
|
if (this.device.IsCustomizeImage == false)
|
{
|
//重新设置图片
|
this.device.IconPath = "Device/Socket1.png";
|
}
|
}
|
else
|
{
|
this.device.DfunctionType = DeviceFunctionType.A未定义;
|
if (this.device.IsCustomizeImage == false)
|
{
|
//重新设置图片
|
if (this.device.Type == DeviceType.AirSwitch)
|
{
|
//空气开关
|
this.device.IconPath = "Device/Switch.png";
|
}
|
else if (this.device.Type == DeviceType.OnOffOutput)
|
{
|
//继电器
|
this.device.IconPath = "Device/RelayEpoint.png";
|
}
|
}
|
}
|
this.device.ReSave();
|
}
|
|
#endregion
|
}
|
}
|