From 6ba43603ccd8868a4ee73e9b978b7cb20a5b2c52 Mon Sep 17 00:00:00 2001
From: wei <kaede@kaededeMacBook-Air.local>
Date: 星期五, 04 十二月 2020 14:24:53 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/WJC'

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

diff --git a/HDL_ON/UI/UI2/3-Intelligence/Automation/TargetDeviceFunList.cs b/HDL_ON/UI/UI2/3-Intelligence/Automation/TargetDeviceFunList.cs
new file mode 100644
index 0000000..c706c8c
--- /dev/null
+++ b/HDL_ON/UI/UI2/3-Intelligence/Automation/TargetDeviceFunList.cs
@@ -0,0 +1,579 @@
+锘縰sing System;
+using Shared;
+using System.Collections.Generic;
+namespace HDL_ON.UI.UI2.Intelligence.Automation
+{
+    public class TargetDeviceFunList : FrameLayout
+    {
+        public TargetDeviceFunList()
+        {
+            Tag = "Logic";
+        }
+        /// <summary>
+        /// 瀹氫箟涓�涓褰曢�変腑璁惧鐘舵�佸垪琛紱
+        /// </summary>
+        private List<Dictionary<string, string>> dicSateteList = new List<Dictionary<string, string>>();
+        /// <summary>
+        /// 瀹氫箟涓�涓彉閲忥紝璁板綍閫変腑鐘舵��
+        /// </summary>
+        private string selectedState = "unknown";
+        public void Show(Entity.Function device, int index, bool edit)
+        {
+            #region 鐣岄潰甯冨眬
+            this.BackgroundColor = CSS.CSS_Color.viewMiddle;
+            LogicView.TopView topView = new LogicView.TopView();
+            this.AddChidren(topView.FLayoutView());
+            topView.clickBackBtn.MouseUpEventHandler += (e, sen) =>
+            {
+                RemoveFromParent();
+            };
+            topView.topNameBtn.Text = device.name;
+
+            FrameLayout fLayout = new FrameLayout
+            {
+                Y = Application.GetRealHeight(64),
+                Height = Application.GetRealHeight(667 - 64),
+            };
+            this.AddChidren(fLayout);
+
+            ///淇濆瓨View
+            LogicView.SaveView saveView = new LogicView.SaveView();
+            saveView.frameLayout.SetCornerWithSameRadius(Application.GetRealHeight(24), HDLUtils.RectCornerTopLeft | HDLUtils.RectCornerTopRight);
+            saveView.btnSave.TextID = StringId.completeLogic;
+            this.AddChidren(saveView.FLayoutView());
+            #endregion
+            #region  缂栬緫璁惧鐘舵��
+            switch (device.functionType)
+            {
+                //寮�鍏崇伅鍏� light.Switch
+                case FunctionType.Dimmer:
+                case FunctionType.RGB:
+                case FunctionType.RGBW:
+                case FunctionType.CCT:
+                    {
+                        //2琛ㄧず(寮�锛屽叧)鍔熻兘
+                        SwitchBrightnessView(fLayout, device, index, edit,2);
+                    }
+                    break;
+                case FunctionType.Relay:
+                    {
+                        //2琛ㄧず(寮�锛屽叧)鍔熻兘
+                        SwitchView(fLayout, device, index, edit, 2);
+                    }
+                    break;
+                //绐楀笜
+                case FunctionType.Curtain:
+                    {
+                        //3琛ㄧず(寮�锛屽叧锛屾殏鍋�)鍔熻兘
+                        SwitchView(fLayout, device, index, edit, 3);
+                    }
+                    break;
+                case FunctionType.TrietexCurtain:
+                case FunctionType.RollerCurtain:
+                    {
+                        //3琛ㄧず(寮�锛屽叧锛屾殏鍋�)鍔熻兘
+                        SwitchBrightnessView(fLayout, device, index, edit, 3);
+                    }
+                    break;
+                case FunctionType.AC: {
+                        #region 鐣岄潰
+                        ///寮�鍏�
+                        LogicView.FunTypeView curtainSwitchView = new LogicView.FunTypeView();
+                        curtainSwitchView.btnText.TextID = StringId.switchLogic;
+                        fLayout.AddChidren(curtainSwitchView.FLayoutView());
+                        #endregion
+                        #region 鐐瑰嚮浜嬩欢
+                        ///寮�鍏崇偣鍑讳簨浠�
+                        curtainSwitchView.btnClick.MouseUpEventHandler += (sender, e) =>
+                        {
+                            SwitchViewMethod(device, curtainSwitchView.btnState, 2);
+                        };
+                        if (edit)
+                        {
+                            GetEditState(device, index, curtainSwitchView.btnState, null, null, null);
+                        }
+                        #endregion
+                    }
+                    break;
+
+            }
+            #endregion
+            #region  淇濆瓨鐐瑰嚮鏃堕棿
+            saveView.btnClick.MouseUpEventHandler += (sen, e) =>
+            {
+
+
+                if (selectedState != "unknown")
+                {
+                    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
+                {
+                    if (!edit)
+                    {
+                        //鎻愮ず鐢ㄦ埛
+                        return;
+                    }
+                    this.RemoveFromParent();
+                    return;
+                }
+                LogicMethod.RemoveAllView();
+                AddLogic addLogic = new AddLogic();
+                MainPage.BasePageView.AddChidren(addLogic);
+                addLogic.Show();
+                MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
+            };
+            #endregion
+
+        }
+        /// <summary>
+        ///寮�鍏�=鐣岄潰
+        /// </summary>
+        /// <param name="fLayout"></param>
+        /// <param name="device"></param>
+        /// <param name="index"></param>
+        /// <param name="edit"></param>
+        /// <param name="intView">閫変腑View鐨勬暟閲�</param>
+        private void SwitchView(FrameLayout fLayout, Entity.Function device, int index, bool edit,int intView)
+        {
+            #region 鐣岄潰
+            ///寮�鍏�
+            LogicView.FunTypeView curtainSwitchView = new LogicView.FunTypeView();
+            curtainSwitchView.btnText.TextID = StringId.switchLogic;
+            fLayout.AddChidren(curtainSwitchView.FLayoutView());
+            #endregion
+            #region 鐐瑰嚮浜嬩欢
+            ///寮�鍏崇偣鍑讳簨浠�
+            curtainSwitchView.btnClick.MouseUpEventHandler += (sender, e) =>
+            {
+                SwitchViewMethod(device, curtainSwitchView.btnState, intView);
+            };
+            if (edit)
+            {
+                GetEditState(device, index, curtainSwitchView.btnState, null, null, null);
+            }
+            #endregion
+
+        }
+        /// <summary>
+        ///锛堝紑鍏�+浜害/鐧惧垎姣�)鐣岄潰
+        /// </summary>
+        /// <param name="fLayout"></param>
+        /// <param name="device"></param>
+        /// <param name="index"></param>
+        /// <param name="edit"></param>
+        /// <param name="intView">閫変腑View鐨勬暟閲�</param>
+        private void SwitchBrightnessView(FrameLayout fLayout, Entity.Function device, int index, bool edit,int intView)
+        {
+            #region 鐣岄潰
+            ///寮�鍏�
+            LogicView.FunTypeView lightSwitchView = new LogicView.FunTypeView();
+            lightSwitchView.btnText.TextID = StringId.switchLogic;
+            fLayout.AddChidren(lightSwitchView.FLayoutView());
+            ///浜害
+            LogicView.FunTypeView brightnessView = new LogicView.FunTypeView();
+            brightnessView.frameLayout.Y = lightSwitchView.frameLayout.Bottom;
+            if (device.functionType == FunctionType.TrietexCurtain || device.functionType == FunctionType.RollerCurtain)
+            {
+                
+                brightnessView.btnText.TextID = StringId.percentum;
+            }
+            else
+            {
+                brightnessView.btnText.TextID = StringId.brightnesLogic;
+            }
+            fLayout.AddChidren(brightnessView.FLayoutView());
+            #endregion
+            #region 鐐瑰嚮浜嬩欢
+            ///寮�鍏崇偣鍑讳簨浠�
+            lightSwitchView.btnClick.MouseUpEventHandler += (sender, e) =>
+            {
+                SwitchViewMethod(device, lightSwitchView.btnState, intView);
+            };
+            ///浜害鐐瑰嚮浜嬩欢
+            brightnessView.btnClick.MouseUpEventHandler += (sender, e) =>
+            {
+                BrightnessMethod(device, brightnessView.btnState, brightnessView.btnText.Text);
+            };
+            if (edit)
+            {
+                GetEditState(device, index, lightSwitchView.btnState, brightnessView.btnState, null, null);
+            }
+            #endregion
+
+        }
+        /// <summary>
+        /// 寮�鍏�=鍔熻兘涓嬩竴绾х晫闈�
+        /// </summary>
+        /// <param name="device"></param>
+        /// <param name="button"></param>
+        /// <param name="len">鏄剧ず閫夋嫨View鏁伴噺</param>
+        private void SwitchViewMethod(Entity.Function device, Button button, int len)
+        {
+            #region 鐣岄潰
+            FrameLayout frame = new FrameLayout
+            {
+                BackgroundColor = CSS.CSS_Color.viewTrans60lucence,
+            };
+            this.AddChidren(frame);
+            LogicView.SwitchView switchView = new LogicView.SwitchView();
+            switchView.FLayoutView(frame, len);
+            #endregion
+
+            #region 鐐瑰嚮浜嬩欢
+            Dictionary<string, string> dic = new Dictionary<string, string>();
+            LogicMethod.dictionary(dic, "key", "on_off");
+            string keyVlaue = "on_off";
+            //寮�-鐐瑰嚮浜嬩欢
+            switchView.btnOn.MouseUpEventHandler += (sender2, e2) =>
+            {
+                LogicMethod.dictionary(dic, "value", "on");
+                button.TextID = StringId.onLogic;
+                selectedState = device.functionType + "_on";
+                AddDictionaryData(dicSateteList, keyVlaue, dic);
+                RemView(frame);
+            };
+            //鍏�-鐐瑰嚮浜嬩欢
+            switchView.btnOff.MouseUpEventHandler += (sender3, e3) =>
+            {
+                LogicMethod.dictionary(dic, "value", "off");
+                button.TextID = StringId.offLogic;
+                selectedState = device.functionType + "_off";
+                AddDictionaryData(dicSateteList, keyVlaue, dic);
+                RemView(frame);
+
+            };
+            //鏆傚仠-鐐瑰嚮浜嬩欢
+            switchView.btnStop.MouseUpEventHandler += (sender3, e3) =>
+            {
+                LogicMethod.dictionary(dic, "value", "stop");
+                button.TextID = StringId.stop;
+                selectedState = device.functionType + "_stop";
+                AddDictionaryData(dicSateteList, keyVlaue, dic);
+                RemView(frame);
+
+            };
+            ///鏄剧ず涔嬪墠鐘舵��
+            if (button.Text != "")
+            {
+                if (button.Text == switchView.btnOn.Text)
+                {
+                    switchView.btnOn.TextColor = CSS.CSS_Color.textConfirmColor;
+                }
+                else if (button.Text == switchView.btnOff.Text)
+                {
+                    switchView.btnOff.TextColor = CSS.CSS_Color.textConfirmColor;
+                }
+                else if (button.Text == switchView.btnStop.Text)
+                {
+                    switchView.btnOff.TextColor = CSS.CSS_Color.textConfirmColor;
+                }
+            }
+            #endregion
+
+
+        }
+
+        /// <summary>
+        /// 浜害/鐧惧垎姣�=鍔熻兘涓嬩竴绾х晫闈�
+        /// </summary>
+        /// <param name="device"></param>
+        /// <param name="button"></param>
+        private void BrightnessMethod(Entity.Function device, Button button, string titleName)
+        {
+            #region 鐣岄潰
+            FrameLayout frame = new FrameLayout
+            {
+                BackgroundColor = CSS.CSS_Color.viewTrans60lucence,
+            };
+            this.AddChidren(frame);
+            LogicView.BrightnessView brightness = new LogicView.BrightnessView();
+            brightness.btnTitle.Text = titleName;
+            brightness.FLayoutView(frame);
+            #endregion
+            #region 鐐瑰嚮浜嬩欢
+            int brightnesValue = 0;
+            Dictionary<string, string> dic = new Dictionary<string, string>();
+            LogicMethod.dictionary(dic, "key", "brightness");
+            string keyVlaue = "brightness";
+            //鈥旂偣鍑讳簨浠�
+            brightness.btn_subtract_click.MouseUpEventHandler += (sender2, e2) =>
+            {
+                if (brightnesValue > 0)
+                {
+                    brightnesValue -= 1;
+                    brightness.seekBarVol.Progress = brightnesValue;
+                }
+            };
+            //+鐐瑰嚮浜嬩欢
+            brightness.btn_add_click.MouseUpEventHandler += (sende2, e2) =>
+            {
+                if (brightnesValue < 100)
+                {
+                    brightnesValue += 1;
+                    brightness.seekBarVol.Progress = brightnesValue;
+
+                }
+            };
+            //杩涘害鏉℃粦鍔ㄧ偣鍑讳簨浠�
+            EventHandler<int> progressclick = (sender2, e2) =>
+            {
+                brightnesValue = brightness.seekBarVol.Progress;
+            };
+            brightness.seekBarVol.OnProgressChangedEvent += progressclick;
+            brightness.seekBarVol.OnStopTrackingTouchEvent += progressclick;
+            //纭畾鐐瑰嚮浜嬩欢
+            brightness.btnConfirm.MouseUpEventHandler += (sende2, e2) =>
+            {
+                if (brightnesValue == 0)
+                {
+                    return;
+                }
+
+                LogicMethod.dictionary(dic, "value", brightnesValue.ToString());
+                selectedState = device.functionType + brightnesValue.ToString();
+                AddDictionaryData(dicSateteList, keyVlaue, dic);
+                button.Text = brightnesValue.ToString();
+                RemView(frame);
+
+            };
+            //鏄剧ず涔嬪墠鐘舵��
+            if (button.Text != "")
+            {
+                brightnesValue = int.Parse(button.Text);
+                brightness.seekBarVol.Progress = brightnesValue;
+            }
+            #endregion
+
+
+        }
+        /// <summary>
+        /// 绉婚櫎鎺т欢
+        /// </summary>
+        /// <param name="frame"></param>
+        private void RemView(FrameLayout frame)
+        {
+            frame.RemoveFromParent();
+        }
+        /// <summary>
+        /// 鏄剧ず缂栬緫涔嬪墠鐨勮澶囩姸鎬�
+        /// </summary>
+        /// <param name="device">缂栬緫璁惧</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, int index, Button button1, Button button2, Button button3, Button button4)
+        {
+            Output outputs = Logic.currlogic.output[index];
+            var dicList = outputs.status as List<Dictionary<string, string>>;
+            //娓呴櫎涔嬪墠鏃ф暟鎹�
+            dicSateteList.Clear();
+            if (dicList.Count != 0)
+            {
+                //鏈夋暟鎹噸鏂拌祴鍊�
+                dicSateteList = dicList;
+            }
+            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;
+                case FunctionType.Dimmer:
+                case FunctionType.RGB:
+                case FunctionType.RGBW:
+                case FunctionType.CCT:
+                    {
+                        foreach (var dic in dicList)
+                        {
+                            string value = dic["value"];
+                            switch (dic["key"])
+                            {
+                                case "on_off":
+                                    {
+                                        if (value == "on")
+                                        {
+                                            button1.Text = Language.StringByID(StringId.onLogic);
+                                        }
+                                        else
+                                        {
+                                            button1.Text = Language.StringByID(StringId.offLogic);
+                                        }
+                                    }
+                                    break;
+                                case "brightness":
+                                    {
+
+                                        button2.Text = value;
+                                    }
+                                    break;
+                            }
+
+                        }
+                    }
+                    break;
+                case FunctionType.Curtain:
+                    {
+                        foreach (var dic in dicList)
+                        {
+                            string value = dic["value"];
+                            switch (value)
+                            {
+                                case "on":
+                                    {
+                                        button1.Text = Language.StringByID(StringId.onLogic);
+                                    }
+                                    break;
+                                case "off":
+                                    {
+                                        button1.Text = Language.StringByID(StringId.offLogic);
+                                    }
+                                    break;
+                                case "stop":
+                                    {
+                                        button1.Text = Language.StringByID(StringId.stop);
+                                    }
+                                    break;
+                            }
+                        }
+                    }
+                    break;
+                case FunctionType.TrietexCurtain:
+                case FunctionType.RollerCurtain: {
+
+                        foreach (var dic in dicList)
+                        {
+                            string value = dic["value"];
+                            switch (dic["key"])
+                            {
+                                case "on_off":
+                                    {
+                                        switch (value)
+                                        {
+                                            case "on":
+                                                {
+                                                    button1.Text = Language.StringByID(StringId.onLogic);
+                                                }
+                                                break;
+                                            case "off":
+                                                {
+                                                    button1.Text = Language.StringByID(StringId.offLogic);
+                                                }
+                                                break;
+                                            case "stop":
+                                                {
+                                                    button1.Text = Language.StringByID(StringId.stop);
+                                                }
+                                                break;
+                                        }
+                                    }
+                                    break;
+                                case "brightness":
+                                    {
+
+                                        button2.Text = value;
+                                    }
+                                    break;
+                            }
+
+                        }
+                    }
+                    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="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);
+            }
+
+        }
+
+    }
+}

--
Gitblit v1.8.0