黄学彪
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
using System;
using System.Collections.Generic;
using Shared.Common;
using Shared.Phone.Device.CommonForm;
using Shared.Phone.UserCenter;
using Shared.Phone.UserView;
using ZigBee.Device;
 
namespace Shared.Phone.MainPage
{
    /// <summary>
    /// 未分配的管理界面
    /// </summary>
    public class UnallocatedRoomForm : EditorCommonForm
    {
        #region ■ 变量声明___________________________
 
        /// <summary>
        /// 界面关闭事件
        /// </summary>
        public Action FormCloseEvent = null;
        /// <summary>
        /// 添加到 的背景图控件
        /// </summary>
        private FrameLayoutStatuControl frameAddBackGroud = null;
        /// <summary>
        /// 功能的桌布控件
        /// </summary>
        private NormalFrameLayout DeviceBodyTableControl = null;
        /// <summary>
        /// 场景的列表控件
        /// </summary>
        private VerticalFrameControl listSceneView = null;
        /// <summary>
        /// 设备的列表控件
        /// </summary>
        private VerticalListControl listDeviceView = null;
        /// <summary>
        /// 场景的桌布控件
        /// </summary>
        private NormalFrameLayout SceneBodyTableControl = null;
        /// <summary>
        /// 全选控件
        /// </summary>
        private NormalViewControl btnAllSelect = null;
        /// <summary>
        /// 选择的场景
        /// </summary>
        private Dictionary<int, SceneUI> dicSelectScene = new Dictionary<int, SceneUI>();
        /// <summary>
        /// 选择的设备
        /// </summary>
        private Dictionary<string, CommonDevice> dicSelectDevice = new Dictionary<string, CommonDevice>();
        /// <summary>
        /// 当前选择的设备类型信息(为了处理速度使用)
        /// </summary>
        private DeviceRowInfo nowSelectDeviceInfo = null;
        /// <summary>
        /// 全部分组的设备信息
        /// </summary>
        private Dictionary<string, DeviceRowInfo> dicGroupDevice = null;
        /// <summary>
        /// 是否已经改变了数据
        /// </summary>
        private bool dataHadChanged = false;
        /// <summary>
        /// 能否全选的状态
        /// </summary>
        private bool canSelectAll = true;
 
        #endregion
 
        #region ■ 初始化_____________________________
 
        /// <summary>
        /// 画面显示(底层会固定调用此方法,借以完成画面创建)
        /// </summary>
        public void ShowForm()
        {
            //初始化头部控件
            this.InitTopFrameLayout();
            //初始化中部控件
            this.InitBodyFrameLayout();
 
            //设置头部信息
            base.SetTitleText(Language.StringByID(R.MyInternationalizationString.Unallocated));
 
            //初始化全选控件
            this.InitAllSelectControl();
 
            //初始化中部信息
            this.InitMiddleFrame();
        }
 
        /// <summary>
        /// 初始化中部信息
        /// </summary>
        private void InitMiddleFrame()
        {
            var tabControl = new SceneFunctionSwitchControl();
            tabControl.Y = Application.GetRealHeight(40);
            bodyFrameLayout.AddChidren(tabControl);
 
            //初始化场景桌布
            this.SceneBodyTableControl = new NormalFrameLayout();
            SceneBodyTableControl.Y = tabControl.Bottom;
            SceneBodyTableControl.Height = bodyFrameLayout.Height - tabControl.Bottom;
            bodyFrameLayout.AddChidren(SceneBodyTableControl);
            //初始化设备桌布
            this.DeviceBodyTableControl = new NormalFrameLayout();
            DeviceBodyTableControl.Y = tabControl.Bottom;
            DeviceBodyTableControl.Height = bodyFrameLayout.Height - tabControl.Bottom;
            bodyFrameLayout.AddChidren(DeviceBodyTableControl);
 
            tabControl.SelectTabEvent += (index) =>
            {
                //场景
                if (index == 0)
                {
                    //初始化场景分支的控件
                    this.InitSceneCaseControl();
                    //检测各控件状态
                    this.CheckControlsStatu(null);
                }
                //功能
                else
                {
                    //初始化功能分支的控件
                    this.InitDeviceCaseControl();
                    //检测各控件状态
                    this.CheckControlsStatu(this.nowSelectDeviceInfo);
                }
            };
 
            //开始初始化场景功能切换控件
            var listTitle = new List<string>();
            listTitle.Add(Language.StringByID(R.MyInternationalizationString.uScence));
            listTitle.Add(Language.StringByID(R.MyInternationalizationString.uFunction));
            //他会自动回调事件
            tabControl.InitControl(listTitle);
        }
 
