From fa6bcb2e9907772480f99205f36ec2a1ce735a22 Mon Sep 17 00:00:00 2001
From: 黄学彪 <hxb@hdlchina.com.cn>
Date: 星期四, 09 一月 2020 14:11:07 +0800
Subject: [PATCH] 合并代码

---
 ZigbeeApp/Shared/Common/Room.cs |  172 +++++++++++++++++++++++++++++++++++++-------------------
 1 files changed, 113 insertions(+), 59 deletions(-)

diff --git a/ZigbeeApp/Shared/Common/Room.cs b/ZigbeeApp/Shared/Common/Room.cs
index c6005c0..8310b10 100755
--- a/ZigbeeApp/Shared/Common/Room.cs
+++ b/ZigbeeApp/Shared/Common/Room.cs
@@ -69,7 +69,7 @@
 
         /// <summary>
         /// 娓╁害浼犳劅鍣�(璁惧涓婚敭)
-        /// </summary>   
+        /// </summary>
         public string TemperatrueDevice = string.Empty;
         /// <summary>
         /// 婀垮害浼犳劅鍣�(璁惧涓婚敭)
@@ -78,11 +78,11 @@
         /// <summary>
         /// 娓╁害
         /// </summary>
-        public double Temperatrue;
+        public decimal Temperatrue;
         /// <summary>
         /// 婀垮害
         /// </summary>
-        public double Humidity;
+        public decimal Humidity;
 
         /// <summary>
         /// 褰撳墠閫夋嫨鐨勬埧闂�
@@ -332,10 +332,23 @@
                         room.Name = $"{room.Name}";
                     }
                     Lists.Add(room);
-                   
+
                 }
             }
             Config.Instance.Home.InitFloor();
+
+            CurrentRoom.RefreshRoomListView();
+        }
+
+        /// <summary>
+        /// 鍒锋柊鎴块棿瑙嗗浘鍒楄〃
+        /// </summary>
+        public void RefreshRoomListView()
+        {
+            Application.RunOnMainThread(() =>
+            {
+                Phone.Device.Room.RoomManagement.Instance.Show();
+            });
         }
 
         /// <summary>
@@ -445,8 +458,33 @@
             //鍒犻櫎鏉ヨ嚜鎷嶇収鎴栬�呯郴缁熷浘搴撶殑鎴块棿鑳屾櫙鍥剧墖
             if (room.BackgroundImageType == 1 || room.BackgroundImageType == 2)
             {
-                DeleteBackGroundIamageFilebyHomeId(room.BackgroundImage);
+                //鍒犻櫎鎺夊師鏉ョ殑鑷畾涔夊浘鐗�
+                if (Global.IsExistsByHomeId(room.BackgroundImage) == true)
+                {
+                    Global.DeleteFilebyHomeId(room.BackgroundImage);
+                    //鍒犻櫎澶囦唤
+                    HdlAutoBackupLogic.DeleteFile(room.BackgroundImage);
+                }
             }
+            //鎴戠殑鍠滅埍
+            var loveRoom = this.GetLoveRoom();
+            if (loveRoom != null)
+            {
+                //绉婚櫎鎴戠殑鍠滅埍閲岄潰鐨勮澶�
+                for (int i = 0; i < room.DeviceUIFilePathList.Count; i++)
+                {
+                    loveRoom.DeviceUIFilePathList.Remove(room.DeviceUIFilePathList[i]);
+                    loveRoom.DeviceUIList.RemoveAll((obj) => { return room.DeviceUIFilePathList[i] == obj.FileName; });
+                }
+                //绉婚櫎鎴戠殑鍠滅埍閲岄潰鐨勫満鏅�
+                for (int i = 0; i < room.SceneUIFilePathList.Count; i++)
+                {
+                    loveRoom.SceneUIFilePathList.Remove(room.SceneUIFilePathList[i]);
+                    loveRoom.SceneUIList.RemoveAll((obj) => { return room.SceneUIFilePathList[i] == obj.FileName; });
+                }
+                loveRoom.Save(false);
+            }
+
             if (Global.IsExistsByHomeId(roomFilePath) == false)
             {
                 return false;
@@ -456,6 +494,9 @@
             Global.DeleteFilebyHomeId(roomFilePath);
             Lists.Remove(room);
             HdlAutoBackupLogic.DeleteFile(roomFilePath);
+
+            CurrentRoom.RefreshRoomListView();
+
             return true;
         }
 
