黄学彪
2019-12-17 5986f63b75bd81c6cef262c670e9251c038cbf5d
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
@@ -101,15 +105,7 @@
                this.AddLimitRow();
                //添加重置电机行
                this.AddElectricalMachineryRow();
                //保存
                var btnSave = new BottomClickButton();
                btnSave.TextID = R.MyInternationalizationString.uSave;
                bodyFrameLayout.AddChidren(btnSave);
                btnSave.ButtonClickEvent += (sender, e) =>
                {
                    //这个保存没啥意义
                    this.CloseForm();
                };
                //限位数据接收
                this.ReceiveLimitData();
            });
@@ -170,7 +166,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;
@@ -188,7 +184,7 @@
            {
                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 +196,10 @@
            this.AddCloseLimitProgress(frameBack);
        }
        #endregion
        #region ■ 开限位行___________________________
        /// <summary>
        /// 添加开限位进度条
        /// </summary>
@@ -209,7 +209,7 @@
            //开限位
            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;
@@ -224,15 +224,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 +248,134 @@
            //线
            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 -= 1;
                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 += 1;
                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) =>
            {
                if (this.receiveOpenlimit == 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;
            };
            HdlThreadLogic.Current.RunThread(async () =>
            {
                //处理中
                bool checking = false;
                while (openSeekBar.Parent != null)
                {
                    if (startWait == false)
                    int nowValue = curtainData.OpenLimitPersent;
                    if (oldProValue == nowValue || checking == true)
                    {
                        await Task.Delay(200);
                        //值不等才处理
                        await Task.Delay(500);
                        continue;
                    }
                    //开启值改变等待
                    await Task.Delay(500);
                    waitTime--;
                    if (waitTime <= 0)
                    oldProValue = nowValue;
                    checking = true;
                    if (curtainData.DeleteOpenLimit == true)
                    {
                        //如果2秒内值不再改变,则进行判断
                        startWait = false;
                        checking = true;
                        var value = curtainData.OpenLimitPersent;
                        if (oldValue == value)
                        //重置开限位点
                        var result = await HdlDeviceCurtainLogic.Current.DeleteCurtainLimitPoint(curtainDevice, Rollershade.LimiType.UpLimit);
                        if (result == false)
                        {
                            //相同数值
                            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;
                        curtainData.DeleteOpenLimit = false;
                    }
                    //将窗帘调整到指定百分比
                    this.sendDiv = 1;
                    curtainDevice.WcdGoToTiltValue(nowValue);
                    checking = false;
                }
            });
        }
        /// <summary>
        /// 确认开限位点
        /// </summary>
        private void SaveOpenLimit()
        {
            //确认当前位置为开限位?
            string msg = Language.StringByID(R.MyInternationalizationString.uCommitCurtainOpenLimitMsg);
            this.ShowMassage(ShowMsgType.Confirm, msg, async () =>
            {
                //执行确认及覆盖上限位点
                var result = await HdlDeviceCurtainLogic.Current.CommitCurtainLimitPoint(curtainDevice, Rollershade.CurtainPrivateInstalledLimi.UpLimit,
                    curtainData.OpenLimitPersent, curtainData.CloseLimitPersent);
                if (result == true)
                {
                    curtainData.DeleteOpenLimit = true;
                    this.receiveOpenlimit = false;
                }
            });
        }
        #endregion
        #region ■ 合限位行___________________________
        /// <summary>
        /// 添加合限位进度条
@@ -336,7 +386,7 @@
            //合限位
            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;
@@ -351,15 +401,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 +425,126 @@
            //线
            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 -= 1;
                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 += 1;
                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) =>
            {
                if (this.receiveCloseLimit == 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;
            };
            HdlThreadLogic.Current.RunThread(async () =>
            {
                //处理中
                bool checking = false;
                while (closeSeekBar.Parent != null)
                {
                    if (startWait == false)
                    int nowValue = curtainData.CloseLimitPersent;
                    if (oldProValue == nowValue || checking == true)
                    {
                        await Task.Delay(200);
                        //值不等才处理
                        await Task.Delay(500);
                        continue;
                    }
                    //开启值改变等待
                    await Task.Delay(500);
                    waitTime--;
                    if (waitTime <= 0)
                    checking = true;
                    oldProValue = nowValue;
                    if (curtainData.DeleteCloseLimit == true)
                    {
                        //如果2秒内值不再改变,则进行判断
                        startWait = false;
                        checking = true;
                        var value = curtainData.CloseLimitPersent;
                        if (oldValue == value)
                        //重置合限位点
                        var result = await HdlDeviceCurtainLogic.Current.DeleteCurtainLimitPoint(curtainDevice, Rollershade.LimiType.DownLimit);
                        if (result == false)
                        {
                            //相同数值
                            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;
                        curtainData.DeleteCloseLimit = false;
                    }
                    //将窗帘调整到指定百分比
                    this.sendDiv = 2;
                    curtainDevice.WcdGoToTiltValue(nowValue);
                    checking = false;
                }
            });
        }
        /// <summary>
        /// 保存合限位点
        /// </summary>
        private void SaveCloseLimit()
        {
            //确认当前位置为合限位?
            string msg = Language.StringByID(R.MyInternationalizationString.uCommitCurtainCloseLimitMsg);
            this.ShowMassage(ShowMsgType.Confirm, msg, async () =>
            {
                //执行确认及覆盖合限位点
                var result = await HdlDeviceCurtainLogic.Current.CommitCurtainLimitPoint(curtainDevice, Rollershade.CurtainPrivateInstalledLimi.DownLimit,
                    curtainData.OpenLimitPersent, curtainData.CloseLimitPersent);
                if (result == true)
                {
                    curtainData.DeleteCloseLimit = true;
                    this.receiveCloseLimit = false;
                }
            });
        }
@@ -476,14 +571,35 @@
                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;
                        int timeCount = 0;
                        while (timeCount <= waitCount)
                        {
                            //进度条值
                            ProgressFormBar.Current.SetValue(timeCount, waitCount);
                            timeCount++;
                            System.Threading.Thread.Sleep(1000);
                        }
                        //关闭进度条
                        ProgressFormBar.Current.Close();
                        //获取数据后,备份窗帘数据
                        this.backupCurtainData = true;
                        //重新初始化界面
@@ -507,8 +623,9 @@
            this.ShowProgressBar();
            this.curtainData = new CurtainData();
            this.receiveUplimit = "0";
            this.receiveDownLimit = "0";
            this.receiveOpenlimit = false;
            this.receiveCloseLimit = false;
            this.sendDiv = 0;
            bool receiptData = false;
            string mainkeys = LocalDevice.Current.GetDeviceMainKeys(curtainDevice);
@@ -617,55 +734,20 @@
                {
                    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 () =>
                                {
                                    //执行确认及覆盖上限位点
                                    var result = await HdlDeviceCurtainLogic.Current.CommitCurtainLimitPoint(curtainDevice, Rollershade.CurtainPrivateInstalledLimi.UpLimit,
                                        curtainData.OpenLimitPersent, curtainData.CloseLimitPersent);
                                    if (result == true)
                                    {
                                        curtainData.DeleteOpenLimit = true;
                                    }
                                });
                            }
                            //合限位
                            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 () =>
                                {
                                    //执行确认及覆盖合限位点
                                    var result = await HdlDeviceCurtainLogic.Current.CommitCurtainLimitPoint(curtainDevice, Rollershade.CurtainPrivateInstalledLimi.DownLimit,
                                        curtainData.OpenLimitPersent, curtainData.CloseLimitPersent);
                                    if (result == true)
                                    {
                                        curtainData.DeleteCloseLimit = true;
                                    }
                                });
                            }
                            receiveOpenlimit = true;
                        }
                        //合限位
                        else if (sendDiv == 2)
                        {
                            receiveCloseLimit = true;
                        }
                    }
                }