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/DeviceFunList.cs |  545 +++++++++++++++++++++++++++++++++++++++++------------
 1 files changed, 418 insertions(+), 127 deletions(-)

diff --git a/HDL_ON/UI/UI2/3-Intelligence/Automation/DeviceFunList.cs b/HDL_ON/UI/UI2/3-Intelligence/Automation/DeviceFunList.cs
index cb35527..f4b2557 100644
--- a/HDL_ON/UI/UI2/3-Intelligence/Automation/DeviceFunList.cs
+++ b/HDL_ON/UI/UI2/3-Intelligence/Automation/DeviceFunList.cs
@@ -9,9 +9,25 @@
         {
             Tag = "Logic";
         }
-
-        public void Show(Entity.Function device, int index, bool edit)
+        /// <summary>
+        /// 琛ㄧず鏄�(鏉′欢/鐩爣)
+        /// </summary>
+        private string if_type;
+        /// <summary>
+        /// 瀹氫箟涓�涓褰曢�変腑璁惧鐘舵�佸垪琛紱
+        /// </summary>
+        private List<Dictionary<string, string>> dicSateteList = new List<Dictionary<string, string>>();
+        /// <summary>
+        /// 瀹氫箟涓�涓彉閲忥紝璁板綍閫変腑鐘舵��
+        /// </summary>
+        private string selectedState = "unknown";
+        /// <summary>
+        /// 瀹氫箟涓�涓彉閲忥紝璁板綍閫変腑鐘舵�佽褰曞睘鎬�
+        /// </summary>
+        private string keyVlaue = "";
+        public void Show(Entity.Function device, int index, bool edit, string str)
         {
+            if_type = str;
             #region 鐣岄潰甯冨眬
             this.BackgroundColor = CSS.CSS_Color.viewMiddle;
             LogicView.TopView topView = new LogicView.TopView();
@@ -29,124 +45,143 @@
             };
             this.AddChidren(fLayout);
             #endregion
