From 652243206427f35a256400a149a1734085824cb9 Mon Sep 17 00:00:00 2001
From: 陈嘉乐 <cjl@hdlchina.com.cn>
Date: 星期三, 02 九月 2020 17:35:03 +0800
Subject: [PATCH] 2020-09-02-4

---
 ZigbeeApp/Shared/Phone/UserCenter/Residence/ResidenceListForm.cs |  560 +++++++++++++++++++++++++++++++++++++++++---------------
 1 files changed, 410 insertions(+), 150 deletions(-)

diff --git a/ZigbeeApp/Shared/Phone/UserCenter/Residence/ResidenceListForm.cs b/ZigbeeApp/Shared/Phone/UserCenter/Residence/ResidenceListForm.cs
index ea31def..50c2d74 100755
--- a/ZigbeeApp/Shared/Phone/UserCenter/Residence/ResidenceListForm.cs
+++ b/ZigbeeApp/Shared/Phone/UserCenter/Residence/ResidenceListForm.cs
@@ -16,13 +16,13 @@
         /// </summary>
         private VerticalListControl listView = null;
         /// <summary>
-        /// 浣忓畢鏁版嵁
+        /// 浣忓畢鏁版嵁(鏈夌綉鏃朵娇鐢�)
         /// </summary>
         private Dictionary<string, Common.ResponseEntity.ResidenceObj> dicResidenceData = null;
         /// <summary>
-        /// 浣忓畢椤哄簭
+        /// 浣忓畢鏁版嵁(鏃犵綉鏃朵娇鐢�)
         /// </summary>
-        private List<string> listResidenceSort = new List<string>();
+        private List<House> listLocalHouse = null;
 
         #endregion
 
@@ -36,16 +36,20 @@
             //璁剧疆鏍囬淇℃伅
             base.SetTitleText(Language.StringByID(R.MyInternationalizationString.ResidenceManagement));
 
-            //鍙充笂娣诲姞鎸夐挳
-            var btnTopIcon = new MostRightIconControl(69, 69);
-            btnTopIcon.UnSelectedImagePath = "Item/Add.png";
-            topFrameLayout.AddChidren(btnTopIcon);
-            btnTopIcon.InitControl();
-            btnTopIcon.ButtonClickEvent += (sender, e) =>
+            //铏氭嫙浣忓畢鏃犳硶鏂板缓浣忓畢
+            if (Common.Config.Instance.Home.IsVirtually == false)
             {
-                //鏄剧ず娣诲姞浣忓畢鍚嶇О鐨勭敾闈�
-                this.ShowAddNameForm();
-            };
+                //鍙充笂娣诲姞鎸夐挳
+                var btnTopIcon = new MostRightIconControl(69, 69);
+                btnTopIcon.UnSelectedImagePath = "Item/Add.png";
+                topFrameLayout.AddChidren(btnTopIcon);
+                btnTopIcon.InitControl();
+                btnTopIcon.ButtonClickEvent += (sender, e) =>
+                {
+                    //鏄剧ず娣诲姞浣忓畢鍚嶇О鐨勭敾闈�
+                    this.ShowAddNameForm();
+                };
+            }
 
             //鍒濆鍖栦腑閮ㄦ帶浠�
             this.InitMiddleFrame();
@@ -59,67 +63,75 @@
             //娓呯┖bodyFrame
             this.ClearBodyFrame();
 
-            //璇诲彇浣忓畢椤哄簭
-            var strData = UserCenterLogic.LoadFileContent(UserCenterLogic.CombinePath(DirNameResourse.LocalMemoryDirectory, DirNameResourse.ResidenceSortFile));
-            if (strData != null)
-            {
-                listResidenceSort = Newtonsoft.Json.JsonConvert.DeserializeObject<List<string>>(strData);
-                strData = null;
-            }
-
             listView = new VerticalListControl(29);
-            listView.Y = Application.GetRealHeight(-6);
             listView.Height = bodyFrameLayout.Height + Application.GetRealHeight(6);
             listView.BackgroundColor = UserCenterColor.Current.White;
             bodyFrameLayout.AddChidren(listView);
 
