From f6b3446e3a4afc0f65814be87aaa0f5ea0c62d69 Mon Sep 17 00:00:00 2001
From: gxc <guoxuecheng@guoxuechengdeMacBook-Pro.local>
Date: 星期一, 28 十月 2019 10:50:30 +0800
Subject: [PATCH] 2019.10.28

---
 ZigbeeApp/Shared/Common/Room.cs |  215 +++++++++++++++++++++++++++++++++--------------------
 1 files changed, 132 insertions(+), 83 deletions(-)

diff --git a/ZigbeeApp/Shared/Common/Room.cs b/ZigbeeApp/Shared/Common/Room.cs
index 64e0190..c60cf9d 100644
--- a/ZigbeeApp/Shared/Common/Room.cs
+++ b/ZigbeeApp/Shared/Common/Room.cs
@@ -140,11 +140,28 @@
 
         /// <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,39 @@
 
         /// <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>();
+                foreach (var room in 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 (deviceList.Find((obj) => obj.FileName == device.FileName) == null)
+                        {
+                            deviceList.Add(device);
+                        }
+                    }
+                }
+                return deviceList;
+            }
+        }
 
         #endregion
 
@@ -710,8 +755,9 @@
         public void AddDevice(string deviceUIFilePath)
         {
             if (string.IsNullOrEmpty(deviceUIFilePath))
-            {
-                return;
+
+             {
+                 return;
             }
             var jsonInfo = Encoding.UTF8.GetString(Global.ReadFileByHomeId(deviceUIFilePath));
             var deviceUI = Newtonsoft.Json.JsonConvert.DeserializeObject<DeviceUI>(jsonInfo);
@@ -815,39 +861,6 @@
         #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瀵硅薄锛屽鏋滀笉瀛樺湪鍒欐柊寤�
         /// </summary>
         /// <returns>The device user interface.</returns>
@@ -855,25 +868,6 @@
         public DeviceUI GetDeviceUI(CommonDevice device)
         {
             return Common.LocalDevice.Current.GetDeviceUI(device);
-        }
-
-        /// <summary>
-        /// 閲嶆柊鑾峰彇-鎵�鏈夋埧闂寸殑鎵�鏈夎澶囩被鍨�
-        /// </summary>
-        public static void GetAllRoomDeviceTypeList()
-        {
-            AllRoomDeviceTypeList.Clear();
-            foreach (var deviceUI in AllRoomDeviceUIList)
-            {
-                if (deviceUI == null || deviceUI.CommonDevice == null)
-                {
-                    continue;
-                }
-                if (!AllRoomDeviceTypeList.Contains(deviceUI.CommonDevice.Type))
-                {
-                    AllRoomDeviceTypeList.Add(deviceUI.CommonDevice.Type);
-                }
-            }
         }
 
         /// <summary>
@@ -947,6 +941,36 @@
             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
 
@@ -962,25 +986,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)
@@ -988,12 +1008,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;
@@ -1043,17 +1064,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();
         }
 
@@ -1125,7 +1159,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);
@@ -1196,7 +1231,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 鈼� 鍒锋柊鍦烘櫙_________________________

--
Gitblit v1.8.0