-
-            //瀹氫箟涓�涓彉閲忥紝璁板綍閫変腑鐘舵��
-            string selectedState = "unknown";
-
-            Input inputdevice = new Input();
-            inputdevice.condition_type = "3";
-            inputdevice.sid = device.sid;
-
-
             switch (device.functionType)
             {
-                //寮�鍏崇伅鍏�
-                case FunctionType.Relay:
+                //寮�鍏崇伅鍏� light.Switch
+                case FunctionType.Dimmer:
                     {
-                        
-
-
-                        //for (int i = 0; i < device.function.Count; i++)
-                        //{
-                        //}
-                        LogicView.SelectTypeView relayView = new LogicView.SelectTypeView();
-                        relayView.btnIcon.Visible = false;
-                        relayView.btnState.Visible = true;
-                        relayView.btnText.TextSize = LogicView.TextSize.text16;
-                        relayView.btnText.Height = Application.GetRealHeight(22);
-                        relayView.btnText.TextID = StringId.switchLogic;
-                        relayView.btnText.X = Application.GetRealWidth(16);
-                        relayView.btnText.Width = Application.GetRealWidth(130);
-                        relayView.btnLine.X = Application.GetRealWidth(16);
-                        relayView.btnLine.Width = Application.GetRealWidth(343);
-                        fLayout.AddChidren(relayView.FLayoutView());
-                        relayView.btnClick.MouseUpEventHandler += (sender, e) =>
+                        LogicView.FunTypeView lightSwitchView = new LogicView.FunTypeView();
+                        lightSwitchView.btnText.TextID = StringId.switchLogic;
+                        lightSwitchView.btnState.Text = "";
+                        fLayout.AddChidren(lightSwitchView.FLayoutView());
+                        lightSwitchView.btnClick.MouseUpEventHandler += (sender, e) =>
                         {
-                            FrameLayout relayFunView = new FrameLayout
+                            FrameLayout frame = new FrameLayout
                             {
                                 BackgroundColor = CSS.CSS_Color.viewTrans60lucence,
                             };
-                            this.AddChidren(relayFunView);
-                            LogicView.SwitchView switchView = new LogicView.SwitchView();
-                            switchView.FLayoutView(relayFunView, 2);
-
-                            Button btnOn = new Button
-                            {
-                                TextAlignment = TextAlignment.Center,
-                                TextSize = LogicView.TextSize.text16,
-                                TextColor = CSS.CSS_Color.textCancelColor,
-                                TextID = StringId.onLogic,
-                                Height = Application.GetRealHeight(44),
-                                Width = Application.GetRealWidth(343),
-                            };
-                            switchView.frameLayout.AddChidren(btnOn);
-                            Button btnLine = new Button
-                            {
-                                Height = 1,
-                                BackgroundColor = CSS.CSS_Color.viewLine,
-                                Y = btnOn.Bottom,
-                            };
-                            switchView.frameLayout.AddChidren(btnLine);
-                            Button btnOff = new Button
-                            {
-                                Y = btnLine.Bottom,
-                                TextAlignment = TextAlignment.Center,
-                                TextSize = LogicView.TextSize.text16,
-                                TextColor = CSS.CSS_Color.textCancelColor,
-                                TextID = StringId.offLogic,
-                                Height = Application.GetRealHeight(44),
-                                Width = Application.GetRealWidth(343),
-                            };
-                            switchView.frameLayout.AddChidren(btnOff);
-
-                            Dictionary<string, string> dic = new Dictionary<string, string>();
-                            LogicMethod.dictionary(dic, "key", "on_off");
-                            LogicMethod.dictionary(dic, "comparator", "=");
-                            LogicMethod.dictionary(dic, "data_type", "string");
-                            inputdevice.condition.Add(dic);
-                            btnOn.MouseUpEventHandler += (sender2, e2) =>
-                            {
-                                LogicMethod.dictionary(dic, "value", "on");
-                                RemView(relayFunView);
-                                relayView.btnState.TextID = StringId.onLogic;
-                                selectedState = device.functionType + "_on";
-                            };
-                            btnOff.MouseUpEventHandler += (sender3, e3) =>
-                            {
-                                LogicMethod.dictionary(dic, "value", "off");
-                                RemView(relayFunView);
-                                relayView.btnState.TextID = StringId.offLogic;
-                                selectedState = device.functionType + "_off";
-                            };
-
+                            this.AddChidren(frame);
+                            SwitchViewMethod(frame, device, lightSwitchView.btnState,2);
                         };
                         if (edit)
                         {
-                            Input inputs = Logic.currlogic.input[index];
-                            if (inputs.condition_type == "3")
-                            {
-                                List<Dictionary<string, string>> dicList = inputs.condition as List<Dictionary<string, string>>;
-                                foreach (var dic in dicList)
-                                {
-                                    string value = dic["value"];
-                                    if (value == "on")
-                                    {
-                                        relayView.btnState.Text = Language.StringByID(StringId.onLogic);
-
-                                    }
-                                    else
-                                    {
-                                        relayView.btnState.Text = Language.StringByID(StringId.offLogic);
-                                    }
-                                }
-                            }
+                            GetEditState(device, edit, index, lightSwitchView.btnState, null, null, null);
                         }
 
                     }
                     break;
+                case FunctionType.RGB:
+                    {
+                        LogicView.FunTypeView lightSwitchView = new LogicView.FunTypeView();
+                        lightSwitchView.btnText.TextID = StringId.switchLogic;
+                        lightSwitchView.btnState.Text = "";
+                        fLayout.AddChidren(lightSwitchView.FLayoutView());
+                        lightSwitchView.btnClick.MouseUpEventHandler += (sender, e) =>
+                        {
+                            FrameLayout frame = new FrameLayout
+                            {
+                                BackgroundColor = CSS.CSS_Color.viewTrans60lucence,
+                            };
+                            this.AddChidren(frame);
+                            SwitchViewMethod(frame, device, lightSwitchView.btnState, 2);
+                        };
+                        if (edit)
+                        {
+                            GetEditState(device, edit, index, lightSwitchView.btnState, null, null, null);
+                        }
 
+                    }
+                    break;
+                case FunctionType.RGBW:
+                    {
+                        LogicView.FunTypeView lightSwitchView = new LogicView.FunTypeView();
+                        lightSwitchView.btnText.TextID = StringId.switchLogic;
+                        lightSwitchView.btnState.Text = "";
+                        fLayout.AddChidren(lightSwitchView.FLayoutView());
+                        lightSwitchView.btnClick.MouseUpEventHandler += (sender, e) =>
+                        {
+                            FrameLayout frame = new FrameLayout
+                            {
+                                BackgroundColor = CSS.CSS_Color.viewTrans60lucence,
+                            };
+                            this.AddChidren(frame);
+                            SwitchViewMethod(frame, device, lightSwitchView.btnState, 2);
+                        };
+                        if (edit)
+                        {
+                            GetEditState(device, edit, index, lightSwitchView.btnState, null, null, null);
+                        }
+
+                    }
+                    break;
+                case FunctionType.CCT:
+                    {
+                        LogicView.FunTypeView lightSwitchView = new LogicView.FunTypeView();
+                        lightSwitchView.btnText.TextID = StringId.switchLogic;
+                        lightSwitchView.btnState.Text = "";
+                        fLayout.AddChidren(lightSwitchView.FLayoutView());
+                        lightSwitchView.btnClick.MouseUpEventHandler += (sender, e) =>
+                        {
+                            FrameLayout frame = new FrameLayout
+                            {
+                                BackgroundColor = CSS.CSS_Color.viewTrans60lucence,
+                            };
+                            this.AddChidren(frame);
+                            SwitchViewMethod(frame, device, lightSwitchView.btnState, 2);
+                        };
+                        if (edit)
+                        {
+                            GetEditState(device, edit, index, lightSwitchView.btnState, null, null, null);
+                        }
+
+                    }
+                    break;
+                case FunctionType.Relay:
+                    {
+                        LogicView.FunTypeView lightSwitchView = new LogicView.FunTypeView();
+                        lightSwitchView.btnText.TextID = StringId.switchLogic;
+                        lightSwitchView.btnState.Text = "";
+                        fLayout.AddChidren(lightSwitchView.FLayoutView());
+                        lightSwitchView.btnClick.MouseUpEventHandler += (sender, e) =>
+                        {
+                            FrameLayout frame = new FrameLayout
+                            {
+                                BackgroundColor = CSS.CSS_Color.viewTrans60lucence,
+                            };
+                            this.AddChidren(frame);
+                            SwitchViewMethod(frame, device, lightSwitchView.btnState, 2);
+                        };
+                        if (edit)
+                        {
+                            GetEditState(device, edit, index, lightSwitchView.btnState, null, null, null);
+                        }
+
+                    }
+                    break;
+                //绐楀笜
+                case FunctionType.Curtain:
+                    {
+                        LogicView.FunTypeView lightSwitchView = new LogicView.FunTypeView();
+                        lightSwitchView.btnText.TextID = StringId.switchLogic;
+                        lightSwitchView.btnState.Text = "";
+                        fLayout.AddChidren(lightSwitchView.FLayoutView());
+                        lightSwitchView.btnClick.MouseUpEventHandler += (sender, e) =>
+                        {
+                            FrameLayout frame = new FrameLayout
+                            {
+                                BackgroundColor = CSS.CSS_Color.viewTrans60lucence,
+                            };
+                            this.AddChidren(frame);
+                            SwitchViewMethod(frame, device, lightSwitchView.btnState, 2);
+                        };
+                        if (edit)
+                        {
+                            GetEditState(device, edit, index, lightSwitchView.btnState, null, null, null);
+                        }
+
+                    }
+                    break;
             }
