| | |
| | | { |
| | | Tag = "Logic"; |
| | | } |
| | | |
| | | public void Show(Entity.Function device, int index, bool edit) |
| | | /// <summary> |
| | | /// 表示是(条件/目标) |
| | | /// </summary> |
| | | private string if_type; |
| | | public void Show(Entity.Function device, int index, bool edit, string str) |
| | | { |
| | | if_type = str; |
| | | #region 界面布局 |
| | | this.BackgroundColor = CSS.CSS_Color.viewMiddle; |
| | | LogicView.TopView topView = new LogicView.TopView(); |
| | |
| | | }; |
| | | this.AddChidren(fLayout); |
| | | #endregion |
| | | |
| | | //定义一个记录选中设备状态列表; |
| | | List<Dictionary<string, string>> dicSateteList = new List<Dictionary<string, string>>(); |
| | | //定义一个变量,记录选中状态 |
| | | string selectedState = "unknown"; |
| | | |
| | | Input inputdevice = new Input(); |
| | | inputdevice.condition_type = "3"; |
| | | inputdevice.sid = device.sid; |
| | | |
| | | |
| | | switch (device.functionType) |
| | | { |
| | | //开关灯光 |
| | | case FunctionType.Relay: |
| | | { |
| | | |
| | | |
| | | |
| | | //for (int i = 0; i < device.function.Count; i++) |
| | | //{ |
| | | //} |
| | |
| | | relayView.btnText.Width = Application.GetRealWidth(130); |
| | | relayView.btnLine.X = Application.GetRealWidth(16); |
| | | relayView.btnLine.Width = Application.GetRealWidth(343); |
| | | relayView.btnState.Text = ""; |
| | | fLayout.AddChidren(relayView.FLayoutView()); |
| | | relayView.btnClick.MouseUpEventHandler += (sender, e) => |
| | | { |
| | |
| | | TextID = StringId.onLogic, |
| | | Height = Application.GetRealHeight(44), |
| | | Width = Application.GetRealWidth(343), |
| | | |
| | | }; |
| | | switchView.frameLayout.AddChidren(btnOn); |
| | | Button btnLine = new Button |
| | |
| | | LogicMethod.dictionary(dic, "key", "on_off"); |
| | | LogicMethod.dictionary(dic, "comparator", "="); |
| | | LogicMethod.dictionary(dic, "data_type", "string"); |
| | | inputdevice.condition.Add(dic); |
| | | btnOn.MouseUpEventHandler += (sender2, e2) => |
| | | { |
| | | LogicMethod.dictionary(dic, "value", "on"); |
| | | RemView(relayFunView); |
| | | relayView.btnState.TextID = StringId.onLogic; |
| | | selectedState = device.functionType + "_on"; |
| | | AddDictionaryData(dicSateteList, "on_off", dic); |
| | | }; |
| | | btnOff.MouseUpEventHandler += (sender3, e3) => |
| | | { |
| | |
| | | RemView(relayFunView); |
| | | relayView.btnState.TextID = StringId.offLogic; |
| | | selectedState = device.functionType + "_off"; |
| | | AddDictionaryData(dicSateteList, "on_off", dic); |
| | | }; |
| | | |
| | | if (relayView.btnState.Text != "") |
| | | { |
| | | if (relayView.btnState.Text == btnOn.Text) |
| | | { |
| | | btnOn.TextColor = CSS.CSS_Color.textConfirmColor; |
| | | } |
| | | else |
| | | { |
| | | btnOff.TextColor = CSS.CSS_Color.textConfirmColor; |
| | | } |
| | | } |
| | | |
| | | }; |
| | | if (edit) |
| | | { |
| | | Input inputs = Logic.currlogic.input[index]; |
| | | if (inputs.condition_type == "3") |
| | | { |
| | | List<Dictionary<string, string>> dicList = inputs.condition as List<Dictionary<string, string>>; |
| | | foreach (var dic in dicList) |
| | | { |
| | | string value = dic["value"]; |
| | | if (value == "on") |
| | | { |
| | | relayView.btnState.Text = Language.StringByID(StringId.onLogic); |
| | | |
| | | } |
| | | else |
| | | { |
| | | relayView.btnState.Text = Language.StringByID(StringId.offLogic); |
| | | } |
| | | } |
| | | } |
| | | GetEditState(device, edit, index, relayView.btnState, null, null, null); |
| | | } |
| | | |
| | | } |
| | |
| | | this.AddChidren(saveView.FLayoutView()); |
| | | saveView.btnClick.MouseUpEventHandler += (sen, e) => |
| | | { |
| | | |
| | | |
| | | if (selectedState != "unknown") |
| | | { |
| | | if (edit) |
| | | if (if_type == LogicMethod.condition_if) |
| | | { |
| | | //移除旧数据 |
| | | Logic.currlogic.input.RemoveAt(index); |
| | | //新数据插入旧数据的位置; |
| | | Logic.currlogic.input.Insert(index, inputdevice); |
| | | |
| | | Input inputDevice = new Input(); |
| | | inputDevice.condition_type = "3"; |
| | | inputDevice.sid = device.sid; |
| | | inputDevice.condition = dicSateteList; |
| | | |
| | | |
| | | if (edit) |
| | | { |
| | | //移除旧数据 |
| | | Logic.currlogic.input.RemoveAt(index); |
| | | //新数据插入旧数据的位置; |
| | | Logic.currlogic.input.Insert(index, inputDevice); |
| | | } |
| | | else |
| | | { |
| | | //添加一个条件 |
| | | AddCondition(inputDevice); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | //添加一个新的时间点条件 |
| | | Logic.currlogic.input.Add(inputdevice); |
| | | 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 |
| | |
| | | this.RemoveFromParent(); |
| | | return; |
| | | } |
| | | RemoveViewByTag("Logic"); |
| | | LogicMethod.RemoveAllView(); |
| | | AddLogic addLogic = new AddLogic(); |
| | | MainPage.BasePageView.AddChidren(addLogic); |
| | | addLogic.Show(); |
| | |
| | | /// 移除控件 |
| | | /// </summary> |
| | | /// <param name="frame"></param> |
| | | public void RemView(FrameLayout frame) |
| | | private void RemView(FrameLayout frame) |
| | | { |
| | | frame.RemoveFromParent(); |
| | | } |
| | | |
| | | public void GetState(Entity.Function device, bool edit, int index,Button button1,Button button2,Button button3,Button button4) |
| | | /// <summary> |
| | | /// 显示编辑之前的设备状态 |
| | | /// </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) |
| | | { |
| | | if (edit) |
| | | var dicList = new List<Dictionary<string, string>>(); |
| | | switch (if_type) |
| | | { |
| | | Input inputs = Logic.currlogic.input[index]; |
| | | var dicList = inputs.condition as List<Dictionary<string, string>>; |
| | | switch (device.functionType) |
| | | { |
| | | //开关灯光 |
| | | case FunctionType.Relay: |
| | | case LogicMethod.condition_if: |
| | | { |
| | | Input inputs = Logic.currlogic.input[index]; |
| | | dicList = inputs.condition as List<Dictionary<string, string>>; |
| | | } |
| | | break; |
| | | case LogicMethod.target_if: |
| | | { |
| | | Output outputs = Logic.currlogic.output[index]; |
| | | dicList = outputs.status as List<Dictionary<string, string>>; |
| | | } |
| | | break; |
| | | } |
| | | switch (device.functionType) |
| | | { |
| | | //开关灯光 |
| | | case FunctionType.Relay: |
| | | { |
| | | foreach (var dic in dicList) |
| | | { |
| | | foreach (var dic in dicList) |
| | | string value = dic["value"]; |
| | | if (value == "on") |
| | | { |
| | | string value = dic["value"]; |
| | | //if (value == "on") |
| | | //{ |
| | | // relayView.btnState.Text = Language.StringByID(StringId.onLogic); |
| | | |
| | | //} |
| | | //else |
| | | //{ |
| | | // relayView.btnState.Text = Language.StringByID(StringId.offLogic); |
| | | //} |
| | | button1.Text = Language.StringByID(StringId.onLogic); |
| | | } |
| | | else |
| | | { |
| | | button1.Text = Language.StringByID(StringId.offLogic); |
| | | } |
| | | } |
| | | 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="input"></param> |
| | | private void AddCondition(Input input) |
| | | { |
| | | int indexValue = -1; |
| | | for (int i = 0; i < Logic.currlogic.input.Count; i++) |
| | | { |
| | | if (Logic.currlogic.input[i].sid == input.sid) |
| | | { |
| | | indexValue = i; |
| | | break; |
| | | } |
| | | } |
| | | |
| | | if (indexValue != -1) |
| | | { |
| | | Logic.currlogic.input.RemoveAt(indexValue); |
| | | Logic.currlogic.input.Insert(indexValue, input); |
| | | } |
| | | else |
| | | { |
| | | Logic.currlogic.input.Add(input); |
| | | } |
| | | |
| | | } |
| | | /// <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); |
| | | } |
| | | |
| | | } |
| | | } |
| | | } |