@@ -754,6 +795,25 @@
             return false;
         }
 
+        /// <summary>
+        /// 鑾峰彇鎴块棿鎵�鍦ㄥ尯鍩�
+        /// 妤煎眰,鎴块棿鍚�
+        /// </summary>
+        /// <returns></returns>
+        public string GetZoneName()
+        {
+            if (string.IsNullOrEmpty(FloorId))
+            {
+                return Name;
+            }
+            var floorName = Config.Instance.Home.GetFloorNameById(FloorId);
+            if (floorName == null)
+            {
+                return Name;
+            }
+            return $"{floorName},{Name}";
+        }
+
         #endregion
 
         #region 鈼� 鏇存柊鎴块棿_________________________
@@ -770,31 +830,6 @@
         #endregion
 
         #region 鈼� 鎴块棿鑳屾櫙鍥剧殑鐩稿叧___________________
-        /// <summary>
-        /// 鍒犻櫎鑳屾櫙鍥剧墖
-        /// </summary>
-        /// <param name="fileName">fileName瀹為檯涓婂寘鍚簡浣忓畢璺姴 濡� 浣忓畢/鏂囦欢鍚�.</param>
-        public static void DeleteBackGroundIamageFilebyHomeId(string fileName)
-        {
-            if (fileName == null)
-            {
-                return;
-            }
-            var pathLists = fileName.Split('/');
-            if (pathLists == null || pathLists.Count() < 9 || pathLists[8] == null)
-            {
-                return;
-            }
-            var path = System.IO.Path.Combine(Config.Instance.FullPath, fileName);
-            if (!Global.IsExistsByHomeId(pathLists[8]))
-            {
-                return;
-            }
-            //鍒犻櫎鏈湴鍥剧墖
-            System.IO.File.Delete(path);
-            //鍒犻櫎澶囦唤
-            Phone.UserCenter.HdlAutoBackupLogic.DeleteFile(pathLists[8]);
-        }
 
         /// <summary>
         /// 绉诲姩鑳屾櫙鍥剧墖鍒颁綇瀹呯洰褰曚笅
@@ -930,6 +965,31 @@
             this.DeleteDevice(device);
         }
 
+        /// <summary>
+        /// 鍒犻櫎鎴戠殑鍠滅埍鐨勮澶�
+        /// </summary>
+        /// <param name="device">瑕佸垹闄ょ殑璁惧瀵硅薄</param>
+        public void DeleteLoveDevice(CommonDevice device)
+        {
+            if (device == null)
+            {
+                return;
+            }
+            //鎴戠殑鍠滅埍
+            var loveRoom = this.GetLoveRoom();
+            if (loveRoom != null)
+            {
+                string deviceFile = device.FilePath;
+                //绉婚櫎缂撳瓨
+                if (loveRoom.DeviceUIFilePathList.Contains(deviceFile) == false)
+                {
+                    return;
+                }
+                loveRoom.DeviceUIFilePathList.Remove(deviceFile);
+                loveRoom.DeviceUIList.RemoveAll((obj) => obj.FileName == deviceFile);
+            }
+        }
+
         #endregion
 
         #region 鈼� 鑾峰彇璁惧_________________________
@@ -1053,16 +1113,16 @@
         /// <param name="sceneIconPath">鑳屾櫙鍥剧墖锛屼笉鍖呭惈浣忓畢璺緞 濡傛灉iconPathType=1鎴栬��2 闇�瑕佹嫾鎺ヤ綇瀹� 鍙樻垚 浣忓畢/sceneIconPath</param>
         /// <param name="commons">Commons.</param>
         /// <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)