        #endregion
 
        #region ■ 场景分支___________________________
 
        /// <summary>
        /// 初始化场景分支的控件
        /// </summary>
        private void InitSceneCaseControl()
        {
            //隐藏设备列表
            this.DeviceBodyTableControl.Visible = false;
            //显示场景
            this.SceneBodyTableControl.Visible = true;
            if (this.SceneBodyTableControl.Name == "Scene")
            {
                //已经初始化过
                return;
            }
            //打个标识而已
            this.SceneBodyTableControl.Name = "Scene";
            //开始执行初始化场景分支的控件
            this.DoInitSceneCaseControl();
        }
 
        /// <summary>
        /// 开始执行初始化场景分支的控件
        /// </summary>
        private void DoInitSceneCaseControl()
        {
            HdlThreadLogic.Current.RunMainInThread(() =>
            {
                //清空桌布
                this.SceneBodyTableControl.RemoveAll();
 
                this.listSceneView = new VerticalFrameControl(3);
                listSceneView.Y = Application.GetRealHeight(53);
                listSceneView.Height = SceneBodyTableControl.Height;
                SceneBodyTableControl.AddChidren(listSceneView);
 
                var listScene = HdlSceneLogic.Current.GetUnalloctedScenes();
                if (listScene.Count == 0) { return; }
 
                foreach (var data in listScene)
                {
                    //场景图片
                    var frameContr = new ScenePictrueControl();
                    listSceneView.AddChidren(frameContr);
                    frameContr.InitControl(data);
 
                    //添加选择控件
                    frameContr.AddSelectControl();
 
                    //收藏
                    frameContr.AddCollectionControl();
                    frameContr.CollectEvent += (collect) =>
                    {
                        //如果当前是收藏房间,则需要刷新主页
                        if (HdlRoomLogic.Current.NowMainPageRoom.IsLove == true)
                        {
                            this.dataHadChanged = true;
                        }
                    };
  
                    frameContr.ButtonClickEvent += (sender, e) =>
                    {
                        //选择
                        frameContr.IsSelected = !frameContr.IsSelected;
                        if (frameContr.IsSelected == true)
                        {
                            dicSelectScene[data.Id] = data;
                        }
                        else
                        {
                            dicSelectScene.Remove(data.Id);
                        }
                        //检测各控件状态
                        this.CheckControlsStatu(null);
                    };
                }
                //促使它超过时,能够往上滑
                var frameTemp = new FrameLayout();
                frameTemp.Height = Application.GetRealHeight(202 + 23);
                listSceneView.AddChidren(frameTemp);
            });
        }
 
        #endregion
 
        #region ■ 功能分支___________________________
 
        /// <summary>
        /// 初始化功能分支的控件
        /// </summary>
        private void InitDeviceCaseControl()
        {
            //隐藏场景列表
            this.SceneBodyTableControl.Visible = false;
            //显示功能
            this.DeviceBodyTableControl.Visible = true;
            if (this.DeviceBodyTableControl.Name == "Function")
            {
                //已经初始化过
                return;
            }
            //打个标识而已
            this.DeviceBodyTableControl.Name = "Function";
            //开始执行初始化功能分支的控件
            this.DoInitDeviceCaseControl();
        }
 
        /// <summary>
        /// 开始执行初始化功能分支的控件
        /// </summary>
        private void DoInitDeviceCaseControl()
        {
            HdlThreadLogic.Current.RunMainInThread(() =>
            {
                //清空桌布,不清空这个的话,它里面还有上一次的东西
                this.listDeviceView?.RemoveAll();
                this.DeviceBodyTableControl.RemoveAll();
 
                //获取分组后的设备列表
                this.dicGroupDevice = this.GetAllGroupDevice();
                if (dicGroupDevice.Count == 0)
                {
                    this.listDeviceView = null;
                    return;
                }
 
                //设备的背景容器
                var frameDeviceBack = new FrameLayout();
                frameDeviceBack.X = HdlControlResourse.XXLeft;
                frameDeviceBack.Y = Application.GetRealHeight(369);
                frameDeviceBack.BackgroundColor = UserCenterColor.Current.White;
                frameDeviceBack.Width = bodyFrameLayout.Width;
                frameDeviceBack.Height = Application.GetRealHeight(1236);
                frameDeviceBack.Radius = (uint)Application.GetRealHeight(58);
                DeviceBodyTableControl.AddChidren(frameDeviceBack);
                //设备列表控件
                this.listDeviceView = new VerticalListControl(35);
                listDeviceView.Y = Application.GetRealHeight(14);
                listDeviceView.Height = Application.GetRealHeight(1236 - 14);
                frameDeviceBack.AddChidren(listDeviceView);
 
                //初始化设备类型菜单
                this.InitDeviceObjectMenu();
            });
        }
 
