tzy
2021-05-25 65bcedda4d8e3ff6500dbf59a4e607d96e469375
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
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
using Shared;
using HDL_ON.Stan;
using System;
using System.Collections.Generic;
using System.Text;
using HDL_ON.UI.CSS;
using HDL_ON.Entity;
 
namespace HDL_ON.UI
{
    /// <summary>
    /// 门锁的控制界面
    /// </summary>
    public class DoorLockPage : DeviceFunctionCardCommonForm
    {
        #region ■ 变量声明___________________________
 
        /// <summary>
        /// 电池控件
        /// </summary>
        private BatteryPersentControl batteryControl = null;
        /// <summary>
        /// 在线图标控件
        /// </summary>
        private IconViewControl btnOnlineIcon = null;
        /// <summary>
        /// 在线文本控件
        /// </summary>
        private NormalViewControl btnOnlineView = null;
        /// <summary>
        /// 声音图标
        /// </summary>
        private IconViewControl btnVoice = null;
        /// <summary>
        /// 声音的滑动条控件
        /// </summary>
        private SeekBarImageControl seekBarVoiceControl = null;
        /// <summary>
        /// 声音百分比
        /// </summary>
        private NormalViewControl btnVoicePersent = null;
        /// <summary>
        /// 常开模式图标
        /// </summary>
        private IconViewControl btnNormallyOpenIcon = null;
        /// <summary>
        /// 中间的开锁或者关锁图片控件
        /// </summary>
        private PicViewControl picLockControl = null;
        /// <summary>
        /// 临时密码tab页中间的控件容器(它的Y轴是 一键开锁/临时密码开锁的底部(粗体字体)+4)
        /// </summary>
        private FrameLayout frameTempPsw = null;
        /// <summary>
        /// 1:选择的是一键开锁 2:选择的是临时密码开锁
        /// </summary>
        private int nowSelectMenu = 1;
        /// <summary>
        /// 门锁数据
        /// </summary>
        private DoorLockData doorLockData = new DoorLockData();
        /// <summary>
        /// 门锁的历史记录
        /// </summary>
        private List<DoorHistoryLog> listHistoryLog = null;
        /// <summary>
        /// 成员列表
        /// </summary>
        private List<ResidenceMemberInfo> listMember = null;
        /// <summary>
        /// 文本缓存
        /// </summary>
        private Dictionary<string, string> dicText = new Dictionary<string, string>();
 
        #endregion
 
        #region ■ 初始化_____________________________
 
        /// <summary>
        /// 门锁的控制界面
        /// </summary>
        public DoorLockPage()
        {
            //门锁不允许收藏
            this.ShowColltionButton = false;
        }
 
        /// <summary>
        /// 初始化白色区域的内容
        /// </summary>
        public override void InitFrameWhiteContent()
        {
            //智能门锁
            base.SetTitleText(Language.StringByID(StringId.DoorLock));
 
            this.dicText["已连接"] = Language.StringByID(StringId.Connected);
            this.dicText["未连接"] = Language.StringByID(StringId.UnConnected);
 
            //左右翻页的事件
            base.PageChangeEvent += (index) =>
            {
                if (index == 1)
                {
                    //初始化门锁历史记录以及控件
                    this.InitDoorHistoryLogAndControl();
                }
            };
 
            //刷新当前设备的状态缓存
            this.RefreshNowDeviceStatuMemory(this.device);
            //初始化第一个索引页的内容
            this.InitFrameWhiteContent1();
            //初始化第二个索引页(历史记录)
            this.InitFrameWhiteContent2();
            //刷新界面状态
            this.RefreshFormStatu();
        }
 
