From 48ba446936b51fffafa7c3600c0dadc6ac0e8c20 Mon Sep 17 00:00:00 2001
From: 陈嘉乐 <cjl@hdlchina.com.cn>
Date: 星期五, 10 七月 2020 10:52:13 +0800
Subject: [PATCH] 2020-07-10-01

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

diff --git a/ZigbeeApp/Shared/Phone/UserCenter/Device/Curtain/AutoOpenDirectionAndLimitSettionForm.cs b/ZigbeeApp/Shared/Phone/UserCenter/Device/Curtain/AutoOpenDirectionAndLimitSettionForm.cs
index 38eaf8a..2bc736f 100755
--- a/ZigbeeApp/Shared/Phone/UserCenter/Device/Curtain/AutoOpenDirectionAndLimitSettionForm.cs
+++ b/ZigbeeApp/Shared/Phone/UserCenter/Device/Curtain/AutoOpenDirectionAndLimitSettionForm.cs
@@ -61,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;
 
@@ -99,6 +99,24 @@
                 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
                 {
                     //娣诲姞鏂瑰悜琛�
@@ -124,7 +142,7 @@
                         //璁惧寮傚父琛ユ晳 -> 娣诲姞閲嶇疆鐢垫満琛�
                         this.AddElectricalMachineryRow();
                     }
-                    catch (Exception ex2) { HdlLogLogic.Current.WriteLog(ex2, "寮�鍚堝笜琛ユ晳寮傚父"); }
+                    catch (Exception ex2) { HdlLogLogic.Current.WriteLog(ex2, "寮�鍚堝笜琛ユ晳寮傚父2"); }
                 }
             });
         }
@@ -159,10 +177,10 @@
 
                 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;
@@ -234,6 +252,8 @@
             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;
@@ -316,7 +336,8 @@
             frameBack.AddChidren(btnSave);
             btnSave.ButtonClickEvent += (sender, e) =>
             {
-                if (this.receiveOpenlimit == true)
+                //2020.05.17:杩藉姞铏氭嫙浣忓畢鍙互鐩存帴鐐瑰嚮
+                if (this.receiveOpenlimit == true || Common.Config.Instance.Home.IsVirtually == true)
                 {
                     //纭寮�闄愪綅鐐�
                     this.SaveOpenLimit();
@@ -336,27 +357,28 @@
                 //鏁版嵁鍙樻洿,鐧惧垎姣�
                 curtainData.OpenLimitPersent = value;
             };
+            //铏氭嫙浣忓畢涓嶉渶瑕佺洃鍚�
+            if (Common.Config.Instance.Home.IsVirtually == true)
+            {
+                return;
+            }
 
             HdlThreadLogic.Current.RunThread(async () =>
             {
-                //澶勭悊涓�
-                bool checking = false;
                 while (openSeekBar.Parent != null)
                 {
                     int nowValue = curtainData.OpenLimitPersent;
-                    if (oldProValue == nowValue || checking == true)
+                    if (oldProValue == nowValue)
                     {
                         //鍊间笉绛夋墠澶勭悊
                         await Task.Delay(500);
                         continue;
                     }
                     oldProValue = nowValue;
-                    checking = true;
 
                     //灏嗙獥甯樿皟鏁村埌鎸囧畾鐧惧垎姣�
                     this.sendDiv = 1;
                     curtainDevice.WcdGoToTiltValue(nowValue);
-                    checking = false;
                 }
             });
         }
