using System;
|
using System.Collections.Generic;
|
using System.Text;
|
using ZigBee.Device;
|
|
namespace Shared.Phone.UserCenter.DeviceAirConditioner
|
{
|
/// <summary>
|
/// 空调的室内机列表界面
|
/// </summary>
|
public class IndoorUnitListForm : EditorCommonForm
|
{
|
#region ■ 变量声明___________________________
|
|
/// <summary>
|
/// 设备列表
|
/// </summary>
|
private List<CommonDevice> listDevice = null;
|
/// <summary>
|
/// 控件信息
|
/// </summary>
|
private Dictionary<string, RowControlInfo> dicControl = new Dictionary<string, RowControlInfo>();
|
/// <summary>
|
/// 激活的设备地址
|
/// </summary>
|
private string actionDeviceKeys = null;
|
/// <summary>
|
/// 接收回复的端点
|
/// </summary>
|
private HashSet<int> listReceivePoint = new HashSet<int>();
|
|
#endregion
|
|
#region ■ 初始化_____________________________
|
|
/// <summary>
|
/// 画面显示(底层会固定调用此方法,借以完成画面创建)
|
/// </summary>
|
/// <param name="i_diviceMac">设备Mac地址</param>
|
public void ShowForm(string i_diviceMac)
|
{
|
this.listDevice = HdlDeviceCommonLogic.Current.GetDevicesByMac(i_diviceMac);
|
//收集全部端点
|
foreach (var device in this.listDevice)
|
{
|
listReceivePoint.Add(device.DeviceEpoint);
|
}
|
//设置头部信息
|
base.SetTitleText(Language.StringByID(R.MyInternationalizationString.uIndoorUnitSettion));
|
|
//初始化中部信息
|
this.InitMiddleFrame();
|
}
|
|
/// <summary>
|
/// 初始化中部信息
|
/// </summary>
|
private void InitMiddleFrame()
|
{
|
//清空bodyFrame
|
this.ClearBodyFrame();
|
|
var listView = new VerticalFrameControl(14);
|
listView.Height = bodyFrameLayout.Height;
|
bodyFrameLayout.AddChidren(listView);
|
|
var frameTemp = new FrameLayout();
|
frameTemp.Height = Application.GetRealHeight(69);
|
listView.AddChidren(frameTemp);
|
|
HdlThreadLogic.Current.RunMainInThread(() =>
|
{
|
for (int i = 0; i < listDevice.Count; i++)
|
{
|
//添加空调行
|
this.AddAcControlRow(listView, (AC)listDevice[i]);
|
}
|
var frameTemp2 = new FrameLayout();
|
frameTemp2.Height = Application.GetRealHeight(29);
|
listView.AddChidren(frameTemp2);
|
|
//数据接收
|
this.StartReceiveDataEvent();
|
//发送读取属性的命令
|
this.SetReadAttributeComand();
|
});
|
}
|
|
/// <summary>
|
/// 添加空调行
|
/// </summary>
|
/// <param name="listView"></param>
|
/// <param name="device"></param>
|
private void AddAcControlRow(VerticalFrameControl listView, AC device)
|
{
|
var rowInfo = new RowControlInfo();
|
|
var frameTable = new FrameLayoutStatuControl();
|
frameTable.UseClickStatu = false;
|
frameTable.Width = Application.GetRealWidth(994);
|
frameTable.Height = Application.GetRealHeight(337);
|
frameTable.BackgroundImagePath = "Item/IndoorUnitGround.png";
|
frameTable.Gravity = Gravity.CenterHorizontal;
|
listView.AddChidren(frameTable);
|
|
//设备图标
|
var btnIconBack = new FrameLayout();
|
btnIconBack.X = Application.GetRealWidth(46);
|
btnIconBack.Y = Application.GetRealHeight(43);
|
btnIconBack.Height = this.GetPictrueRealSize(112);
|
btnIconBack.Width = this.GetPictrueRealSize(112);
|
btnIconBack.Radius = (uint)this.GetPictrueRealSize(112) / 2;
|
btnIconBack.BackgroundColor = 0xfff5f6fa;
|
frameTable.AddChidren(btnIconBack, ChidrenBindMode.NotBind);
|
rowInfo.btnIconBack = btnIconBack;
|
|
var btnIcon = new IconViewControl(78);
|
btnIcon.Gravity = Gravity.Center;
|
HdlDeviceCommonLogic.Current.SetDeviceIconToControl(btnIcon, device);
|
btnIconBack.AddChidren(btnIcon);
|
frameTable.ChangedChidrenBindMode(btnIconBack, ChidrenBindMode.BindEvent);
|
rowInfo.btnIcon = btnIcon;
|
|
//设备名称
|
var btnDeviceName = new NormalViewControl(700, 60, true);
|
btnDeviceName.Text = HdlDeviceCommonLogic.Current.GetDeviceEpointName(device);
|
btnDeviceName.X = Application.GetRealWidth(193);
|
btnDeviceName.Y = Application.GetRealHeight(45);
|
frameTable.AddChidren(btnDeviceName, ChidrenBindMode.BindEvent);
|
rowInfo.btnDeviceName = btnDeviceName;
|
//房间
|
var btnRoom = new NormalViewControl(400, 50, true);
|
btnRoom.X = btnDeviceName.X;
|
btnRoom.Y = btnDeviceName.Bottom + Application.GetRealHeight(12);
|
btnRoom.TextSize = 12;
|
btnRoom.TextColor = UserCenterColor.Current.TextGrayColor1;
|
btnRoom.Text = HdlRoomLogic.Current.GetRoomNameByDevice(device);
|
frameTable.AddChidren(btnRoom, ChidrenBindMode.BindEvent);
|
rowInfo.btnRoom = btnRoom;
|
//摄氏度
|
var btnValue = new NormalViewControl(300, 60, true);
|
btnValue.Y = Application.GetRealHeight(58);
|
btnValue.X = frameTable.Width - Application.GetRealWidth(300 + 58);
|
btnValue.TextAlignment = TextAlignment.CenterRight;
|
frameTable.AddChidren(btnValue, ChidrenBindMode.BindEvent);
|
rowInfo.btnValue = btnValue;
|
//室内温度
|
if (device.currentLocalTemperature == 0)
|
{
|
//0℃
|
btnValue.Text = "0.0℃";
|
}
|
else
|
{
|
btnValue.Text = device.currentLocalTemperature + ".0℃";
|
}
|
|
//警告图标
|
var btnWarningIcon = new IconViewControl(69);
|
btnWarningIcon.X = btnIconBack.X;
|
btnWarningIcon.Y = btnRoom.Bottom + Application.GetRealHeight(43);
|
btnWarningIcon.UnSelectedImagePath = "Item/WarningIcon1.png";
|
frameTable.AddChidren(btnWarningIcon, ChidrenBindMode.NotBind);
|
btnWarningIcon.Visible = false;
|
rowInfo.btnWarningIcon = btnWarningIcon;
|
//警告信息
|
var btnWarningMsg = new NormalViewControl(500, 50, true);
|
btnWarningMsg.X = btnWarningIcon.Right + Application.GetRealWidth(12);
|
btnWarningMsg.Y = btnRoom.Bottom + Application.GetRealHeight(55);
|
btnWarningMsg.TextSize = 12;
|
btnWarningMsg.TextColor = UserCenterColor.Current.TextGrayColor1;
|
frameTable.AddChidren(btnWarningMsg, ChidrenBindMode.NotBind);
|
rowInfo.btnWarningMsg = btnWarningMsg;
|
//开关
|
var btnSwitch = new IconViewControl(69);
|
btnSwitch.X = frameTable.Width - Application.GetRealWidth(69 + 46);
|
btnSwitch.Y = btnRoom.Bottom + Application.GetRealHeight(43);
|
btnSwitch.UnSelectedImagePath = "Item/Switch.png";
|
btnSwitch.SelectedImagePath = "Item/SwitchSelected.png";
|
frameTable.AddChidren(btnSwitch, ChidrenBindMode.NotBind);
|
rowInfo.btnSwitch = btnSwitch;
|
btnSwitch.ButtonClickEvent += async (sender, e) =>
|
{
|
if (btnSwitch.IsSelected == false)
|
{
|
//如果不是虚拟住宅的话
|
if (Common.Config.Instance.Home.IsVirtually == false)
|
{
|
//打开空调
|
var result = await HdlDeviceAirConditionerLogic.Current.OpenAirConditioner(device);
|
if (result == false)
|
{
|
return;
|
}
|
}
|
btnIcon.IsSelected = true;
|
btnIconBack.BackgroundColor = 0xfffef1ed;
|
}
|
else
|
{
|
//如果不是虚拟住宅的话
|
if (Common.Config.Instance.Home.IsVirtually == false)
|
{
|
//关闭空调
|
var result = await HdlDeviceAirConditionerLogic.Current.CloseAirConditioner(device);
|
if (result == false)
|
{
|
return;
|
}
|
}
|
btnIcon.IsSelected = false;
|
btnIconBack.BackgroundColor = 0xfff5f6fa;
|
}
|
btnSwitch.IsSelected = !btnSwitch.IsSelected;
|
//如果是虚拟住宅的话
|
if (Common.Config.Instance.Home.IsVirtually == true)
|
{
|
device.currentSystemMode = btnSwitch.IsSelected == true ? 3 : 0;
|
}
|
};
|
//如果是展示模板的话
|
if (Common.Config.Instance.Home.IsShowTemplate == true)
|
{
|
btnSwitch.CanClick = false;
|
}
|
|
frameTable.ButtonClickEvent += (sender, e) =>
|
{
|
this.actionDeviceKeys = HdlDeviceCommonLogic.Current.GetDeviceMainKeys(device);
|
|
var form = new IndoorUnitSettionForm();
|
form.AddForm(device);
|
};
|
|
dicControl[HdlDeviceCommonLogic.Current.GetDeviceMainKeys(device)] = rowInfo;
|
}
|
|
#endregion
|
|
#region ■ 发送命令___________________________
|
|
/// <summary>
|
/// 发送读取属性的命令
|
/// </summary>
|
private void SetReadAttributeComand()
|
{
|
//如果是虚拟住宅或者展示模板的话
|
if (Common.Config.Instance.Home.IsShowTemplate == true || Common.Config.Instance.Home.IsVirtually == true)
|
{
|
return;
|
}
|
HdlThreadLogic.Current.RunThread(() =>
|
{
|
while (this.listReceivePoint.Count > 0 && this.Parent != null)
|
{
|
for (int i = 0; i < listDevice.Count; i++)
|
{
|
if (this.Parent == null)
|
{
|
return;
|
}
|
//已经发送过了,就不用再发送
|
if (this.listReceivePoint.Contains(listDevice[i].DeviceEpoint) == true)
|
{
|
//读取状态
|
HdlDeviceAttributeLogic.Current.SendThermostatStatuComand(listDevice[i]);
|
System.Threading.Thread.Sleep(200);
|
}
|
}
|
//3秒后再次循环
|
System.Threading.Thread.Sleep(3000);
|
}
|
});
|
}
|
|
#endregion
|
|
#region ■ 数据接收___________________________
|
|
/// <summary>
|
/// 数据接收
|
/// </summary>
|
private void StartReceiveDataEvent()
|
{
|
HdlGatewayReceiveLogic.Current.AddAttributeEvent("IndoorUnitListFormEvent", ReceiveComandDiv.A设备属性上报, (device) =>
|
{
|
string mainkeys = HdlDeviceCommonLogic.Current.GetDeviceMainKeys(device);
|
if (dicControl.ContainsKey(mainkeys) == false || device.DeviceStatusReport.CluterID != 513)
|
{
|
return;
|
}
|
var localDevice = HdlDeviceCommonLogic.Current.GetDevice(mainkeys);
|
if (localDevice == null)
|
{
|
return;
|
}
|
//已经接收到数据,则移除端点
|
this.listReceivePoint.Remove(device.DeviceEpoint);
|
|
var rowInfo = dicControl[mainkeys];
|
for (int i = 0; i < device.DeviceStatusReport.AttriBute.Count; i++)
|
{
|
var data = device.DeviceStatusReport.AttriBute[i];
|
if (data.AttributeId == 0)
|
{
|
HdlThreadLogic.Current.RunMain(() =>
|
{
|
//室内温度
|
if (((AC)localDevice).currentLocalTemperature == 0)
|
{
|
//0℃
|
rowInfo.btnValue.Text = "0.0℃";
|
}
|
else
|
{
|
rowInfo.btnValue.Text = ((AC)localDevice).currentLocalTemperature + ".0℃";
|
}
|
});
|
}
|
else if (data.AttributeId == 28)
|
{
|
//此属性描述恒温设备正处于哪种模式
|
//Off = 0 Auto = 1 Cool = 3 Heat = 4 FanOnly = 7 Dry = 8
|
if (data.AttriButeData != 0)
|
{
|
HdlThreadLogic.Current.RunMain(() =>
|
{
|
rowInfo.btnSwitch.IsSelected = true;
|
rowInfo.btnIcon.IsSelected = true;
|
rowInfo.btnIconBack.BackgroundColor = 0xfffef1ed;
|
});
|
}
|
}
|
else if (data.AttributeId == 4097)
|
{
|
//42:需要清洗滤网
|
if (data.AttriButeData == 42)
|
{
|
HdlThreadLogic.Current.RunMain(() =>
|
{
|
rowInfo.btnWarningIcon.Visible = true;
|
//请注意清洗滤网哦
|
rowInfo.btnWarningMsg.TextID = R.MyInternationalizationString.uPleaseClreanACfilter;
|
});
|
}
|
}
|
}
|
});
|
}
|
|
#endregion
|
|
#region ■ 界面关闭___________________________
|
|
/// <summary>
|
/// 界面关闭
|
/// </summary>
|
public override void CloseFormBefore()
|
{
|
HdlGatewayReceiveLogic.Current.RemoveEvent("IndoorUnitListFormEvent");
|
|
base.CloseFormBefore();
|
}
|
|
#endregion
|
|
#region ■ 界面重新激活事件___________________
|
|
/// <summary>
|
/// 自身的上层界面关闭后,它自身处于最上层时,触发的事件
|
/// </summary>
|
public override int FormActionAgainEvent()
|
{
|
if (this.actionDeviceKeys != null && dicControl.ContainsKey(this.actionDeviceKeys) == true)
|
{
|
//刷新设备信息
|
var device = HdlDeviceCommonLogic.Current.GetDevice(this.actionDeviceKeys);
|
if (device != null)
|
{
|
var contr = dicControl[this.actionDeviceKeys];
|
contr.btnDeviceName.Text = HdlDeviceCommonLogic.Current.GetDeviceEpointName(device);
|
contr.btnRoom.Text = HdlRoomLogic.Current.GetRoomNameByDevice(device);
|
}
|
}
|
this.actionDeviceKeys = null;
|
|
return 1;
|
}
|
|
#endregion
|
|
#region ■ 结构体_____________________________
|
|
/// <summary>
|
/// 行数据
|
/// </summary>
|
private class RowControlInfo
|
{
|
/// <summary>
|
/// 设备名字
|
/// </summary>
|
public NormalViewControl btnDeviceName = null;
|
/// <summary>
|
/// 设备房间
|
/// </summary>
|
public NormalViewControl btnRoom = null;
|
/// <summary>
|
/// 设备图标背景
|
/// </summary>
|
public FrameLayout btnIconBack = null;
|
/// <summary>
|
/// 设备图标
|
/// </summary>
|
public IconViewControl btnIcon = null;
|
/// <summary>
|
/// 摄氏度
|
/// </summary>
|
public NormalViewControl btnValue = null;
|
/// <summary>
|
/// 警告图标
|
/// </summary>
|
public IconViewControl btnWarningIcon = null;
|
/// <summary>
|
/// 警告信息
|
/// </summary>
|
public NormalViewControl btnWarningMsg = null;
|
/// <summary>
|
/// 开关
|
/// </summary>
|
public IconViewControl btnSwitch = null;
|
}
|
|
#endregion
|
}
|
}
|