        /// <summary>
        /// 初始化第一个索引页的内容
        /// </summary>
        private void InitFrameWhiteContent1()
        {
            //电池控件
            this.batteryControl = new BatteryPersentControl();
            //它有个最小的X轴
            batteryControl.X = Application.GetRealWidth(104) > base.btnRoomName.Right ?
                Application.GetRealWidth(104) : base.btnRoomName.Right + Application.GetRealWidth(4);
            FrameWhiteCentet1.AddChidren(batteryControl);
            if (batteryControl.Height > base.btnRoomName.Height)
            {
                //一个是25,一个是21,弄不准到底谁更高,因为计算方法不一样
                batteryControl.Y = base.btnRoomName.Y - (batteryControl.Height - base.btnRoomName.Height) / 2;
            }
            else
            {
                batteryControl.Y = base.btnRoomName.Y + (batteryControl.Height - base.btnRoomName.Height) / 2;
            }
            batteryControl.InitControl();
            batteryControl.SetValue(100);
 
            //在线状态
            this.btnOnlineIcon = new IconViewControl(24);
            btnOnlineIcon.X = batteryControl.Right + Application.GetRealWidth(12);
            btnOnlineIcon.Y = batteryControl.Y;
            btnOnlineIcon.UnSelectedImagePath = "FunctionIcon/DoorLock/Connect.png";
            FrameWhiteCentet1.AddChidren(btnOnlineIcon);
            //在线文本
            this.btnOnlineView = new NormalViewControl(Application.GetRealWidth(100), btnOnlineIcon.Height, false);
            btnOnlineView.X = btnOnlineIcon.Right + Application.GetRealWidth(4);
            btnOnlineView.Y = btnOnlineIcon.Y;
            btnOnlineView.TextSize = CSS_FontSize.PromptFontSize_SecondaryLevel;
            btnOnlineView.TextColor = CSS_Color.PromptingColor1;
            btnOnlineView.TextID = StringId.Connected;
            FrameWhiteCentet1.AddChidren(btnOnlineView);
            //右上角配置结束的事件
            base.SettionFinishEvent += () =>
            {
                //从新设置坐标
                batteryControl.X = Application.GetRealWidth(104) > base.btnRoomName.Right ?
                     Application.GetRealWidth(104) : base.btnRoomName.Right + Application.GetRealWidth(4);
                btnOnlineIcon.X = batteryControl.Right + Application.GetRealWidth(12);
                btnOnlineView.X = btnOnlineIcon.Right + Application.GetRealWidth(4);
            };
 
            //中间的开锁或者关锁图片控件
            this.picLockControl = new PicViewControl(256, 260);
            picLockControl.Y = Application.GetRealHeight(129);
            picLockControl.Gravity = Gravity.CenterHorizontal;
            picLockControl.UnSelectedImagePath = "FunctionIcon/DoorLock/LockPictrue1.png";
            FrameWhiteCentet1.AddChidren(picLockControl);
            picLockControl.ButtonClickEvent += (sender, e) =>
            {
                //一键开锁
                this.DoOneKeyToUnlockDoor();
            };
 
            //临时密码的控件容器
            this.frameTempPsw = new FrameLayout();
            frameTempPsw.Y = Application.GetRealHeight(129);
            frameTempPsw.Height = Application.GetRealHeight(260);
            frameTempPsw.Visible = false;
            FrameWhiteCentet1.AddChidren(frameTempPsw);
 
            //声音
            this.btnVoice = new IconViewControl(24);
            btnVoice.UnSelectedImagePath = "FunctionIcon/DoorLock/Voice.png";
            btnVoice.X = Application.GetRealWidth(23);
            btnVoice.Y = Application.GetRealHeight(410);
            FrameWhiteCentet1.AddChidren(btnVoice);
 
            //声音的滑动条
            this.seekBarVoiceControl = new SeekBarImageControl(215);
            seekBarVoiceControl.Gravity = Gravity.CenterHorizontal;
            FrameWhiteCentet1.AddChidren(seekBarVoiceControl);
            seekBarVoiceControl.Y = btnVoice.Y - (seekBarVoiceControl.Height - btnVoice.Height) / 2;
            //绑定PageLayout控件
            seekBarVoiceControl.BindPageLayout();
 
            //声音百分比
            this.btnVoicePersent = new NormalViewControl(Application.GetRealWidth(50), btnVoice.Height, false);
            btnVoicePersent.X = seekBarVoiceControl.Right + Application.GetRealWidth(8) - seekBarVoiceControl.SeekBarPadding;
            btnVoicePersent.Y = btnVoice.Y;
            btnVoicePersent.TextColor = CSS_Color.PromptingColor1;
            btnVoicePersent.TextSize = CSS_FontSize.PromptFontSize_FirstLevel;
            btnVoicePersent.Text = "100%";
            FrameWhiteCentet1.AddChidren(btnVoicePersent);
 
            seekBarVoiceControl.ProgressChangedEvent += (div, value) =>
            {
                btnVoicePersent.Text = value + "%";
                if (div == 1)
                {
                }
            };
 
            //初始化开锁菜单(一键开锁,临时密码开锁)
            this.InitUnLockMenuControl();
            //初始化底部菜单图标
            this.InitBottomMenuIconControl();
        }
 