        #endregion
 
        #region ■ 初始化设备类型菜单_________________
 
        /// <summary>
        /// 初始化设备类型菜单
        /// </summary>
        private void InitDeviceObjectMenu()
        {
            //头部的白色背景
            var functionBack1 = new FrameLayout();
            functionBack1.X = HdlControlResourse.XXLeft;
            functionBack1.Y = Application.GetRealHeight(55);
            functionBack1.Height = Application.GetRealHeight(160);
            functionBack1.Width = Application.GetRealWidth(1028);
            functionBack1.BackgroundColor = ZigbeeColor.Current.GXCBackgroundColor;
            DeviceBodyTableControl.AddChidren(functionBack1);
            functionBack1.SetCornerWithSameRadius(Application.GetRealHeight(17), HDLUtils.RectCornerTopLeft);
            var functionBack2 = new FrameLayout();
            functionBack2.X = HdlControlResourse.XXLeft;
            functionBack2.Y = functionBack1.Bottom - Application.GetRealHeight(50);
            functionBack2.Height = Application.GetRealHeight(279 - 160 + 50);
            functionBack2.Width = Application.GetRealWidth(1028);
            functionBack2.BackgroundColor = ZigbeeColor.Current.GXCBackgroundColor;
            DeviceBodyTableControl.AddChidren(functionBack2);
            functionBack2.SetCornerWithSameRadius(Application.GetRealHeight(58), HDLUtils.RectCornerBottomLeft);
 
            //左右滑动的控件
            var HorizontalView = new HorizontalScrolViewLayout();
            HorizontalView.X = HdlControlResourse.XXLeft;
            HorizontalView.Y = Application.GetRealHeight(55);
            HorizontalView.Height = Application.GetRealHeight(279);
            HorizontalView.Width = Application.GetRealWidth(1028);
            DeviceBodyTableControl.AddChidren(HorizontalView);
 
            //上一次选择的菜单
            Controls.DeviceFunctionMenuControl oldSelectContr = null;
            foreach (string strText in this.dicGroupDevice.Keys)
            {
                var rowInfo = dicGroupDevice[strText];
 
                //设备类型的容器
                var devieFrame = new FrameLayout();
                devieFrame.Width = Application.GetRealWidth(220);
                HorizontalView.AddChidren(devieFrame);
 
                //菜单图片控件
                var deviceObjContr = new Controls.DeviceFunctionMenuControl();
                devieFrame.AddChidren(deviceObjContr);
                deviceObjContr.InitControl(strText, rowInfo.IconPath, rowInfo.IconPathSelected);
                deviceObjContr.ButtonClickEvent += (sender, e) =>
                {
                    //选择的是同一个东西的话,不处理
                    if (this.nowSelectDeviceInfo.Text != rowInfo.Text)
                    {
                        //上一次的菜单取消,本次菜单选择
                        oldSelectContr.SetSelectStatu(false);
                        deviceObjContr.SetSelectStatu(true);
                        oldSelectContr = deviceObjContr;
 
                        this.nowSelectDeviceInfo = rowInfo;
                        HdlThreadLogic.Current.RunMainInThread(() =>
                        {
                            //初始化设备列表控件
                            this.InitListDeviceControls(rowInfo);
                            //检测各控件状态
                            this.CheckControlsStatu(this.nowSelectDeviceInfo);
                        });
                    }
                };
 
                if (this.nowSelectDeviceInfo == null)
                {
                    //设置初始选择
                    this.nowSelectDeviceInfo = rowInfo;
                    //记录初始选择的菜单控件
                    oldSelectContr = deviceObjContr;
                    deviceObjContr.SetSelectStatu(true);
                }
            }
            if (this.nowSelectDeviceInfo != null)
            {
                //初始化默认的设备列表控件
                this.InitListDeviceControls(nowSelectDeviceInfo);
            }
        }
 
