From 3069c032027eeea7a14fa9f462440bb2d802d9a9 Mon Sep 17 00:00:00 2001
From: wei <kaede@kaededeMacBook-Air.local>
Date: 星期一, 11 一月 2021 14:25:09 +0800
Subject: [PATCH] 20210111-合并代码
---
HDL_ON/Entity/Room.cs | 194 ++++++++++++++++--------------------------------
1 files changed, 66 insertions(+), 128 deletions(-)
diff --git a/HDL_ON/Entity/Room.cs b/HDL_ON/Entity/Room.cs
index 60c8e35..055a4c6 100644
--- a/HDL_ON/Entity/Room.cs
+++ b/HDL_ON/Entity/Room.cs
@@ -46,7 +46,7 @@
public SpatialInfo(string spatialType)
{
roomType = "FLOOR";
- parentId = UserInfo.Current.CurReginID;
+ parentId = DB_ResidenceData.Instance.CurrentRegion.RegionID;
}
public string roomId = "";
@@ -65,121 +65,33 @@
///// </summary>
//public bool DeleteSign = false;
-
- protected ResponsePackNew SaveSpatialInfo()
- {
- var pm = new HttpServerRequest();
- var revPack = new ResponsePackNew();
- if (string.IsNullOrEmpty(createTime) && string.IsNullOrEmpty(modifyTime))
- {
- revPack = pm.AddRoom(new List<SpatialInfo>() { this });
- }
- else if (string.IsNullOrEmpty(createTime) && !string.IsNullOrEmpty(modifyTime))
- {
- revPack = pm.DeleteRoom(new List<string>() { roomId });
- }
- else if (!string.IsNullOrEmpty(createTime) && !string.IsNullOrEmpty(modifyTime))
- {
- revPack = pm.UpdateRoom(new List<SpatialInfo>() { this });
- }
- return revPack;
- }
-
- /// <summary>
- /// 涓嬭浇浜戠鎴块棿鏁版嵁
- /// </summary>
- public void DownloadRoomList()
- {
- new System.Threading.Thread(() =>
- {
- var pm = new HttpServerRequest();
- var pack = pm.GetRoomList();
- if (pack.Code == StateCode.SUCCESS)
- {
- var revData = Newtonsoft.Json.JsonConvert.DeserializeObject<SpatialApiPack>(pack.Data.ToString());
- if (revData != null)
- {
- CurrentSpatial.UpdateSpatialList(revData.list, OptionType.Cover);
- }
- }
- else
- {
- MainPage.Log($"璇诲彇鎴块棿鏁版嵁澶辫触:\r\nCode:{pack.Code}; msg:{pack.message}");
- }
- })
- { IsBackground = true }.Start();
- }
-
/// <summary>
/// 鏇存柊绌洪棿淇℃伅
/// </summary>
/// <param name="spatials">绌洪棿淇℃伅</param>
/// <param name="optionType">鎿嶄綔绫诲瀷锛欰DD/UPDATE/DELETE</param>
- public void UpdateSpatialList(List<SpatialInfo> spatials,OptionType optionType)
+ public void UpdateSpatialList(List<SpatialInfo> spatials)
{
var roomUpdateList = spatials.FindAll((obj) => obj.roomType == "ROOM");
var floorUpdateList = spatials.FindAll((obj) => obj.roomType == "FLOOR");
//澶勭悊鎴块棿鍒楄〃
if (roomUpdateList != null && roomUpdateList.Count > 0)
{
- if (optionType == OptionType.Update)
+ CurrentSpatial.DeleteAllRoom();
+ foreach (var newRoom in roomUpdateList)
{
- foreach (var updateTemp in roomUpdateList)
- {
- var localRoom = CurrentSpatial.RoomList.Find((obj) => obj.roomId == updateTemp.roomId);
- if (localRoom != null)
- {
- if (localRoom.modifyTime != updateTemp.modifyTime)
- {
- localRoom.roomName = updateTemp.roomName;
- localRoom.roomImage = updateTemp.roomImage;
- localRoom.parentId = updateTemp.parentId;
- localRoom.createTime = updateTemp.createTime;
- localRoom.modifyTime = updateTemp.modifyTime;
- localRoom.SaveRoomData(false);
- }
- }else
- {
- updateTemp.SaveRoomData(false);
- }
- }
- }
- else if (optionType == OptionType.Cover)
- {
- CurrentSpatial.DeleteAllRoom();
- foreach(var newRoom in roomUpdateList)
- {
- newRoom.SaveRoomData(false);
- RoomList.Add(Newtonsoft.Json.JsonConvert.DeserializeObject<Room>(
- Newtonsoft.Json.JsonConvert.SerializeObject(newRoom)));
- }
+ newRoom.SaveRoomFile();
+ RoomList.Add(Newtonsoft.Json.JsonConvert.DeserializeObject<Room>(
+ Newtonsoft.Json.JsonConvert.SerializeObject(newRoom)));
}
}
//妤煎眰鎴块棿鍒楄〃
if (floorUpdateList != null && floorUpdateList.Count > 0)
{
- if (optionType == OptionType.Update)
+ FloorList.Clear();
+ foreach (var updateTemp in floorUpdateList)
{
- foreach(var updateTemp in floorUpdateList)
- {
- var localFloor = FloorList.Find((obj) => obj.roomId == updateTemp.roomId);
- if (localFloor == null)
- {
- FloorList.Add(updateTemp);
- }
- else
- {
- localFloor = updateTemp;
- }
- }
- }
- if(optionType == OptionType.Cover)
- {
- FloorList.Clear();
- foreach (var updateTemp in floorUpdateList)
- {
- FloorList.Add(updateTemp);
- }
+ FloorList.Add(updateTemp);
}
var ssd = System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(FloorList));
Common.FileUtlis.Files.WriteFileByBytes(dataSavePath, ssd);
@@ -247,7 +159,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,10 +167,10 @@
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;
@@ -267,6 +179,11 @@
var ssd = System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(CurrentSpatial.FloorList));
Common.FileUtlis.Files.WriteFileByBytes(dataSavePath, ssd);
}
+ else
+ {
+ Utlis.ShowTip(Language.StringByID(StringId.AddFloorFail) + "\r\nCode:" + revPack.Code);
+ }
+ newFloor = floor;
return revPack.Code;
}
/// <summary>
@@ -358,7 +275,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 });
@@ -373,7 +290,7 @@
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));
Common.FileUtlis.Files.WriteFileByBytes(dataSavePath, ssd);
@@ -381,6 +298,7 @@
}
}
}
+ newRoom = room;
return pack.Code;
}
/// <summary>
@@ -414,22 +332,26 @@
rooms = null;
}
- public void ClearRooms()
+ public void Clear()
{
- if (floors != null)
+ if (_currentSpatial != null)
{
- floors.Clear();
- }
- if (rooms != null)
- {
- rooms.Clear();
+ if (_currentSpatial.floors != null)
+ {
+ _currentSpatial.floors.Clear();
+ }
+ if (_currentSpatial.rooms != null)
+ {
+ _currentSpatial.rooms.Clear();
+ }
+ _currentSpatial = null;
}
}
/// <summary>
/// 鍒濆鍖栨瘡涓埧闂寸殑鍔熻兘鏁版嵁
/// </summary>
- public void InitRoomFunction()
+ public void InitRoomListFunctions()
{
new System.Threading.Thread(() =>
{
@@ -438,8 +360,7 @@
//鍒濆鍖栦綇瀹呮墍鏈夋埧闂村姛鑳芥暟鎹�
foreach (var r in RoomList)
{
- r.GetRoomFunctions(true);
- r.GetRoomScenes(true);
+ InitRoomFuntion(r);
}
}
catch (Exception ex)
@@ -449,25 +370,42 @@
})
{ IsBackground = true }.Start();
}
+ /// <summary>
+ /// 鍒濆鍖栨埧闂村姛鑳�
+ /// </summary>
+ /// <param name="tempRoom"></param>
+ public void InitRoomFuntion(Room tempRoom)
+ {
+ tempRoom.GetRoomFunctions(true);
+ tempRoom.GetRoomScenes(true);
+ }
/// <summary>
- /// 淇濆瓨鎴块棿鏁版嵁
+ /// 淇濆瓨鎴块棿鏁版嵁鏂囦欢
/// </summary>
- public string SaveRoomData(bool upServer = true)
+ public void SaveRoomFile()
{
- var packCode = StateCode.SUCCESS;
- bool needSave = true;
- if (upServer)
- {
- packCode = SaveSpatialInfo().Code;
- }
- if (needSave)
- {
- var ssd = System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(this));
- Common.FileUtlis.Files.WriteFileByBytes(dataSavePath, ssd);
- }
- return packCode;
+ var ssd = System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(this));
+ Common.FileUtlis.Files.WriteFileByBytes(dataSavePath, ssd);
}
+ /// <summary>
+ /// 鏇存柊鎴块棿鏁版嵁
+ /// </summary>
+ public void UpdataRoomInfo()
+ {
+ new System.Threading.Thread(() =>
+ {
+ var pm = new HttpServerRequest();
+ var pack = pm.UpdateRoom(new List<SpatialInfo>() { this });
+ this.SaveRoomFile();
+ if (pack.Code != StateCode.SUCCESS)
+ {
+ IMessageCommon.Current.ShowErrorInfoAlter(pack.Code);
+ }
+ })
+ { IsBackground = true }.Start();
+ }
+
#endregion
}
@@ -513,7 +451,7 @@
{
if (CurrentSpatial.FloorList.Count > 0)
{
- var f = CurrentSpatial.FloorList.Find((obj) => obj.roomId == parentId);
+ var f = CurrentSpatial.FloorList.Find((obj) => obj.uid == parentId);
if (f != null)
{
return f.roomName + " ";
--
Gitblit v1.8.0