陈嘉乐
2020-07-10 48ba446936b51fffafa7c3600c0dadc6ac0e8c20
ZigbeeApp/Shared/Phone/UserCenter/Device/Curtain/AutoOpenDirectionAndLimitSettionForm.cs
@@ -23,13 +23,17 @@
        /// </summary>
        private CurtainData curtainData = null;
        /// <summary>
        /// 允许接收上限位(0:不允许 1:允许)
        /// 接收开限位 false:没有接收到 true:已经接收到
        /// </summary>
        private string receiveUplimit = "0";
        private bool receiveOpenlimit = false;
        /// <summary>
        /// 允许接收下限位(0:不允许 1:允许)
        /// 接收合限位 false:没有接收到 true:已经接收到
        /// </summary>
        private string receiveDownLimit = "0";
        private bool receiveCloseLimit = false;
        /// <summary>
        /// 发送区分 1:开限位 2:合限位
        /// </summary>
        private int sendDiv = 0;
        /// <summary>
        /// 是否备份窗帘数据
        /// </summary>
@@ -41,11 +45,11 @@
        /// <summary>
        /// 开限位的进度条
        /// </summary>
        private HorizontalSeekBar openSeekBar = null;
        private SeekBarControl openSeekBar = null;
        /// <summary>
        /// 合限位的进度条
        /// </summary>
        private HorizontalSeekBar closeSeekBar = null;
        private SeekBarControl closeSeekBar = null;
        #endregion
@@ -57,7 +61,7 @@
        /// <param name="i_listdevice">窗帘的回路</param>
        public void ShowForm(Rollershade i_CurtainDevice)
        {
            UserView.HomePage.Instance.ScrollEnabled = false;
            this.ScrollEnabled = false;
            this.curtainDevice = i_CurtainDevice;
@@ -95,23 +99,51 @@
                listView.Height = bodyFrameLayout.Height;
                bodyFrameLayout.AddChidren(listView);
                //添加方向行
                this.AddDirectionRow();
                //添加限位行
                this.AddLimitRow();
                //添加重置电机行
                this.AddElectricalMachineryRow();
                //保存
                var btnSave = new BottomClickButton();
                btnSave.TextID = R.MyInternationalizationString.uSave;
                bodyFrameLayout.AddChidren(btnSave);
                btnSave.ButtonClickEvent += (sender, e) =>
                //导轨长度为0时
                if (curtainData.CurtainLength <= 0)
                {
                    //这个保存没啥意义
                    this.CloseForm();
                };
                //限位数据接收
                this.ReceiveLimitData();
                    //电机数据异常,请重置电机
                    this.ShowMassage(ShowMsgType.Error, Language.StringByID(R.MyInternationalizationString.uCurtainDataIsErrorPleaseResetCurtain));
                    try
                    {
                        //设备异常补救 -> 添加重置电机行
                        this.AddElectricalMachineryRow();
                        return;
                    }
                    catch (Exception ex2)
                    {
                        HdlLogLogic.Current.WriteLog(ex2, "开合帘补救异常1");
                        return;
                    }
                }
                try
                {
                    //添加方向行
                    this.AddDirectionRow();
                    //添加限位行
                    this.AddLimitRow();
                    //添加重置电机行
                    this.AddElectricalMachineryRow();
                    //限位数据接收
                    this.ReceiveLimitData();
                }
                catch (Exception ex)
                {
                    //Log出力
                    string msg = "当前激活的界面[" + UserCenterResourse.NowActionFormID + "]";
                    HdlLogLogic.Current.WriteLog(ex, msg);
                    //电机数据异常,请重置电机
                    this.ShowMassage(ShowMsgType.Error, Language.StringByID(R.MyInternationalizationString.uCurtainDataIsErrorPleaseResetCurtain));
                    try
                    {
                        this.listView.RemoveAll();
                        //设备异常补救 -> 添加重置电机行
                        this.AddElectricalMachineryRow();
                    }
                    catch (Exception ex2) { HdlLogLogic.Current.WriteLog(ex2, "开合帘补救异常2"); }
                }
            });
        }
