using System; using Shared; using System.Collections.Generic; namespace HDL_ON.UI.UI2.Intelligence.Automation { public class OutdoorEnvironment : FrameLayout { public OutdoorEnvironment() { Tag = "Logic"; } public void Show() { #region 界面布局 LogicView.TopView topView = new LogicView.TopView(); this.AddChidren(topView.FLayoutView()); topView.clickBackBtn.MouseUpEventHandler += (e, sen) => { RemoveFromParent(); }; topView.topNameBtn.TextID = StringId.shiwaihuanjingbianhua; FrameLayout viewLayout = new FrameLayout { Y = Application.GetRealHeight(64), Width = Application.GetRealWidth(LogicView.TextSize.view375), Height = Application.GetRealHeight(LogicView.TextSize.view667 - 64), BackgroundColor = CSS.CSS_Color.viewMiddle, }; this.AddChidren(viewLayout); //温度高于 LogicView.SelectTypeView temperaturehigherView = new LogicView.SelectTypeView(); temperaturehigherView.btnIcon.Visible = false; temperaturehigherView.btnText.X = Application.GetRealWidth(16); temperaturehigherView.btnLine.X = Application.GetRealWidth(16); temperaturehigherView.btnLine.Width = Application.GetRealWidth(375 - 16 - 16); temperaturehigherView.btnText.TextID = StringId.wendugaoyu; viewLayout.AddChidren(temperaturehigherView.FLayoutView()); //温度低于 LogicView.SelectTypeView temperatureunderView = new LogicView.SelectTypeView(); temperatureunderView.frameLayout.Y = temperaturehigherView.frameLayout.Bottom; temperatureunderView.btnIcon.Visible = false; temperatureunderView.btnText.X = Application.GetRealWidth(16); temperatureunderView.btnLine.X = Application.GetRealWidth(16); temperatureunderView.btnLine.Width = Application.GetRealWidth(375 - 16 - 16); temperatureunderView.btnText.TextID = StringId.wendudiyu; viewLayout.AddChidren(temperatureunderView.FLayoutView()); //湿度高于 LogicView.SelectTypeView humidityhigherView = new LogicView.SelectTypeView(); humidityhigherView.frameLayout.Y = temperatureunderView.frameLayout.Bottom + Application.GetRealHeight(8); humidityhigherView.btnIcon.Visible = false; humidityhigherView.btnText.X = Application.GetRealWidth(16); humidityhigherView.btnLine.X = Application.GetRealWidth(16); humidityhigherView.btnLine.Width = Application.GetRealWidth(375 - 16 - 16); humidityhigherView.btnText.TextID = StringId.shidugaoyu; viewLayout.AddChidren(humidityhigherView.FLayoutView()); //湿度低于 LogicView.SelectTypeView humidityunderView = new LogicView.SelectTypeView(); humidityunderView.frameLayout.Y = humidityhigherView.frameLayout.Bottom; humidityunderView.btnIcon.Visible = false; humidityunderView.btnText.X = Application.GetRealWidth(16); humidityunderView.btnLine.X = Application.GetRealWidth(16); humidityunderView.btnLine.Width = Application.GetRealWidth(375 - 16 - 16); humidityunderView.btnText.TextID = StringId.shidudiyu; viewLayout.AddChidren(humidityunderView.FLayoutView()); //PM2.5 LogicView.SelectTypeView pmhigherView = new LogicView.SelectTypeView(); pmhigherView.frameLayout.Y = humidityunderView.frameLayout.Bottom + Application.GetRealHeight(8); pmhigherView.btnIcon.Visible = false; pmhigherView.btnText.X = Application.GetRealWidth(16); pmhigherView.btnLine.X = Application.GetRealWidth(16); pmhigherView.btnLine.Width = Application.GetRealWidth(375 - 16 - 16); pmhigherView.btnText.TextID = StringId.PM25; viewLayout.AddChidren(pmhigherView.FLayoutView()); #endregion #region 所有点击事件 //温度高于 temperaturehigherView.btnClick.MouseUpEventHandler += (sen, e) => { InputBoxAction(StringId.wendugaoyu); }; //温度低于 temperatureunderView.btnClick.MouseUpEventHandler += (sen, e) => { InputBoxAction(StringId.wendudiyu); }; //湿度高于 humidityhigherView.btnClick.MouseUpEventHandler += (sen, e) => { InputBoxAction(StringId.shidugaoyu); }; //湿度低于 humidityunderView.btnClick.MouseUpEventHandler += (sen, e) => { InputBoxAction(StringId.shidudiyu); }; //PM2.5 pmhigherView.btnClick.MouseUpEventHandler += (sen, e) => { PmAction(this); }; #endregion } /// /// 温度,湿度弹框设置值 /// /// 文本 /// 编辑之前的状态值,默认为20 public void InputBoxAction(int textInt, string stateValue = "20") { new LogicView.TipPopView { }.InputBox(textInt, stateValue, (value) => { string keyValue = ""; string comparator = "="; switch (textInt) { case StringId.wendugaoyu: { keyValue = "temperature"; comparator = ">"; } break; case StringId.wendudiyu: { keyValue = "temperature"; comparator = "<"; } break; case StringId.shidugaoyu: { keyValue = "humidity"; comparator = ">"; } break; case StringId.shidudiyu: { keyValue = "humidity"; comparator = "<"; } break; } AddDic(keyValue, comparator, value,"float"); }); } /// /// PM2.5设置值 /// /// 当前界面 /// 编辑之前的状态值,默认为"" public void PmAction(FrameLayout frame, string stateValue = "") { PublicInterface pmView = new PublicInterface(); var pmListStr = pmView.GetViewList("pm25"); pmView.SingleSelectionShow(frame, pmListStr, Language.StringByID(StringId.PM25), pmView.GetString("pm25", stateValue) , (text) => { var value= pmView.GetValue("pm25", text); AddDic("pm25", "in", value, "integer"); }); } /// /// 封装数据 /// /// 类型值(pm25;temperature;humidity) /// 比较关系 /// 值 public void AddDic(string keyValue, string comparator,string value,string data_type) { Input input = new Input(); input.sid = LogicMethod.CurrLogicMethod.NewSid(); input.condition_type = "6"; Dictionary dic = new Dictionary(); LogicMethod.CurrLogicMethod.dictionary(dic, "key", keyValue); LogicMethod.CurrLogicMethod.dictionary(dic, "comparator", comparator); LogicMethod.CurrLogicMethod.dictionary(dic, "data_type", data_type); LogicMethod.CurrLogicMethod.dictionary(dic, "value", value); input.condition.Add(dic); AddCondition(input, keyValue, comparator); } /// /// 添加条件 /// /// /// /// 比较关系 private void AddCondition(Input input, string keyValue, string comparator) { ///记录索引值 int index = -1; for (var i = 0; i < Logic.currlogic.input.Count; i++) { var condition_type = Logic.currlogic.input[i].condition_type; if (condition_type == "6") { var dicList = Logic.currlogic.input[i].condition; if (ExistKey(dicList, keyValue, comparator)) { ///找到标记索引,退出循环体 index = i; break; } } } if (index != -1) { //移除旧数据 Logic.currlogic.input.RemoveAt(index); //新数据插入旧数据的位置 Logic.currlogic.input.Insert(index, input); } else { Logic.currlogic.input.Add(input); } LogicMethod.CurrLogicMethod.RemoveAllView(); AddLogic addLogic = new AddLogic(); MainPage.BasePageView.AddChidren(addLogic); addLogic.Show(); MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1; } /// /// 判断是否存在Key /// /// /// /// 比较关系 /// private bool ExistKey(List> dicList, string keyValue, string comparator) { for (int i = 0; i < dicList.Count; i++) { var dic = dicList[i]; string key = dic["key"]; string comparatorValue = dic["comparator"]; if (key == keyValue && comparatorValue == comparator) { //判断是否存在 return true; } } return false; } } }