-
 
 
             #region  淇濆瓨
@@ -157,19 +192,50 @@
             this.AddChidren(saveView.FLayoutView());
             saveView.btnClick.MouseUpEventHandler += (sen, e) =>
             {
+
+
                 if (selectedState != "unknown")
                 {
-                    if (edit)
+                    if (if_type == LogicMethod.condition_if)
                     {
-                        //绉婚櫎鏃ф暟鎹�
-                        Logic.currlogic.input.RemoveAt(index);
-                        //鏂版暟鎹彃鍏ユ棫鏁版嵁鐨勪綅缃�;
-                        Logic.currlogic.input.Insert(index, inputdevice);
+
+                        Input inputDevice = new Input(); 
+                        inputDevice.condition_type = "3";
+                        inputDevice.sid = device.sid;
+                        inputDevice.condition = dicSateteList;
+
+
+                        if (edit)
+                        {
+                            //绉婚櫎鏃ф暟鎹�
+                            Logic.currlogic.input.RemoveAt(index);
+                            //鏂版暟鎹彃鍏ユ棫鏁版嵁鐨勪綅缃�;
+                            Logic.currlogic.input.Insert(index, inputDevice);
+                        }
+                        else
+                        {
+                            //娣诲姞涓�涓潯浠�
+                            AddCondition(inputDevice);
+                        }
                     }
                     else
                     {
-                        //娣诲姞涓�涓柊鐨勬椂闂寸偣鏉′欢
-                        Logic.currlogic.input.Add(inputdevice);
+                        Output outputDevice = new Output();
+                        outputDevice.target_type = "1";
+                        outputDevice.sid = device.sid;
+                        outputDevice.status = dicSateteList;
+                        if (edit)
+                        {
+                            //绉婚櫎鏃ф暟鎹�
+                            Logic.currlogic.output.RemoveAt(index);
+                            //鏂版暟鎹彃鍏ユ棫鏁版嵁鐨勪綅缃�;
+                            Logic.currlogic.output.Insert(index, outputDevice);
+                        }
+                        else
+                        {
+                            //娣诲姞涓�涓潯浠�
+                            AddTarget(outputDevice);
+                        }
                     }
                 }
                 else
@@ -182,7 +248,7 @@
                     this.RemoveFromParent();
                     return;
                 }
