黄学彪
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
using Shared.Common;
using Shared.Phone.UserCenter;
using System;
using System.Collections.Generic;
using System.Text;
using ZigBee.Device;
 
namespace Shared.Phone.Category
{
    /// <summary>
    /// 场景执行目标添加设备的界面
    /// </summary>
    public class AdjustTargetAddDeviceForm : EditorCommonForm
    {
        #region ■ 变量声明___________________________
 
        /// <summary>
        /// 完成选择的事件(Key:设备主键)
        /// </summary>
        public Action<Dictionary<string, List<Safeguard.TaskListInfo>>> FinishSelectEvent = null;
        /// <summary>
        /// 当前已经添加的执行目标
        /// </summary>
        private List<Scene.DeviceListData> listAdjustTarget = null;
        /// <summary>
        /// 当前已经添加的执行目标(存在检测用)
        /// </summary>
        private Dictionary<string, List<Safeguard.TaskListInfo>> dicOldListTask = null;
        /// <summary>
        /// 当前界面上显示的执行目标(存在检测用)
        /// </summary>
        private Dictionary<string, List<Safeguard.TaskListInfo>> dicNewListTask = null;
        /// <summary>
        /// 完成按钮
        /// </summary>
        private BottomClickButton btnFinishControl = null;
        /// <summary>
        /// 设备功能的菜单控件
        /// </summary>
        private HorizontalScrolViewLayout deviceFunctionMenuContr = null;
        /// <summary>
        /// 设备列表控件
        /// </summary>
        private VerticalListControl listDeviceView = null;
        /// <summary>
        /// 当前选择的楼层
        /// </summary>
        private string nowSelectFloorId = string.Empty;
 
        #endregion
 
        #region ■ 初始化_____________________________
 
        /// <summary>
        /// 画面显示(底层会固定调用此方法,借以完成画面创建)
        /// </summary>
        /// <param name="i_listAdjustTarget">当前执行目标列表</param>
        public void ShowForm(List<Scene.DeviceListData> i_listAdjustTarget)
        {
            this.listAdjustTarget = i_listAdjustTarget;
 
            //设置头部信息
            base.SetTitleText(Language.StringByID(R.MyInternationalizationString.AddFunction));
            //初始化右上角的控件
            this.InitTopRightMenuControl();
            //初始化中部信息
            this.InitMiddleFrame();
        }
 
        /// <summary>
        /// 初始化中部信息
        /// </summary>
        private void InitMiddleFrame()
        {
            //清空body
            this.ClearBodyFrame();
            //初始化房间菜单控件
            this.InitRoomMenuControl();
        }
 
        /// <summary>
        /// 初始化右上角的控件
        /// </summary>
        private void InitTopRightMenuControl()
        {
            //获取楼层
            var dicFloor = HdlRoomLogic.Current.GetFloorSortList();
            if (dicFloor.Count == 0)
            {
                return;
            }
            var btnIconContr = new MostRightIconControl(69, 69);
            btnIconContr.UnSelectedImagePath = "Item/Drop_Down.png";
            topFrameLayout.AddChidren(btnIconContr);
            btnIconContr.InitControl();
 
            var btnFloor = new NormalViewControl(300, 69, true);
            btnFloor.Gravity = Gravity.CenterVertical;
            btnFloor.X = btnIconContr.X + btnIconContr.btnIcon.X - Application.GetRealWidth(300);
            btnFloor.TextAlignment = TextAlignment.CenterRight;
            topFrameLayout.AddChidren(btnFloor);
 
            foreach (var floorId in dicFloor.Keys)
            {
                //第一个楼层
                this.nowSelectFloorId = floorId;
                btnFloor.Text = dicFloor[floorId];
                break;
            }
 
            btnIconContr.ButtonClickEvent += (sender, e) =>
            {
                //楼层菜单
                var contr = new TopRightFloorMenuControl(dicFloor.Count, 2, this.nowSelectFloorId, Language.StringByID(R.MyInternationalizationString.SelectFloor));
                foreach (var floorId in dicFloor.Keys)
                {
                    contr.AddRowMenu(floorId, () =>
                    {
                        //记录起选择的ID
                        this.nowSelectFloorId = floorId;
                        btnFloor.Text = dicFloor[this.nowSelectFloorId];
                        //初始化中部信息
                        this.InitMiddleFrame();
                    });
                }
            };
        }
 
