JLChen
2021-05-14 3bedb23993745f97e5870eca160c9f00c053c44c
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
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
using Shared;
using HDL_ON.UI.CSS;
using HDL_ON.Stan;
using System;
using System.Collections.Generic;
using System.Text;
using HDL_ON.Entity;
 
namespace HDL_ON.UI
{
    /// <summary>
    /// 门锁常开自动化编辑界面
    /// </summary>
    public class DoorLockAlwaysOnManagerPage : EditorCommonForm
    {
        #region ■ 变量声明___________________________
 
        /// <summary>
        /// 常开自动化信息
        /// </summary>
        private AlwayOnAutomationInfo automationInfo = null;
        /// <summary>
        /// 一些文本
        /// </summary>
        private Dictionary<string, string> dicText = new Dictionary<string, string>();
 
        #endregion
 
        #region ■ 初始化_____________________________
 
        /// <summary>
        /// 画面显示(底层会固定调用此方法,借以完成画面创建)
        /// </summary>
        public void ShowForm(AlwayOnAutomationInfo info)
        {
            this.automationInfo = info;
            if (info == null)
            {
                this.automationInfo = new AlwayOnAutomationInfo();
                //新建自动化
                base.SetTitleText(Language.StringByID(StringId.newAutomation));
            }
            else
            {
                //编辑自动化
                base.SetTitleText(Language.StringByID(StringId.editAutomation));
            }
 
            this.dicText["周1"] = Language.StringByID(StringId.monday);
            this.dicText["周2"] = Language.StringByID(StringId.tuesday);
            this.dicText["周3"] = Language.StringByID(StringId.wednesday);
            this.dicText["周4"] = Language.StringByID(StringId.thursday);
            this.dicText["周5"] = Language.StringByID(StringId.friday);
            this.dicText["周6"] = Language.StringByID(StringId.saturday);
            this.dicText["周7"] = Language.StringByID(StringId.sunday);
 
            //初始化中部信息
            this.InitMiddleFrame();
        }
 
        /// <summary>
        /// 初始化中部信息
        /// </summary>
        private void InitMiddleFrame()
        {
            //清空bodyFrame
            this.ClearBodyFrame();
 
            //初始化条件控件
            this.InitConditionControl();
            //初始化目标控件
            this.InitTargetControl();
            //初始化循环方式控件
            this.InitLoopControl();
 
            //确认按钮
            var btnSave = this.AddBottomClickButton(Language.StringByID(StringId.Confirm));
            btnSave.ButtonClickEvent += (sender, e) =>
            {
            };
        }
 
        #endregion
 
        #region ■ 初始化条件控件_____________________
 
