From 35a2888945bcf1b7ef6f34d30f1709b9c848fce6 Mon Sep 17 00:00:00 2001 From: wei <kaede@kaededeMacBook-Air.local> Date: 星期三, 16 十二月 2020 15:17:18 +0800 Subject: [PATCH] 111 --- HDL_ON/Entity/Room.cs | 74 ++++++++++++++++++++++--------------- 1 files changed, 44 insertions(+), 30 deletions(-) diff --git a/HDL_ON/Entity/Room.cs b/HDL_ON/Entity/Room.cs index ea6c102..dfcbf83 100644 --- a/HDL_ON/Entity/Room.cs +++ b/HDL_ON/Entity/Room.cs @@ -46,7 +46,7 @@ public SpatialInfo(string spatialType) { roomType = "FLOOR"; - parentId = DB_ResidenceData.residenceData.CurReginID; + parentId = DB_ResidenceData.Instance.CurrentRegion.RegionID; } public string roomId = ""; @@ -182,7 +182,7 @@ } } var ssd = System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(FloorList)); - FileUtils.WriteFileByBytes(dataSavePath, ssd); + Common.FileUtlis.Files.WriteFileByBytes(dataSavePath, ssd); } } @@ -202,7 +202,7 @@ { try { - var floorsDataBytes = FileUtils.ReadFile("FloorsData"); + var floorsDataBytes = Common.FileUtlis.Files.ReadFile("FloorsData"); if (floorsDataBytes != null) { var floorsDataString = System.Text.Encoding.UTF8.GetString(floorsDataBytes); @@ -247,7 +247,7 @@ /// 澧炲姞妤煎眰 /// </summary> /// <param name="floor"></param> - public string AddFloor(SpatialInfo floor) + public string AddFloor(SpatialInfo floor, out SpatialInfo newFloor) { var pm = new HttpServerRequest(); var revPack = new ResponsePackNew(); @@ -255,17 +255,23 @@ if (revPack.Code == StateCode.SUCCESS) { var revData = Newtonsoft.Json.JsonConvert.DeserializeObject<List<SpatialInfo>>(revPack.Data.ToString()); - if(revData.Count>0) + if (revData.Count > 0) { var addFloor = revData.Find((obj) => obj.uid == floor.uid); - if(addFloor!= null) + if (addFloor != null) { CurrentSpatial.FloorList.Add(addFloor); + floor = addFloor; } } var ssd = System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(CurrentSpatial.FloorList)); - FileUtils.WriteFileByBytes(dataSavePath, ssd); + Common.FileUtlis.Files.WriteFileByBytes(dataSavePath, ssd); } + else + { + Utlis.ShowTip(Language.StringByID(StringId.AddFloorFail) + "\r\nCode:" + revPack.Code); + } + newFloor = floor; return revPack.Code; } /// <summary> @@ -279,7 +285,7 @@ if (revPack.Code == StateCode.SUCCESS) { var ssd = System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(FloorList)); - FileUtils.WriteFileByBytes(dataSavePath, ssd); + Common.FileUtlis.Files.WriteFileByBytes(dataSavePath, ssd); } return revPack.Code; } @@ -301,7 +307,7 @@ CurrentSpatial.FloorList.Remove(tRoom); } var ssd = System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(FloorList)); - FileUtils.WriteFileByBytes(dataSavePath, ssd); + Common.FileUtlis.Files.WriteFileByBytes(dataSavePath, ssd); } else { @@ -329,13 +335,13 @@ try { rooms = new List<Room> { }; - var filePathList = FileUtils.ReadFiles(); + var filePathList = Common.FileUtlis.Files.ReadFiles(); foreach (var filePath in filePathList) { if (filePath.StartsWith("RoomData_")) { - var roomDataBytes = FileUtils.ReadFile(filePath); + var roomDataBytes = Common.FileUtlis.Files.ReadFile(filePath); var roomDataString = System.Text.Encoding.UTF8.GetString(roomDataBytes); var room = Newtonsoft.Json.JsonConvert.DeserializeObject<Room>(roomDataString); if (room != null) @@ -357,7 +363,7 @@ /// 澧炲姞鎴块棿 /// </summary> /// <param name="room"></param> - public string AddRoom(Room room) + public string AddRoom(Room room,out Room newRoom) { var pm = new HttpServerRequest(); var pack = pm.AddRoom(new List<SpatialInfo>() { room }); @@ -372,14 +378,15 @@ var tempRoom = revData.Find((obj) => obj.uid == room.uid); if (tempRoom != null) { - room = tempRoom as Room; + room.roomId = tempRoom.roomId; CurrentSpatial.RoomList.Add(room); var ssd = System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(room)); - FileUtils.WriteFileByBytes(dataSavePath, ssd); + Common.FileUtlis.Files.WriteFileByBytes(dataSavePath, ssd); } } } } + newRoom = room; return pack.Code; } /// <summary> @@ -397,7 +404,7 @@ { CurrentSpatial.RoomList.Remove(room); } - FileUtils.DeleteFile(room.dataSavePath); + Common.FileUtlis.Files.DeleteFile(room.dataSavePath); } return pack.Code; } @@ -408,10 +415,27 @@ { foreach(var localRoom in RoomList) { - FileUtils.DeleteFile(localRoom.dataSavePath); + Common.FileUtlis.Files.DeleteFile(localRoom.dataSavePath); } - RoomList.Clear(); + rooms = null; } + + public void Clear() + { + if (_currentSpatial != null) + { + if (_currentSpatial.floors != null) + { + _currentSpatial.floors.Clear(); + } + if (_currentSpatial.rooms != null) + { + _currentSpatial.rooms.Clear(); + } + _currentSpatial = null; + } + } + /// <summary> /// 鍒濆鍖栨瘡涓埧闂寸殑鍔熻兘鏁版嵁 /// </summary> @@ -450,7 +474,7 @@ if (needSave) { var ssd = System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(this)); - FileUtils.WriteFileByBytes(dataSavePath, ssd); + Common.FileUtlis.Files.WriteFileByBytes(dataSavePath, ssd); } return packCode; } @@ -504,16 +528,6 @@ { return f.roomName + " "; } - else - { - foreach(var f1 in CurrentSpatial.FloorList) - { - if(f1.uid == parentId) - { - return f.roomName + " "; - } - } - } } return ""; } @@ -534,7 +548,7 @@ } if (functions.Count == 0) { - foreach (var f in DB_ResidenceData.functionList.GetAllFunction()) + foreach (var f in FunctionList.List.GetDeviceFunctionList()) { if (f.roomIds.Contains(roomId) && roomId != null) { @@ -576,7 +590,7 @@ } if (scenes.Count == 0) { - foreach (var s in DB_ResidenceData.functionList.scenes) + foreach (var s in FunctionList.List.scenes) { if (s.roomIds.Contains(roomId) && roomId != null) { -- Gitblit v1.8.0