From 6fa9d69da922c8049f5acfcbb9ce9fd26811024c Mon Sep 17 00:00:00 2001
From: xm <1271024303@qq.com>
Date: 星期四, 16 四月 2020 17:10:57 +0800
Subject: [PATCH] 请合并代码

---
 ZigbeeApp/Shared/Phone/UserCenter/Device/Curtain/AutoOpenDirectionAndLimitSettionForm.cs |  843 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 843 insertions(+), 0 deletions(-)

diff --git a/ZigbeeApp/Shared/Phone/UserCenter/Device/Curtain/AutoOpenDirectionAndLimitSettionForm.cs b/ZigbeeApp/Shared/Phone/UserCenter/Device/Curtain/AutoOpenDirectionAndLimitSettionForm.cs
new file mode 100755
index 0000000..de7b257
--- /dev/null
+++ b/ZigbeeApp/Shared/Phone/UserCenter/Device/Curtain/AutoOpenDirectionAndLimitSettionForm.cs
@@ -0,0 +1,843 @@
+锘縰sing Shared.Common;
+using System;
+using System.Collections.Generic;
+using System.Text;
+using System.Threading.Tasks;
+using ZigBee.Device;
+
+namespace Shared.Phone.UserCenter.DeviceCurtain
+{
+    /// <summary>
+    /// 寮�鍚堝笜鐨勬柟鍚戜笌闄愪綅鐨勯厤缃晫闈�
+    /// </summary>
+    public class AutoOpenDirectionAndLimitSettionForm : EditorCommonForm
+    {
+        #region 鈻� 鍙橀噺澹版槑___________________________
+
+        /// <summary>
+        ///绐楀笜鐨勫洖璺�
+        /// </summary>
+        private Rollershade curtainDevice = null;
+        /// <summary>
+        /// 绐楀笜鏁版嵁
+        /// </summary>
+        private CurtainData curtainData = null;
+        /// <summary>
+        /// 鎺ユ敹寮�闄愪綅 false:娌℃湁鎺ユ敹鍒� true:宸茬粡鎺ユ敹鍒�
+        /// </summary>
+        private bool receiveOpenlimit = false;
+        /// <summary>
+        /// 鎺ユ敹鍚堥檺浣� false:娌℃湁鎺ユ敹鍒� true:宸茬粡鎺ユ敹鍒�
+        /// </summary>
+        private bool receiveCloseLimit = false;
+        /// <summary>
+        /// 鍙戦�佸尯鍒� 1:寮�闄愪綅 2:鍚堥檺浣�
+        /// </summary>
+        private int sendDiv = 0;
+        /// <summary>
+        /// 鏄惁澶囦唤绐楀笜鏁版嵁
+        /// </summary>
+        private bool backupCurtainData = false;
+        /// <summary>
+        /// 鍒楄〃鎺т欢
+        /// </summary>
+        private VerticalListControl listView = null;
+        /// <summary>
+        /// 寮�闄愪綅鐨勮繘搴︽潯
+        /// </summary>
+        private SeekBarControl openSeekBar = null;
+        /// <summary>
+        /// 鍚堥檺浣嶇殑杩涘害鏉�
+        /// </summary>
+        private SeekBarControl closeSeekBar = null;
+
+        #endregion
+
+        #region 鈻� 鍒濆鍖朹____________________________
+
+        /// <summary>
+        /// 鐢婚潰鏄剧ず(搴曞眰浼氬浐瀹氳皟鐢ㄦ鏂规硶锛屽�熶互瀹屾垚鐢婚潰鍒涘缓)
+        /// </summary>
+        /// <param name="i_listdevice">绐楀笜鐨勫洖璺�</param>
+        public void ShowForm(Rollershade i_CurtainDevice)
+        {
+            this.ScrollEnabled = false;
+
+            this.curtainDevice = i_CurtainDevice;
+
+            //璁剧疆鏍囬淇℃伅
+            base.SetTitleText(Language.StringByID(R.MyInternationalizationString.uDirectionAndLimit));
+
+            HdlThreadLogic.Current.RunThread(() =>
+            {
+                //鍒濆鍖栦腑閮ㄦ帶浠�
+                this.InitMiddleFrame();
+            });
+        }
+
+        /// <summary>
+        /// 鍒濆鍖栦腑閮ㄤ俊鎭�
+        /// </summary>
+        private void InitMiddleFrame()
+        {
+            //鑾峰彇璁惧鍒濆鏁版嵁
+            var result = this.InitCurtainDefultData();
+            if (result == false)
+            {
+                //鏄剧ず閲嶆柊鍔犺浇鐨勭晫闈�
+                this.ShowReLoadView();
+                return;
+            }
+            HdlThreadLogic.Current.RunMain(() =>
+            {
+                //娓呯┖bodyFrame
+                bodyFrameLayout.BackgroundColor = UserCenterColor.Current.White;
+                this.ClearBodyFrame();
+
+                this.listView = new VerticalListControl(29);
+                listView.Y = Application.GetRealHeight(-6);
+                listView.Height = bodyFrameLayout.Height;
+                bodyFrameLayout.AddChidren(listView);
+
+                //瀵艰建闀垮害涓�0鏃�
+                if (curtainData.CurtainLength <= 0)
+                {
+                    //鐢垫満鏁版嵁寮傚父,璇烽噸缃數鏈�
+                    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"); }
+                }
+            });
+        }
+
+        #endregion
+
+        #region 鈻� 鏂瑰悜琛宊____________________________
+
+        /// <summary>
+        /// 娣诲姞鏂瑰悜琛�
+        /// </summary>
+        private void AddDirectionRow()
+        {
+            var rowDirection = new FrameRowControl(listView.rowSpace / 2);
+            listView.AddChidren(rowDirection);
+            //鏂瑰悜
+            rowDirection.AddLeftCaption(Language.StringByID(R.MyInternationalizationString.uDirection), 600);
+            //鍙崇澶�
+            rowDirection.AddRightArrow();
+            //鐘舵��
+            var btnStatu = rowDirection.AddMostRightView("", 300);
+            btnStatu.TextID = curtainData.Direction == false ? R.MyInternationalizationString.uForwardDirection : R.MyInternationalizationString.uReverseDirection;
+            //搴曠嚎
+            rowDirection.AddBottomLine();
+
+            int nowSelectNo = curtainData.Direction == false ? 0 : 1;
+            rowDirection.ButtonClickEvent += (sender, e) =>
+            {
+                var listText = new List<string>();
+                listText.Add(Language.StringByID(R.MyInternationalizationString.uForwardDirection));//姝e悜
+                listText.Add(Language.StringByID(R.MyInternationalizationString.uReverseDirection));//鍙嶅悜
+
+                var form = new BottomItemSelectForm();
+                form.AddForm(Language.StringByID(R.MyInternationalizationString.uDirectionSelect), listText, nowSelectNo);
+                form.FinishSelectEvent += async (index) =>
+                {
+                    //鍙樻洿鏂瑰悜
+                    var result = await HdlDeviceCurtainLogic.Current.SetCurtainDirection(curtainDevice, index == 0 ? false : true);
+                    if (result == false)
+                    {
+                        return;
+                    }
+                    nowSelectNo = index;
+                    btnStatu.Text = listText[index];
+                    curtainData.Direction = index == 0 ? false : true;
+                };
+            };
+        }
+
+        #endregion
+
+        #region 鈻� 闄愪綅琛宊____________________________
+
+        /// <summary>
+        /// 娣诲姞闄愪綅琛�
+        /// </summary>
+        private void AddLimitRow()
+        {
+            var frameBack = new FrameLayout();
+            frameBack.Height = Application.GetRealHeight(956);
+
+            var rowLimit = new FrameRowControl(listView.rowSpace / 2);
+            rowLimit.UseClickStatu = false;
+            listView.AddChidren(rowLimit);
+            //闄愪綅
+            rowLimit.AddLeftCaption(Language.StringByID(R.MyInternationalizationString.uLimit), 600);
+            //鍙崇澶�
+            var btnRinght = rowLimit.AddMostRightEmptyIcon(58, 58);
+            rowLimit.ChangedChidrenBindMode(btnRinght, ChidrenBindMode.NotBind);
+            btnRinght.UseClickStatu = false;
+            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(956);
+            };
+            //搴曠嚎
+            rowLimit.AddBottomLine();
+
+            listView.AddChidren(frameBack);
+            //娣诲姞寮�闄愪綅杩涘害鏉�
+            this.AddOpenLimitProgress(frameBack);
+            //娣诲姞鍚堥檺浣嶈繘搴︽潯
+            this.AddCloseLimitProgress(frameBack);
+        }
+
+        #endregion
+
+        #region 鈻� 寮�闄愪綅琛宊__________________________
+
+        /// <summary>
+        /// 娣诲姞寮�闄愪綅杩涘害鏉�
+        /// </summary>
+        /// <param name="frameBack"></param>
+        private void AddOpenLimitProgress(FrameLayout frameBack)
+        {
+            //寮�闄愪綅
+            var btnProgressView = new NormalViewControl(200, 50, true);
+            btnProgressView.X = ControlCommonResourse.XXLeft;
+            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;
+            btnProgress1.TextSize = 12;
+            btnProgress1.TextColor = UserCenterColor.Current.TextGrayColor1;
+            btnProgress1.Text = progressValue + "%";
+            frameBack.AddChidren(btnProgress1);
+            //杩涘害鏉�
+            this.openSeekBar = new SeekBarControl(965);
+            openSeekBar.Y = btnProgressView.Bottom + Application.GetRealHeight(46);
+            openSeekBar.ProgressBarColor = 0xff288bfd;
+            openSeekBar.Progress = progressValue;
+            frameBack.AddChidren(openSeekBar);
+
+            var btnTemp1 = new NormalViewControl(200, 50, true);
+            btnTemp1.X = ControlCommonResourse.XXLeft;
+            btnTemp1.Y = btnProgressView.Bottom + Application.GetRealHeight(115);
+            btnTemp1.TextSize = 12;
+            btnTemp1.TextColor = UserCenterColor.Current.TextGrayColor3;
+            btnTemp1.Text = "0%";
+            frameBack.AddChidren(btnTemp1);
+            var btnTemp2 = new NormalViewControl(200, 50, true);
+            btnTemp2.X = frameBack.Width - Application.GetRealWidth(200 + 50);
+            btnTemp2.Y = btnTemp1.Y;
+            btnTemp2.TextAlignment = TextAlignment.CenterRight;
+            btnTemp2.TextSize = 12;
+            btnTemp2.TextColor = UserCenterColor.Current.TextGrayColor3;
+            btnTemp2.Text = "100%";
+            frameBack.AddChidren(btnTemp2);
+            //绾�
+            var btnLine = new NormalViewControl(frameBack.Width - ControlCommonResourse.XXLeft * 2, ControlCommonResourse.BottomLineHeight, false);
+            btnLine.X = ControlCommonResourse.XXLeft;
+            btnLine.Y = btnTemp2.Bottom + Application.GetRealHeight(156);
+            btnLine.BackgroundColor = UserCenterColor.Current.ButtomLine;
+            frameBack.AddChidren(btnLine);
+
+            //鍑忓彿
+            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) =>
+            {
+                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) =>
+            {
+                if (this.receiveOpenlimit == true)
+                {
+                    //纭寮�闄愪綅鐐�
+                    this.SaveOpenLimit();
+                }
+            };
+
+            int oldProValue = curtainData.OpenLimitPersent;
+            openSeekBar.ProgressChangedEvent += (div, value) =>
+            {
+                //寮�闄愪綅涓嶈兘澶т簬鍚堥檺浣�
+                if (value > closeSeekBar.Progress)
+                {
+                    openSeekBar.Progress = closeSeekBar.Progress;
+                    return;
+                }
+                btnProgress1.Text = value + "%";
+                //鏁版嵁鍙樻洿,鐧惧垎姣�
+                curtainData.OpenLimitPersent = value;
+            };
+
+            HdlThreadLogic.Current.RunThread(async () =>
+            {
+                //澶勭悊涓�
+                bool checking = false;
+                while (openSeekBar.Parent != null)
+                {
+                    int nowValue = curtainData.OpenLimitPersent;
+                    if (oldProValue == nowValue || checking == true)
+                    {
+                        //鍊间笉绛夋墠澶勭悊
+                        await Task.Delay(500);
+                        continue;
+                    }
+                    oldProValue = nowValue;
+                    checking = true;
+
+                    //灏嗙獥甯樿皟鏁村埌鎸囧畾鐧惧垎姣�
+                    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 () =>
+            {
+                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 = await HdlDeviceCurtainLogic.Current.CommitCurtainLimitPoint(curtainDevice, Rollershade.CurtainPrivateInstalledLimi.UpLimit,
+                    (int)openValue, (int)closeValue);
+                if (result == true)
+                {
+                    this.receiveOpenlimit = false;
+                }
+            });
+        }
+
+        #endregion
+
+        #region 鈻� 鍚堥檺浣嶈___________________________
+
+        /// <summary>
+        /// 娣诲姞鍚堥檺浣嶈繘搴︽潯
+        /// </summary>
+        /// <param name="frameBack"></param>
+        private void AddCloseLimitProgress(FrameLayout frameBack)
+        {
+            //鍚堥檺浣�
+            var btnProgressView = new NormalViewControl(200, 50, true);
+            btnProgressView.X = ControlCommonResourse.XXLeft;
+            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;
+            btnProgress1.TextSize = 12;
+            btnProgress1.TextColor = UserCenterColor.Current.TextGrayColor1;
+            btnProgress1.Text = progressValue + "%";
+            frameBack.AddChidren(btnProgress1);
+            //杩涘害鏉�
+            this.closeSeekBar = new SeekBarControl(965);
+            closeSeekBar.Y = btnProgressView.Bottom + Application.GetRealHeight(46);
+            closeSeekBar.ProgressBarColor = 0xff288bfd;
+            closeSeekBar.Progress = progressValue;
+            frameBack.AddChidren(closeSeekBar);
+
+            var btnTemp1 = new NormalViewControl(200, 50, true);
+            btnTemp1.X = ControlCommonResourse.XXLeft;
+            btnTemp1.Y = btnProgressView.Bottom + Application.GetRealHeight(115);
+            btnTemp1.TextSize = 12;
+            btnTemp1.TextColor = UserCenterColor.Current.TextGrayColor3;
+            btnTemp1.Text = "0%";
+            frameBack.AddChidren(btnTemp1);
+            var btnTemp2 = new NormalViewControl(200, 50, true);
+            btnTemp2.X = frameBack.Width - Application.GetRealWidth(200 + 50);
+            btnTemp2.Y = btnTemp1.Y;
+            btnTemp2.TextAlignment = TextAlignment.CenterRight;
+            btnTemp2.TextSize = 12;
+            btnTemp2.TextColor = UserCenterColor.Current.TextGrayColor3;
+            btnTemp2.Text = "100%";
+            frameBack.AddChidren(btnTemp2);
+            //绾�
+            var btnLine = new NormalViewControl(frameBack.Width - ControlCommonResourse.XXLeft * 2, ControlCommonResourse.BottomLineHeight, false);
+            btnLine.X = ControlCommonResourse.XXLeft;
+            btnLine.Y = btnTemp2.Bottom + Application.GetRealHeight(156);
+            btnLine.BackgroundColor = UserCenterColor.Current.ButtomLine;
+            frameBack.AddChidren(btnLine);
+
+            //鍑忓彿
+            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) =>
+            {
+                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) =>
+            {
+                if (this.receiveCloseLimit == true)
+                {
+                    //淇濆瓨鍚堥檺浣嶇偣
+                    this.SaveCloseLimit();
+                }
+            };
+
+            int oldProValue = curtainData.CloseLimitPersent;
+            closeSeekBar.ProgressChangedEvent += (div, value) =>
+            {
+                if (value < curtainData.OpenLimitPersent)
+                {
+                    //鍚堥檺浣嶄笉鑳藉皬浜庡悎闄愪綅
+                    closeSeekBar.Progress = openSeekBar.Progress;
+                    return;
+                }
+                btnProgress1.Text = value + "%";
+                //鏁版嵁鍙樻洿,鐧惧垎姣�
+                curtainData.CloseLimitPersent = value;
+            };
+
+            HdlThreadLogic.Current.RunThread(async () =>
+            {
+                //澶勭悊涓�
+                bool checking = false;
+                while (closeSeekBar.Parent != null)
+                {
+                    int nowValue = curtainData.CloseLimitPersent;
+                    if (oldProValue == nowValue || checking == true)
+                    {
+                        //鍊间笉绛夋墠澶勭悊
+                        await Task.Delay(500);
+                        continue;
+                    }
+                    checking = true;
+                    oldProValue = nowValue;
+
+                    //灏嗙獥甯樿皟鏁村埌鎸囧畾鐧惧垎姣�
+                    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 () =>
+            {
+                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 = await HdlDeviceCurtainLogic.Current.CommitCurtainLimitPoint(curtainDevice, Rollershade.CurtainPrivateInstalledLimi.DownLimit,
+                    (int)openValue, (int)closeValue);
+
+                if (result == true)
+                {
+                    this.receiveCloseLimit = false;
+                }
+            });
+        }
+
+        #endregion
+
+        #region 鈻� 閲嶇疆鐢垫満___________________________
+
+        /// <summary>
+        /// 娣诲姞閲嶇疆鐢垫満琛�
+        /// </summary>
+        private void AddElectricalMachineryRow()
+        {
+            var rowReset = new FrameRowControl(listView.rowSpace / 2);
+            listView.AddChidren(rowReset);
+            //閲嶇疆鐢垫満
+            rowReset.AddLeftCaption(Language.StringByID(R.MyInternationalizationString.uResetElectricalMachinery), 600);
+            //搴曠嚎
+            rowReset.AddBottomLine();
+            rowReset.ButtonClickEvent += (sender, e) =>
+            {
+                //閲嶇疆鐢垫満灏嗗垵濮嬪寲{0}鏂瑰悜涓庨檺浣嶈缃紝纭缁х画锛�
+                string msg = Language.StringByID(R.MyInternationalizationString.uResetElectricalMachineryMsg);
+                msg = msg.Replace("{0}", "\r\n");
+                this.ShowMassage(ShowMsgType.Confirm, msg, () =>
+                {
+                    //寮�鍚繘搴︽潯
+                    ProgressFormBar.Current.Start();
+                    //姝e湪閲嶇疆鐢垫満
+                    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;
+                        //閲嶆柊鍒濆鍖栫晫闈�
+                        this.InitMiddleFrame();
+                    });
+                });
+            };
+        }
+
+        #endregion
+
+        #region 鈻� 鍒濆鍖栫獥甯樻暟鎹甠____________________
+
+        /// <summary>
+        /// 鍒濆鍖栫獥甯樻暟鎹�
+        /// </summary>
+        /// <returns></returns>
+        private bool InitCurtainDefultData()
+        {
+            //寮�鍚繘搴︽潯
+            this.ShowProgressBar();
+
+            this.curtainData = new CurtainData();
+            this.receiveOpenlimit = false;
+            this.receiveCloseLimit = false;
+            this.sendDiv = 0;
+
+            int receiptDataCount = 0;
+            string mainkeys = LocalDevice.Current.GetDeviceMainKeys(curtainDevice);
+            HdlGatewayReceiveLogic.Current.AddAttributeEvent("CurtainDeviceAttribute", ReceiveComandDiv.A璁惧灞炴�т笂鎶�, (device) =>
+            {
+                string checkKey = LocalDevice.Current.GetDeviceMainKeys(device);
+                if (mainkeys != checkKey || device.DeviceStatusReport.CluterID != 258)
+                {
+                    return;
+                }
+                foreach (var attriBute in device.DeviceStatusReport.AttriBute)
+                {
+                    if (attriBute.AttributeId == 23)
+                    {
+                        //寮�鍚堝笜鏂瑰悜
+                        if (0 < (attriBute.AttriButeData & 0x01))
+                        {
+                            //鍙嶅悜
+                            curtainData.Direction = true;
+                        }
+                        else
+                        {
+                            //姝e悜
+                            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;
+                        receiptDataCount++;
+                    }
+                }
+            });
+            //鍙戦�佽幏鍙栫獥甯橀檺浣嶉厤缃殑鍛戒护
+            HdlDeviceCurtainLogic.Current.SetGetCurtainLimitSettionComand(curtainDevice);
+
+            int timeCount = 30;
+            while (receiptDataCount != 4 && timeCount >= 0)
+            {
+                System.Threading.Thread.Sleep(100);
+                timeCount--;
+            }
+            //鍏抽棴杩涘害鏉�
+            this.CloseProgressBar();
+
+            if (timeCount <= 0)
+            {
+                //鑾峰彇绐楀笜鏂瑰悜涓庨檺浣嶈缃け璐�
+                string msg = Language.StringByID(R.MyInternationalizationString.uGetCurtainDirectionAndLimitSettionFail);
+                //鎷兼帴涓娿�愮綉鍏冲洖澶嶈秴鏃躲�戠殑Msg
+                msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, null, "鍥炲瓒呮椂");
+                this.ShowMassage(ShowMsgType.Tip, msg);
+                return false;
+            }
+            //绉婚櫎鐩戝惉
+            HdlGatewayReceiveLogic.Current.RemoveEvent("CurtainDeviceAttribute");
+
+            //澶囦唤绐楀笜鏁版嵁
+            if (this.backupCurtainData == true && curtainData.CurtainLength > 0)
+            {
+                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);
+                });
+            }
+
+            return true;
+        }
+
+        #endregion
+
+        #region 鈻� 闄愪綅鏁版嵁鎺ユ敹_______________________
+
+        /// <summary>
+        /// 闄愪綅鏁版嵁鎺ユ敹
+        /// </summary>
+        private void ReceiveLimitData()
+        {
+            if (HdlGatewayReceiveLogic.Current.IsEsixt("ReceiveLimitData") == true)
+            {
+                HdlGatewayReceiveLogic.Current.RemoveEvent("ReceiveLimitData");
+            }
+            string mainkeys = LocalDevice.Current.GetDeviceMainKeys(curtainDevice);
+            HdlGatewayReceiveLogic.Current.AddAttributeEvent("ReceiveLimitData", ReceiveComandDiv.A璁惧灞炴�т笂鎶�, (device) =>
+            {
+                string checkKey = LocalDevice.Current.GetDeviceMainKeys(device);
+                if (mainkeys != checkKey || device.DeviceStatusReport.CluterID != 258)
+                {
+                    return;
+                }
+                foreach (var attriBute in device.DeviceStatusReport.AttriBute)
+                {
+                    //绐楀笜鐧惧垎姣旀帹閫�
+                    if (attriBute.AttributeId == 8)
+                    {
+                        //寮�闄愪綅
+                        if (sendDiv == 1)
+                        {
+                            receiveOpenlimit = true;
+                        }
+                        //鍚堥檺浣�
+                        else if (sendDiv == 2)
+                        {
+                            receiveCloseLimit = true;
+                        }
+                    }
+                }
+            });
+        }
+
+        #endregion
+
+        #region 鈻� 鐣岄潰鍏抽棴___________________________
+
+        /// <summary>
+        /// 鐣岄潰鍏抽棴
+        /// </summary>
+        public override void CloseFormBefore()
+        {
+            HdlGatewayReceiveLogic.Current.RemoveEvent("CurtainDeviceAttribute");
+            HdlGatewayReceiveLogic.Current.RemoveEvent("ReceiveLimitData");
+
+            base.CloseFormBefore();
+        }
+
+        #endregion
+
+        #region 鈻� 缁撴瀯浣揰____________________________
+
+        /// <summary>
+        /// 绐楀笜鏁版嵁
+        /// </summary>
+        private class CurtainData
+        {
+            /// <summary>
+            /// false:鐢垫満鏂瑰悜姝e悜锛泃rue:鐢垫満鏂瑰悜鍙嶅悜
+            /// </summary>
+            public bool Direction = false;
+            /// <summary>
+            /// 寮�闄愪綅鐨勫��
+            /// </summary>
+            public int OpenLimitValue = -1;
+            /// <summary>
+            /// 寮�闄愪綅鐨勭櫨鍒嗘瘮
+            /// </summary>
+            public int OpenLimitPersent = -1;
+            /// <summary>
+            /// 鍚堥檺浣嶇殑鍊�
+            /// </summary>
+            public int CloseLimitValue = -1;
+            /// <summary>
+            /// 鍚堥檺浣嶇殑鐧惧垎姣�
+            /// </summary>
+            public int CloseLimitPersent = -1;
+            /// <summary>
+            /// 绐楀笜鎬婚暱
+            /// </summary>
+            public int CurtainLength = -1;
+        }
+
+        #endregion
+    }
+}

--
Gitblit v1.8.0