wei
2021-07-05 90fadf3023d54d780154eaa2a839e2106317297f
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
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
        }
        /// <summary>
        /// 温度,湿度弹框设置值
        /// </summary>
        /// <param name="textInt">文本</param>
        /// <param name="stateValue">编辑之前的状态值,默认为20</param>
        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 = "outdoor_temp";
                            comparator = ">";
                        }
                        break;
                    case StringId.wendudiyu:
                        {
                            keyValue = "outdoor_temp";
                            comparator = "<";
                        }
                        break;
                    case StringId.shidugaoyu:
                        {
                            keyValue = "outdoor_humity";
                            comparator = ">";
                        }
                        break;
                    case StringId.shidudiyu:
                        {
                            keyValue = "outdoor_humity";
                            comparator = "<";
                        }
                        break;
                }
 
                AddDic(keyValue, comparator, value);
            });
        }
        /// <summary>
        /// PM2.5设置值
        /// </summary>
        /// <param name="frame">当前界面</param>
        /// <param name="stateValue">编辑之前的状态值,默认为""</param>
        public void PmAction(FrameLayout frame, string stateValue = "")
        {
            PublicInterface pmView = new PublicInterface();
            var pmListStr = pmView.GetViewList("pm2.5");
            pmView.SingleSelectionShow(frame, pmListStr, Language.StringByID(StringId.PM25), GetString(stateValue)
               , (text) =>
               {
                   string value = "";
                   if (text == Language.StringByID(StringId.pmyou))
                   {
                       value = "10";
                   }
                   else if (text == Language.StringByID(StringId.pmliang))
                   {
                       value = "50";
                   }
                   else if (text == Language.StringByID(StringId.pmqingdu))
                   {
                       value = "90";
                   }
                   else if (text == Language.StringByID(StringId.pmzhongdu))
                   {
                       value = "130";
                   }
                   else if (text == Language.StringByID(StringId.pmzhongduwuran))
                   {
                       value = "170";
                   }
                   AddDic("pm2.5", "=", value);
               });
        }
        /// <summary>
        /// 封装数据
        /// </summary>
        /// <param name="keyValue">类型值(pm2.5;outdoor_temp;outdoor_humity)</param>
        /// <param name="comparator">比较关系</param>
        /// <param name="value">值</param>
        private void AddDic(string keyValue, string comparator, string value)
        {
            Input input = new Input();
            input.sid = LogicMethod.NewSid();
            input.condition_type = "4";
            Dictionary<string, string> dic = new Dictionary<string, string>();
            LogicMethod.dictionary(dic, "key", keyValue);
            LogicMethod.dictionary(dic, "comparator", comparator);
            LogicMethod.dictionary(dic, "data_type", "float");
            LogicMethod.dictionary(dic, "value", value);
            input.condition.Add(dic);
            AddCondition(input, keyValue, comparator);
        }
        /// <summary>
        /// 添加条件
        /// </summary>
        /// <param name="input"></param>
        /// <param name="keyValue"></param>
        /// <param name="comparator">比较关系</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 == "4")
                {
                    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.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;
        }
 
 
        public string GetString(string strValue)
        {
            string text = "";
            int intValue = 0;
            if (strValue != "")
            {
                intValue = int.Parse(strValue);
            }
            if (intValue > 0 && intValue < 35)
            {
                text = Language.StringByID(StringId.pmyou);
            }
            else if (intValue > 35 && intValue < 75)
            {
                text = Language.StringByID(StringId.pmliang);
            }
            else if (intValue > 75 && intValue < 115)
            {
                text = Language.StringByID(StringId.pmqingdu);
            }
            else if (intValue > 115 && intValue < 150)
            {
                text = Language.StringByID(StringId.pmzhongdu);
            }
            else if (intValue > 150)
            {
                text = Language.StringByID(StringId.pmzhongduwuran);
            }
 
            return text;
        }
    }
}