        #endregion
 
        #region ■ 房间菜单控件_______________________
 
        /// <summary>
        /// 初始化房间菜单控件
        /// </summary>
        private void InitRoomMenuControl()
        {
            //获取能够显示的房间列表
            var listRoom = this.GetCanShowRoomList();
            if (listRoom.Count == 0)
            {
                //没有可以添加的目标
                this.ShowNotDataImage(bodyFrameLayout, Language.StringByID(R.MyInternationalizationString.uNotHadAddTarget));
                return;
            }
 
            //这个控件的高度为:房间菜单的底部到屏幕底部
            var functionBodyView = new FrameLayout();
 
            //房间菜单控件
            var roomSwitchContr = new RoomDeviceGroupMenuControl(listRoom);
            this.bodyFrameLayout.AddChidren(roomSwitchContr);
            //选择事件
            roomSwitchContr.SelectRoomEvent += (selectRoom) =>
            {
                //在外面清空(特效的问题)
                if (this.deviceFunctionMenuContr != null && this.deviceFunctionMenuContr.Parent != null)
                {
                    this.deviceFunctionMenuContr.RemoveAll();
                }
                this.listDeviceView?.RemoveAll();
 
                HdlThreadLogic.Current.RunMainInThread(() =>
                {
                    //刷新设备分支控件
                    this.RefreshFunctionView(selectRoom, functionBodyView);
                });
            };
 
            functionBodyView.Y = roomSwitchContr.Bottom;
            functionBodyView.Height = bodyFrameLayout.Height - roomSwitchContr.Bottom;
            bodyFrameLayout.AddChidren(functionBodyView);
 
            //完成按钮
            this.btnFinishControl = new BottomClickButton();
            btnFinishControl.TextID = R.MyInternationalizationString.uFinish;
            bodyFrameLayout.AddChidren(btnFinishControl);
            if (this.dicNewListTask == null || this.dicNewListTask.Count == 0)
            {
                btnFinishControl.Visible = false;
            }
            btnFinishControl.ButtonClickEvent += (sender, e) =>
            {
                //回调函数
                this.FinishSelectEvent?.Invoke(this.dicNewListTask);
 
                this.CloseForm();
            };
 
            //执行初始化(会自动触发SelectRoomEvent事件)
            roomSwitchContr.InitControl();
        }
 
        /// <summary>
        /// 获取能够显示的房间列表
        /// </summary>
        /// <param name="listRomm"></param>
        /// <returns></returns>
        private List<Room> GetCanShowRoomList()
        {
            if (this.dicNewListTask == null)
            {
                //先将列表Dictionary化
                this.dicNewListTask = new Dictionary<string, List<Safeguard.TaskListInfo>>();
                this.dicOldListTask = new Dictionary<string, List<Safeguard.TaskListInfo>>();
                foreach (var data in this.listAdjustTarget)
                {
                    if (data.Type == 0)
                    {
                        //只要设备
                        string mainkey = HdlDeviceCommonLogic.Current.GetDeviceMainKeys(data.DeviceAddr, data.Epoint);
                        dicOldListTask[mainkey] = data.TaskList;
                    }
                }
            }
          
            //当前楼层的全部房间
            var lisrRoom = HdlRoomLogic.Current.GetRoomsByFloorIdAppendLoveRoom(this.nowSelectFloorId);
            var listShowRoom = new List<Room>();
            foreach (var room in lisrRoom)
            {
                foreach (var mainkey in room.ListDevice)
                {
                    var device = HdlDeviceCommonLogic.Current.GetDevice(mainkey);
                    if (this.CheckDeviceCanShow(device) == true)
                    {
                        //这个设备本地存在,并且它还没有加入到执行目标列表,则这个房间可以显示
                        listShowRoom.Add(room);
                        break;
                    }
                }
            }
            return listShowRoom;
        }
 