        /// <summary>
        /// 初始化条件控件
        /// </summary>
        private void InitConditionControl()
        {
            //如果
            var btnIf = new NormalViewControl(300, 22, true);
            btnIf.X = HdlControlResourse.XXLeft;
            btnIf.Y = Application.GetRealHeight(12);
            btnIf.TextID = StringId.ifCondition;
            btnIf.TextSize = CSS_FontSize.SubheadingFontSize;
            btnIf.TextColor = CSS_Color.FirstLevelTitleColor;
            btnIf.IsBold = true;
            bodyFrameLayout.AddChidren(btnIf);
 
            //白色背景容器
            var frameBack = new FrameLayout();
            frameBack.Y = btnIf.Bottom + Application.GetRealHeight(12);
            frameBack.Width = Application.GetRealWidth(343);
            frameBack.Height = Application.GetRealHeight(88);
            frameBack.Gravity = Gravity.CenterHorizontal;
            frameBack.BackgroundColor = CSS_Color.MainBackgroundColor;
            frameBack.Radius = (uint)Application.GetRealWidth(12);
            bodyFrameLayout.AddChidren(frameBack);
 
            //条件
            var rowConditon = new FrameRowControl();
            rowConditon.LeftOffset = Application.GetRealWidth(12) - HdlControlResourse.XXLeft;
            rowConditon.Width = frameBack.Width;
            frameBack.AddChidren(rowConditon);
            var btnConditon = rowConditon.AddLeftCaption(Language.StringByID(StringId.Condtion), 300);
            btnConditon.TextColor = CSS_Color.FirstLevelTitleColor;
            //底线
            rowConditon.AddBottomLine();
 
            //时刻
            var rowTime = new FrameRowControl();
            rowTime.Y = rowConditon.Bottom;
            rowTime.LeftOffset = Application.GetRealWidth(12) - HdlControlResourse.XXLeft;
            rowTime.Width = frameBack.Width;
            frameBack.AddChidren(rowTime);
            rowTime.AddLeftIcon(28, "LogicIcon/time.png");
            var btnTime = rowTime.AddLeftCaption(Language.StringByID(StringId.hour), 300);
            btnTime.TextColor = CSS_Color.FirstLevelTitleColor;
            rowTime.AddRightArrow();
            var btnValue = rowTime.AddMostRightView(this.automationInfo.Hour + ":" + this.automationInfo.Minute.ToString().PadLeft(2, '0'), 80);
            rowTime.ButtonClickEvent += (sender, e) =>
            {
                //时间选择弹窗
                var form = new BottomTimeSelectControl();
                form.InitControl(this.automationInfo.Hour, this.automationInfo.Minute);
                form.FinishEvent += (div, selectHour, selectMin) =>
                {
                    if (div != 1) { return; }
                    this.automationInfo.Hour = selectHour;
                    this.automationInfo.Minute = selectMin;
                    btnValue.Text = this.automationInfo.Hour + ":" + this.automationInfo.Minute.ToString().PadLeft(2, '0');
                };
            };
        }
 
        #endregion
 
        #region ■ 初始化目标控件_____________________
 
        /// <summary>
        /// 初始化目标控件
        /// </summary>
        private void InitTargetControl()
        {
            //就执行
            var btnExecuted = new NormalViewControl(300, 22, true);
            btnExecuted.X = HdlControlResourse.XXLeft;
            btnExecuted.Y = Application.GetRealHeight(154);
            btnExecuted.TextID = StringId.isExecuted;
            btnExecuted.TextSize = CSS_FontSize.SubheadingFontSize;
            btnExecuted.TextColor = CSS_Color.FirstLevelTitleColor;
            btnExecuted.IsBold = true;
            bodyFrameLayout.AddChidren(btnExecuted);
 
            //白色背景容器
            var frameBack = new FrameLayout();
            frameBack.Y = btnExecuted.Bottom + Application.GetRealHeight(12);
            frameBack.Width = Application.GetRealWidth(343);
            frameBack.Height = Application.GetRealHeight(88);
            frameBack.Gravity = Gravity.CenterHorizontal;
            frameBack.BackgroundColor = CSS_Color.MainBackgroundColor;
            frameBack.Radius = (uint)Application.GetRealWidth(12);
            bodyFrameLayout.AddChidren(frameBack);
 
            //动作行控件
            var rowAction = new FrameRowControl();
            rowAction.LeftOffset = Application.GetRealWidth(12) - HdlControlResourse.XXLeft;
            rowAction.Width = frameBack.Width;
            frameBack.AddChidren(rowAction);
            //动作
            var btnAction = rowAction.AddLeftCaption(Language.StringByID(StringId.Action), 300);
            btnAction.TextColor = CSS_Color.FirstLevelTitleColor;
            //底线
            rowAction.AddBottomLine();
 
            //常开模式行控件
            var rowModel = new FrameRowControl();
            rowModel.Y = rowAction.Bottom;
            rowModel.LeftOffset = Application.GetRealWidth(12) - HdlControlResourse.XXLeft;
            rowModel.Width = frameBack.Width;
            frameBack.AddChidren(rowModel);
            //图标
            rowModel.AddLeftIcon(28, "FunctionIcon/DoorLock/NormallyOpenIcon2.png");
            //常开模式
            var btnAlwayOn = rowModel.AddLeftCaption(Language.StringByID(StringId.AlwaysOnModel), 300);
            btnAlwayOn.TextColor = CSS_Color.FirstLevelTitleColor;
            //右箭头
            rowModel.AddRightArrow();
            //值
            var btnValue = rowModel.AddMostRightView(this.automationInfo.IsOpenAlwayOn == true ?
                Language.StringByID(StringId.kaiqi) : Language.StringByID(StringId.Close), 80);
 
            rowModel.ButtonClickEvent += (sender, e) =>
            {
                //选择弹窗
                var form = new BottomMenuSelectControl(2);
                //开启
                form.AddMenu(Language.StringByID(StringId.kaiqi), () =>
                {
                    this.automationInfo.IsOpenAlwayOn = true;
                    btnValue.Text = Language.StringByID(StringId.kaiqi);
                });
                //关闭
                form.AddMenu(Language.StringByID(StringId.Close), () =>
                {
                    this.automationInfo.IsOpenAlwayOn = false;
                    btnValue.Text = Language.StringByID(StringId.Close);
                },CSS_Color.PromptingColor1);
            };
        }
 
