From e5f993f52e09eb46878baced83bb8492f147d41c Mon Sep 17 00:00:00 2001 From: WJC <wjc@hdlchina.com.cn> Date: 星期一, 04 十一月 2019 17:58:40 +0800 Subject: [PATCH] 2019-11-04-1 --- ZigbeeApp/Shared/Common/Room.cs | 835 ++++++++++++++++++++++++++++++++++------------------------- 1 files changed, 483 insertions(+), 352 deletions(-) diff --git a/ZigbeeApp/Shared/Common/Room.cs b/ZigbeeApp/Shared/Common/Room.cs old mode 100755 new mode 100644 index d29e34b..b15f457 --- a/ZigbeeApp/Shared/Common/Room.cs +++ b/ZigbeeApp/Shared/Common/Room.cs @@ -44,7 +44,7 @@ { get { - return GetFloorNameById(FloorId); + return Config.Instance.Home.GetFloorNameById(FloorId); } } /// <summary> @@ -67,12 +67,12 @@ /// </summary> public Dictionary<string, string> FloorList = new Dictionary<string, string> { }; - /// <summary> - /// 娓╁害浼犳劅鍣�(璁惧涓婚敭) + /// <summary> + /// 娓╁害浼犳劅鍣�(璁惧涓婚敭) /// </summary> public string TemperatrueDevice = string.Empty; - /// <summary> - /// 婀垮害浼犳劅鍣�(璁惧涓婚敭) + /// <summary> + /// 婀垮害浼犳劅鍣�(璁惧涓婚敭) /// </summary> public string HumidityDevice = string.Empty; @@ -94,7 +94,7 @@ /// <summary> /// 鍠滅埍鎴块棿id /// </summary> - public const string LoveRoomId= "Favorite"; + public const string LoveRoomId = "Favorite"; /// <summary> /// 鏄惁鏄粯璁ゅ枩鐖辨埧闂� @@ -134,17 +134,34 @@ { return new List<string> { }; } - return GetLoveRoom().DeviceUIFilePathList; + return CurrentRoom.GetLoveRoom().DeviceUIFilePathList; } } /// <summary> /// 鎵�鏈夋埧闂寸殑鎵�鏈夎澶囩被鍨� - /// 鍏堣皟鐢� GetAllRoomDeviceTypeList() /// </summary> /// <value>All room device type list.</value> [Newtonsoft.Json.JsonIgnore] - public static List<DeviceType> AllRoomDeviceTypeList = new List<DeviceType> { }; + public static List<DeviceType> AllRoomDeviceTypeList + { + get + { + var typeList = new List<DeviceType> { }; + foreach (var deviceUI in AllRoomDeviceUIList) + { + if (deviceUI == null || deviceUI.CommonDevice == null) + { + continue; + } + if (!typeList.Contains(deviceUI.CommonDevice.Type)) + { + typeList.Add(deviceUI.CommonDevice.Type); + } + } + return typeList; + } + } /// <summary> /// 鑾峰彇鎵�鏈夋埧闂寸殑鎵�鏈夊満鏅� @@ -191,11 +208,41 @@ /// <summary> /// 鑾峰彇鎵�鏈夋埧闂寸殑鎵�鏈夎澶� - /// 璇峰厛璋冪敤 GetAllRoomDeviceUIList()鏂规硶 /// </summary> /// <value>All room device UIL ist.</value> [Newtonsoft.Json.JsonIgnore] - public static List<DeviceUI> AllRoomDeviceUIList = new List<DeviceUI> { }; + public static List<DeviceUI> AllRoomDeviceUIList + { + get + { + List<DeviceUI> deviceList = new List<DeviceUI>(); + for (int i = 0; i < Lists.Count; i++) + { + var room = Lists[i]; + if (room.IsSharedRoom) + { + continue; + } + if (room.DeviceUIList.Count == 0) + { + continue; + } + for (int j = 0; j < room.DeviceUIList.Count; j++) + { + var device = room.DeviceUIList[j]; + if (device == null || device.CommonDevice == null) + { + continue; + } + if (deviceList.Find((obj) => obj.FileName == device.FileName) == null) + { + deviceList.Add(device); + } + } + } + return deviceList; + } + } #endregion @@ -249,35 +296,35 @@ } } - /// <summary> - /// 浠庢湰鍦伴噸鏂板姞杞藉叏閮ㄧ殑鎴块棿 + /// <summary> + /// 浠庢湰鍦伴噸鏂板姞杞藉叏閮ㄧ殑鎴块棿 /// </summary> - public static void RefreshAllRoomByLocation() - { - Lists.Clear(); - var homeTemp = Config.Instance.Home; - homeTemp.RoomFilePathList.Clear(); - - var listFile = Global.FileListByHomeId(); - - //鎴戠殑鍠滅埍鐨勬埧闂村繀椤昏鍦ㄧ0浣嶆墠琛� - string fRoom = "Room_Favorite.json"; - if (listFile.Contains(fRoom) == true) - { - listFile.Remove(fRoom); - homeTemp.AddRoomListFilePath(fRoom); - } - - foreach (string fileName in listFile) - { - if (fileName.StartsWith("Room_")) - { - homeTemp.AddRoomListFilePath(fileName); - } - } - homeTemp.Save(false); - CanInitAllRoom = true; - InitAllRoom(); + public static void RefreshAllRoomByLocation() + { + Lists.Clear(); + var homeTemp = Config.Instance.Home; + homeTemp.RoomFilePathList.Clear(); + + var listFile = Global.FileListByHomeId(); + + //鎴戠殑鍠滅埍鐨勬埧闂村繀椤昏鍦ㄧ0浣嶆墠琛� + string fRoom = "Room_Favorite.json"; + if (listFile.Contains(fRoom) == true) + { + listFile.Remove(fRoom); + homeTemp.AddRoomListFilePath(fRoom); + } + + foreach (string fileName in listFile) + { + if (fileName.StartsWith("Room_")) + { + homeTemp.AddRoomListFilePath(fileName); + } + } + homeTemp.Save(false); + CanInitAllRoom = true; + InitAllRoom(); } #endregion @@ -349,7 +396,7 @@ /// 鑾峰彇鍠滅埍鎴块棿 /// </summary> /// <returns></returns> - public static Room GetLoveRoom() + public Room GetLoveRoom() { return CurrentRoom.GetRoomById(LoveRoomId); } @@ -382,7 +429,7 @@ //璁惧锛坉eviceUI锛� beforeRoom.DeviceUIList.Clear(); foreach (var deviceFilePath in beforeRoom.DeviceUIFilePathList) - { + { beforeRoom.DeviceUIList.Add(Common.LocalDevice.Current.GetDeviceUI(deviceFilePath)); } //鍦烘櫙(SceneUI) @@ -433,7 +480,7 @@ } return nowRoom; } - catch(Exception ex) + catch (Exception ex) { return null; } @@ -450,6 +497,16 @@ } /// <summary> + /// 鏍规嵁鎴块棿鍚嶅瓧锛岃幏鍙栨埧闂村璞� + /// </summary> + /// <returns>The room by name.</returns> + /// <param name="roomName">鎴块棿鍚�</param> + public Room GetRoomByName(string roomName) + { + return Lists.Find((obj) => obj.Name == roomName); + } + + /// <summary> /// 鏍规嵁璁惧鑾峰彇鎴块棿鍚嶅瓧(妤煎眰+鎴块棿鍚�) /// </summary> /// <returns>鎴块棿鍚�</returns> @@ -457,15 +514,15 @@ public string GetRoomNameByDevice(CommonDevice device) { var room = this.GetRoomByDevice(device); - if (room == null) - { - //鏈垎閰嶅尯鍩� - return Language.StringByID(R.MyInternationalizationString.uDeviceNotAssignedRoom); + if (room == null) + { + //鏈垎閰嶅尯鍩� + return Language.StringByID(R.MyInternationalizationString.uDeviceNotAssignedRoom); } - if (Config.Instance.Home.FloorDics.ContainsKey(room.FloorId) == true) - { - //(妤煎眰+鎴块棿鍚�) - return Config.Instance.Home.FloorDics[room.FloorId] + " " + room.Name; + if (Config.Instance.Home.FloorDics.ContainsKey(room.FloorId) == true) + { + //(妤煎眰+鎴块棿鍚�) + return Config.Instance.Home.FloorDics[room.FloorId] + " " + room.Name; } return room.Name; } @@ -477,11 +534,11 @@ /// <param name="device">璁惧瀵硅薄</param> public Room GetRoomByDevice(CommonDevice device) { - var deviceUI = new DeviceUI { }; - deviceUI.DeviceAddr = device.DeviceAddr; + var deviceUI = new DeviceUI { }; + deviceUI.DeviceAddr = device.DeviceAddr; deviceUI.DeviceEpoint = device.DeviceEpoint; - return Lists.Find((obj) => obj.DeviceUIFilePathList.Contains(deviceUI.FileName)); + return Lists.Find((obj) => obj.IsLove == false && obj.DeviceUIFilePathList.Contains(deviceUI.FileName)); } /// <summary> @@ -519,6 +576,55 @@ return null; } + /// <summary> + /// 鑾峰彇褰撳墠妤煎眰鐨勬埧闂� + /// </summary> + /// <param name="id"></param> + /// <returns></returns> + public List<Room> GetRoomsByFloorId(string id) + { + return Lists.FindAll((obj) => obj.FloorId == id); + } + /// <summary> + /// 鑾峰彇褰撳墠妤煎眰鐨勬埧闂村悕绉� + /// </summary> + /// <param name="id"></param> + /// <returns></returns> + public List<string> GetRoomNamesByFloorId(string id) + { + List<string> names = new List<string> { }; + foreach (var r in Lists) + { + if (r.FloorId == id) + { + names.Add(r.Name); + } + } + return names; + } + + /// <summary> + /// 鑾峰彇褰撳墠妤煎眰鐨勬埧闂�(鎷兼帴浜嗐�愬父鐢ㄣ�戝湪绗竴浣�) + /// </summary> + /// <param name="id"></param> + /// <returns></returns> + public List<Room> GetRoomsByFloorIdAppendLoveRoom(string id) + { + var r = Lists.FindAll((obj) => obj.FloorId == id); + r.Insert(0, GetLoveRoom()); + return r; + } + + /// <summary> + /// 鑾峰彇褰撳墠妤煎眰鐨勬埧闂�(鎷兼帴浜嗐�愬父鐢ㄣ�戝湪绗竴浣�) + /// </summary> + /// <returns></returns> + public List<Room> GetRoomsByCurrentFloorIdAppendLoveRoom() + { + var r = Lists.FindAll((obj) => obj.FloorId == Config.Instance.Home.CurrentFloorId); + r.Insert(0, GetLoveRoom()); + return r; + } #endregion @@ -541,12 +647,12 @@ //娣诲姞鍒版柊鐨勬埧闂� var room = this.GetRoomById(roomId); - if (room != null) - { - room.AddDevice(device); + if (room != null) + { + room.AddDevice(device); } - } - + } + /// <summary> /// 鎴块棿鍚嶅瓧鏄惁鏈変慨鏀� /// </summary> @@ -556,9 +662,9 @@ public bool IsRoomChanged(CommonDevice device, string roomId) { var room = this.GetRoomByDevice(device); - if (room == null || room.Id != roomId) - { - return true; + if (room == null || room.Id != roomId) + { + return true; } return false; } @@ -615,7 +721,7 @@ try { var newPath = System.IO.Path.Combine(Config.Instance.FullPath, newFile); - var path = System.IO.Path.Combine(Shared.IO.FileUtils.RootPath,oldFile); + var path = System.IO.Path.Combine(Shared.IO.FileUtils.RootPath, oldFile); Global.MoveFileToDirectory(path, newPath); //澶囦唤 Phone.UserCenter.HdlAutoBackupLogic.AddOrEditorFile(oldFile); @@ -689,7 +795,6 @@ #endregion #region 鈼� 鍒犻櫎璁惧_________________________ - /// <summary> /// 鍒犻櫎鍔熻兘-璁惧 /// </summary> @@ -717,64 +822,31 @@ return; } DeviceUI deviceUI = new DeviceUI(); - deviceUI.DeviceAddr = device.DeviceAddr; + deviceUI.DeviceAddr = device.DeviceAddr; deviceUI.DeviceEpoint = device.DeviceEpoint; //鏍规嵁璁惧锛岃幏鍙栨墍鍦ㄧ殑鎴块棿 var room = this.GetRoomByDevice(device); - if (room == null) - { - return; - } - //绉婚櫎缂撳瓨 - if (room.DeviceUIFilePathList.Contains(deviceUI.FileName) == false) - { - return; - } - room.DeviceUIFilePathList.Remove(deviceUI.FileName); - - room.DeviceUIList.RemoveAll((obj) => obj.FileName == deviceUI.FileName); - room.Save(); - //鏇存敼鑷姩澶囦唤 + if (room == null) + { + return; + } + //绉婚櫎缂撳瓨 + if (room.DeviceUIFilePathList.Contains(deviceUI.FileName) == false) + { + return; + } + room.DeviceUIFilePathList.Remove(deviceUI.FileName); + + room.DeviceUIList.RemoveAll((obj) => obj.FileName == deviceUI.FileName); + room.Save(); + //鏇存敼鑷姩澶囦唤 HdlAutoBackupLogic.AddOrEditorFile(room.FileName); } #endregion #region 鈼� 鑾峰彇璁惧_________________________ - - /// <summary> - /// 鑾峰彇鎵�鏈夋埧闂寸殑鎵�鏈夎澶� - /// </summary> - public static void GetAllRoomDeviceUIList() - { - List<string> devicePathList = new List<string>(); - //鎵�鏈夋埧闂寸殑鎵�鏈夎澶� - AllRoomDeviceUIList.Clear(); - foreach (var room in Shared.Common.Room.Lists) - { - if(room.IsSharedRoom) - { - continue; - } - if (room.DeviceUIList.Count == 0) - { - continue; - } - foreach (var device in room.DeviceUIList) - { - if (device == null || device.CommonDevice == null) - { - continue; - } - if (!devicePathList.Contains(device.FileName)) - { - AllRoomDeviceUIList.Add(device); - devicePathList.Add(device.FileName); - } - } - } - } /// <summary> /// 鏍规嵁璁惧鑾峰彇瀹冪殑UI瀵硅薄锛屽鏋滀笉瀛樺湪鍒欐柊寤� @@ -787,44 +859,105 @@ } /// <summary> - /// 閲嶆柊鑾峰彇-鎵�鏈夋埧闂寸殑鎵�鏈夎澶囩被鍨� + /// 鑾峰彇褰撳墠鎴块棿涓嬬殑鍏ㄩ儴璁惧 /// </summary> - public static void GetAllRoomDeviceTypeList() + /// <returns></returns> + public List<CommonDevice> GetRoomListDevice() { - AllRoomDeviceTypeList.Clear(); - foreach (var deviceUI in AllRoomDeviceUIList) + var listDevice = new List<CommonDevice>(); + foreach (var device in this.DeviceUIList) + { + if (device == null || device.CommonDevice == null) + { + continue; + } + listDevice.Add(device.CommonDevice); + } + if (listDevice.Count == 0) + { + return listDevice; + } + return Common.LocalDevice.Current.SortDevice(listDevice); + } + + /// <summary> + /// 鑾峰彇鎴块棿璁惧绫诲瀷 + /// </summary> + /// <param name="room"></param> + /// <returns></returns> + public static List<DeviceType> GetdeviceTypes(Room room) + { + List<DeviceType> typeList = new List<DeviceType> { }; + foreach (var deviceUI in room.DeviceUIList) { if (deviceUI == null || deviceUI.CommonDevice == null) { continue; } - if (!AllRoomDeviceTypeList.Contains(deviceUI.CommonDevice.Type)) + if (!typeList.Contains(deviceUI.CommonDevice.Type)) { - AllRoomDeviceTypeList.Add(deviceUI.CommonDevice.Type); + typeList.Add(deviceUI.CommonDevice.Type); } } + return typeList; } - /// <summary> - /// 鑾峰彇褰撳墠鎴块棿涓嬬殑鍏ㄩ儴璁惧 - /// </summary> + /// <summary> + /// 鑾峰彇璇ョ被鍨嬬殑璁惧 + /// </summary> + /// <param name="room"></param> + /// <param name="deviceType"></param> /// <returns></returns> - public List<CommonDevice> GetRoomListDevice() - { - var listDevice = new List<CommonDevice>(); - foreach (var device in this.DeviceUIList) - { - if (device == null || device.CommonDevice == null) - { - continue; - } - listDevice.Add(device.CommonDevice); - } - if (listDevice.Count == 0) - { - return listDevice; - } - return Common.LocalDevice.Current.SortDevice(listDevice); + public static List<DeviceUI> GetDeviceUIs(Room room, DeviceType deviceType) + { + List<DeviceUI> typeList = new List<DeviceUI> { }; + foreach (var deviceUI in room.DeviceUIList) + { + if (deviceUI == null || deviceUI.CommonDevice == null) + { + continue; + } + if (deviceUI.CommonDevice.Type != deviceType) + { + continue; + } + if (!typeList.Contains(deviceUI)) + { + typeList.Add(deviceUI); + } + } + return typeList; + } + + /// <summary> + /// 鑾峰彇璇ユゼ灞傜殑鍦烘櫙 + /// </summary> + /// <param name="floorId"></param> + /// <returns></returns> + public List<SceneUI> GetSceneUIsByFloorId(string floorId) + { + var rooms = GetRoomsByFloorId(floorId); + if (rooms == null) + { + return null; + } + var sceneList = new List<SceneUI> { }; + foreach (var r in rooms) + { + if (r.SceneUIList.Count == 0) + { + continue; + } + foreach (var sceneUI in r.SceneUIList) + { + if (sceneUI == null) + { + continue; + } + sceneList.Add(sceneUI); + } + } + return sceneList; } #endregion @@ -841,25 +974,21 @@ /// <param name="iconPathType">I鍦烘櫙鑳屾櫙鍥剧墖鏉ユ簮绫诲瀷 鍥剧墖鏉ユ簮 0--鏈湴鍥惧簱 1--鎷嶇収 2--绯荤粺鍥惧簱 榛樿0</param> public async System.Threading.Tasks.Task<int> AddScene(string sceneName, string sceneIconPath, List<ZigBee.Device.Scene.AddSceneMemberData> commons, int iconPathType = 0) { - if (AllRoomSceneUIList.Find(s => s.Name == sceneName) != null) + var scenes = GetSceneUIsByFloorId(FloorId); + if (scenes != null && scenes.Count > 0) { - return -1; + if (scenes.Find(s => s.Name == sceneName) != null) + { + return -1; + } } + var getSceneIdAllData = await ZigBee.Device.Scene.GetSceneNewIdAsync(sceneName); if (getSceneIdAllData == null || getSceneIdAllData.getSceneIdData == null) { return 0; } var getSceneIdData = getSceneIdAllData.getSceneIdData; - //寰幆鐩稿悓鎶ラ敊 - foreach (var tempSceneUI in AllRoomSceneUIList) - { - if (tempSceneUI.Id == getSceneIdAllData.getSceneIdData.NewScenesId) - { - //鍦烘櫙宸插瓨鍦� - return -1; - } - } bool result = true; foreach (var common in commons) @@ -867,12 +996,13 @@ //娣诲姞鏂版垚鍛� var addSceneMemberData = new ZigBee.Device.Scene.AddSceneMemberData { - DeviceAddr = common.DeviceAddr, Type = common.Type, + DeviceAddr = common.DeviceAddr, Epoint = common.Epoint, ScenesId = getSceneIdData.NewScenesId, TaskList = common.TaskList, DelayTime = common.DelayTime, + MemberNumber = common.MemberNumber, ElseScenesId = common.ElseScenesId }; //common.ScenesId = getSceneIdData.NewScenesId; @@ -904,7 +1034,7 @@ Id = getSceneIdData.NewScenesId, IconPath = fullPath, IconPathType = iconPathType, - AddSceneMemberDataList= commons + AddSceneMemberDataList = commons }; SceneUIList.Add(sceneUI); SceneUIFilePathList.Add(sceneUI.FileName); @@ -922,17 +1052,30 @@ /// <param name="scene">Scene.</param> public void AddScene(SceneUI scene) { - var sceneUI = new SceneUI - { - Name = scene.Name, - Id = scene.Id, - IconPath = scene.IconPath, - IconPathType = scene.IconPathType, - AddSceneMemberDataList = scene.AddSceneMemberDataList - }; - SceneUIList.Add(sceneUI); - SceneUIFilePathList.Add(sceneUI.FileName); - sceneUI.Save(); + //var sceneUI = new SceneUI + //{ + // Name = scene.Name, + // Id = scene.Id, + // IconPath = scene.IconPath, + // IconPathType = scene.IconPathType, + // AddSceneMemberDataList = scene.AddSceneMemberDataList + //}; + SceneUIList.Add(scene); + SceneUIFilePathList.Add(scene.FileName); + scene.Save(); + Save(); + } + + /// <summary> + /// 鍒犻櫎鍦烘櫙 + /// </summary> + /// <param name="scene"></param> + public void DeleteScene(SceneUI scene) + { + //scene.IsCollected = false; + scene.Save(); + SceneUIList.Remove(scene); + SceneUIFilePathList.Remove(scene.FileName); Save(); } @@ -946,9 +1089,9 @@ /// <param name="room"></param> /// <param name="filePath"></param> /// <returns></returns> - public bool IsCollectInRoom(Room room,string filePath) + public bool IsCollectInRoom(Room room, string filePath) { - if(room.IsLove) + if (room.IsLove) { return true; } @@ -1004,7 +1147,8 @@ ScenesId = sceneUI.Id, TaskList = addCommon.TaskList, DelayTime = addCommon.DelayTime, - ElseScenesId = addCommon.ElseScenesId + ElseScenesId = addCommon.ElseScenesId, + MemberNumber = addCommon.MemberNumber }; //娣诲姞鏂版垚鍛� 杩斿洖缁撴灉 var addSceneMemberResponseAllData = await ZigBee.Device.Scene.AddSceneMemberAsync(addSceneMemberData); @@ -1040,7 +1184,7 @@ /// <param name="sceneUI">Scene user interface.</param> public void RemoveScene(SceneUI sceneUI) { - if(Global.IsExistsByHomeId(sceneUI.FileName)==false) + if (Global.IsExistsByHomeId(sceneUI.FileName) == false) { return; } @@ -1075,7 +1219,21 @@ } return null; } - + /// <summary> + /// 鑾峰彇璇ユゼ灞傛墍鏈夊満鏅� + /// </summary> + /// <param name="floorId"></param> + /// <returns></returns> + public List<SceneUI> GetSameFloorScenes(string floorId) + { + List<SceneUI> sceneUIs = new List<SceneUI> { }; + var rooms = CurrentRoom.GetRoomsByFloorId(floorId); + foreach (var r in rooms) + { + sceneUIs.AddRange(r.SceneUIList); + } + return sceneUIs; + } #endregion #region 鈼� 鍒锋柊鍦烘櫙_________________________ @@ -1148,195 +1306,168 @@ { HdlAutoBackupLogic.AddOrEditorFile(FileName); } - } - - #endregion - - #region 鈼� 妤煎眰鍜屾埧闂撮『搴忕浉鍏砡______________ - - /// <summary> - /// 鏍规嵁妤煎眰鐨勪富閿幏鍙栨帓搴忓悗鐨勬埧闂村垪琛� - /// </summary> - /// <param name="i_floorKeys">妤煎眰鐨勪富閿�</param> - /// <param name="getShard">鍒嗕韩鐨勬埧闂存槸鍚︿篃鑾峰彇</param> - /// <returns></returns> - public List<Room> GetFloorSortRoom(string i_floorKeys, bool getShard = true) - { - Dictionary<string, List<string>> dicAllSort = new Dictionary<string, List<string>>(); - //璇诲彇鎴块棿椤哄簭 - string fullName = UserCenterLogic.CombinePath(DirNameResourse.LocalMemoryDirectory, DirNameResourse.RoomSortFile); - var strData = UserCenterLogic.LoadFileContent(fullName); - if (strData != null) - { - dicAllSort = Newtonsoft.Json.JsonConvert.DeserializeObject<Dictionary<string, List<string>>>(strData); - } - - var listRoomSort = new List<string>(); - if (dicAllSort.ContainsKey(i_floorKeys) == true) - { - listRoomSort = dicAllSort[i_floorKeys]; - } - else - { - dicAllSort[i_floorKeys] = listRoomSort; - } - - var dicRoom = new Dictionary<string, Common.Room>(); - foreach (var room in Common.Room.Lists) - { - if (room.FloorId != i_floorKeys || room.IsLove == true) - { - //涓嶆槸鍚屼竴涓ゼ灞� - continue; - } - if (listRoomSort.Contains(room.Id) == false) - { - //鏂版坊鍔犵殑鎴块棿 - listRoomSort.Add(room.Id); - } - if (getShard == false && room.IsSharedRoom == true) - { - //涓嶈鍒嗕韩鐨勬埧闂� - continue; - } - dicRoom[room.Id] = room; - } - - var listSortRoom = new List<Room>(); - for (int i = 0; i < listRoomSort.Count; i++) - { - if (dicRoom.ContainsKey(listRoomSort[i]) == true) - { - listSortRoom.Add(dicRoom[listRoomSort[i]]); - } - } - - //淇濆瓨椤哄簭 - UserCenterLogic.SaveFileContent(fullName, dicAllSort); - return listSortRoom; - } - - /// <summary> - /// 淇濆瓨鎴块棿鐨勯『搴� - /// </summary> - /// <param name="i_floorKeys">妤煎眰涓婚敭</param> - /// <param name="listSort">鎴块棿椤哄簭(鎴块棿鐨勪富閿�)</param> - public void SaveRoomSort(string i_floorKeys, List<string> listSort) - { - Dictionary<string, List<string>> dicAllSort = new Dictionary<string, List<string>>(); - //璇诲彇鎴块棿椤哄簭 - string fullName = UserCenterLogic.CombinePath(DirNameResourse.LocalMemoryDirectory, DirNameResourse.RoomSortFile); - var strData = UserCenterLogic.LoadFileContent(fullName); - if (strData != null) - { - dicAllSort = Newtonsoft.Json.JsonConvert.DeserializeObject<Dictionary<string, List<string>>>(strData); - } - - //淇濆瓨椤哄簭 - dicAllSort[i_floorKeys] = listSort; - UserCenterLogic.SaveFileContent(fullName, dicAllSort); - dicAllSort.Clear(); - } - - /// <summary> - /// 鑾峰彇鎺掑簭鍚庣殑妤煎眰 - /// </summary> - /// <returns></returns> - public Dictionary<string, string> GetFloorSortList() - { - //璇诲彇妤煎眰椤哄簭 - var listFloorSort = new List<string>(); - string fullName = UserCenterLogic.CombinePath(DirNameResourse.LocalMemoryDirectory, DirNameResourse.FloorSortFile); - var strData = UserCenterLogic.LoadFileContent(fullName); - if (strData != null) - { - listFloorSort = Newtonsoft.Json.JsonConvert.DeserializeObject<List<string>>(strData); - } - foreach (string keys in Common.Config.Instance.Home.FloorDics.Keys) - { - if (listFloorSort.Contains(keys) == false) - { - //鏂版坊鍔犵殑妤煎眰 - listFloorSort.Add(keys); - } - } - - var dic = new Dictionary<string, string>(); - for (int i = 0; i < listFloorSort.Count; i++) - { - if (Config.Instance.Home.FloorDics.ContainsKey(listFloorSort[i]) == true) - { - dic[listFloorSort[i]] = Config.Instance.Home.FloorDics[listFloorSort[i]]; - } - } - - //淇濆瓨椤哄簭 - UserCenterLogic.SaveFileContent(fullName, listFloorSort); - return dic; - } - - /// <summary> - /// 淇濆瓨妤煎眰鐨勯『搴� - /// </summary> - /// <param name="listSort">妤煎眰鐨勪富閿�</param> - public void SaveFloorSort(List<string> listSort) - { - string fullName = UserCenterLogic.CombinePath(DirNameResourse.LocalMemoryDirectory, DirNameResourse.FloorSortFile); - //淇濆瓨椤哄簭 - UserCenterLogic.SaveFileContent(fullName, listSort); - } - - #endregion - - #region 鈼� 鍏嬮殕鎴块棿瀵硅薄_____________________ - - /// <summary> - /// 鍏嬮殕鎴块棿瀵硅薄 - /// </summary> - /// <returns></returns> - public Room CloneRoomClass() - { - var newRoom = new Room(); - //鍏嬮殕灞炴�� - newRoom.Id = this.Id; - newRoom.FloorId = this.FloorId; - newRoom.TemperatrueDevice = this.TemperatrueDevice; - newRoom.HumidityDevice = this.HumidityDevice; - newRoom.Name = this.Name; - newRoom.BackgroundImage = this.BackgroundImage; - newRoom.BackgroundImageType = this.BackgroundImageType; - - return newRoom; - } - - #endregion - - #region 鈼� 妤煎眰___________________________ - - /// <summary> - /// 鑾峰彇妤煎眰鍚嶇О - /// </summary> - /// <param name="floorId"></param> - /// <returns></returns> - public string GetFloorNameById(string floorId) - { - if (Config.Instance.Home.FloorDics.Count == 0) - { - return null; - } - - foreach (var floor in Config.Instance.Home.FloorDics) - { - if (floorId == floor.Key) - { - return floor.Value; - } - } - return null; } #endregion - + #region 鈼� 妤煎眰鍜屾埧闂撮『搴忕浉鍏砡______________ + + /// <summary> + /// 鏍规嵁妤煎眰鐨勪富閿幏鍙栨帓搴忓悗鐨勬埧闂村垪琛� + /// </summary> + /// <param name="i_floorKeys">妤煎眰鐨勪富閿�</param> + /// <param name="getShard">鍒嗕韩鐨勬埧闂存槸鍚︿篃鑾峰彇</param> + /// <returns></returns> + public List<Room> GetFloorSortRoom(string i_floorKeys, bool getShard = true) + { + Dictionary<string, List<string>> dicAllSort = new Dictionary<string, List<string>>(); + //璇诲彇鎴块棿椤哄簭 + string fullName = UserCenterLogic.CombinePath(DirNameResourse.LocalMemoryDirectory, DirNameResourse.RoomSortFile); + var strData = UserCenterLogic.LoadFileContent(fullName); + if (strData != null) + { + dicAllSort = Newtonsoft.Json.JsonConvert.DeserializeObject<Dictionary<string, List<string>>>(strData); + } + + var listRoomSort = new List<string>(); + if (dicAllSort.ContainsKey(i_floorKeys) == true) + { + listRoomSort = dicAllSort[i_floorKeys]; + } + else + { + dicAllSort[i_floorKeys] = listRoomSort; + } + + var dicRoom = new Dictionary<string, Common.Room>(); + foreach (var room in Common.Room.Lists) + { + if (room.FloorId != i_floorKeys || room.IsLove == true) + { + //涓嶆槸鍚屼竴涓ゼ灞� + continue; + } + if (listRoomSort.Contains(room.Id) == false) + { + //鏂版坊鍔犵殑鎴块棿 + listRoomSort.Add(room.Id); + } + if (getShard == false && room.IsSharedRoom == true) + { + //涓嶈鍒嗕韩鐨勬埧闂� + continue; + } + dicRoom[room.Id] = room; + } + + var listSortRoom = new List<Room>(); + for (int i = 0; i < listRoomSort.Count; i++) + { + if (dicRoom.ContainsKey(listRoomSort[i]) == true) + { + listSortRoom.Add(dicRoom[listRoomSort[i]]); + } + } + + //淇濆瓨椤哄簭 + UserCenterLogic.SaveFileContent(fullName, dicAllSort); + return listSortRoom; + } + + /// <summary> + /// 淇濆瓨鎴块棿鐨勯『搴� + /// </summary> + /// <param name="i_floorKeys">妤煎眰涓婚敭</param> + /// <param name="listSort">鎴块棿椤哄簭(鎴块棿鐨勪富閿�)</param> + public void SaveRoomSort(string i_floorKeys, List<string> listSort) + { + Dictionary<string, List<string>> dicAllSort = new Dictionary<string, List<string>>(); + //璇诲彇鎴块棿椤哄簭 + string fullName = UserCenterLogic.CombinePath(DirNameResourse.LocalMemoryDirectory, DirNameResourse.RoomSortFile); + var strData = UserCenterLogic.LoadFileContent(fullName); + if (strData != null) + { + dicAllSort = Newtonsoft.Json.JsonConvert.DeserializeObject<Dictionary<string, List<string>>>(strData); + } + + //淇濆瓨椤哄簭 + dicAllSort[i_floorKeys] = listSort; + UserCenterLogic.SaveFileContent(fullName, dicAllSort); + dicAllSort.Clear(); + } + + /// <summary> + /// 鑾峰彇鎺掑簭鍚庣殑妤煎眰 + /// </summary> + /// <returns></returns> + public Dictionary<string, string> GetFloorSortList() + { + //璇诲彇妤煎眰椤哄簭 + var listFloorSort = new List<string>(); + string fullName = UserCenterLogic.CombinePath(DirNameResourse.LocalMemoryDirectory, DirNameResourse.FloorSortFile); + var strData = UserCenterLogic.LoadFileContent(fullName); + if (strData != null) + { + listFloorSort = Newtonsoft.Json.JsonConvert.DeserializeObject<List<string>>(strData); + } + foreach (string keys in Common.Config.Instance.Home.FloorDics.Keys) + { + if (listFloorSort.Contains(keys) == false) + { + //鏂版坊鍔犵殑妤煎眰 + listFloorSort.Add(keys); + } + } + + var dic = new Dictionary<string, string>(); + for (int i = 0; i < listFloorSort.Count; i++) + { + if (Config.Instance.Home.FloorDics.ContainsKey(listFloorSort[i]) == true) + { + dic[listFloorSort[i]] = Config.Instance.Home.FloorDics[listFloorSort[i]]; + } + } + + //淇濆瓨椤哄簭 + UserCenterLogic.SaveFileContent(fullName, listFloorSort); + return dic; + } + + /// <summary> + /// 淇濆瓨妤煎眰鐨勯『搴� + /// </summary> + /// <param name="listSort">妤煎眰鐨勪富閿�</param> + public void SaveFloorSort(List<string> listSort) + { + string fullName = UserCenterLogic.CombinePath(DirNameResourse.LocalMemoryDirectory, DirNameResourse.FloorSortFile); + //淇濆瓨椤哄簭 + UserCenterLogic.SaveFileContent(fullName, listSort); + } + + #endregion + + #region 鈼� 鍏嬮殕鎴块棿瀵硅薄_____________________ + + /// <summary> + /// 鍏嬮殕鎴块棿瀵硅薄 + /// </summary> + /// <returns></returns> + public Room CloneRoomClass() + { + var newRoom = new Room(); + //鍏嬮殕灞炴�� + newRoom.Id = this.Id; + newRoom.FloorId = this.FloorId; + newRoom.TemperatrueDevice = this.TemperatrueDevice; + newRoom.HumidityDevice = this.HumidityDevice; + newRoom.Name = this.Name; + newRoom.BackgroundImage = this.BackgroundImage; + newRoom.BackgroundImageType = this.BackgroundImageType; + + return newRoom; + } + + #endregion + } -} +} \ No newline at end of file -- Gitblit v1.8.0