-                RemoveViewByTag("Logic");
+                LogicMethod.RemoveAllView();
                 AddLogic addLogic = new AddLogic();
                 MainPage.BasePageView.AddChidren(addLogic);
                 addLogic.Show();
@@ -196,17 +262,39 @@
         /// 绉婚櫎鎺т欢
         /// </summary>
         /// <param name="frame"></param>
-        public void RemView(FrameLayout frame)
+        private void RemView(FrameLayout frame)
         {
             frame.RemoveFromParent();
         }
-
-        public void GetState(Entity.Function device, bool edit, int index,Button button1,Button button2,Button button3,Button button4)
+        /// <summary>
+        /// 鏄剧ず缂栬緫涔嬪墠鐨勮澶囩姸鎬�
+        /// </summary>
+        /// <param name="device">缂栬緫璁惧</param>
+        /// <param name="edit">缂栬緫鐘舵��</param>
+        /// <param name="index">缂栬緫鏁版嵁鐨勭储寮�</param>
+        /// <param name="button1">鏄剧ずBtn</param>
+        /// <param name="button2">鏄剧ずBtn</param>
+        /// <param name="button3">鏄剧ずBtn</param>
+        /// <param name="button4">鏄剧ずBtn</param>
+        private void GetEditState(Entity.Function device, bool edit, int index, Button button1, Button button2, Button button3, Button button4)
         {
-            if (edit)
+            var dicList = new List<Dictionary<string, string>>();
+            switch (if_type)
             {
-                Input inputs = Logic.currlogic.input[index];
-                var dicList = inputs.condition as List<Dictionary<string, string>>;
+                case LogicMethod.condition_if:
+                    {
+                        Input inputs = Logic.currlogic.input[index];
+                        dicList = inputs.condition as List<Dictionary<string, string>>;
+                    }
+                    break;
+                case LogicMethod.target_if:
+                    {
+                        Output outputs = Logic.currlogic.output[index];
+                        dicList = outputs.status as List<Dictionary<string, string>>;
+                    }
+                    break;
+            }
+            if (if_type== LogicMethod.condition_if) {
                 switch (device.functionType)
                 {
                     //寮�鍏崇伅鍏�
@@ -215,20 +303,223 @@
                             foreach (var dic in dicList)
                             {
                                 string value = dic["value"];
-                                //if (value == "on")
-                                //{
-                                //    relayView.btnState.Text = Language.StringByID(StringId.onLogic);
-
-                                //}
-                                //else
-                                //{
-                                //    relayView.btnState.Text = Language.StringByID(StringId.offLogic);
-                                //}
+                                if (value == "on")
+                                {
+                                    button1.Text = Language.StringByID(StringId.onLogic);
+                                }
+                                else
+                                {
+                                    button1.Text = Language.StringByID(StringId.offLogic);
+                                }
                             }
                         }
                         break;
 
                 }
+
+            }
+            else if (if_type == LogicMethod.target_if)
+            {
+                switch (device.functionType)
+                {
+                    //寮�鍏崇伅鍏�
+                    case FunctionType.Relay:
+                        {
+                            foreach (var dic in dicList)
+                            {
+                                string value = dic["value"];
+                                if (value == "on")
+                                {
+                                    button1.Text = Language.StringByID(StringId.onLogic);
+                                }
+                                else
+                                {
+                                    button1.Text = Language.StringByID(StringId.offLogic);
+                                }
+                            }
+                        }
+                        break;
+
+                }
+
+            }
+
+        }
+        /// <summary>
+        /// 娣诲姞閫変腑鏁版嵁
+        /// </summary>
+        /// <param name="dicList">瀛樺偍鏁版嵁鍒楄〃</param>
+        /// <param name="keyValue">璇嗗埆璁惧</param> 
+        /// <param name="dictionary">閫変腑鏁版嵁</param>
+        /// <returns></returns>
+        private void AddDictionaryData(List<Dictionary<string, string>> dicList, string keyValue, Dictionary<string, string> dictionary)
+        {
+            int indexValue = -1;
+            for (int i = 0; i < dicList.Count; i++)
+            {
+                var dic = dicList[i];
+                if (dic.ContainsValue(keyValue)) 
+                {
+                    //鍒ゆ柇鏄惁瀛樺湪
+                    indexValue = i;
+                    break;
+                }
+            }
+
+            if (indexValue != -1)
+            {
+                //瀛樺湪绉婚櫎
+                dicList.RemoveAt(indexValue);
+                //閲嶆柊娣诲姞
+                dicList.Insert(indexValue, dictionary);
+            }
+            else
+            {
+                //鏂版坊鍔�
+                dicList.Add(dictionary);
+            }
+
+        }
+        /// <summary>
+        /// 娣诲姞鏉′欢
+        /// </summary>
+        /// <param name="input"></param>
+        private void AddCondition(Input input)
+        {
+            int indexValue = -1;
+            for (int i = 0; i < Logic.currlogic.input.Count; i++)
+            {
+                if (Logic.currlogic.input[i].sid == input.sid)
+                {
+                    indexValue = i;
+                    break;
+                }
+            }
+
+            if (indexValue != -1)
+            {
+                Logic.currlogic.input.RemoveAt(indexValue);
+                Logic.currlogic.input.Insert(indexValue, input);
+            }
+            else
+            {
+                Logic.currlogic.input.Add(input);
+            }
+
+        }
+        /// <summary>
+        /// 娣诲姞鐩爣
+        /// </summary>
+        /// <param name="target"></param>
+        private void AddTarget(Output target)
+        {
+            int indexValue = -1;
+            for (int i = 0; i < Logic.currlogic.output.Count; i++)
+            {
+                if (Logic.currlogic.output[i].sid == target.sid)
+                {
+                    indexValue = i;
+                    break;
+                }
+            }
+
+            if (indexValue != -1)
+            {
+                Logic.currlogic.output.RemoveAt(indexValue);
+                Logic.currlogic.output.Insert(indexValue, target);
+            }
+            else
+            {
+                Logic.currlogic.output.Add(target);
+            }
+
+        }
+        /// <summary>
+        /// 寮�鍏冲姛鑳藉睍寮�鐣岄潰
+        /// </summary>
+        /// <param name="frame"></param>
+        /// <param name="device"></param>
+        /// <param name="button"></param>
+        /// <param name="len"></param>
+        public void SwitchViewMethod(FrameLayout frame, Entity.Function device,Button button, int len) {
+
+            LogicView.SwitchView switchView = new LogicView.SwitchView();
+            switchView.FLayoutView(frame, len);
+
+            Button btnOn = new Button
+            {
+                TextAlignment = TextAlignment.Center,
+                TextSize = LogicView.TextSize.text16,
+                TextColor = CSS.CSS_Color.textCancelColor,
+                TextID = StringId.onLogic,
+                Height = Application.GetRealHeight(44),
+                Width = Application.GetRealWidth(343),
+
+            };
+            switchView.frameLayout.AddChidren(btnOn);
+            Button btnLine = new Button
+            {
+                Height = 1,
+                BackgroundColor = CSS.CSS_Color.viewLine,
+                Y = btnOn.Bottom,
+            };
+            switchView.frameLayout.AddChidren(btnLine);
+            Button btnOff = new Button
+            {
+                Y = btnLine.Bottom,
+                TextAlignment = TextAlignment.Center,
+                TextSize = LogicView.TextSize.text16,
+                TextColor = CSS.CSS_Color.textCancelColor,
+                TextID = StringId.offLogic,
+                Height = Application.GetRealHeight(44),
+                Width = Application.GetRealWidth(343),
+            };
+            switchView.frameLayout.AddChidren(btnOff);
+
+            Dictionary<string, string> dic = new Dictionary<string, string>();
+            switch (if_type)
+            {
+                case LogicMethod.condition_if:
+                    {
+                        LogicMethod.dictionary(dic, "key", "on_off");
+                        LogicMethod.dictionary(dic, "comparator", "=");
+                        LogicMethod.dictionary(dic, "data_type", "string");
+                        keyVlaue = "on_off";
+                    }
+                    break;
+                case LogicMethod.target_if:
+                    {
+                        LogicMethod.dictionary(dic, "key", "on_off");
+                        keyVlaue = "on_off";
+                    }
+                    break;
+            }
+            btnOn.MouseUpEventHandler += (sender2, e2) =>
+            {
+                LogicMethod.dictionary(dic, "value", "on");
+                RemView(frame);
+                button.TextID = StringId.onLogic;
+                selectedState = device.functionType + "_on";
+                AddDictionaryData(dicSateteList, keyVlaue, dic);
+            };
+            btnOff.MouseUpEventHandler += (sender3, e3) =>
+            {
+                LogicMethod.dictionary(dic, "value", "off");
+                RemView(frame);
+                button.TextID = StringId.offLogic;
+                selectedState = device.functionType + "_off";
+                AddDictionaryData(dicSateteList, keyVlaue, dic);
+            };
+            if (button.Text != "")
+            {
+                if (button.Text == btnOn.Text)
+                {
+                    btnOn.TextColor = CSS.CSS_Color.textConfirmColor;
+                }
+                else
+                {
+                    btnOff.TextColor = CSS.CSS_Color.textConfirmColor;
+                }
             }
         }
     }

--
Gitblit v1.8.0