陈嘉乐
2020-12-03 3037541d683de2f9dd775870055d244ba15839f2
HDL_ON/UI/UI2/3-Intelligence/Automation/TargetDeviceFunList.cs
@@ -45,10 +45,19 @@
                //开关灯光 light.Switch
                case FunctionType.Dimmer:
                    {
                        #region 界面
                        ///开关
                        LogicView.FunTypeView lightSwitchView = new LogicView.FunTypeView();
                        lightSwitchView.btnText.TextID = StringId.switchLogic;
                        lightSwitchView.btnState.Text = "";
                        fLayout.AddChidren(lightSwitchView.FLayoutView());
                        ///亮度
                        LogicView.FunTypeView brightnessView = new LogicView.FunTypeView();
                        brightnessView.frameLayout.Y = lightSwitchView.frameLayout.Bottom;
                        brightnessView.btnText.TextID = StringId.brightnesLogic;
                        fLayout.AddChidren(brightnessView.FLayoutView());
                        #endregion
                        #region 点击事件
                        ///开关点击事件
                        lightSwitchView.btnClick.MouseUpEventHandler += (sender, e) =>
                        {
                            FrameLayout frame = new FrameLayout
@@ -56,86 +65,115 @@
                                BackgroundColor = CSS.CSS_Color.viewTrans60lucence,
                            };
                            this.AddChidren(frame);
                            SwitchViewMethod(frame, device, lightSwitchView.btnState, 2);
                            Dictionary<string, string> dic = new Dictionary<string, string>();
                            LogicMethod.dictionary(dic, "key", "on_off");
                            keyVlaue = "on_off";
                            LogicView.SwitchView switchView = new LogicView.SwitchView();
                            switchView.FLayoutView(frame, 2);
                            switchView.btnOn.MouseUpEventHandler += (sender2, e2) =>
                            {
                                LogicMethod.dictionary(dic, "value", "on");
                                lightSwitchView.btnState.TextID = StringId.onLogic;
                                selectedState = device.functionType + "_on";
                                AddDictionaryData(dicSateteList, keyVlaue, dic);
                                RemView(frame);
                            };
                            switchView.btnOff.MouseUpEventHandler += (sender3, e3) =>
                            {
                                LogicMethod.dictionary(dic, "value", "off");
                                lightSwitchView.btnState.TextID = StringId.offLogic;
                                selectedState = device.functionType + "_off";
                                AddDictionaryData(dicSateteList, keyVlaue, dic);
                                RemView(frame);
                            };
                            if (lightSwitchView.btnState.Text != "")
                            {
                                if (lightSwitchView.btnState.Text == switchView.btnOn.Text)
                                {
                                    switchView.btnOn.TextColor = CSS.CSS_Color.textConfirmColor;
                                }
                                else
                                {
                                    switchView.btnOff.TextColor = CSS.CSS_Color.textConfirmColor;
                                }
                            }
                        };
                        ///亮度点击事件
                        brightnessView.btnClick.MouseUpEventHandler += (sender, e) =>
                        {
                            FrameLayout frame = new FrameLayout
                            {
                                BackgroundColor = CSS.CSS_Color.viewTrans60lucence,
                            };
                            this.AddChidren(frame);
                            int brightnesValue =0;
                            Dictionary<string, string> dic = new Dictionary<string, string>();
                            LogicMethod.dictionary(dic, "key", "brightness");
                            keyVlaue = "brightness";
                            LogicView.BrightnessView brightness = new LogicView.BrightnessView();
                            brightness.btnTitle.TextID = StringId.brightnesLogic;
                            brightness.FLayoutView(frame);
                            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);
                                brightnessView.btnState.Text = brightnesValue.ToString();
                                RemView(frame);
                            };
                            if (brightnessView.btnState.Text != "")
                            {
                                brightnesValue = int.Parse(brightnessView.btnState.Text);
                                brightness.seekBarVol.Progress = brightnesValue;
                            }
                        };
                        if (edit)
                        {
                            GetEditState(device, edit, index, lightSwitchView.btnState, null, null, null);
                            GetEditState(device, index, lightSwitchView.btnState, brightnessView.btnState, null, null);
                        }
                        #endregion
                    }
                    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) =>
                        {
@@ -144,41 +182,50 @@
                                BackgroundColor = CSS.CSS_Color.viewTrans60lucence,
                            };
                            this.AddChidren(frame);
                            SwitchViewMethod(frame, device, lightSwitchView.btnState, 2);
                            Dictionary<string, string> dic = new Dictionary<string, string>();
                            LogicMethod.dictionary(dic, "key", "on_off");
                            keyVlaue = "on_off";
                            LogicView.SwitchView switchView = new LogicView.SwitchView();
                            switchView.FLayoutView(frame, 3);
                            switchView.btnOn.MouseUpEventHandler += (sender2, e2) =>
                            {
                                LogicMethod.dictionary(dic, "value", "on");
                                lightSwitchView.btnState.TextID = StringId.onLogic;
                                selectedState = device.functionType + "_on";
                                AddDictionaryData(dicSateteList, keyVlaue, dic);
                                RemView(frame);
                            };
                            switchView.btnOff.MouseUpEventHandler += (sender3, e3) =>
                            {
                                LogicMethod.dictionary(dic, "value", "off");
                                lightSwitchView.btnState.TextID = StringId.offLogic;
                                selectedState = device.functionType + "_off";
                                AddDictionaryData(dicSateteList, keyVlaue, dic);
                                RemView(frame);
                            };
                            if (lightSwitchView.btnState.Text != "")
                            {
                                if (lightSwitchView.btnState.Text == switchView.btnOn.Text)
                                {
                                    switchView.btnOn.TextColor = CSS.CSS_Color.textConfirmColor;
                                }
                                else
                                {
                                    switchView.btnOff.TextColor = CSS.CSS_Color.textConfirmColor;
                                }
                            }
                        };
                        if (edit)
                        {
                            GetEditState(device, edit, index, lightSwitchView.btnState, null, null, null);
                            GetEditState(device, 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  保存
            ///保存View
            LogicView.SaveView saveView = new LogicView.SaveView();
@@ -240,17 +287,22 @@
        /// 显示编辑之前的设备状态
        /// </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)
        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)
            {
                //开关灯光
@@ -270,7 +322,36 @@
                        }
                    }
                    break;
                case FunctionType.Dimmer:
                    {
                        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;
            }
        }
@@ -344,7 +425,7 @@
        /// <param name="device"></param>
        /// <param name="button"></param>
        /// <param name="len"></param>
        public void SwitchViewMethod(FrameLayout frame, Entity.Function device, Button button, int len)
        public void SwitchViewMethod1(FrameLayout frame, Entity.Function device, Button button, int len)
        {
            LogicView.SwitchView switchView = new LogicView.SwitchView();