From 792ca2a402feb952ef890d653f2e049c1230baf1 Mon Sep 17 00:00:00 2001
From: wxr <464027401@qq.com>
Date: 星期六, 19 十二月 2020 18:48:33 +0800
Subject: [PATCH] 1111
---
HDL_ON/Entity/Room.cs | 270 +++++++++++++++++++++++++++++++++++++----------------
1 files changed, 188 insertions(+), 82 deletions(-)
diff --git a/HDL_ON/Entity/Room.cs b/HDL_ON/Entity/Room.cs
index 91e78cd..0f3cc1d 100644
--- a/HDL_ON/Entity/Room.cs
+++ b/HDL_ON/Entity/Room.cs
@@ -1,6 +1,7 @@
锘縰sing System;
using System.Collections.Generic;
using HDL_ON.DAL.Server;
+using Shared;
namespace HDL_ON.Entity
{
@@ -45,40 +46,43 @@
public SpatialInfo(string spatialType)
{
roomType = "FLOOR";
- parentId = DB_ResidenceData.residenceData.CurReginID;
+ parentId = DB_ResidenceData.Instance.CurrentRegion.RegionID;
}
public string roomId = "";
public string roomName = "";
- public string roomImage = "";
+ //public string roomImage = "";
+ public string roomImage = "Classification/Room/Roombg.png";
public string roomType = "";
public string parentId = "";
public string uid = Guid.NewGuid().ToString();
public string createTime = "";
public string modifyTime = "";
- /// <summary>
- /// 鍒犻櫎鏍囪
- /// 闇�瑕佸垹闄ゆ暟鎹椂锛屾爣璁颁负锛歵rue
- /// 鐢变簯绔垹闄ゆ垚鍔熶箣鍚庯紝杩斿洖鏁版嵁鍐嶆竻闄ゆ湰鍦版暟鎹�
- /// </summary>
- public bool DeleteSign = false;
+ ///// <summary>
+ ///// 鍒犻櫎鏍囪 20201208锛氬彲娆�:APP鐨勫湪绾垮拰绂荤嚎闂锛屽垰鍒氱‘瀹氫簡锛岀绾挎棤娉曠紪杈戯紝鍙兘鎺у埗
+ ///// 闇�瑕佸垹闄ゆ暟鎹椂锛屾爣璁颁负锛歵rue
+ ///// 鐢变簯绔垹闄ゆ垚鍔熶箣鍚庯紝杩斿洖鏁版嵁鍐嶆竻闄ゆ湰鍦版暟鎹�
+ ///// </summary>
+ //public bool DeleteSign = false;
- protected void SaveSpatialInfo()
+ protected ResponsePackNew SaveSpatialInfo()
{
var pm = new HttpServerRequest();
+ var revPack = new ResponsePackNew();
if (string.IsNullOrEmpty(createTime) && string.IsNullOrEmpty(modifyTime))
{
- pm.AddRoom(new List<SpatialInfo>() { this });
+ revPack = pm.AddRoom(new List<SpatialInfo>() { this });
}
else if (string.IsNullOrEmpty(createTime) && !string.IsNullOrEmpty(modifyTime))
{
- pm.DeleteRoom(new List<string>() { roomId });
+ revPack = pm.DeleteRoom(new List<string>() { roomId });
}
else if (!string.IsNullOrEmpty(createTime) && !string.IsNullOrEmpty(modifyTime))
{
- pm.UpdateRoom(new List<SpatialInfo>() { this });
+ revPack = pm.UpdateRoom(new List<SpatialInfo>() { this });
}
+ return revPack;
}
/// <summary>
@@ -125,15 +129,18 @@
var localRoom = CurrentSpatial.RoomList.Find((obj) => obj.roomId == updateTemp.roomId);
if (localRoom != null)
{
- localRoom.roomName = updateTemp.roomName;
- localRoom.roomImage = updateTemp.roomImage;
- localRoom.parentId = updateTemp.parentId;
- localRoom.createTime = updateTemp.createTime;
- localRoom.modifyTime = updateTemp.modifyTime;
- localRoom.SaveRoomData();
+ 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();
+ updateTemp.SaveRoomData(false);
}
}
}
@@ -142,7 +149,9 @@
CurrentSpatial.DeleteAllRoom();
foreach(var newRoom in roomUpdateList)
{
- newRoom.SaveRoomData();
+ newRoom.SaveRoomData(false);
+ RoomList.Add(Newtonsoft.Json.JsonConvert.DeserializeObject<Room>(
+ Newtonsoft.Json.JsonConvert.SerializeObject(newRoom)));
}
}
}
@@ -163,7 +172,6 @@
localFloor = updateTemp;
}
}
- CurrentSpatial.SaveFloorData();
}
if(optionType == OptionType.Cover)
{
@@ -172,9 +180,9 @@
{
FloorList.Add(updateTemp);
}
- var ssd = System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(FloorList));
- FileUtils.WriteFileByBytes(dataSavePath, ssd);
}
+ var ssd = System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(FloorList));
+ Common.FileUtlis.Files.WriteFileByBytes(dataSavePath, ssd);
}
}
@@ -194,16 +202,16 @@
{
try
{
- var floorsDataBytes = FileUtils.ReadFile(dataSavePath);
+ var floorsDataBytes = Common.FileUtlis.Files.ReadFile("FloorsData");
if (floorsDataBytes != null)
{
var floorsDataString = System.Text.Encoding.UTF8.GetString(floorsDataBytes);
MainPage.Log(floorsDataString);
floors = Newtonsoft.Json.JsonConvert.DeserializeObject<List<SpatialInfo>>(floorsDataString);
- if (floors == null)
- {
- floors = new List<SpatialInfo>();
- }
+ }
+ if (floors == null)
+ {
+ floors = new List<SpatialInfo>();
}
}
catch (Exception ex)
@@ -239,55 +247,75 @@
/// 澧炲姞妤煎眰
/// </summary>
/// <param name="floor"></param>
- public void AddFloor(SpatialInfo floor)
+ public string AddFloor(SpatialInfo floor, out SpatialInfo newFloor)
{
- FloorList.Add(floor);
- SaveFloorData();
+ var pm = new HttpServerRequest();
+ var revPack = new ResponsePackNew();
+ revPack = pm.AddRoom(new List<SpatialInfo>() { floor });
+ if (revPack.Code == StateCode.SUCCESS)
+ {
+ var revData = Newtonsoft.Json.JsonConvert.DeserializeObject<List<SpatialInfo>>(revPack.Data.ToString());
+ if (revData.Count > 0)
+ {
+ var addFloor = revData.Find((obj) => obj.uid == floor.uid);
+ if (addFloor != null)
+ {
+ CurrentSpatial.FloorList.Add(addFloor);
+ floor = addFloor;
+ }
+ }
+ 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>
/// 鏇存柊妤煎眰淇℃伅
/// </summary>
/// <param name="floor"></param>
- public void UpdateFloor()
+ public string UpdateFloor(SpatialInfo floor)
{
- SaveFloorData();
+ var pm = new HttpServerRequest();
+ var revPack = pm.UpdateRoom(new List<SpatialInfo>() { floor });
+ if (revPack.Code == StateCode.SUCCESS)
+ {
+ var ssd = System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(FloorList));
+ Common.FileUtlis.Files.WriteFileByBytes(dataSavePath, ssd);
+ }
+ return revPack.Code;
}
/// <summary>
/// 鍒犻櫎妤煎眰
/// </summary>
/// <param name="floor"></param>
- public void DelFloor(SpatialInfo floor)
+ public string DelFloor(string floorId)
{
- var tRoom = FloorList.Find((obj) => obj.uid == floor.uid);
- if (tRoom != null)
+ if (string.IsNullOrEmpty( floorId))
+ return "";
+ var pm = new HttpServerRequest();
+ var code = pm.DeleteRoom(new List<string>() { floorId }).Code;
+ if (code == StateCode.SUCCESS)
{
- FloorList.Remove(floor);
- floor.modifyTime = "";
+ var tRoom = CurrentSpatial.FloorList.Find((obj) => obj.roomId == floorId);
+ if (tRoom != null)
+ {
+ CurrentSpatial.FloorList.Remove(tRoom);
+ }
+ var ssd = System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(FloorList));
+ Common.FileUtlis.Files.WriteFileByBytes(dataSavePath, ssd);
}
- SaveFloorData();
+ else
+ {
+ Utlis.ShowTip(Language.StringByID(StringId.DeleteFloorFail) + "\r\nCode:" + code);
+ }
+ return code;
}
- /// <summary>
- /// 淇濆瓨妤煎眰鏁版嵁
- /// </summary>
- void SaveFloorData()
- {
- var ssd = System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(FloorList));
- FileUtils.WriteFileByBytes(dataSavePath, ssd);
- MainPage.Log($"Save floor Data");
- SaveSpatialInfo();
- }
-
- /// <summary>
- /// 淇濆瓨鎴块棿鏁版嵁
- /// </summary>
- public void SaveRoomData()
- {
- var ssd = System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(this));
- FileUtils.WriteFileByBytes(dataSavePath, ssd);
- MainPage.Log($"Save Room Data {roomName} : {uid}");
- SaveSpatialInfo();
- }
#endregion
#region 鎴块棿鍒楄〃
@@ -307,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)
@@ -335,25 +363,50 @@
/// 澧炲姞鎴块棿
/// </summary>
/// <param name="room"></param>
- public void AddRoom(Room room)
+ public string AddRoom(Room room,out Room newRoom)
{
- RoomList.Add(room);
- room.SaveRoomData();
+ var pm = new HttpServerRequest();
+ var pack = pm.AddRoom(new List<SpatialInfo>() { room });
+
+ if (pack.Code == StateCode.SUCCESS)
+ {
+ var revData = Newtonsoft.Json.JsonConvert.DeserializeObject<List<SpatialInfo>>(pack.Data.ToString());
+ if (revData != null)
+ {
+ if (revData.Count > 0)
+ {
+ var tempRoom = revData.Find((obj) => obj.uid == room.uid);
+ if (tempRoom != null)
+ {
+ 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);
+ }
+ }
+ }
+ }
+ newRoom = room;
+ return pack.Code;
}
/// <summary>
/// 鍒犻櫎鎴块棿
/// </summary>
/// <param name="room"></param>
- public void DelRoom(Room room)
+ public string DelRoom(Room room)
{
- var tRoom = RoomList.Find((obj) => obj.uid == room.uid);
- if (tRoom != null)
+ var pm = new HttpServerRequest();
+ var pack = pm.DeleteRoom(new List<string>() { room.roomId });
+ if (pack.Code == StateCode.SUCCESS)
{
- FileUtils.DeleteFile(room.dataSavePath);
- RoomList.Remove(room);
- room.DeleteSign = true;
+ var tRoom = RoomList.Find((obj) => obj.roomId == room.roomId);
+ if (tRoom != null)
+ {
+ CurrentSpatial.RoomList.Remove(room);
+ }
+ Common.FileUtlis.Files.DeleteFile(room.dataSavePath);
}
- room.SaveRoomData();
+ return pack.Code;
}
/// <summary>
/// 鍒犻櫎鎵�鏈夋埧闂�
@@ -362,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>
@@ -390,7 +460,24 @@
{ IsBackground = true }.Start();
}
-
+ /// <summary>
+ /// 淇濆瓨鎴块棿鏁版嵁
+ /// </summary>
+ public string SaveRoomData(bool upServer = true)
+ {
+ 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;
+ }
#endregion
}
@@ -405,7 +492,26 @@
roomType = "ROOM";
roomName = "Room";
}
- public string backgroundImage = "Classification/Room/Roombg.png";
+ //public string backgroundImage = "Classification/Room/Roombg.png";
+ public string backgroundImage
+ {
+ get
+ {
+ if (string.IsNullOrEmpty(roomImage))
+ {
+ return "Classification/Room/Roombg.png";
+ }
+ else
+ {
+ return roomImage;
+ }
+ }
+ set
+ {
+ roomImage = value;
+ }
+ }
+
/// <summary>
/// 妤煎眰
@@ -415,9 +521,9 @@
{
get
{
- if (FloorList.Count > 0)
+ if (CurrentSpatial.FloorList.Count > 0)
{
- var f = FloorList.Find((obj) => obj.uid == parentId);
+ var f = CurrentSpatial.FloorList.Find((obj) => obj.uid == parentId);
if (f != null)
{
return f.roomName + " ";
@@ -442,9 +548,9 @@
}
if (functions.Count == 0)
{
- foreach (var f in DB_ResidenceData.functionList.GetAllFunction())
+ foreach (var f in FunctionList.List.GetDeviceFunctionList())
{
- if (f.roomIds.Contains(uid) && uid != null)
+ if (f.roomIds.Contains(roomId) && roomId != null)
{
functions.Add(f);
}
@@ -484,9 +590,9 @@
}
if (scenes.Count == 0)
{
- foreach (var s in DB_ResidenceData.functionList.scenes)
+ foreach (var s in FunctionList.List.scenes)
{
- if (s.roomIds.Contains(uid) && uid != null)
+ if (s.roomIds.Contains(roomId) && roomId != null)
{
scenes.Add(s);
}
--
Gitblit v1.8.0