        /// <summary>
        /// 初始化开锁菜单(一键开锁,临时密码开锁)
        /// </summary>
        private void InitUnLockMenuControl()
        {
            //如果是成员,则只有一键开锁
            if (DB_ResidenceData.Instance.CurrentRegion.isOtherShare == true)
            {
                //一键开锁
                var btnOneKey = new NormalViewControl(100, 25, true);
                btnOneKey.Y = Application.GetRealHeight(100);
                btnOneKey.TextSize = CSS_FontSize.HeadlineFontSize;
                btnOneKey.TextColor = CSS_Color.MainColor;
                btnOneKey.Text = Language.StringByID(StringId.OneKeyUnlocking);
                btnOneKey.Width = this.GetTextRealWidth(btnOneKey.Text, CSS_FontSize.HeadlineFontSize, true);
                btnOneKey.Gravity = Gravity.CenterHorizontal;
                btnOneKey.IsBold = true;
                FrameWhiteCentet1.AddChidren(btnOneKey);
            }
            else
            {
                //一键开锁
                var btnOneKey = new NormalViewControl(100, 25, true);
                btnOneKey.Y = Application.GetRealHeight(100);
                btnOneKey.TextSize = Language.CurrentLanguage == "Chinese" ? CSS_FontSize.HeadlineFontSize : CSS_FontSize.SubheadingFontSize;
                btnOneKey.TextColor = CSS_Color.MainColor;
                btnOneKey.Text = Language.StringByID(StringId.OneKeyUnlocking);
                btnOneKey.TextAlignment = TextAlignment.CenterRight;
                btnOneKey.IsBold = true;
                btnOneKey.Width = this.GetTextRealWidth(btnOneKey.Text, CSS_FontSize.HeadlineFontSize, true);
                FrameWhiteCentet1.AddChidren(btnOneKey);
                btnOneKey.X = Application.GetRealWidth(140) - btnOneKey.Width;
 
                //临时密码开锁
                var btnTempPsw = new NormalViewControl(100, 25, true);
                btnTempPsw.X = btnOneKey.Right + Application.GetRealWidth(36);
                btnTempPsw.Y = btnOneKey.Y;
                btnTempPsw.TextColor = CSS_Color.PromptingColor1;
                btnTempPsw.Text = Language.StringByID(StringId.TemporaryPasswordUnlocking);
                btnTempPsw.Width = this.GetTextRealWidth(btnTempPsw.Text, CSS_FontSize.HeadlineFontSize, true);
                FrameWhiteCentet1.AddChidren(btnTempPsw);
 
                btnOneKey.ButtonClickEvent += (sender, e) =>
                {
                    //选择的是同一个,则不处理
                    if (this.nowSelectMenu == 1) { return; }
                    this.nowSelectMenu = 1;
 
                    btnOneKey.IsBold = true;
                    btnOneKey.TextSize = Language.CurrentLanguage == "Chinese" ? CSS_FontSize.HeadlineFontSize : CSS_FontSize.SubheadingFontSize;
                    btnOneKey.TextColor = CSS_Color.MainColor;
 
                    btnTempPsw.IsBold = false;
                    btnTempPsw.TextSize = CSS_FontSize.TextFontSize;
                    btnTempPsw.TextColor = CSS_Color.PromptingColor1;
 
                    //设置中间容器控件可视化
                    this.SetMiddleFrameControlVisible();
                };
 
                btnTempPsw.ButtonClickEvent += (sender, e) =>
                {
                    //选择的是同一个,则不处理
                    if (this.nowSelectMenu == 2) { return; }
                    this.nowSelectMenu = 2;
 
                    btnOneKey.IsBold = false;
                    btnOneKey.TextSize = CSS_FontSize.TextFontSize;
                    btnOneKey.TextColor = CSS_Color.PromptingColor1;
 
                    btnTempPsw.IsBold = true;
                    btnTempPsw.TextSize = Language.CurrentLanguage == "Chinese" ? CSS_FontSize.HeadlineFontSize : CSS_FontSize.SubheadingFontSize;
                    btnTempPsw.TextColor = CSS_Color.MainColor;
 
                    //设置中间容器控件可视化
                    this.SetMiddleFrameControlVisible();
                };
            }
        }
 
        #endregion
 
        #region ■ 初始化第二个索引页(历史记录)_______
 
        /// <summary>
        /// 初始化第二个索引页(历史记录)
        /// </summary>
        private void InitFrameWhiteContent2()
        {
            //添加第二个page
            this.AddSecondPage();
        }
 
        /// <summary>
        /// 初始化门锁历史记录以及控件
        /// </summary>
        private void InitDoorHistoryLogAndControl()
        {
            //已经初始化
            if (this.listHistoryLog != null) { return; }
 
            this.ShowProgressBar();
            HdlThreadLogic.Current.RunThread(() =>
            {
                //初始化成员列表信息
                if (this.InitMemberListInfo() == false)
                {
                    this.CloseProgressBar();
                    return;
                }
                //获取门锁历史记录
                this.listHistoryLog = new DAL.Server.HttpServerRequest().GetDoorHistoryLogs(this.device);
                this.CloseProgressBar();
                if (this.listHistoryLog == null)
                {
                    return;
                }
                HdlThreadLogic.Current.RunMain(() =>
                {
                    //初始化门锁历史记录列表控件
                    this.InitDoorHistoryLogListControl(this.listHistoryLog);
                });
            });
        }
 