@@ -368,15 +390,14 @@
         {
             //纭褰撳墠浣嶇疆涓哄紑闄愪綅?
             string msg = Language.StringByID(R.MyInternationalizationString.uCommitCurtainOpenLimitMsg);
-            this.ShowMassage(ShowMsgType.Confirm, msg, async () =>
+            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 = await HdlDeviceCurtainLogic.Current.CommitCurtainLimitPoint(curtainDevice, Rollershade.CurtainPrivateInstalledLimi.UpLimit,
-                    (int)openValue, (int)closeValue);
+                var result = HdlDeviceCurtainLogic.Current.SetAutoOpenCurtainLimitPoint(curtainDevice, (int)openValue, (int)closeValue, curtainData.CurtainLength);
                 if (result == true)
                 {
                     this.receiveOpenlimit = false;
@@ -404,6 +425,8 @@
             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;
@@ -486,7 +509,8 @@
             frameBack.AddChidren(btnSave);
             btnSave.ButtonClickEvent += (sender, e) =>
             {
-                if (this.receiveCloseLimit == true)
+                //2020.05.17:杩藉姞铏氭嫙浣忓畢鍙互鐩存帴鐐瑰嚮
+                if (this.receiveCloseLimit == true || Common.Config.Instance.Home.IsVirtually == true)
                 {
                     //淇濆瓨鍚堥檺浣嶇偣
                     this.SaveCloseLimit();
@@ -506,27 +530,28 @@
                 //鏁版嵁鍙樻洿,鐧惧垎姣�
                 curtainData.CloseLimitPersent = value;
             };
+            //铏氭嫙浣忓畢涓嶉渶瑕佺洃鍚�
+            if (Common.Config.Instance.Home.IsVirtually == true)
+            {
+                return;
+            }
 
             HdlThreadLogic.Current.RunThread(async () =>
             {
-                //澶勭悊涓�
-                bool checking = false;
                 while (closeSeekBar.Parent != null)
                 {
                     int nowValue = curtainData.CloseLimitPersent;
-                    if (oldProValue == nowValue || checking == true)
+                    if (oldProValue == nowValue)
                     {
                         //鍊间笉绛夋墠澶勭悊
                         await Task.Delay(500);
                         continue;
                     }
-                    checking = true;
                     oldProValue = nowValue;
 
                     //灏嗙獥甯樿皟鏁村埌鎸囧畾鐧惧垎姣�
                     this.sendDiv = 2;
                     curtainDevice.WcdGoToTiltValue(nowValue);
-                    checking = false;
                 }
             });
         }
@@ -538,15 +563,14 @@
         {
             //纭褰撳墠浣嶇疆涓哄悎闄愪綅?
             string msg = Language.StringByID(R.MyInternationalizationString.uCommitCurtainCloseLimitMsg);
-            this.ShowMassage(ShowMsgType.Confirm, msg, async () =>
+            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 = await HdlDeviceCurtainLogic.Current.CommitCurtainLimitPoint(curtainDevice, Rollershade.CurtainPrivateInstalledLimi.DownLimit,
-                    (int)openValue, (int)closeValue);
+                var result = HdlDeviceCurtainLogic.Current.SetAutoOpenCurtainLimitPoint(curtainDevice, (int)openValue, (int)closeValue, curtainData.CurtainLength);
 
                 if (result == true)
                 {
@@ -572,6 +596,11 @@
             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");
@@ -629,15 +658,26 @@
         /// <returns></returns>
         private bool InitCurtainDefultData()
         {
-            //寮�鍚繘搴︽潯
-            this.ShowProgressBar();
-
             this.curtainData = new CurtainData();
             this.receiveOpenlimit = false;
             this.receiveCloseLimit = false;
             this.sendDiv = 0;
 
-            bool receiptData = false;
+            //濡傛灉褰撳墠鏄櫄鎷熶綇瀹�
+            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();
+
+            int receiptDataCount = 0;
             string mainkeys = LocalDevice.Current.GetDeviceMainKeys(curtainDevice);
             HdlGatewayReceiveLogic.Current.AddAttributeEvent("CurtainDeviceAttribute", ReceiveComandDiv.A璁惧灞炴�т笂鎶�, (device) =>
             {
@@ -661,23 +701,25 @@
                             //姝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;
-                        //鏁版嵁鎺ユ敹缁撴潫
-                        receiptData = true;
+                        receiptDataCount++;
                     }
                 }
             });
@@ -685,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--;
@@ -704,21 +746,6 @@
             }
             //绉婚櫎鐩戝惉
             HdlGatewayReceiveLogic.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);
-                });
-            }
 
             return true;
         }
@@ -775,8 +802,6 @@
         {
             HdlGatewayReceiveLogic.Current.RemoveEvent("CurtainDeviceAttribute");
             HdlGatewayReceiveLogic.Current.RemoveEvent("ReceiveLimitData");
-
-            UserView.HomePage.Instance.ScrollEnabled = true;
 
             base.CloseFormBefore();
         }

--
Gitblit v1.8.0