From 9a4b76398009cf76c508d61f7e48fb6f5cb7ac2d Mon Sep 17 00:00:00 2001
From: xm <1271024303@qq.com>
Date: 星期二, 21 七月 2020 09:46:53 +0800
Subject: [PATCH] 请合并最新多功能面板代码

---
 ZigbeeApp/Shared/Phone/UserCenter/Residence/ResidenceListForm.cs |  120 +++++++++++++++++++++++-------------------------------------
 1 files changed, 46 insertions(+), 74 deletions(-)

diff --git a/ZigbeeApp/Shared/Phone/UserCenter/Residence/ResidenceListForm.cs b/ZigbeeApp/Shared/Phone/UserCenter/Residence/ResidenceListForm.cs
index 0dd08fd..3300808 100755
--- a/ZigbeeApp/Shared/Phone/UserCenter/Residence/ResidenceListForm.cs
+++ b/ZigbeeApp/Shared/Phone/UserCenter/Residence/ResidenceListForm.cs
@@ -23,10 +23,6 @@
         /// 浣忓畢鏁版嵁(鏃犵綉鏃朵娇鐢�)
         /// </summary>
         private List<House> listLocalHouse = null;
-        /// <summary>
-        /// 浣忓畢椤哄簭
-        /// </summary>
-        private List<string> listResidenceSort = new List<string>();
 
         #endregion
 
@@ -67,13 +63,6 @@
             //娓呯┖bodyFrame
             this.ClearBodyFrame();
 
-            //璇诲彇浣忓畢椤哄簭
-            var strData = UserCenterLogic.LoadFileContent(UserCenterLogic.CombinePath(DirNameResourse.LocalMemoryDirectory, DirNameResourse.ResidenceSortFile));
-            if (strData != null)
-            {
-                listResidenceSort = Newtonsoft.Json.JsonConvert.DeserializeObject<List<string>>(strData);
-            }
-
             listView = new VerticalListControl(29);
             listView.Height = bodyFrameLayout.Height + Application.GetRealHeight(6);
             listView.BackgroundColor = UserCenterColor.Current.White;
