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/Register/SubaccountListView.cs |  285 +++++++++++++++++++++++++++++++++++++++------------------
 1 files changed, 195 insertions(+), 90 deletions(-)

diff --git a/Crabtree/SmartHome/UI/SimpleControl/Phone/Register/SubaccountListView.cs b/Crabtree/SmartHome/UI/SimpleControl/Phone/Register/SubaccountListView.cs
index c383656..6cefea4 100644
--- a/Crabtree/SmartHome/UI/SimpleControl/Phone/Register/SubaccountListView.cs
+++ b/Crabtree/SmartHome/UI/SimpleControl/Phone/Register/SubaccountListView.cs
@@ -5,15 +5,28 @@
 {
     public class SubaccountListView : FrameLayout
     {
-        List<SubAccountRes> subaccountList;
+        /// <summary>
+        /// 
+        /// </summary>
+        List<ResidenceMemberInfo> subaccountList;
+        /// <summary>
+        /// 
+        /// </summary>
         VerticalScrolViewLayout subaccountListView;
 
-        public SubaccountListView (List<SubAccountRes> SubaccountList)
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <param name="SubaccountList"></param>
+        public SubaccountListView (List<ResidenceMemberInfo> SubaccountList)
         {
             BackgroundColor = SkinStyle.Current.MainColor;
             subaccountList = SubaccountList;
         }
 
+        /// <summary>
+        /// 
+        /// </summary>
         public void ShowSubaccountListView ()
         {
             #region ---TopView---
@@ -58,6 +71,11 @@
             topView.AddChidren (ItemButton);
             #endregion
 
+            //2020-07-01
+            if (UserConfig.Instance.CurrentRegion != null && !string.IsNullOrEmpty (UserConfig.Instance.CurrentRegion.Name)) {
+                NameButton.Text = UserConfig.Instance.CurrentRegion.Name;
+            }
+
             EventHandler<MouseEventArgs> addSubaccountHandler = (sender, e) => {
                 modifySubaccount (null);
             };
@@ -73,7 +91,7 @@
             Button btnUserIcon = new Button () {
                 X = Application.GetRealWidth (27),
                 Width = Application.GetRealWidth (96),
-                Height = Application.GetRealHeight (96),
+                Height = Application.GetRealWidth (96),
                 Gravity = Gravity.CenterVertical,
                 Radius = 5,
                 BorderColor = SkinStyle.Current.Transparent,
@@ -109,13 +127,34 @@
 
             VerticalScrolViewLayout contentView = new VerticalScrolViewLayout () {
                 Y = topUserMsgView.Bottom,
-                Height = Application.GetRealHeight (1136) - topUserMsgView.Bottom,
+                Height = Application.GetRealHeight (1136-80) - topUserMsgView.Bottom,
                 BackgroundColor = SkinStyle.Current.ViewColor,
                 ScrollEnabled = false,
             };
             AddChidren (contentView);
 
-         
+            //#region
+            ////褰撳墠浣忓畢
+            //FrameLayout homeView = new FrameLayout () {
+            //    Height = Application.GetRealHeight (100),
+            //    BackgroundColor = SkinStyle.Current.Transparent
+            //};
+            //contentView.AddChidren (homeView);
+
+            //Button btnHomeText = new Button () {
+            //    X = Application.GetRealWidth (40),
+            //    Width = Application.GetRealWidth (600),
+            //    //TextID = R.MyInternationalizationString.Subaccount,
+            //    TextAlignment = TextAlignment.CenterLeft,
+            //    TextColor = SkinStyle.Current.TextColor1,
+            //};
+            //homeView.AddChidren (btnHomeText);
+
+            //if (UserConfig.Instance.CurrentRegion != null && !string.IsNullOrEmpty (UserConfig.Instance.CurrentRegion.Name)) {
+            //    btnHomeText.Text = "Current residence: " + UserConfig.Instance.CurrentRegion.Name;
+            //}
+            //#endregion
+
             FrameLayout subaccountView = new FrameLayout () {
                 Height = Application.GetRealHeight (50),
                 BackgroundColor = SkinStyle.Current.MainColor
@@ -143,16 +182,41 @@
             };
             contentView.AddChidren (subaccountListView);
 
-            addSubaccountList ();
+            RefreshSubaccountList ();
 
+            addTipView ();
         }
 
-        void addSubaccountList ()
+        void addTipView () {
+            var TipView = new Button () {
+                Width = LayoutParams.MatchParent,
+                Y = Application.GetRealHeight (Application.DesignHeight - 80),
+                Height = Application.GetRealHeight (80),
+                BackgroundColor = 0xFFFFFFE0,
+                TextSize = 11,
+                TextColor = 0xFF1F1F1F,
+                TextAlignment = TextAlignment.Center,
+                IsMoreLines = true,
+                Text = "Manage the member list of the current residence and share it to other accounts. \n Tips: You need to add the registered member account.",
+
+            };
+            AddChidren (TipView);
+        }
+
+        /// <summary>
+        /// 鍒锋柊鎴愬憳鍒楄〃View
+        /// </summary>
+        void RefreshSubaccountList ()
         {
             subaccountListView.RemoveAll ();
+            if(subaccountList == null) {
+                subaccountList = new List<ResidenceMemberInfo> ();
+            }
             foreach (var subaccount in subaccountList) {
-                if (subaccount.UserType == 2)
-                    continue;
+                ////2020-01-07 甯︾‘璁�
+                //if (subaccount.AccountType == 2)
+                //    continue;
+
                 RowLayout subaccountRowView = new RowLayout () { 
                     Height = Application.GetRealHeight(110),
                 };
@@ -187,12 +251,12 @@
                 };
                 subaccountRowView.AddChidren (rightButton);
 
-                EventHandler<MouseEventArgs> eHandler = (sender, e) => {
-                    modifySubaccount (subaccount);
-                };
-                subaccountRowView.MouseUpEventHandler += eHandler;
-                btnDebugTitle.MouseUpEventHandler += eHandler;
-                rightButton.MouseUpEventHandler += eHandler;
+                //EventHandler<MouseEventArgs> eHandler = (sender, e) => {
+                //    modifySubaccount (subaccount);
+                //};
+                //subaccountRowView.MouseUpEventHandler += eHandler;
+                //btnDebugTitle.MouseUpEventHandler += eHandler;
+                //rightButton.MouseUpEventHandler += eHandler;
 
                 Button btnRowLine = new Button () { 
                     Y = Application.GetRealHeight(105),
@@ -216,14 +280,15 @@
                         if (e) {
                             MainPage.Loading.Start ("Please wait...");
                             try {
-                                var requestObj = new RemoveSubAccountObj () { Email = subaccount.Account };
-                                var requestJson = Newtonsoft.Json.JsonConvert.SerializeObject (requestObj);
-                                var revertObj = MainPage.RequestHttps ("RemoveSubAccount", requestJson);
-                                if (revertObj.StateCode == "SUCCESS") {
+                                var revertObj = HttpServerRequest.Current.DeleteResidenceMemberAccount (subaccount);
+                                if (revertObj.Code == StateCode.SUCCESS) {
                                     Application.RunOnMainThread (() => {
                                         subaccountList.Remove (subaccount);
-                                        addSubaccountList ();
+                                        RefreshSubaccountList ();
                                     });
+                                } else {
+                                    //閿欒鎻愮ず
+                                    IMessageCommon.Current.ShowErrorInfoAlter (revertObj.Code);
                                 }
                             } catch {
                                 MainPage.FailureToServer ();
@@ -238,17 +303,22 @@
             }
         }
 
-        void modifySubaccount (SubAccountRes subaccount)
+        /// <summary>
+        /// 娣诲姞鎴栬�呬慨鏀规垚鍛樹俊鎭紝鐩墠淇敼鍔熻兘宸插幓鎺�
+        /// </summary>
+        /// <param name="subaccount"></param>
+        void modifySubaccount (ResidenceMemberInfo subaccount)
         {
             bool isModify = true;
             if (subaccount == null) {
-                subaccount = new SubAccountRes ();
+                subaccount = new ResidenceMemberInfo ();
                 isModify = false;
             }
             Dialog dialog = new Dialog ();
             FrameLayout subaccountDialogView = new FrameLayout () {
                 Width = Application.GetRealWidth (500),
-                Height = Application.GetRealHeight (650 - 100),
+                //Height = Application.GetRealHeight (650 - 100),
+                Height = Application.GetRealHeight (390),
                 BackgroundColor = SkinStyle.Current.DialogColor,
                 Radius = 5,
                 BorderColor = SkinStyle.Current.Transparent,
@@ -290,16 +360,16 @@
             //    BorderColor = SkinStyle.Current.DialogTitle,
             //    BorderWidth = 2,
             //    TextAlignment = TextAlignment.Center,
-            //    Text = subaccount.Remark,
+            //    Text = subaccount.nickName,
             //};
             //subaccountDialogView.AddChidren (etSubaccountReamrk);
-            
+
             Button btnEmail = new Button () {
                 X = Application.GetRealWidth (40),
                 Y = btnTitle.Bottom + Application.GetRealHeight (30),
                 Width = Application.GetRealWidth (420),
                 Height = Application.GetRealHeight (40),
-                Text="User name",
+                Text = "SubAccount",
                 TextAlignment = TextAlignment.CenterLeft,
                 TextColor = SkinStyle.Current.TextColor,
             };
@@ -319,29 +389,29 @@
             };
             subaccountDialogView.AddChidren (etEmail);
 
-            Button btnSubaccountPassword = new Button () {
-                X = Application.GetRealWidth (40),
-                Y = etEmail.Bottom + Application.GetRealHeight (20),
-                Width = Application.GetRealWidth (420),
-                Height = Application.GetRealHeight (40),
-                TextID = R.MyInternationalizationString.Password,
-                TextAlignment = TextAlignment.CenterLeft,
-                TextColor = SkinStyle.Current.TextColor,
-            };
-            subaccountDialogView.AddChidren (btnSubaccountPassword);
+            //Button btnSubaccountPassword = new Button () {
+            //    X = Application.GetRealWidth (40),
+            //    Y = etEmail.Bottom + Application.GetRealHeight (20),
+            //    Width = Application.GetRealWidth (420),
+            //    Height = Application.GetRealHeight (40),
+            //    TextID = R.MyInternationalizationString.Password,
+            //    TextAlignment = TextAlignment.CenterLeft,
+            //    TextColor = SkinStyle.Current.TextColor,
+            //};
+            //subaccountDialogView.AddChidren (btnSubaccountPassword);
 
-            EditText etSubaccountPassword = new EditText () {
-                X = Application.GetRealWidth (40),
-                Y = btnSubaccountPassword.Bottom,
-                Width = Application.GetRealWidth (420),
-                Height = Application.GetRealHeight (80),
-                TextColor = SkinStyle.Current.TextColor,
-                Radius = 5,
-                BorderColor = SkinStyle.Current.DialogTitle,
-                BorderWidth = 2,
-                TextAlignment = TextAlignment.Center,
-            };
-            subaccountDialogView.AddChidren (etSubaccountPassword);
+            //EditText etSubaccountPassword = new EditText () {
+            //    X = Application.GetRealWidth (40),
+            //    Y = btnSubaccountPassword.Bottom,
+            //    Width = Application.GetRealWidth (420),
+            //    Height = Application.GetRealHeight (80),
+            //    TextColor = SkinStyle.Current.TextColor,
+            //    Radius = 5,
+            //    BorderColor = SkinStyle.Current.DialogTitle,
+            //    BorderWidth = 2,
+            //    TextAlignment = TextAlignment.Center,
+            //};
+            //subaccountDialogView.AddChidren (etSubaccountPassword);
 
             FrameLayout bottomView = new FrameLayout () {
                 Y = subaccountDialogView.Height - Application.GetRealHeight (90),
@@ -379,58 +449,62 @@
 
             btnSaveSubaccount.MouseUpEventHandler += (sender3, e3) => {
                 string addSubaccount = etEmail.Text.Trim ();
-                string addSubaccountPassword = etSubaccountPassword.Text.Trim ();
-                string addSubaccountReamrk = DateTime.Now.Ticks.ToString();
+                //string addSubaccountPassword = etSubaccountPassword.Text.Trim ();
+                //string addSubaccountReamrk = DateTime.Now.Ticks.ToString();
                 //string addSubaccountReamrk = etSubaccountReamrk.Text.Trim ();
                 if (string.IsNullOrEmpty (addSubaccount)) {
                     new Tip () { MaxWidth = 250, Text = Language.StringByID (R.MyInternationalizationString.TipEntrySubaccount), Direction = AMPopTipDirection.Down, CloseTime = 3 }.Show(etEmail);
                     return;
                 }
-                if (string.IsNullOrEmpty (addSubaccountPassword)) {
-                    new Tip () { MaxWidth = 250, Text = Language.StringByID (R.MyInternationalizationString.PleaseEnterPassword), Direction = AMPopTipDirection.Down, CloseTime = 3 }.Show(etSubaccountPassword);
-                    return;
-                }
-                if(string.IsNullOrEmpty (addSubaccountReamrk)){
-                    //new Tip () { MaxWidth = 250, Text = Language.StringByID (R.MyInternationalizationString.TipEntrySubaccountRemark), Direction = AMPopTipDirection.Down, CloseTime = 3 }.Show(etSubaccountReamrk);
-                    //return;
-                }if (addSubaccountPassword.Length < 6) {
-                    new Tip () { MaxWidth = 250, Text = Language.StringByID (R.MyInternationalizationString.PasswordLenghtTip), Direction = AMPopTipDirection.Down, CloseTime = 3 }.Show (etSubaccountPassword);
-                    return;
-                }
+                //if (string.IsNullOrEmpty (addSubaccountPassword)) {
+                //    new Tip () { MaxWidth = 250, Text = Language.StringByID (R.MyInternationalizationString.PleaseEnterPassword), Direction = AMPopTipDirection.Down, CloseTime = 3 }.Show(etSubaccountPassword);
+                //    return;
+                //}
+                //if (string.IsNullOrEmpty (addSubaccountReamrk)) {
+                //    new Tip () { MaxWidth = 250, Text = Language.StringByID (R.MyInternationalizationString.TipEntrySubaccountRemark), Direction = AMPopTipDirection.Down, CloseTime = 3 }.Show (etSubaccountReamrk);
+                //    return;
+                //}
+                //if (addSubaccountPassword.Length < 6) {
+                //    new Tip () { MaxWidth = 250, Text = Language.StringByID (R.MyInternationalizationString.PasswordLenghtTip), Direction = AMPopTipDirection.Down, CloseTime = 3 }.Show (etSubaccountPassword);
+                //    return;
+                //}
                 MainPage.Loading.Start ("Please wait...");
 
-                subaccount.Account = addSubaccount;
-                subaccount.Remark = addSubaccountReamrk;
+                //subaccount.Account = addSubaccount;
+                //subaccount.Remark = addSubaccountReamrk;
                 System.Threading.Tasks.Task.Run (() => {
                     try {
                         if (isModify) {
-                            var requestObj = new EditSubAccountObj () { Id = subaccount.UserID, Email = addSubaccount, Password = addSubaccountPassword, Remark = addSubaccountReamrk };
-                            var requestJson = Newtonsoft.Json.JsonConvert.SerializeObject (requestObj);
-                            var revertObj = MainPage.RequestHttps ("EditSubAccount", requestJson);
-                            if (revertObj.StateCode == "SUCCESS") {
-                                Application.RunOnMainThread (() => {
-                                    addSubaccountList ();
-                                    dialog.Close ();
-                                });
-                            }
+                            //var requestObj = new EditSubAccountObj () { Id = subaccount.UserID, Email = addSubaccount, Password = addSubaccountPassword, Remark = addSubaccountReamrk };
+                            //var requestJson = Newtonsoft.Json.JsonConvert.SerializeObject (requestObj);
+                            //var revertObj = MainPage.RequestHttps ("EditSubAccount", requestJson, true);
+                            //if (revertObj.StateCode.ToUpper() == StateCode.SUCCESS) {
+                            //    Application.RunOnMainThread (() => {
+                            //        addSubaccountList ();
+                            //        dialog.Close ();
+                            //    });
+                            //}
                         } else {
-                            var requestObj = new SignSubAccountObj () { Email = addSubaccount, Password = addSubaccountPassword, Remark = addSubaccountReamrk };
-                            var requestJson = Newtonsoft.Json.JsonConvert.SerializeObject (requestObj);
-                            var revertObj = MainPage.RequestHttps ("SignSubAccount", requestJson);
-                            if (revertObj.StateCode == "SUCCESS") {
-                                var requestObj2 = new GetSubAccountListObj ();
-                                var requesetJson2 = Newtonsoft.Json.JsonConvert.SerializeObject (requestObj2);
-                                var requesetRevertObj2 = MainPage.RequestHttps ("GetSubAccountList", requesetJson2);
-                                if (requesetRevertObj2.StateCode == "SUCCESS") {
-                                    var responseDataObj = Newtonsoft.Json.JsonConvert.DeserializeObject<List<SubAccountRes>> (requesetRevertObj2.ResponseData.ToString ());
+                            //娣诲姞瀛愯处鍙�
+                            var revertObj = HttpServerRequest.Current.BindResidenceMemberAccount (addSubaccount, addSubaccount);
+                            if (revertObj.Code == StateCode.SUCCESS) {
+                                var revertObj2 = HttpServerRequest.Current.GetResidenceMemberAccount ();
+                                if (revertObj2.Code == StateCode.SUCCESS) {
+                                    var responseDataObj = Newtonsoft.Json.JsonConvert.DeserializeObject<List<ResidenceMemberInfo>> (revertObj2.Data.ToString ());
                                     subaccountList = responseDataObj;
                                     Application.RunOnMainThread (() => {
-                                        new Alert ("", Language.StringByID (R.MyInternationalizationString.addsuccess),
+                                        new Alert ("", Language.StringByID (R.MyInternationalizationString.AddedSuccessfully),
                                                    Language.StringByID (R.MyInternationalizationString.Close)).Show ();
-                                        addSubaccountList ();
+                                        RefreshSubaccountList ();
                                         dialog.Close ();
                                     });
+                                } else {
+                                    //閿欒鎻愮ず
+                                    IMessageCommon.Current.ShowErrorInfoAlter (revertObj2.Code);
                                 }
+                            } else {
+                                //BindSubAccount閿欒鎻愮ず
+                                IMessageCommon.Current.ShowErrorInfoAlter (revertObj.Code);
                             }
                         }
                     } catch (Exception ex) {
@@ -438,7 +512,7 @@
                             new Alert ("", Language.StringByID (R.MyInternationalizationString.FailureToServer),
                                        Language.StringByID (R.MyInternationalizationString.Close)).Show ();
                         });
-                        Console.WriteLine (ex.ToString());
+                        Utlis.WriteLine (ex.ToString());
                     } finally {
                         Application.RunOnMainThread (() => {
                             MainPage.Loading.Hide ();
@@ -450,13 +524,44 @@
             //etSubaccountReamrk.EditorEnterAction += (obj) => {
             //    etEmail.Foucs = true;
             //};
-            etEmail.EditorEnterAction += (obj) => {
-                etSubaccountPassword.Foucs = true;
-            };
-            etSubaccountPassword.EditorEnterAction += (obj) => {
-                Application.HideSoftInput ();
-            };
+            //etEmail.EditorEnterAction += (obj) => {
+            //    etSubaccountPassword.Foucs = true;
+            //};
+            //etSubaccountPassword.EditorEnterAction += (obj) => {
+            //    Application.HideSoftInput ();
+            //};
             dialog.Show ();
         }
+
+
+        ///// <summary>
+        ///// 鑾峰彇瀛愯处鍙峰垪琛�
+        ///// </summary>
+        //void GetSubaccountList ()
+        //{
+        //    subaccountListView.RemoveAll ();
+        //    subaccountList = new List<ResidenceMemberInfo> ();
+
+        //    MainPage.Loading.Start ("Please wait...");
+        //    System.Threading.Tasks.Task.Run (() => {
+        //        try {
+        //            var revertObj = HttpServerRequest.Current.GetResidenceMemberAccount ();
+        //            if (revertObj.Code == StateCode.SUCCESS) {
+        //                var responseDataObj = Newtonsoft.Json.JsonConvert.DeserializeObject<List<ResidenceMemberInfo>> (revertObj.Data.ToString ());
+        //                subaccountList = responseDataObj;
+        //            } else {
+        //                IMessageCommon.Current.ShowErrorInfoAlter (revertObj.Code);
+        //            }
+        //        } catch (Exception ex) {
+        //            //MainPage.FailureToServer ();
+        //            Utlis.WriteLine (ex.Message);
+        //        } finally {
+        //            Application.RunOnMainThread (() => {
+        //                RefreshSubaccountList ();
+        //                MainPage.Loading.Hide ();
+        //            });
+        //        }
+        //    });
+        //}
     }
 }
\ No newline at end of file

--
Gitblit v1.8.0