From cc8749fe1d158ee21670bde77fad237be2f0c416 Mon Sep 17 00:00:00 2001 From: JLChen <551775569@qq.com> Date: 星期五, 08 一月 2021 11:47:06 +0800 Subject: [PATCH] 2021-01-08 1.去掉无关文件 --- Crabtree/SmartHome/UI/SimpleControl/Phone/Guide/GuideAddResidence.cs | 244 +++++++++++++++++++++--------------------------- 1 files changed, 106 insertions(+), 138 deletions(-) diff --git a/Crabtree/SmartHome/UI/SimpleControl/Phone/Guide/GuideAddResidence.cs b/Crabtree/SmartHome/UI/SimpleControl/Phone/Guide/GuideAddResidence.cs index 2b49a86..8475308 100644 --- a/Crabtree/SmartHome/UI/SimpleControl/Phone/Guide/GuideAddResidence.cs +++ b/Crabtree/SmartHome/UI/SimpleControl/Phone/Guide/GuideAddResidence.cs @@ -110,20 +110,12 @@ } }) { IsBackground = true }.Start (); }); - // 璇诲彇浣忓畢鍒楄〃 - var requestObj2 = new GetHomePagerObj (); - requestObj2.ReqDto.LoginAccessToken = MainPage.LoginUser.LoginTokenString; - var requestJson2 = Newtonsoft.Json.JsonConvert.SerializeObject (requestObj2); - var revertObj2 = MainPage.RequestHttps (API.GetHomePager, requestJson2); - if (revertObj2.StateCode.ToUpper () == "SUCCESS") { - var mResidenceRes = Newtonsoft.Json.JsonConvert.DeserializeObject<ResidenceRes> (revertObj2.ResponseData.ToString ()); - var responseDataObj = mResidenceRes.PageData; - //if(responseDataObj == null && responseDataObj.Count == 0) { - // return; - //} - UserConfig.Instance.HomeLists = responseDataObj; - if (responseDataObj != null && responseDataObj.Count > 0) { + //鑾峰彇浣忓畢鍒楄〃 + var revertObjCode = HttpServerRequest.Current.GetHomePager (); + if (revertObjCode == StateCode.SUCCESS) { + var mHomeLists = UserConfig.Instance.HomeLists; + if (mHomeLists != null && mHomeLists.Count > 0) { if (string.IsNullOrEmpty (UserConfig.Instance.HomeLists [0].Name)) { Application.RunOnMainThread (() => { MainPage.Loading.Hide (); @@ -133,7 +125,7 @@ } UserConfig.Instance.SaveUserConfig (); //2020-01-16 - var mHome = responseDataObj.Find ((obj) => obj.Id == UserConfig.Instance.CurrentRegion.Id); + var mHome = mHomeLists.Find ((obj) => obj.Id == UserConfig.Instance.CurrentRegion.Id); if (mHome != null) { UserConfig.Instance.CurrentRegion = mHome; } else { @@ -147,8 +139,7 @@ return; } } else { - ShowGetHomePagerErrorInfo (revertObj2.StateCode); - + IMessageCommon.Current.ShowErrorInfoAlter (revertObjCode); Application.RunOnMainThread (() => { MainPage.Loading.Hide (); this.RemoveFromParent (); @@ -166,38 +157,12 @@ this.RemoveFromParent (); needHide = false; }); - Console.WriteLine (ex.Message); + Utlis.WriteLine (ex.Message); } finally { needHide = false; } }) { IsBackground = true }.Start (); } - - - - /// <summary> - /// - /// </summary> - /// <param name="stateCodeStr"></param> - void ShowGetHomePagerErrorInfo (string stateCodeStr) - { - string mes = ""; - //2020-01-06 寰呰ˉ鍏� - if (stateCodeStr == ErrorCode.NetworkError) { - mes = ErrorCode.NetworkError; - } else { - mes = ErrorCode.OperationFailed + ErrorCode.Reason + stateCodeStr; - - } - if (!string.IsNullOrEmpty (mes)) { - Application.RunOnMainThread (() => { - new Alert ("", mes, Language.StringByID (R.MyInternationalizationString.Close)).Show (); - }); - } - - - } - /// <summary> /// 鍔犺浇鍒锋柊鎵�鏈変綇瀹� @@ -227,9 +192,7 @@ new Alert ("", ErrorCode.InsufficientAuthority, "Close").Show (); return; } - GotoGuideAddGatewayView (UserConfig.Instance.CurrentRegion); - } } catch { } @@ -266,8 +229,6 @@ } - - /// <summary> /// 鍔犺浇鐣岄潰 /// </summary> @@ -289,7 +250,7 @@ var btnPoint = new Button () { Width = Application.GetRealWidth (10), - Height = Application.GetRealHeight (10), + Height = Application.GetRealWidth (10), X = Application.GetRealWidth (50), Gravity = Gravity.CenterVertical, UnSelectedImagePath = "Item/Point.png", @@ -307,13 +268,12 @@ }; rowView.AddChidren (btnName); - //鏄剧ず鍒嗕韩鎸夐挳 if (home.IsOthreShare) { Button FromSharingButton = new Button () { X = Application.GetRealWidth (480), Width = Application.GetRealWidth (30), - Height = Application.GetRealHeight (30), + Height = Application.GetRealWidth (30), Gravity = Gravity.CenterVertical, UnSelectedImagePath = "CrabtreeAdd/FromSharing.png", SelectedImagePath = "CrabtreeAdd/FromSharing.png", @@ -375,7 +335,7 @@ }; rowView.AddChidren (btnCheck); } - if (UserConfig.Instance.CurrentRegion.Id != home.Id && MainPage.LoginUser.AccountType != 1) { + if (UserConfig.Instance.CurrentRegion.Id != home.Id) { Button btnDel = new Button () { TextID = R.MyInternationalizationString.Del, BackgroundColor = SkinStyle.Current.DelColor, @@ -468,6 +428,7 @@ btnConfirm.MouseUpEventHandler += (dou, ni) => { string password = etPw.Text.Trim (); if (string.IsNullOrEmpty (password)) { + Utlis.ShowAlertOnMainThread (Language.StringByID (R.MyInternationalizationString.PasswordIsEmpty)); return; } System.Threading.Tasks.Task.Run (() => { @@ -475,23 +436,17 @@ Application.RunOnMainThread (() => { MainPage.Loading.Start ("Please wait..."); }); - var requestObj = new LoginObj () { Account = MainPage.LoginUser.AccountString, Password = password }; - var requestJson = Newtonsoft.Json.JsonConvert.SerializeObject (requestObj); - var revertObj = MainPage.RequestHttps (API.Login, requestJson); - if (revertObj.StateCode.ToUpper () == "SUCCESS") { - - var requestObj2 = new DelHomeObj () { - HomeId = home.Id, - LoginAccessToken = MainPage.LoginUser.LoginTokenString - }; - var requestJson2 = Newtonsoft.Json.JsonConvert.SerializeObject (requestObj2); - var revertObj2 = MainPage.RequestHttps (API.DelHome, requestJson2); - if (revertObj2.StateCode.ToUpper () == "SUCCESS") { + + var revertObj = HttpServerRequest.Current.LoginByPassword (MainPage.LoginUser.AccountString, password); + if (revertObj.Code == StateCode.SUCCESS) { + //鍒犻櫎浣忓畢 + var revertObj2 = HttpServerRequest.Current.DeleteHome (home.Id); + if (revertObj2.Code == StateCode.SUCCESS) { Application.RunOnMainThread (() => { GetHomeList (); }); } else { - ShowDelHomeErrorInfo (revertObj2.StateCode); + IMessageCommon.Current.ShowErrorInfoAlter (revertObj2.Code); } } else { Application.RunOnMainThread (() => { @@ -538,18 +493,49 @@ } /// <summary> + /// 鍚姩鏈湴妯″紡 + /// </summary> + void EnableLocalMode () { + MainPage.AddTip ("Enable local mode."); + Utlis.ShowAppLinkStatus (AppLinkStatus.WiFiOffline); + CommonPage.IsRemote = false; + SmartHome.MqttCommon.DisConnectRemoteMqttClient ("EnableLocalMode"); + } + + /// <summary> + /// 鍚姩杩滅▼妯″紡 + /// </summary> + void EnableRemoteMode () + { + MainPage.AddTip ("Restore remote mode."); + Utlis.ShowAppLinkStatus (AppLinkStatus.CloudUnlink); + CommonPage.IsRemote = true; + } + + /// <summary> /// 璺宠浆缃戝叧鎼滅储椤甸潰 /// </summary> /// <param name="home"></param> void GotoGuideAddGatewayView (RegionInfoRes home) { try { + //杩滅▼杩炴帴鐨勬椂鍊欑姝� 鎼滅储缃戝叧鍜屾坊鍔犺澶� + if (CommonPage.IsRemote) { + ////褰撳墠澶勪簬杩滅▼杩炴帴妯″紡锛屾棤娉曡繘鍏ユ悳绱㈢綉鍏抽〉闈€�傝鍏堝垏鎹㈠洖鏈湴杩炴帴妯″紡銆� + //new Alert ("", "Currently in remote connection mode, unable to enter the search gateway page. Please switch back to local connection mode first.", Language.StringByID (R.MyInternationalizationString.Close)).Show (); + //return; + + //2020-06-29 鍚姩鏈湴閫氫俊妯″紡 + EnableLocalMode (); + } + + var addGatewayDialog = new GuideAddGateway (); (Parent as PageLayout).AddChidren (addGatewayDialog); addGatewayDialog.ShowPage (home); (Parent as PageLayout).PageIndex = (Parent as PageLayout).ChildrenCount - 1; } catch { - System.Console.WriteLine ("============>GotoGuideAddGatewayView 璺宠浆澶辫触 "); + Utlis.WriteLine ("============>GotoGuideAddGatewayView 璺宠浆澶辫触 "); } } @@ -563,11 +549,11 @@ void ChangeRegion (RegionInfoRes home, bool goHomePage = true, bool bNeedCheckAddRoom = false, bool goToGuideAddGatewayView = false) { if (home == null || string.IsNullOrEmpty (home.Id)) return; - - MainPage.Loading.Start ("Please wait..."); + Application.RunOnMainThread (() => { + MainPage.Loading.Start ("Please wait..."); + }); System.Threading.Tasks.Task.Run (() => { try { - //if (home.RegionID != UserConfig.Instance.CurrentRegion.RegionID) { var backuplist = IO.FileUtils.ReadFiles (); int index = 0; if (string.IsNullOrEmpty (UserConfig.Instance.CurrentRegion.Id)) { @@ -579,7 +565,7 @@ System.IO.FileInfo fileInfo = new System.IO.FileInfo (IO.FileUtils.RootPath + fileName); if (fileInfo.Exists) { fileInfo.MoveTo (oldRegionRootPath + fileName); - Console.WriteLine ("move file : " + fileName); + Utlis.WriteLine ("move file : " + fileName); } index++; Application.RunOnMainThread (() => { @@ -596,41 +582,28 @@ Application.RunOnMainThread (() => { if (goToGuideAddGatewayView) { IsNeedGoToGuideAddGatewayView = true; - //2020-01-16 - //GotoGuideAddGatewayView (home); - - //var addGatewayDialog = new GuideAddGateway (); - //UserMiddle.guidePageView.AddChidren (addGatewayDialog); - //addGatewayDialog.ShowPage (home);//guidePageView - //UserMiddle.guidePageView.PageIndex = 1; } GetHomeList (false); - if (goHomePage) { UserConfig.Instance.RefreshUserConfig (); new Alert ("", Language.StringByID (R.MyInternationalizationString.SwitchRegionSuccessfully), Language.StringByID (R.MyInternationalizationString.Close)).Show (); //this.RemoveFromParent (); - CommonPage.IsRemote = false; + //CommonPage.IsRemote = false; EquipmentPublicClass.CheckLinkRemote (UserConfig.Instance.internetStatus); } if (bNeedCheckAddRoom) { CheckIfNeedAddRoom (); } - - }); MainPage.LoginUser.SaveUserInfo (); - - - //} } catch (Exception ex) { Application.RunOnMainThread (() => { new Alert ("", Language.StringByID (R.MyInternationalizationString.CheckInternet), Language.StringByID (R.MyInternationalizationString.Close)).Show (); }); - Console.WriteLine (ex.Message); + Utlis.WriteLine (ex.Message); } finally { Application.RunOnMainThread (() => { MainPage.Loading.Hide (); @@ -701,10 +674,10 @@ etZoneName.EditorEnterAction += (obj) => { Application.HideSoftInput (); }; - if (MainPage.LoginUser.AccountType == 1) { - etZoneName.Enable = false; - etZoneName.BorderWidth = 0; - } + //if (MainPage.LoginUser.AccountType == 1) { + // etZoneName.Enable = false; + // etZoneName.BorderWidth = 0; + //} var BottomView = new FrameLayout () { Y = Application.GetRealHeight (400 - 88), @@ -721,31 +694,39 @@ }; btnOption.MouseUpEventHandler += (sdf, fds) => { dialog.Close (); - if (etZoneName.Text.Trim () == "") { + var homeName = etZoneName.Text.Trim (); + if (homeName == "") { new Alert ("", Language.StringByID (R.MyInternationalizationString.PleaseEnterZoneName), Language.StringByID (R.MyInternationalizationString.Close)).Show (); return; } - if (isChangeName) { - //home.Name = button.Text = etZoneName.Text; - var requestObj2 = new EditHomeObj () { HomeId = home.Id, Name = etZoneName.Text, LoginAccessToken = MainPage.LoginUser.LoginTokenString }; - string urlHead = MainPage.RequestHttpsHost; - if (requestObj2.IsOtherAccountCtrl) { - urlHead = UserConfig.Instance.MasterAccountRequestBaseUrl; - requestObj2.LoginAccessToken = UserConfig.Instance.MasterAccountToken; - } - var requestJson2 = Newtonsoft.Json.JsonConvert.SerializeObject (requestObj2); - var revertObj2 = MainPage.RequestHttps (API.EditHome, requestJson2, urlHead); - if (revertObj2.StateCode.ToUpper () != "SUCCESS") { - ShowEditHomeErrorInfo (revertObj2.StateCode); - return; - } - home.Name = button.Text = etZoneName.Text; - IO.FileUtils.ReNameFoler (UserConfig.Instance.CurrentRegion.Name, home.Name); - return; - } + //2020-04-26 + MainPage.Loading.Start ("Please wait..."); + System.Threading.Tasks.Task.Run (() => { + try { + if (isChangeName) { + var revertObj2 = HttpServerRequest.Current.EditResidenceInfo (0, homeName); + if (revertObj2.Code != StateCode.SUCCESS) { + IMessageCommon.Current.ShowErrorInfoAlter (revertObj2.Code); + return; + } + Application.RunOnMainThread (() => { + home.Name = button.Text = homeName; + }); + //IO.FileUtils.ReNameFoler (UserConfig.Instance.CurrentRegion.Name, home.Name); + return; + } - EditResidence (home, etZoneName.Text.Trim (), guide); + EditResidence (home, homeName, guide); + + } catch { + //MainPage.FailureToServer (); + } finally { + Application.RunOnMainThread (() => { + MainPage.Loading.Hide (); + }); + } + }); }; @@ -783,50 +764,37 @@ if (home.Name != residenceName) { if (string.IsNullOrEmpty(home.Id)) { - var requestObj21 = new AddHomeObj () { - Name = residenceName , - LoginAccessToken = MainPage.LoginUser.LoginTokenString, - - }; - var requestJson21 = Newtonsoft.Json.JsonConvert.SerializeObject (requestObj21); - var revertObj21 = MainPage.RequestHttps (API.AddHome, requestJson21); - if ( revertObj21.StateCode.ToUpper() != "SUCCESS") { - ShowAddHomeErrorInfo (revertObj21.StateCode); + var revertObj21 = HttpServerRequest.Current.AddHome (residenceName); + if (revertObj21.Code != StateCode.SUCCESS) { + IMessageCommon.Current.ShowErrorInfoAlter (revertObj21.Code); return false; } + home.Name = residenceName; //鍒涘缓浣忓畢鎴愬姛锛屽垏鎹㈠埌璇ヤ綇瀹� - var responseDataObj = Newtonsoft.Json.JsonConvert.DeserializeObject<List<RegionInfoRes>> (revertObj21.ResponseData.ToString ()); - if (responseDataObj != null && responseDataObj.Count > 0) { - ChangeRegion (responseDataObj [0], true, true, goToGuideAddGatewayView); - + var newHome = Newtonsoft.Json.JsonConvert.DeserializeObject<RegionInfoResNew> (revertObj21.Data.ToString ()); + if (newHome != null && !string.IsNullOrEmpty(newHome.Id)) { + home = HttpServerRequest.Current.RegionInfoResNewToHome (newHome); + if (UserConfig.Instance.HomeLists == null) { + UserConfig.Instance.HomeLists = new List<RegionInfoRes> (); + } + UserConfig.Instance.HomeLists.Add (home); + UserConfig.Instance.SaveUserConfig (); + ChangeRegion (home, true, true, goToGuideAddGatewayView); } } else { - var requestObj2 = new EditHomeObj () { HomeId = home.Id, Name = residenceName, LoginAccessToken = MainPage.LoginUser.LoginTokenString }; - string urlHead = MainPage.RequestHttpsHost; - if (requestObj2.IsOtherAccountCtrl) { - urlHead = UserConfig.Instance.MasterAccountRequestBaseUrl; - requestObj2.LoginAccessToken = UserConfig.Instance.MasterAccountToken; - } - var requestJson2 = Newtonsoft.Json.JsonConvert.SerializeObject (requestObj2); - var revertObj2 = MainPage.RequestHttps (API.EditHome, requestJson2, urlHead); - if (revertObj2.StateCode.ToUpper() != "SUCCESS") { - ShowEditHomeErrorInfo (revertObj2.StateCode); + var revertObj2 = HttpServerRequest.Current.EditResidenceInfo (0, residenceName); + if (revertObj2.Code != StateCode.SUCCESS) { + IMessageCommon.Current.ShowErrorInfoAlter (revertObj2.Code); return false; } home.Name = residenceName; - IO.FileUtils.ReNameFoler (UserConfig.Instance.CurrentRegion.Name, home.Name); + //IO.FileUtils.ReNameFoler (UserConfig.Instance.CurrentRegion.Name, home.Name); ChangeRegion (home, false, true, goToGuideAddGatewayView); //CheckIfNeedAddRoom (); } - - //ShowHomeList (false); - //2020-01-09 鍘绘帀鍒囨崲浣忓畢 - //UserConfig.Instance.CurrentRegion = home; - //UserConfig.Instance.SaveUserConfig (); }else { ChangeRegion (home, false, true, goToGuideAddGatewayView); - //CheckIfNeedAddRoom (); } return true; -- Gitblit v1.8.0