        #endregion
 
        #region ■ 功能分支___________________________
 
        /// <summary>
        /// 刷新功能分支控件
        /// </summary>
        /// <param name="room"></param>
        private void RefreshFunctionView(Common.Room room, FrameLayout functionBodyView)
        {
            //获取分组后的设备
            var dicGroupDevice = this.GetAllGroupDevice(room);
 
            //只初始化一次
            if (this.deviceFunctionMenuContr == null || this.deviceFunctionMenuContr.Parent == null)
            {
                //设备菜单的白色背景
                var functionBack1 = new FrameLayout();
                functionBack1.X = HdlControlResourse.XXLeft;
                functionBack1.Height = Application.GetRealHeight(160);
                functionBack1.Width = Application.GetRealWidth(1028);
                functionBack1.BackgroundColor = ZigbeeColor.Current.GXCBackgroundColor;
                functionBodyView.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;
                functionBodyView.AddChidren(functionBack2);
                functionBack2.SetCornerWithSameRadius(Application.GetRealHeight(58), HDLUtils.RectCornerBottomLeft);
 
                //设备菜单的左右滑动的控件
                this.deviceFunctionMenuContr = new HorizontalScrolViewLayout();
                deviceFunctionMenuContr.X = HdlControlResourse.XXLeft;
                deviceFunctionMenuContr.Height = Application.GetRealHeight(279);
                deviceFunctionMenuContr.Width = Application.GetRealWidth(1028);
                functionBodyView.AddChidren(deviceFunctionMenuContr);
 
                //设备的背景容器
                var frameDeviceBack = new FrameLayout();
                frameDeviceBack.X = HdlControlResourse.XXLeft;
                frameDeviceBack.Y = deviceFunctionMenuContr.Bottom + Application.GetRealHeight(35);
                frameDeviceBack.BackgroundColor = UserCenterColor.Current.White;
                frameDeviceBack.Width = bodyFrameLayout.Width;
                frameDeviceBack.Height = functionBodyView.Height - deviceFunctionMenuContr.Bottom - Application.GetRealHeight(35);
                frameDeviceBack.SetCornerWithSameRadius(Application.GetRealHeight(58), HDLUtils.RectCornerTopLeft);
                functionBodyView.AddChidren(frameDeviceBack);
 
                //设备列表控件
                this.listDeviceView = new VerticalListControl(35);
                listDeviceView.Y = Application.GetRealHeight(11);
                listDeviceView.Width = Application.GetRealWidth(1022);
                listDeviceView.Height = frameDeviceBack.Height - Application.GetRealHeight(11);
                listDeviceView.SetCornerWithSameRadius(Application.GetRealHeight(58), HDLUtils.RectCornerTopLeft);
                frameDeviceBack.AddChidren(listDeviceView);
            }
 
            //上一次选择的菜单和数据
            DeviceRowInfo nowSelectDeviceInfo = null;
            MainPage.Controls.DeviceFunctionMenuControl oldSelectContr = null;
            foreach (string strText in dicGroupDevice.Keys)
            {
                var rowInfo = dicGroupDevice[strText];
 
                //设备类型的容器
                var devieFrame = new FrameLayout();
                devieFrame.Width = Application.GetRealWidth(220);
                deviceFunctionMenuContr.AddChidren(devieFrame);
 
                //菜单图片控件
                var deviceObjContr = new MainPage.Controls.DeviceFunctionMenuControl();
                devieFrame.AddChidren(deviceObjContr);
                deviceObjContr.InitControl(strText, rowInfo.IconPath, rowInfo.IconPathSelected);
                deviceObjContr.ButtonClickEvent += (sender, e) =>
                {
                    //选择的是同一个东西的话,不处理
                    if (nowSelectDeviceInfo.TextId != rowInfo.TextId)
                    {
                        //上一次的菜单取消,本次菜单选择
                        oldSelectContr.SetSelectStatu(false);
                        deviceObjContr.SetSelectStatu(true);
                        oldSelectContr = deviceObjContr;
 
                        nowSelectDeviceInfo = rowInfo;
                        HdlThreadLogic.Current.RunMainInThread(() =>
                        {
                            //初始化设备列表控件
                            this.InitListDeviceControls(listDeviceView, rowInfo);
                        });
                    }
                };
 
                if (nowSelectDeviceInfo == null)
                {
                    //设置初始选择
                    nowSelectDeviceInfo = rowInfo;
                    //记录初始选择的菜单控件
                    oldSelectContr = deviceObjContr;
                    deviceObjContr.SetSelectStatu(true);
                }
            }
            if (nowSelectDeviceInfo != null)
            {
                //初始化默认的设备列表控件
                this.InitListDeviceControls(listDeviceView, nowSelectDeviceInfo);
            }
        }
 