        #endregion
 
        #region ■ 初始化设备列表控件_________________
 
        /// <summary>
        /// 初始化设备列表控件
        /// </summary>
        /// <param name="rowInfo"></param>
        /// <param name="listView"></param>
        private void InitListDeviceControls(DeviceRowInfo rowInfo)
        {
            this.listDeviceView.RemoveAll();
            //初始化设备列表控件
            foreach (var deviceKey in rowInfo.listDeviceKeys)
            {
                var device = HdlDeviceCommonLogic.Current.GetDevice(deviceKey);
                var deviceRow = new Controls.DeviceSelectUnallocatedControl(listDeviceView.rowSpace / 2);
                listDeviceView.AddChidren(deviceRow);
                deviceRow.InitControl(device);
 
                if (this.dicSelectDevice.ContainsKey(deviceKey) == true)
                {
                    //如果它之前选择了的话
                    deviceRow.IsSelected = true;
                }
                deviceRow.ButtonClickEvent += (sender, e) =>
                {
                    deviceRow.IsSelected = !deviceRow.IsSelected;
                    //记录缓存
                    if (deviceRow.IsSelected == true)
                    {
                        this.dicSelectDevice[deviceKey] = device;
                    }
                    else
                    {
                        this.dicSelectDevice.Remove(deviceKey);
                    }
                    //检测各控件状态
                    this.CheckControlsStatu(rowInfo);
                };
            }
            //促使它超过时,能够往上滑
            var frameTemp = new FrameLayout();
            frameTemp.Height = Application.GetRealHeight(202 + 23);
            listDeviceView.AddChidren(frameTemp);
        }
 
        #endregion
 
        #region ■ 全选控件___________________________
 
        /// <summary>
        /// 初始化全选控件
        /// </summary>
        private void InitAllSelectControl()
        {
            this.btnAllSelect = new NormalViewControl(150, 70, true);
            btnAllSelect.TextAlignment = TextAlignment.CenterRight;
            btnAllSelect.X = topFrameLayout.Width - Application.GetRealWidth(150 + 115);
            btnAllSelect.Gravity = Gravity.CenterVertical;
            btnAllSelect.TextID = R.MyInternationalizationString.AllSelect;
            btnAllSelect.IsBold = true;
            topFrameLayout.AddChidren(btnAllSelect);
            btnAllSelect.ButtonClickEvent += (sender, e) =>
            {
                //场景分支
                if (SceneBodyTableControl.Visible == true)
                {
                    if (listSceneView == null) { return; }
                    for (int i = 0; ; i++)
                    {
                        var myContr = listSceneView.frameTable.GetChildren(i);
                        if (myContr == null)
                        {
                            break;
                        }
                        if (myContr is ScenePictrueControl)
                        {
                            ((ScenePictrueControl)myContr).IsSelected = this.canSelectAll;
                            var scene = ((ScenePictrueControl)myContr).scene;
                            if (this.canSelectAll == true)
                            {
                                //添加缓存
                                dicSelectScene[scene.Id] = scene;
                            }
                            else
                            {
                                //移除缓存
                                dicSelectScene.Remove(scene.Id);
                            }
                        }
                    }
                    //检测各控件状态
                    this.CheckControlsStatu(null);
                }
                //功能分支
                else
                {
                    if (listDeviceView == null) { return; }
                    for (int i = 0; ; i++)
                    {
                        var myContr = listDeviceView.GetChildren(i);
                        if (myContr == null)
                        {
                            break;
                        }
                        if (myContr is Controls.DeviceSelectUnallocatedControl)
                        {
                            ((Controls.DeviceSelectUnallocatedControl)myContr).IsSelected = this.canSelectAll;
                            var device = ((Controls.DeviceSelectUnallocatedControl)myContr).device;
                            if (this.canSelectAll == true)
                            {
                                //添加缓存
                                dicSelectDevice[HdlDeviceCommonLogic.Current.GetDeviceMainKeys(device)] = device;
                            }
                            else
                            {
                                //移除缓存
                                dicSelectDevice.Remove(HdlDeviceCommonLogic.Current.GetDeviceMainKeys(device));
                            }
                        }
                    }
                    //检测各控件状态
                    this.CheckControlsStatu(this.nowSelectDeviceInfo);
                }
            };
        }
 
        #endregion
 
        #region ■ [添加到]控件_______________________
 
