黄学彪
2020-12-16 0d9f64668fd7350d6a21fd157e32009a96d98134
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
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using ZigBee.Device;
 
namespace Shared.Phone.UserCenter.Safety
{
    /// <summary>
    /// 安防管理的主界面★
    /// </summary>
    public class SafetyManagementMainForm : EditorCommonForm
    {
        #region ■ 变量声明___________________________
 
        /// <summary>
        /// 桌布控件,用于存放或者移除功能块控件(Tab控件专用)
        /// </summary>
        private NormalFrameLayout frameLayoutDraw = null;
        /// <summary>
        /// 安防控件
        /// </summary>
        private SafetyMasterControl garrisonControl = null;
        /// <summary>
        /// Tab的选择。1:安防记录Tab  2:传感器状态Tab
        /// </summary>
        private int TabSelectIndex = 2;
        /// <summary>
        /// 在线状态的锁
        /// </summary>
        private object objOnlineLock = new object();
 
        #endregion
 
        #region ■ 初始化_____________________________
 
        /// <summary>
        /// 画面显示(底层会固定调用此方法,借以完成画面创建)
        /// </summary>
        public void ShowForm()
        {
            //设置头部信息
            base.SetTitleText(Language.StringByID(R.MyInternationalizationString.SafetyManagement));
 
            //初始化中部信息
            this.InitMiddleFrame();
        }
 
        /// <summary>
        /// 初始化中部信息
        /// </summary>
        private void InitMiddleFrame()
        {
            //清空bodyFrame
            this.ClearBodyFrame();
 
            //初始化右上角图标
            this.InitTopRightIcon();
 
            //初始化全部内存信息
            this.InitAllMemoryData();
        }
 
