using System; using Shared; using System.Collections.Generic; namespace HDL_ON.UI.UI2.Intelligence.Automation { public class TargetDeviceFunList : FrameLayout { public TargetDeviceFunList() { Tag = "Logic"; } /// /// 定义一个记录选中设备状态列表; /// private List> dicSateteList = new List>(); /// /// 定义一个变量,记录选中状态 /// private string selectedState = "unknown"; /// /// 定义一个变量,记录选中状态记录属性 /// private string keyVlaue = ""; 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); #endregion switch (device.functionType) { //开关灯光 light.Switch case FunctionType.Dimmer: { #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) => { FrameLayout frame = new FrameLayout { BackgroundColor = CSS.CSS_Color.viewTrans60lucence, }; this.AddChidren(frame); Dictionary dic = new Dictionary(); 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"); RemView(frame); lightSwitchView.btnState.TextID = StringId.onLogic; selectedState = device.functionType + "_on"; AddDictionaryData(dicSateteList, keyVlaue, dic); }; switchView.btnOff.MouseUpEventHandler += (sender3, e3) => { LogicMethod.dictionary(dic, "value", "off"); RemView(frame); lightSwitchView.btnState.TextID = StringId.offLogic; selectedState = device.functionType + "_off"; AddDictionaryData(dicSateteList, keyVlaue, dic); }; 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); Dictionary dic = new Dictionary(); LogicMethod.dictionary(dic, "key", "on_off"); keyVlaue = "on_off"; LogicView.BrightnessView brightness = new LogicView.BrightnessView(); brightness.btnTitle.TextID = StringId.brightnesLogic; brightness.FLayoutView(frame); brightness.btn_subtract.MouseUpEventHandler += (sender2, e2) => { LogicMethod.dictionary(dic, "value", "on"); RemView(frame); lightSwitchView.btnState.TextID = StringId.onLogic; selectedState = device.functionType + "_on"; AddDictionaryData(dicSateteList, keyVlaue, dic); }; brightness.btn_add.MouseUpEventHandler += (sender3, e3) => { LogicMethod.dictionary(dic, "value", "off"); RemView(frame); lightSwitchView.btnState.TextID = StringId.offLogic; selectedState = device.functionType + "_off"; AddDictionaryData(dicSateteList, keyVlaue, dic); }; 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); } #endregion } break; case FunctionType.RGB: break; case FunctionType.RGBW: break; case FunctionType.CCT: break; case FunctionType.Relay: { LogicView.FunTypeView lightSwitchView = new LogicView.FunTypeView(); lightSwitchView.btnText.TextID = StringId.switchLogic; fLayout.AddChidren(lightSwitchView.FLayoutView()); lightSwitchView.btnClick.MouseUpEventHandler += (sender, e) => { FrameLayout frame = new FrameLayout { BackgroundColor = CSS.CSS_Color.viewTrans60lucence, }; this.AddChidren(frame); Dictionary dic = new Dictionary(); 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"); RemView(frame); lightSwitchView.btnState.TextID = StringId.onLogic; selectedState = device.functionType + "_on"; AddDictionaryData(dicSateteList, keyVlaue, dic); }; switchView.btnOff.MouseUpEventHandler += (sender3, e3) => { LogicMethod.dictionary(dic, "value", "off"); RemView(frame); lightSwitchView.btnState.TextID = StringId.offLogic; selectedState = device.functionType + "_off"; AddDictionaryData(dicSateteList, keyVlaue, dic); }; 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); } } break; //窗帘 case FunctionType.Curtain: break; } #region 保存 ///保存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()); 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 } /// /// 移除控件 /// /// private void RemView(FrameLayout frame) { frame.RemoveFromParent(); } /// /// 显示编辑之前的设备状态 /// /// 编辑设备 /// 编辑状态 /// 编辑数据的索引 /// 显示Btn /// 显示Btn /// 显示Btn /// 显示Btn private void GetEditState(Entity.Function device, bool edit, int index, Button button1, Button button2, Button button3, Button button4) { Output outputs = Logic.currlogic.output[index]; var dicList = outputs.status as List>; 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; } } /// /// 添加选中数据 /// /// 存储数据列表 /// 识别设备 /// 选中数据 /// private void AddDictionaryData(List> dicList, string keyValue, Dictionary 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); } } /// /// 添加目标 /// /// 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); } } /// /// 开关功能展开界面 /// /// /// /// /// public void SwitchViewMethod1(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 dic = new Dictionary(); LogicMethod.dictionary(dic, "key", "on_off"); keyVlaue = "on_off"; 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; } } } } }