        /// <summary>
        /// 初始化添加到控件
        /// </summary>
        private void InitAddToControl()
        {
            //添加到 的背景图控件
            this.frameAddBackGroud = new FrameLayoutStatuControl();
            frameAddBackGroud.UseClickStatu = false;
            frameAddBackGroud.Height = Application.GetRealHeight(202);
            frameAddBackGroud.Gravity = Gravity.BottomCenter;
            frameAddBackGroud.BackgroundImagePath = "Room/AddBackground.png";
            bodyFrameLayout.AddChidren(frameAddBackGroud);
            frameAddBackGroud.Visible = false;
 
            //添加到 按钮
            var btnAdd = new NormalViewControl(1034, 156, true);
            btnAdd.Gravity = Gravity.Center;
            btnAdd.BackgroundColor = UserCenterColor.Current.White;
            btnAdd.TextColor = ZigbeeColor.Current.GXCTextSelectedColor4;
            btnAdd.TextAlignment = TextAlignment.Center;
            btnAdd.TextID = R.MyInternationalizationString.AddTo;
            btnAdd.TextSize = 17;
            btnAdd.Radius = (uint)Application.GetRealHeight(35);
            frameAddBackGroud.AddChidren(btnAdd, ChidrenBindMode.BindEvent);
            frameAddBackGroud.ButtonClickEvent += (sender, e) =>
            {
                HdlControlLogic.Current.ShowBottomListRoomView(string.Empty, Language.StringByID(R.MyInternationalizationString.AddTo), (selectId, selectName) =>
                {
                    if (selectId == string.Empty)
                    {
                        //选择的是未分配
                        return;
                    }
                    //变更了当前房间的东西,主页需要刷新
                    if (HdlRoomLogic.Current.NowMainPageRoom.Id == selectId)
                    {
                        this.dataHadChanged = true;
                    }
                    //保存选择的设备和场景
                    var room = HdlRoomLogic.Current.GetRoomById(selectId);
                    this.SaveSelectDeviceAndScene(room);
                    //分类界面需要刷新
                    UserPage.Instance.RefreshCategoryForm = true;
                    //上传空间区域信息
                    HdlRoomLogic.Current.SetRoomInfoToGateway();
                });
            };
        }
 
        /// <summary>
        /// 保存选择的设备和场景
        /// </summary>
        /// <param name="room"></param>
        private void SaveSelectDeviceAndScene(Room room)
        {
            foreach (var deviceKey in this.dicSelectDevice.Keys)
            {
                //添加设备
                HdlRoomLogic.Current.AddDevice(room, dicSelectDevice[deviceKey], true);
                foreach (var rowInf in dicGroupDevice.Values)
                {
                    //移除缓存
                    if (rowInf.listDeviceKeys.Contains(deviceKey) == true)
                    {
                        rowInf.listDeviceKeys.Remove(deviceKey);
                    }
                }
            }
            foreach (var scene in this.dicSelectScene.Values)
            {
                //添加场景
                HdlSceneLogic.Current.AddSceneToRoom(room, scene);
            }
            //清空缓存
            this.dicSelectScene.Clear();
            this.dicSelectDevice.Clear();
            //右上角的文字切换为 全选
            btnAllSelect.TextID = R.MyInternationalizationString.AllSelect;
            this.canSelectAll = true;
 
            //场景分支需要重新初始化
            this.DoInitSceneCaseControl();
 
            if (this.nowSelectDeviceInfo != null)
            {
               
                bool allHadDevice = true;
                foreach (var data in this.dicGroupDevice.Values)
                {
                    if (data.listDeviceKeys.Count == 0)
                    {
                        //有分支已经没有设备了
                        allHadDevice = false;
                        break;
                    }
                }
                //如果所有分支都还有设备的话,就刷新当前的列表即可
                if (allHadDevice == true)
                {
                    //初始化设备列表控件
                    this.InitListDeviceControls(this.nowSelectDeviceInfo);
                }
                else
                {
                    //如果存在分支已经没有设备了的话,那么它的菜单也需要删除掉,所以需要重新初始化
                    this.nowSelectDeviceInfo = null;
                    this.DoInitDeviceCaseControl();
                }
            }
            //隐藏 添加到 按钮
            this.frameAddBackGroud.Visible = false;
        }
 
        #endregion
 
        #region ■ 整合设备___________________________
 
