JLChen
2021-01-06 f60ce72c3c29c7d31a046795c88ec39a69e73d45
Crabtree/SmartHome/UI/SimpleControl/Phone/Guide/GuideAddGateway.cs
@@ -83,10 +83,11 @@
            etRemark.EditorEnterAction += (obj) => {
                Application.HideSoftInput ();
            };
            if (MainPage.LoginUser.AccountType == 1) {
                etRemark.Enable = false;
                etRemark.BorderWidth = 0;
            }
            //if (MainPage.LoginUser.AccountType == 1) {
            //    etRemark.Enable = false;
            //    etRemark.BorderWidth = 0;
            //}
            var BottomView = new FrameLayout () {
                Y = Application.GetRealHeight (400 - 88),
@@ -303,7 +304,7 @@
                            goNext = CheckIfGoNext (common);
                         
                        } catch (Exception ex) {
                            Console.WriteLine (ex.Message);
                            Utlis.WriteLine (ex.Message);
                        } finally {
                            Application.RunOnMainThread (() => {
                                MainPage.Loading.Hide ();
@@ -312,17 +313,17 @@
                                    CommonPage.FindGatewayChilrenIPAddress = common.IPAddress;
                                    inThisView = false;
                                    if (inView != null) {
                                        Console.WriteLine ("inView != null");
                                        Utlis.WriteLine ("inView != null");
                                        var deviceListView = new GuideSettingGateway (common);
                                        (inView.Parent as PageLayout).AddChidren (deviceListView);
                                        deviceListView.ShowPage ();
                                        (inView.Parent as PageLayout).PageIndex = (inView.Parent as PageLayout).ChildrenCount - 1;
                                    } else {
                                        Console.WriteLine ("inView == null");
                                        Utlis.WriteLine ("inView == null");
                                        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,14 +346,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 wrongPasswordAlert = new Alert ("", ErrorCode.GatewayPasswordError, "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 ("", ErrorCode.NotConnectedToWIFI, "Close", "Search again");
                checkInternetAlert.Show ();
                checkInternetAlert.ResultEventHandler += (dsss, eee) => {
@@ -401,7 +404,7 @@
                        }
                        Control control = new Control ();
                        Console.WriteLine ("组播搜索网关,搜索地址是:" + CommonPage.EndPoint.ToString () + "    " + CommonPage.GateWayList.Count);
                        Utlis.WriteLine ("组播搜索网关,搜索地址是:" + CommonPage.EndPoint.ToString () + "    " + CommonPage.GateWayList.Count);
                        control.Send (new Target () {
                            IPEndPoint = CommonPage.EndPoint,
                            Command = Command.ReadGateway,
@@ -410,7 +413,7 @@
                            AddData = ms.ToArray ()
                        }, SendCount.Zero, false);
                        Console.WriteLine ("广播搜索网关,搜索地址是:" + new Net.NetWiFi ().BroadcastIpAddress.ToString () + "    " + CommonPage.GateWayList.Count);
                        Utlis.WriteLine ("广播搜索网关,搜索地址是:" + new Net.NetWiFi ().BroadcastIpAddress.ToString () + "    " + CommonPage.GateWayList.Count);
                        control.Send (new Target () {
                            IPEndPoint = new System.Net.IPEndPoint (new Net.NetWiFi ().BroadcastIpAddress, 6000),
                            Command = Command.ReadGateway,
@@ -430,7 +433,7 @@
                    CommonPage.LocalPhoneFindDevice = false;
                    #endregion
                } catch (Exception ex) {
                    Console.WriteLine (ex.ToString ());
                    Utlis.WriteLine (ex.ToString ());
                } finally {
                    Application.RunOnMainThread (() => {
                        if (CommonPage.GateWayList.Count == 0) {
@@ -443,6 +446,8 @@
                        } else {
                            if (this != null && this.Parent != null) {
                                if (inThisView) {// this.Parent.GetChildren (this.Parent.ChildrenCount - 1) == this) {
                                    Alert confirmAlert1 = new Alert ("", ErrorCode.IfAllTheGatewaysAreNotInTheList, "Close", "Search again");
                                    confirmAlert1.Show ();
                                    confirmAlert1.ResultEventHandler += (ddf, ddd) => {
                                        MainPage.Loading.Hide ();
@@ -468,19 +473,18 @@
            if (UserConfig.Instance.IsLocalEncrypt) {
                //密码检验正确
                if (UserConfig.Instance.EncryptedPasswordCorrect) {
                    inView.confirmAlert.Show ();
                    inView.confirmAlert.ResultEventHandler += (ddf, ddd) => {
                    Alert confirmAlert = new Alert ("", ErrorCode.MakeSureGatewayIsPoweredUp, "Close", "Search again");
                    confirmAlert.Show ();
                    confirmAlert.ResultEventHandler += (ddf, ddd) => {
                        MainPage.Loading.Hide ();
                        if (ddd) {
                            inView.SearchGatewayList ();
                        }
                    };
                } else {
                    inView.wrongPasswordAlert.Show ();
                    inView.wrongPasswordAlert.ResultEventHandler += (ddf, ddd) => {
                    Alert wrongPasswordAlert = new Alert ("", ErrorCode.GatewayPasswordError, "Close", "Search again");
                    wrongPasswordAlert.Show ();
                    wrongPasswordAlert.ResultEventHandler += (ddf, ddd) => {
                        MainPage.Loading.Hide ();
                        if (ddd) {
                            inView.SearchGatewayList ();
@@ -489,8 +493,9 @@
                }
            } else {
                inView.confirmAlert.Show ();
                inView.confirmAlert.ResultEventHandler += (ddf, ddd) => {
                Alert confirmAlert = new Alert ("", ErrorCode.MakeSureGatewayIsPoweredUp, "Close", "Search again");
                confirmAlert.Show ();
                confirmAlert.ResultEventHandler += (ddf, ddd) => {
                    MainPage.Loading.Hide ();
                    if (ddd) {
                        inView.SearchGatewayList ();
@@ -527,11 +532,11 @@
        /// </summary>
        /// <param name="backBytes"></param>
        /// <returns></returns>
        static bool CheckIsSuccessfulWithBytes (byte [] backBytes, string errorStr = "Modify gateway configuration failed!")
        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;
@@ -584,7 +589,7 @@
            //    UserConfig.Instance.IsLocalEncrypt = true;
            //    //string aseKeyStr = CommonPage.MyEncodingUTF8.GetString (AseKeyBytes);
            //    //UserConfig.Instance.LocalEncryptKey = aseKeyStr;
            //    System.Console.WriteLine ($"============>LocalEncryptKey 加密成功Key为:{UserConfig.Instance.LocalEncryptKey}");
            //    Utlis.WriteLine ($"============>LocalEncryptKey 加密成功Key为:{UserConfig.Instance.LocalEncryptKey}");
            //}
            var backBytes = Control.ControlBytesSendHasReturn (Command.Read_APP_Data_STORE_1D5C_CMD, common.SubnetID, common.DeviceID, new byte [] { });
@@ -613,7 +618,7 @@
                        if (!result) {
                            Application.RunOnMainThread (() => {
                                MainPage.Loading.Hide ();
                                new Alert ("", ErrorCode.OperationFailed, Language.StringByID (R.MyInternationalizationString.Close)).Show ();
                                new Alert ("", "Encryption gateway failed, please try again.", Language.StringByID (R.MyInternationalizationString.Close)).Show ();
                            });
                          
@@ -621,7 +626,7 @@
                        }
                        //修改成功,设置本地为加密方式
                        UserConfig.Instance.IsLocalEncrypt = true;
                        //System.Console.WriteLine ($"============>LocalEncryptKey 加密成功Key为:{UserConfig.Instance.LocalEncryptKey}");
                        //Utlis.WriteLine ($"============>LocalEncryptKey 加密成功Key为:{UserConfig.Instance.LocalEncryptKey}");
                    }
                    goNext = true;