        #endregion
 
        #region ■ 初始化循环方式控件_________________
 
        /// <summary>
        /// 初始化循环方式控件
        /// </summary>
        private void InitLoopControl()
        {
            //循环方式
            var btnloop = new NormalViewControl(300, 22, true);
            btnloop.X = HdlControlResourse.XXLeft;
            btnloop.Y = Application.GetRealHeight(296);
            btnloop.TextID = StringId.cyclic;
            btnloop.TextSize = CSS_FontSize.SubheadingFontSize;
            btnloop.TextColor = CSS_Color.FirstLevelTitleColor;
            btnloop.IsBold = true;
            bodyFrameLayout.AddChidren(btnloop);
 
            //周期的白色背景容器
            var frameDayBack = new FrameLayout();
            frameDayBack.Y = btnloop.Bottom + Application.GetRealHeight(12);
            frameDayBack.Width = Application.GetRealWidth(343);
            frameDayBack.Height = Application.GetRealHeight(50);
            frameDayBack.Gravity = Gravity.CenterHorizontal;
            frameDayBack.BackgroundColor = CSS_Color.MainBackgroundColor;
            frameDayBack.Radius = (uint)Application.GetRealWidth(12);
            bodyFrameLayout.AddChidren(frameDayBack);
 
            //周期行控件
            var rowLoop = new FrameRowControl();
            rowLoop.LeftOffset = Application.GetRealWidth(12) - HdlControlResourse.XXLeft;
            rowLoop.Width = frameDayBack.Width;
            rowLoop.Height = Application.GetRealHeight(50);
            frameDayBack.AddChidren(rowLoop);
            //周期
            var cycleText = this.GetLoopCondtionText();
            var btnCycle = rowLoop.AddLeftCaption(cycleText, 270);
            btnCycle.TextColor = CSS_Color.FirstLevelTitleColor;
            btnCycle.IsMoreLines = false;//让它不换行了,不然有点难看
            //右箭头
            rowLoop.AddRightArrow();
            rowLoop.ButtonClickEvent += (sender, e) =>
            {
                //显示周期循环配置窗口
                this.ShowLoopMethordSettionDialog(btnCycle);
            };
 
            //推送的白色背景容器
            var framePushBack = new FrameLayout();
            framePushBack.Y = frameDayBack.Bottom + Application.GetRealHeight(8);
            framePushBack.Width = Application.GetRealWidth(343);
            framePushBack.Height = Application.GetRealHeight(100);
            framePushBack.Gravity = Gravity.CenterHorizontal;
            framePushBack.BackgroundColor = CSS_Color.MainBackgroundColor;
            framePushBack.Radius = (uint)Application.GetRealWidth(12);
            bodyFrameLayout.AddChidren(framePushBack);
 
            //推送行控件
            var rowPush = new FrameRowControl();
            rowPush.Width = framePushBack.Width;
            rowPush.Height = Application.GetRealHeight(50);
            rowPush.LeftOffset = Application.GetRealWidth(12) - HdlControlResourse.XXLeft;
            framePushBack.AddChidren(rowPush);
            //执行推送
            var btnPush = rowPush.AddLeftCaption(Language.StringByID(StringId.push), 300);
            btnPush.TextColor = CSS_Color.FirstLevelTitleColor;
            //底线
            rowPush.AddBottomLine();
            //推送的开关按钮
            var btnPushSwitch = rowPush.AddMostRightSwitchIcon();
            btnPushSwitch.ButtonClickEvent += (sender, e) =>
            {
                btnPushSwitch.IsSelected = !btnPushSwitch.IsSelected;
            };
 
            //发送通知行控件
            var rowNotice = new FrameRowControl();
            rowNotice.Y = rowPush.Bottom;
            rowNotice.Width = framePushBack.Width;
            rowNotice.Height = Application.GetRealHeight(50);
            rowNotice.LeftOffset = Application.GetRealWidth(12) - HdlControlResourse.XXLeft;
            framePushBack.AddChidren(rowNotice);
            //发送通知
            var btnNotice = rowNotice.AddLeftCaption(Language.StringByID(StringId.notification), 300);
            btnNotice.TextColor = CSS_Color.FirstLevelTitleColor;
            //右箭头
            rowNotice.AddRightArrow();
            rowNotice.ButtonClickEvent += (sender, e) =>
            {
                var form = new UI2.Intelligence.Automation.InputPushText();
                MainPage.BasePageView.AddChidren(form);
                //form.Show(this.automationInfo.PushSettion);
                form.Show();
                MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
                //form.action += (pushInfo) =>
                //{
                //    //赋值
                //    this.automationInfo.PushSettion = pushInfo;
                //};
            };
        }
 