        #endregion
 
        #region ■ 初始化设备列表控件_________________
 
        /// <summary>
        /// 初始化设备列表控件
        /// </summary>
        /// <param name="listView"></param>
        /// <param name="rowInfo"></param>
        private void InitListDeviceControls(VerticalListControl listView, DeviceRowInfo rowInfo)
        {
            //先清空
            listView.RemoveAll();
 
            var listDevice = new List<CommonDevice>();
            for (int i = 0; i < rowInfo.listDeviceKeys.Count; i++)
            {
                var device = HdlDeviceCommonLogic.Current.GetDevice(rowInfo.listDeviceKeys[i]);
                if (device != null)
                {
                    listDevice.Add(device);
                }
                else
                {
                    rowInfo.listDeviceKeys.RemoveAt(i);
                    i--;
                }
            }
 
            HdlThreadLogic.Current.RunMain(() =>
            {
                foreach (var device in listDevice)
                {
                    //添加设备行
                    this.AddDeviceRow(listView, device);
                }
                //调整桌布,促使它能够滑动超过完成按钮
                listView.AdjustRealHeightByBottomButton(Application.GetRealHeight(23), Application.GetRealHeight(529));
            });
        }
 
        /// <summary>
        /// 添加设备行
        /// </summary>
        /// <param name="listView"></param>
        /// <param name="device"></param>
        private void AddDeviceRow(VerticalListControl listView, CommonDevice device)
        {
            string mainkey = HdlDeviceCommonLogic.Current.GetDeviceMainKeys(device);
            //设备控件
            var rowDevice = new FrameRowControl(listView.rowSpace / 2);
            rowDevice.RightOffset = HdlControlResourse.XXLeft - Application.GetRealWidth(109);
            listView.AddChidren(rowDevice);
 
            //设备图标背景控件
            var frameIconBackGroud = new FrameLayout();
            frameIconBackGroud.Height = this.GetPictrueRealSize(112);
            frameIconBackGroud.Width = this.GetPictrueRealSize(112);
            frameIconBackGroud.Gravity = Gravity.CenterVertical;
            frameIconBackGroud.X = Application.GetRealWidth(46);
            frameIconBackGroud.Radius = (uint)this.GetPictrueRealSize(112 / 2);
            frameIconBackGroud.BackgroundColor = Common.ZigbeeColor.Current.GXCGrayBackgroundColor;
            rowDevice.AddChidren(frameIconBackGroud, ChidrenBindMode.NotBind);
            frameIconBackGroud.Y += rowDevice.chidrenYaxis;
 
            //设备图标控件
            var btnDeviceIcon = new IconViewControl(78);
            btnDeviceIcon.Gravity = Gravity.Center;
            HdlDeviceCommonLogic.Current.SetDeviceIconToControl(btnDeviceIcon, device);
            frameIconBackGroud.AddChidren(btnDeviceIcon);
            //重新绑定事件
            rowDevice.ChangedChidrenBindMode(frameIconBackGroud, ChidrenBindMode.BindEvent);
 
            //设备名字
            var btnDeviceName = new NormalViewControl(600, 60, true);
            btnDeviceName.X = Application.GetRealWidth(181);
            btnDeviceName.Gravity = Gravity.CenterVertical;
            btnDeviceName.Text = HdlDeviceCommonLogic.Current.GetDeviceEpointName(device);
            rowDevice.AddChidren(btnDeviceName, ChidrenBindMode.BindEvent);
            btnDeviceName.Y += rowDevice.chidrenYaxis;
            //底线
            var btnBottomLine = new NormalViewControl(Application.GetRealWidth(841), HdlControlResourse.BottomLineHeight, false);
            btnBottomLine.X = Application.GetRealWidth(181);
            btnBottomLine.Y = rowDevice.Height - HdlControlResourse.BottomLineHeight;
            btnBottomLine.BackgroundColor = UserCenterColor.Current.ButtomLine;
            rowDevice.AddChidren(btnBottomLine, ChidrenBindMode.NotBind);
            //右箭头
            rowDevice.AddRightArrow();
            //状态
            var btnStatu = rowDevice.AddMostRightView("", 400);
            if (this.dicNewListTask.ContainsKey(mainkey) == true)
            {
                //显示配置状态
                btnStatu.Text = HdlSafeguardLogic.Current.GetAdjustTargetStatuText(dicNewListTask[mainkey]);
            }
            rowDevice.ButtonClickEvent += (sender, e) =>
            {
                //功能的详细配置
                this.ShowDeviceDetailSettion(device, btnStatu);
            };
        }
 
