陈嘉乐
2020-07-10 48ba446936b51fffafa7c3600c0dadc6ac0e8c20
ZigbeeApp/Shared/Phone/UserCenter/Device/AirConditioner/IndoorUnitSettionForm.cs
@@ -15,11 +15,19 @@
        /// <summary>
        /// 列表控件
        /// </summary>
        private VerticalListControl listview = null;
        private FrameListControl listview = null;
        /// <summary>
        /// 当前选择的网关
        /// </summary>
        private AC deviceAc = null;
        /// <summary>
        /// 摆风模式(用二进制来玩自定义模式 0:不使用 1:使用)
        /// </summary>
        private int swingMode = 0;
        /// <summary>
        /// 固定预留的数据
        /// </summary>
        private string fixValue = null;
        #endregion
@@ -39,8 +47,27 @@
            //初始化右上角菜单
            this.InitTopRightMenu();
            //初始化中部控件
            this.InitMiddleFrame();
            HdlThreadLogic.Current.RunThread(() =>
            {
                //开启进度条
                this.ShowProgressBar();
                //读取空调摆风模式
                var result = this.ReadAirConditionerSwingModeSupport();
                if (result == false)
                {
                    //关闭进度条
                    this.CloseProgressBar(ShowReLoadMode.YES);
                    return;
                }
                //关闭进度条
                this.CloseProgressBar();
                HdlThreadLogic.Current.RunMain(() =>
                {
                    //初始化中部控件
                    this.InitMiddleFrame();
                });
            });
        }
        /// <summary>
@@ -51,15 +78,19 @@
            //清空bodyFrame
            this.ClearBodyFrame();
            var listBackControl = new VerticalFrameControl();
            listBackControl.Height = bodyFrameLayout.Height;
            bodyFrameLayout.AddChidren(listBackControl);
            //初始化桌布
            var tableContr = new InformationEditorControl();
            this.listview = tableContr.InitControl(bodyFrameLayout, Language.StringByID(R.MyInternationalizationString.uInfoEditor), 369, 1368);
            this.listview = tableContr.InitControl(listBackControl.frameTable, Language.StringByID(R.MyInternationalizationString.uInfoEditor), 1368);
            //图片
            var btnPic = new DeviceInfoIconControl();
            btnPic.Y = Application.GetRealHeight(92);
            btnPic.Gravity = Gravity.CenterHorizontal;
            bodyFrameLayout.AddChidren(btnPic);
            listBackControl.frameTable.AddChidren(btnPic);
            btnPic.InitControl(this.deviceAc);
            //设备备注