+            //璁剧疆浣忓畢淇℃伅
+            this.SetResidenceInfo(1);
+        }
+
+        /// <summary>
+        /// 璁剧疆浣忓畢淇℃伅(1:鍏堣鍙栦簯绔�,鏃犳硶鑱旂綉,鍐嶈鍙栨湰鍦�  2:鍙浜戠  3:鍙鏈湴)
+        /// </summary>
+        /// <param name="div">1:鍏堣鍙栦簯绔�,鏃犳硶鑱旂綉,鍐嶈鍙栨湰鍦�  2:鍙浜戠  3:鍙鏈湴</param>
+        private void SetResidenceInfo(int div)
+        {
             HdlThreadLogic.Current.RunThread(() =>
             {
-                //璁剧疆浣忓畢淇℃伅
-                this.SetResidenceInfo();
+                //铏氭嫙浣忓畢鐨勮瘽,鍙鏈湴
+                if (div == 3 || Config.Instance.Home.IsVirtually == true)
+                {
+                    //鍙鏈湴
+                    this.SetResidenceInfoByOffline();
+                }
+                else
+                {
+                    //寮�鍚繘搴︽潯
+                    this.ShowProgressBar();
+                    //璁剧疆浣忓畢淇℃伅(鏈夌綉鎯呭喌)
+                    var result = this.SetResidenceInfoByOnline();
+                    if (result == true)
+                    {
+                        //浜戠璇诲彇鎴愬姛
+                        this.CloseProgressBar();
+                        return;
+                    }
+                    if (div == 2)
+                    {
+                        //濡傛灉鍙浜戠 鍏抽棴杩涘害鏉�
+                        this.CloseProgressBar(ShowReLoadMode.YES);
+                        return;
+                    }
+                    //濡傛灉鍦ㄦ病缃戠殑鎯呭喌涓�,浠庢枃浠跺す璺緞涓幏鍙栧叏閮ㄤ綇瀹�,鐒跺悗鏄剧ず
+                    this.SetResidenceInfoByOffline();
+
+                    //鍏抽棴杩涘害鏉�
+                    this.CloseProgressBar();
+                }
             });
         }
 
         #endregion
 
-        #region 鈻� 璁剧疆浣忓畢淇℃伅_______________________
+        #region 鈻� 璁剧疆浣忓畢淇℃伅(鏈夌綉鎯呭喌)_____________
 
         /// <summary>
-        /// 璁剧疆浣忓畢淇℃伅
+        /// 璁剧疆浣忓畢淇℃伅(鏈夌綉鎯呭喌)
         /// </summary>
-        private async void SetResidenceInfo()
+        private bool SetResidenceInfoByOnline()
         {
-            //寮�鍚繘搴︽潯
-            this.ShowProgressBar();
-
             //鑾峰彇浣忓畢淇℃伅
             var Pra = new GetResidenceInfoPra();
-            string resultData = await UserCenterLogic.GetResponseDataByRequestHttps("App/GetHomePager", false, Pra);
-            if (resultData == null)
+            string resultData = UserCenterLogic.GetResponseDataByRequestHttps("App/GetHomePager", false, Pra, new List<string> { "NotCheck" }, false);
+            if (string.IsNullOrEmpty(resultData) == true)
             {
-                //鍏抽棴杩涘害鏉�
-                this.CloseProgressBar(ShowReLoadMode.YES);
-                return;
+                return false;
             }
-            //鍏抽棴杩涘害鏉�
-            this.CloseProgressBar();
-
             var pageData = Newtonsoft.Json.JsonConvert.DeserializeObject<Common.ResponseEntity.ResidenceRes>(resultData);
-
-            //鏆傛椂瀛樺偍鏁版嵁
-            var dicData = new Dictionary<string, Common.ResponseEntity.ResidenceObj>();
-            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);
-                }
-            }
-            //淇濆瓨椤哄簭
-            string fullName = UserCenterLogic.CombinePath(DirNameResourse.LocalMemoryDirectory, DirNameResourse.ResidenceSortFile);
-            UserCenterLogic.SaveFileContent(fullName, listResidenceSort);
+            //鎺掑簭浣忓畢
+            var listHouse = HdlResidenceLogic.Current.SortHouse(pageData.PageData);
 
             HdlThreadLogic.Current.RunMain(() =>
             {
@@ -127,33 +139,29 @@
                 {
                     return;
                 }
-                listView.Height = bodyFrameLayout.Height + Application.GetRealHeight(6);
+                listView.Height = bodyFrameLayout.Height;
 
                 this.dicResidenceData = new Dictionary<string, Common.ResponseEntity.ResidenceObj>();
-                for (int i = 0; i < listResidenceSort.Count; i++)
+                for (int i = 0; i < listHouse.Count; i++)
                 {
-                    var info = dicData[listResidenceSort[i]];
-                    if (info.IsOthreShare == false)
-                    {
-                        //鏀堕泦璇ヨ处鍙锋墍鎷ユ湁鐨勮嚜宸辩殑浣忓畢鐨勬暟鎹�
-                        this.dicResidenceData[info.Id] = info;
-                    }
-                    this.AddRowLayout(info, i != listResidenceSort.Count - 1);
+                    var info = listHouse[i];
+
+                    //鏀堕泦璇ヨ处鍙蜂綇瀹呯殑鏁版嵁
+                    this.dicResidenceData[info.Id] = info;
+                    //娣诲姞浣忓畢鐨勮(鏈夌綉鎯呭喌)
+                    this.AddRowLayoutByOnline(info, i != listHouse.Count - 1);
                 }
                 //璋冩暣鍒楄〃鎺т欢鐨勯珮搴�
                 this.listView.AdjustRealHeight(Application.GetRealHeight(23));
             });