@@ -89,7 +78,7 @@
         /// <param name="div">1:鍏堣鍙栦簯绔�,鏃犳硶鑱旂綉,鍐嶈鍙栨湰鍦�  2:鍙浜戠  3:鍙鏈湴</param>
         private void SetResidenceInfo(int div)
         {
-            HdlThreadLogic.Current.RunThread(async () =>
+            HdlThreadLogic.Current.RunThread(() =>
             {
                 //铏氭嫙浣忓畢鐨勮瘽,鍙鏈湴
                 if (div == 3 || Config.Instance.Home.IsVirtually == true)
@@ -102,7 +91,7 @@
                     //寮�鍚繘搴︽潯
                     this.ShowProgressBar();
                     //璁剧疆浣忓畢淇℃伅(鏈夌綉鎯呭喌)
-                    var result = await this.SetResidenceInfoByOnline();
+                    var result = this.SetResidenceInfoByOnline();
                     if (result == true)
                     {
                         //浜戠璇诲彇鎴愬姛
@@ -131,13 +120,12 @@
         /// <summary>
         /// 璁剧疆浣忓畢淇℃伅(鏈夌綉鎯呭喌)
         /// </summary>
-        private async System.Threading.Tasks.Task<bool> SetResidenceInfoByOnline()
+        private bool SetResidenceInfoByOnline()
         {
             //鑾峰彇浣忓畢淇℃伅
             var Pra = new GetResidenceInfoPra();
-            var listNotCheck = new List<string>() { "NotSetAgain" };
-            string resultData = await UserCenterLogic.GetResponseDataByRequestHttps("App/GetHomePager", false, Pra, listNotCheck);
-            if (resultData == null)
+            string resultData = UserCenterLogic.GetResponseDataByRequestHttps("App/GetHomePager", false, Pra, new List<string> { "NotCheck" });
+            if (string.IsNullOrEmpty(resultData) == true)
             {
                 return false;
             }
@@ -145,27 +133,12 @@
 
             //鏆傛椂瀛樺偍鏁版嵁
             var dicData = new Dictionary<string, Common.ResponseEntity.ResidenceObj>();
+            var listResidenceSort = new List<string>();
             for (int i = 0; i < pageData.PageData.Count; i++)
             {
                 dicData[pageData.PageData[i].Id] = pageData.PageData[i];
-                if (listResidenceSort.Contains(pageData.PageData[i].Id) == false)
-                {
-                    //鏂版坊鍔犵殑浣忓畢
-                    listResidenceSort.Add(pageData.PageData[i].Id);
-                }
+                listResidenceSort.Add(pageData.PageData[i].Id);
             }
-            for (int i = 0; i < listResidenceSort.Count; i++)
-            {
-                //绉婚櫎鎺変笉瀛樺湪浜嗙殑椤哄簭
-                if (dicData.ContainsKey(listResidenceSort[i]) == false)
-                {
-                    listResidenceSort.RemoveAt(i);
-                    i--;
-                }
-            }
-            //淇濆瓨椤哄簭
-            string fullName = UserCenterLogic.CombinePath(DirNameResourse.LocalMemoryDirectory, DirNameResourse.ResidenceSortFile);
-            UserCenterLogic.SaveFileContent(fullName, listResidenceSort);
 
             HdlThreadLogic.Current.RunMain(() =>
             {
@@ -215,14 +188,14 @@
                 btnHome = rowLayout.frameTable.AddLeftCaption(info.Name, 800, 60, true);
                 btnHome.TextSize = 15;
                 btnHome.Y = Application.GetRealHeight(12) + rowLayout.chidrenYaxis;
-                rowLayout.frameTable.AddChidren(btnHome, ChidrenBindMode.BindEventOnly);
+                rowLayout.frameTable.AddChidren(btnHome, ChidrenBindMode.BindEvent);
 
                 //褰撳墠浣忓畢
                 var btnNowView = rowLayout.frameTable.AddLeftCaption(Language.StringByID(R.MyInternationalizationString.uNowResidence), 800, 49, true);
                 btnNowView.Y = Application.GetRealHeight(72) + rowLayout.chidrenYaxis;
                 btnNowView.TextSize = 12;
                 btnNowView.TextColor = UserCenterColor.Current.TextGrayColor1;
-                rowLayout.frameTable.AddChidren(btnNowView, ChidrenBindMode.BindEventOnly);
+                rowLayout.frameTable.AddChidren(btnNowView, ChidrenBindMode.BindEvent);
             }
             else
             {
@@ -250,7 +223,7 @@
                     }
                     this.ShowMassage(ShowMsgType.Confirm, msg, () =>
                     {
-                        HdlThreadLogic.Current.RunThread(async () =>
+                        HdlThreadLogic.Current.RunThread(() =>
                         {
                             //寮�鍚繘搴︽潯
                             this.ShowProgressBar();
@@ -258,12 +231,7 @@
                             //妫�娴嬫湰鍦版湁娌℃湁杩欎釜浣忓畢
                             this.CheckIsExsitResidence(info);
 
-                            Config.Instance.HomeId = info.Id;
-                            //閲嶆柊鍒濆鍖栦綇瀹呭璞�
-                            Config.Instance.Home = House.GetHouseByHouseId(info.Id);
-                            Config.Instance.Save();
-                            //鍒锋柊涓汉涓績鐨勫唴瀛樺強绾跨▼
-                            await UserCenterLogic.InitUserCenterMenmoryAndThread(false);
+                            HdlResidenceLogic.Current.SwitchResidence(info.Id);
 
                             HdlThreadLogic.Current.RunMain(() =>
                             {
@@ -350,14 +318,14 @@
                 btnHome = rowLayout.frameTable.AddLeftCaption(i_home.Name, 800, 60, true);
                 btnHome.TextSize = 15;
                 btnHome.Y = Application.GetRealHeight(12) + rowLayout.chidrenYaxis;
-                rowLayout.frameTable.AddChidren(btnHome, ChidrenBindMode.BindEventOnly);
+                rowLayout.frameTable.AddChidren(btnHome, ChidrenBindMode.BindEvent);
 
                 //褰撳墠浣忓畢
                 var btnNowView = rowLayout.frameTable.AddLeftCaption(Language.StringByID(R.MyInternationalizationString.uNowResidence), 800, 49, true);
                 btnNowView.Y = Application.GetRealHeight(72) + rowLayout.chidrenYaxis;
                 btnNowView.TextSize = 12;
                 btnNowView.TextColor = UserCenterColor.Current.TextGrayColor1;
-                rowLayout.frameTable.AddChidren(btnNowView, ChidrenBindMode.BindEventOnly);
+                rowLayout.frameTable.AddChidren(btnNowView, ChidrenBindMode.BindEvent);
             }
             else
             {
@@ -385,16 +353,9 @@
                     }
                     this.ShowMassage(ShowMsgType.Confirm, msg, () =>
                     {
-                        HdlThreadLogic.Current.RunThread(async () =>
+                        HdlThreadLogic.Current.RunThread(() =>
                         {
-                            this.ShowProgressBar();
-
-                            Config.Instance.HomeId = i_home.Id;
-                            //閲嶆柊鍒濆鍖栦綇瀹呭璞�
-                            Config.Instance.Home = House.GetHouseByHouseId(i_home.Id);
-                            Config.Instance.Save();
-                            //鍒锋柊涓汉涓績鐨勫唴瀛樺強绾跨▼
-                            await UserCenterLogic.InitUserCenterMenmoryAndThread(false);
+                            HdlResidenceLogic.Current.SwitchResidence(i_home.Id);
 
                             HdlThreadLogic.Current.RunMain(() =>
                             {
@@ -462,7 +423,10 @@
                     if (info != null)
                     {
                         //缂栬緫浜戠鐨勪綇瀹呭悕绉�
-                        this.EditorResidenceName(textValue, info, btnHome);
+                        HdlThreadLogic.Current.RunThread(() =>
+                        {
+                            this.EditorResidenceName(textValue, info, btnHome);
+                        });
                     }
                     else
                     {
@@ -472,7 +436,7 @@
                             return;
                         }
                         //鍒锋柊鍐呭瓨鐨勪綇瀹呭悕
-                        House.EditorHouseByHouseId(i_house.Id, textValue);
+                        HdlResidenceLogic.Current.EditorHouseByHouseId(i_house.Id, textValue);
                         //鏇存敼鏄剧ず鐨勫悕瀛�
                         btnHome.Text = textValue;
                     }
@@ -486,7 +450,7 @@
         /// <param name="ResidenceName"></param>
         /// <param name="info"></param>
         /// <returns></returns>
-        private async void EditorResidenceName(string ResidenceName, Common.ResponseEntity.ResidenceObj info, NormalViewControl btnHome)
+        private void EditorResidenceName(string ResidenceName, Common.ResponseEntity.ResidenceObj info, NormalViewControl btnHome)
         {
             //妫�娴嬭兘鍚︿繚瀛樹綇瀹�
             if (this.CheckIsCanSaveResidence(info.Id, ResidenceName, true) == false)
@@ -503,16 +467,20 @@
             Pra.LoginAccessToken = Config.Instance.Token;
 
             //缂栬緫浣忓畢
-            bool flage = await UserCenterLogic.GetResultStatuByRequestHttps("App/EditHome", false, Pra);
+            bool flage = UserCenterLogic.GetResultStatuByRequestHttps("App/EditHome", false, Pra, new List<string> { "NotCheck" });
             //鍏抽棴杩涘害鏉�
             this.CloseProgressBar();
 
             if (flage == true)
             {
-                //鍒锋柊鍐呭瓨鐨勪綇瀹呭悕
-                House.EditorHouseByHouseId(info.Id, ResidenceName);
-                //鏇存敼鏄剧ず鐨勫悕瀛�
-                btnHome.Text = ResidenceName;
+                HdlThreadLogic.Current.RunMain(() =>
+                {
+                    //鍒锋柊鍐呭瓨鐨勪綇瀹呭悕
+                    HdlResidenceLogic.Current.EditorHouseByHouseId(info.Id, ResidenceName);
+                    //鏇存敼鏄剧ず鐨勫悕瀛�
+                    btnHome.Text = ResidenceName;
+                    info.Name = ResidenceName;
+                });
             }
         }
 
@@ -545,7 +513,10 @@
                 dialogForm.CloseDialog();
 
                 //淇濆瓨浣忓畢
-                this.AddNewResidence(textValue);
+                HdlThreadLogic.Current.RunThread(() =>
+                {
+                    this.AddNewResidence(textValue);
+                });
             });
         }
 
@@ -554,7 +525,7 @@
         /// </summary>
         /// <param name="ResidenceName"></param>
         /// <returns></returns>
-        private async void AddNewResidence(string ResidenceName)
+        private void AddNewResidence(string ResidenceName)
         {
             //妫�娴嬭兘鍚︿繚瀛樹綇瀹�
             if (this.CheckIsCanSaveResidence(string.Empty, ResidenceName, false) == false)
@@ -567,8 +538,8 @@
             var Pra = new AddResidencePra();
             Pra.Name = ResidenceName;
             //娣诲姞浣忓畢
-            string resultData = await UserCenterLogic.GetResponseDataByRequestHttps("App/AddHome", false, Pra);
-            if (resultData == null)
+            string resultData = UserCenterLogic.GetResponseDataByRequestHttps("App/AddHome", false, Pra);
+            if (string.IsNullOrEmpty(resultData) == true)
             {
                 //鍏抽棴杩涘害鏉�
                 this.CloseProgressBar();
@@ -577,10 +548,15 @@
 
             var newInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<List<NewResidenceInfo>>(resultData);
 
-            House.AddHouse(newInfo[0].Id, ResidenceName, 0);
-            //閲嶆柊鍒锋柊鍒楄〃
-            this.listView.RemoveAll();
-            this.SetResidenceInfo(2);
+            HdlResidenceLogic.Current.AddHouseToMemmory(newInfo[0].Id, ResidenceName);
+
+            HdlThreadLogic.Current.RunMain(() =>
+            {
+                //閲嶆柊鍒锋柊鍒楄〃
+                this.listView.RemoveAll();
+                this.SetResidenceInfo(2);
+            });
+
         }
 
         #endregion
@@ -739,10 +715,6 @@
                 {
                     if (Config.Instance.HomeFilePathList.Contains($"House_{keys}.json") == false)
                     {
-                        //淇濆瓨椤哄簭
-                        listResidenceSort.Remove(keys);
-                        HdlRoomLogic.Current.SaveFloorSort(listResidenceSort);
-
                         this.listView.RemoveAll();
                         //鏁版嵁宸茬粡鍙樻洿 閲嶆柊璁剧疆浣忓畢淇℃伅
                         this.SetResidenceInfo(2);

--
Gitblit v1.8.0