@@ -70,7 +101,7 @@
            btnNote.InitControl();
            //划线
            btnNote.AddBottomLine();
            btnNote.txtInput.FinishInputEvent += async () =>
            btnNote.txtInput.FinishInputEvent += () =>
             {
                 string oldName = Common.LocalDevice.Current.GetDeviceEpointName(deviceAc);
                 if (btnNote.Text.Trim() == string.Empty)
@@ -81,7 +112,7 @@
                 if (oldName != btnNote.Text)
                 {
                     //设备名称修改
                     var result = await Common.LocalDevice.Current.ReName(deviceAc, btnNote.Text);
                     var result = Common.LocalDevice.Current.ReName(deviceAc, btnNote.Text);
                     if (result == false)
                     {
                         return;
@@ -110,11 +141,7 @@
            rowBeloneArea.AddBottomLine();
            rowBeloneArea.SelectRoomEvent += (roomKeys) =>
            {
                //保存这个设备属于哪个区域
                deviceAc.DeviceRoomId = roomKeys;
                deviceAc.ReSave();
                Common.Room.CurrentRoom.ChangedRoom(deviceAc, roomKeys);
                HdlRoomLogic.Current.ChangedRoom(deviceAc, roomKeys);
            };
            //空调模式
@@ -133,29 +160,54 @@
            var rowSwing = new FrameRowControl(listview.rowSpace / 2);
            rowSwing.UseClickStatu = false;
            listview.AddChidren(rowSwing);
            rowSwing.AddLeftCaption(Language.StringByID(R.MyInternationalizationString.uAirConditionerSwing), 600);
            rowSwing.AddLeftCaption(Language.StringByID(R.MyInternationalizationString.uAirConditionerSwing), 400);
            rowSwing.AddBottomLine();
            var btnSwicth = rowSwing.AddMostRightSwitchIcon();
            btnSwicth.ButtonClickEvent += (sender, e) =>
            var btnSwingSwitch = rowSwing.AddMostRightSwitchIcon();
            if (this.swingMode == 1)
            {
                btnSwicth.IsSelected = !btnSwicth.IsSelected;
                btnSwingSwitch.IsSelected = true;
            }
            btnSwingSwitch.ButtonClickEvent += (sender, e) =>
            {
                //不能再点击
                btnSwingSwitch.CanClick = false;
                string statu = btnSwingSwitch.IsSelected == true ? "0" : "1";
                //将二进制转换为十进制
                int sendData = Convert.ToInt32(this.fixValue + statu, 2);
                HdlThreadLogic.Current.RunThread(() =>
                {
                    var result = HdlDeviceAirConditionerLogic.Current.SetUseAcSwingFunctionStatu(deviceAc, sendData);
                    if (result == true)
                    {
                        HdlThreadLogic.Current.RunMain(() =>
                        {
                            btnSwingSwitch.IsSelected = !btnSwingSwitch.IsSelected;
                            this.swingMode = this.swingMode == 1 ? 0 : 1;
                            deviceAc.UseSwingFunction = btnSwingSwitch.IsSelected;
                            deviceAc.ReSave();
                        });
                    }
                    //能够继续点击
                    btnSwingSwitch.CanClick = true;
                });
            };
            //初始化桌布完成
            tableContr.FinishInitControl(bodyFrameLayout, this.listview);
            tableContr.FinishInitControl();
            tableContr = null;
            //保存
            var btnFinish = new BottomClickButton();
            btnFinish.TextID = R.MyInternationalizationString.uSave;
            bodyFrameLayout.AddChidren(btnFinish);
            btnFinish.ButtonClickEvent += async (sender, e) =>
            btnFinish.ButtonClickEvent += (sender, e) =>
            {
                string oldName = Common.LocalDevice.Current.GetDeviceEpointName(deviceAc);
                if (oldName != btnNote.Text)
                {
                    //设备名称修改
                    var result = await Common.LocalDevice.Current.ReName(deviceAc, btnNote.Text);
                    var result = Common.LocalDevice.Current.ReName(deviceAc, btnNote.Text);
                    if (result == false)
                    {
                        return;
@@ -196,7 +248,7 @@
        /// </summary>
        private void ShowTopRightMenu()
        {
            var frame = new TopRightMenuControl(1);
            var frame = new TopRightMenuControl(1, 1);
            //定位
            var deviceMenu = Language.StringByID(R.MyInternationalizationString.uFixedPosition);
            frame.AddRowMenu(deviceMenu, "Item/FixedPosition.png", "Item/FixedPositionSelected.png", () =>
@@ -207,5 +259,68 @@
        }
        #endregion
        #region ■ 读取空调摆风模式___________________
        /// <summary>
        /// 读取空调摆风模式
        /// </summary>
        private bool ReadAirConditionerSwingModeSupport()
        {
            //如果是虚拟住宅
            if (Common.Config.Instance.Home.IsVirtually == true)
            {
                var data = ModelData.DeviceModelDataLogic.Current.GetAcSwingModeSupport(deviceAc);
                //转换为二进制
                var value = Convert.ToString(data, 2).PadLeft(16, '0');
                //这个设置是放在后面的
                this.fixValue = value.Substring(0, value.Length - 1);
                this.swingMode = Convert.ToInt32(value.Substring(this.fixValue.Length));
                return true;
            }
            string mainkeys = Common.LocalDevice.Current.GetDeviceMainKeys(deviceAc);
            HdlGatewayReceiveLogic.Current.AddAttributeEvent("ReadAirConditionerModeSupport", ReceiveComandDiv.A设备属性上报, (report) =>
            {
                string checkKeys = Common.LocalDevice.Current.GetDeviceMainKeys(report);
                if (checkKeys != mainkeys || report.DeviceStatusReport.CluterID != 514)
                {
                    return;
                }
                for (int i = 0; i < report.DeviceStatusReport.AttriBute.Count; i++)
                {
                    var data = report.DeviceStatusReport.AttriBute[i];
                    if (data.AttributeId == 4097)
                    {
                        HdlGatewayReceiveLogic.Current.RemoveEvent("ReadAirConditionerModeSupport");
                        //转换为二进制
                        var value = Convert.ToString(data.AttriButeData, 2).PadLeft(16, '0');
                        //这个设置是放在后面的
                        this.fixValue = value.Substring(0, value.Length - 1);
                        this.swingMode = Convert.ToInt32(value.Substring(this.fixValue.Length));
                    }
                }
            });
            //获取是否启用空调摆风模式的状态(打开 或者 关闭)
            deviceAc.ReadUseSwingFunctionStatu();
            int timeOut = 0;
            while (this.fixValue == null && timeOut <= 30)
            {
                System.Threading.Thread.Sleep(100);
                timeOut++;
            }
            if (this.fixValue == null)
            {
                //获取空调摆风状态失败
                string msg = Language.StringByID(R.MyInternationalizationString.uGetAirConditionerSwingFunctionFail);
                msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, null, "回复超时");
                this.ShowMassage(ShowMsgType.Tip, msg);
                return false;
            }
            return true;
        }
        #endregion
    }
}