        /// <summary>
        /// 初始化Tab控件
        /// </summary>
        private void InitTabSwitchControl()
        {
            var frameBack = new FrameLayout();
            frameBack.Height = Application.GetRealHeight(1300);
            frameBack.Y = Application.GetRealHeight(444);
            frameBack.BackgroundColor = 0xa1ffffff;
            frameBack.SetCornerWithSameRadius(Application.GetRealHeight(58), HDLUtils.RectCornerTopLeft | HDLUtils.RectCornerTopRight);
            bodyFrameLayout.AddChidren(frameBack);
 
            //桌布控件
            frameLayoutDraw = new NormalFrameLayout();
            frameLayoutDraw.Y = Application.GetRealHeight(181);
            frameLayoutDraw.Height = frameBack.Height - Application.GetRealHeight(181);
            frameBack.AddChidren(frameLayoutDraw);
 
            //计算宽度使用
            var btnTemp = new ButtonBase();
            btnTemp.TextSize = 16;
            btnTemp.IsBold = true;
 
            btnTemp.TextID = R.MyInternationalizationString.uSecurityLog;
            int frameLogWidth = btnTemp.GetRealWidthByText() + Application.GetRealWidth(30);
 
            btnTemp.TextID = R.MyInternationalizationString.uSensorStatu;
            int frameSensorWidth = btnTemp.GetRealWidthByText() + Application.GetRealWidth(30);
 
            //安防记录(点击范围有点小,需要扩大它的点击范围)
            var frameLog = new FrameLayoutStatuControl();
            frameLog.UseClickStatu = false;
            frameLog.Height = Application.GetRealHeight(123);
            frameLog.Width = frameLogWidth;
            frameLog.X = (frameBack.Width - frameLogWidth - frameSensorWidth) / 2;
            frameLog.Y = Application.GetRealHeight(58);
            frameBack.AddChidren(frameLog);
            //标题
            var btnLog = new NormalViewControl(100, 63, true);
            btnLog.Width = frameLog.Width;
            btnLog.TextAlignment = TextAlignment.Center;
            btnLog.TextID = R.MyInternationalizationString.uSecurityLog;
            btnLog.TextColor = UserCenterColor.Current.TextGrayColor3;
            frameLog.AddChidren(btnLog, ChidrenBindMode.BindEvent);
            //底线
            var btnLogLine = new NormalViewControl(40, 10, true);
            btnLogLine.Y = Application.GetRealHeight(86);
            //btnLogLine.X = btnLog.X + btnLog.Width / 2 - Application.GetRealWidth(40) / 2;
            btnLogLine.Gravity = Gravity.CenterHorizontal;
            btnLogLine.Radius = (uint)Application.GetRealHeight(10) / 2;
            btnLogLine.BackgroundColor = UserCenterColor.Current.TextOrangeColor;
            frameLog.AddChidren(btnLogLine, ChidrenBindMode.BindEvent);
            btnLogLine.Visible = false;
 
            //传感器状态(点击范围有点小,需要扩大它的点击范围)
            var frameSensor = new FrameLayoutStatuControl();
            frameSensor.UseClickStatu = false;
            frameSensor.Height = frameLog.Height;
            frameSensor.Width = frameSensorWidth;
            frameSensor.X = frameLog.Right;
            frameSensor.Y = frameLog.Y;
            frameBack.AddChidren(frameSensor);
            //标题
            var btnSensor = new NormalViewControl(100, 63, true);
            btnSensor.Width = frameSensor.Width;
            btnSensor.TextID = R.MyInternationalizationString.uSensorStatu;
            btnSensor.TextSize = 16;
            btnSensor.TextAlignment = TextAlignment.Center;
            btnSensor.TextColor = UserCenterColor.Current.TextColor2;
            btnSensor.IsBold = true;
            frameSensor.AddChidren(btnSensor, ChidrenBindMode.BindEvent);
            //底线
            var btnSensorLine = new NormalViewControl(40, 10, true);
            btnSensorLine.BackgroundColor = UserCenterColor.Current.TextOrangeColor;
            btnSensorLine.Y = btnLogLine.Y;
            //btnSensorLine.X = btnSensor.X + btnSensor.Width / 2 - Application.GetRealWidth(40) / 2;
            btnSensorLine.Gravity = Gravity.CenterHorizontal;
            btnSensorLine.Radius = (uint)Application.GetRealHeight(10) / 2;
            frameSensor.AddChidren(btnSensorLine, ChidrenBindMode.BindEvent);
 
            //安防记录Tab
            frameLog.ButtonClickEvent += (sender, e) =>
            {
                //字体大小和颜色变更
                btnSensor.TextColor = UserCenterColor.Current.TextGrayColor3;
                btnSensor.TextSize = 14;
                btnSensor.IsBold = false;
                btnLog.TextColor = UserCenterColor.Current.TextColor2;
                btnLog.TextSize = 16;
                btnLog.IsBold = true;
 
                btnLogLine.Visible = true;
                btnSensorLine.Visible = false;
 
                this.TabSelectIndex = 1;
 
                //显示安防记录
                this.SetSafeguardLogToForm();
            };
 
            //传感器状态Tab
            frameSensor.ButtonClickEvent += (sender, e) =>
            {
                //字体大小和颜色变更
                btnSensor.TextColor = UserCenterColor.Current.TextColor2;
                btnSensor.TextSize = 16;
                btnSensor.IsBold = true;
                btnLog.TextColor = UserCenterColor.Current.TextGrayColor3;
                btnLog.TextSize = 14;
                btnLog.IsBold = false;
 
                btnLogLine.Visible = false;
                btnSensorLine.Visible = true;
 
                this.TabSelectIndex = 2;
 
                //显示传感器列表
                this.SetSensorDataToForm();
            };
        }
 