        #endregion
 
        #region ■ 显示周期循环配置窗口_______________
 
        /// <summary>
        /// 显示周期循环配置窗口
        /// </summary>
        private void ShowLoopMethordSettionDialog(NormalViewControl btnCycle)
        {
            //之前选择的控件
            NormalViewControl btnOldView = null;
 
            var form = new BottomItemEditorControl(4, Language.StringByID(StringId.cyclic));
            form.ClickConfirmClose = false;
            //执行一次
            form.AddRowMenu(Language.StringByID(StringId.performA), string.Empty, (btnView, btnValue) =>
            {
                this.automationInfo.LoopDiv = 1;
                if (btnOldView != null)
                {
                    //还原颜色
                    btnOldView.TextColor = CSS_Color.FirstLevelTitleColor;
                }
                //变更颜色
                btnView.TextColor = CSS_Color.textConfirmColor;
                btnOldView = btnView;
                //变更显示文本
                btnCycle.Text = this.GetLoopCondtionText();
 
            }, false);
 
            //每天
            form.AddRowMenu(Language.StringByID(StringId.days), string.Empty, (btnView, btnValue) =>
            {
                this.automationInfo.LoopDiv = 2;
                if (btnOldView != null)
                {
                    //还原颜色
                    btnOldView.TextColor = CSS_Color.FirstLevelTitleColor;
                }
                //变更颜色
                btnView.TextColor = CSS_Color.textConfirmColor;
                btnOldView = btnView;
                //变更显示文本
                btnCycle.Text = this.GetLoopCondtionText();
 
            }, false);
 
            //每周
            form.AddRowMenu(Language.StringByID(StringId.weekly), string.Empty, (btnView, btnValue) =>
            {
                //关闭弹窗,显示周期循环(星期)的配置窗口
                form.Close();
                this.ShowLoopMethordWeekDialog(btnCycle);
            });
 
            //每月
            form.AddRowMenu(Language.StringByID(StringId.monthly), string.Empty, (btnView, btnValue) =>
            {
                //关闭弹窗,显示周期循环(月份)的配置窗口
                form.Close();
                this.ShowLoopMethordMonthDialog(btnCycle);
            });
 
            form.FinishEvent += (div) =>
            {
                //当点击了确认时,如果还没选择,则无反应
                if (div != 1 || btnOldView == null) { return; }
 
                form.Close();
            };
        }
 