        /// <summary>
        /// 初始化门锁历史记录列表控件
        /// </summary>
        /// <param name="listLog">显示的门锁记录</param>
        private void InitDoorHistoryLogListControl(List<DoorHistoryLog> listLog)
        {
            //按年分组
            var dicData = new Dictionary<int, List<DoorHistoryLog>>();
            foreach (var info in listLog)
            {
                var year = info.Time.Year;
                if (dicData.ContainsKey(year) == false)
                {
                    dicData[year] = new List<DoorHistoryLog>();
                }
                dicData[year].Add(info);
            }
 
            //先清空
            base.FrameWhiteCentet2.RemoveAll();
 
            //日志
            var btnLog = new NormalViewControl(150, 35, true);
            btnLog.Y = Application.GetRealHeight(15);
            btnLog.X = HdlControlResourse.XXLeft;
            btnLog.TextSize = CSS_FontSize.EmphasisFontSize_FirstLevel;
            btnLog.TextColor = CSS_Color.FirstLevelTitleColor;
            btnLog.TextID = StringId.Log;
            FrameWhiteCentet2.AddChidren(btnLog);
 
            //列表容器
            var listView = new VerticalFrameControl();
            listView.Y = Application.GetRealHeight(72);
            listView.Height = base.FrameWhiteCentet2.Height - Application.GetRealHeight(72);
            base.FrameWhiteCentet2.AddChidren(listView);
 
            //初始Y轴为0
            int yy = 0;
            foreach (var strYear in dicData.Keys)
            {
                //年
                var btnYear = new NormalViewControl(100, 24, true);
                btnYear.X = HdlControlResourse.XXLeft;
                btnYear.Y = yy;
                btnYear.TextColor = CSS_Color.FirstLevelTitleColor;
                btnYear.TextSize = CSS_FontSize.SubheadingFontSize;
                btnYear.Text = strYear.ToString();
                //中文
                if (Language.CurrentLanguage == "Chinese")
                {
                    btnYear.Text += Language.StringByID(StringId.Years);
                }
                listView.frameTable.AddChidren(btnYear);
 
                //年与消息记录的间距为14
                yy = btnYear.Bottom + Application.GetRealHeight(14);
                foreach (var logInfo in dicData[strYear])
                {
                    //消息
                    var btnMsg = new NormalViewControl(295, 20, true);
                    btnMsg.Y = yy;
                    btnMsg.Gravity = Gravity.CenterHorizontal;
                    btnMsg.TextColor = CSS_Color.FirstLevelTitleColor;
                    btnMsg.Text = logInfo.StrMsg;
                    listView.frameTable.AddChidren(btnMsg);
                    //时间
                    var btnTime = new NormalViewControl(200, 18, true);
                    btnTime.Y = btnMsg.Bottom + Application.GetRealHeight(2);
                    btnTime.X = btnMsg.X;
                    btnTime.TextSize = CSS_FontSize.PromptFontSize_FirstLevel;
                    btnTime.TextColor = CSS_Color.PromptingColor1;
                    btnTime.Text = HdlCommonLogic.Current.ConvertDayText(logInfo.Time.Month, logInfo.Time.Day) + " " + logInfo.Time.ToString("HH:mm");
                    listView.frameTable.AddChidren(btnTime);
                    //线
                    var btnLine = new NormalViewControl(btnMsg.Width, HdlControlResourse.BottomLineHeight, false);
                    btnLine.Y = btnTime.Bottom + Application.GetRealHeight(11);
                    btnLine.Gravity = Gravity.CenterHorizontal;
                    btnLine.BackgroundColor = CSS_Color.DividingLineColor;
                    listView.frameTable.AddChidren(btnLine);
                    //两条消息的间距为10
                    yy = btnLine.Bottom + Application.GetRealHeight(10);
                }
                //年与年之间的间距为24
                yy += Application.GetRealHeight(24);
            }
            //调整桌布高度
            listView.AdjustTableHeight();
        }
 
        #endregion
 
        #region ■ 初始化底部菜单图标_________________
 
        /// <summary>
        /// 初始化底部菜单图标
        /// </summary>
        private void InitBottomMenuIconControl()
        {
            //如果是成员,则只有开锁方式管理
            if (DB_ResidenceData.Instance.CurrentRegion.isOtherShare == true)
            {
                //开锁方式管理图标
                var btnManagerIcon = new IconViewControl(40);
                btnManagerIcon.Gravity = Gravity.CenterHorizontal;
                btnManagerIcon.Y = Application.GetRealHeight(466);
                btnManagerIcon.UnSelectedImagePath = "FunctionIcon/DoorLock/UnLockManager.png";
                this.FrameWhiteCentet1.AddChidren(btnManagerIcon);
                btnManagerIcon.ButtonClickEvent += (sender, e) =>
                {
                    //初始化成员列表信息
                    if (this.InitMemberListInfo() == false)
                    {
                        return;
                    }
                    var form = new DoorLockUnlockMethordManagerPage();
                    form.AddForm(this.device, this.listMember);
                };
            }
            else
            {
                //开锁方式管理图标
                var btnManagerIcon = new IconViewControl(40);
                btnManagerIcon.Y = Application.GetRealHeight(466);
                btnManagerIcon.UnSelectedImagePath = "FunctionIcon/DoorLock/UnLockManager.png";
                this.FrameWhiteCentet1.AddChidren(btnManagerIcon);
                btnManagerIcon.X = (this.FrameWhiteCentet1.Width - btnManagerIcon.Width * 2 - Application.GetRealWidth(40)) / 2;
                btnManagerIcon.ButtonClickEvent += (sender, e) =>
                {
                    //初始化成员列表信息
                    if (this.InitMemberListInfo() == false)
                    {
                        return;
                    }
                    var form = new DoorLockUnlockMethordManagerPage();
                    form.AddForm(this.device, this.listMember);
                };
 
                //常开模式图标
                this.btnNormallyOpenIcon = new IconViewControl(40);
                btnNormallyOpenIcon.X = btnManagerIcon.Right + Application.GetRealWidth(40);
                btnNormallyOpenIcon.Y = btnManagerIcon.Y;
                btnNormallyOpenIcon.UnSelectedImagePath = "FunctionIcon/DoorLock/NormallyOpenIcon2.png";
                this.FrameWhiteCentet1.AddChidren(btnNormallyOpenIcon);
                btnNormallyOpenIcon.ButtonClickEvent += (sender, e) =>
                {
                    var form = new DoorLockAlwaysOnListPage();
                    form.AddForm(this.device);
                };
            }
        }
 
