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

---
 HDL_ON/UI/UI2/3-Intelligence/Automation/MainView.cs |  287 +++++++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 276 insertions(+), 11 deletions(-)

diff --git a/HDL_ON/UI/UI2/3-Intelligence/Automation/MainView.cs b/HDL_ON/UI/UI2/3-Intelligence/Automation/MainView.cs
index ecfd441..e5a83d5 100644
--- a/HDL_ON/UI/UI2/3-Intelligence/Automation/MainView.cs
+++ b/HDL_ON/UI/UI2/3-Intelligence/Automation/MainView.cs
@@ -2,6 +2,8 @@
 using HDL_ON.UI.UI2.Intelligence.Automation.LogicView;
 using Shared;
 using System.Collections.Generic;
+using Newtonsoft.Json.Linq;
+
 namespace HDL_ON.UI.UI2.Intelligence.Automation
 {
     public class MainView
@@ -16,9 +18,23 @@
         public static void MainShow()
         {
             automationPage.RemoveAll();
-            VerticalScrolViewLayout vv = new VerticalScrolViewLayout();
+            VerticalRefreshLayout vv = new VerticalRefreshLayout();
+            vv.Height = Application.GetRealHeight(667 - 64 - 49);//妯℃嫙楂樺害
             automationPage.AddChidren(vv);
-
+            vv.BeginHeaderRefreshingAction += () =>
+            {
+                //娓呴櫎涔嬪墠鑷姩鍖栧垪琛�;
+                Logic.LogicList.Clear();
+                //鑾峰彇鑷姩鍒楄〃
+                GetLogicList();
+                //鍒锋柊鑷姩鍖栫晫闈�
+                MainShow();
+                //鍏抽棴鍒锋柊View锛�
+                vv.EndHeaderRefreshing();
+            };
+            //鑾峰彇鑷姩鍖栧垪琛�
+            GetLogicList();
+            // for (int i = Logic.LogicList.Count-1; i >= 0; i--)闄嶅簭鎺掑垪
             for (int i = 0; i < Logic.LogicList.Count; i++)
             {
                 var currLogic = Logic.LogicList[i];
@@ -42,12 +58,25 @@
                     if (logicView.btnSwitchIcon.IsSelected)
                     {
                         logicView.btnSwitchIcon.IsSelected = true;
+                        currLogic.enable = "true";
+
+
                     }
                     else
                     {
                         logicView.btnSwitchIcon.IsSelected = false;
+                        currLogic.enable = "false";
                     }
+                    Send.switchLogic(currLogic);
+
                 };
+                GetSelectIcon(logicView.frameLayout, currLogic);
+                //if (i==0)闄嶅簭鎺掑垪
+                if (Logic.LogicList.Count - 1 == i)
+                {
+                    ///鏈�鍚庝竴涓窛绂绘渶搴曢儴12,鐣岄潰鏄剧ず鏁堟灉浣滅敤;
+                    vv.AddChidren(new FrameLayout { Height = Application.GetRealHeight(12) });
+                }
                 if (currLogic.enable == "true")
                 {
                     logicView.btnSwitchIcon.IsSelected = true;
@@ -73,7 +102,7 @@
                 {
                     Y = btnTipNot.Bottom,
                     Height = Application.GetRealWidth(100),
-                    TextID = StringId.TipNotOpen,
+                    TextID = StringId.ContentIsEmpty,
                     TextAlignment = TextAlignment.Center,
                     TextColor = CSS.CSS_Color.TextualColor,
                     TextSize = CSS.CSS_FontSize.PromptFontSize_FirstLevel,
@@ -136,32 +165,31 @@
         public static string GetWeekString(List<string> weekList)
         {
             string weekTextName = "";
-
-            if (weekList.Contains("0"))
+            if (weekList.Contains("1"))
             {
                 weekTextName += Language.StringByID(StringId.monday) + ",";
             }
-            if (weekList.Contains("1"))
+            if (weekList.Contains("2"))
             {
                 weekTextName += Language.StringByID(StringId.tuesday) + ",";
             }
-            if (weekList.Contains("2"))
+            if (weekList.Contains("3"))
             {
                 weekTextName += Language.StringByID(StringId.wednesday) + ",";
             }
-            if (weekList.Contains("3"))
+            if (weekList.Contains("4"))
             {
                 weekTextName += Language.StringByID(StringId.thursday) + ",";
             }
-            if (weekList.Contains("4"))
+            if (weekList.Contains("5"))
             {
                 weekTextName += Language.StringByID(StringId.friday) + ",";
             }
-            if (weekList.Contains("5"))
+            if (weekList.Contains("6"))
             {
                 weekTextName += Language.StringByID(StringId.saturday) + ",";
             }
-            if (weekList.Contains("6"))
+            if (weekList.Contains("0"))
             {
                 weekTextName += Language.StringByID(StringId.sunday) + ",";
             }
@@ -171,6 +199,8 @@
             }
             return weekTextName.TrimEnd(',');
         }
+
+
         /// <summary>
         /// 鑾峰彇姣忔湀鐨勫瓧绗︿覆
         /// </summary>
@@ -189,5 +219,240 @@
             }
             return monTextName.TrimEnd(',');
         }
+        /// <summary>
+        /// 鑾峰彇閫昏緫鍒楄〃
+        /// </summary>
+        private static void GetLogicList()
+        {
+
+            if (Logic.LogicList.Count != 0)
+            {
+                //鑷姩鍖栧垪琛ㄤ负0鎵嶅幓鑾峰彇鑷姩鍖栧垪琛紱
+                return;
+            }
+            List<string> logicIdList = new List<string>();
+            //鑾峰彇閫昏緫ID鍒楄〃
+            var idStr = Send.getLogicIdList();
+            if (idStr.Code == "0" && idStr.Data != null && idStr.Data.ToString() != "")
+            {
+                var date = Newtonsoft.Json.JsonConvert.SerializeObject(idStr.Data);
+                var dateList = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Date>>(date);
+                for (int i = 0; i < dateList.Count; i++)
+                {
+                    //娣诲姞閫昏緫ID
+                    logicIdList.Add(dateList[i].userLogicId);
+                }
+            }
+            //鑾峰彇鑷姩鍖栧垪琛�
+            var logicStr = Send.getLogic(logicIdList);
+            if (logicStr.Code == "0" && logicStr.Data != null && logicStr.Data.ToString() != "")
+            {
+                //鑾峰彇閫昏緫璇︾粏杩斿洖鏄竴涓暟缁�(object绫诲瀷杞崲涓烘暟缁�);
+                var jArray = JArray.Parse(logicStr.Data.ToString());
+                for (int a = 0; a < jArray.Count; a++)
+                {
+                    var jay = jArray[a];
+                    //鏁版嵁杩斿簭鍒楀寲涓篖ogic瀵硅薄
+                    var str = Newtonsoft.Json.JsonConvert.SerializeObject(jay);
+                    var logic = Newtonsoft.Json.JsonConvert.DeserializeObject<Logic>(str);
+                    if (logic != null)
+                    {
+                        //鏌ユ壘鏄惁宸茬粡瀛樺湪璇ラ�昏緫
+                        var if_logic = Logic.LogicList.Find((c) => c.userLogicId == logic.userLogicId);
+                        if (if_logic == null)
+                        {
+                            //娣诲姞閫昏緫
+                            Logic.LogicList.Add(logic);
+                        }
+                    }
+
+                }
+            }
+
+        }
+        /// <summary>
+        /// 鍒ゆ柇JObject瀵硅薄鏄瓨鍦ㄥ仴鍊�
+        /// </summary>
+        /// <param name="jObject"></param>
+        /// <param name="key"></param>
+        /// <returns></returns>
+        private bool Exist(JObject jObject, string key)
+        {
+
+            if (jObject.Property(key) != null)
+            {
+                return true;
+            }
+            return false;
+        }
+
+        /// <summary>
+        /// 鏄剧ず鏉′欢鎴栬�呯洰鏍囩被鍨嬪浘鏍�
+        /// </summary>
+        /// <param name="layouFrame">鐖舵帶浠�</param>
+        /// <param name="logic">褰撳墠閫昏緫</param>
+        private static void GetSelectIcon(FrameLayout layouFrame, Logic logic)
+        {
+
+            //閲嶆柊鎺掑垪鍥炬爣搴忓彿
+            List<int> iconIntValue = new List<int>();
+            iconIntValue.Clear();
+
+            //1-10(琛ㄧず鏉′欢鍥炬爣)鑷繁灞�閮ㄥ畾涔変负浜嗘樉绀洪�変腑鏉′欢绫诲瀷鍥炬爣
+            //1-鏃堕棿鍥炬爣
+            //2-鍔熻兘鍥炬爣
+            for (int i = 0; i < logic.input.Count; i++)
+            {
+
+                var int1 = int.Parse(logic.input[i].condition_type);
+                int iconInt = 0;
+                switch (int1)
+                {
+                    case 1:
+                    case 2:
+                        {
+                            iconInt = 1;
+
+                        }
+                        break;
+                    case 3:
+                        {
+                            iconInt = 2;
+
+                        }
+                        break;
+                }
+
+                if (!iconIntValue.Contains(iconInt))
+                {
+                    iconIntValue.Add(iconInt);
+                }
+
+            }
+
+            //鍒嗗壊鏉′欢鍜岀洰鏍囩殑鍥炬爣
+            iconIntValue.Add(11);
+
+            //12-20(琛ㄧず鐩爣鍥炬爣)鑷繁灞�閮ㄥ畾涔変负浜嗘樉绀洪�変腑鐩爣绫诲瀷鍥炬爣
+            //12-鍔熻兘鍥炬爣
+            //13-鍦烘櫙鍥炬爣
+            //14-寤舵椂鍥炬爣
+            for (int i = 0; i < logic.output.Count; i++)
+            {
+                var int1 = int.Parse(logic.output[i].target_type);
+                int iconInt = 0;
+                switch (int1)
+                {
+                    case 1:
+                        {
+                            iconInt = 12;
+
+                        }
+                        break;
+                    case 2:
+                        {
+                            iconInt = 13;
+
+                        }
+                        break;
+                    case 3:
+                        {
+                            iconInt = 14;
+
+                        }
+                        break;
+                }
+
+                if (!iconIntValue.Contains(iconInt))
+                {
+                    iconIntValue.Add(iconInt);
+                }
+            }
+            //鍥炬爣鎺т欢鐨勭埗鎺т欢
+            FrameLayout frame = new FrameLayout {
+                Height=Application.GetRealHeight(40),
+                Width=Application.GetRealWidth(275),
+                Y= Application.GetRealHeight(56),
+            };
+            layouFrame.AddChidren(frame);
+
+
+            for (int i = 0; i < iconIntValue.Count; i++)
+            {
+                //鍥炬爣鎺т欢
+                Button btnIcon = new Button
+                {
+                    Width = Application.GetRealWidth(28),
+                    Height = Application.GetRealWidth(28),
+                    Gravity=Gravity.CenterVertical,
+                };
+                frame.AddChidren(btnIcon);
+
+                if (i == 0)
+                {
+                    btnIcon.X = Application.GetRealWidth(12);
+                }
+                else
+                {
+                    btnIcon.X = Application.GetRealWidth(12+(28+4)*i);
+                }
+                string strIcon = "";
+                switch (iconIntValue[i]) {
+                  
+                    case 1: {
+                            strIcon = "LogicIcon/selectTheTime.png";
+                        }
+                        break;
+                    case 2:
+                        {
+
+                            strIcon = "LogicIcon/selectTheFun.png";
+                        }
+                        break;
+                    case 11:
+                        {
+                            //鍒嗗壊鏉′欢鍜岀洰鏍囩殑鍥炬爣
+                            strIcon = "LogicIcon/link.png";
+                        } break;
+                    case 12:
+                        {
+
+                            strIcon = "LogicIcon/selectTheFun.png";
+                        }
+                        break;
+                    case 13: {
+                            strIcon = "LogicIcon/selectTheScene.png";
+                        } break;
+                    case 14: {
+                            //strIcon = "LogicIcon/timeicon.png";
+                        }
+                        break;
+
+                }
+                btnIcon.UnSelectedImagePath = strIcon;
+            }
+        }
+    }
+    class Date
+    {
+        /// <summary>
+        /// 浜戠鍞竴id
+        /// </summary>
+        public string userLogicId = "";
+        public string gatewayId = "";
+        /// <summary>
+        /// 閫昏緫鍞竴鏍囪瘑
+        /// </summary>
+        public string sid = "";
+        public string name = "";
+        public string enable = "";
+        //public CycleA cycle;
+        //public string modifyTime = "";
+    }
+
+    class CycleA
+    {
+        public string type = "";
+        public string[] value;
     }
 }

--
Gitblit v1.8.0