+        public async System.Threading.Tasks.Task<int> AddScene(string sceneName, string sceneIconPath, List<ZigBee.Device.Scene.AddSceneMemberData> commons, int iconPathType)
         {
-            var scenes = GetSceneUIsByFloorId(FloorId);
-            if(scenes!=null && scenes.Count>0)
-            {
-                if (scenes.Find(s => s.Name == sceneName) != null)
-                {
-                    return -1;
-                }
-            }
+            //var scenes = GetSceneUIsByFloorId(FloorId);
+            //if(scenes!=null && scenes.Count>0)
+            //{
+            //    if (scenes.Find(s => s.Name == sceneName) != null)
+            //    {
+            //        return -1;
+            //    }
+            //}
 
             var getSceneIdAllData = await ZigBee.Device.Scene.GetSceneNewIdAsync(sceneName);
             if (getSceneIdAllData == null || getSceneIdAllData.getSceneIdData == null)
@@ -1102,26 +1162,18 @@
             //鍔犲叆鎴愬姛
             if (result)
             {
-                //iconPathType=0 鐩存帴浼犲�硷紝 iconPathType=1鍜宨conPathType=2闇�瑕佹嫾鎺ヤ綇瀹呰矾寰�
-                var fullPath = sceneIconPath;
-                if (iconPathType == 1 || iconPathType == 2)
-                {
-                    Common.Room.CurrentRoom.MoveBackGroundIamageFileToDirectory(sceneIconPath, $"{Config.Instance.FullPath}/{sceneIconPath}");
-                    fullPath = $"{Config.Instance.FullPath}/{sceneIconPath}";
-                }
                 var sceneUI = new SceneUI
                 {
                     Name = sceneName,
                     Id = getSceneIdData.NewScenesId,
-                    IconPath = fullPath,
+                    IconPath = sceneIconPath,
                     IconPathType = iconPathType,
                     AddSceneMemberDataList= commons
                 };
+                sceneUI.Save();
                 SceneUIList.Add(sceneUI);
                 SceneUIFilePathList.Add(sceneUI.FileName);
-                sceneUI.Save();
                 Save();
-                HdlAutoBackupLogic.AddOrEditorFile(sceneUI.FileName);
                 return 1;
             }
             return 0;
@@ -1167,15 +1219,10 @@
         /// <summary>
         /// 鏄惁鏄敹钘忚澶�
         /// </summary>
-        /// <param name="room"></param>
         /// <param name="filePath"></param>
         /// <returns></returns>
-        public bool IsCollectInRoom(Room room,string filePath)
+        public bool IsCollectInRoom(string filePath)
         {
-            if(room.IsLove)
-            {
-                return true;
-            }
             if (GetLoveRoom().DeviceUIFilePathList.Find((obj) => obj == filePath) == null)
             {
                 return false;
@@ -1195,10 +1242,10 @@
         /// <param name="addCommons">Add commons.</param>
         public async System.Threading.Tasks.Task<int> ModifyScene(SceneUI sceneUI, Scene.SceneRemoveMemberData sceneRemoveMemberData, List<Scene.AddSceneMemberData> addCommons)
         {
-            if (AllRoomSceneUIList.Find(s => s.Name == sceneUI.Name) == null)
-            {
-                return 0;
-            }
+            //if (AllRoomSceneUIList.Find(s => s.Name == sceneUI.Name) == null)
+            //{
+            //    return 0;
+            //}
 
             bool result = true;
             //绉婚櫎鎴愬憳 杩斿洖缁撴灉
@@ -1272,6 +1319,13 @@
             SceneUIList.Remove(sceneUI);
             SceneUIFilePathList.Remove(sceneUI.FileName);
             Save();
+            if (IsLove == false)
+            {
+                if (CurrentRoom.GetLoveRoom().SceneUIList.Find((obj) => obj.Id == sceneUI.Id) != null)
+                {
+                    CurrentRoom.GetLoveRoom().DeleteScene(sceneUI);
+                }
+            }
             Global.DeleteFilebyHomeId(sceneUI.FileName);
             HdlAutoBackupLogic.DeleteFile(sceneUI.FileName);
         }

--
Gitblit v1.8.0