From 6fa9d69da922c8049f5acfcbb9ce9fd26811024c Mon Sep 17 00:00:00 2001 From: xm <1271024303@qq.com> Date: 星期四, 16 四月 2020 17:10:57 +0800 Subject: [PATCH] 请合并代码 --- ZigbeeApp/Shared/Phone/UserCenter/Residence/ResidenceListForm.cs | 599 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 599 insertions(+), 0 deletions(-) diff --git a/ZigbeeApp/Shared/Phone/UserCenter/Residence/ResidenceListForm.cs b/ZigbeeApp/Shared/Phone/UserCenter/Residence/ResidenceListForm.cs new file mode 100755 index 0000000..393b9e2 --- /dev/null +++ b/ZigbeeApp/Shared/Phone/UserCenter/Residence/ResidenceListForm.cs @@ -0,0 +1,599 @@ +锘縰sing Shared.Common; +using System; +using System.Collections.Generic; + +namespace Shared.Phone.UserCenter.Residence +{ + /// <summary> + /// 浣忓畢绠$悊鐨勭敾闈⑩槄 + /// </summary> + public class ResidenceListForm : EditorCommonForm + { + #region 鈻� 鍙橀噺澹版槑___________________________ + + /// <summary> + /// 鍒楄〃鎺т欢 + /// </summary> + private VerticalListControl listView = null; + /// <summary> + /// 浣忓畢鏁版嵁 + /// </summary> + private Dictionary<string, Common.ResponseEntity.ResidenceObj> dicResidenceData = null; + /// <summary> + /// 浣忓畢椤哄簭 + /// </summary> + private List<string> listResidenceSort = new List<string>(); + + #endregion + + #region 鈻� 鍒濆鍖朹____________________________ + + /// <summary> + /// 鐢婚潰鏄剧ず(搴曞眰浼氬浐瀹氳皟鐢ㄦ鏂规硶锛屽�熶互瀹屾垚鐢婚潰鍒涘缓) + /// </summary> + public void ShowForm() + { + //璁剧疆鏍囬淇℃伅 + 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) => + { + //鏄剧ず娣诲姞浣忓畢鍚嶇О鐨勭敾闈� + this.ShowAddNameForm(); + }; + + //鍒濆鍖栦腑閮ㄦ帶浠� + this.InitMiddleFrame(); + } + + /// <summary> + /// 鍒濆鍖栦腑閮ㄦ帶浠� + /// </summary> + private void InitMiddleFrame() + { + //娓呯┖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.Height = bodyFrameLayout.Height + Application.GetRealHeight(6); + listView.BackgroundColor = UserCenterColor.Current.White; + bodyFrameLayout.AddChidren(listView); + + HdlThreadLogic.Current.RunThread(() => + { + //璁剧疆浣忓畢淇℃伅 + this.SetResidenceInfo(); + }); + } + + #endregion + + #region 鈻� 璁剧疆浣忓畢淇℃伅_______________________ + + /// <summary> + /// 璁剧疆浣忓畢淇℃伅 + /// </summary> + private async void SetResidenceInfo() + { + //寮�鍚繘搴︽潯 + this.ShowProgressBar(); + + //鑾峰彇浣忓畢淇℃伅 + var Pra = new GetResidenceInfoPra(); + string resultData = await UserCenterLogic.GetResponseDataByRequestHttps("App/GetHomePager", false, Pra); + if (resultData == null) + { + //鍏抽棴杩涘害鏉� + this.CloseProgressBar(ShowReLoadMode.YES); + return; + } + //鍏抽棴杩涘害鏉� + 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); + } + } + 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(() => + { + if (this.Parent == null) + { + return; + } + listView.Height = bodyFrameLayout.Height + Application.GetRealHeight(6); + + this.dicResidenceData = new Dictionary<string, Common.ResponseEntity.ResidenceObj>(); + for (int i = 0; i < listResidenceSort.Count; i++) + { + if (dicData.ContainsKey(listResidenceSort[i]) == false) + { + continue; + } + var info = dicData[listResidenceSort[i]]; + + //鏀堕泦璇ヨ处鍙蜂綇瀹呯殑鏁版嵁 + this.dicResidenceData[info.Id] = info; + this.AddRowLayout(info, i != listResidenceSort.Count - 1); + } + //璋冩暣鍒楄〃鎺т欢鐨勯珮搴� + this.listView.AdjustRealHeight(Application.GetRealHeight(23)); + }); + } + + #endregion + + #region 鈻� 娣诲姞浣忓畢鐨勮_______________________ + + /// <summary> + /// 娣诲姞浣忓畢鐨勮 + /// </summary> + /// <param name="info"></param> + private void AddRowLayout(Common.ResponseEntity.ResidenceObj info, 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 (info.Id == Config.Instance.Home.Id) + { + //浣忓畢鍚嶇О + 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); + + //褰撳墠浣忓畢 + 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); + } + else + { + //浣忓畢鍚嶇О + btnHome = rowLayout.frameTable.AddLeftCaption(info.Name, 800, true); + btnHome.TextSize = 15; + } + //鍙崇澶� + rowLayout.frameTable.AddRightArrow(); + if (addLine == true) + { + //搴曠嚎 + rowLayout.frameTable.AddBottomLine(); + } + + rowLayout.frameTable.ButtonClickEvent += (sender, e) => + { + if (info.Id != Config.Instance.Home.Id) + { + //纭鍒囨崲褰撳墠浣忓畢鍒般�屻��? + string msg = Language.StringByID(R.MyInternationalizationString.uSwitchResidenceMsg); + if (msg.Contains("{0}") == true) + { + msg = string.Format(msg, info.Name); + } + this.ShowMassage(ShowMsgType.Confirm, msg, () => + { + HdlThreadLogic.Current.RunThread(async () => + { + this.ShowProgressBar(); + + //妫�娴嬫湰鍦版湁娌℃湁杩欎釜浣忓畢 + this.CheckIsExsitResidence(info); + + Config.Instance.HomeId = info.Id; + //閲嶆柊鍒濆鍖栦綇瀹呭璞� + Config.Instance.Home = House.GetHouseByHouseId(info.Id); + Config.Instance.Save(); + //鍒锋柊涓汉涓績鐨勫唴瀛樺強绾跨▼ + await UserCenterLogic.InitUserCenterMenmoryAndThread(false); + + HdlRoomLogic.Current.InitAllRoom(); + + HdlThreadLogic.Current.RunMain(() => + { + //閲嶆柊鍒锋柊鍒楄〃 + this.listView.RemoveAll(); + this.SetResidenceInfo(); + }); + }); + }); + } + else + { + //妫�娴嬭兘鍚﹀垹闄や綇瀹� + bool flage = this.CheckIsCanDeleteResidence(info); + var form = new ResidenceManagementForm(); + form.AddForm(flage); + } + }; + + if (info.IsOthreShare == true) + { + //鍒嗕韩鐨�,涓嶈兘鏇存敼 + return; + } + //鏇存敼 + var btnChanged = rowLayout.AddEditorControl(); + btnChanged.TextID = R.MyInternationalizationString.uChanged1; + btnChanged.ButtonClickEvent += (sender, e) => + { + //鏄剧ず缂栬緫鍚嶇О鐣岄潰 + this.ShowEditorNameForm(info, btnHome); + }; + } + + #endregion + + #region 鈻� 缂栬緫浣忓畢鍚嶇О_______________________ + + /// <summary> + /// 鏄剧ず缂栬緫浣忓畢鍚嶇О鐣岄潰 + /// </summary> + /// <param name="info"></param> + private void ShowEditorNameForm(Common.ResponseEntity.ResidenceObj info, NormalViewControl btnHome) + { + //鐢熸垚涓�涓脊绐楃敾闈� + var dialogForm = new DialogInputControl(); + //缂栬緫浣忓畢 + dialogForm.SetTitleText(Language.StringByID(R.MyInternationalizationString.uChangedName)); + //璇疯緭鍏ヤ綇瀹呭悕绉� + dialogForm.SetTipText(Language.StringByID(R.MyInternationalizationString.uPleaseInputResidenceName)); + dialogForm.Text = info.Name; + + //鎸変笅纭鎸夐挳 + dialogForm.ComfirmClickEvent += ((textValue) => + { + if (textValue == string.Empty) + { + //璇疯緭鍏ヤ綇瀹呭悕绉� + string msg = Language.StringByID(R.MyInternationalizationString.uPleaseInputResidenceName); + this.ShowMassage(ShowMsgType.Error, msg); + return; + } + //鐢婚潰鍏抽棴 + dialogForm.CloseDialog(); + + if (info.Name != textValue) + { + //缂栬緫浜戠鐨勪綇瀹呭悕绉� + this.EditorResidenceName(textValue, info); + } + }); + } + + /// <summary> + /// 缂栬緫浜戠鐨勪綇瀹呭悕绉� + /// </summary> + /// <param name="ResidenceName"></param> + /// <param name="info"></param> + /// <returns></returns> + private async void EditorResidenceName(string ResidenceName, Common.ResponseEntity.ResidenceObj info) + { + //妫�娴嬭兘鍚︿繚瀛樹綇瀹� + if (this.CheckIsCanSaveResidence(info.Id, ResidenceName, true) == false) + { + return; + } + //寮�鍚繘搴︽潯 + this.ShowProgressBar(); + + var Pra = new EditorResidencePra(); + Pra.HomeId = info.Id; + Pra.Name = ResidenceName; + if (info.IsOthreShare == true) + { + Pra.LoginAccessToken = UserCenterLogic.GetConnectMainToken(); + } + //缂栬緫浣忓畢 + 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 + + #region 鈻� 娣诲姞浣忓畢鍚嶇О_______________________ + + /// <summary> + /// 鏄剧ず娣诲姞浣忓畢鍚嶇О鐨勭敾闈� + /// </summary> + private void ShowAddNameForm() + { + //鐢熸垚涓�涓脊绐楃敾闈� + var dialogForm = new DialogInputControl(); + //鍒涘缓浣忓畢 + dialogForm.SetTitleText(Language.StringByID(R.MyInternationalizationString.uCreatResidence)); + //璇疯緭鍏ヤ綇瀹呭悕绉� + dialogForm.SetTipText(Language.StringByID(R.MyInternationalizationString.uPleaseInputResidenceName)); + //鎸変笅纭鎸夐挳 + dialogForm.ComfirmClickEvent += ((textValue) => + { + if (textValue == string.Empty) + { + //璇疯緭鍏ヤ綇瀹呭悕绉� + string msg = Language.StringByID(R.MyInternationalizationString.uPleaseInputResidenceName); + this.ShowMassage(ShowMsgType.Error, msg); + return; + } + //鐢婚潰鍏抽棴 + dialogForm.CloseDialog(); + + //淇濆瓨浣忓畢 + this.AddNewResidence(textValue); + }); + } + + /// <summary> + /// 鍚戜簯绔坊鍔犳柊鐨勪綇瀹� + /// </summary> + /// <param name="ResidenceName"></param> + /// <returns></returns> + private async void AddNewResidence(string ResidenceName) + { + //妫�娴嬭兘鍚︿繚瀛樹綇瀹� + if (this.CheckIsCanSaveResidence(string.Empty, ResidenceName, false) == false) + { + return; + } + //寮�鍚繘搴︽潯 + this.ShowProgressBar(); + + var Pra = new AddResidencePra(); + Pra.Name = ResidenceName; + //娣诲姞浣忓畢 + string resultData = await UserCenterLogic.GetResponseDataByRequestHttps("App/AddHome", false, Pra); + if (resultData == null) + { + //鍏抽棴杩涘害鏉� + this.CloseProgressBar(); + return; + } + + var newInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<List<NewResidenceInfo>>(resultData); + + House.AddHouse(newInfo[0].Id, ResidenceName, 0); + //閲嶆柊鍒锋柊鍒楄〃 + this.listView.RemoveAll(); + this.SetResidenceInfo(); + } + + #endregion + + #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 (info.IsOthreShare == false) + { + int myCount = 0; + foreach (var data in this.dicResidenceData.Values) + { + if (data.IsOthreShare == false) + { + myCount++; + } + } + //濡傛灉姝よ处鍙蜂笅鍙墿涓嬪敮涓�涓�涓嚜宸辩殑浣忓畢锛屽垯涓嶈兘鍐嶅垹闄� + if (myCount == 1) + { + return false; + } + } + return true; + } + + /// <summary> + /// 妫�娴嬭兘鍚︿繚瀛樹綇瀹� + /// </summary> + /// <param name="residenceId">浣忓畢ID</param> + /// <param name="residenceName">浣忓畢鍚�</param> + /// <param name="isEditor">isEditor</param> + /// <returns></returns> + private bool CheckIsCanSaveResidence(string residenceId, string residenceName, bool isEditor) + { + //浣忓畢鍚嶅瓧閲嶅妫�娴� + foreach (string strId in this.dicResidenceData.Keys) + { + 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; + } + } + return true; + } + + #endregion + + #region 鈻� 鐣岄潰閲嶆柊婵�娲讳簨浠禵__________________ + + /// <summary> + /// 鑷韩鐨勪笂灞傜晫闈㈠叧闂悗,瀹冭嚜韬浜庢渶涓婂眰鏃�,瑙﹀彂鐨勪簨浠� + /// </summary> + public override int FormActionAgainEvent() + { + foreach (string keys in dicResidenceData.Keys) + { + if (Config.Instance.HomeFilePathList.Contains($"House_{keys}.json") == false) + { + //淇濆瓨椤哄簭 + listResidenceSort.Remove(keys); + HdlRoomLogic.Current.SaveFloorSort(listResidenceSort); + + this.listView.RemoveAll(); + //鏁版嵁宸茬粡鍙樻洿 + HdlThreadLogic.Current.RunThread(() => + { + //閲嶆柊璁剧疆浣忓畢淇℃伅 + this.SetResidenceInfo(); + }); + break; + } + } + return 1; + } + + #endregion + + #region 鈻� 缁撴瀯浣揰____________________________ + + /// <summary> + /// 璁块棶浣忓畢淇℃伅鎺ュ彛鐨勫惎鍔ㄥ弬鏁�(鏌ヨ涓撶敤) + /// </summary> + public class GetResidenceInfoPra : IfacePraCommon + { + /// <summary> + /// RequestVersion + /// </summary> + public string RequestVersion = Common.CommonPage.RequestVersion; + /// <summary> + /// ReqDto + /// </summary> + public TokenInfo ReqDto = new TokenInfo(); + } + + /// <summary> + /// 璁块棶浣忓畢淇℃伅鎺ュ彛鐨勫惎鍔ㄥ弬鏁�(鏌ヨ涓撶敤) + /// </summary> + public class TokenInfo + { + /// <summary> + /// LoginAccessToken + /// </summary> + public string LoginAccessToken = Common.Config.Instance.Token; + /// <summary> + /// PageSetting + /// </summary> + public PageSettingInfo PageSetting = new PageSettingInfo() + { + Page = 1, + PageSize = 5000 + }; + } + + /// <summary> + /// 娣诲姞浣忓畢鐨勫惎鍔ㄥ弬鏁� + /// </summary> + public class AddResidencePra : IfacePraCommon + { + /// <summary> + /// RequestVersion + /// </summary> + public string RequestVersion = Common.CommonPage.RequestVersion; + /// <summary> + /// LoginAccessToken + /// </summary> + public string LoginAccessToken = Common.Config.Instance.Token; + /// <summary> + /// Name + /// </summary> + public string Name = string.Empty; + } + + /// <summary> + /// 鏂颁綇瀹呯殑淇℃伅 + /// </summary> + public class NewResidenceInfo + { + /// <summary> + /// ZigbeeHomeGuid + /// </summary> + public string Id = string.Empty; + } + + #endregion + } +} -- Gitblit v1.8.0