        #endregion
 
        #region ■ 初始化临时密码控件_________________
 
        /// <summary>
        /// 初始化临时密码控件
        /// </summary>
        private void InitTempPasswordControl()
        {
            this.frameTempPsw.RemoveAll();
 
            //生成临时密码的背景图片
            var picBack = new PicViewControl(258, 165);
            picBack.Gravity = Gravity.CenterHorizontal;
            picBack.UnSelectedImagePath = "FunctionIcon/DoorLock/CrearPswBackgroud.png";
            this.frameTempPsw.AddChidren(picBack);
 
            //密码显示控件
            var btnPassword = new NormalViewControl(150, 50, true);
            btnPassword.Gravity = Gravity.CenterHorizontal;
            btnPassword.TextSize = CSS_FontSize.SubheadingFontSize;
            btnPassword.TextColor = CSS_Color.MainBackgroundColor;
            btnPassword.TextAlignment = TextAlignment.Center;
            this.frameTempPsw.AddChidren(btnPassword);
 
            //如果没有临时密码
            if (this.doorLockData.TempPassword == string.Empty)
            {
                //当没有临时密码时,这个背景放在中间
                picBack.Y = Application.GetRealHeight(47);
                //因为图片的压缩问题,这个Y轴和蓝湖的不一样,蓝湖是99
                btnPassword.Y = Application.GetRealHeight(88);
 
                //生成临时密码
                btnPassword.TextID = StringId.CreatTemporaryPassword;
                btnPassword.ButtonClickEvent += (sender, e) =>
                {
                    //显示生成临时密码的弹窗界面
                    this.ShowCreatTemporaryPasswordDialog(DateTime.Now, DateTime.Now.AddDays(1).AddMinutes(-1));
                };
            }
            //拥有临时密码
            else
            {
                //显示临时密码
                btnPassword.Text = this.doorLockData.TempPassword;
                //因为图片的压缩问题,这个Y轴和蓝湖的不一样,蓝湖是51
                btnPassword.Y = Application.GetRealHeight(40);
 
                //删除临时密码图标
                var btnDelete = new IconViewControl(28);
                btnDelete.UnSelectedImagePath = "FunctionIcon/DoorLock/Delete.png";
                btnDelete.X = Application.GetRealWidth(19);
                btnDelete.Y = Application.GetRealHeight(115);
                this.frameTempPsw.AddChidren(btnDelete);
                btnDelete.ButtonClickEvent += (sender, e) =>
                {
                    //清除当前临时密码?
                    HdlMessageLogic.Current.ShowMassage(ShowMsgType.Confirm, Language.StringByID(StringId.ClearTempPsswordMsg), () =>
                    {
                        //清空临时密码
                        this.doorLockData.TempPassword = string.Empty;
                        this.doorLockData.StatrtTime = string.Empty;
                        this.doorLockData.EndTime = string.Empty;
                        //重新初始化临时密码控件
                        this.InitTempPasswordControl();
                    });
                };
 
                //复制临时密码图标
                var btnCopy = new IconViewControl(28);
                btnCopy.UnSelectedImagePath = "FunctionIcon/DoorLock/Shard.png";
                btnCopy.X = this.frameTempPsw.Width - btnCopy.IconSize - btnDelete.X;
                btnCopy.Y = btnDelete.Y;
                this.frameTempPsw.AddChidren(btnCopy);
                btnCopy.ButtonClickEvent += (sender, e) =>
                {
                    //临时密码已经复制
                    HdlCommonLogic.Current.SetTextToShearPlate(this.doorLockData.TempPassword, Language.StringByID(StringId.TempPsswordHasBeenCopy));
                };
 
                //生效时间
                var frameEffective = this.CreatEffectiveTimeControl(this.frameTempPsw, Language.StringByID(StringId.EffectiveTime), this.doorLockData.StatrtTime);
                frameEffective.X = Application.GetRealWidth(24);
                frameEffective.Y = Application.GetRealHeight(180);
 
                //失效时间
                var frameFailure = this.CreatEffectiveTimeControl(this.frameTempPsw, Language.StringByID(StringId.FailureTime), this.doorLockData.EndTime);
                frameFailure.X = this.frameTempPsw.Width - frameFailure.Width - frameEffective.X;
                frameFailure.Y = frameEffective.Y;
 
                //-
                var btnLine = new NormalViewControl(frameFailure.X - frameEffective.Right, frameFailure.Height, false);
                btnLine.X = frameEffective.Right;
                btnLine.Y = frameEffective.Y;
                btnLine.Text = "-";
                btnLine.TextAlignment = TextAlignment.Center;
                btnLine.TextColor = CSS_Color.FirstLevelTitleColor;
                btnLine.TextSize = CSS_FontSize.PromptFontSize_FirstLevel;
                this.frameTempPsw.AddChidren(btnLine);
            }
        }
 