        /// <summary>
        /// 初始化右上角图标
        /// </summary>
        private void InitTopRightIcon()
        {
            //快捷方式
            var btnShortCut = new MostRightIconControl(69, 69);
            btnShortCut.UnSelectedImagePath = "Safeguard/SafetyShortcut.png";
            btnShortCut.SelectedImagePath = "Safeguard/SafetyShortcutSelected.png";
 
            if (HdlUserCenterResourse.ResidenceOption.AuthorityNo == 1 || HdlUserCenterResourse.ResidenceOption.AuthorityNo == 2)
            {
                //快捷方式向左移动
                btnShortCut.X = Application.GetRealWidth(855);
 
                var btnIcon = new MostRightIconControl(69, 69);
                btnIcon.UnSelectedImagePath = "Item/More.png";
                topFrameLayout.AddChidren(btnIcon);
                btnIcon.InitControl();
                btnIcon.ButtonClickEvent += (sender, e) =>
                {
                    //菜单控件
                    var frameMenu = new TopRightMenuControl(2, 2);
                    //防区列表
                    string menu1 = Language.StringByID(R.MyInternationalizationString.uGarrisonAreaList);
                    frameMenu.AddRowMenu(menu1, "Item/GarrisonList.png", "Item/GarrisonListSelected.png", () =>
                    {
                        HdlCheckLogic.Current.CheckSecondarySecurity(() =>
                        { 
                            //验证成功
                            var form = new GarrisonAreaListMenuForm();
                            form.AddForm(); 
                        }, 
                        () =>
                        {
                            //请前往个人中心{0}设置二次安全验证方式
                            string msg = Language.StringByID(R.MyInternationalizationString.uGotoCenterAndSetSecondAuthentication).Replace("{0}", "\r\n");
                            this.ShowMassage(ShowMsgType.Confirm, msg, () =>
                            {
                                var form = new UserMain.SecondAuthenticationForm();
                                form.AddForm();
                            });
                        });
                    });
                    //密码设置
                    string menu2 = Language.StringByID(R.MyInternationalizationString.uPasswordSettion);
                    frameMenu.AddRowMenu(menu2, "Item/PswSettion.png", "Item/PswSettionSelected.png", () =>
                    {
                        HdlCheckLogic.Current.CheckSecondarySecurity(() =>
                        {
                            //验证成功
                            var form = new PasswordMenuForm();
                            form.AddForm();
                        },
                        () =>
                        {
                            //请前往个人中心{0}设置二次安全验证方式
                            string msg = Language.StringByID(R.MyInternationalizationString.uGotoCenterAndSetSecondAuthentication).Replace("{0}", "\r\n");
                            this.ShowMassage(ShowMsgType.Confirm, msg, () =>
                            {
                                var form = new UserMain.SecondAuthenticationForm();
                                form.AddForm();
                            });
                        });
                    });
                };
            }
 
            topFrameLayout.AddChidren(btnShortCut);
            btnShortCut.InitControl();
            if (HdlUserCenterResourse.ResidenceOption.SafetyShortcut == true)
            {
                //使用快捷方式
                btnShortCut.IsSelected = true;
            }
            btnShortCut.ButtonClickEvent += (sender, e) =>
            {
                if (btnShortCut.IsSelected == true)
                {
                    //确定取消主页的「安防」捷径?
                    this.ShowMassage(ShowMsgType.Confirm, Language.StringByID(R.MyInternationalizationString.uCancelSafetyShortcutMsg), () =>
                    {
                        HdlUserCenterResourse.ResidenceOption.SafetyShortcut = false;
                        HdlUserCenterResourse.ResidenceOption.Save();
                        btnShortCut.IsSelected = false;
                        //取消主页的「安防」捷径的话,主页需要重新刷新
                        UserView.UserPage.Instance.RefreshAllForm = true;
                    });
                }
                else
                {
                    //确定创建「安防」捷径到主页?
                    this.ShowMassage(ShowMsgType.Confirm, Language.StringByID(R.MyInternationalizationString.uCreatSafetyShortcutMsg), () =>
                    {
                        HdlUserCenterResourse.ResidenceOption.SafetyShortcut = true;
                        HdlUserCenterResourse.ResidenceOption.Save();
                        btnShortCut.IsSelected = true;
                        //创建主页的「安防」捷径的话,主页需要重新刷新
                        UserView.UserPage.Instance.RefreshAllForm = true;
                    });
                }
            };
        }
 
        #endregion
 
        #region ■ 初始化全部缓存_____________________
 
