| | |
| | | /// 创建新的住宅(返回住宅id,null代表失败)
|
| | | /// </summary>
|
| | | /// <param name="residenceName">住宅名称</param>
|
| | | public async System.Threading.Tasks.Task<string> CreatNewResidence(string residenceName)
|
| | | public string CreatNewResidence(string residenceName)
|
| | | {
|
| | | 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)
|
| | | {
|
| | | return null;
|
| | | }
|
| | |
| | | /// </summary>
|
| | | /// <param name="residenceId"></param>
|
| | | /// <returns></returns>
|
| | | public async System.Threading.Tasks.Task SwitchResidence(string residenceId)
|
| | | public bool SwitchResidence(string residenceId)
|
| | | {
|
| | | //打开进度条
|
| | | ProgressBar.Show();
|
| | |
| | | Config.Instance.Home = this.GetHouseByHouseId(residenceId);
|
| | | Config.Instance.Save();
|
| | | //刷新个人中心的内存及线程
|
| | | await UserCenterLogic.InitUserCenterMenmoryAndThread(false);
|
| | | bool result = UserCenterLogic.InitUserCenterMenmoryAndThread(false);
|
| | |
|
| | | //关闭进度条
|
| | | ProgressBar.Close();
|
| | |
|
| | | return result;
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
| | | /// <param name="residenceId">住宅id</param>
|
| | | /// <param name="residenceName">住宅名称</param>
|
| | | /// <returns></returns>
|
| | | public async System.Threading.Tasks.Task<bool> EditorResidenceName(string residenceId, string residenceName)
|
| | | public bool EditorResidenceName(string residenceId, string residenceName)
|
| | | {
|
| | | var Pra = new EditorResidencePra();
|
| | | Pra.HomeId = residenceId;
|
| | |
| | | Pra.LoginAccessToken = Config.Instance.Token;
|
| | |
|
| | | //编辑住宅
|
| | | bool flage = await UserCenterLogic.GetResultStatuByRequestHttps("App/EditHome", false, Pra);
|
| | | bool flage = UserCenterLogic.GetResultStatuByRequestHttps("App/EditHome", false, Pra);
|
| | | if (flage == true)
|
| | | {
|
| | | //刷新内存的住宅名
|
| | |
| | | home.Name = residenceName;
|
| | | home.Save();
|
| | | //住宅修改名称的话,主页需要重新刷新
|
| | | UserView.UserPage.Instance.RefreshForm = true;
|
| | | UserView.UserPage.Instance.RefreshAllForm = true;
|
| | | }
|
| | |
|
| | |
|
| | |
| | | public House GetHouseByHouseId(string houseId)
|
| | | {
|
| | | var path = System.IO.Path.Combine(Shared.IO.FileUtils.RootPath, Config.Instance.Guid, houseId, $"House_{houseId}.json");
|
| | | var file = Shared.IO.FileUtils.ReadFile(path);
|
| | | var file = HdlFileLogic.Current.ReadFileByteContent(path);
|
| | | if (file == null)
|
| | | {
|
| | | return null;
|
| | |
| | | public House GetHouseByFilePath(string filePath)
|
| | | {
|
| | | var path = System.IO.Path.Combine(Shared.IO.FileUtils.RootPath, Config.Instance.Guid, GetHouseIdByFilePath(filePath), filePath);
|
| | | var file = Shared.IO.FileUtils.ReadFile(path);
|
| | | var file = HdlFileLogic.Current.ReadFileByteContent(path);
|
| | | if (file == null)
|
| | | {
|
| | | return null;
|
| | |
| | | /// <summary>
|
| | | /// 获取云端住宅列表
|
| | | /// </summary>
|
| | | public async System.Threading.Tasks.Task<List<string>> GetHomeListsFromDb()
|
| | | /// <param name="checkNetwork">是否检测网络,如果设置检测的话,当不能联网时,直接返回本地住宅</param>
|
| | | /// <returns></returns>
|
| | | public List<string> GetHomeListsFromDb(bool checkNetwork)
|
| | | {
|
| | | var pageSetting = new SendDataToServer.ResidenceListPageSettingObj()
|
| | | if (checkNetwork == true && HdlWifiLogic.Current.CanAccessHttp == false)
|
| | | {
|
| | | PageSize = CommonPage.PageSize
|
| | | };
|
| | |
|
| | | var reqDto = new SendDataToServer.ResidenceListObj()
|
| | | {
|
| | | LoginAccessToken = Config.Instance.Token,
|
| | | PageSetting = pageSetting
|
| | | };
|
| | | //当前无法联网
|
| | | return Config.Instance.HomeFilePathList;
|
| | | }
|
| | | var requestObj = new SendDataToServer.ResidenceListReqDto()
|
| | | {
|
| | | ReqDto = reqDto,
|
| | | RequestVersion = CommonPage.RequestVersion,
|
| | | ReqDto = new SendDataToServer.ResidenceListObj()
|
| | | {
|
| | | LoginAccessToken = Config.Instance.Token,
|
| | | PageSetting = new SendDataToServer.ResidenceListPageSettingObj { PageSize = 999 }
|
| | | }
|
| | | };
|
| | | try
|
| | | {
|
| | | var requestJson = Newtonsoft.Json.JsonConvert.SerializeObject(requestObj);
|
| | | var revertObj = await CommonPage.Instance.RequestHttpsZigbeeAsync("App/GetHomePager", System.Text.Encoding.UTF8.GetBytes(requestJson));
|
| | | var revertObj = CommonPage.Instance.RequestHttpsZigbeeAsync("App/GetHomePager", System.Text.Encoding.UTF8.GetBytes(requestJson), 5);
|
| | | if (revertObj == null)
|
| | | {
|
| | | return null;
|
| | |
| | | if (revertObj.StateCode.ToUpper() == "SUCCESS")
|
| | | {
|
| | | var responseDataObj = Newtonsoft.Json.JsonConvert.DeserializeObject<Shared.Common.ResponseEntity.ResidenceRes>(revertObj.ResponseData.ToString());
|
| | | if(responseDataObj.TotalCount>0)
|
| | | if (responseDataObj.TotalCount > 0)
|
| | | {
|
| | | //清空当前住宅列表
|
| | | Config.Instance.HomeFilePathList.Clear();
|
| | |
| | | var listHome = new List<Common.House>();
|
| | | foreach (var housePath in Common.Config.Instance.HomeFilePathList)
|
| | | {
|
| | | var home =this.GetHouseByFilePath(housePath);
|
| | | var home = this.GetHouseByFilePath(housePath);
|
| | | if (home == null)
|
| | | {
|
| | | continue;
|
| | | }
|
| | | listHome.Add(home);
|
| | | }
|
| | | return listHome;
|
| | | return this.SortHouse(listHome);
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | |
| | | if (arryHouse.Length > 0)
|
| | | {
|
| | | //读取文件内容
|
| | | var textValue = UserCenterLogic.LoadFileContent(System.IO.Path.Combine(nowPath, arryHouse[0]));
|
| | | var textValue = HdlFileLogic.Current.ReadFileTextContent(System.IO.Path.Combine(nowPath, arryHouse[0]));
|
| | | if (textValue == null)
|
| | | {
|
| | | continue;
|
| | |
| | | listHome.Add(myHouse);
|
| | | }
|
| | | }
|
| | | return listHome;
|
| | | return this.SortHouse(listHome);
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 住宅排序___________________________
|
| | |
|
| | | /// <summary>
|
| | | /// 住宅排序
|
| | | /// </summary>
|
| | | /// <param name="i_listHouse"></param>
|
| | | /// <returns></returns>
|
| | | public List<House> SortHouse(List<House> i_listHouse)
|
| | | {
|
| | | //从一堆文字中,获取这一堆文字里面数字字符串的最长长度
|
| | | var listName = new List<string>();
|
| | | foreach (var house in i_listHouse)
|
| | | {
|
| | | listName.Add(house.Name);
|
| | | }
|
| | | int numberLength = this.GetNumberMaxLength(listName);
|
| | |
|
| | | var listSort = new List<string[]>();
|
| | | var dicHouse = new Dictionary<string, House>();
|
| | | foreach (var house in i_listHouse)
|
| | | {
|
| | | //临时缓存
|
| | | dicHouse[house.Id] = house;
|
| | |
|
| | | var strArry = new string[2];
|
| | | strArry[0] = house.Id;
|
| | | strArry[1] = string.Empty;
|
| | |
|
| | | string value = string.Empty;
|
| | | foreach (var c in house.Name)
|
| | | {
|
| | | if (char.IsNumber(c) == true)
|
| | | {
|
| | | //数字
|
| | | value += c.ToString();
|
| | | continue;
|
| | | }
|
| | | else if (value != string.Empty)
|
| | | {
|
| | | //如果房间名字带有数字的话,则左边加零,因为这里有个排序的问题
|
| | | strArry[1] += value.PadLeft(numberLength, '0');
|
| | | value = string.Empty;
|
| | | }
|
| | | strArry[1] += c.ToString();
|
| | | }
|
| | | if (value != string.Empty)
|
| | | {
|
| | | //以数字结尾的话
|
| | | strArry[1] += value.PadLeft(numberLength, '0');
|
| | | }
|
| | | listSort.Add(strArry);
|
| | | }
|
| | | //排序
|
| | | listSort.Sort((obj1, obj2) =>
|
| | | {
|
| | | if (obj1[1].CompareTo(obj2[1]) > 0)
|
| | | {
|
| | | return 1;
|
| | | }
|
| | | return -1;
|
| | | });
|
| | | var listSortHouse = new List<House>();
|
| | | foreach (var strArry in listSort)
|
| | | {
|
| | | listSortHouse.Add(dicHouse[strArry[0]]);
|
| | | }
|
| | | return listSortHouse;
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 云端住宅排序
|
| | | /// </summary>
|
| | | /// <param name="i_listData"></param>
|
| | | /// <returns></returns>
|
| | | public List<Common.ResponseEntity.ResidenceObj> SortHouse(List<Common.ResponseEntity.ResidenceObj> i_listData)
|
| | | {
|
| | | //从一堆文字中,获取这一堆文字里面数字字符串的最长长度
|
| | | var listName = new List<string>();
|
| | | foreach (var house in i_listData)
|
| | | {
|
| | | listName.Add(house.Name);
|
| | | }
|
| | | int numberLength = this.GetNumberMaxLength(listName);
|
| | |
|
| | | var listSort = new List<string[]>();
|
| | | var dicHouse = new Dictionary<string, Common.ResponseEntity.ResidenceObj>();
|
| | | foreach (var house in i_listData)
|
| | | {
|
| | | //临时缓存
|
| | | dicHouse[house.Id] = house;
|
| | |
|
| | | var strArry = new string[2];
|
| | | strArry[0] = house.Id;
|
| | | strArry[1] = string.Empty;
|
| | |
|
| | | string value = string.Empty;
|
| | | foreach (var c in house.Name)
|
| | | {
|
| | | if (char.IsNumber(c) == true)
|
| | | {
|
| | | //数字
|
| | | value += c.ToString();
|
| | | continue;
|
| | | }
|
| | | else if (value != string.Empty)
|
| | | {
|
| | | //如果房间名字带有数字的话,则左边加零,因为这里有个排序的问题
|
| | | strArry[1] += value.PadLeft(numberLength, '0');
|
| | | value = string.Empty;
|
| | | }
|
| | | strArry[1] += c.ToString();
|
| | | }
|
| | | if (value != string.Empty)
|
| | | {
|
| | | //以数字结尾的话
|
| | | strArry[1] += value.PadLeft(numberLength, '0');
|
| | | }
|
| | | listSort.Add(strArry);
|
| | | }
|
| | | //排序
|
| | | listSort.Sort((obj1, obj2) =>
|
| | | {
|
| | | if (obj1[1].CompareTo(obj2[1]) > 0)
|
| | | {
|
| | | return 1;
|
| | | }
|
| | | return -1;
|
| | | });
|
| | | var listSortHouse = new List<Common.ResponseEntity.ResidenceObj>();
|
| | | foreach (var strArry in listSort)
|
| | | {
|
| | | listSortHouse.Add(dicHouse[strArry[0]]);
|
| | | }
|
| | | return listSortHouse;
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 从一堆文字中,获取这一堆文字里面数字字符串的最长长度
|
| | | /// </summary>
|
| | | /// <param name="listText"></param>
|
| | | /// <returns></returns>
|
| | | private int GetNumberMaxLength(List<string> listText)
|
| | | {
|
| | | int maxLength = 0;
|
| | | foreach (var text in listText)
|
| | | {
|
| | | string value = string.Empty;
|
| | | foreach (var c in text)
|
| | | {
|
| | | if (char.IsNumber(c) == true)
|
| | | {
|
| | | //数字
|
| | | value += c.ToString();
|
| | | continue;
|
| | | }
|
| | | else if (value != string.Empty)
|
| | | {
|
| | | //判断数字长度
|
| | | if (maxLength <= value.Length)
|
| | | {
|
| | | maxLength = value.Length;
|
| | | }
|
| | | value = string.Empty;
|
| | | }
|
| | | }
|
| | | //判断数字长度
|
| | | if (maxLength <= value.Length)
|
| | | {
|
| | | maxLength = value.Length;
|
| | | }
|
| | | }
|
| | | return maxLength;
|
| | | }
|
| | |
|
| | | #endregion
|