        /// <summary>
        /// 生成生效/失效时间控件
        /// </summary>
        /// <param name="frameTempPsw">父控件</param>
        /// <param name="i_text">显示的文本</param>
        /// <param name="i_time">显示的时间</param>
        /// <returns></returns>
        private FrameLayout CreatEffectiveTimeControl(FrameLayout frameTempPsw, string i_text, string i_time)
        {
            //线框背景控件
            var frameBack = new FrameLayout();
            frameBack.Width = Application.GetRealWidth(120);
            frameBack.Height = Application.GetRealHeight(50);
            frameBack.Radius = (uint)Application.GetRealWidth(7);
            frameBack.BorderWidth = 1;
            frameBack.BorderColor = CSS_Color.PromptingColor1;
            frameTempPsw.AddChidren(frameBack);
 
            //显示文本
            var btnText = new NormalViewControl(frameBack.Width, Application.GetRealHeight(18), false);
            btnText.Y = Application.GetRealHeight(8);
            btnText.TextColor = CSS_Color.FirstLevelTitleColor;
            btnText.TextSize = CSS_FontSize.PromptFontSize_FirstLevel;
            btnText.Text = i_text;
            btnText.TextAlignment = TextAlignment.Center;
            frameBack.AddChidren(btnText);
 
            //显示时间
            var btnTime = new NormalViewControl(frameBack.Width, Application.GetRealHeight(18), false);
            btnTime.Y = btnText.Bottom;
            btnTime.TextColor = CSS_Color.FirstLevelTitleColor;
            btnTime.TextSize = CSS_FontSize.PromptFontSize_FirstLevel;
            btnTime.Text = i_time;
            btnTime.TextAlignment = TextAlignment.Center;
            frameBack.AddChidren(btnTime);
 
            return frameBack;
        }
 
        #endregion
 
        #region ■ 生成临时密码_______________________
 
        /// <summary>
        /// 显示生成临时密码的弹窗界面
        /// </summary>
        private void ShowCreatTemporaryPasswordDialog(DateTime startTime, DateTime endTime)
        {
            //默认时间Form-To为一天
            var contr = new BottomItemEditorControl(2, string.Empty);
            //点击确认时,不关闭界面
            contr.CloseByConfirm = false;
 
            //生效时间
            var effectiveTime = Language.StringByID(StringId.EffectiveTime);
            contr.AddRowMenu(effectiveTime, startTime.ToString("yyyy.MM.dd HH:mm"), (btnView, btnValue) =>
            {
                //关掉界面,然后重新调起来
                contr.Close();
 
                var form = new DoorLockSelectTimePage();
                form.AddForm(startTime);
                form.SelectFinshEvent += (selectTime) =>
                {
                    //重新调起界面
                    this.ShowCreatTemporaryPasswordDialog(selectTime, endTime);
                };
            });
 
            //失效时间
            var failTime = Language.StringByID(StringId.FailureTime);
            contr.AddRowMenu(failTime, endTime.ToString("yyyy.MM.dd HH:mm"), (btnView, btnValue) =>
            {
                //关掉界面,然后重新调起来
                contr.Close();
 
                var form = new DoorLockSelectTimePage();
                form.AddForm(endTime);
                form.SelectFinshEvent += (selectTime) =>
                {
                    //重新调起界面
                    this.ShowCreatTemporaryPasswordDialog(startTime, selectTime);
                };
            });
            contr.FinishEvent += (div) =>
            {
                //点击了生成
                if (div == 1)
                {
                    if (this.CheckEffectiveTime(startTime, endTime) == false)
                    {
                        return;
                    }
                    //关掉界面
                    contr.Close();
 
                    //生成临时密码
                    this.doorLockData.TempPassword = "987654";
                    this.doorLockData.StatrtTime = startTime.ToString("yyyy.MM.dd HH:mm");
                    this.doorLockData.EndTime = endTime.ToString("yyyy.MM.dd HH:mm");
                    //重新初始化临时密码控件
                    this.InitTempPasswordControl();
                }
            };
 
            //需要初始化之后,按钮才不会为null  变更【生成】按钮的宽度和X轴
            contr.btnConfirm.TextID = StringId.Generate;
            contr.btnConfirm.Width = contr.btnConfirm.GetRealWidthByText();
            contr.btnConfirm.X = contr.btnConfirm.Parent.Width - contr.btnConfirm.Width - contr.btnCancel.X;
        }
 
        /// <summary>
        /// 检测生效时间是否正确
        /// </summary>
        /// <param name="startTime">生效时间</param>
        /// <param name="endTime">失效时间</param>
        /// <returns></returns>
        private bool CheckEffectiveTime(DateTime startTime, DateTime endTime)
        {
            if (startTime >= endTime)
            {
                //生效时间必须大于失效时间
                HdlMessageLogic.Current.ShowMassage(ShowMsgType.Tip, Language.StringByID(StringId.EffectiveTimeMustBeOverFailureTime));
                return false;
            }
            return true;
        }
 
        #endregion
 
        #region ■ 设备状态反馈_______________________
 
        /// <summary>
        /// 设备状态反馈
        /// </summary>
        /// <param name="i_LocalDevice"></param>
        public override void DeviceStatuPush(Function i_LocalDevice)
        {
            //不是同一个东西
            if (this.device.sid != i_LocalDevice.sid) { return; }
 
            //刷新当前设备的状态缓存
            this.RefreshNowDeviceStatuMemory(i_LocalDevice);
            //刷新界面状态
            this.RefreshFormStatu();
        }
 
