From 5a5a2b696866f947b6025d26c3302e8ffef46435 Mon Sep 17 00:00:00 2001
From: JLChen <551775569@qq.com>
Date: 星期一, 11 一月 2021 16:11:20 +0800
Subject: [PATCH] 2021-01-11 1.更新MQTT连接和本地搜索网关方法。2.子账号相关接口完善
---
Crabtree/SmartHome/UI/SimpleControl/Phone/Guide/GuideAddResidence.cs | 599 +++++++++++++++++++++++++++++++++++++++++++----------------
1 files changed, 438 insertions(+), 161 deletions(-)
diff --git a/Crabtree/SmartHome/UI/SimpleControl/Phone/Guide/GuideAddResidence.cs b/Crabtree/SmartHome/UI/SimpleControl/Phone/Guide/GuideAddResidence.cs
index 8fb12fd..9def5f4 100644
--- a/Crabtree/SmartHome/UI/SimpleControl/Phone/Guide/GuideAddResidence.cs
+++ b/Crabtree/SmartHome/UI/SimpleControl/Phone/Guide/GuideAddResidence.cs
@@ -5,13 +5,93 @@
{
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 {
@@ -30,14 +110,13 @@
}
}) { IsBackground = true }.Start ();
});
- // 璇诲彇浣忓畢鍒楄〃
- var requestJson2 = Newtonsoft.Json.JsonConvert.SerializeObject (new HomeListObj ());
- var revertObj2 = MainPage.RequestHttps ("HomeList", requestJson2);
- if (revertObj2.StateCode == "SUCCESS") {
- var responseDataObj = Newtonsoft.Json.JsonConvert.DeserializeObject<List<RegionInfoRes>> (revertObj2.ResponseData.ToString ());
- UserConfig.Instance.HomeLists = responseDataObj;
- if (UserConfig.Instance.HomeLists.Count > 0) {
- if (string.IsNullOrEmpty (UserConfig.Instance.HomeLists [0].RegionName)) {
+
+ //鑾峰彇浣忓畢鍒楄〃
+ 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 ();
this.RemoveFromParent ();
@@ -45,7 +124,13 @@
});
}
UserConfig.Instance.SaveUserConfig ();
- UserConfig.Instance.CurrentRegion = responseDataObj.Find ((obj) => obj.RegionName == UserConfig.Instance.CurrentRegion.RegionName);
+ //2020-01-16
+ var mHome = mHomeLists.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 ();
@@ -54,6 +139,7 @@
return;
}
} else {
+ IMessageCommon.Current.ShowErrorInfoAlter (revertObjCode);
Application.RunOnMainThread (() => {
MainPage.Loading.Hide ();
this.RemoveFromParent ();
@@ -65,99 +151,95 @@
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 () { RegionID = "", RegionName = "" }, 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),
@@ -168,30 +250,42 @@
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",
SelectedImagePath = "Item/Point.png",
- Visible = home.RegionID != UserConfig.Instance.CurrentRegion.RegionID
+ Visible = home.Id != UserConfig.Instance.CurrentRegion.Id
};
rowView.AddChidren (btnPoint);
var btnName = new Button () {
Width = Application.GetRealWidth (390),
- Text = home.RegionName,
+ Text = home.Name,
TextAlignment = TextAlignment.CenterLeft,
X = Application.GetRealWidth (90),
TextColor = SkinStyle.Current.TextColor1,
};
rowView.AddChidren (btnName);
+ //鏄剧ず鍒嗕韩鎸夐挳
+ if (home.IsOthreShare) {
+ Button FromSharingButton = new Button () {
+ X = Application.GetRealWidth (480),
+ Width = Application.GetRealWidth (30),
+ Height = Application.GetRealWidth (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),
@@ -202,28 +296,36 @@
SelectedImagePath = "Item/RightSelected.png",
};
rowView.AddChidren (rightButton1);
+
EventHandler<MouseEventArgs> eHandler = (sender, e) => {
- if (home.RegionID == UserConfig.Instance.CurrentRegion.RegionID) {
- //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.Id == UserConfig.Instance.CurrentRegion.Id) {
+ 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)=> {
- if (home.RegionID == UserConfig.Instance.CurrentRegion.RegionID) {
- GuideAddHomeDialog (home, false,true, btnName);
+ btnName.MouseUpEventHandler += (sender, e) => {
+ if (home.Id == UserConfig.Instance.CurrentRegion.Id) {
+ if (home.IsOthreShare) {
+ //鎻愮ず娌℃湁鍒嗕韩浣忓畢鐨勬潈闄�
+ new Alert ("", ErrorCode.InsufficientAuthority, "Close").Show ();
+ return;
+ }
+ GuideAddHomeDialog (home, false, true, btnName);
} else {
ChangeRegion (home);
}
};
- if (home.RegionID == UserConfig.Instance.CurrentRegion.RegionID) {
+ if (home.Id == UserConfig.Instance.CurrentRegion.Id) {
Button btnCheck = new Button () {
X = Application.GetRealWidth (20),
Y = Application.GetRealHeight (25),
@@ -233,13 +335,19 @@
};
rowView.AddChidren (btnCheck);
}
- if (UserConfig.Instance.CurrentRegion.RegionID != home.RegionID && MainPage.LoginUser.AccountType != 1) {
+ if (UserConfig.Instance.CurrentRegion.Id != home.Id) {
Button btnDel = new Button () {
TextID = R.MyInternationalizationString.Del,
BackgroundColor = SkinStyle.Current.DelColor,
};
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 () {
@@ -320,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 (() => {
@@ -327,17 +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 ("Login", requestJson, false, false);
- if (revertObj.StateCode == "SUCCESS") {
- var requestObj2 = new DeleteHomeObj () { Id = home.RegionID };
- var requestJson2 = Newtonsoft.Json.JsonConvert.SerializeObject (requestObj2);
- var revertObj2 = MainPage.RequestHttps ("DeleteHome", requestJson2);
- if (revertObj2.StateCode == "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 (() => {
- ShowHomeList ();
+ GetHomeList ();
});
+ } else {
+ IMessageCommon.Current.ShowErrorInfoAlter (revertObj2.Code);
}
} else {
Application.RunOnMainThread (() => {
@@ -361,29 +470,102 @@
}
+ void ShowDelHomeErrorInfo (string stateCodeStr)
+ {
+ string mes = "";
+ if (stateCodeStr == "NoLogin") {
+ mes = ErrorCode.NoLogin;
+ } else if (stateCodeStr == "CurrentHomeExixtsGatewayBind") {
+ mes = ErrorCode.CurrentHomeExixtsGatewayBind;
+ } else if (stateCodeStr == ErrorCode.NetworkError) {
+ mes = ErrorCode.NetworkError;
+ } else {
+ //RequestServerFailed
+ //mes = ErrorCode.AddFailed;
+ mes = ErrorCode.OperationFailed + ErrorCode.Reason + stateCodeStr;
+
+ }
+ if (!string.IsNullOrEmpty (mes)) {
+ Application.RunOnMainThread (() => {
+ new Alert ("", mes, Language.StringByID (R.MyInternationalizationString.Close)).Show ();
+ });
+ }
+ }
+
+ /// <summary>
+ /// 鍚姩鏈湴妯″紡
+ /// </summary>
+ void EnableLocalMode () {
+ MainPage.AddTip ("Enable local mode.");
+ Utlis.ShowAppLinkStatus (AppLinkStatus.WiFiOffline);
+ CommonPage.IsRemote = false;
+ SmartHome.MqttCommon.DisConnectRemote ("EnableLocalMode", false);
+ }
+
+ /// <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.RegionName)) {
+ if (string.IsNullOrEmpty (UserConfig.Instance.CurrentRegion.Id)) {
UserConfig.Instance.CurrentRegion = UserConfig.Instance.HomeLists [0];
}
- string oldRegionRootPath = IO.FileUtils.CreateRegionBackup (UserConfig.Instance.CurrentRegion.RegionName);
+ 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 (() => {
@@ -392,30 +574,36 @@
});
}
IO.FileUtils.DeleteAllFile ();
- string newRegionRootPath = IO.FileUtils.CreateRegionBackup (home.RegionName);
+ 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;
+ }
+ 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 ();
@@ -479,17 +667,17 @@
Radius = 5,
BorderColor = SkinStyle.Current.BorderColor,
BorderWidth = 2,
- Text = home.RegionName,
+ Text = home.Name,
};
bodyView.AddChidren (etZoneName);
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),
@@ -506,30 +694,40 @@
};
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.RegionName = button.Text = etZoneName.Text;
- var requestObj2 = new EditHomeObj () { Id = home.RegionID, Name = home.RegionName };
- var requestJson2 = Newtonsoft.Json.JsonConvert.SerializeObject (requestObj2);
- var revertObj2 = MainPage.RequestHttps ("EditHome", requestJson2);
- IO.FileUtils.ReNameFoler (UserConfig.Instance.CurrentRegion.RegionName, home.RegionName);
- 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;
- }
+
+ //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, homeName, guide);
+
+ } catch {
+ //MainPage.FailureToServer ();
+ } finally {
+ Application.RunOnMainThread (() => {
+ MainPage.Loading.Hide ();
+ });
+ }
+ });
+
};
if(!guide)
@@ -561,29 +759,51 @@
/// </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.RegionName != residenceName) {
- home.RegionName = residenceName;
- if (string.IsNullOrEmpty(home.RegionID)) {
- var requestObj21 = new AddHomeObj () { Name = residenceName };
- var requestJson21 = Newtonsoft.Json.JsonConvert.SerializeObject (requestObj21);
- var revertObj21 = MainPage.RequestHttps ("AddHome", requestJson21);
- if ( revertObj21.StateCode != "SUCCESS") {
+ if (home.Name != residenceName) {
+
+ if (string.IsNullOrEmpty(home.Id)) {
+ var revertObj21 = HttpServerRequest.Current.AddHome (residenceName);
+ if (revertObj21.Code != StateCode.SUCCESS) {
+ IMessageCommon.Current.ShowErrorInfoAlter (revertObj21.Code);
return false;
}
+
+ home.Name = residenceName;
+ //鍒涘缓浣忓畢鎴愬姛锛屽垏鎹㈠埌璇ヤ綇瀹�
+ 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 () { Id = home.RegionID, Name = home.RegionName };
- var requestJson2 = Newtonsoft.Json.JsonConvert.SerializeObject (requestObj2);
- var revertObj2 = MainPage.RequestHttps ("EditHome", requestJson2);
- IO.FileUtils.ReNameFoler (UserConfig.Instance.CurrentRegion.RegionName, home.RegionName);
- if (revertObj2.StateCode != "SUCCESS") {
+ 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);
+ ChangeRegion (home, false, true, goToGuideAddGatewayView);
+ //CheckIfNeedAddRoom ();
}
- UserConfig.Instance.CurrentRegion = home;
- UserConfig.Instance.SaveUserConfig ();
+ }else {
+ ChangeRegion (home, false, true, goToGuideAddGatewayView);
}
+ 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";
@@ -600,12 +820,69 @@
room.Add (newRoomFilePath);
room.Save (newRoomFilePath);
Room.Lists.Add (room);
+
+ Room.InitAllRoom ();
}
- if (home.RegionName != residenceName) {
- ShowHomeList ();
+ }
+
+
+ void ShowAddHomeErrorInfo (string stateCodeStr) {
+ string mes = "";
+ if (stateCodeStr == "NoLogin") {
+ mes = ErrorCode.NoLogin;
+ } else if (stateCodeStr == "Exist") {
+ mes = ErrorCode.NameExist;
+ } else if (stateCodeStr == ErrorCode.NetworkError) {
+ mes = ErrorCode.NetworkError;
+ } else {
+ //RequestServerFailed
+ //mes = ErrorCode.AddFailed;
+ mes = ErrorCode.OperationFailed + ErrorCode.Reason + stateCodeStr;
+
}
- return true;
-
+ if (!string.IsNullOrEmpty (mes)) {
+ Application.RunOnMainThread (() => {
+ new Alert ("", mes, Language.StringByID (R.MyInternationalizationString.Close)).Show ();
+ });
+ }
+ }
+
+
+ /// <summary>
+ /// 鍝嶅簲鐘舵�佺爜:
+ //(1)Success 鍒� [璋冪敤姝ゆ帴鍙f搷浣滄垚鍔焆, ResponseData鍒欎负null
+ //(2)ParameterOrEmpty,鍒欏搷搴斿瓧娈典腑 [ErrorInfo] 涓洪敊璇俊鎭�, ResponseData鍒欎负null
+ //(3)NoLogin,鍒欏搷搴斿瓧娈典腑 [ErrorInfo] 涓洪敊璇俊鎭负 [鏃犳晥鐧诲綍Token!]
+ //(5)NoRecord,,鍒欏搷搴斿瓧娈典腑 [ErrorInfo] 涓洪敊璇俊鎭负 [鏈埌鐩稿叧璁板綍, 璇风‘璁ゆ偍鎻愪氦鍙傛暟鏄惁姝g‘]
+ //(6)Exist,鍒欏搷搴斿瓧娈典腑 [ErrorInfo] 涓洪敊璇俊鎭负 [褰撳墠鎻愪氦鐨勭殑浣忓畢:XXXX锛屽悕绉板凡瀛樺湪!]
+ //(7)NoPermission,鍒欏搷搴斿瓧娈典腑 [ErrorInfo] 涓洪敊璇俊鎭负 [鎮ㄥ苟涓嶅叿鏈夋鍒嗕韩鑰呮浣忓畢鐨勬潈闄�!]
+ //(8)InsufficientAuthority,鍒欏搷搴斿瓧娈典腑 [ErrorInfo] 涓洪敊璇俊鎭负 [鎮ㄥ苟涓嶅叿鏈夋鍒嗕韩鑰呮浣忓畢鐨勫畬鍏ㄦ帶鍒舵潈闄�!]
+ //(9)HomeIdAndTokenNoConsistent,鍒欏搷搴斿瓧娈典腑 [ErrorInfo] 涓洪敊璇俊鎭负 [鎮ㄥ綋鍓峊oken涓庝綘褰撳墠鎺у埗鐨凥omeId涓嶄竴鑷�!]
+ //(10)NoPermission,鍒欏搷搴斿瓧娈典腑 [ErrorInfo] 涓洪敊璇俊鎭负 [XXX]
+ /// </summary>
+ /// <param name="stateCodeStr"></param>
+ void ShowEditHomeErrorInfo (string stateCodeStr)
+ {
+ string mes = "";
+ if (stateCodeStr == "NoLogin") {
+ mes = ErrorCode.NoLogin;
+ } else if (stateCodeStr == "Exist") {
+ mes = ErrorCode.NameExist;
+ } else if (stateCodeStr == "HomeIdAndTokenNoConsistent") {
+ mes = ErrorCode.HomeIdAndTokenNoConsistent;
+ } else if (stateCodeStr == ErrorCode.NetworkError) {
+ mes = ErrorCode.NetworkError;
+ } else {
+ //RequestServerFailed
+ //mes = ErrorCode.AddFailed;
+ mes = ErrorCode.OperationFailed + ErrorCode.Reason + stateCodeStr;
+
+ }
+ if (!string.IsNullOrEmpty (mes)) {
+ Application.RunOnMainThread (() => {
+ new Alert ("", mes, Language.StringByID (R.MyInternationalizationString.Close)).Show ();
+ });
+ }
}
}
}
--
Gitblit v1.8.0