From 48ba446936b51fffafa7c3600c0dadc6ac0e8c20 Mon Sep 17 00:00:00 2001
From: 陈嘉乐 <cjl@hdlchina.com.cn>
Date: 星期五, 10 七月 2020 10:52:13 +0800
Subject: [PATCH] 2020-07-10-01

---
 ZigbeeApp/Shared/Phone/UserCenter/Residence/ResidenceListForm.cs |  508 +++++++++++++++++++++++++++++++++++++++++---------------
 1 files changed, 371 insertions(+), 137 deletions(-)

diff --git a/ZigbeeApp/Shared/Phone/UserCenter/Residence/ResidenceListForm.cs b/ZigbeeApp/Shared/Phone/UserCenter/Residence/ResidenceListForm.cs
index a20b2b5..2ac9c0a 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,76 +63,83 @@
             //娓呯┖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);
 
-            HdlThreadLogic.Current.RunThread(() =>
+            //璁剧疆浣忓畢淇℃伅
+            this.SetResidenceInfo(1);
+        }
+
+        /// <summary>
+        /// 璁剧疆浣忓畢淇℃伅(1:鍏堣鍙栦簯绔�,鏃犳硶鑱旂綉,鍐嶈鍙栨湰鍦�  2:鍙浜戠  3:鍙鏈湴)
+        /// </summary>
+        /// <param name="div">1:鍏堣鍙栦簯绔�,鏃犳硶鑱旂綉,鍐嶈鍙栨湰鍦�  2:鍙浜戠  3:鍙鏈湴</param>
+        private void SetResidenceInfo(int div)
+        {
+            HdlThreadLogic.Current.RunThread(async () =>
             {
-                //璁剧疆浣忓畢淇℃伅
-                this.SetResidenceInfo();
+                //铏氭嫙浣忓畢鐨勮瘽,鍙鏈湴
+                if (div == 3 || Config.Instance.Home.IsVirtually == true)
+                {
+                    //鍙鏈湴
+                    this.SetResidenceInfoByOffline();
+                }
+                else
+                {
+                    //寮�鍚繘搴︽潯
+                    this.ShowProgressBar();
+                    //璁剧疆浣忓畢淇℃伅(鏈夌綉鎯呭喌)
+                    var result = await 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 async System.Threading.Tasks.Task<bool> SetResidenceInfoByOnline()
         {
-            //寮�鍚繘搴︽潯
-            this.ShowProgressBar();
-
             //鑾峰彇浣忓畢淇℃伅
             var Pra = new GetResidenceInfoPra();
-            string resultData = await UserCenterLogic.GetResponseDataByRequestHttps("App/GetHomePager", false, Pra);
+            var listNotCheck = new List<string>() { "NotSetAgain" };
+            string resultData = await UserCenterLogic.GetResponseDataByRequestHttps("App/GetHomePager", false, Pra, listNotCheck);
             if (resultData == null)
             {
-                //鍏抽棴杩涘害鏉�
-                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>();
+            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(() =>
             {
@@ -136,7 +147,7 @@
                 {
                     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++)
@@ -146,27 +157,23 @@
                         continue;
                     }
                     var info = dicData[listResidenceSort[i]];
-                    if (info.IsOthreShare == false)
-                    {
-                        //鏀堕泦璇ヨ处鍙锋墍鎷ユ湁鐨勮嚜宸辩殑浣忓畢鐨勬暟鎹�
-                        this.dicResidenceData[info.Id] = info;
-                    }
-                    this.AddRowLayout(info, i != listResidenceSort.Count - 1);
+
+                    //鏀堕泦璇ヨ处鍙蜂綇瀹呯殑鏁版嵁
+                    this.dicResidenceData[info.Id] = info;
+                    //娣诲姞浣忓畢鐨勮(鏈夌綉鎯呭喌)
+                    this.AddRowLayoutByOnline(info, i != listResidenceSort.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);
@@ -182,14 +189,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
             {
@@ -219,23 +226,21 @@
                     {
                         HdlThreadLogic.Current.RunThread(async () =>
                         {
+                            //寮�鍚繘搴︽潯
                             this.ShowProgressBar();
 
-                            Config.Instance.HomeId = info.Id;
-                            Global.CreateHomeDirectory(info.Id);
-                            //閲嶆柊鍒濆鍖栦綇瀹呭璞�
-                            Config.Instance.Home = House.GetHouseByHouseId(info.Id);
-                            Config.Instance.Save();
-                            //鍒锋柊涓汉涓績鐨勫唴瀛樺強绾跨▼
-                            await UserCenterLogic.InitUserCenterMenmoryAndThread(false);
+                            //妫�娴嬫湰鍦版湁娌℃湁杩欎釜浣忓畢
+                            this.CheckIsExsitResidence(info);
 
-                            HdlRoomLogic.Current.InitAllRoom();
+                            await HdlResidenceLogic.Current.SwitchResidence(info.Id);
 
                             HdlThreadLogic.Current.RunMain(() =>
                             {
                                 //閲嶆柊鍒锋柊鍒楄〃
                                 this.listView.RemoveAll();
-                                this.SetResidenceInfo();
+                                this.SetResidenceInfo(2);
+                                //鍏抽棴杩涘害鏉�
+                                this.CloseProgressBar();
                             });
                         });
                     });
@@ -255,17 +260,130 @@
                 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) =>
             {
                 //鏄剧ず缂栬緫鍚嶇О鐣岄潰
-                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(async () =>
+                        {
+                            await HdlResidenceLogic.Current.SwitchResidence(i_home.Id);
+
+                            HdlThreadLogic.Current.RunMain(() =>
+                            {
+                                //閲嶆柊鍒锋柊鍒楄〃
+                                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);
             };
         }
 
@@ -276,16 +394,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) =>
@@ -299,11 +419,25 @@
                 }
                 //鐢婚潰鍏抽棴
                 dialogForm.CloseDialog();
-
-                if (info.Name != textValue)
+                if (oldName != textValue)
                 {
-                    //缂栬緫浜戠鐨勪綇瀹呭悕绉�
-                    this.EditorResidenceName(textValue, info);
+                    if (info != null)
+                    {
+                        //缂栬緫浜戠鐨勪綇瀹呭悕绉�
+                        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;
+                    }
                 }
             });
         }
@@ -314,7 +448,7 @@
         /// <param name="ResidenceName"></param>
         /// <param name="info"></param>
         /// <returns></returns>
-        private async void EditorResidenceName(string ResidenceName, Common.ResponseEntity.ResidenceObj info)
+        private async void EditorResidenceName(string ResidenceName, Common.ResponseEntity.ResidenceObj info, NormalViewControl btnHome)
         {
             //妫�娴嬭兘鍚︿繚瀛樹綇瀹�
             if (this.CheckIsCanSaveResidence(info.Id, ResidenceName, true) == false)
@@ -327,23 +461,22 @@
             var Pra = new EditorResidencePra();
             Pra.HomeId = info.Id;
             Pra.Name = ResidenceName;
-            if (info.IsOthreShare == true)
-            {
-                Pra.LoginAccessToken = UserCenterLogic.GetConnectMainToken();
-            }
+            Pra.IsOtherAccountCtrl = false;
+            Pra.LoginAccessToken = Config.Instance.Token;
+
             //缂栬緫浣忓畢
-            bool flage = await UserCenterLogic.GetResultStatuByRequestHttps("App/EditHome", info.IsOthreShare, Pra);
-            if (flage == false)
+            bool flage = await UserCenterLogic.GetResultStatuByRequestHttps("App/EditHome", false, Pra);
+            //鍏抽棴杩涘害鏉�
+            this.CloseProgressBar();
+
+            if (flage == true)
             {
-                //鍏抽棴杩涘害鏉�
-                this.CloseProgressBar();
-                return;
+                //鍒锋柊鍐呭瓨鐨勪綇瀹呭悕
+                HdlResidenceLogic.Current.EditorHouseByHouseId(info.Id, ResidenceName);
+                //鏇存敼鏄剧ず鐨勫悕瀛�
+                btnHome.Text = ResidenceName;
+                info.Name = ResidenceName;
             }
-            //鍒锋柊鍐呭瓨鐨勪綇瀹呭悕
-            House.EditorHouseByHouseId(info.Id, ResidenceName);
-            //閲嶆柊鍒锋柊鍒楄〃
-            this.listView.RemoveAll();
-            this.SetResidenceInfo();
         }
 
         #endregion
@@ -407,10 +540,10 @@
 
             var newInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<List<NewResidenceInfo>>(resultData);
 
-            House.AddHouse(newInfo[0].Id, ResidenceName, 0);
+            HdlResidenceLogic.Current.AddHouseToMemmory(newInfo[0].Id, ResidenceName);
             //閲嶆柊鍒锋柊鍒楄〃
             this.listView.RemoveAll();
-            this.SetResidenceInfo();
+            this.SetResidenceInfo(2);
         }
 
         #endregion
@@ -418,26 +551,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;
         }
 
@@ -450,16 +645,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;
@@ -474,22 +696,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);
-                    HdlRoomLogic.Current.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;

--
Gitblit v1.8.0