From 0f2e0147e8990e913d16d99bc1b94fb6bc53abd7 Mon Sep 17 00:00:00 2001
From: 陈嘉乐 <cjl@hdlchina.com.cn>
Date: 星期四, 03 十二月 2020 15:35:42 +0800
Subject: [PATCH] 2020-12-03-1

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

diff --git a/HDL_ON/UI/UI2/3-Intelligence/Automation/LogicMethod.cs b/HDL_ON/UI/UI2/3-Intelligence/Automation/LogicMethod.cs
index 7630684..8d56021 100644
--- a/HDL_ON/UI/UI2/3-Intelligence/Automation/LogicMethod.cs
+++ b/HDL_ON/UI/UI2/3-Intelligence/Automation/LogicMethod.cs
@@ -1,10 +1,27 @@
 锘縰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>
@@ -72,10 +89,386 @@
             //娣诲姞閿��
             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) 
+        {
 
-        public static void InputCondition() {
+            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()
+        {
+            List<HDL_ON.Entity.Function> list = new List<Entity.Function>();
+            for (int i=0;i<10;i++) {
+                HDL_ON.Entity.Function function = new Entity.Function();
+                switch (i) {
+                    case 0: {
+                            function.sid = "1234560001212121020182";
+                            function.name ="鐏厜";
+                            list.Add(function);
+                        }
+                        break;
+                    case 1: {
+                          
+                            function.sid = "1234560001212121030182";
+                            function.name = "绐楀笜";
+                            list.Add(function);
+                        } break;
+                    case 2: {
+                            function.sid = "1234560001212121040182";
+                            function.name = "绌鸿皟";
+                            list.Add(function);
+                        } break;
+                    case 3:
+                        {
+                            function.sid = "1234560001212121010282";
+                            function.name = "RGBW";
+                            list.Add(function);
+                        }
+                        break;
+                    case 4:
+                        {
+
+                            function.sid = "1234560001212121010382";
+                            function.name = "CCT鐏�";
+                            list.Add(function);
+                        }
+                        break;
+                    case 5:
+                        {
+                            function.sid = "1234560001212121010482";
+                            function.name = "寮�鍚堝笜";
+                            list.Add(function);
+                        }
+                        break;
+                    case 6:
+                        {
+                            function.sid = "1234560001212121010582";
+                            function.name = "鍗峰笜";
+                            list.Add(function);
+                        }
+                        break;
+                    case 7:
+                        {
+                            function.sid = "1234560001212121040282";
+                            function.name = "鍦扮儹";
+                            list.Add(function);
+                        }
+                        break;
+                    case 8:
+                        {
+                            function.sid = "1234560001212121020282";
+                            function.name = "璋冨叧";
+                            list.Add(function);
+                        }
+                        break;
+                    case 9:
+                        {
+                            function.sid = "1234560001212121020482";
+                            function.name = "RGB";
+                            list.Add(function);
+                        }
+                        break;
+                }
+            }
+            return list;
+            //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.roomIds.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.roomIds)
+            {
+                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:
+                case FunctionType.RGB:
+                case FunctionType.RGBW:
+                case FunctionType.CCT:
+                case FunctionType.Dimmer:
+                    {
+                        strPath = "LogicIcon/lightloguc.png";
+                    }
+                    break;
+                case FunctionType.Curtain:
+                case FunctionType.RollerCurtain:
+                case FunctionType.TrietexCurtain:
+                    {
+                        strPath = "LogicIcon/curtainlogic.png";
+                    }
+                    break;
+                case FunctionType.AC:
+                    {
+                        strPath = "LogicIcon/airconditionerlogic.png";
+                    }
+                    break;
+                case FunctionType.FloorHeating:
+                    {
+                        strPath = "LogicIcon/heatlogic.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|| device.functionType == FunctionType.CCT || device.functionType == FunctionType.RGB|| device.functionType == FunctionType.RGBW);
+            if (lightjosn != null)
+            {
+                deviceStrTypeList.Add(Language.StringByID(StringId.Lights));
+            }
+
+            var curtainjosn = deviceList.Find((device) => device.functionType ==FunctionType.Curtain|| device.functionType == FunctionType.TrietexCurtain|| device.functionType == FunctionType.RollerCurtain);
+            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));
+            }
+            var floorHeating = deviceList.Find((device) => device.functionType == FunctionType.FloorHeating);
+            if (ac != null)
+            {
+                deviceStrTypeList.Add(Language.StringByID(StringId.FloorHeating));
+            }
+            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);
+                functionTypeList.Add(FunctionType.RGB);
+                functionTypeList.Add(FunctionType.RGBW);
+                functionTypeList.Add(FunctionType.CCT);
+            }
+            else if (deviceType == Language.StringByID(StringId.Curtain))
+            {
+                functionTypeList.Add(FunctionType.Curtain);
+                functionTypeList.Add(FunctionType.RollerCurtain);
+                functionTypeList.Add(FunctionType.TrietexCurtain);
+            }
+            else if (deviceType == Language.StringByID(StringId.AC))
+            {
+                functionTypeList.Add(FunctionType.AC);
+            }
+            else if (deviceType == Language.StringByID(StringId.FloorHeating))
+            {
+                functionTypeList.Add(FunctionType.FloorHeating);
+            }
+            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);
+                        deviceTypeList.Add(FunctionType.RGB);
+                        deviceTypeList.Add(FunctionType.RGBW);
+                        deviceTypeList.Add(FunctionType.Dimmer);
+                        deviceTypeList.Add(FunctionType.CCT);
+                        deviceTypeList.Add(FunctionType.Curtain);
+                        deviceTypeList.Add(FunctionType.RollerCurtain);
+                        deviceTypeList.Add(FunctionType.TrietexCurtain);
+                        deviceTypeList.Add(FunctionType.AC);
+                        deviceTypeList.Add(FunctionType.FloorHeating);
+                    }
+                    break;
+                case target_if:
+                    {
+                        deviceTypeList.Add(FunctionType.Relay);
+                        deviceTypeList.Add(FunctionType.RGB);
+                        deviceTypeList.Add(FunctionType.RGBW);
+                        deviceTypeList.Add(FunctionType.Dimmer);
+                        deviceTypeList.Add(FunctionType.CCT);
+                        deviceTypeList.Add(FunctionType.Curtain);
+                        deviceTypeList.Add(FunctionType.RollerCurtain);
+                        deviceTypeList.Add(FunctionType.TrietexCurtain);
+                        deviceTypeList.Add(FunctionType.AC);
+                        deviceTypeList.Add(FunctionType.FloorHeating);
+                    }
+                    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