gxc
2019-10-17 1f65fe366062b3f2cda6b03e1849afce6d2646f8
ZigbeeApp/Shared/Common/Room.cs
old mode 100755 new mode 100644
@@ -38,12 +38,22 @@
        /// </summary>
        public string FloorId = string.Empty;
        /// <summary>
        /// 楼层名称
        /// </summary>
        public string FloorName
        {
            get
            {
               return Config.Instance.Home.GetFloorNameById(FloorId);
            }
        }
        /// <summary>
        /// 房间名
        /// </summary>
        public string Name = string.Empty;
        /// <summary>
        /// 房间的时候背景图
        /// 房间背景图
        /// </summary>
        public string BackgroundImage = string.Empty;
@@ -56,6 +66,15 @@
        /// 楼层--备用
        /// </summary>
        public Dictionary<string, string> FloorList = new Dictionary<string, string> { };
        /// <summary>
        /// 温度传感器(设备主键)
        /// </summary>
        public string TemperatrueDevice = string.Empty;
        /// <summary>
        /// 湿度传感器(设备主键)
        /// </summary>
        public string HumidityDevice = string.Empty;
        /// <summary>
        /// 当前选择的房间
@@ -73,6 +92,11 @@
        public readonly List<string> DeviceUIFilePathList = new List<string>();
        /// <summary>
        /// 喜爱房间id
        /// </summary>
        public const string LoveRoomId= "Favorite";
        /// <summary>
        /// 是否是默认喜爱房间
        /// </summary>
        /// <value><c>true</c> if is love; otherwise, <c>false</c>.</value>
@@ -81,7 +105,7 @@
        {
            get
            {
                return Id == "Favorite";
                return Id == LoveRoomId;
            }
        }
@@ -110,8 +134,7 @@
                {
                    return new List<string> { };
                }
                var loveRoom = Lists[0];
                return loveRoom.DeviceUIFilePathList;
                return CurrentRoom.GetLoveRoom().DeviceUIFilePathList;
            }
        }
@@ -204,7 +227,7 @@
            if (Config.Instance.Home.RoomFilePathList.Contains("Room_Favorite.json") == false)
            {
                //默认添加喜爱的房间--禁止修改房间名
                var love = new Room { Name = Language.StringByID(R.MyInternationalizationString.Favorite), BackgroundImage = "Room/r0.png", Id = "Favorite" };
                var love = new Room { Name = Language.StringByID(R.MyInternationalizationString.Favorite), BackgroundImage = "Room/r0.png", Id = LoveRoomId };
                love.Save(true);
                //添加到house 房间路径列表
                var currentHome = Config.Instance.Home;
@@ -323,6 +346,15 @@
        #region ◆ 获取房间________________________
        /// <summary>
        /// 获取喜爱房间
        /// </summary>
        /// <returns></returns>
        public  Room GetLoveRoom()
        {
            return CurrentRoom.GetRoomById(LoveRoomId);
        }
        /// <summary>
        /// 通过路径获取房间
        /// </summary>
        /// <returns>The room by file path.</returns>
@@ -431,6 +463,16 @@
        }
        /// <summary>
        /// 根据房间名字,获取房间对象
        /// </summary>
        /// <returns>The room by name.</returns>
        /// <param name="roomName">房间名</param>
        public Room GetRoomByName(string roomName)
        {
            return Lists.Find((obj) => obj.Name == roomName);
        }
        /// <summary>
        /// 根据设备获取房间名字(楼层+房间名)
        /// </summary>
        /// <returns>房间名</returns>
@@ -500,6 +542,55 @@
            return null;
        }
        /// <summary>
        /// 获取当前楼层的房间
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public  List<Room> GetRoomsByFloorId(string id)
        {
            return Lists.FindAll((obj) => obj.FloorId==id);
        }
        /// <summary>
        /// 获取当前楼层的房间名称
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public  List<string> GetRoomNamesByFloorId(string id)
        {
            List<string> names = new List<string> { };
            foreach(var r in Lists)
            {
                if(r.FloorId==id)
                {
                    names.Add(r.Name);
                }
            }
            return names;
        }
        /// <summary>
        /// 获取当前楼层的房间(拼接了【常用】在第一位)
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public  List<Room> GetRoomsByFloorIdAppendLoveRoom(string id)
        {
            var r= Lists.FindAll((obj) => obj.FloorId == id);
            r.Insert(0, GetLoveRoom());
            return r;
        }
        /// <summary>
        /// 获取当前楼层的房间(拼接了【常用】在第一位)
        /// </summary>
        /// <returns></returns>
        public  List<Room> GetRoomsByCurrentFloorIdAppendLoveRoom()
        {
            var r = Lists.FindAll((obj) => obj.FloorId == Config.Instance.Home.CurrentFloorId);
            r.Insert(0, GetLoveRoom());
            return r;
        }
        #endregion