@@ -143,12 +175,12 @@
                listText.Add(Language.StringByID(R.MyInternationalizationString.uForwardDirection));//正向
                listText.Add(Language.StringByID(R.MyInternationalizationString.uReverseDirection));//反向
                var form = new BottomDialogSelectForm();
                var form = new BottomItemSelectForm();
                form.AddForm(Language.StringByID(R.MyInternationalizationString.uDirectionSelect), listText, nowSelectNo);
                form.FinishSelectEvent += async (index) =>
                form.FinishSelectEvent += (index) =>
                {
                    //变更方向
                    var result = await HdlDeviceCurtainLogic.Current.SetCurtainDirection(curtainDevice, index == 0 ? false : true);
                    var result = HdlDeviceCurtainLogic.Current.SetCurtainDirection(curtainDevice, index == 0 ? false : true);
                    if (result == false)
                    {
                        return;
@@ -170,7 +202,7 @@
        private void AddLimitRow()
        {
            var frameBack = new FrameLayout();
            frameBack.Height = Application.GetRealHeight(679);
            frameBack.Height = Application.GetRealHeight(956);
            var rowLimit = new FrameRowControl(listView.rowSpace / 2);
            rowLimit.UseClickStatu = false;
@@ -181,14 +213,14 @@
            var btnRinght = rowLimit.AddMostRightEmptyIcon(58, 58);
            rowLimit.ChangedChidrenBindMode(btnRinght, ChidrenBindMode.NotBind);
            btnRinght.UseClickStatu = false;
            btnRinght.UnSelectedImagePath = "Item/Next.png";
            btnRinght.UnSelectedImagePath = "Item/RightNext.png";
            btnRinght.SelectedImagePath = "Item/Down.png";
            btnRinght.IsSelected = true;
            btnRinght.ButtonClickEvent += (sender, e) =>
            {
                btnRinght.IsSelected = !btnRinght.IsSelected;
                //展开折叠
                frameBack.Height = frameBack.Height > 10 ? 0 : Application.GetRealHeight(679);
                frameBack.Height = frameBack.Height > 10 ? 0 : Application.GetRealHeight(956);
            };
            //底线
            rowLimit.AddBottomLine();
@@ -200,6 +232,10 @@
            this.AddCloseLimitProgress(frameBack);
        }
        #endregion
        #region ■ 开限位行___________________________
        /// <summary>
        /// 添加开限位进度条
        /// </summary>
@@ -209,13 +245,15 @@
            //开限位
            var btnProgressView = new NormalViewControl(200, 50, true);
            btnProgressView.X = ControlCommonResourse.XXLeft;
            btnProgressView.Y = Application.GetRealHeight(60);
            btnProgressView.Y = Application.GetRealHeight(78);
            btnProgressView.TextSize = 12;
            btnProgressView.TextColor = UserCenterColor.Current.TextGrayColor1;
            btnProgressView.TextID = R.MyInternationalizationString.uOpenLimit;
            frameBack.AddChidren(btnProgressView);
            int progressValue = (int)(curtainData.OpenLimitValue / (curtainData.CurtainLength * 1.0) * 100);
            //设置百分比的初始值
            curtainData.OpenLimitPersent = progressValue;
            var btnProgress1 = new NormalViewControl(200, 50, true);
            btnProgress1.X = Application.GetRealWidth(200);
            btnProgress1.Y = btnProgressView.Y;
@@ -224,15 +262,9 @@
            btnProgress1.Text = progressValue + "%";
            frameBack.AddChidren(btnProgress1);
            //进度条
            this.openSeekBar = new HorizontalSeekBar();
            this.openSeekBar = new SeekBarControl(965);
            openSeekBar.Y = btnProgressView.Bottom + Application.GetRealHeight(46);
            openSeekBar.Gravity = Gravity.CenterHorizontal;
            openSeekBar.Width = Application.GetRealWidth(962);
            openSeekBar.Height = Application.GetRealHeight(84);
            openSeekBar.Max = 100;
            openSeekBar.BackgroundColor = 0xfff5f5f5;
            openSeekBar.ThumbColor = Common.ZigbeeColor.Current.GXCButtonBlueColor;
            openSeekBar.ProgressColor = 0xff288bfd;
            openSeekBar.ProgressBarColor = 0xff288bfd;
            openSeekBar.Progress = progressValue;
            frameBack.AddChidren(openSeekBar);
@@ -254,78 +286,128 @@
            //线
            var btnLine = new NormalViewControl(frameBack.Width - ControlCommonResourse.XXLeft * 2, ControlCommonResourse.BottomLineHeight, false);
            btnLine.X = ControlCommonResourse.XXLeft;
            btnLine.Y = btnTemp2.Bottom + Application.GetRealHeight(69);
            btnLine.Y = btnTemp2.Bottom + Application.GetRealHeight(156);
            btnLine.BackgroundColor = UserCenterColor.Current.ButtomLine;
            frameBack.AddChidren(btnLine);
            int oldValue = progressValue;
            int waitTime = 4;//500毫秒为单位
            bool startWait = false;
            bool checking = false;
            openSeekBar.ProgressChanged += (sender, value) =>
            //减号
            var btnMinus = new IconViewControl(104);
            btnMinus.UseClickStatu = true;
            btnMinus.X = Application.GetRealWidth(847);
            btnMinus.Y = Application.GetRealHeight(46);
            btnMinus.UnSelectedImagePath = "Item/MinusSign2.png";
            btnMinus.SelectedImagePath = "Item/MinusSign2Selected.png";
            frameBack.AddChidren(btnMinus);
            btnMinus.ButtonClickEvent += (sender, e) =>
            {
                //值继续改变,则等待时间还原
                waitTime = 4;
                if (openSeekBar.Progress <= 0)
                {
                    return;
                }
                openSeekBar.Progress -= 5;
                openSeekBar.ProgressChangedEvent(1, openSeekBar.Progress);
            };
            //加号
            var btnPlus = new IconViewControl(104);
            btnPlus.UseClickStatu = true;
            btnPlus.X = btnMinus.Right;
            btnPlus.Y = btnMinus.Y;
            btnPlus.UnSelectedImagePath = "Item/PlusSign2.png";
            btnPlus.SelectedImagePath = "Item/PlusSign2Selected.png";
            frameBack.AddChidren(btnPlus);
            btnPlus.ButtonClickEvent += (sender, e) =>
            {
                if (openSeekBar.Progress >= 100)
                {
                    return;
                }
                openSeekBar.Progress += 5;
                openSeekBar.ProgressChangedEvent(1, openSeekBar.Progress);
            };
            //保存
            var btnSave = new NormalViewControl(150, 60, true);
            btnSave.X = Application.GetRealWidth(906);
            btnSave.Y = btnTemp1.Bottom + Application.GetRealHeight(68);
            btnSave.TextAlignment = TextAlignment.Center;
            btnSave.TextID = R.MyInternationalizationString.uSave;
            btnSave.TextColor = UserCenterColor.Current.TextOrangeColor;
            frameBack.AddChidren(btnSave);
            btnSave.ButtonClickEvent += (sender, e) =>
            {
                //2020.05.17:追加虚拟住宅可以直接点击
                if (this.receiveOpenlimit == true || Common.Config.Instance.Home.IsVirtually == true)
                {
                    //确认开限位点
                    this.SaveOpenLimit();
                }
            };
            int oldProValue = curtainData.OpenLimitPersent;
            openSeekBar.ProgressChangedEvent += (div, value) =>
            {
                //开限位不能大于合限位
                if (value > closeSeekBar.Progress)
                {
                    openSeekBar.Progress = closeSeekBar.Progress;
                    return;
                }
                if (checking == false)
                {
                    startWait = true;
                }
                btnProgress1.Text = value + "%";
                //数据变更,百分比
                curtainData.OpenLimitPersent = value;
            };
            //虚拟住宅不需要监听
            if (Common.Config.Instance.Home.IsVirtually == true)
            {
                return;
            }
            HdlThreadLogic.Current.RunThread(async () =>
            {
                while (openSeekBar.Parent != null)
                {
                    if (startWait == false)
                    int nowValue = curtainData.OpenLimitPersent;
                    if (oldProValue == nowValue)
                    {
                        await Task.Delay(200);
                        //值不等才处理
                        await Task.Delay(500);
                        continue;
                    }
                    //开启值改变等待
                    await Task.Delay(500);
                    waitTime--;
                    if (waitTime <= 0)
                    {
                        //如果2秒内值不再改变,则进行判断
                        startWait = false;
                        checking = true;
                    oldProValue = nowValue;
                        var value = curtainData.OpenLimitPersent;
                        if (oldValue == value)
                        {
                            //相同数值
                            checking = false;
                            continue;
                        }
                        oldValue = value;
                        if (curtainData.DeleteOpenLimit == true)
                        {
                            //重置开限位点
                            var result = await HdlDeviceCurtainLogic.Current.DeleteCurtainLimitPoint(curtainDevice, Rollershade.LimiType.UpLimit);
                            if (result == false)
                            {
                                checking = false;
                                continue;
                            }
                            curtainData.DeleteOpenLimit = false;
                        }
                        receiveUplimit = "1";
                        //将窗帘调整到指定百分比
                        curtainDevice.WcdGoToTiltValue(value);
                        checking = false;
                    }
                    //将窗帘调整到指定百分比
                    this.sendDiv = 1;
                    curtainDevice.WcdGoToTiltValue(nowValue);
                }
            });
        }
        /// <summary>
        /// 确认开限位点
        /// </summary>
        private void SaveOpenLimit()
        {
            //确认当前位置为开限位?
            string msg = Language.StringByID(R.MyInternationalizationString.uCommitCurtainOpenLimitMsg);
            this.ShowMassage(ShowMsgType.Confirm, msg, () =>
            {
                decimal openValue = ((decimal)curtainData.OpenLimitPersent / 100) * curtainData.CurtainLength;
                decimal closeValue = ((decimal)curtainData.CloseLimitPersent / 100) * curtainData.CurtainLength;
                if (openValue < 0) { openValue = 0; }
                if (closeValue < 0) { closeValue = curtainData.CurtainLength; }
                //执行确认及覆盖上限位点
                var result = HdlDeviceCurtainLogic.Current.SetAutoOpenCurtainLimitPoint(curtainDevice, (int)openValue, (int)closeValue, curtainData.CurtainLength);
                if (result == true)
                {
                    this.receiveOpenlimit = false;
                }
            });
        }
        #endregion
        #region ■ 合限位行___________________________
        /// <summary>
        /// 添加合限位进度条
@@ -336,13 +418,15 @@
            //合限位
            var btnProgressView = new NormalViewControl(200, 50, true);
            btnProgressView.X = ControlCommonResourse.XXLeft;
            btnProgressView.Y = Application.GetRealHeight(397);
            btnProgressView.Y = Application.GetRealHeight(536);
            btnProgressView.TextSize = 12;
            btnProgressView.TextColor = UserCenterColor.Current.TextGrayColor1;
            btnProgressView.TextID = R.MyInternationalizationString.uCloseLimit;
            frameBack.AddChidren(btnProgressView);
            int progressValue = (int)(curtainData.CloseLimitValue / (curtainData.CurtainLength * 1.0) * 100);
            //设置百分比的初始值
            curtainData.CloseLimitPersent = progressValue;
            var btnProgress1 = new NormalViewControl(200, 50, true);
            btnProgress1.X = Application.GetRealWidth(200);
            btnProgress1.Y = btnProgressView.Y;
@@ -351,15 +435,9 @@
            btnProgress1.Text = progressValue + "%";
            frameBack.AddChidren(btnProgress1);
            //进度条
            this.closeSeekBar = new HorizontalSeekBar();
            this.closeSeekBar = new SeekBarControl(965);
            closeSeekBar.Y = btnProgressView.Bottom + Application.GetRealHeight(46);
            closeSeekBar.Gravity = Gravity.CenterHorizontal;
            closeSeekBar.Width = Application.GetRealWidth(962);
            closeSeekBar.Height = Application.GetRealHeight(84);
            closeSeekBar.Max = 100;
            closeSeekBar.BackgroundColor = 0xfff5f5f5;
            closeSeekBar.ThumbColor = Common.ZigbeeColor.Current.GXCButtonBlueColor;
            closeSeekBar.ProgressColor = 0xff288bfd;
            closeSeekBar.ProgressBarColor = 0xff288bfd;
            closeSeekBar.Progress = progressValue;
            frameBack.AddChidren(closeSeekBar);
@@ -381,75 +459,122 @@
            //线
            var btnLine = new NormalViewControl(frameBack.Width - ControlCommonResourse.XXLeft * 2, ControlCommonResourse.BottomLineHeight, false);
            btnLine.X = ControlCommonResourse.XXLeft;
            btnLine.Y = btnTemp2.Bottom + Application.GetRealHeight(69);
            btnLine.Y = btnTemp2.Bottom + Application.GetRealHeight(156);
            btnLine.BackgroundColor = UserCenterColor.Current.ButtomLine;
            frameBack.AddChidren(btnLine);
            int oldValue = progressValue;
            int waitTime = 4;//500毫秒为单位
            bool startWait = false;
            bool checking = false;
            closeSeekBar.ProgressChanged += (sender, value) =>
            //减号
            var btnMinus = new IconViewControl(104);
            btnMinus.UseClickStatu = true;
            btnMinus.X = Application.GetRealWidth(847);
            btnMinus.Y = Application.GetRealHeight(504);
            btnMinus.UnSelectedImagePath = "Item/MinusSign2.png";
            btnMinus.SelectedImagePath = "Item/MinusSign2Selected.png";
            frameBack.AddChidren(btnMinus);
            btnMinus.ButtonClickEvent += (sender, e) =>
            {
                //值继续改变,则等待时间还原
                waitTime = 4;
                //合限位不能小于合限位
                if (value < openSeekBar.Progress)
                if (closeSeekBar.Progress <= 0)
                {
                    return;
                }
                closeSeekBar.Progress -= 5;
                closeSeekBar.ProgressChangedEvent(1, closeSeekBar.Progress);
            };
            //加号
            var btnPlus = new IconViewControl(104);
            btnPlus.UseClickStatu = true;
            btnPlus.X = btnMinus.Right;
            btnPlus.Y = btnMinus.Y;
            btnPlus.UnSelectedImagePath = "Item/PlusSign2.png";
            btnPlus.SelectedImagePath = "Item/PlusSign2Selected.png";
            frameBack.AddChidren(btnPlus);
            btnPlus.ButtonClickEvent += (sender, e) =>
            {
                if (closeSeekBar.Progress >= 100)
                {
                    return;
                }
                closeSeekBar.Progress += 5;
                closeSeekBar.ProgressChangedEvent(1, closeSeekBar.Progress);
            };
            //保存
            var btnSave = new NormalViewControl(150, 60, true);
            btnSave.X = Application.GetRealWidth(906);
            btnSave.Y = btnTemp1.Bottom + Application.GetRealHeight(68);
            btnSave.TextAlignment = TextAlignment.Center;
            btnSave.TextID = R.MyInternationalizationString.uSave;
            btnSave.TextColor = UserCenterColor.Current.TextOrangeColor;
            frameBack.AddChidren(btnSave);
            btnSave.ButtonClickEvent += (sender, e) =>
            {
                //2020.05.17:追加虚拟住宅可以直接点击
                if (this.receiveCloseLimit == true || Common.Config.Instance.Home.IsVirtually == true)
                {
                    //保存合限位点
                    this.SaveCloseLimit();
                }
            };
            int oldProValue = curtainData.CloseLimitPersent;
            closeSeekBar.ProgressChangedEvent += (div, value) =>
            {
                if (value < curtainData.OpenLimitPersent)
                {
                    //合限位不能小于合限位
                    closeSeekBar.Progress = openSeekBar.Progress;
                    return;
                }
                if (checking == false)
                {
                    startWait = true;
                }
                btnProgress1.Text = value + "%";
                //数据变更,百分比
                curtainData.CloseLimitPersent = value;
            };
            //虚拟住宅不需要监听
            if (Common.Config.Instance.Home.IsVirtually == true)
            {
                return;
            }
            HdlThreadLogic.Current.RunThread(async () =>
            {
                while (closeSeekBar.Parent != null)
                {
                    if (startWait == false)
                    int nowValue = curtainData.CloseLimitPersent;
                    if (oldProValue == nowValue)
                    {
                        await Task.Delay(200);
                        //值不等才处理
                        await Task.Delay(500);
                        continue;
                    }
                    //开启值改变等待
                    await Task.Delay(500);
                    waitTime--;
                    if (waitTime <= 0)
                    {
                        //如果2秒内值不再改变,则进行判断
                        startWait = false;
                        checking = true;
                    oldProValue = nowValue;
                        var value = curtainData.CloseLimitPersent;
                        if (oldValue == value)
                        {
                            //相同数值
                            checking = false;
                            continue;
                        }
                        oldValue = value;
                        if (curtainData.DeleteCloseLimit == true)
                        {
                            //重置合限位点
                            var result = await HdlDeviceCurtainLogic.Current.DeleteCurtainLimitPoint(curtainDevice, Rollershade.LimiType.DownLimit);
                            if (result == false)
                            {
                                checking = false;
                                continue;
                            }
                            curtainData.DeleteCloseLimit = false;
                        }
                        receiveDownLimit = "1";
                        //将窗帘调整到指定百分比
                        curtainDevice.WcdGoToTiltValue(value);
                        checking = false;
                    }
                    //将窗帘调整到指定百分比
                    this.sendDiv = 2;
                    curtainDevice.WcdGoToTiltValue(nowValue);
                }
            });
        }
        /// <summary>
        /// 保存合限位点
        /// </summary>
        private void SaveCloseLimit()
        {
            //确认当前位置为合限位?
            string msg = Language.StringByID(R.MyInternationalizationString.uCommitCurtainCloseLimitMsg);
            this.ShowMassage(ShowMsgType.Confirm, msg, () =>
            {
                decimal openValue = ((decimal)curtainData.OpenLimitPersent / 100) * curtainData.CurtainLength;
                decimal closeValue = ((decimal)curtainData.CloseLimitPersent / 100) * curtainData.CurtainLength;
                if (openValue < 0) { openValue = 0; }
                if (closeValue < 0) { closeValue = curtainData.CurtainLength; }
                //执行确认及覆盖上限位点
                var result = HdlDeviceCurtainLogic.Current.SetAutoOpenCurtainLimitPoint(curtainDevice, (int)openValue, (int)closeValue, curtainData.CurtainLength);
                if (result == true)
                {
                    this.receiveCloseLimit = false;
                }
            });
        }
