From 944b87b6bcccb095cd73f13f4410fb20faf48f74 Mon Sep 17 00:00:00 2001
From: gxc <guoxuecheng@guoxuechengdeMacBook-Pro.local>
Date: 星期三, 25 十二月 2019 11:21:06 +0800
Subject: [PATCH] 2019.12.25

---
 ZigbeeApp/Shared/Phone/UserCenter/Gateway/Add/WiredGatewaySearchForm.cs |  160 +++++++++++++++++++++++++----------------------------
 1 files changed, 76 insertions(+), 84 deletions(-)

diff --git a/ZigbeeApp/Shared/Phone/UserCenter/Gateway/Add/WiredGatewaySearchForm.cs b/ZigbeeApp/Shared/Phone/UserCenter/Gateway/Add/WiredGatewaySearchForm.cs
index dd788ba..89680e3 100755
--- a/ZigbeeApp/Shared/Phone/UserCenter/Gateway/Add/WiredGatewaySearchForm.cs
+++ b/ZigbeeApp/Shared/Phone/UserCenter/Gateway/Add/WiredGatewaySearchForm.cs
@@ -29,6 +29,10 @@
         /// 鑾峰彇寰楀埌浜嗘柊缃戝叧
         /// </summary>
         private bool newGatewayGetting = false;
+        /// <summary>
+        /// 缃戝叧妫�娴嬩腑
+        /// </summary>
+        private string isGatewayChecking = "0";
 
         #endregion
 
@@ -111,7 +115,7 @@
             btnMsg1.Y = picGwImage.Bottom + Application.GetRealHeight(112);
             btnMsg1.TextID = R.MyInternationalizationString.uSearchGatewayFailMsg1;
             bodyFrameLayout.AddChidren(btnMsg1);
-            //1.闀挎寜ZB/RST閿�20绉掞紝缃戝叧鎭㈠鍑哄巶璁剧疆锛屾寚绀虹伅鍏ㄩ儴鐔剓0}鐏悗锛岄噸鏂板叆缃戙��
+            //1.闀挎寜ZB/RST閿�20绉掞紝缃戝叧鎭㈠鍑哄巶璁剧疆锛屾寚绀虹伅鍏ㄩ儴鐔勭伃鍚庯紝閲嶆柊鍏ョ綉銆�
             var btnMsg2 = new NormalViewControl(930, 100, true);
             btnMsg2.X = Application.GetRealWidth(75);
             btnMsg2.Y = btnMsg1.Bottom + Application.GetRealHeight(35);
@@ -120,7 +124,7 @@
             btnMsg2.TextColor = UserCenterColor.Current.TextGrayColor1;
             btnMsg2.IsMoreLines = true;
             bodyFrameLayout.AddChidren(btnMsg2);
-            //2.鐐规寜HID/WCFG閿紝杩涘叆缃戝叧鎹㈢粦妯″紡锛岀郴缁熸寚绀虹伅蹇棯{0}5绉掋��
+            //2.鐐规寜HID/WCFG閿紝杩涘叆缃戝叧鎹㈢粦妯″紡锛岀郴缁熸寚绀虹伅蹇棯5绉掋��
             var btnMsg3 = new NormalViewControl(930, 100, true);
             btnMsg3.X = Application.GetRealWidth(75);
             btnMsg3.Y = btnMsg2.Bottom + Application.GetRealHeight(12);
@@ -173,6 +177,11 @@
             var btnGoBack = new BottomClickButton(688);
             btnGoBack.Y = Application.GetRealHeight(1495);
             btnGoBack.TextID = R.MyInternationalizationString.uGobackGatewayManage;
+            if (UserCenterResourse.DicActionForm.ContainsKey("GatewayListForm") == false)
+            {
+                //杩斿洖涓婚〉
+                btnGoBack.TextID = R.MyInternationalizationString.uGobackToHomePage;
+            }
             bodyFrameLayout.AddChidren(btnGoBack);
             btnGoBack.ButtonClickEvent += (sender, e) =>
             {
@@ -214,7 +223,7 @@
             picGwImage.AddChidren(btnRound);
 
             string strMsg = btnMsg.Text;
-            HdlThreadLogic.Current.RunThread(async () =>
+            HdlThreadLogic.Current.RunThread(() =>
             {
                 //娓呯┖鍏ㄩ儴鍒楄〃
                 HdlGatewayLogic.Current.ClearAllRealGateway();
@@ -229,8 +238,22 @@
                     maxCount--;
                     if (maxCount % 4 == 0)
                     {
-                        //姣�2绉掓娴嬫悳绱㈠埌鐨勭綉鍏�
-                        await this.CheckZbGatewayAndSetRow();
+                        lock(isGatewayChecking)
+                        {
+                            if (isGatewayChecking != "1")
+                            {
+                                isGatewayChecking = "1";
+                                HdlThreadLogic.Current.RunThread(async () =>
+                                {
+                                    //姣�2绉掓娴嬫悳绱㈠埌鐨勭綉鍏�
+                                    await this.CheckZbGatewayAndSetRow();
+                                    lock (isGatewayChecking)
+                                    {
+                                        isGatewayChecking = "0";
+                                    }
+                                });
+                            }
+                        }
                     }
                     if (this.newGatewayGetting == true)
                     {
@@ -265,12 +288,15 @@
                         this.InitFailMiddleFrame();
                     });
                 }
-                else
+                else if (newGatewayGetting == true)
                 {
                     HdlThreadLogic.Current.RunMain(() =>
                     {
-                        var form = new WiredGatewayListForm();
-                        this.AddFromAndRemoveNowForm(form, listZbGateway, dicZbGatewayDiv);
+                        if (this.Parent != null)
+                        {
+                            var form = new GatewayManage.GatewaySearchListForm();
+                            this.AddFromAndRemoveNowForm(form, listZbGateway, dicZbGatewayDiv);
+                        }
                     });
                 }
             });
