| | |
| | | { |
| | | public class GuideAddResidence : FrameLayout |
| | | { |
| | | public bool IsHideBack = false; |
| | | |
| | | bool IsNeedGoToGuideAddGatewayView = false; |
| | | |
| | | public GuideAddResidence () |
| | | { |
| | | BackgroundColor = SkinStyle.Current.MainColor; |
| | | } |
| | | |
| | | public void ShowHomeList (bool showDialog = true) |
| | | //bool isInitViewEnd = false; |
| | | VerticalScrolViewLayout VerticalScrolViewMiddle; |
| | | |
| | | public void ShowHomeView (bool showDialog = false) { |
| | | #region 标题 |
| | | var topView = new FrameLayout () { |
| | | Y = Application.GetRealHeight (36), |
| | | Height = Application.GetRealHeight (90), |
| | | }; |
| | | AddChidren (topView); |
| | | |
| | | var title = new Button () { |
| | | TextAlignment = TextAlignment.Center, |
| | | Text = "Zones/Residences", |
| | | TextSize = 19, |
| | | TextColor = SkinStyle.Current.TextColor1 |
| | | }; |
| | | topView.AddChidren (title); |
| | | |
| | | Button ItemButton = new Button () { |
| | | Width = Application.GetRealWidth (55), |
| | | Height = Application.GetRealHeight (55), |
| | | UnSelectedImagePath = "Item/+.png", |
| | | SelectedImagePath = "Item/+.png", |
| | | Y = Application.GetRealHeight (17), |
| | | X = Application.GetRealWidth (640 - 80), |
| | | }; |
| | | topView.AddChidren (ItemButton); |
| | | ItemButton.MouseUpEventHandler += (sender1, e1) => { |
| | | //GuideAddHomeDialog (new RegionInfoRes () { Id = "", Name = "" }, false); |
| | | GuideAddHomeDialog (new RegionInfoRes () { Id = "", Name = "" }, false); |
| | | }; |
| | | |
| | | //if (!IsHideBack) { |
| | | var back = new Button () { |
| | | Height = Application.GetRealHeight (90), |
| | | Width = Application.GetRealWidth (85), |
| | | UnSelectedImagePath = "Item/Back.png", |
| | | SelectedImagePath = "Item/BackSelected.png", |
| | | }; |
| | | topView.AddChidren (back); |
| | | back.MouseUpEventHandler += (sender, e) => { |
| | | if (IsHideBack) { |
| | | ShowIfLogoutAlter (); |
| | | } else { |
| | | (Parent as PageLayout).PageIndex -= 1; |
| | | } |
| | | |
| | | }; |
| | | |
| | | //} |
| | | |
| | | |
| | | |
| | | #endregion |
| | | |
| | | var BodyView = new FrameLayout () { |
| | | Width = LayoutParams.MatchParent, |
| | | Height = Application.GetRealHeight (1136 - 126), |
| | | Y = topView.Bottom, |
| | | BackgroundColor = SkinStyle.Current.ViewColor, |
| | | }; |
| | | AddChidren (BodyView); |
| | | |
| | | VerticalScrolViewMiddle = new VerticalScrolViewLayout (); |
| | | BodyView.AddChidren (VerticalScrolViewMiddle); |
| | | |
| | | GetHomeList (showDialog); |
| | | |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 查询所有住宅列表 |
| | | /// </summary> |
| | | /// <param name="showDialog"></param> |
| | | void GetHomeList (bool showDialog = false) |
| | | { |
| | | |
| | | new System.Threading.Thread (() => { |
| | | bool needHide = true; |
| | | try { |
| | |
| | | |
| | | var requestJson2 = Newtonsoft.Json.JsonConvert.SerializeObject (requestObj2); |
| | | var revertObj2 = MainPage.RequestHttps (API.GetHomePager, requestJson2); |
| | | if (revertObj2.StateCode.ToUpper() == "SUCCESS") { |
| | | 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) { |
| | |
| | | }); |
| | | } |
| | | UserConfig.Instance.SaveUserConfig (); |
| | | UserConfig.Instance.CurrentRegion = responseDataObj.Find ((obj) => obj.Name == UserConfig.Instance.CurrentRegion.Name); |
| | | //2020-01-16 |
| | | var mHome = responseDataObj.Find ((obj) => obj.Id == UserConfig.Instance.CurrentRegion.Id); |
| | | if (mHome != null) { |
| | | UserConfig.Instance.CurrentRegion = mHome; |
| | | } else { |
| | | UserConfig.Instance.CurrentRegion = UserConfig.Instance.HomeLists [0]; |
| | | } |
| | | } else { |
| | | Application.RunOnMainThread (() => { |
| | | MainPage.Loading.Hide (); |
| | |
| | | MainPage.Loading.Hide (); |
| | | ShowHomeListView (showDialog); |
| | | }); |
| | | } catch (Exception ex) { |
| | | Application.RunOnMainThread (() => { |
| | | MainPage.Loading.Hide (); |
| | | this.RemoveFromParent (); |
| | | } catch (Exception ex) { |
| | | Application.RunOnMainThread (() => { |
| | | MainPage.Loading.Hide (); |
| | | this.RemoveFromParent (); |
| | | needHide = false; |
| | | }); |
| | | Utlis.WriteLine (ex.Message); |
| | | } finally { |
| | | needHide = false; |
| | | }); |
| | | Console.WriteLine (ex.Message); |
| | | } finally { |
| | | needHide = false; |
| | | } |
| | | }) { IsBackground = true }.Start (); |
| | | } |
| | | }) { IsBackground = true }.Start (); |
| | | } |
| | | |
| | | |
| | |
| | | |
| | | } |
| | | |
| | | void ShowHomeListView (bool showDialog = true) |
| | | |
| | | /// <summary> |
| | | /// 加载刷新所有住宅 |
| | | /// </summary> |
| | | /// <param name="ifNeedShowDialog"></param> |
| | | void ShowHomeListView (bool ifNeedShowDialog = false) |
| | | { |
| | | RemoveAll (); |
| | | #region 标题 |
| | | var topView = new FrameLayout () { |
| | | Y = Application.GetRealHeight (36), |
| | | Height = Application.GetRealHeight (90), |
| | | }; |
| | | AddChidren (topView); |
| | | |
| | | var title = new Button () { |
| | | TextAlignment = TextAlignment.Center, |
| | | Text= "Zones/Residences", |
| | | TextSize = 19, |
| | | TextColor = SkinStyle.Current.TextColor1 |
| | | }; |
| | | topView.AddChidren (title); |
| | | |
| | | Button ItemButton = new Button () { |
| | | Width = Application.GetRealWidth (55), |
| | | Height = Application.GetRealHeight (55), |
| | | UnSelectedImagePath = "Item/+.png", |
| | | SelectedImagePath = "Item/+.png", |
| | | Y = Application.GetRealHeight (17), |
| | | X = Application.GetRealWidth (640 - 80), |
| | | }; |
| | | topView.AddChidren (ItemButton); |
| | | ItemButton.MouseUpEventHandler += (sender1, e1) => { |
| | | GuideAddHomeDialog (new RegionInfoRes () { Id = "", Name = "" }, false); |
| | | }; |
| | | if (showDialog) { |
| | | var back = new Button () { |
| | | Height = Application.GetRealHeight (90), |
| | | Width = Application.GetRealWidth (85), |
| | | UnSelectedImagePath = "Item/Back.png", |
| | | SelectedImagePath = "Item/BackSelected.png", |
| | | }; |
| | | topView.AddChidren (back); |
| | | back.MouseUpEventHandler += (sender, e) => { |
| | | (Parent as PageLayout).PageIndex -= 1; |
| | | }; |
| | | } |
| | | #endregion |
| | | |
| | | var BodyView = new FrameLayout () { |
| | | Width = LayoutParams.MatchParent, |
| | | Height = Application.GetRealHeight (1136 - 126), |
| | | Y = topView.Bottom, |
| | | BackgroundColor = SkinStyle.Current.ViewColor, |
| | | }; |
| | | AddChidren (BodyView); |
| | | |
| | | VerticalScrolViewLayout VerticalScrolViewMiddle = new VerticalScrolViewLayout (); |
| | | BodyView.AddChidren (VerticalScrolViewMiddle); |
| | | |
| | | try { |
| | | VerticalScrolViewMiddle.RemoveAll (); |
| | | foreach (var tempHome in UserConfig.Instance.HomeLists) { |
| | | AddResidenceListRow (tempHome, VerticalScrolViewMiddle); |
| | | } |
| | | } catch { } |
| | | |
| | | if (UserConfig.Instance.GatewayList !=null && UserConfig.Instance.GatewayList.Count == 0) { |
| | | if (showDialog) { |
| | | |
| | | if (!UserConfig.Instance.CheckHomeGatewaysNotEmpty ()) { |
| | | if (ifNeedShowDialog) { |
| | | GuideAddHomeDialog (UserConfig.Instance.HomeLists [0], true); |
| | | UserConfig.Instance.CurrentRegion = UserConfig.Instance.HomeLists [0]; |
| | | } |
| | | } |
| | | try { |
| | | if (IsNeedGoToGuideAddGatewayView) { |
| | | IsNeedGoToGuideAddGatewayView = false; |
| | | if (UserConfig.Instance.CurrentRegion.IsOthreShare) { |
| | | //提示没有分享住宅的权限 |
| | | new Alert ("", ErrorCode.InsufficientAuthority, "Close").Show (); |
| | | return; |
| | | } |
| | | |
| | | GotoGuideAddGatewayView (UserConfig.Instance.CurrentRegion); |
| | | |
| | | } |
| | | } catch { } |
| | | |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 提示用户是否退出登录 |
| | | /// </summary> |
| | | void ShowIfLogoutAlter () |
| | | { |
| | | var logoutAlert = new Alert ("", "Log out?", "No", "Yes"); |
| | | logoutAlert.Show (); |
| | | logoutAlert.ResultEventHandler += (sender1, e1) => { |
| | | if (e1) { |
| | | AccountLogout (); |
| | | } |
| | | }; |
| | | |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 退出登录 |
| | | /// </summary> |
| | | void AccountLogout () |
| | | { |
| | | try { |
| | | this.RemoveFromParent (); |
| | | MainPage.LoginUser.LastTime = DateTime.Now.AddDays (-30); |
| | | MainPage.LoginUser.SaveUserInfo (); |
| | | new AccountLogin ().Show (); |
| | | } catch { |
| | | |
| | | } |
| | | |
| | | } |
| | | |
| | | |
| | | |
| | | /// <summary> |
| | | /// 加载界面 |
| | | /// </summary> |
| | | /// <param name="home">Home.</param> |
| | | /// <param name="VerticalScrolViewMiddle">Vertical scrol view middle.</param> |
| | | void AddResidenceListRow (RegionInfoRes home, VerticalScrolViewLayout VerticalScrolViewMiddle ) |
| | | /// <param name="mVerticalScrolViewMiddle">Vertical scrol view middle.</param> |
| | | void AddResidenceListRow (RegionInfoRes home, VerticalScrolViewLayout mVerticalScrolViewMiddle) |
| | | { |
| | | var rowView = new RowLayout () { |
| | | Height = Application.GetRealHeight (110), |
| | | }; |
| | | VerticalScrolViewMiddle.AddChidren (rowView); |
| | | mVerticalScrolViewMiddle.AddChidren (rowView); |
| | | |
| | | Button btnRowLine = new Button () { |
| | | Y = Application.GetRealHeight (107), |
| | |
| | | }; |
| | | rowView.AddChidren (btnName); |
| | | |
| | | |
| | | //显示分享按钮 |
| | | if (home.IsOthreShare) { |
| | | Button FromSharingButton = new Button () { |
| | | X = Application.GetRealWidth (480), |
| | | Width = Application.GetRealWidth (30), |
| | | Height = Application.GetRealHeight (30), |
| | | Gravity = Gravity.CenterVertical, |
| | | UnSelectedImagePath = "CrabtreeAdd/FromSharing.png", |
| | | SelectedImagePath = "CrabtreeAdd/FromSharing.png", |
| | | }; |
| | | rowView.AddChidren (FromSharingButton); |
| | | } |
| | | |
| | | var goNextButton = new Button () { |
| | | X = Application.GetRealWidth (500), |
| | | Width = Application.GetRealWidth (120), |
| | | }; |
| | | rowView.AddChidren (goNextButton); |
| | | |
| | | |
| | | Button rightButton1 = new Button () { |
| | | X = Application.GetRealWidth (550), |
| | |
| | | SelectedImagePath = "Item/RightSelected.png", |
| | | }; |
| | | rowView.AddChidren (rightButton1); |
| | | |
| | | EventHandler<MouseEventArgs> eHandler = (sender, e) => { |
| | | if (home.Id == UserConfig.Instance.CurrentRegion.Id) { |
| | | //UserConfig.Instance.GatewayMAC = gatewayMAC; |
| | | var addGatewayDialog = new GuideAddGateway (); |
| | | (Parent as PageLayout).AddChidren (addGatewayDialog); |
| | | addGatewayDialog.ShowPage (home); |
| | | (Parent as PageLayout).PageIndex = (Parent as PageLayout).ChildrenCount - 1; |
| | | if (home.IsOthreShare) { |
| | | //提示没有分享住宅的权限 |
| | | new Alert ("", ErrorCode.InsufficientAuthority, "Close").Show (); |
| | | return; |
| | | } |
| | | |
| | | GotoGuideAddGatewayView (home); |
| | | } else { |
| | | ChangeRegion (home); |
| | | } |
| | | }; |
| | | rightButton1.MouseUpEventHandler += eHandler; |
| | | rightButton1.MouseUpEventHandler += eHandler; |
| | | goNextButton.MouseUpEventHandler += eHandler; |
| | | btnName.MouseUpEventHandler += (sender,e)=> { |
| | | btnName.MouseUpEventHandler += (sender, e) => { |
| | | if (home.Id == UserConfig.Instance.CurrentRegion.Id) { |
| | | GuideAddHomeDialog (home, false,true, btnName); |
| | | if (home.IsOthreShare) { |
| | | //提示没有分享住宅的权限 |
| | | new Alert ("", ErrorCode.InsufficientAuthority, "Close").Show (); |
| | | return; |
| | | } |
| | | GuideAddHomeDialog (home, false, true, btnName); |
| | | } else { |
| | | ChangeRegion (home); |
| | | } |
| | |
| | | }; |
| | | rowView.AddRightView (btnDel); |
| | | btnDel.MouseUpEventHandler += (sd, ee) => { |
| | | if (home.IsOthreShare) { |
| | | //提示没有分享住宅的权限 |
| | | new Alert ("", ErrorCode.InsufficientAuthority, "Close").Show (); |
| | | return; |
| | | } |
| | | |
| | | Dialog dialog = new Dialog (); |
| | | |
| | | FrameLayout dialogBody = new FrameLayout () { |
| | |
| | | }); |
| | | var requestObj = new LoginObj () { Account = MainPage.LoginUser.AccountString, Password = password }; |
| | | var requestJson = Newtonsoft.Json.JsonConvert.SerializeObject (requestObj); |
| | | var revertObj = MainPage.RequestHttps (API.Login, requestJson, false, false); |
| | | if (revertObj.StateCode.ToUpper() == "SUCCESS") { |
| | | var revertObj = MainPage.RequestHttps (API.Login, requestJson); |
| | | if (revertObj.StateCode.ToUpper () == "SUCCESS") { |
| | | |
| | | var requestObj2 = new DelHomeObj () { HomeId = home.Id }; |
| | | 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") { |
| | | Application.RunOnMainThread (() => { |
| | | ShowHomeList (); |
| | | GetHomeList (); |
| | | }); |
| | | } else { |
| | | ShowDelHomeErrorInfo (revertObj2.StateCode); |
| | |
| | | if (stateCodeStr == "NoLogin") { |
| | | mes = ErrorCode.NoLogin; |
| | | } else if (stateCodeStr == "CurrentHomeExixtsGatewayBind") { |
| | | mes = ErrorCode.HomeIdAndTokenNoConsistent; |
| | | mes = ErrorCode.CurrentHomeExixtsGatewayBind; |
| | | } else if (stateCodeStr == ErrorCode.NetworkError) { |
| | | mes = ErrorCode.NetworkError; |
| | | } else { |
| | |
| | | } |
| | | |
| | | /// <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 { |
| | | |
| | | Utlis.WriteLine ("============>GotoGuideAddGatewayView 跳转失败 "); |
| | | } |
| | | |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 更换本地区域 |
| | | /// </summary> |
| | | /// <param name="home">Home.</param> |
| | | /// <param name="gatewayMAC">Gateway mac.</param> |
| | | void ChangeRegion (RegionInfoRes home, bool goHomePage = true) |
| | | /// |
| | | void ChangeRegion (RegionInfoRes home, bool goHomePage = true, bool bNeedCheckAddRoom = false, bool goToGuideAddGatewayView = false) |
| | | { |
| | | MainPage.Loading.Start ("Please wait..."); |
| | | if (home == null || string.IsNullOrEmpty (home.Id)) return; |
| | | 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.Name)) { |
| | | if (string.IsNullOrEmpty (UserConfig.Instance.CurrentRegion.Id)) { |
| | | UserConfig.Instance.CurrentRegion = UserConfig.Instance.HomeLists [0]; |
| | | } |
| | | string oldRegionRootPath = IO.FileUtils.CreateRegionBackup (UserConfig.Instance.CurrentRegion.Name); |
| | | string oldRegionRootPath = IO.FileUtils.CreateRegionBackup (UserConfig.Instance.CurrentRegion.Id); |
| | | IO.FileUtils.DeleteRegionFiles (oldRegionRootPath); |
| | | foreach (var fileName in backuplist) { |
| | | 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 (() => { |
| | |
| | | }); |
| | | } |
| | | IO.FileUtils.DeleteAllFile (); |
| | | string newRegionRootPath = IO.FileUtils.CreateRegionBackup (home.Name); |
| | | string newRegionRootPath = IO.FileUtils.CreateRegionBackup (home.Id); |
| | | IO.FileUtils.RestoreRegionFiles (newRegionRootPath); |
| | | UserConfig.Instance.CurrentRegion = home; |
| | | UserConfig.Instance.SaveUserConfig (); |
| | | Room.InitAllRoom (); |
| | | Application.RunOnMainThread (() => { |
| | | ShowHomeList (); |
| | | 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; |
| | | EquipmentPublicClass.CheckLinkRemote (2); |
| | | //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 (); |
| | |
| | | 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 = home.Name }; |
| | | var requestJson2 = Newtonsoft.Json.JsonConvert.SerializeObject (requestObj2); |
| | | var revertObj2 = MainPage.RequestHttps (API.EditHome, requestJson2); |
| | | IO.FileUtils.ReNameFoler (UserConfig.Instance.CurrentRegion.Name, home.Name); |
| | | return; |
| | | } |
| | | ChangeRegion (home, false); |
| | | var addGatewayDialog = new GuideAddGateway (); |
| | | if (guide) { |
| | | EditResidence (home, etZoneName.Text.Trim ()); |
| | | UserMiddle.guidePageView.AddChidren (addGatewayDialog); |
| | | addGatewayDialog.ShowPage (home);//guidePageView |
| | | UserMiddle.guidePageView.PageIndex = 1; |
| | | } else { |
| | | UserMiddle.SettingPageView.AddChidren (addGatewayDialog); |
| | | addGatewayDialog.ShowPage (home); |
| | | UserMiddle.SettingPageView.PageIndex = 2; |
| | | } |
| | | |
| | | |
| | | //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; |
| | | //} |
| | | |
| | | //EditResidence (home, etZoneName.Text.Trim (), guide); |
| | | |
| | | |
| | | //2020-04-26 |
| | | MainPage.Loading.Start ("Please wait..."); |
| | | System.Threading.Tasks.Task.Run (() => { |
| | | |
| | | try { |
| | | |
| | | 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; |
| | | } |
| | | Application.RunOnMainThread (() => { |
| | | home.Name = button.Text = etZoneName.Text; |
| | | }); |
| | | IO.FileUtils.ReNameFoler (UserConfig.Instance.CurrentRegion.Name, home.Name); |
| | | return; |
| | | } |
| | | |
| | | EditResidence (home, etZoneName.Text.Trim (), guide); |
| | | |
| | | |
| | | } catch { |
| | | //MainPage.FailureToServer (); |
| | | } finally { |
| | | Application.RunOnMainThread (() => { |
| | | MainPage.Loading.Hide (); |
| | | }); |
| | | } |
| | | }); |
| | | |
| | | }; |
| | | |
| | | if(!guide) |
| | |
| | | /// </summary> |
| | | /// <param name="home">Home.</param> |
| | | /// <param name="residenceName">Et zone name string.</param> |
| | | bool EditResidence (RegionInfoRes home,string residenceName) |
| | | bool EditResidence (RegionInfoRes home, string residenceName, bool goToGuideAddGatewayView = false) |
| | | { |
| | | if (home.Name != residenceName) { |
| | | home.Name = residenceName; |
| | | |
| | | if (string.IsNullOrEmpty(home.Id)) { |
| | | var requestObj21 = new AddHomeObj () { |
| | | Name = residenceName , |
| | |
| | | ShowAddHomeErrorInfo (revertObj21.StateCode); |
| | | 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); |
| | | |
| | | } |
| | | } else { |
| | | var requestObj2 = new EditHomeObj () { HomeId = home.Id, Name = home.Name }; |
| | | 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); |
| | | IO.FileUtils.ReNameFoler (UserConfig.Instance.CurrentRegion.Name, home.Name); |
| | | var revertObj2 = MainPage.RequestHttps (API.EditHome, requestJson2, urlHead); |
| | | if (revertObj2.StateCode.ToUpper() != "SUCCESS") { |
| | | ShowEditHomeErrorInfo (revertObj2.StateCode); |
| | | return false; |
| | | } |
| | | home.Name = residenceName; |
| | | IO.FileUtils.ReNameFoler (UserConfig.Instance.CurrentRegion.Name, home.Name); |
| | | ChangeRegion (home, false, true, goToGuideAddGatewayView); |
| | | //CheckIfNeedAddRoom (); |
| | | } |
| | | UserConfig.Instance.CurrentRegion = home; |
| | | UserConfig.Instance.SaveUserConfig (); |
| | | |
| | | //ShowHomeList (false); |
| | | //2020-01-09 去掉切换住宅 |
| | | //UserConfig.Instance.CurrentRegion = home; |
| | | //UserConfig.Instance.SaveUserConfig (); |
| | | }else { |
| | | ChangeRegion (home, false, true, goToGuideAddGatewayView); |
| | | //CheckIfNeedAddRoom (); |
| | | } |
| | | return true; |
| | | |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 检测是否默认创建房间 |
| | | /// </summary> |
| | | void CheckIfNeedAddRoom () { |
| | | if (Room.Lists.FindAll ((obj) => obj.Name == "Living Room" || obj.Name == "Bedroom").Count == 0) { |
| | | Room room = new Room (); |
| | | string newRoomFilePath = typeof (Room).Name + "_Living Room"; |
| | |
| | | room.Add (newRoomFilePath); |
| | | room.Save (newRoomFilePath); |
| | | Room.Lists.Add (room); |
| | | |
| | | Room.InitAllRoom (); |
| | | } |
| | | if (home.Name != residenceName) { |
| | | ShowHomeList (); |
| | | } |
| | | return true; |
| | | |
| | | } |
| | | |
| | | |