        #endregion
 
        #region ■ 功能的详细配置_____________________
 
        /// <summary>
        /// 功能的详细配置
        /// </summary>
        /// <param name="device"></param>
        /// <param name="btnStatu"></param>
        private void ShowDeviceDetailSettion(CommonDevice device, NormalViewControl btnStatu)
        {
            string mainKeys = HdlDeviceCommonLogic.Current.GetDeviceMainKeys(device);
 
            List<Safeguard.TaskListInfo> listTaskinfo = null;
            if (dicNewListTask.ContainsKey(mainKeys) == true)
            {
                //取缓存中还未保存的数据
                listTaskinfo = dicNewListTask[mainKeys];
            }
 
            if (device.Type == DeviceType.DimmableLight//调光器
                || device.Type == DeviceType.ColorDimmableLight)//彩灯
            {
                var form = new UserCenter.Safety.AlarmTargetStatuSelectLightForm();
                form.AddForm(device, listTaskinfo);
                form.FinishSelectEvent += (statuText, listInfo) =>
                {
                    if (listInfo.Count == 0) { statuText = string.Empty; }
                    btnStatu.Text = statuText;
                    //将新的执行目标添加入缓存
                    this.AddSettionDataToMemory(device, listInfo);
                };
            }
            else if (device.Type == DeviceType.Thermostat)//空调
            {
                var form = new UserCenter.Safety.AlarmTargetStatuSelectAcForm();
                form.AddForm(device, listTaskinfo);
                form.FinishSelectEvent += (statuText, listInfo) =>
                {
                    if (listInfo.Count == 0) { statuText = string.Empty; }
                    btnStatu.Text = statuText;
                    //将新的执行目标添加入缓存
                    this.AddSettionDataToMemory(device, listInfo);
                };
            }
            else if (device.Type == DeviceType.WindowCoveringDevice)//窗帘
            {
                var form = new UserCenter.Safety.AlarmTargetStatuSelectCurtainForm();
                form.AddForm(device, listTaskinfo);
                form.FinishSelectEvent += (statuText, listInfo) =>
                {
                    if (listInfo.Count == 0) { statuText = string.Empty; }
                    btnStatu.Text = statuText;
                    //将新的执行目标添加入缓存
                    this.AddSettionDataToMemory(device, listInfo);
                };
            }
            else
            {
                //其他直接归为开关类
                var form = new UserCenter.Safety.AlarmTargetStatuSelectSwitchForm();
                form.AddForm(device, listTaskinfo);
                form.FinishSelectEvent += (statuText, listInfo) =>
                {
                    if (listInfo.Count == 0) { statuText = string.Empty; }
                    btnStatu.Text = statuText;
                    //将新的执行目标添加入缓存
                    this.AddSettionDataToMemory(device, listInfo);
                };
            }
        }
 
