From 9137222ece9b978eb97b5598f2eee6e070bcf9d6 Mon Sep 17 00:00:00 2001
From: JLChen <551775569@qq.com>
Date: 星期五, 28 二月 2020 15:22:16 +0800
Subject: [PATCH] 2020-02-28 更新

---
 Crabtree/SmartHome/UI/SimpleControl/Phone/Guide/GuideAddGateway.cs |  151 +++++++++++++++++++++++++++++++++++++++----------
 1 files changed, 119 insertions(+), 32 deletions(-)

diff --git a/Crabtree/SmartHome/UI/SimpleControl/Phone/Guide/GuideAddGateway.cs b/Crabtree/SmartHome/UI/SimpleControl/Phone/Guide/GuideAddGateway.cs
index 6d97bb6..e7792e0 100644
--- a/Crabtree/SmartHome/UI/SimpleControl/Phone/Guide/GuideAddGateway.cs
+++ b/Crabtree/SmartHome/UI/SimpleControl/Phone/Guide/GuideAddGateway.cs
@@ -322,7 +322,7 @@
                                         UserHomePage.FrameLayoutMain.AddChidren (UserMiddle.guidePageView);
                                         var guide = new GuideAddResidence ();
                                         UserMiddle.guidePageView.AddChidren (guide);
-                                        guide.ShowHomeList ();
+                                        guide.ShowHomeView ();
                                         UserMiddle.guidePageView.PageIndex = 0;
                                         //閲嶇疆涓哄姞瀵嗘ā寮�
                                         UserConfig.Instance.IsLocalEncrypt = true;
@@ -345,12 +345,16 @@
 
 
         static bool inThisView = false;
