From 3272ca5b51e19f7f8a827b0f68400570a547fe60 Mon Sep 17 00:00:00 2001
From: 陈嘉乐 <cjl@hdlchina.com.cn>
Date: 星期二, 28 四月 2020 15:02:44 +0800
Subject: [PATCH] 2020-04-28-1

---
 ZigbeeApp/Shared/Phone/UserCenter/Residence/ResidenceListForm.cs |  109 ++++++++++++++++++++++++++++++++++++++----------------
 1 files changed, 77 insertions(+), 32 deletions(-)

diff --git a/ZigbeeApp/Shared/Phone/UserCenter/Residence/ResidenceListForm.cs b/ZigbeeApp/Shared/Phone/UserCenter/Residence/ResidenceListForm.cs
index 99aac4c..393b9e2 100755
--- a/ZigbeeApp/Shared/Phone/UserCenter/Residence/ResidenceListForm.cs
+++ b/ZigbeeApp/Shared/Phone/UserCenter/Residence/ResidenceListForm.cs
@@ -68,7 +68,6 @@
             }
 
             listView = new VerticalListControl(29);
-            listView.Y = Application.GetRealHeight(-6);
             listView.Height = bodyFrameLayout.Height + Application.GetRealHeight(6);
             listView.BackgroundColor = UserCenterColor.Current.White;
             bodyFrameLayout.AddChidren(listView);
@@ -117,6 +116,15 @@
                     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);
@@ -132,12 +140,14 @@
                 this.dicResidenceData = new Dictionary<string, Common.ResponseEntity.ResidenceObj>();
                 for (int i = 0; i < listResidenceSort.Count; i++)
                 {
-                    var info = dicData[listResidenceSort[i]];
-                    if (info.IsOthreShare == false)
+                    if (dicData.ContainsKey(listResidenceSort[i]) == false)
                     {
-                        //鏀堕泦璇ヨ处鍙锋墍鎷ユ湁鐨勮嚜宸辩殑浣忓畢鐨勬暟鎹�
-                        this.dicResidenceData[info.Id] = info;
+                        continue;
                     }
+                    var info = dicData[listResidenceSort[i]];
+
+                    //鏀堕泦璇ヨ处鍙蜂綇瀹呯殑鏁版嵁
+                    this.dicResidenceData[info.Id] = info;
                     this.AddRowLayout(info, i != listResidenceSort.Count - 1);
                 }
                 //璋冩暣鍒楄〃鎺т欢鐨勯珮搴�
@@ -206,14 +216,19 @@
                     {
                         HdlThreadLogic.Current.RunThread(async () =>
                         {
-                            ProgressBar.Show();
+                            this.ShowProgressBar();
+
+                            //妫�娴嬫湰鍦版湁娌℃湁杩欎釜浣忓畢
+                            this.CheckIsExsitResidence(info);
+
                             Config.Instance.HomeId = info.Id;
-                            Global.CreateHomeDirectory(info.Id);
+                            //閲嶆柊鍒濆鍖栦綇瀹呭璞�
+                            Config.Instance.Home = House.GetHouseByHouseId(info.Id);
                             Config.Instance.Save();
                             //鍒锋柊涓汉涓績鐨勫唴瀛樺強绾跨▼
-                            await UserCenterLogic.InitUserCenterMenmoryAndThread();
+                            await UserCenterLogic.InitUserCenterMenmoryAndThread(false);
 
-                            Room.InitAllRoom();
+                            HdlRoomLogic.Current.InitAllRoom();
 
                             HdlThreadLogic.Current.RunMain(() =>
                             {
@@ -239,13 +254,8 @@
                 return;
             }
             //鏇存敼
-            var btnChanged = new NormalViewControl(Application.GetRealWidth(184), rowLayout.Height, false);
-            btnChanged.BackgroundColor = 0xff4a4a4a;
-            btnChanged.TextSize = 12;
-            btnChanged.TextColor = UserCenterColor.Current.White;
-            btnChanged.TextAlignment = TextAlignment.Center;
+            var btnChanged = rowLayout.AddEditorControl();
             btnChanged.TextID = R.MyInternationalizationString.uChanged1;
-            rowLayout.AddRightView(btnChanged);
             btnChanged.ButtonClickEvent += (sender, e) =>
             {
                 //鏄剧ず缂栬緫鍚嶇О鐣岄潰
@@ -264,8 +274,7 @@
         private void ShowEditorNameForm(Common.ResponseEntity.ResidenceObj info, NormalViewControl btnHome)
         {
             //鐢熸垚涓�涓脊绐楃敾闈�
-            var dialogForm = new DialogInputForm();
-            dialogForm.AddForm(DialogFrameMode.OnlyInput);
+            var dialogForm = new DialogInputControl();
             //缂栬緫浣忓畢
             dialogForm.SetTitleText(Language.StringByID(R.MyInternationalizationString.uChangedName));
             //璇疯緭鍏ヤ綇瀹呭悕绉�
@@ -283,7 +292,7 @@
                     return;
                 }
                 //鐢婚潰鍏抽棴
-                dialogForm.CloseForm();
+                dialogForm.CloseDialog();
 
                 if (info.Name != textValue)
                 {
@@ -341,8 +350,7 @@
         private void ShowAddNameForm()
         {
             //鐢熸垚涓�涓脊绐楃敾闈�
-            var dialogForm = new DialogInputForm();
-            dialogForm.AddForm(DialogFrameMode.OnlyInput);
+            var dialogForm = new DialogInputControl();
             //鍒涘缓浣忓畢
             dialogForm.SetTitleText(Language.StringByID(R.MyInternationalizationString.uCreatResidence));
             //璇疯緭鍏ヤ綇瀹呭悕绉�
@@ -358,7 +366,7 @@
                     return;
                 }
                 //鐢婚潰鍏抽棴
-                dialogForm.CloseForm();
+                dialogForm.CloseDialog();
 
                 //淇濆瓨浣忓畢
                 this.AddNewResidence(textValue);
@@ -404,25 +412,57 @@
         #region 鈻� 涓�鑸柟娉昣__________________________
 
         /// <summary>
+        /// 妫�娴嬫湰鍦版湁娌℃湁杩欎釜浣忓畢
+        /// </summary>
+        /// <param name="info"></param>
+        private void CheckIsExsitResidence(Common.ResponseEntity.ResidenceObj info)
+        {
+            var path = System.IO.Path.Combine(Shared.IO.FileUtils.RootPath, Config.Instance.Guid, info.Id);
+            bool isExsit = System.IO.Directory.Exists(path);
+            if (isExsit == true) { return; }
+            //鍒涘缓鏂囦欢澶�
+            Global.CreateHomeDirectory(info.Id);
+            //鍒涘缓鏂扮殑浣忓畢
+            var house = new House();
+            house.Id = info.Id;
+            house.Name = info.Name;
+            house.IsOthreShare = info.IsOthreShare;
+            house.AccountType = info.AccountType;
+            house.MainUserDistributedMark = info.MainUserDistributedMark;
+            house.Longitude = info.Longitude;
+            house.Latitude = info.Latitude;
+            house.Save(false);
+
+            string fileName = house.FileName;
+            if (Config.Instance.HomeFilePathList.Contains(fileName) == false)
+            {
+                //娣诲姞鍒楄〃
+                Config.Instance.HomeFilePathList.Add(fileName);
+            }
+        }
+
+        /// <summary>
         /// 妫�娴嬭兘鍚﹀垹闄や綇瀹�
         /// </summary>
         /// <param name="info"></param>
         /// <returns></returns>
         private bool CheckIsCanDeleteResidence(Common.ResponseEntity.ResidenceObj info)
         {
-            if (this.dicResidenceData.Count == 1)
+            if (info.IsOthreShare == false)
             {
-                //濡傛灉姝よ处鍙蜂笅鍙墿涓嬪敮涓�涓�涓嚜宸辩殑浣忓畢锛屽綋鍒犻櫎杩欎釜浣忓畢鏃讹紝鎻愮ず涓嶈兘鍒犻櫎
-                //鍥犱负鏈�灏戣鏈変竴涓綇瀹�
-                if (this.dicResidenceData.ContainsKey(info.Id) == true)
+                int myCount = 0;
+                foreach (var data in this.dicResidenceData.Values)
+                {
+                    if (data.IsOthreShare == false)
+                    {
+                        myCount++;
+                    }
+                }
+                //濡傛灉姝よ处鍙蜂笅鍙墿涓嬪敮涓�涓�涓嚜宸辩殑浣忓畢锛屽垯涓嶈兘鍐嶅垹闄�
+                if (myCount == 1)
                 {
                     return false;
                 }
-            }
-            if (info.IsOthreShare == true)
-            {
-                //鍒嗕韩杩囨潵鐨勪綇瀹呬笉鑳藉垹闄�
-                return false;
             }
             return true;
         }
@@ -439,6 +479,11 @@
             //浣忓畢鍚嶅瓧閲嶅妫�娴�
             foreach (string strId in this.dicResidenceData.Keys)
             {
+                if (this.dicResidenceData[strId].IsOthreShare == true)
+                {
+                    //鍒嗕韩鐨勪綇瀹呬笉鑰冭檻
+                    continue;
+                }
                 if (residenceId != strId && residenceName == this.dicResidenceData[strId].Name)
                 {
                     //浣忓畢鍚嶅瓧宸茬粡瀛樺湪
@@ -466,7 +511,7 @@
                 {
                     //淇濆瓨椤哄簭
                     listResidenceSort.Remove(keys);
-                    Room.CurrentRoom.SaveFloorSort(listResidenceSort);
+                    HdlRoomLogic.Current.SaveFloorSort(listResidenceSort);
 
                     this.listView.RemoveAll();
                     //鏁版嵁宸茬粡鍙樻洿
@@ -515,7 +560,7 @@
             public PageSettingInfo PageSetting = new PageSettingInfo()
             {
                 Page = 1,
-                PageSize = 500
+                PageSize = 5000
             };
         }
 

--
Gitblit v1.8.0