        /// <summary>
        /// 初始化全部内存信息
        /// </summary>
        private async void InitAllMemoryData()
        {
            //开启进度条
            this.ShowProgressBar();
 
            //正在与网关通讯中,请稍后
            this.SetProgressValue(Language.StringByID(R.MyInternationalizationString.uConnectToGatewayPleaseWait));
 
            //检测主网关
            var result = await this.CheckMainGateway();
            if (result == false)
            {
                //关闭进度条
                this.CloseProgressBar(ShowReLoadMode.YES);
                //网关回复超时,请稍后再试
                string msg = Language.StringByID(R.MyInternationalizationString.uGatewayResponseTimeOut);
                this.ShowMassage(ShowMsgType.Tip, msg);
 
                return;
            }
 
            //安防信息初始化中,请稍后
            this.SetProgressValue(Language.StringByID(R.MyInternationalizationString.uGarrisonInfoInittingPleaseWait));
 
            //刷新安防信息
            result = await HdlSafeguardLogic.Current.ReFreshByGateway();
            if (result == false)
            {
                //关闭进度条
                this.CloseProgressBar(ShowReLoadMode.YES);
                return;
            }
            //关闭进度条
            this.CloseProgressBar();
 
            //数据初始化完成后
            HdlThreadLogic.Current.RunMain(() =>
            {
                //初始化头部的那三个图标
                garrisonControl = new SafetyMasterControl();
                garrisonControl.Y = Application.GetRealHeight(46);
                bodyFrameLayout.AddChidren(garrisonControl);
                garrisonControl.InitControl();
                //初始化Tab控件
                this.InitTabSwitchControl();
 
                //设置传感器数据到画面
                this.SetSensorDataToForm();
            });
        }
 
        /// <summary>
        /// 检测主网关
        /// </summary>
        /// <returns></returns>
        private async Task<bool> CheckMainGateway()
        {
            int count = 0;
            //等待主网关
            while (ZbGateway.MainGateWay == null)
            {
                await Task.Delay(500);
                count++;
                if (count == 10)
                {
                    return false;
                }
            }
            return true;
        }
 
        #endregion
 
        #region ■ 界面关闭___________________________
 
        /// <summary>
        /// 画面关闭
        /// </summary>
        public override void CloseFormBefore()
        {
            //移除全部监听事件
            this.RemoveAllListenEvent();
 
            base.CloseFormBefore();
        }
 
        /// <summary>
        /// 移除全部监听事件
        /// </summary>
        private void RemoveAllListenEvent()
        {
            HdlGatewayReceiveLogic.Current.RemoveEvent("SafetyManagementMainFormAlarm");
            HdlGatewayReceiveLogic.Current.RemoveEvent("SafetyManagementMainFormReceivePushOnline");
        }
 
        #endregion
 
        #region ■ 传感器相关_________________________
 
        /// <summary>
        /// 传感器的状态控件
        /// </summary>
        private Dictionary<string, SafetySensorStatuControl> dicSensorStatuView = new Dictionary<string, SafetySensorStatuControl>();
 
        #region 添加传感器行_
 
        /// <summary>
        /// 设置传感器数据到画面
        /// </summary>
        private void SetSensorDataToForm()
        {
            if (this.TabSelectIndex != 2)
            {
                return;
            }
            //移除全部监听事件
            this.RemoveAllListenEvent();
 
            this.dicSensorStatuView.Clear();
 
            //添加列表控件 
            frameLayoutDraw.RemoveAll();
            var listView = new VerticalFrameControl(35);
            listView.Height = frameLayoutDraw.Height;
            frameLayoutDraw.AddChidren(listView);
 
            HdlThreadLogic.Current.RunThread(() =>
            {
                //获取安防的全部传感器设备的信息
                var dicDevice = HdlSafeguardLogic.Current.GetAllSensorDeviceInfo();
                var listDevice = new List<CommonDevice>();
 
                HdlThreadLogic.Current.RunMain(() =>
                {
                    foreach (var zoneId in dicDevice.Keys)
                    {
                        foreach (var Info in dicDevice[zoneId])
                        {
                            if (this.Parent == null)
                            {
                                return;
                            }
                            //添加行
                            this.AddSensorStatuRow(listView, zoneId, Info);
 
                            //收集传感器
                            var tempDevice = HdlDeviceCommonLogic.Current.GetDevice(Info.MacAddr, Info.Epoint);
                            if (tempDevice != null)
                            {
                                listDevice.Add(tempDevice);
                            }
                        }
                    }
                    //调整列表控件高度
                    listView.AdjustChidrenFrameHeight(listView.frameTable, Application.GetRealHeight(46));
                    //开启传感器报警监视
                    this.StartCheckDeviceAlarm();
                    //开启设备在线监测
                    this.StartCheckDeviceOnline(listDevice);
                });
            });
        }
 