-        Alert checkInternetAlert = new Alert ("", "Your phone in not connected to WIFI network, please connet", "Close", "Search again");
-        Alert confirmAlert = new Alert ("", "Please make sure gateway is powered up and comect to WiFi router.", "Close", "Search again");
-        Alert confirmAlert1 = new Alert ("", "If not all the gateways are in the list,you can search again.", "Close", "Search again");
+        //Alert checkInternetAlert = new Alert ("", "Your phone in not connected to WIFI network, please connet", "Close", "Search again");
+        //Alert confirmAlert = new Alert ("", "Please make sure gateway is powered up and comect to WiFi router.", "Close", "Search again");
+        //Alert confirmAlert1 = new Alert ("", "If not all the gateways are in the list,you can search again.", "Close", "Search again");
+        //Alert wrongPasswordAlert = new Alert ("", ErrorCode.GatewayPasswordError, "Close", "Search again");
+
         void SearchGatewayList ()
         {
             if (UserConfig.Instance.internetStatus == 0 || UserConfig.Instance.internetStatus == 1) {
+                Alert checkInternetAlert = new Alert ("", "Your phone in not connected to WIFI network, please connet", "Close", "Search again");
+
                 checkInternetAlert.Show ();
 
                 checkInternetAlert.ResultEventHandler += (dsss, eee) => {
@@ -370,6 +374,7 @@
                     #region 鎼滅储璁惧
                     ////2020-01-14 榛樿鏄庢枃寮�濮嬫悳绱�
                     UserConfig.Instance.IsLocalEncrypt = false;
+                    UserConfig.Instance.EncryptedPasswordCorrect = true;
 
                     CommonPage.LocalPhoneFindDevice = true;
                     CommonPage.RandomHigh = (byte)new Random ().Next (255);
@@ -433,17 +438,15 @@
                         if (CommonPage.GateWayList.Count == 0) {
                             MainPage.Loading.Hide ();
                             if (this != null && this.Parent != null) {
-                                confirmAlert.Show ();
-                                confirmAlert.ResultEventHandler += (ddf, ddd) => {
-                                    MainPage.Loading.Hide ();
-                                    if (ddd) {
-                                        SearchGatewayList ();
-                                    }
-                                };
+                                ShowConfirmAlert ();
+                                
+                               
                             }
                         } else {
                             if (this != null && this.Parent != null) {
                                 if (inThisView) {// this.Parent.GetChildren (this.Parent.ChildrenCount - 1) == this) {
+                                    Alert confirmAlert1 = new Alert ("", "If not all the gateways are in the list,you can search again.", "Close", "Search again");
+
                                     confirmAlert1.Show ();
                                     confirmAlert1.ResultEventHandler += (ddf, ddd) => {
                                         MainPage.Loading.Hide ();
@@ -459,7 +462,49 @@
             }) { IsBackground = true }.Start ();
         }
 
+        /// <summary>
+        /// 鎻愮ず
+        /// Please make sure gateway is powered up and comect to WiFi router.
+        /// 鎴栬��
+        /// 
+        /// </summary>
+        static void ShowConfirmAlert () {
+            if (UserConfig.Instance.IsLocalEncrypt) {
+                //瀵嗙爜妫�楠屾纭�
+                if (UserConfig.Instance.EncryptedPasswordCorrect) {
+                    Alert confirmAlert = new Alert ("", "Please make sure gateway is powered up and comect to WiFi router.", "Close", "Search again");
+                    confirmAlert.Show ();
+                    confirmAlert.ResultEventHandler += (ddf, ddd) => {
+                        MainPage.Loading.Hide ();
+                        if (ddd) {
+                            inView.SearchGatewayList ();
+                        }
+                    };
+                } else {
+                    Alert wrongPasswordAlert = new Alert ("", ErrorCode.GatewayPasswordError, "Close", "Search again");
+                    wrongPasswordAlert.Show ();
+                    wrongPasswordAlert.ResultEventHandler += (ddf, ddd) => {
+                        MainPage.Loading.Hide ();
+                        if (ddd) {
+                            inView.SearchGatewayList ();
+                        }
+                    };
 
+                }
+            } else {
+                Alert confirmAlert = new Alert ("", "Please make sure gateway is powered up and comect to WiFi router.", "Close", "Search again");
+                confirmAlert.Show ();
+                confirmAlert.ResultEventHandler += (ddf, ddd) => {
+                    MainPage.Loading.Hide ();
+                    if (ddd) {
+                        inView.SearchGatewayList ();
+                    }
+                };
+
+            }
+           
+
+        }
 
 
         //static byte [] AseKeyBytes;
@@ -486,11 +531,11 @@
         /// </summary>
         /// <param name="backBytes"></param>
         /// <returns></returns>
-        static bool CheckIsSuccessfulWithBytes (byte [] backBytes)
+        static bool CheckIsSuccessfulWithBytes (byte [] backBytes, string errorStr = "Modify gateway configuration failed,please try again!")
         {
             if (backBytes == null) {
                 Application.RunOnMainThread (() => {
-                    new Alert ("", Language.StringByID (R.MyInternationalizationString.TipEquipmentNotOnline),
+                    new Alert ("", ErrorCode.GatewayNoResponse,
                                Language.StringByID (R.MyInternationalizationString.Close)).Show ();
                 });
                 return false;
@@ -498,7 +543,7 @@
                 return true;
             } else {
                 Application.RunOnMainThread (() => {
-                    new Alert ("", Language.StringByID (R.MyInternationalizationString.OperationFailed),
+                    new Alert ("", errorStr,
                                Language.StringByID (R.MyInternationalizationString.Close)).Show ();
                 });
                 return false;
@@ -532,19 +577,19 @@
             });
 
             bool goNext = false;
-            if (!UserConfig.Instance.IsLocalEncrypt) {
-                //濡傛灉娌″姞瀵嗭紝璧颁慨鏀瑰姞瀵嗘柟娉�
-                var result = SetGateWayLocalEncryption (common);
-                if (!result) {
-                    MainPage.LoadingHide ();
-                    return result;//淇敼澶辫触 杩斿洖goNext false
-                }
-                //淇敼鎴愬姛,璁剧疆鏈湴涓哄姞瀵嗘柟寮�
-                UserConfig.Instance.IsLocalEncrypt = true;
-                //string aseKeyStr = CommonPage.MyEncodingUTF8.GetString (AseKeyBytes);
-                //UserConfig.Instance.LocalEncryptKey = aseKeyStr;
-                System.Console.WriteLine ($"============>LocalEncryptKey 鍔犲瘑鎴愬姛Key涓猴細{UserConfig.Instance.LocalEncryptKey}");
-            }
+            //if (!UserConfig.Instance.IsLocalEncrypt) {
+            //    //濡傛灉娌″姞瀵嗭紝璧颁慨鏀瑰姞瀵嗘柟娉�
+            //    var result = SetGateWayLocalEncryption (common);
+            //    if (!result) {
+            //        MainPage.LoadingHide ();
+            //        return result;//淇敼澶辫触 杩斿洖goNext false
+            //    }
+            //    //淇敼鎴愬姛,璁剧疆鏈湴涓哄姞瀵嗘柟寮�
+            //    UserConfig.Instance.IsLocalEncrypt = true;
+            //    //string aseKeyStr = CommonPage.MyEncodingUTF8.GetString (AseKeyBytes);
+            //    //UserConfig.Instance.LocalEncryptKey = aseKeyStr;
+            //    System.Console.WriteLine ($"============>LocalEncryptKey 鍔犲瘑鎴愬姛Key涓猴細{UserConfig.Instance.LocalEncryptKey}");
+            //}
 
             var backBytes = Control.ControlBytesSendHasReturn (Command.Read_APP_Data_STORE_1D5C_CMD, common.SubnetID, common.DeviceID, new byte [] { });
           
@@ -552,9 +597,8 @@
                 Application.RunOnMainThread (() => {
                     new Alert ("", "No response from gateway. Please make sure the gateway is online and its firmware is up to date.", Language.StringByID (R.MyInternationalizationString.Close)).Show ();
                 });
+               
             }
-
-            MainPage.LoadingHide ();
 
             if (backBytes.Length >= 37) {
                 //******************浣忓畢ID string绫诲瀷*************
@@ -565,19 +609,62 @@
                 //2020-01-12
                 backIDStr = backIDStr.Replace ("\0", "");
                 if (enable || backIDStr == UserConfig.Instance.CurrentRegion.Id || string.IsNullOrEmpty (backIDStr)) {
+                   
+
+                    if (!UserConfig.Instance.IsLocalEncrypt) {
+                        //濡傛灉娌″姞瀵嗭紝璧颁慨鏀瑰姞瀵嗘柟娉�
+                        var result = SetGateWayLocalEncryption (common);
+                        if (!result) {
+                            Application.RunOnMainThread (() => {
+                                MainPage.Loading.Hide ();
+                                new Alert ("", "Encryption gateway failed, please try again.", Language.StringByID (R.MyInternationalizationString.Close)).Show ();
+
+                            });
+                          
+                            return result;//淇敼澶辫触 杩斿洖goNext false
+                        }
+                        //淇敼鎴愬姛,璁剧疆鏈湴涓哄姞瀵嗘柟寮�
+                        UserConfig.Instance.IsLocalEncrypt = true;
+                        //System.Console.WriteLine ($"============>LocalEncryptKey 鍔犲瘑鎴愬姛Key涓猴細{UserConfig.Instance.LocalEncryptKey}");
+                    }
                     goNext = true;
+
                 } else {
-                    Application.RunOnMainThread (() => {
-                        new Alert ("", ErrorCode.UnableToBindGateway, Language.StringByID (R.MyInternationalizationString.Close)).Show ();
-                    });
+                    UnableToBindGatewayAlertShow ();
                 }
             } else {
                 Application.RunOnMainThread (() => {
                     new Alert ("", ErrorCode.GatewayVersionLow, Language.StringByID (R.MyInternationalizationString.Close)).Show ();
                 });
             }
+            MainPage.LoadingHide ();
             return goNext;
 
         }
+
+
+        static void UnableToBindGatewayAlertShow ()
+        {
+            if (inView == null)
+                return;
+            Application.RunOnMainThread (() => {
+
+                //if (this != null && this.Parent != null) {
+                var alter = new Alert ("", ErrorCode.UnableToBindGateway, Language.StringByID (R.MyInternationalizationString.Close));
+                alter.ResultEventHandler += (sender1, e1) => {
+                    if (e1) {
+                        if (inView == null)
+                            return;
+                        //閲嶇疆涓哄姞瀵嗘ā寮�
+                        UserConfig.Instance.IsLocalEncrypt = true;
+                        (inView.Parent as PageLayout).PageIndex -= 1;
+                    }
+                };
+                alter.Show ();
+                //}
+
+            });
+
+        }
     }
 }
\ No newline at end of file

--
Gitblit v1.8.0