        #endregion
 
        #region ■ 刷新界面状态_______________________
 
        /// <summary>
        /// 刷新界面状态
        /// </summary>
        private void RefreshFormStatu()
        {
            //如果不在线
            if (this.doorLockData.IsOnline == false)
            {
                //开锁图片
                this.picLockControl.UnSelectedImagePath = "FunctionIcon/DoorLock/LockPictrue2.png";
                //连接状态
                this.btnOnlineIcon.UnSelectedImagePath = "FunctionIcon/DoorLock/UnConnect.png";
                this.btnOnlineView.Text = this.dicText["未连接"];
                this.btnOnlineView.TextColor = CSS_Color.AuxiliaryColor2;
                //常开模式图标
                if (this.btnNormallyOpenIcon != null)
                {
                    this.btnNormallyOpenIcon.UnSelectedImagePath = "FunctionIcon/DoorLock/NormallyOpenIcon2.png";
                }
            }
            else
            {
                //开锁图片
                this.picLockControl.UnSelectedImagePath = this.doorLockData.Open == true ? "FunctionIcon/DoorLock/UnLockPictrue3.png" : "FunctionIcon/DoorLock/LockPictrue1.png";
                //连接状态
                this.btnOnlineIcon.UnSelectedImagePath = "FunctionIcon/DoorLock/Connect.png";
                this.btnOnlineView.Text = this.dicText["已连接"];
                this.btnOnlineView.TextColor = CSS_Color.PromptingColor1;
                //常开模式图标
                if (this.btnNormallyOpenIcon != null)
                {
                    this.btnNormallyOpenIcon.UnSelectedImagePath = "FunctionIcon/DoorLock/NormallyOpenIcon1.png";
                }
            }
        }
 
        /// <summary>
        /// 设置中间容器控件可视化
        /// </summary>
        private void SetMiddleFrameControlVisible()
        {
            //如果选择的是 一键开锁
            if (this.nowSelectMenu == 1)
            {
                this.picLockControl.Visible = true;
                this.frameTempPsw.Visible = false;
            }
            else
            {
                this.picLockControl.Visible = false;
                this.frameTempPsw.Visible = true;
                //临时密码已经变更,需要刷新界面
                if (this.doorLockData.IsTempPasswordChanged == true)
                {
                    //初始化临时密码控件
                    this.InitTempPasswordControl();
                    this.doorLockData.IsTempPasswordChanged = false;
                }
            }
        }
 
        #endregion
 
        #region ■ 发送各种命令_______________________
 
        /// <summary>
        /// 发送开关命令
        /// </summary>
        private void SendSwitchComand()
        {
            //this.btnSwitch.CanClick = false;
 
            //string statu = this.btnSwitch.IsSelected == true ? "off" : "on";
            //HdlThreadLogic.Current.RunThread(() =>
            //{
            //    var dic = new Dictionary<string, string>();
            //    dic.Add(FunctionAttributeKey.OnOff, statu);
            //    Control.Ins.SendWriteCommand(this.device, dic, true);
            //    HdlThreadLogic.Current.RunMain(() =>
            //    {
            //        this.btnSwitch.CanClick = true;
            //    });
            //});
        }
 
        #endregion
 
        #region ■ 初始化成员列表信息_________________
 
        /// <summary>
        /// 初始化成员列表信息
        /// </summary>
        /// <returns></returns>
        private bool InitMemberListInfo()
        {
            //已经初始化
            if (this.listMember != null) { return true; }
 
            //主账号需要去获取成员列表,而子账号只能他自己
            if (DB_ResidenceData.Instance.CurrentRegion.isOtherShare == false)
            {
                //获取成员列表
                var responePack = new DAL.Server.HttpServerRequest().GetResidenceMemberAccount();
                if (responePack.Code == DAL.Server.StateCode.SUCCESS)
                {
                    this.listMember = Newtonsoft.Json.JsonConvert.DeserializeObject<List<ResidenceMemberInfo>>(responePack.Data.ToString());
                }
                //失败
                else
                {
                    //提示
                    DAL.Server.IMessageCommon.Current.ShowErrorInfoAlter(responePack.Code);
                    return false;
                }
            }
            else
            {
                //先初始化
                this.listMember = new List<ResidenceMemberInfo>();
            }
 
            //自身加进去,自己位于首位
            var info = new ResidenceMemberInfo();
            info.childAccountId = OnAppConfig.Instance.LastLoginUserId;
            info.childAccountType = DB_ResidenceData.Instance.CurrentRegion.isOtherShare == false ? "ADMIN" : "ORDINARY";
            info.nickName = UserInfo.Current.userName;
            this.listMember.Insert(0, info);
            if (string.IsNullOrEmpty(info.nickName))
            {
                info.nickName = UserInfo.Current.AccountString;
            }
 
            foreach (var info2 in this.listMember)
            {
                //设置用户昵称
                if (string.IsNullOrEmpty(info2.nickName))
                {
                    info2.nickName = info2.memberName;
                }
            }
 
            return true;
        }
        #endregion
 
        #region ■ 一键开锁___________________________
 
