wxr
2020-12-17 1a13c963a5fb8cad92bf03667e411f46d6a6a843
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
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
using System;
using System.Collections.Generic;
using Shared;
namespace HDL_ON.UI.UI2.Intelligence.Automation
{
    public class TimeTpye : FrameLayout
    {
        public TimeTpye()
        {
            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.selectionTimeCondition;
 
            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 timepointView = new LogicView.SelectTypeView();
            timepointView.btnIcon.Visible = false;
            timepointView.btnText.X = Application.GetRealWidth(16);
            timepointView.btnLine.X = Application.GetRealWidth(16);
            timepointView.btnLine.Width = Application.GetRealWidth(375 - 16 - 16);
            timepointView.btnText.TextID = StringId.hour;
            viewLayout.AddChidren(timepointView.FLayoutView());
 
            //时间范围
            LogicView.SelectTypeView timeHorizonView = new LogicView.SelectTypeView();
            timeHorizonView.frameLayout.Y = timepointView.frameLayout.Bottom;
            timeHorizonView.btnIcon.Visible = false;
            timeHorizonView.btnText.X = Application.GetRealWidth(16);
            timeHorizonView.btnLine.X = Application.GetRealWidth(16);
            timeHorizonView.btnLine.Width = Application.GetRealWidth(375 - 16 - 16);
            timeHorizonView.btnText.TextID = StringId.timeHorizon;
            viewLayout.AddChidren(timeHorizonView.FLayoutView());
 
            #endregion
 
            #region  时间点  时间范围点击事件
            //时间点点击事件
            timepointView.btnClick.MouseUpEventHandler += (sen, e) =>
            {
                //主界面控件
                FrameLayout fLayout = new FrameLayout
                {
                    BackgroundColor = CSS.CSS_Color.viewTrans60lucence,
                };
                this.AddChidren(fLayout);
                TimePoint(fLayout, false, 100);
 
            };
            //时间范围点击事件
            timeHorizonView.btnClick.MouseUpEventHandler += (sen, e) =>
            {
                //主界面控件
                FrameLayout fLayout = new FrameLayout
                {
                    BackgroundColor = CSS.CSS_Color.viewTrans60lucence,
                };
                //添加主界面
                this.AddChidren(fLayout);
                //var fLayout = GetFrame(this,"2");
 
                TimeHorizon(fLayout, false, 0);
            };
 
            #endregion
        }
 