        /// <summary>
        /// 将新的执行目标添加入缓存
        /// </summary>
        /// <param name="deviceInfo"></param>
        /// <param name="listInfo"></param>
        private void AddSettionDataToMemory(CommonDevice device, List<Safeguard.TaskListInfo> listInfo)
        {
            string mainKeys = HdlDeviceCommonLogic.Current.GetDeviceMainKeys(device);
            if (listInfo == null || listInfo.Count == 0)
            {
                //指定为无动作模式
                if (this.dicNewListTask.ContainsKey(mainKeys) == true)
                {
                    this.dicNewListTask.Remove(mainKeys);
                    if (dicNewListTask.Count == 0)
                    {
                        this.btnFinishControl.Visible = false;
                    }
                }
            }
            else
            {
                //确认添加动作
                this.dicNewListTask[mainKeys] = listInfo;
                if (this.btnFinishControl.Visible == false)
                {
                    this.btnFinishControl.Visible = true;
                }
            }
        }
 
        #endregion
 
        #region ■ 整合设备___________________________
 
        /// <summary>
        /// 获取分组后的设备
        /// </summary>
        /// <returns></returns>
        private Dictionary<string, DeviceRowInfo> GetAllGroupDevice(Common.Room room)
        {
            //全部的设备
            var listDeviceTemp = HdlRoomLogic.Current.GetRoomListDevice(room);
            var listDevice = new List<CommonDevice>();
            foreach (var device in listDeviceTemp)
            {
                //判断该设备能否显示
                if (this.CheckDeviceCanShow(device) == true)
                {
                    listDevice.Add(device);
                }
            }
 
            //根据设备所属类型排序
            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].TextId = typeInfo.BeloneText;
                }
                dic[typeInfo.BeloneText].listDeviceKeys.Add(HdlDeviceCommonLogic.Current.GetDeviceMainKeys(device));
            }
            return dic;
        }
 
        #endregion
 
        #region ■ 界面关闭___________________________
 
        /// <summary>
        /// 界面关闭
        /// </summary>
        public override void CloseFormBefore()
        {
            this.FinishSelectEvent = null;
 
            base.CloseFormBefore();
        }
 
        #endregion
 
        #region ■ 一般方法___________________________
 
        /// <summary>
        /// 检测设备能否显示
        /// </summary>
        /// <param name="device"></param>
        private bool CheckDeviceCanShow(CommonDevice device)
        {
            if (device == null) { return false; }
            if (device.Type == DeviceType.AirSwitch ||//空气开关
                device.Type == DeviceType.ColorDimmableLight ||//调光灯
                device.Type == DeviceType.DimmableLight ||//彩灯
                device.Type == DeviceType.OnOffOutput ||//继电器
                device.Type == DeviceType.Thermostat ||//空调
                device.Type == DeviceType.ColorTemperatureLight ||//色温灯
                device.Type == DeviceType.WindowCoveringDevice)//窗帘
            {
                string mainkey = HdlDeviceCommonLogic.Current.GetDeviceMainKeys(device);
                return this.dicOldListTask.ContainsKey(mainkey) == false;
            }
            return false;
        }
 
        #endregion
 
        #region ■ 结构体_____________________________
 
        /// <summary>
        /// 设备行信息
        /// </summary>
        private class DeviceRowInfo
        {
            /// <summary>
            /// 文本,目前用来做主键
            /// </summary>
            public string TextId = 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
    }
}