wxr
2021-11-19 a170a2ecef6d5c87883ed552dbbc81cfb0358d13
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
using System;
using System.Collections.Generic;
using Shared;
namespace HDL_ON.UI.UI2.Intelligence.Automation
{
    public class WeatherCondition : FrameLayout
    {
        public WeatherCondition()
        {
            Tag = "Logic";
        }
        public void Show()
        {
            #region  界面布局
            LogicView.TopView topView = new LogicView.TopView();
            topView.frameLayout.Height = Application.GetRealHeight(64 + 20);
            this.AddChidren(topView.FLayoutView());
            topView.topNameBtn.TextID = StringId.selectionCondition;
            topView.Location();
            topView.clickBackBtn.MouseUpEventHandler += (e, sen) =>
            {
                RemoveFromParent();
            };
 
            FrameLayout viewLayout = new FrameLayout
            {
                Y = Application.GetRealHeight(64 + 20),
                Width = Application.GetRealWidth(LogicView.TextSize.view375),
                Height = Application.GetRealHeight(LogicView.TextSize.view667 - 64 - 20),
                BackgroundColor = CSS.CSS_Color.viewMiddle,
            };
            this.AddChidren(viewLayout);
            #endregion
 
            var list = new List<string> {
                Language.StringByID(StringId.clearday),
                Language.StringByID(StringId.cloudy),
                Language.StringByID(StringId.rain),
            };
            for (int i = 0; i < list.Count; i++)
            {
                LogicView.SelectTypeView view = new LogicView.SelectTypeView();
                view.frameLayout.Y = Application.GetRealHeight(i * 50);
                view.btnIcon.Visible = false;
                view.btnNextIcon.Visible = false;
                view.btnText.X = Application.GetRealWidth(16);
                view.btnLine.X = Application.GetRealWidth(16);
                view.btnLine.Width = Application.GetRealWidth(375 - 16 - 16);
                view.btnText.Text = list[i];
                view.btnClick.Tag = list[i];
                viewLayout.AddChidren(view.FLayoutView());
 
                view.btnClick.MouseUpEventHandler += (sen, e) =>
                {
                    string value = "";
                    string text = view.btnClick.Tag.ToString();
                    if (text == Language.StringByID(StringId.clearday))
                    {
                        value = "Sunny";
                    }
                    else if (text == Language.StringByID(StringId.cloudy))
                    {
                        value = "Cloudy";
                    }
                    else if (text == Language.StringByID(StringId.rain))
                    {
                        value = "Rain";
                    }
                    AddDic(value);
                };
            }
 
        }
        /// <summary>
        /// 封装数据
        /// </summary>
        /// <param name="value"></param>
        private void AddDic(string value)
        {
            Input input = new Input(); 
            input.sid = LogicMethod.CurrLogicMethod.NewSid();
            input.condition_type = "6";
            Dictionary<string, string> dic = new Dictionary<string, string>();
            LogicMethod.CurrLogicMethod.dictionary(dic, "key", "weather");
            LogicMethod.CurrLogicMethod.dictionary(dic, "comparator", "=");
            LogicMethod.CurrLogicMethod.dictionary(dic, "data_type", "string");
            LogicMethod.CurrLogicMethod.dictionary(dic, "value", value);
            input.condition.Add(dic);
            AddCondition(input, "weather",  "=");
        }
        /// <summary>
        /// 添加条件
        /// </summary>
        /// <param name="input"></param>
        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;
                    }
                    ///找到标记索引,退出循环体
                    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;
 
        }
        /// <summary>
        /// 判断是否存在Key
        /// </summary>
        /// <param name="dicList"></param>
        /// <param name="keyValue"></param>
        /// <param name="comparator">比较关系</param>
        /// <returns></returns>
        private bool ExistKey(List<Dictionary<string, string>> 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;
        }
    }
}