        /// <summary>
        /// 时间点方法
        /// </summary>
        /// <param name="fLayout">在哪个界面显示</param>
        /// <param name="edit">(true=编辑;false=新建)</param>
        /// <param name="index">编辑条件的索引</param>
        public void TimePoint(FrameLayout fLayout, bool edit, int index)
        {
            LogicView.TimeView timePointView = new LogicView.TimeView();
            timePointView.FLayoutView(fLayout);
            EventHandler<MouseEventArgs> removefLayout = (sender, e1) =>
             {
                 //移除fLayout界面
                 fLayout.RemoveFromParent();
             };
            //取消点击事件
            timePointView.btnCancel.MouseUpEventHandler += removefLayout;
 
            //加载数据界面的设置方法(列表互不联动)
            timePointView.mUIPickerView.setNPicker(timePointView.GethStringList(), timePointView.GetmStringList(), null);
 
            var systemHour = DateTime.Now.Hour; //获取小时
            var systeMinute = DateTime.Now.Minute;//获取分钟
            int systemHourIndex = 0;
            int systeMinuteIndex = 0;
            for (int i = 0; i < timePointView.GethIntList0().Count; i++)
            {
                var currhour = timePointView.GethIntList0()[i];
                if (systemHour == currhour)
                {
                    systemHourIndex = i;
                    break;
                }
            }
            for (int i = 0; i < timePointView.GetmIntList().Count; i++)
            {
                var currminute = timePointView.GetmIntList()[i];
                if (systeMinute == currminute)
                {
                    systeMinuteIndex = i;
                    break;
                }
            }
 
            //默认初始选中状态
            timePointView.mUIPickerView.setCurrentItems(systemHourIndex, systeMinuteIndex, 0);
            string currH = "";
            string currM = "";
            if (systemHour < 10)
            {
                currH = "0" + systemHour.ToString();
            }
            else
            {
                currH = systemHour.ToString();
            }
            if (systeMinute < 10)
            {
                currM = "0" + systeMinute.ToString();
            }
            else
            {
                currM = systeMinute.ToString();
            }
            //定义一个局部变量记录选中时间
            string timepoint = currH + ":" + currM;
            if (edit)
            {
                Input inputs = Logic.currlogic.input[index];
                if (inputs.condition_type == "1")
                {
                    List<Dictionary<string, string>> dicList = inputs.condition as List<Dictionary<string, string>>;
                    foreach (var dic in dicList)
                    {
                        string timeValue = dic["value"];
                        int hIndex = timePointView.GetValueIndex(timeValue, 0, 1, timePointView.GethIntList());
                        int mIndex = timePointView.GetValueIndex(timeValue, 1, 0, timePointView.GetmIntList());
                        //更新初始状态
                        timePointView.mUIPickerView.setCurrentItems(hIndex - 1, mIndex, 0);
                        timepoint = timeValue;
                    }
                }
            }
 
            //选中时间回调方法,时间变化一次回调一次
            timePointView.mUIPickerView.OnSelectChangeEvent += (index1, index2, index3) =>
            {
                string hour = timePointView.GethStringList()[index1].Split(' ')[0];
                string minuet = timePointView.GetmStringList()[index2].Split(' ')[0];
                timepoint = hour + ":" + minuet;
            };
            //确定点击事件
            timePointView.btnConfirm.MouseUpEventHandler += (sender, e3) =>
            {
                Input inputTime = new Input();
                inputTime.sid = LogicMethod.NewSid();
                inputTime.condition_type = "1";
                Dictionary<string, string> dic = new Dictionary<string, string>();
                LogicMethod.dictionary(dic, "key", "timepoint");
                LogicMethod.dictionary(dic, "comparator", "=");
                LogicMethod.dictionary(dic, "data_type", "string");
                LogicMethod.dictionary(dic, "value", timepoint);
                inputTime.condition.Add(dic);
                if (edit)
                {
                    //移除旧数据
                    Logic.currlogic.input.RemoveAt(index);
                    //新数据插入旧数据的位置;
                    Logic.currlogic.input.Insert(index, inputTime);
                }
                else
                {
                    //添加一个新的时间点条件
                    Logic.currlogic.input.Add(inputTime);
                }
                LogicMethod.RemoveAllView();
                AddLogic addLogic = new AddLogic();
                MainPage.BasePageView.AddChidren(addLogic);
                addLogic.Show();
                MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
 
            };
        }
        /// <summary>
        /// 时间范围方法
        /// </summary>
        /// <param name="fLayout">在哪个界面显示</param>
        /// <param name="edit">(true=编辑;false=新建)</param>
        /// <param name="index">编辑条件的索引</param>
        public void TimeHorizon(FrameLayout fLayout, bool edit, int index)
        {
            #region 界面布局
            LogicView.TimeHorizonView timeHorizonView = new LogicView.TimeHorizonView();
            timeHorizonView.FLayoutView(fLayout);
            //开始时间
            LogicView.SelectTypeView startTimeView = new LogicView.SelectTypeView();
            startTimeView.frameLayout.Y = Application.GetRealHeight(87);
            startTimeView.btnIcon.Visible = false;
            startTimeView.btnText.X = Application.GetRealWidth(16);
            startTimeView.btnText.TextID = StringId.startTime;
            startTimeView.btnLine.X = Application.GetRealWidth(16);
            startTimeView.btnLine.Width = Application.GetRealWidth(375 - 16 - 16);
            startTimeView.btnNextIcon.X = Application.GetRealWidth(307);
            timeHorizonView.frameLayout.AddChidren(startTimeView.FLayoutView());
            //显示开始时间文本
            Button btnStartTimeText = new Button
            {
                TextSize = LogicView.TextSize.text12,
                Width = Application.GetRealWidth(32 + 3+20),
                Height = Application.GetRealHeight(17),
                TextColor = CSS.CSS_Color.textCancelColor,
                Y = Application.GetRealHeight(17),
                X = Application.GetRealWidth(260-20),
                Tag = "0",
            };
            startTimeView.frameLayout.AddChidren(btnStartTimeText);
 
            //结束时间
            LogicView.SelectTypeView endTimeView = new LogicView.SelectTypeView();
            endTimeView.frameLayout.SetCornerWithSameRadius(Application.GetRealHeight(12), HDLUtils.RectCornerBottomLeft | HDLUtils.RectCornerBottomRight);
            endTimeView.frameLayout.Y = startTimeView.frameLayout.Bottom;
            endTimeView.btnIcon.Visible = false;
            endTimeView.btnLine.Visible = false;
            endTimeView.btnText.X = Application.GetRealWidth(16);
            endTimeView.btnText.TextID = StringId.endTime;
            endTimeView.btnNextIcon.X = Application.GetRealWidth(307);
            timeHorizonView.frameLayout.AddChidren(endTimeView.FLayoutView());
            //显示结束时间文本
            Button btnEndTimeText = new Button
            {
                TextSize = LogicView.TextSize.text12,
                Width = Application.GetRealWidth(32 + 3+20),
                Height = Application.GetRealHeight(17),
                TextColor = CSS.CSS_Color.textCancelColor,
                Y = Application.GetRealHeight(17),
                X = Application.GetRealWidth(260-20),
                Tag = "0",
            };
            endTimeView.frameLayout.AddChidren(btnEndTimeText);
 
            #endregion
 
            #region 点击事件
            //开始时间点击事件
            EventHandler<MouseEventArgs> StartTimeClick = (sender,e) => {
                SelectedTimeHorizon(fLayout, btnStartTimeText);
            };
            startTimeView.btnClick.MouseUpEventHandler += StartTimeClick;
            btnStartTimeText.MouseUpEventHandler += StartTimeClick;
            //结束时间点击事件
            EventHandler<MouseEventArgs> EndTimeClick = (sender, e) => {
                SelectedTimeHorizon(fLayout, btnEndTimeText);
            };
            endTimeView.btnClick.MouseUpEventHandler += EndTimeClick;
            btnEndTimeText.MouseUpEventHandler += EndTimeClick;
 
           
            //确定点击事件
            timeHorizonView.btnConfirm.MouseUpEventHandler += (sender, e) =>
            {
                if (btnStartTimeText.Tag.ToString() == "0")
                {
                    //提示:请选中开始时间
                    return;
                }
                if (btnEndTimeText.Tag.ToString() == "0")
                {
                    //提示:请选中结束时间
                    return;
                }
                if (btnStartTimeText.Tag.ToString() == btnEndTimeText.Tag.ToString())
                {
                    //提示:时间一样的
                    return;
                }
                if (int.Parse(btnStartTimeText.Tag.ToString()) > int.Parse(btnEndTimeText.Tag.ToString()))
                {
                    //提示:开始时间不能大于结束时间
                    return;
                }
 
                Input inputTime = new Input();
                inputTime.sid = LogicMethod.NewSid();
                inputTime.condition_type = "2";
                Dictionary<string, string> dic = new Dictionary<string, string>();
                LogicMethod.dictionary(dic, "key", "timesection");
                LogicMethod.dictionary(dic, "comparator", "=");
                LogicMethod.dictionary(dic, "data_type", "string");
                LogicMethod.dictionary(dic, "value", btnStartTimeText.Text + "-" + btnEndTimeText.Text);
                inputTime.condition.Add(dic);
                if (edit)
                {
                    //移除旧数据
                    Logic.currlogic.input.RemoveAt(index);
                    //新数据插入旧数据的位置
                    Logic.currlogic.input.Insert(index, inputTime);
                    fLayout.RemoveFromParent();
                }
                else
                {
                    //添加一个新的时间点条件
                    Logic.currlogic.input.Add(inputTime);
                }
                LogicMethod.RemoveAllView();
                AddLogic addLogic = new AddLogic();
                MainPage.BasePageView.AddChidren(addLogic);
                addLogic.Show();
                MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
 
 
            };
            #endregion
 
            if (edit)
            {
                Input inputs = Logic.currlogic.input[index];
                if (inputs.condition_type == "2")
                {
                    List<Dictionary<string, string>> dicList = inputs.condition as List<Dictionary<string, string>>;
                    foreach (var dic in dicList)
                    {
                        string value = dic["value"];
                        string startTime = value.Split('-')[0];
                        string endtTime = value.Split('-')[1];
                        btnStartTimeText.Text = startTime;
                        btnStartTimeText.Tag = int.Parse(startTime.Split(':')[0]) * 60 + int.Parse(startTime.Split(':')[1]);
                        btnEndTimeText.Text = endtTime;
                        btnEndTimeText.Tag = int.Parse(endtTime.Split(':')[0]) * 60 + int.Parse(endtTime.Split(':')[1]);
                    }
                }
            }
        }
        /// <summary>
        /// 设置时间段时间的方法
        /// </summary>
        /// <param name="fLayout"></param>
        /// <param name="btn"></param>
        public void SelectedTimeHorizon(FrameLayout fLayout, Button btn)
        {
 
            LogicView.TimeView timePointView = new LogicView.TimeView();
            timePointView.FLayoutView(fLayout);
            EventHandler<MouseEventArgs> RemovefLayout = (sender, e1) =>
            {
                //只移除时间弹窗界面
                timePointView.frameLayout.RemoveFromParent();
            };
            //取消点击事件
            timePointView.btnCancel.MouseUpEventHandler += RemovefLayout;
            //加载数据界面的设置方法(列表互不联动)
            timePointView.mUIPickerView.setNPicker(timePointView.GethStringList(), timePointView.GetmStringList(), null);
 
            var systemHour = DateTime.Now.Hour; //获取小时
            var systeMinute = DateTime.Now.Minute;//获取分钟
            int systemHourIndex = 0;
            int systeMinuteIndex = 0;
            for (int i = 0; i < timePointView.GethIntList0().Count; i++)
            {
                var currhour = timePointView.GethIntList0()[i];
                if (systemHour == currhour)
                {
                    systemHourIndex = i;
                    break;
                }
            }
            for (int i = 0; i < timePointView.GetmIntList().Count; i++)
            {
                var currminute = timePointView.GetmIntList()[i];
                if (systeMinute == currminute)
                {
                    systeMinuteIndex = i;
                    break;
                }
            }
 
            //默认初始选中状态
            timePointView.mUIPickerView.setCurrentItems(systemHourIndex, systeMinuteIndex, 0);
            string currH = "";
            string currM = "";
            if (systemHour < 10)
            {
                currH = "0" + systemHour.ToString();
            }
            else
            {
                currH = systemHour.ToString();
            }
            if (systeMinute < 10)
            {
                currM = "0" + systeMinute.ToString();
            }
            else
            {
                currM = systeMinute.ToString();
            }
            //定义一个局部变量记录选中时间
            string timepoint = currH + ":" + currM;
            int sumTime = systemHour*60+ systeMinute;
 
            if (btn.Tag.ToString() != "0")
            {
                string h = "", m = "";
                sumTime = int.Parse(btn.Tag.ToString());
                if ((sumTime / 60) < 10)
                {
                    h = "0" + (sumTime / 60).ToString();
                }
                else
                {
                    h = (sumTime / 60).ToString();
                }
 
                if ((sumTime % 60) < 10)
                {
                    m = "0" + (sumTime % 60).ToString();
                }
                else
                {
                    m = (sumTime % 60).ToString();
                }
                timepoint = h + ":" + m;
 
                int hourIndex = timePointView.GetValueIndex(timepoint, 0, 1, timePointView.GethIntList());
                int minuteIndex = timePointView.GetValueIndex(timepoint, 1, 0, timePointView.GetmIntList());
                //更新状态
                timePointView.mUIPickerView.setCurrentItems(hourIndex - 1, minuteIndex, 0);
            }
 
            //选中时间回调方法,时间变化一次回调一次
            timePointView.mUIPickerView.OnSelectChangeEvent += (index1, index2, index3) =>
            {
 
                string hour = timePointView.GethStringList()[index1].Split(' ')[0];
                string minuet = timePointView.GetmStringList()[index2].Split(' ')[0];
                timepoint = hour + ":" + minuet;
                sumTime = int.Parse(hour) * 60 + int.Parse(minuet);
 
 
            };
            //确定点击事件
            timePointView.btnConfirm.MouseUpEventHandler += (sender1, e3) =>
            {
                btn.Tag = sumTime;
                btn.Text = timepoint;
                //只移除时间弹窗界面
                timePointView.frameLayout.RemoveFromParent();
            };
        }
        /// <summary>
        /// 灰色弹框父控件
        /// </summary>
        /// <param name="frame">显示在哪个界面</param>
        /// <returns></returns>
        public FrameLayout GetFrame(FrameLayout frame, string tagKey)
        {
            for (int i = 0; i < frame.ChildrenCount; i++)
            {
                var fra = frame.GetChildren(i);
                if (fra != null)
                {
                    fra.RemoveFromParent();
                }
            }
 
 
            FrameLayout fLayout = new FrameLayout()
            {
                BackgroundColor = CSS.CSS_Color.viewTrans60lucence,
 
            };
            frame.AddChidren(fLayout);
 
 
            return fLayout;
        }
    }
}