From a46cd0adb5af29e8a9cf47c219475acaedfcf839 Mon Sep 17 00:00:00 2001
From: wxr <464027401@qq.com>
Date: 星期二, 01 十二月 2020 17:09:00 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/WJC'

---
 HDL_ON/UI/UI2/3-Intelligence/Automation/LogicMethod.cs |  344 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 344 insertions(+), 0 deletions(-)

diff --git a/HDL_ON/UI/UI2/3-Intelligence/Automation/LogicMethod.cs b/HDL_ON/UI/UI2/3-Intelligence/Automation/LogicMethod.cs
new file mode 100644
index 0000000..17ebb5e
--- /dev/null
+++ b/HDL_ON/UI/UI2/3-Intelligence/Automation/LogicMethod.cs
@@ -0,0 +1,344 @@
+锘縰sing System;
+using System.Collections.Generic;
+using Shared;
+
+namespace HDL_ON.UI.UI2.Intelligence.Automation
+{
+    
+    public class LogicMethod
+    {
+        /// <summary>
+        /// 琛ㄧず鏄潯浠�
+        /// </summary>
+        public const string condition_if = "鏉′欢";
+        /// <summary>
+        /// 琛ㄧず鏄洰鏍�
+        /// </summary>
+        public const string target_if = "鐩爣";
+        /// <summary>
+        /// 绉婚櫎鎵�鏈�"Logic"鐣岄潰
+        /// </summary>
+        public static void RemoveAllView()
+        {
+            MainPage.BasePageView.RemoveViewByTag("Logic");
+        }
+        /// <summary>
+        /// 鐢熸垚閫昏緫sid鏂规硶
+        /// </summary>
+        public static string NewSid()
+        {
+            string logicId = "";
+            try
+            {
+                string sOidBeginsWith = "000101";//鍘傚晢 + 閫氳鏂瑰紡
+                DateTime dt = DateTime.Now;
+                DateTime startTime = TimeZoneInfo.ConvertTimeToUtc(new DateTime(2020, 1, 1));
+                long m = (long)((dt - startTime).TotalMilliseconds / 10);
+                string sTimeSpan = "00000000";
+
+                byte[] arry = new byte[4];
+                arry[0] = (byte)(m & 0xFF);
+                arry[1] = (byte)((m & 0xFF00) >> 8);
+                arry[2] = (byte)((m & 0xFF0000) >> 16);
+                arry[3] = (byte)((m >> 24) & 0xFF);
+                sTimeSpan = arry[0].ToString("X2") + arry[1].ToString("X2") + arry[2].ToString("X2") + arry[3].ToString("X2");
+
+
+                if (sTimeSpan.Length > 8)
+                {
+                    sTimeSpan = sTimeSpan.Substring(0, 8);
+                }
+                else
+                {
+                    sTimeSpan = "00000000";
+                }
+
+                logicId = sOidBeginsWith + sTimeSpan;
+
+                logicId += "0A";
+                logicId += "0A01";
+                //0A01 鐗╂ā鍨嬩负閫昏緫锛� 0001 琛ㄧず 1 鍙烽�昏緫鍔熻兘
+                int iTopLogicId = 1;
+
+                Random random = new Random();
+                iTopLogicId = random.Next(0, 255);
+                iTopLogicId += random.Next(0, 255);
+
+                logicId += iTopLogicId.ToString("X4");//閫昏緫鍙� 涓や釜byte 
+                logicId += "1100";
+            }
+            catch
+            {
+                return logicId;
+            }
+            return logicId;
+        }
+        /// <summary>
+        /// 灏佽Dictionary瀵硅薄
+        /// </summary>
+        /// <param name="dic">Dictionary绫�</param>
+        /// <param name="key">鍋�</param>
+        /// <param name="value">鍊�</param>
+        public static void dictionary(Dictionary<string, string> dic, string key, string value)
+        {
+            if (dic.ContainsKey(key)) //鍒ゆ柇鏄惁瀛樺湪閿��
+            {
+                //閿瓨鍦ㄧЩ闄�
+                dic.Remove(key);
+            }
+            //娣诲姞閿��
+            dic.Add(key, value);
+        }
+        /// <summary>
+        /// 鑾峰彇缃戝叧鎴块棿鍒楄〃
+        /// </summary>
+        /// <returns></returns>
+        public static List<HDL_ON.Entity.Room> GetGatewayRoomList() 
+        {
+            return HDL_ON.Entity.DB_ResidenceData.rooms;
+        }
+        /// <summary>
+        /// 鑾峰彇缃戝叧鎴块棿鍒楄〃
+        /// </summary>
+        /// <returns></returns>
+        public static List<HDL_ON.Entity.Room> GetGatewayRoomList(string name) 
+        {
+
+            List<Entity.Room> roomList = new List<Entity.Room>();
+            Entity.Room room1 = new Entity.Room();
+            room1.name = name;//榛樿涓�涓埧闂村悕涓�:鍏ㄩ儴鍖哄煙
+            room1.sid = "鍏ㄩ儴鍖哄煙";//榛樿sid鐢ㄨ瘑鍒鎴块棿
+            roomList.Add(room1);//榛樿娣诲姞鍒版埧闂村垪琛ㄩ噷
+            var roomLists = GetGatewayRoomList();
+            foreach (var room in roomLists)
+            {
+                roomList.Add(room);
+            }
+
+            return roomList;
+        }
+        /// <summary>
+        /// 鑾峰彇缃戝叧璁惧鍒楄〃
+        /// </summary>
+        /// <returns></returns>
+        public static List<HDL_ON.Entity.Function> GetGatewayDeviceList()
+        {
+
+            return HDL_ON.Entity.DB_ResidenceData.functionList.GetAllFunction();
+        }
+        /// <summary>
+        /// 鑾峰彇缃戝叧鍦烘櫙鍒楄〃
+        /// </summary>
+        /// <returns></returns>
+        public static List<HDL_ON.Entity.Scene> GetSceneList()
+        {
+           return  HDL_ON.Entity.DB_ResidenceData.functionList.scenes;
+        }
+        /// <summary>
+        /// 鑾峰彇鎴块棿鐨勮澶囧垪琛�
+        /// </summary>
+        /// <param name="room">褰撳墠鎴块棿</param>
+        /// <returns></returns>
+        public static List<HDL_ON.Entity.Function> GetRoomDevice(HDL_ON.Entity.Room room)
+        {
+            List<HDL_ON.Entity.Function> deviceLists = new List<Entity.Function>();
+            List<HDL_ON.Entity.Function> lists = GetGatewayDeviceList();
+            foreach (var dev in lists)
+            {
+                if (dev.roomIdList.Find((id) => id == room.sid) != null)
+                {
+                    deviceLists.Add(dev);
+                }
+                if (room.sid == "鍏ㄩ儴鍖哄煙")
+                {
+                    //鎴块棿鍚嶄负鍏ㄩ儴鍖哄煙鏃讹紝鏄剧ず缃戝叧鍏ㄩ儴璁惧
+                    deviceLists = lists;
+                }
+
+            }
+            return deviceLists;
+        }
+        /// <summary>
+        /// 鑾峰彇褰撲釜璁惧
+        /// </summary>
+        /// <param name="sid">璁惧鍞竴鏍囪瘑</param>
+        /// <returns></returns>
+        public static HDL_ON.Entity.Function GetDevice(string sid)
+        {
+            HDL_ON.Entity.Function device = new Entity.Function() { name= "Unknown",sid="璁惧涓嶅瓨鍦�"};
+            List<HDL_ON.Entity.Function> deviceLists = GetGatewayDeviceList();
+            foreach (var dev in deviceLists)
+            {
+                if (dev.sid == sid)
+                {
+                    device = dev;
+                    break;
+                }
+            }
+            return device;
+        }
+
+        /// <summary>
+        /// 鑾峰彇褰撲釜鍦烘櫙
+        /// </summary>
+        /// <param name="sid">鍦烘櫙鍞竴鏍囪瘑</param>
+        /// <returns></returns>
+        public static HDL_ON.Entity.Scene GetSecne(string sid)
+        {
+            HDL_ON.Entity.Scene scene = new Entity.Scene() { name = "Unknown", sid = "鍦烘櫙涓嶅瓨鍦�" };
+            List<HDL_ON.Entity.Scene> sceneLists = GetSceneList();
+            foreach (var sce in sceneLists)
+            {
+                if (sce.sid == sid)
+                {
+                    scene = sce;
+                    break;
+                }
+            }
+            return scene;
+        }
+        /// <summary>
+        /// 鑾峰彇鎴块棿鍚�(鍗虫槸=鍖哄煙鍚嶇О)
+        /// </summary>
+        /// <param name="device">璁惧</param>
+        /// <returns></returns>
+        public static string GetGetRoomName(HDL_ON.Entity.Function device)
+        {
+            string roomName = "";
+            List<HDL_ON.Entity.Room> roomLists = GetGatewayRoomList();
+
+            foreach (var dev in device.roomIdList)
+            {
+                var room = roomLists.Find((c) => c.sid == dev);
+                if (room != null)
+                {
+                    roomName += room.floorName + "." + room.name + ",";
+                }
+            }
+
+            return roomName.TrimEnd(',');
+        }
+        /// <summary>
+        /// 鑾峰彇璁惧绫诲瀷鍥炬爣
+        /// </summary>
+        /// <param name="functionType">璁惧绫诲瀷</param>
+        /// <returns></returns>
+        public static string GetIconPath(FunctionType functionType)
+        {
+            string strPath = "";
+            switch (functionType)
+            {
+                case FunctionType.Relay:
+                    {
+                        strPath = "LogicIcon/lightloguc.png";
+                    }
+                    break;
+
+            }
+            return strPath;
+        }
+        /// <summary>
+        /// 璁惧绫诲瀷鐨勫垪琛�(鐏厜绫伙紝绐楀笜绫汇�傘�傘��)
+        /// </summary>
+        /// <param name="deviceList">璁惧鍒楄〃</param>
+        /// <returns></returns>
+        public static List<string> GetDeviceTypeList(List<HDL_ON.Entity.Function> deviceList) 
+        {
+            List<string> deviceStrTypeList = new List<string>(); 
+            deviceStrTypeList.Clear();
+            var lightjosn = deviceList.Find((device) => device.functionType == FunctionType.Relay || device.functionType == FunctionType.Dimmer);
+            if (lightjosn != null)
+            {
+                deviceStrTypeList.Add(Language.StringByID(StringId.Lights));
+            }
+
+            var curtainjosn = deviceList.Find((device) => device.functionType ==FunctionType.Curtain);
+            if (curtainjosn != null)
+            {
+                deviceStrTypeList.Add(Language.StringByID(StringId.Curtain));
+            }
+
+            var ac = deviceList.Find((device) => device.functionType == FunctionType.AC);
+            if (ac != null)
+            {
+                deviceStrTypeList.Add(Language.StringByID(StringId.AC));
+            }
+            return deviceStrTypeList;
+
+        }
+        /// <summary>
+        /// 璁惧绫诲瀷FunctionType鍒楄〃
+        /// </summary>
+        /// <param name="deviceType">璁惧绫诲瀷(鐏厜绫伙紝绐楀笜绫汇��)</param>
+        /// <returns></returns>
+        public static List<FunctionType> GetDeviceTypeFunctionList(string deviceType)
+        {
+            List<FunctionType> functionTypeList = new List<FunctionType>();
+            if (deviceType == Language.StringByID(StringId.Lights))
+            {
+                functionTypeList.Add(FunctionType.Relay);
+                functionTypeList.Add(FunctionType.Dimmer);
+            }
+            else if (deviceType == Language.StringByID(StringId.Curtain))
+            {
+                functionTypeList.Add(FunctionType.Curtain);
+            }
+            return functionTypeList;
+
+        }
+        /// <summary>
+        /// 鏉′欢/鐩爣鏀寔璁惧
+        /// </summary>
+        /// <returns></returns>
+        public static List<FunctionType> GetSupportEquipment(string if_type)  
+        {
+            List<FunctionType> deviceTypeList = new List<FunctionType>();
+            switch (if_type) {
+                case condition_if: {
+                        deviceTypeList.Add(FunctionType.Relay);
+                    }
+                    break;
+                case target_if:
+                    {
+                        deviceTypeList.Add(FunctionType.Relay);
+                    }
+                    break;
+            }
+            return deviceTypeList;
+        }
+        /// <summary>
+        /// 鏄剧ず鐨勮澶囧垪琛�
+        /// </summary>
+        /// <param name="functionType">婧愭暟鎹垪琛�1</param>
+        /// <param name="deviceList">婧愭暟鎹垪琛�2</param>
+        /// <returns></returns>
+        public static List<Entity.Function> GetShowDeviceList(List<FunctionType> functionType, List<HDL_ON.Entity.Function> deviceList)
+        {
+            List<HDL_ON.Entity.Function> devList = new List<Entity.Function>();
+            foreach (var dev in deviceList)
+            {
+                if (functionType.Contains(dev.functionType))
+                {
+                    ///杩囨护鎺変笉闇�瑕佹樉绀虹殑璁惧
+                    devList.Add(dev);
+                }
+            }
+            return devList;
+        }
+        /// <summary>
+        /// 杩斿洖鏈�缁堟敮鎸佹樉绀哄嚭鏉ョ殑璁惧鍒楄〃
+        /// </summary>
+        /// <param name="room">褰撳墠鎴块棿</param>
+        /// <param name="str">鍒ゆ柇绗︼紙琛ㄧず=杈撳叆璁惧鍜岃緭鍑鸿澶囷級</param>
+        /// <returns></returns>
+        public static List<Entity.Function> GetFunctionDeviceList(Entity.Room room, string str)
+        {
+            List<FunctionType> functionTypeList = GetSupportEquipment(str);
+            //杩斿洖鎴块棿璁惧鍒楄〃
+            var roomDeviceList = GetRoomDevice(room);
+            //杩斿洖鏈�缁堟敮鎸佹樉绀哄嚭鏉ョ殑璁惧鍒楄〃
+            var list = GetShowDeviceList(functionTypeList, roomDeviceList);
+            return list;
+        }
+    }
+}

--
Gitblit v1.8.0