        /// <summary>
        /// 添加传感器状态的行
        /// </summary>
        /// <param name="listView"></param>
        /// <param name="zoneID">防区ID</param>
        /// <param name="sensorInfo">传感器的信息</param>
        private void AddSensorStatuRow(VerticalFrameControl listView, int zoneID, Safeguard.ZoneDeviceListData sensorInfo)
        {
            CommonDevice device = HdlDeviceCommonLogic.Current.GetDevice(sensorInfo.MacAddr, sensorInfo.Epoint);
            if (device == null)
            {
                return;
            }
 
            //自定义传感器状态控件
            var frameDevice = new SafetySensorStatuControl();
            listView.AddChidren(frameDevice);
            frameDevice.InitControl(device);
            //添加阴影特效
            frameDevice.SetViewShadow(true);
 
            string mainkeys = HdlDeviceCommonLogic.Current.GetDeviceMainKeys(device);
            this.dicSensorStatuView[mainkeys] = frameDevice;
        }
 
        #endregion
 
        #region 传感器报警_
 
        /// <summary>
        /// 开启传感器报警监视
        /// </summary>
        private void StartCheckDeviceAlarm()
        {
            //根据接口推送,设置报警信息
            HdlGatewayReceiveLogic.Current.AddAttributeEvent("SafetyManagementMainFormAlarm", ReceiveComandDiv.A传感器上报, (device) =>
            {
                if (HdlSafeguardLogic.Current.IsSensorDeviceExist(device) == false)
                {
                    //如果这个设备不存在于安防,则不处理
                    return;
                }
 
                //传感器状态
                string mainkey = HdlDeviceCommonLogic.Current.GetDeviceMainKeys(device);
                if (this.dicSensorStatuView.ContainsKey(mainkey) == false)
                {
                    return;
                }
                var control = this.dicSensorStatuView[mainkey];
                //获取传感器报警信息的翻译文本
                var msgInfo = HdlAlarmsLogic.Current.GetSensorAlarmInfo(device);
                HdlThreadLogic.Current.RunMain(() =>
                {
                    control?.SetSensoReportInfo(msgInfo);
                });
            });
        }
 
        #endregion
 
        #region 在线状态_
 
        /// <summary>
        /// 上一次获取设备在线的时间(不能让它每点一次都去获取设备状态)
        /// </summary>
        private DateTime oldGetOnlineTime = new DateTime(1900, 1, 1);
 
        /// <summary>
        /// 开启设备在线监测
        /// </summary>
        /// <param name="listDevice">传感器列表</param>
        private void StartCheckDeviceOnline(List<CommonDevice> listDevice)
        {
            if (listDevice.Count == 0)
            {
                return;
            }
            if (oldGetOnlineTime.Year != 1900)
            {
                var timeValue = (DateTime.Now - oldGetOnlineTime).TotalSeconds;
                if (timeValue < 10)
                {
                    //最少要间隔十秒,才去重新获取
                    return;
                }
            }
            oldGetOnlineTime = DateTime.Now;
 
            //从设备列表中获取在线状态
            HdlThreadLogic.Current.RunThread(() =>
            {
                foreach (var device in listDevice)
                {
                    if (this.Parent == null)
                    {
                        //界面关闭
                        return;
                    }
                    var deviceInfo = HdlDeviceCommonLogic.Current.ReadDeviceEpointDeviceInfo(device);
                    if (deviceInfo != null)
                    {
                        //设置设备在线状态
                        this.ReceiveDeviceStatuPush(device, deviceInfo);
                    }
                    System.Threading.Thread.Sleep(50);
                }
            }, ShowErrorMode.NO);
        }
 
