using System; using System.Collections.Generic; using System.Text; using ZigBee.Device; namespace Shared.Phone.UserCenter.DeviceAirConditioner { /// /// 空调的室内机列表界面 /// public class IndoorUnitListForm : EditorCommonForm { #region ■ 变量声明___________________________ /// /// 设备列表 /// private List listDevice = null; /// /// 控件信息 /// private Dictionary dicControl = new Dictionary(); /// /// 激活的设备地址 /// private string actionDeviceKeys = null; /// /// 接收回复的端点 /// private HashSet listReceivePoint = new HashSet(); #endregion #region ■ 初始化_____________________________ /// /// 画面显示(底层会固定调用此方法,借以完成画面创建) /// /// 设备Mac地址 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(); } /// /// 初始化中部信息 /// 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(); }); } /// /// 添加空调行 /// /// /// 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 ■ 发送命令___________________________ /// /// 发送读取属性的命令 /// 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 ■ 数据接收___________________________ /// /// 数据接收 /// 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 ■ 界面关闭___________________________ /// /// 界面关闭 /// public override void CloseFormBefore() { HdlGatewayReceiveLogic.Current.RemoveEvent("IndoorUnitListFormEvent"); base.CloseFormBefore(); } #endregion #region ■ 界面重新激活事件___________________ /// /// 自身的上层界面关闭后,它自身处于最上层时,触发的事件 /// 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 ■ 结构体_____________________________ /// /// 行数据 /// private class RowControlInfo { /// /// 设备名字 /// public NormalViewControl btnDeviceName = null; /// /// 设备房间 /// public NormalViewControl btnRoom = null; /// /// 设备图标背景 /// public FrameLayout btnIconBack = null; /// /// 设备图标 /// public IconViewControl btnIcon = null; /// /// 摄氏度 /// public NormalViewControl btnValue = null; /// /// 警告图标 /// public IconViewControl btnWarningIcon = null; /// /// 警告信息 /// public NormalViewControl btnWarningMsg = null; /// /// 开关 /// public IconViewControl btnSwitch = null; } #endregion } }