+            return true;
         }
 
-        #endregion
-
-        #region 鈻� 娣诲姞浣忓畢鐨勮_______________________
-
         /// <summary>
-        /// 娣诲姞浣忓畢鐨勮
+        /// 娣诲姞浣忓畢鐨勮(鏈夌綉鎯呭喌)
         /// </summary>
         /// <param name="info"></param>
-        private void AddRowLayout(Common.ResponseEntity.ResidenceObj info, bool addLine)
+        private void AddRowLayoutByOnline(Common.ResponseEntity.ResidenceObj info, bool addLine)
         {
             var rowLayout = new RowLayoutControl(listView.rowSpace / 2);
             this.listView.AddChidren(rowLayout);
@@ -169,14 +177,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
             {
@@ -204,22 +212,26 @@
                     }
                     this.ShowMassage(ShowMsgType.Confirm, msg, () =>
                     {
-                        HdlThreadLogic.Current.RunThread(async () =>
+                        HdlThreadLogic.Current.RunThread(() =>
                         {
-                            ProgressBar.Show();
-                            Config.Instance.HomeId = info.Id;
-                            Global.CreateHomeDirectory(info.Id);
-                            Config.Instance.Save();
-                            //鍒锋柊涓汉涓績鐨勫唴瀛樺強绾跨▼
-                            await UserCenterLogic.InitUserCenterMenmoryAndThread();
+                            //寮�鍚繘搴︽潯
+                            this.ShowProgressBar();
 
-                            Room.InitAllRoom();
+                            //妫�娴嬫湰鍦版湁娌℃湁杩欎釜浣忓畢
+                            this.CheckIsExsitResidence(info);
+
+                            var result = HdlResidenceLogic.Current.SwitchResidence(info.Id);
 
                             HdlThreadLogic.Current.RunMain(() =>
                             {
-                                //閲嶆柊鍒锋柊鍒楄〃
-                                this.listView.RemoveAll();
-                                this.SetResidenceInfo();
+                                if (result == true)
+                                {
+                                    //閲嶆柊鍒锋柊鍒楄〃
+                                    this.listView.RemoveAll();
+                                    this.SetResidenceInfo(2);
+                                }
+                                //鍏抽棴杩涘害鏉�
+                                this.CloseProgressBar();
                             });
                         });
                     });
@@ -238,19 +250,143 @@
                 //鍒嗕韩鐨�,涓嶈兘鏇存敼
                 return;
             }
+            //杩囨埛
+            var btnTransfer = rowLayout.AddDeleteControl();
+            btnTransfer.TextID = R.MyInternationalizationString.uTransfer;
+            btnTransfer.ButtonClickEvent += (sender, e) =>
+            {
+                var form = new TransferResidenceMainForm();
+                form.AddForm();
+            };
             //鏇存敼
-            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) =>
             {
                 //鏄剧ず缂栬緫鍚嶇О鐣岄潰
-                this.ShowEditorNameForm(info, btnHome);
+                this.ShowEditorNameForm(info, null, btnHome);
             };