        /// <summary>
        /// 显示周期循环(星期)的配置窗口
        /// </summary>
        private void ShowLoopMethordWeekDialog(NormalViewControl btnCycle)
        {
            //星期一到星期日
            var listText = new List<string>();
            listText.Add(this.dicText["周1"]);
            listText.Add(this.dicText["周2"]);
            listText.Add(this.dicText["周3"]);
            listText.Add(this.dicText["周4"]);
            listText.Add(this.dicText["周5"]);
            listText.Add(this.dicText["周6"]);
            listText.Add(this.dicText["周7"]);
 
            var listSelect = new List<int>();
            if (this.automationInfo.LoopDiv == 3)
            {
                //之前选择的是这个区分才能有默认选择
                foreach (var value in this.automationInfo.ListLoopValue)
                {
                    //默认选择
                    listSelect.Add(value - 1);
                }
            }
 
            var form = new BottomItemSelectControl(7, Language.StringByID(StringId.cyclic));
            form.AddRowMenu(listText, listSelect);
            form.FinishEvent += (div, listIndex) =>
            {
                if (div == 0)
                {
                    //如果点击了取消,则调起 周期循环配置窗口
                    this.ShowLoopMethordSettionDialog(btnCycle);
                    return;
                }
                //更改缓存
                this.automationInfo.LoopDiv = 3;
                this.automationInfo.ListLoopValue = new List<int>();
 
                foreach (var index in listIndex)
                {
                    this.automationInfo.ListLoopValue.Add(index + 1);
                }
                //变更显示文本
                btnCycle.Text = this.GetLoopCondtionText();
            };
        }
 
        /// <summary>
        /// 显示周期循环(月份)的配置窗口
        /// </summary>
        private void ShowLoopMethordMonthDialog(NormalViewControl btnCycle)
        {
            var listSelect = new List<int>();
            if (this.automationInfo.LoopDiv == 4)
            {
                //之前选择的是这个区分才能有默认选择
                foreach (var value in this.automationInfo.ListLoopValue)
                {
                    //默认选择
                    listSelect.Add(value);
                }
            }
 
            var form = new BottomSomeDaySelectControl(Language.StringByID(StringId.monthly));
            form.InitControl(listSelect);
            form.FinishEvent += (div, listIndex) =>
            {
                if (div == 0)
                {
                    //如果点击了取消,则调起 周期循环配置窗口
                    this.ShowLoopMethordSettionDialog(btnCycle);
                    return;
                }
                //更改缓存
                this.automationInfo.LoopDiv = 4;
                this.automationInfo.ListLoopValue = new List<int>();
 
                foreach (var day in listIndex)
                {
                    this.automationInfo.ListLoopValue.Add(day);
                }
                //变更显示文本
                btnCycle.Text = this.GetLoopCondtionText();
            };
        }
 
        #endregion
 
        #region ■ 一般方法___________________________
 
        /// <summary>
        /// 获取循环条件的翻译文本
        /// </summary>
        /// <returns></returns>
        private string GetLoopCondtionText()
        {
            //执行一次
            if (this.automationInfo.LoopDiv == 1)
            {
                return Language.StringByID(StringId.performA);
            }
            //每天
            else if (this.automationInfo.LoopDiv == 2)
            {
                return Language.StringByID(StringId.days);
            }
            //每周
            else if (this.automationInfo.LoopDiv == 3)
            {
                var textValue = string.Empty;
                foreach (var weekValue in this.automationInfo.ListLoopValue)
                {
                    textValue += this.dicText["周" + weekValue] + ",";
                }
                //去掉最后的逗号
                return textValue.Substring(0, textValue.Length - 1);
            }
            //每月
            else if (this.automationInfo.LoopDiv == 4)
            {
                var textValue = Language.StringByID(StringId.monthly) + " ";
                foreach (var day in this.automationInfo.ListLoopValue)
                {
                    textValue += day.ToString() + ",";
                }
                //去掉最后的逗号
                return textValue.Substring(0, textValue.Length - 1);
            }
            return string.Empty;
        }
 
        #endregion
    }
}