        /// <summary>
        /// 接受设备在线推送
        /// </summary>
        /// <param name="device"></param>
        private void ReceiveDeviceStatuPush(CommonDevice device, CommonDevice.DeviceInfoData deviceInfo)
        {
            if (this.Parent == null)
            {
                //界面关闭
                return;
            }
            string mainkeys = HdlDeviceCommonLogic.Current.GetDeviceMainKeys(device);
            if (this.dicSensorStatuView.ContainsKey(mainkeys) == true)
            {
                CommonDevice Loacldevice = HdlDeviceCommonLogic.Current.GetDevice(mainkeys);
                if (Loacldevice == null)
                {
                    return;
                }
                //在线状态一样的话,不需要刷新
                if (Loacldevice.IsOnline == deviceInfo.IsOnline)
                {
                    return;
                }
                //保存状态
                Loacldevice.IsOnline = deviceInfo.IsOnline;
 
                //因为这是推送过来的,我不保证那一瞬间这个东西会不会被移除
                var control = this.dicSensorStatuView[mainkeys];
                HdlThreadLogic.Current.RunMain(() =>
                {
                    //设置控件的在线状态文本效果
                    bool bolOnline = HdlDeviceCommonLogic.Current.CheckDeviceIsOnline(device);
                    control?.SetOnlineStatu(bolOnline);
                });
            }
        }
 
        #endregion
 
        #endregion
 
        #region ■ 安防记录相关_______________________
 
        /// <summary>
        /// 当日的安防记录的FrameLayout
        /// </summary>
        private SafeguardLogControl TodaySafeguardFrame = null;
        /// <summary>
        /// 其他日期的安防记录的FrameLayout
        /// </summary>
        private FrameLayout otherDaySafeguardFrame = null;
 
        /// <summary>
        /// 设置安防记录到界面
        /// </summary>
        private void SetSafeguardLogToForm()
        {
            if (this.TabSelectIndex != 1)
            {
                return;
            }
            //移除全部监听事件
            this.RemoveAllListenEvent();
 
            this.dicSensorStatuView.Clear();
 
            frameLayoutDraw.RemoveAll();
            var listView = new VerticalFrameControl(0);
            listView.Height = frameLayoutDraw.Height;
            frameLayoutDraw.AddChidren(listView);
 
            HdlThreadLogic.Current.RunThread(() =>
            {
                var dicAlarm = HdlAlarmsLogic.Current.GetSafeguardAlarmInfo();
                var dicInfo = new Dictionary<string, Dictionary<int, List<SafeguardAlarmInfo>>>();
                //这里不显示布防和撤防的信息
                foreach (var day in dicAlarm.Keys)
                {
                    var listInfo = new Dictionary<int, List<SafeguardAlarmInfo>>();
                    foreach (var info in dicAlarm[day])
                    {
                        if (info.AlarmType == SafeguardAlarmType.Sensor)
                        {
                            //只要传感器的
                            if (listInfo.ContainsKey(info.ZoneId) == false)
                            {
                                listInfo[info.ZoneId] = new List<SafeguardAlarmInfo>();
                            }
                            listInfo[info.ZoneId].Add(info);
                        }
                    }
                    //如果没有传感器的报警信息,则当不存在处理
                    if (listInfo.Count > 0)
                    {
                        dicInfo[day] = listInfo;
                    }
                }
                dicAlarm = null;
 
                HdlThreadLogic.Current.RunMain(() =>
                {
                    if (this.Parent == null)
                    {
                        return;
                    }
                    //初始化当日的安防记录控件
                    string nowDayKey = DateTime.Now.ToString("yyyyMMdd");
                    Dictionary<int, List<SafeguardAlarmInfo>> nowDayData = null;
                    if (dicInfo.ContainsKey(nowDayKey) == true)
                    {
                        nowDayData = dicInfo[nowDayKey];
                        //移除掉当日记录
                        dicInfo.Remove(nowDayKey);
                    }
                    //执行初始化
                    TodaySafeguardFrame = new SafeguardLogControl();
                    TodaySafeguardFrame.Y = Application.GetRealHeight(10);
                    listView.AddChidren(TodaySafeguardFrame);
                    TodaySafeguardFrame.InitControl(nowDayKey, nowDayData);
 
                    //初始化其他日期的安防记录控件
                    if (dicInfo.Count > 0)
                    {
                        otherDaySafeguardFrame = new FrameLayout();
                        otherDaySafeguardFrame.Height = Application.GetRealHeight(10);
                        listView.AddChidren(otherDaySafeguardFrame);
                        foreach (var dayText in dicInfo.Keys)
                        {
                            //执行初始化
                            var contr = new SafeguardLogControl();
                            if (otherDaySafeguardFrame.ChildrenCount > 0)
                            {
                                contr.Y = otherDaySafeguardFrame.GetChildren(otherDaySafeguardFrame.ChildrenCount - 1).Bottom + Application.GetRealHeight(35);
                            }
                            otherDaySafeguardFrame.AddChidren(contr);
                            contr.InitControl(dayText, dicInfo[dayText]);
                        }
                        //调整高度
                        otherDaySafeguardFrame.Height = otherDaySafeguardFrame.GetChildren(otherDaySafeguardFrame.ChildrenCount - 1).Bottom;
                    }
                    //调整桌布高度
                    listView.AdjustTableHeight();
                    //开启传感器报警监视
                    this.StartCheckDeviceAlarm();
                });
            });
        }
 
