黄学彪
2019-11-07 82a773d1783549caca563831aac8affc059deedf
ZigbeeApp/Shared/Phone/UserCenter/Device/AirConditioner/AirConditionerModeForm.cs
@@ -16,6 +16,18 @@
        /// 当前选择的网关
        /// </summary>
        private AC deviceAc = null;
        /// <summary>
        /// 上报的数据(用二进制来玩自定义模式 0:制冷 1:制热 2:送风 3:除湿 4:自动 5~7:备用)
        /// </summary>
        private string reportValue = null;
        /// <summary>
        /// 旧的数据
        /// </summary>
        private string oldReportValue = null;
        /// <summary>
        /// 固定预留的数据
        /// </summary>
        private string fixValue = null;
        #endregion
@@ -31,6 +43,9 @@
            //设置头部信息
            base.SetTitleText(Language.StringByID(R.MyInternationalizationString.uAirConditionerMode));
            //读取空调自定义模式
            this.ReadAirConditionerModeSupport();
            //初始化中部信息
            this.InitMiddleFrame();
@@ -50,27 +65,71 @@
            listView.Height = bodyFrameLayout.Height + Application.GetRealHeight(6);
            bodyFrameLayout.AddChidren(listView);
            //制冷
            this.AddAirConditionerModeRow(listView, "AC/Mode_Cool2.png", Language.StringByID(R.MyInternationalizationString.uMode_Cool), 1);
            //制热
            this.AddAirConditionerModeRow(listView, "AC/Mode_Heat2.png", Language.StringByID(R.MyInternationalizationString.uMode_Heat), 2);
            //自动
            this.AddAirConditionerModeRow(listView, "AC/Mode_AutoSelected.png", Language.StringByID(R.MyInternationalizationString.uMode_Auto), 3);
            //送风
            this.AddAirConditionerModeRow(listView, "AC/Mode_Fan2.png", Language.StringByID(R.MyInternationalizationString.uMode_FanOnly), 4);
            //除湿
            this.AddAirConditionerModeRow(listView, "AC/Mode_Dry2.png", Language.StringByID(R.MyInternationalizationString.uMode_Dry), 5);
            listView.AdjustRealHeight(Application.GetRealHeight(23));
            //保存
            var btnOk = new BottomClickButton();
            btnOk.TextID = R.MyInternationalizationString.uSave;
            bodyFrameLayout.AddChidren(btnOk);
            btnOk.ButtonClickEvent += (sender, e) =>
            HdlThreadLogic.Current.RunThread(() =>
            {
                this.CloseForm();
            };
                //开启进度条
                this.ShowProgressBar();
                int timeOut = 0;
                while (this.reportValue == null && timeOut <= 30)
                {
                    System.Threading.Thread.Sleep(100);
                    timeOut++;
                }
                if (this.reportValue == null)
                {
                    //获取空调模式失败
                    string msg = Language.StringByID(R.MyInternationalizationString.uGetAcModeFail);
                    msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, null, "回复超时");
                    this.ShowMassage(ShowMsgType.Tip, msg);
                    this.CloseProgressBar(ShowReLoadMode.YES);
                    return;
                }
                //关闭进度条
                this.CloseProgressBar();
                HdlThreadLogic.Current.RunMain(() =>
                {
                    //制冷
                    this.AddAirConditionerModeRow(listView, "AC/Mode_Cool2.png", Language.StringByID(R.MyInternationalizationString.uMode_Cool), 0);
                    //制热
                    this.AddAirConditionerModeRow(listView, "AC/Mode_Heat2.png", Language.StringByID(R.MyInternationalizationString.uMode_Heat), 1);
                    //自动
                    this.AddAirConditionerModeRow(listView, "AC/Mode_AutoSelected.png", Language.StringByID(R.MyInternationalizationString.uMode_Auto), 4);
                    //送风
                    this.AddAirConditionerModeRow(listView, "AC/Mode_Fan2.png", Language.StringByID(R.MyInternationalizationString.uMode_FanOnly), 2);
                    //除湿
                    this.AddAirConditionerModeRow(listView, "AC/Mode_Dry2.png", Language.StringByID(R.MyInternationalizationString.uMode_Dry), 3);
                    listView.AdjustRealHeight(Application.GetRealHeight(23));
                    //保存
                    var btnOk = new BottomClickButton();
                    btnOk.TextID = R.MyInternationalizationString.uSave;
                    bodyFrameLayout.AddChidren(btnOk);
                    btnOk.ButtonClickEvent += async (sender, e) =>
                     {
                         if (this.oldReportValue == this.reportValue)
                         {
                            //数据相同,不需要修改
                            this.CloseForm();
                             return;
                         }
                         //将二进制转换为十进制
                         var data = Convert.ToInt32(this.fixValue + this.reportValue, 2);
                         var result = await HdlDeviceAirConditionerLogic.Current.SetAcModeSupport(deviceAc, data);
                         if (result == true)
                         {
                             //更改缓存
                             for (int i = 0; i < this.reportValue.Length; i++)
                             {
                                 deviceAc.listSupportMode[i] = Convert.ToInt32(reportValue[i]);
                             }
                             deviceAc.ReSave();
                             this.CloseForm();
                         }
                     };
                });
            });
        }
        /// <summary>