+        }
+
+        #endregion
+
+        #region 鈻� 璁剧疆浣忓畢淇℃伅(鏃犵綉鎯呭喌)_____________
+
+        /// <summary>
+        /// 璁剧疆浣忓畢淇℃伅(鏃犵綉鎯呭喌)
+        /// </summary>
+        private void SetResidenceInfoByOffline()
+        {
+            //浠庢枃浠跺す涓幏鍙栧叏閮ㄧ殑浣忓畢瀵硅薄
+            this.listLocalHouse = HdlResidenceLogic.Current.GetAllLocalResidenceListByDirectory();
+            if (listLocalHouse.Count == 0)
+            {
+                return;
+            }
+
+            HdlThreadLogic.Current.RunMain(() =>
+            {
+                listView.Height = bodyFrameLayout.Height;
+
+                for (int i = 0; i < listLocalHouse.Count; i++)
+                {
+                    //娣诲姞浣忓畢鐨勮(鏃犵綉鎯呭喌)
+                    this.AddRowLayoutByOffline(listLocalHouse[i], i != listLocalHouse.Count - 1);
+                }
+                //璋冩暣鍒楄〃鎺т欢鐨勯珮搴�
+                this.listView.AdjustRealHeight(Application.GetRealHeight(23));
+            });
+        }
+
+        /// <summary>
+        /// 娣诲姞浣忓畢鐨勮(鏃犵綉鎯呭喌)
+        /// </summary>
+        /// <param name="i_home"></param>
+        private void AddRowLayoutByOffline(House i_home, bool addLine)
+        {
+            var rowLayout = new RowLayoutControl(listView.rowSpace / 2);
+            this.listView.AddChidren(rowLayout);
+
+            //鍥炬爣
+            var btnIcon = rowLayout.frameTable.AddLeftIcon(81);
+            btnIcon.UnSelectedImagePath = "Item/ResidenceIcon.png";
+            //褰撳墠浣忓畢
+            NormalViewControl btnHome = null;
+            if (i_home.Id == Config.Instance.Home.Id)
+            {
+                //浣忓畢鍚嶇О
+                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.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.BindEvent);
+            }
+            else
+            {
+                //浣忓畢鍚嶇О
+                btnHome = rowLayout.frameTable.AddLeftCaption(i_home.Name, 800, true);
+                btnHome.TextSize = 15;
+            }
+            //鍙崇澶�
+            rowLayout.frameTable.AddRightArrow();
+            if (addLine == true)
+            {
+                //搴曠嚎
+                rowLayout.frameTable.AddBottomLine();
+            }
+
+            rowLayout.frameTable.ButtonClickEvent += (sender, e) =>
+            {
+                if (i_home.Id != Config.Instance.Home.Id)
+                {
+                    //纭鍒囨崲褰撳墠浣忓畢鍒般�屻��?
+                    string msg = Language.StringByID(R.MyInternationalizationString.uSwitchResidenceMsg);
+                    if (msg.Contains("{0}") == true)
+                    {
+                        msg = string.Format(msg, i_home.Name);
+                    }
+                    this.ShowMassage(ShowMsgType.Confirm, msg, () =>
+                    {
+                        HdlThreadLogic.Current.RunThread(() =>
+                        {
+                            var result = HdlResidenceLogic.Current.SwitchResidence(i_home.Id);
+
+                            HdlThreadLogic.Current.RunMain(() =>
+                            {
+                                if (result == true)
+                                {
+                                    //閲嶆柊鍒锋柊鍒楄〃
+                                    this.listView.RemoveAll();
+                                    this.SetResidenceInfo(3);
+                                }
+                                //鍏抽棴杩涘害鏉�
+                                this.CloseProgressBar();
+                            });
+                        });
+                    });
+                }
+                else
+                {
+                    //妫�娴嬭兘鍚﹀垹闄や綇瀹�
+                    bool flage = this.CheckIsCanDeleteResidence(i_home);
+                    var form = new ResidenceManagementForm();
+                    form.AddForm(flage);
+                }
+            };
+            ////鏇存敼
+            //var btnChanged = rowLayout.AddEditorControl();
+            //btnChanged.TextID = R.MyInternationalizationString.uChanged1;
+            //btnChanged.ButtonClickEvent += (sender, e) =>
+            //{
+            //    //鏄剧ず缂栬緫鍚嶇О鐣岄潰
+            //    this.ShowEditorNameForm(null, i_home, btnHome);
+            //};
         }
 
         #endregion
