wxr
2021-07-01 43b0d5870d528f23ecd6aeceb6cfd4325188b46f
HDL_ON/UI/UI2/3-Intelligence/Automation/TargetDeviceFunList.cs
@@ -1,6 +1,8 @@
using System;
using System;
using Shared;
using System.Collections.Generic;
using HDL_ON.Entity;
namespace HDL_ON.UI.UI2.Intelligence.Automation
{
    public class TargetDeviceFunList : FrameLayout
@@ -43,34 +45,93 @@
            this.AddChidren(saveView.FLayoutView());
            #endregion
            #region  编辑设备状态
            switch (device.functionType)
            switch (device.spk)
            {
                //开关灯光 light.Switch
                case FunctionType.Dimmer:
                case FunctionType.RGB:
                case FunctionType.RGBW:
                case FunctionType.ColorTemperature:
                case SPK.LightDimming:
                case SPK.LightRGB:
                case SPK.LightRGBW:
                case SPK.LightCCT:
                    {
                        //2表示(开,关)功能
                        SwitchBrightnessView(fLayout, device, index, edit, 2);
                        #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;
                        brightnessView.btnText.TextID = StringId.brightnesLogic;
                        fLayout.AddChidren(brightnessView.FLayoutView());
                        #endregion
                        #region 点击事件
                        ///开关点击事件
                        lightSwitchView.btnClick.MouseUpEventHandler += (sender, e) =>
                        {
                            SwitchViewMethod(device, lightSwitchView.btnState, 2);
                        };
                        ///亮度点击事件
                        brightnessView.btnClick.MouseUpEventHandler += (sender, e) =>
                        {
                            BrightnessMethod(device, brightnessView.btnState, brightnessView.btnText.Text);
                        };
                        if (edit)
                        {
                            //显示编辑之前的设备状态
                            GetEditState(device, index, lightSwitchView.btnState, brightnessView.btnState, null, null);
                        }
                        #endregion
                    }
                    break;
                case FunctionType.Relay:
                case SPK.LightSwitch:
                    {
                        //2表示(开,关)功能
                        SwitchView(fLayout, device, index, edit, 2);
                        #region 界面
                        ///开关
                        LogicView.FunTypeView lightSwitchView = new LogicView.FunTypeView();
                        lightSwitchView.btnText.TextID = StringId.switchLogic;
                        fLayout.AddChidren(lightSwitchView.FLayoutView());
                        #endregion
                        #region 点击事件
                        ///开关点击事件
                        lightSwitchView.btnClick.MouseUpEventHandler += (sender, e) =>
                        {
                            SwitchViewMethod(device, lightSwitchView.btnState, 2);
                        };
                        if (edit)
                        {
                            //显示编辑之前的设备状态
                            GetEditState(device, index, lightSwitchView.btnState, null, null, null);
                        }
                        #endregion
                    }
                    break;
                //窗帘
                case FunctionType.Curtain:
                case FunctionType.MotorCurtain:
                case FunctionType.RollingShutter:
                case SPK.CurtainSwitch:
                case SPK.CurtainTrietex:
                case SPK.CurtainRoller:
                    {
                        //3表示(开,关,暂停)功能
                        SwitchView(fLayout, device, index, edit, 3);
                        #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, 3);
                        };
                        if (edit)
                        {
                            //显示编辑之前的设备状态
                            GetEditState(device, index, curtainSwitchView.btnState, null, null, null);
                        }
                        #endregion
                    }
                    break;
                case FunctionType.AC:
                case SPK.AcStandard:
                    {
                        #region 界面
                        ///开关
@@ -107,19 +168,17 @@
                        {
                            ///之前的状态文本
                            string tempValue = temperatureView.btnState.Text;
                            LogicView.TemperatureView tempView= new LogicView.TemperatureView();
                            tempView.FLayoutView(this, tempValue,(stateStr)=> {
                            LogicView.TemperatureView tempView = new LogicView.TemperatureView();
                            tempView.FLayoutView(this, tempValue, (stateStr) =>
                            {
                                //界面显示选中值
                                temperatureView.btnState.Text = stateStr;
                                //设备属性值,云雀上定义好的;
                                string keyVlaue = "set_temp";
                                selectedState = device.functionType + "_"+ keyVlaue;
                                selectedState = device.spk + "_" + keyVlaue;
                                string set_temp_value = stateStr.Replace("℃", "");
                                //数据封装
                                Dictionary<string, string> dic = new Dictionary<string, string>();
                                LogicMethod.dictionary(dic, "key", keyVlaue);
                                LogicMethod.dictionary(dic, "value", set_temp_value);
                                AddDictionaryData(dicSateteList, keyVlaue, dic);
                                AddDictionary(keyVlaue, set_temp_value);
                            });
@@ -131,20 +190,16 @@
                            string currText = acModehView.btnState.Text;
                            //设备属性值,云雀上定义好的;
                            string keyVlaue = "mode";
                            selectedState = device.functionType + "_"+keyVlaue;
                            selectedState = device.spk + "_" + keyVlaue;
                            PublicInterface modeView = new PublicInterface();
                            var modeListStr=  modeView.GetViewList(keyVlaue);
                            var modeListStr = modeView.GetViewList(keyVlaue);
                            modeView.SingleSelectionShow(this, modeListStr, Language.StringByID(StringId.modeLogic), currText
                               , (stateValue) =>
                               {
                                   //界面显示选中值
                                   acModehView.btnState.Text = stateValue;
                                   //数据封装
                                   Dictionary<string, string> dic = new Dictionary<string, string>();
                                   LogicMethod.dictionary(dic, "key", keyVlaue);
                                   LogicMethod.dictionary(dic, "value", modeView.GetModeValueString(stateValue, keyVlaue));
                                   AddDictionaryData(dicSateteList, keyVlaue, dic);
                                   AddDictionary(keyVlaue, modeView.GetModeValueString(stateValue, keyVlaue));
                               });
                        };
@@ -156,7 +211,7 @@
                            string currText = acSpeedView.btnState.Text;
                            //设备属性值,云雀上定义好的;
                            string keyVlaue = "fan";
                            selectedState = device.functionType + "_" + keyVlaue;
                            selectedState = device.spk + "_" + keyVlaue;
                            PublicInterface speedView = new PublicInterface();
                            var speedListStr = speedView.GetViewList(keyVlaue);
                            speedView.SingleSelectionShow(this, speedListStr, Language.StringByID(StringId.speedLogic), currText
@@ -165,10 +220,7 @@
                                   //界面显示选中值
                                   acSpeedView.btnState.Text = stateValue;
                                   //数据封装
                                   Dictionary<string, string> dic = new Dictionary<string, string>();
                                   LogicMethod.dictionary(dic, "key", keyVlaue);
                                   LogicMethod.dictionary(dic, "value", speedView.GetModeValueString(stateValue, keyVlaue));
                                   AddDictionaryData(dicSateteList, keyVlaue, dic);
                                   AddDictionary(keyVlaue, speedView.GetModeValueString(stateValue, keyVlaue));
                               });
                        };
@@ -181,7 +233,7 @@
                        #endregion
                    }
                    break;
                case FunctionType.FloorHeating:
                case SPK.FloorHeatStandard:
                    {
                        #region 界面
                        ///开关
@@ -207,6 +259,7 @@
                        ///开关点击事件
                        floorHeatingSwitchVie.btnClick.MouseUpEventHandler += (sender, e) =>
                        {
                            SwitchViewMethod(device, floorHeatingSwitchVie.btnState, 2);
                        };
                        ///温度点击事件
@@ -214,33 +267,30 @@
                        {
                            string tempValue = temperatureView.btnState.Text;
                            LogicView.TemperatureView tempView = new LogicView.TemperatureView();
                            tempView.FLayoutView(this, tempValue, (stateStr) => {
                            tempView.FLayoutView(this, tempValue, (stateStr) =>
                            {
                                //界面显示选中值
                                temperatureView.btnState.Text = stateStr;
                                //设备属性值,云雀上定义好的;
                                string keyVlaue = "set_temp";
                                selectedState = device.functionType + "_"+ keyVlaue;
                                selectedState = device.spk + "_" + keyVlaue;
                                string set_temp_value = stateStr.Replace("℃", "");
                                //数据封装
                                Dictionary<string, string> dic = new Dictionary<string, string>();
                                LogicMethod.dictionary(dic, "key", keyVlaue);
                                LogicMethod.dictionary(dic, "value", set_temp_value);
                                AddDictionaryData(dicSateteList, keyVlaue, dic);
                                AddDictionary(keyVlaue, set_temp_value);
                            });
                        };
                        ///模式点击事件
                        floorHeatingModehView.btnClick.MouseUpEventHandler += (sender, e) =>
                        {
                            ///之前的状态文本
                            string currText= floorHeatingModehView.btnState.Text;
                            string currText = floorHeatingModehView.btnState.Text;
                            //设备属性值,云雀上定义好的;
                            string keyVlaue = "mode";
                            selectedState = device.functionType + "_"+ keyVlaue;
                            selectedState = device.spk + "_" + keyVlaue;
                            PublicInterface modeView = new PublicInterface();
                            var modeListStr = modeView.GetViewList("floorheatingmode");
                            modeView.SingleSelectionShow(this, modeListStr, Language.StringByID(StringId.modeLogic), currText
@@ -249,10 +299,7 @@
                                   //界面显示选中值
                                   floorHeatingModehView.btnState.Text = stateValue;
                                   //数据封装
                                   Dictionary<string, string> dic = new Dictionary<string, string>();
                                   LogicMethod.dictionary(dic, "key", keyVlaue);
                                   LogicMethod.dictionary(dic, "value", modeView.GetModeValueString(stateValue, "floorheatingmode"));
                                   AddDictionaryData(dicSateteList, keyVlaue, dic);
                                   AddDictionary(keyVlaue, modeView.GetModeValueString(stateValue, "floorheatingmode"));
                               });
                        };
@@ -271,26 +318,25 @@
            #region  保存点击事件
            saveView.btnClick.MouseUpEventHandler += (sen, e) =>
            {
                if (selectedState != "unknown")
                {
                    Output outputDevice = new Output();
                    outputDevice.target_type = "1";
                    outputDevice.sid = device.sid;
                    switch (device.functionType)
                    switch (device.spk)
                    {
                        case FunctionType.Dimmer:
                        case FunctionType.RGB:
                        case FunctionType.RGBW:
                        case FunctionType.ColorTemperature:
                        case SPK.LightDimming:
                        case SPK.LightRGB:
                        case SPK.LightRGBW:
                        case SPK.LightCCT:
                            {
                                //调光做了一个特殊处理;
                                if (dicSateteList.Count > 1)
                                {
                                    foreach (var dictionary in dicSateteList)
                                    {
                                        if (dictionary["key"] == "on_off")
                                        string keyValue = dictionary["key"];
                                        if (keyValue == "on_off")
                                        {
                                            if (dictionary["value"] == "off")
                                            {
@@ -308,8 +354,8 @@
                                }
                                break;
                            }
                        case FunctionType.AC:
                        case FunctionType.FloorHeating:
                        case SPK.AcStandard:
                        case SPK.FloorHeatStandard:
                            {
                                //(空调/地热)做了一个特殊处理;
@@ -371,85 +417,6 @@
            #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.MotorCurtain || device.functionType == FunctionType.RollingShutter)
            {
                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>
@@ -459,37 +426,37 @@
        private void SwitchViewMethod(Entity.Function device, Button button, int len)
        {
            #region 界面
            FrameLayout frame = new FrameLayout
            {
                BackgroundColor = CSS.CSS_Color.viewTrans60lucence,
            };
            FrameLayout frame = new FrameLayout { BackgroundColor = CSS.CSS_Color.viewTrans60lucence };
            this.AddChidren(frame);
            LogicView.SwitchView switchView = new LogicView.SwitchView();
            switchView.FLayoutView(frame, len, button.Text, (strValue) =>
            {
                int id = 0;
                switch (strValue) {
                    case "on": {
                switch (strValue)
                {
                    case "on":
                        {
                            id = StringId.onLogic;
                        }
                        break;
                    case "off": {
                    case "off":
                        {
                            id = StringId.offLogic;
                        } break;
                    case "stop": {
                        }
                        break;
                    case "stop":
                        {
                            id = StringId.stop;
                        } break;
                        }
                        break;
                }
                //界面显示选中值
                button.TextID = id;
                selectedState = device.functionType + "_" + strValue;
                selectedState = device.spk + "_" + strValue;
                //设备属性值,云雀上定义好的;
                string keyVlaue = "on_off";
                //数据封装
                Dictionary<string, string> dic = new Dictionary<string, string>();
                LogicMethod.dictionary(dic, "key", "on_off");
                LogicMethod.dictionary(dic, "value", strValue);
                AddDictionaryData(dicSateteList, keyVlaue, dic);
                AddDictionary(keyVlaue, strValue);
            });
            #endregion
        }
@@ -507,33 +474,30 @@
            brightness.FLayoutView(this, titleName, stateVlaue, (brightnesValue) =>
            {
                //界面显示选中值
                button.Text = brightnesValue+"%";
                button.Text = brightnesValue + "%";
                selectedState = device.spk + brightnesValue.ToString();
                //设备属性值,云雀上定义好的;
                string keyVlaue = "";
                selectedState = device.functionType + brightnesValue.ToString();
                //数据封装
                Dictionary<string, string> dic = new Dictionary<string, string>();
                switch (device.functionType)
                switch (device.spk)
                {
                    //开关灯光 light.Switch
                    case FunctionType.Dimmer:
                    case FunctionType.RGB:
                    case FunctionType.RGBW:
                    case FunctionType.ColorTemperature:
                    case SPK.LightDimming:
                    case SPK.LightRGB:
                    case SPK.LightRGBW:
                    case SPK.LightCCT:
                        {
                            LogicMethod.dictionary(dic, "key", "brightness");
                            keyVlaue = "brightness";
                        }
                        break;
                    case FunctionType.MotorCurtain:
                    case FunctionType.RollingShutter:
                    case SPK.CurtainRoller:
                    case SPK.CurtainTrietex:
                        {
                            LogicMethod.dictionary(dic, "key", "percent");
                            keyVlaue = "percent";
                        }
                        break;
                }
                LogicMethod.dictionary(dic, "value", brightnesValue.ToString());
                AddDictionaryData(dicSateteList, keyVlaue, dic);
                //数据封装
                AddDictionary(keyVlaue, brightnesValue);
            });
            #endregion
@@ -561,18 +525,30 @@
            InpOrOutLogicMethod.EditState(device, dicList, button1, button2, button3, button4);
        }
        /// <summary>
        /// 添加处理选中数据
        /// 添加选中数据
        /// </summary>
        /// <param name="dicList">存储数据列表</param>
        /// <param name="keyValue">识别设备</param>
        /// <param name="dictionary">选中数据</param>
        /// <param name="KeyValue">设备属性值,云雀上定义好的</param>
        /// <param name="selectedValue">状态值</param>
        private void AddDictionary(string KeyValue, string selectedValue)
        {
            //数据封装
            Dictionary<string, string> dic = new Dictionary<string, string>();
            LogicMethod.dictionary(dic, "key", KeyValue);
            LogicMethod.dictionary(dic, "value", selectedValue);
            AddDictionaryList(KeyValue, dic);
        }
        /// <summary>
        /// 更新数据列表
        /// </summary>
        /// <param name="keyValue">设备属性值,云雀上定义好的</param>
        /// <param name="dictionary">添加选中数据</param>
        /// <returns></returns>
        private void AddDictionaryData(List<Dictionary<string, string>> dicList, string keyValue, Dictionary<string, string> dictionary)
        private void AddDictionaryList(string keyValue, Dictionary<string, string> dictionary)
        {
            int indexValue = -1;
            for (int i = 0; i < dicList.Count; i++)
            for (int i = 0; i < dicSateteList.Count; i++)
            {
                var dic = dicList[i];
                var dic = dicSateteList[i];
                if (dic.ContainsValue(keyValue))
                {
                    //判断是否存在
@@ -584,14 +560,14 @@
            if (indexValue != -1)
            {
                //存在移除
                dicList.RemoveAt(indexValue);
                dicSateteList.RemoveAt(indexValue);
                //重新添加
                dicList.Insert(indexValue, dictionary);
                dicSateteList.Insert(indexValue, dictionary);
            }
            else
            {
                //新添加
                dicList.Add(dictionary);
                dicSateteList.Add(dictionary);
            }
        }
@@ -622,7 +598,7 @@
            }
        }
    }