        /// <summary>
        /// 一键开锁
        /// </summary>
        private void DoOneKeyToUnlockDoor()
        {
            if (this.doorLockData.IsOnline == false)
            {
                //设备不在线
                HdlMessageLogic.Current.ShowMassage(ShowMsgType.TipRemind, Language.StringByID(StringId.DeviceNotOnline), null, null, null, 2);
                return;
            }
            //第一次使用,请先绑定门锁密码
            //HdlMessageLogic.Current.ShowMassage(ShowMsgType.Confirm, Language.StringByID(StringId.PleaseBindTheDoorPswFirst), () =>
            //{
            //    var form = new TextInputDialog(Language.StringByID(StringId.PleaseInputDoorAdminPassword), string.Empty, Language.StringByID(StringId.PleaseInputDoorAdminPassword), null, null, true);
            //    form.Show((password) =>
            //    {
            //        //门锁绑定成功
            //        HdlMessageLogic.Current.ShowMassage(ShowMsgType.ConfirmSuccess, Language.StringByID(StringId.BindDoorLockSuccess), () =>
            //        {
            //        });
            //    });
            //});
 
            if (UserInfo.Current.appUnlockPage.Contains("3") == true)
            {
                //调起安全认证
                HdlCheckLogic.Current.CheckUnlockSecurity(true, (div) =>
                {
                    //锁已打开
                    if (div == 1)
                    {
                        HdlMessageLogic.Current.ShowMassage(ShowMsgType.TipSuccess, Language.StringByID(StringId.LockIsOpened), null, null, null, 2);
                    }
                    else
                    {
                        //为了安全,请跳转至个人中心{0}设置个人密码,并应用于门锁开锁
                        HdlMessageLogic.Current.ShowMassage(ShowMsgType.Confirm, Language.StringByID(StringId.JumpToPersonalCentetToSetPasswordMsg), () =>
                        {
                            var page = new AppUnlockSettingsPage();
                            MainPage.BasePageView.AddChidren(page);
                            page.LoadPage();
                            MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
 
                        }, Language.StringByID(StringId.Jump));
                    }
                });
            }
            else
            {
                //为了安全,请跳转至个人中心{0}设置个人密码,并应用于门锁开锁
                HdlMessageLogic.Current.ShowMassage(ShowMsgType.Confirm, Language.StringByID(StringId.JumpToPersonalCentetToSetPasswordMsg), () =>
                {
                    var page = new AppUnlockSettingsPage();
                    MainPage.BasePageView.AddChidren(page);
                    page.LoadPage();
                    MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
 
                }, Language.StringByID(StringId.Jump));
            }
        }
 
        #endregion
 
        #region ■ 一般方法___________________________
 
        /// <summary>
        /// 刷新当前设备的状态缓存
        /// </summary>
        private void RefreshNowDeviceStatuMemory(Function i_LocalDevice)
        {
            this.doorLockData.IsOnline = i_LocalDevice.online;
            for (int i = 0; i < i_LocalDevice.attributes.Count; i++)
            {
                var data = i_LocalDevice.attributes[i];
                //门锁状态
                if (data.key == "status")
                {
                    if (data.state == "open") { this.doorLockData.Open = true; }
                    else if (data.state == "normal_open")
                    {
                        //常开模式
                        this.doorLockData.Open = true;
                        this.doorLockData.NormalOpen = true;
                    }
                    else
                    {
                        this.doorLockData.Open = false;
                        this.doorLockData.NormalOpen = false;
                    }
                }
                //音量
                else if (data.key == "volume")
                {
                    var value = data.state;
                    if (value != string.Empty)
                    {
                        this.doorLockData.Voice = Convert.ToInt32(value);
                    }
                }
                //电池百分比
                else if (data.key == "battery_percentage")
                {
                    var value = data.state;
                    if (value != string.Empty)
                    {
                        this.doorLockData.BatteryPersent = Convert.ToInt32(value);
                    }
                }
            }
        }
 
        #endregion
 
        #region ■ 结构体_____________________________
 
        /// <summary>
        /// 门锁的数据
        /// </summary>
        private class DoorLockData
        {
            /// <summary>
            /// 是否打开
            /// </summary>
            public bool Open = true;
            /// <summary>
            /// 电池电量
            /// </summary>
            public int BatteryPersent = 0;
            /// <summary>
            /// 是否在线
            /// </summary>
            public bool IsOnline = false;
            /// <summary>
            /// 是否静音
            /// </summary>
            public bool Mute = false;
            /// <summary>
            /// 音量
            /// </summary>
            public int Voice = 0;
            /// <summary>
            /// 是否处于常开模式
            /// </summary>
            public bool NormalOpen = false;
            /// <summary>
            /// 临时密码
            /// </summary>
            public string TempPassword = string.Empty;
            /// <summary>
            /// 临时密码是否被变更
            /// </summary>
            public bool IsTempPasswordChanged = true;
            /// <summary>
            /// 临时密码生效时间(2020.03.17 13:27)
            /// </summary>
            public string StatrtTime = string.Empty;
            /// <summary>
            /// 临时密码失效时间(2020.03.17 13:27)
            /// </summary>
            public string EndTime = string.Empty;
        }
 
        #endregion
    }
}