@@ -260,16 +396,18 @@
         /// <summary>
         /// 鏄剧ず缂栬緫浣忓畢鍚嶇О鐣岄潰
         /// </summary>
-        /// <param name="info"></param>
-        private void ShowEditorNameForm(Common.ResponseEntity.ResidenceObj info, NormalViewControl btnHome)
+        /// <param name="info">鏈夌綉鏃朵娇鐢�</param>
+        /// <param name="i_house">鏃犵綉鏃堕�傜敤</param>
+        private void ShowEditorNameForm(Common.ResponseEntity.ResidenceObj info, House i_house, NormalViewControl btnHome)
         {
+            string oldName = info != null ? info.Name : i_house.Name;
             //鐢熸垚涓�涓脊绐楃敾闈�
             var dialogForm = new DialogInputControl();
             //缂栬緫浣忓畢
             dialogForm.SetTitleText(Language.StringByID(R.MyInternationalizationString.uChangedName));
             //璇疯緭鍏ヤ綇瀹呭悕绉�
             dialogForm.SetTipText(Language.StringByID(R.MyInternationalizationString.uPleaseInputResidenceName));
-            dialogForm.Text = info.Name;
+            dialogForm.Text = oldName;
 
             //鎸変笅纭鎸夐挳
             dialogForm.ComfirmClickEvent += ((textValue) =>
@@ -283,11 +421,28 @@
                 }
                 //鐢婚潰鍏抽棴
                 dialogForm.CloseDialog();
-
-                if (info.Name != textValue)
+                if (oldName != textValue)
                 {
-                    //缂栬緫浜戠鐨勪綇瀹呭悕绉�
-                    this.EditorResidenceName(textValue, info);
+                    if (info != null)
+                    {
+                        //缂栬緫浜戠鐨勪綇瀹呭悕绉�
+                        HdlThreadLogic.Current.RunThread(() =>
+                        {
+                            this.EditorResidenceName(textValue, info, btnHome);
+                        });
+                    }
+                    else
+                    {
+                        //鐩存帴缂栬緫浣忓畢缂撳瓨
+                        if (this.CheckIsCanSaveResidence(i_house.Id, textValue, true) == false)
+                        {
+                            return;
+                        }
+                        //鍒锋柊鍐呭瓨鐨勪綇瀹呭悕
+                        HdlResidenceLogic.Current.EditorHouseByHouseId(i_house.Id, textValue);
+                        //鏇存敼鏄剧ず鐨勫悕瀛�
+                        btnHome.Text = textValue;
+                    }
                 }
             });
         }
@@ -298,7 +453,7 @@
         /// <param name="ResidenceName"></param>
         /// <param name="info"></param>
         /// <returns></returns>