@@ -90,21 +149,83 @@
            //显示文本
            var btnText = rowFrame.AddLeftCaption(textValue, 400);
            btnText.TextSize = 15;
            if (div != 5)
            if (div != 3)
            {
                //底线
                rowFrame.AddBottomLine();
            }
            //选择
            var btnSelect = rowFrame.AddMostRightEmptyIcon(58, 58);
            btnSelect.Visible = false;
            if (this.reportValue[div] == '0')
            {
                btnSelect.Visible = false;
            }
            btnSelect.UnSelectedImagePath = "Item/ItemSelected.png";
            rowFrame.ButtonClickEvent += (sender, e) =>
            {
                btnSelect.Visible = !btnSelect.Visible;
                //变更值
                if (btnSelect.Visible == true)
                {
                    this.reportValue = reportValue.Substring(0, div) + "1" + reportValue.Substring(div + 1);
                }
                else
                {
                    this.reportValue = reportValue.Substring(0, div) + "0" + reportValue.Substring(div + 1);
                }
            };
        }
        #endregion
        #region ■ 读取空调自定义模式_________________
        /// <summary>
        /// 读取空调自定义模式
        /// </summary>
        private void ReadAirConditionerModeSupport()
        {
            string mainkeys = Common.LocalDevice.Current.GetDeviceMainKeys(deviceAc);
            HdlDeviceAttributeLogic.Current.AddAttributeEvent("ReadAirConditionerModeSupport", "DeviceStatusReport", (report) =>
            {
                string checkKeys = Common.LocalDevice.Current.GetDeviceMainKeys(report);
                if (checkKeys != mainkeys || report.DeviceStatusReport.CluterID != 513)
                {
                    return;
                }
                for (int i = 0; i < report.DeviceStatusReport.AttriBute.Count; i++)
                {
                    var data = report.DeviceStatusReport.AttriBute[i];
                    if (data.AttributeId == 4099)
                    {
                        HdlDeviceAttributeLogic.Current.RemoveEvent("ReadAirConditionerModeSupport");
                        //转换为二进制
                        var value = Convert.ToString(data.AttriButeData, 2).PadLeft(16, '0');
                        //这五个设置是放在后面的
                        this.fixValue = value.Substring(0, value.Length - 5);
                        this.reportValue = value.Substring(this.fixValue.Length);
                        oldReportValue = reportValue;
                    }
                }
            });
            //发送读取空调自定义模式
            deviceAc.ReadModeSupport();
        }
        #endregion
        #region ■ 界面关闭___________________________
        /// <summary>
        /// 界面关闭
        /// </summary>
        public override void CloseForm()
        {
            HdlDeviceAttributeLogic.Current.RemoveEvent("ReadAirConditionerModeSupport");
            base.CloseForm();
        }
        #endregion
    }
}