@@ -288,8 +314,7 @@
             List<string> listId = new List<string>();
             for (int i = 0; i < ZbGateway.GateWayList.Count; i++)
             {
-                string strip = HdlGatewayLogic.Current.GetGatewayBaseInfoAttribute(ZbGateway.GateWayList[i], "IpAddress").ToString();
-                if (strip == string.Empty)
+                if (ZbGateway.GateWayList[i].getGatewayBaseInfo.IpAddress == string.Empty)
                 {
                     //IP娌℃湁鐨勭綉鍏筹紝鎴戜篃涓嶇煡閬撳畠鏄共鍢涚殑
                     continue;
@@ -321,94 +346,61 @@
                 {
                     continue;
                 }
-                //鏀堕泦缃戝叧瀵硅薄
-                this.listZbGateway.Add(way);
 
                 //缃戝叧缁戝畾妯″紡
                 GatewayBindMode mode = GatewayBindMode.BindAgain;
-                if (HdlGatewayLogic.Current.HomeIdIsEmpty(way) == true)
+                //濡傛灉鏄涓�娆$粦瀹�,鎴栬�呮槸浠ュ墠宸茬粡缁戝畾杩囦簡鐨�
+                if (HdlGatewayLogic.Current.HomeIdIsEmpty(way) == true
+                    || way.getGatewayBaseInfo.HomeId == Common.Config.Instance.HomeId)
                 {
-                    //绗竴娆$粦瀹�,涔熷氨鏄綉鍏充綇瀹匢D涓虹┖
-                    mode = GatewayBindMode.First;
-                    this.dicZbGatewayDiv[listId[i]] = 0;
-                    //鑾峰彇鍒颁簡鏂扮綉鍏�
-                    this.newGatewayGetting = true;
-                }
-                else if (way.getGatewayBaseInfo.HomeId == Common.Config.Instance.HomeId)
-                {
-                    //宸茬粡缁戝畾杩囦簡
-                    this.dicZbGatewayDiv[listId[i]] = 1;
-                    mode = GatewayBindMode.Binded;
-                }
-                else
-                {
-                    //闇�瑕佹崲缁�
-                    this.dicZbGatewayDiv[listId[i]] = 2;
-                    mode = GatewayBindMode.BindAgain;
-                }
-                //鏈湴鏄惁鏈夎繖涓綉鍏�
-                bool isExist = HdlGatewayLogic.Current.IsGatewayExist(way);
-                //濡傛灉
-                if (mode != GatewayBindMode.BindAgain)
-                {
+                    if (way.getGatewayBaseInfo.HomeId != Common.Config.Instance.HomeId)
+                    {
+                        //绗竴娆$粦瀹�,涔熷氨鏄綉鍏充綇瀹匢D涓虹┖
+                        mode = GatewayBindMode.First;
+                    }
+                    else
+                    {
+                        //宸茬粡缁戝畾杩囦簡
+                        mode = GatewayBindMode.Binded;
+                    }
+
                     //娣诲姞鎼滅储鍒扮殑缃戝叧鍒扮紦瀛�(鎵ц缃戝叧淇濆瓨鎿嶄綔)
                     ShowErrorMode showMode = this.dicIdCheckCount[listId[i]] == 0 ? ShowErrorMode.YES : ShowErrorMode.NO;
-                    var result = await this.DoSaveGateway(way, showMode);
+                    var result = await HdlGatewayLogic.Current.AddNewGateway(way, ShowErrorMode.NO);
                     if (result == false)
                     {
                         continue;
                     }
                 }
+                //鏀堕泦缃戝叧瀵硅薄
+                this.listZbGateway.Add(way);
+
                 //濡傛灉瀹冨凡缁忓畬鍏ㄦ垚鍔熶簡鐨勮瘽锛屽垯灏嗗畠鐨勫墿浣欐鏁扮疆闆�
                 this.dicIdCheckCount[listId[i]] = 0;
-                if (isExist == true)
+                //鍏ㄩ儴澶勭悊OK鍚庯紝鎵嶈兘璁剧疆flage
+                if (mode == GatewayBindMode.First)
                 {
-                    //宸茬粡缁戝畾杩囦簡鐨勶紝鍒欎笉鍐嶆樉绀�
-                    continue;
+                    //绗竴娆$粦瀹�
+                    this.dicZbGatewayDiv[listId[i]] = 0;
+                    //鑾峰彇鍒颁簡鏂扮綉鍏�
+                    this.newGatewayGetting = true;
                 }
-                if (mode != GatewayBindMode.BindAgain)
+                else if (mode == GatewayBindMode.Binded)
+                {
+                    //宸茬粡缁戝畾杩�
+                    this.dicZbGatewayDiv[listId[i]] = 1;
+                }
+                else
+                {
+                    //闇�瑕侀噸鏂扮粦瀹�
+                    this.dicZbGatewayDiv[listId[i]] = 2;
+                }
+
+                if (mode == GatewayBindMode.First)
                 {
                     //鎴戣寰楄繖閲岄渶瑕佽幏鍙栦竴涓嬫柊缃戝叧鐨勮澶囧垪琛�
-                    await Common.LocalDevice.Current.SetDeviceToMemmoryByGateway(way);
+                    Common.LocalDevice.Current.SetDeviceToMemmoryByGateway(way);
                 }
-            }
-            return true;
-        }
-
-        #endregion
-
-        #region 鈻� 鎵ц缃戝叧淇濆瓨_______________________
-
-        /// <summary>
-        /// 鎵ц缃戝叧淇濆瓨
-        /// </summary>
-        /// <param name="zbGateway">缃戝叧瀵硅薄</param>
-        /// <param name="mode">鏄惁鏄剧ず閿欒</param>
-        /// <returns></returns>
-        private async Task<bool> DoSaveGateway(ZbGateway zbGateway, ShowErrorMode mode)
-        {
-            //娣诲姞鎼滅储鍒扮殑缃戝叧鍒扮紦瀛�
-            //1:姝e父  -1:寮傚父  0:褰撳墠鐨勭綉鍏崇粦瀹氬湪浜嗗綋鍓嶈处鍙蜂笅鐨勪笉鍚屼綇瀹呴噷闈�
-            int result = await HdlGatewayLogic.Current.AddNewGateway(zbGateway, mode);
-            if (result == -1)
-            {
-                return false;
-            }
-
-            //鍓嶇殑缃戝叧缁戝畾鍦ㄤ簡褰撳墠璐﹀彿涓嬬殑涓嶅悓浣忓畢閲岄潰
-            if (result == 0)
-            {
-                if (mode == ShowErrorMode.YES)
-                {
-                    //缃戝叧缁戝畾鍦ㄥ綋鍓嶈处鍙蜂笅鐨勫叾浠栦綇瀹呴噷\r\n璇疯В闄ょ粦瀹氬悗鍐嶈瘯
-                    string msg = Language.StringByID(R.MyInternationalizationString.uTheGatewayInOtherResidenceMsg);
-                    if (msg.Contains("{0}") == true)
-                    {
-                        msg = string.Format(msg, "\r\n");
-                    }
-                    this.ShowMassage(ShowMsgType.Tip, msg);
-                }
-                return false;
             }
             return true;
         }
@@ -420,7 +412,7 @@
         /// <summary>
         /// 鐢婚潰鍏抽棴
         /// </summary>
-        public override void CloseForm()
+        public override void CloseFormBefore()
         {
             ZigBee.Common.Application.IsSearchingGateway = false;
             //鏂紑娌℃湁鎵ц缁戝畾鐨勭綉鍏崇殑mqtt
@@ -437,16 +429,16 @@
                 foreach (var way in list)
                 {
                     ZbGateway.GateWayList.RemoveAll((obj) => HdlGatewayLogic.Current.GetGatewayId(obj) == HdlGatewayLogic.Current.GetGatewayId(way));
-                    way.DisConnect("Search");
+                    way.DisConnectLocalMqttClient("Search");
                 }
             }
-            if (UserCenterResourse.listActionFormId.Contains("GatewayManagementForm") == false)
+            if (UserCenterResourse.listActionFormId.Contains("UserMainForm") == false)
             {
                 //鍒锋柊涓婚〉
                 UserView.UserPage.Instance.Fresh();
             }
 
-            base.CloseForm();
+            base.CloseFormBefore();
         }
 
         #endregion

--
Gitblit v1.8.0