        /// <summary>
        /// 添加安防设备上报的行控件(安防推送会调用这个东西)
        /// </summary>
        /// <param name="device">设备对象</param>
        public void AddSafeguardLogPushRow(CommonDevice device)
        {
            if (this.TabSelectIndex != 1 || HdlAlarmsLogic.Current.listSafetyAlarmInfo.Count == 0)
            {
                return;
            }
            var info = HdlAlarmsLogic.Current.listSafetyAlarmInfo[0];
            if (device != null)
            {
                string mainkey1 = HdlDeviceCommonLogic.Current.GetDeviceMainKeys(info.DeviceAddr, info.DeviceEpoint);
                string mainkey2 = HdlDeviceCommonLogic.Current.GetDeviceMainKeys(device);
                if (mainkey1 != mainkey2)
                {
                    //不是同一个东西
                    return;
                }
            }
 
            HdlThreadLogic.Current.RunMain(() =>
            {
                if (this.TodaySafeguardFrame != null)
                {
                    //添加报警信息
                    var value = this.TodaySafeguardFrame.AddSafeguardAlarmInfo(info);
                    if (value > 0)
                    {
                        //其他日期的FrameLayout往下移动
                        if (this.otherDaySafeguardFrame != null)
                        {
                            this.otherDaySafeguardFrame.Y += value;
                        }
                        //桌布控件
                        var contrTable = (FrameLayout)this.TodaySafeguardFrame.Parent;
                        //列表控件
                        var listview = (VerticalFrameControl)contrTable.Parent;
                        //调整桌布高度
                        listview?.AdjustTableHeight();
                    }
                }
            });
        }
 
        /// <summary>
        /// 防区推送
        /// </summary>
        /// <param name="garrison"></param>
        public void GarrisonModePush(GarrisonMode garrison)
        {
            HdlThreadLogic.Current.RunMain(() =>
            {
                garrisonControl?.SetIconStatuByGarrisonMode(garrison);
            });
        }
 
        #endregion
 
        #region ■ 界面重新激活事件___________________
 
        /// <summary>
        /// 自身的上层界面关闭后,它自身处于最上层时,触发的事件
        /// </summary>
        public override int FormActionAgainEvent()
        {
            //设置布防按钮的可视状态
            garrisonControl?.SetButtonVisible();
 
            if (this.TabSelectIndex == 1)
            {
                //设置安防记录到界面
                this.SetSafeguardLogToForm();
            }
            else if (this.TabSelectIndex == 2)
            {
                //设置传感器数据到画面
                this.SetSensorDataToForm();
            }
            return 1;
        }
 
        #endregion
    }
}