-        private async void EditorResidenceName(string ResidenceName, Common.ResponseEntity.ResidenceObj info)
+        private void EditorResidenceName(string ResidenceName, Common.ResponseEntity.ResidenceObj info, NormalViewControl btnHome)
         {
             //妫�娴嬭兘鍚︿繚瀛樹綇瀹�
             if (this.CheckIsCanSaveResidence(info.Id, ResidenceName, true) == false)
@@ -308,26 +463,22 @@
             //寮�鍚繘搴︽潯
             this.ShowProgressBar();
 
-            var Pra = new EditorResidencePra();
-            Pra.HomeId = info.Id;
-            Pra.Name = ResidenceName;
-            if (info.IsOthreShare == true)
+            var result = HdlResidenceLogic.Current.EditorResidenceName(info.Id, ResidenceName);
+
+            //鍏抽棴杩涘害鏉�
+            this.CloseProgressBar();
+
+            if (result == true)
             {
-                Pra.LoginAccessToken = UserCenterLogic.GetConnectMainToken();
+                HdlThreadLogic.Current.RunMain(() =>
+                {
+                    //鍒锋柊鍐呭瓨鐨勪綇瀹呭悕
+                    HdlResidenceLogic.Current.EditorHouseByHouseId(info.Id, ResidenceName);
+                    //鏇存敼鏄剧ず鐨勫悕瀛�
+                    btnHome.Text = ResidenceName;
+                    info.Name = ResidenceName;
+                });
             }
-            //缂栬緫浣忓畢
-            bool flage = await UserCenterLogic.GetResultStatuByRequestHttps("App/EditHome", info.IsOthreShare, Pra);
-            if (flage == false)
-            {
-                //鍏抽棴杩涘害鏉�
-                this.CloseProgressBar();
-                return;
-            }
-            //鍒锋柊鍐呭瓨鐨勪綇瀹呭悕
-            House.EditorHouseByHouseId(info.Id, ResidenceName);
-            //閲嶆柊鍒锋柊鍒楄〃
-            this.listView.RemoveAll();
-            this.SetResidenceInfo();
         }
 
         #endregion
@@ -359,7 +510,10 @@
                 dialogForm.CloseDialog();
 
                 //淇濆瓨浣忓畢
-                this.AddNewResidence(textValue);
+                HdlThreadLogic.Current.RunThread(() =>
+                {
+                    this.AddNewResidence(textValue);
+                });
             });
         }
 
@@ -368,7 +522,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)
@@ -381,8 +535,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();
@@ -391,10 +545,15 @@
 
             var newInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<List<NewResidenceInfo>>(resultData);
 
-            House.AddHouse(newInfo[0].Id, ResidenceName, 0);
-            //閲嶆柊鍒锋柊鍒楄〃
-            this.listView.RemoveAll();
-            this.SetResidenceInfo();
+            HdlResidenceLogic.Current.AddHouseToMemmory(newInfo[0].Id, ResidenceName);
+
+            HdlThreadLogic.Current.RunMain(() =>
+            {
+                //閲嶆柊鍒锋柊鍒楄〃
+                this.listView.RemoveAll();
+                this.SetResidenceInfo(2);
+            });
+
         }
 
         #endregion
@@ -402,26 +561,88 @@
         #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 true;
+        }
+
+        /// <summary>
+        /// 妫�娴嬭兘鍚﹀垹闄や綇瀹�(鏃犵綉浣跨敤)
+        /// </summary>
+        /// <param name="info"></param>
+        /// <returns></returns>
+        private bool CheckIsCanDeleteResidence(House i_house)
+        {
+            if (i_house.IsVirtually == false)
             {
-                //鍒嗕韩杩囨潵鐨勪綇瀹呬笉鑳藉垹闄�
+                //闈炶櫄鎷熶綇瀹呴兘涓嶅厑璁稿垹闄�,鍙湁鍦ㄨ兘鑱旂綉鐨勬椂鍊�,鎵嶈兘鍒犻櫎
                 return false;
             }
+
+            int myCount = 0;
+            foreach (var data in this.listLocalHouse)
+            {
+                if (data.IsVirtually == true)
+                {
+                    myCount++;
+                }
+            }
+            //濡傛灉姝よ处鍙蜂笅鍙墿涓嬪敮涓�涓�涓櫄鎷熺殑浣忓畢锛屽垯涓嶈兘鍐嶅垹闄�
+            if (myCount == 1)
+            {
+                return false;
+            }
+
             return true;
         }
 