@@ -670,7 +761,6 @@
        #endregion
        #region ◆ 删除设备_________________________
        /// <summary>
        /// 删除功能-设备
        /// </summary>
@@ -786,6 +876,78 @@
            }
        }
        /// <summary>
        /// 获取当前房间下的全部设备
        /// </summary>
        /// <returns></returns>
        public List<CommonDevice> GetRoomListDevice()
        {
            var listDevice = new List<CommonDevice>();
            foreach (var device in this.DeviceUIList)
            {
                if (device == null || device.CommonDevice == null)
                {
                    continue;
                }
                listDevice.Add(device.CommonDevice);
            }
            if (listDevice.Count == 0)
            {
                return listDevice;
            }
            return Common.LocalDevice.Current.SortDevice(listDevice);
        }
        /// <summary>
        /// 获取房间设备类型
        /// </summary>
        /// <param name="room"></param>
        /// <returns></returns>
        public static List<DeviceType> GetdeviceTypes(Room room)
        {
            List<DeviceType> typeList = new List<DeviceType> { };
            foreach (var deviceUI in room.DeviceUIList)
            {
                if (deviceUI == null || deviceUI.CommonDevice == null)
                {
                    continue;
                }
                if (!typeList.Contains(deviceUI.CommonDevice.Type))
                {
                    typeList.Add(deviceUI.CommonDevice.Type);
                }
            }
            return typeList;
        }
        /// <summary>
        /// 获取该类型的设备
        /// </summary>
        /// <param name="room"></param>
        /// <param name="deviceType"></param>
        /// <returns></returns>
        public static List<DeviceUI> GetDeviceUIs(Room room ,DeviceType deviceType)
        {
            List<DeviceUI> typeList = new List<DeviceUI> { };
            foreach (var deviceUI in room.DeviceUIList)
            {
                if (deviceUI == null || deviceUI.CommonDevice == null)
                {
                    continue;
                }
                if(deviceUI.CommonDevice.Type!=deviceType)
                {
                    continue;
                }
                if (!typeList.Contains(deviceUI))
                {
                    typeList.Add(deviceUI);
                }
            }
            return typeList;
        }
        #endregion
        #region ◆ 添加场景_________________________
@@ -895,6 +1057,28 @@
            Save();
        }
        #endregion
        #region ◆ 设备是否收藏______________________
        /// <summary>
        /// 是否是收藏设备
        /// </summary>
        /// <param name="room"></param>
        /// <param name="filePath"></param>
        /// <returns></returns>
        public bool IsCollectInRoom(Room room,string filePath)
        {
            if(room.IsLove)
            {
                return true;
            }
            if (GetLoveRoom().DeviceUIFilePathList.Find((obj) => obj == filePath) == null)
            {
                return false;
            }
            return true;
        }
        #endregion
        #region ◆ 修改场景________________________
@@ -1121,7 +1305,7 @@
            var dicRoom = new Dictionary<string, Common.Room>();
            foreach (var room in Common.Room.Lists)
            {
                if (room.FloorId != i_floorKeys)
                if (room.FloorId != i_floorKeys || room.IsLove == true)
                {
                    //不是同一个楼层
                    continue;
@@ -1237,6 +1421,8 @@
            //克隆属性
            newRoom.Id = this.Id;
            newRoom.FloorId = this.FloorId;
            newRoom.TemperatrueDevice = this.TemperatrueDevice;
            newRoom.HumidityDevice = this.HumidityDevice;
            newRoom.Name = this.Name;
            newRoom.BackgroundImage = this.BackgroundImage;
            newRoom.BackgroundImageType = this.BackgroundImageType;
@@ -1245,5 +1431,6 @@
        }
        #endregion
    }
}