        /// <summary>
        /// 获取分组后的设备
        /// </summary>
        /// <returns></returns>
        private Dictionary<string, DeviceRowInfo> GetAllGroupDevice()
        {
            //全部的设备
            var listDevice = HdlRoomLogic.Current.GetUnalloctedDevice();
            //根据设备所属类型排序
            listDevice = HdlDeviceCommonLogic.Current.SortDeviceByBelongType(listDevice);
            var dic = new Dictionary<string, DeviceRowInfo>();
            foreach (var device in listDevice)
            {
                var typeInfo = HdlDeviceCommonLogic.Current.GetDeviceBelongEnumInfo(device);
                //按所属ID分组
                if (dic.ContainsKey(typeInfo.BeloneText) == false)
                {
                    dic[typeInfo.BeloneText] = new DeviceRowInfo();
                    string path1 = string.Empty;
                    string path2 = string.Empty;
                    //获取图片
                    HdlDeviceCommonLogic.Current.GetDeviceFunctionTypeMenuIcon(typeInfo, ref path1, ref path2);
                    dic[typeInfo.BeloneText].IconPath = path1;
                    dic[typeInfo.BeloneText].IconPathSelected = path2;
                    dic[typeInfo.BeloneText].Text = typeInfo.BeloneText;
                }
                dic[typeInfo.BeloneText].listDeviceKeys.Add(HdlDeviceCommonLogic.Current.GetDeviceMainKeys(device));
            }
            return dic;
        }
 
        #endregion
 
        #region ■ 界面关闭___________________________
 
        /// <summary>
        /// 界面关闭
        /// </summary>
        public override void CloseFormBefore()
        {
            //调用回调事件
            this.FormCloseEvent?.Invoke();
            this.FormCloseEvent = null;
 
            if (this.dataHadChanged == true)
            {
                HdlThreadLogic.Current.RunMainInThread(() =>
                {
                    //刷新主页
                    HomeMainPageForm.Instance?.RefreshBodyView();
                });
            }
            base.CloseFormBefore();
        }
 
        #endregion
 
        #region ■ 一般方法___________________________
 
        /// <summary>
        /// 检测各控件状态
        /// </summary>
        private void CheckControlsStatu(DeviceRowInfo rowInfo)
        {
            if (this.frameAddBackGroud == null)
            {
                //初始化添加到控件
                this.InitAddToControl();
            }
 
            if (dicSelectScene.Count == 0 && dicSelectDevice.Count == 0)
            {
                //隐藏 添加到 控件
                if (frameAddBackGroud.Visible == true)
                {
                    frameAddBackGroud.Visible = false;
                }
            }
            else
            {
                //显示 添加到 控件
                if (frameAddBackGroud.Visible == false)
                {
                    frameAddBackGroud.Visible = true;
                }
            }
            //当前选择的是场景分支
            if (rowInfo == null)
            {
                if (this.dicSelectScene.Count > 0)
                {
                    //右上角的文字切换为 取消
                    btnAllSelect.TextID = R.MyInternationalizationString.Cancel;
                    this.canSelectAll = false;
                }
                else
                {
                    //右上角的文字切换为 全选
                    btnAllSelect.TextID = R.MyInternationalizationString.AllSelect;
                    this.canSelectAll = true;
                }
            }
            //当前选择的是功能分支
            else
            {
                foreach (var deviceKey in rowInfo.listDeviceKeys)
                {
                    //如果当前的设备类型选择分支下,存在之前选择的设备的话
                    if (this.dicSelectDevice.ContainsKey(deviceKey) == true)
                    {
                        //右上角的文字切换为 取消
                        btnAllSelect.TextID = R.MyInternationalizationString.Cancel;
                        this.canSelectAll = false;
                        return;
                    }
                }
                //如果不存在的话,右上角的文字切换为 全选
                btnAllSelect.TextID = R.MyInternationalizationString.AllSelect;
                this.canSelectAll = true;
            }
        }
 
        #endregion
 
        #region ■ 结构体_____________________________
 
        /// <summary>
        /// 设备行信息
        /// </summary>
        private class DeviceRowInfo
        {
            /// <summary>
            /// 文本,目前用来做主键
            /// </summary>
            public string Text = string.Empty;
            /// <summary>
            /// 图标
            /// </summary>
            public string IconPath = string.Empty;
            /// <summary>
            /// 图标
            /// </summary>
            public string IconPathSelected = string.Empty;
            /// <summary>
            /// 设备回路主键
            /// </summary>
            public List<string> listDeviceKeys = new List<string>();
        }
 
        #endregion
    }
}