@@ -471,19 +596,49 @@
            rowReset.AddBottomLine();
            rowReset.ButtonClickEvent += (sender, e) =>
            {
                //如果当前是虚拟住宅
                if (Common.Config.Instance.Home.IsVirtually == true)
                {
                    return;
                }
                //重置电机将初始化{0}方向与限位设置,确认继续?
                string msg = Language.StringByID(R.MyInternationalizationString.uResetElectricalMachineryMsg);
                msg = msg.Replace("{0}", "\r\n");
                this.ShowMassage(ShowMsgType.Confirm, msg, () =>
                {
                    //开启进度条
                    ProgressFormBar.Current.Start();
                    //正在重置电机
                    ProgressFormBar.Current.SetMsg(Language.StringByID(R.MyInternationalizationString.uElectricalMachineryResetting));
                    //重置窗帘
                    HdlThreadLogic.Current.RunThread(async () =>
                    {
                        //重置窗帘
                        var result = await HdlDeviceCurtainLogic.Current.RestoreCurtain(curtainDevice);
                        if (result == false)
                        {
                            //关闭进度条
                            ProgressFormBar.Current.Close();
                            return;
                        }
                        //每10的长度大概是2秒,多预留1次出来
                        int waitCount = ((curtainData.CurtainLength / 10) + 1) * 3;
                        if (waitCount < 12)
                        {
                            waitCount = 12;
                        }
                        int timeCount = 0;
                        while (timeCount <= waitCount)
                        {
                            //进度条值
                            ProgressFormBar.Current.SetValue(timeCount, waitCount);
                            timeCount++;
                            System.Threading.Thread.Sleep(1000);
                        }
                        //关闭进度条
                        ProgressFormBar.Current.Close();
                        //获取数据后,备份窗帘数据
                        this.backupCurtainData = true;
                        //重新初始化界面
@@ -503,16 +658,28 @@
        /// <returns></returns>
        private bool InitCurtainDefultData()
        {
            this.curtainData = new CurtainData();
            this.receiveOpenlimit = false;
            this.receiveCloseLimit = false;
            this.sendDiv = 0;
            //如果当前是虚拟住宅
            if (Common.Config.Instance.Home.IsVirtually == true)
            {
                var data = ModelData.DeviceModelDataLogic.Current.GetCurtainLimitPoint(curtainDevice);
                curtainData.Direction = data.Direction;
                curtainData.CurtainLength = data.curtainLength;
                curtainData.OpenLimitValue = data.upLimit;
                curtainData.CloseLimitValue = data.downLimit;
                return true;
            }
            //开启进度条
            this.ShowProgressBar();
            this.curtainData = new CurtainData();
            this.receiveUplimit = "0";
            this.receiveDownLimit = "0";
            bool receiptData = false;
            int receiptDataCount = 0;
            string mainkeys = LocalDevice.Current.GetDeviceMainKeys(curtainDevice);
            HdlDeviceAttributeLogic.Current.AddAttributeEvent("CurtainDeviceAttribute", "DeviceStatusReport", (device) =>
            HdlGatewayReceiveLogic.Current.AddAttributeEvent("CurtainDeviceAttribute", ReceiveComandDiv.A设备属性上报, (device) =>
            {
                string checkKey = LocalDevice.Current.GetDeviceMainKeys(device);
                if (mainkeys != checkKey || device.DeviceStatusReport.CluterID != 258)
@@ -534,23 +701,25 @@
                            //正向
                            curtainData.Direction = false;
                        }
                        receiptDataCount++;
                    }
                    else if (attriBute.AttributeId == 1)
                    {
                        //窗帘总长
                        curtainData.CurtainLength = attriBute.AttriButeData;
                        receiptDataCount++;
                    }
                    else if (attriBute.AttributeId == 16)
                    {
                        //开限位
                        curtainData.OpenLimitValue = attriBute.AttriButeData;
                        receiptDataCount++;
                    }
                    else if (attriBute.AttributeId == 17)
                    {
                        //合限位
                        curtainData.CloseLimitValue = attriBute.AttriButeData;
                        //数据接收结束
                        receiptData = true;
                        receiptDataCount++;
                    }
                }
            });
@@ -558,7 +727,7 @@
            HdlDeviceCurtainLogic.Current.SetGetCurtainLimitSettionComand(curtainDevice);
            int timeCount = 30;
            while (receiptData == false && timeCount >= 0)
            while (receiptDataCount != 4 && timeCount >= 0)
            {
                System.Threading.Thread.Sleep(100);
                timeCount--;
@@ -576,22 +745,7 @@
                return false;
            }
            //移除监听
            HdlDeviceAttributeLogic.Current.RemoveEvent("CurtainDeviceAttribute");
            //备份窗帘数据
            if (this.backupCurtainData == true)
            {
                this.backupCurtainData = false;
                HdlThreadLogic.Current.RunThread(async () =>
                {
                    //方向备份
                    await HdlDeviceCurtainLogic.Current.BackupCurtainDirection(curtainDevice, curtainData.Direction);
                    //限位备份
                    int uplimit= (int)(curtainData.OpenLimitValue / (curtainData.CurtainLength * 1.0) * 100);
                    int downlimit = (int)(curtainData.CloseLimitValue / (curtainData.CurtainLength * 1.0) * 100);
                    await HdlDeviceCurtainLogic.Current.BackupCurtainLimitPoint(curtainDevice, uplimit, downlimit);
                });
            }
            HdlGatewayReceiveLogic.Current.RemoveEvent("CurtainDeviceAttribute");
            return true;
        }
@@ -605,59 +759,32 @@
        /// </summary>
        private void ReceiveLimitData()
        {
            if (HdlDeviceAttributeLogic.Current.IsEsixt("ReceiveLimitData") == true)
            if (HdlGatewayReceiveLogic.Current.IsEsixt("ReceiveLimitData") == true)
            {
                HdlDeviceAttributeLogic.Current.RemoveEvent("ReceiveLimitData");
                HdlGatewayReceiveLogic.Current.RemoveEvent("ReceiveLimitData");
            }
            string mainkeys = LocalDevice.Current.GetDeviceMainKeys(curtainDevice);
            HdlDeviceAttributeLogic.Current.AddAttributeEvent("ReceiveLimitData", "DeviceStatusReport", (device) =>
            HdlGatewayReceiveLogic.Current.AddAttributeEvent("ReceiveLimitData", ReceiveComandDiv.A设备属性上报, (device) =>
            {
                string checkKey = LocalDevice.Current.GetDeviceMainKeys(device);
                if (mainkeys != checkKey || device.DeviceStatusReport.CluterID != 258)
                {
                    return;
                }
                lock (receiveUplimit)
                foreach (var attriBute in device.DeviceStatusReport.AttriBute)
                {
                    if (receiveUplimit == "0" && receiveDownLimit == "0")
                    //窗帘百分比推送
                    if (attriBute.AttributeId == 8)
                    {
                        return;
                    }
                    foreach (var attriBute in device.DeviceStatusReport.AttriBute)
                    {
                        //窗帘百分比推送
                        if (attriBute.AttributeId == 8)
                        //开限位
                        if (sendDiv == 1)
                        {
                            //上限位
                            if (receiveUplimit == "1")
                            {
                                receiveUplimit = "0";
                                openSeekBar.Progress = curtainData.OpenLimitPersent;
                                //确认当前位置{0}为开限位?
                                string msg = Language.StringByID(R.MyInternationalizationString.uCommitCurtainOpenLimitMsg);
                                msg = msg.Replace("{0}", curtainData.OpenLimitPersent + "%");
                                this.ShowMassage(ShowMsgType.Confirm, msg, async () =>
                                {
                                    //执行确认及覆盖上限位点
                                    await HdlDeviceCurtainLogic.Current.CommitCurtainLimitPoint(curtainDevice, Rollershade.CurtainPrivateInstalledLimi.UpLimit,
                                        curtainData.OpenLimitPersent, curtainData.CloseLimitPersent);
                                });
                            }
                            //合限位
                            else if (receiveDownLimit == "1")
                            {
                                receiveDownLimit = "0";
                                closeSeekBar.Progress = curtainData.CloseLimitPersent;
                                //确认当前位置{0}为合限位?
                                string msg = Language.StringByID(R.MyInternationalizationString.uCommitCurtainCloseLimitMsg);
                                msg = msg.Replace("{0}", curtainData.CloseLimitPersent + "%");
                                this.ShowMassage(ShowMsgType.Confirm, msg, async () =>
                                {
                                    //执行确认及覆盖合限位点
                                    await HdlDeviceCurtainLogic.Current.CommitCurtainLimitPoint(curtainDevice, Rollershade.CurtainPrivateInstalledLimi.DownLimit,
                                        curtainData.OpenLimitPersent, curtainData.CloseLimitPersent);
                                });
                            }
                            receiveOpenlimit = true;
                        }
                        //合限位
                        else if (sendDiv == 2)
                        {
                            receiveCloseLimit = true;
                        }
                    }
                }
@@ -671,14 +798,12 @@
        /// <summary>
        /// 界面关闭
        /// </summary>
        public override void CloseForm()
        public override void CloseFormBefore()
        {
            HdlDeviceAttributeLogic.Current.RemoveEvent("CurtainDeviceAttribute");
            HdlDeviceAttributeLogic.Current.RemoveEvent("ReceiveLimitData");
            HdlGatewayReceiveLogic.Current.RemoveEvent("CurtainDeviceAttribute");
            HdlGatewayReceiveLogic.Current.RemoveEvent("ReceiveLimitData");
            UserView.HomePage.Instance.ScrollEnabled = true;
            base.CloseForm();
            base.CloseFormBefore();
        }
        #endregion
@@ -694,14 +819,6 @@
            /// false:电机方向正向;true:电机方向反向
            /// </summary>
            public bool Direction = false;
            /// <summary>
            /// 是否重置开限位点
            /// </summary>
            public bool DeleteOpenLimit = true;
            /// <summary>
            /// 是否重置合限位点
            /// </summary>
            public bool DeleteCloseLimit = true;
            /// <summary>
            /// 开限位的值
            /// </summary>