@@ -434,16 +655,43 @@
         /// <returns></returns>
         private bool CheckIsCanSaveResidence(string residenceId, string residenceName, bool isEditor)
         {
-            //浣忓畢鍚嶅瓧閲嶅妫�娴�
-            foreach (string strId in this.dicResidenceData.Keys)
+            if (this.dicResidenceData != null)
             {
-                if (residenceId != strId && residenceName == this.dicResidenceData[strId].Name)
+                //浣忓畢鍚嶅瓧閲嶅妫�娴�
+                foreach (string strId in this.dicResidenceData.Keys)
                 {
-                    //浣忓畢鍚嶅瓧宸茬粡瀛樺湪
-                    int msgId = isEditor == true ? R.MyInternationalizationString.EditZigbeeHome_Exist : R.MyInternationalizationString.AddZigbeeHome_Exist;
-                    string msg = Language.StringByID(msgId);
-                    this.ShowMassage(ShowMsgType.Error, msg);
-                    return false;
+                    if (this.dicResidenceData[strId].IsOthreShare == true)
+                    {
+                        //鍒嗕韩鐨勪綇瀹呬笉鑰冭檻
+                        continue;
+                    }
+                    if (residenceId != strId && residenceName == this.dicResidenceData[strId].Name)
+                    {
+                        //浣忓畢鍚嶅瓧宸茬粡瀛樺湪
+                        int msgId = isEditor == true ? R.MyInternationalizationString.EditZigbeeHome_Exist : R.MyInternationalizationString.AddZigbeeHome_Exist;
+                        string msg = Language.StringByID(msgId);
+                        this.ShowMassage(ShowMsgType.Error, msg);
+                        return false;
+                    }
+                }
+            }
+            else
+            {
+                foreach (var myHouse in this.listLocalHouse)
+                {
+                    if (myHouse.IsOthreShare == true)
+                    {
+                        //鍒嗕韩鐨勪綇瀹呬笉鑰冭檻
+                        continue;
+                    }
+                    if (residenceId != myHouse.Id && residenceName == myHouse.Name)
+                    {
+                        //浣忓畢鍚嶅瓧宸茬粡瀛樺湪
+                        int msgId = isEditor == true ? R.MyInternationalizationString.EditZigbeeHome_Exist : R.MyInternationalizationString.AddZigbeeHome_Exist;
+                        string msg = Language.StringByID(msgId);
+                        this.ShowMassage(ShowMsgType.Error, msg);
+                        return false;
+                    }
                 }
             }
             return true;
@@ -458,22 +706,34 @@
         /// </summary>
         public override int FormActionAgainEvent()
         {
-            foreach (string keys in dicResidenceData.Keys)
+            if (dicResidenceData != null)
             {
-                if (Config.Instance.HomeFilePathList.Contains($"House_{keys}.json") == false)
+                foreach (string keys in dicResidenceData.Keys)
                 {
-                    //淇濆瓨椤哄簭
-                    listResidenceSort.Remove(keys);
-                    Room.CurrentRoom.SaveFloorSort(listResidenceSort);
-
-                    this.listView.RemoveAll();
-                    //鏁版嵁宸茬粡鍙樻洿
-                    HdlThreadLogic.Current.RunThread(() =>
+                    if (Config.Instance.HomeFilePathList.Contains($"House_{keys}.json") == false)
                     {
-                        //閲嶆柊璁剧疆浣忓畢淇℃伅
-                        this.SetResidenceInfo();
-                    });
-                    break;
+                        this.listView.RemoveAll();
+                        //鏁版嵁宸茬粡鍙樻洿 閲嶆柊璁剧疆浣忓畢淇℃伅
+                        this.SetResidenceInfo(2);
+                        break;
+                    }
+                }
+            }
+            else
+            {
+                //妫�娴嬭繕鏈夎繖涓綇瀹呮枃浠跺悧
+                var strPath = System.IO.Path.Combine(Shared.IO.FileUtils.RootPath, Common.Config.Instance.Guid);
+                foreach (var myHouse in this.listLocalHouse)
+                {
+                    string fullName = System.IO.Path.Combine(strPath, myHouse.FileName);
+                    //濡傛灉涓嶅瓨鍦ㄤ簡鐨勮瘽
+                    if (System.IO.File.Exists(fullName) == false)
+                    {
+                        //鏁版嵁宸茬粡鍙樻洿 閲嶆柊璁剧疆浣忓畢淇℃伅
+                        this.listView.RemoveAll();
+                        this.SetResidenceInfo(3);
+                        return 1;
+                    }
                 }
             }
             return 1;
@@ -513,7 +773,7 @@
             public PageSettingInfo PageSetting = new PageSettingInfo()
             {
                 Page = 1,
-                PageSize = 500
+                PageSize = 5000
             };
         }
 

--
Gitblit v1.8.0