xm
2020-07-20 b02e8275a21dc06bf54b66273485d44e007a2616
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
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using Newtonsoft.Json.Linq;
using Shared.Common;
using Shared.Phone.UserCenter.Device.Bind;
using Shared.Phone.UserCenter.Safety;
using ZigBee.Device;
using static ZigBee.Device.BindObj;
using static ZigBee.Device.Panel;
namespace Shared.Phone.UserCenter.DeviceBind
{
    /// <summary>
    /// 简约多功能面板
    /// 当前界面默认选择第一个楼层,第一个类型
    /// </summary>
    public class PanelSimpleMutilfunctionTargetsForm : BindCommonLayout
    {
        #region  构造函数
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="deviceMac">简约多功能面板Mac</param> 
        public PanelSimpleMutilfunctionTargetsForm(string deviceMac)
        {
            curControlDev = new Panel();
            var dev = Common.LocalDevice.Current.GetDevice(deviceMac, 62);//简约面板随便一个回路来获取设备
            if (dev != null)
            {
                curControlDev.CurrentGateWayId = dev.CurrentGateWayId;
            }
            curControlDev.Type = DeviceType.OnOffSwitch;
            curControlDev.DeviceAddr = deviceMac;
        }
        #endregion
 
        #region  变量申明 
        /// <summary>
        /// 控制设备
        /// </summary>
        Panel curControlDev;
        /// <summary>
        /// 显示被绑定设备或场景的view
        /// </summary>
        VerticalFrameRefreshControl midVerticalScrolViewLayout;
        /// <summary>
        /// 显示绑定类型 
        /// </summary>
        FrameLayout typeFrameLayout;
        /// <summary>
        /// 绑定类型提示文本
        /// </summary>
        Button btnTipText;
        /// <summary>
        /// 保存完成按钮
        /// </summary>
        Button btnFinifh;
        /// <summary>
        /// 本地设备列表
        /// </summary>
        private System.Collections.Generic.List<CommonDevice> localDeviceList = new System.Collections.Generic.List<CommonDevice>();
        /// <summary>
        /// 本地场景列表 
        /// </summary>
        private System.Collections.Generic.List<SceneUI> scList = new System.Collections.Generic.List<SceneUI> { };
        /// <summary>
        /// 当前类型的绑定表
        /// </summary>
        public List<BindListAllInfo> curBindTypeList = new List<BindListAllInfo>();
        /// <summary>
        /// 当前类型
        /// 0:场景  1:开关  2:插座  3:灯光  4:遮阳 5:空调 6:新风
        /// </summary>
        int curBindType = 0;
        /// <summary>
        /// 是否支持读取
        /// </summary>
        bool IsRead = false;
        /// <summary>
        /// 是否支持再次读取【当目标读取不全情况下重新读取】
        /// </summary>
        bool IsAgain = false;
        /// <summary>
        /// 上一次读取端点 
        /// </summary>
        private int oldReadEpoint = 2;
        /// <summary>
        /// 特殊类型的个数【开关/插座/灯光】需要计算显示的个数 
        /// </summary>
        int specialTypeCount = 0;
 
        private Action bindReceiveAction = null;
        /// <summary>
        /// 回调绑定目标页面刷新
        /// </summary>
        public Action<List<BindListResponseObj>> action;
        #endregion
 
        #region UI设计 
        /// <summary>
        /// 目标页显示
        /// </summary>
        public void Show()
        {
            //标题栏
            TitleUI();
            //中部UI【标题栏下的UI】
            MidFrameLayouUI();
            //类型栏UI
            BindTypeUI();
 
            CommonPage.Loading.Start("");
            InitLocalDeviceList();
            if (MutilfunctionPanelMethod.bindTargetsFromMutilfunctionPanelList.Count == 0)
            {
                IsRead = true;
            }
            else
            {
                IsRead = false;
            }
            InitData();
        }
 
        /// <summary>
        /// 标题栏
        /// </summary>
        void TitleUI()
        {
            string titleText = "";
            titleText = Language.StringByID(R.MyInternationalizationString.uBindTargets);
 
            this.TopFrameLayout(this, titleText);
            EventHandler<MouseEventArgs> eHandlerBack = (sender, e) =>
            {
                RemoveFromParent();
            };
            this.btnTitle.Width = Application.GetRealWidth(1080 - 161 - 300);
            this.btnBack.MouseUpEventHandler += eHandlerBack;
            this.btnBackFrameLayout.MouseUpEventHandler += eHandlerBack;
            this.MidFrameLayout(this);
 
            var btnAddFrameLayout = new FrameLayout()
            {
                X = Application.GetRealWidth(772 - 58),
                Width = Application.GetRealWidth(192),
            };
            this.titleFrameLayout.AddChidren(btnAddFrameLayout);
 
            var btnBindAdd = new Button
            {
                X = Application.GetRealWidth(62),
                Height = Application.GetMinReal(72),
                Width = Application.GetMinReal(72),
                UnSelectedImagePath = "BindPic/BindAdd.png",
            };
            btnAddFrameLayout.AddChidren(btnBindAdd);
            EventHandler<MouseEventArgs> eHandlerAdd = (sender, e) =>
            {
                var simpleMutilfunctionBindTargetsForm = new Shared.Phone.UserCenter.DeviceBind.PanelSimpleMutilfunctionAddTargetsForm(curControlDev.DeviceAddr, curBindType);
                Shared.Phone.UserView.HomePage.Instance.AddChidren(simpleMutilfunctionBindTargetsForm);
                Shared.Phone.UserView.HomePage.Instance.PageIndex += 1;
                simpleMutilfunctionBindTargetsForm.Show();
                Action action = () =>
                {
                    RefreshBindListUI();
                };
                simpleMutilfunctionBindTargetsForm.actionRefreshBindList += action;
            };
            btnBindAdd.MouseDownEventHandler += eHandlerAdd;
            btnAddFrameLayout.MouseDownEventHandler += eHandlerAdd;
        }
 
        /// <summary>
        /// 中部UI【标题栏下的UI】
        /// </summary>
        void MidFrameLayouUI()
        {
            //类型栏1
            typeFrameLayout = new FrameLayout
            {
                X = Application.GetRealWidth(58 / 2),
                Height = Application.GetRealHeight(323),
            };
            this.midFrameLayout.AddChidren(typeFrameLayout);
 
            //设备栏
            midVerticalScrolViewLayout = new VerticalFrameRefreshControl()
            {
                Y = Application.GetRealHeight(323),
                Height = Application.GetRealHeight(1065),
            };
            this.midFrameLayout.AddChidren(midVerticalScrolViewLayout);
            midVerticalScrolViewLayout.BeginHeaderRefreshingAction += () =>
            {
                midVerticalScrolViewLayout.BeginHeaderRefreshing();
                IsRead = true;
                InitData();
            };
 
            //底部保存栏
            var bottomFrameLayout = new FrameLayout()
            {
                Width = LayoutParams.MatchParent,
                Height = Application.GetRealHeight(84 * 2 + 127),
                Y = Application.GetRealHeight(1388),
            };
            this.midFrameLayout.AddChidren(bottomFrameLayout);
 
            btnTipText = new Button()
            {
                Height = Application.GetRealHeight(84),
                TextID = R.MyInternationalizationString.Tip,
                TextColor = Shared.Common.ZigbeeColor.Current.XMGray3,
                TextSize = 12,
                Text = MutilfunctionPanelMethod.MatchTypeBindTextTip(curBindType),
                TextAlignment = TextAlignment.Center,
            };
            bottomFrameLayout.AddChidren(btnTipText);
 
            btnFinifh = new Button()
            {
                Width = Application.GetRealWidth(907),
                Height = Application.GetRealHeight(127),
                Y = Application.GetRealHeight(49 + 35),
                Gravity = Gravity.CenterHorizontal,
                Radius = (uint)Application.GetRealHeight(127) / 2,
                TextID = R.MyInternationalizationString.Save,
                BackgroundColor = Shared.Common.ZigbeeColor.Current.XMBlack,
                TextColor = Shared.Common.ZigbeeColor.Current.XMWhite,
                IsBold = true,
                TextSize = 16,
            };
            bottomFrameLayout.AddChidren(btnFinifh);
            btnFinifh.MouseUpEventHandler += (sender, e) =>
            {
                SaveTarget();
            };
        }
 
        /// <summary>
        /// 类型栏UI
        /// </summary>
        void BindTypeUI()
        {
            //匹配的类型列表
            var typeList = GetTypeList();
            int index = 0;
            Button curentOldType = null;
            FrameLayout curentOldTypeLayout = null;
            foreach (var typeText in typeList)
            {
                var btnTypeLayout = new FrameLayout
                {
                    Height = Application.GetMinRealAverage(159),
                    Width = Application.GetMinRealAverage(255),
                    Y = Application.GetRealHeight(23),
                    BackgroundImagePath = "Item/RoomIconBackground.png",
                    BorderWidth = 1,
                };
                typeFrameLayout.AddChidren(btnTypeLayout);
 
                var btnType = new Button
                {
                    Height = Application.GetRealHeight(58),
                    Width = Application.GetRealWidth(127),
                    Y = Application.GetRealHeight(58),
                    X = Application.GetRealWidth(14),
                    Text = typeText,
                    TextSize = 12,
                    TextColor = Shared.Common.ZigbeeColor.Current.XMGray3,
                    Gravity = Gravity.Center,
                };
                btnTypeLayout.AddChidren(btnType);
 
                btnType.IsSelected = false;
 
                if (index == 0)
                {
                    btnTypeLayout.Y = Application.GetRealHeight(0);
                    btnTypeLayout.BackgroundImagePath = "Item/RoomIconBackgroundSelected.png";
                    btnType.TextColor = Shared.Common.ZigbeeColor.Current.XMWhite;
                    curentOldType = btnType;
                    curentOldTypeLayout = btnTypeLayout;
                }
                else
                {
                    btnTypeLayout.Y = Application.GetRealHeight(0);
                    btnTypeLayout.X = index * Application.GetRealWidth(260);
                    if (index > 3)
                    {
                        btnTypeLayout.Y = Application.GetRealHeight(58 + 78);
                        if (index == 4)
                        {
                            btnTypeLayout.X = Application.GetRealWidth(0);
                        }
                        else
                        {
                            btnTypeLayout.X = (index - 4) * Application.GetRealWidth(260);
                        }
                    }
                }
 
                EventHandler<MouseEventArgs> eHandlerRoom = (sender, e) =>
                {
                    if (!curentOldType.IsSelected)
                    {
                        if (curentOldType != null)
                        {
                            curentOldType.TextColor = Shared.Common.ZigbeeColor.Current.XMGray3;
                        }
                        curentOldType = btnType;
                        curentOldType.TextColor = Shared.Common.ZigbeeColor.Current.XMWhite;
                    }
 
                    if (btnTypeLayout.BorderWidth == 1)
                    {
                        if (curentOldTypeLayout != null)
                        {
                            curentOldTypeLayout.BorderWidth = 1;
                            curentOldTypeLayout.BorderColor = Shared.Common.ZigbeeColor.Current.XMOrange;
                            curentOldTypeLayout.BackgroundImagePath = "Item/RoomIconBackground.png";
                        }
                        curentOldTypeLayout = btnTypeLayout;
                        curentOldTypeLayout.BorderWidth = 0;
                        curentOldTypeLayout.BackgroundImagePath = "Item/RoomIconBackgroundSelected.png";
                    }
 
                    if (curentOldType.Text == Language.StringByID(R.MyInternationalizationString.scene))
                    {
                        curBindType = 0;
                        RefreshBindListUI();
                    }
                    else if (curentOldType.Text == Language.StringByID(R.MyInternationalizationString.uDeviceBelongId13))
                    {
                        curBindType = 1;
                        RefreshBindListUI();
                    }
                    else if (curentOldType.Text == Language.StringByID(R.MyInternationalizationString.uDeviceBelongId14))
                    {
                        curBindType = 2;
                        RefreshBindListUI();
                    }
                    else if (curentOldType.Text == Language.StringByID(R.MyInternationalizationString.uDeviceBelongId15))
                    {
                        curBindType = 3;
                        RefreshBindListUI();
                    }
                    else if (curentOldType.Text == Language.StringByID(R.MyInternationalizationString.uDeviceBelongId100))
                    {
                        curBindType = 4;
                        RefreshBindListUI();
                    }
                    else if (curentOldType.Text == Language.StringByID(R.MyInternationalizationString.uDeviceBelongId3600))
                    {
                        curBindType = 5;
                        RefreshBindListUI();
                    }
                    else if (curentOldType.Text == Language.StringByID(R.MyInternationalizationString.uDeviceBelongId2310))
                    {
                        curBindType = 6;
                        RefreshBindListUI();
                    }
                };
                btnType.MouseUpEventHandler += eHandlerRoom;
                btnTypeLayout.MouseUpEventHandler += eHandlerRoom;
                index++;
            }
        }
 
        /// <summary>
        /// 绑定表显示
        /// </summary> 
        void RefreshBindListUI()
        {
            midVerticalScrolViewLayout.RemoveAll();
            curBindTypeList = MutilfunctionPanelMethod.GetMatchBindList(curBindType);
            int curIndex = 0;
            for (int i = 0; i < curBindTypeList.Count; i++)
            {
                curIndex = i;
                var bindObj = curBindTypeList[i];
                SceneUI curSceneUI = null;
 
                var rowLayout = new RowLayoutControl(midVerticalScrolViewLayout.rowSpace / 2);
                rowLayout.BackgroundColor = ZigbeeColor.Current.XMWhite;
                midVerticalScrolViewLayout.AddChidren(rowLayout);
                rowLayout.frameTable.UseClickStatu = false;
                var devicePic = rowLayout.frameTable.AddLeftIcon();
                devicePic.Y = Application.GetRealHeight(25);//49
                devicePic.UnSelectedImagePath = "DoorLock/DoorLockUserPic.png";
 
                #region 绑定数据处理
                int currentIndex = i;
                var btnBindNameText = "";
                var btnFloorRoomNameText = "";
                if (currentIndex == curBindTypeList.Count - 1)
                {
                    rowLayout.LineColor = Shared.Common.ZigbeeColor.Current.XMWhite;
                }
 
                if (curBindType == 0)
                {
                    //Scene
                    curSceneUI = HdlSceneLogic.Current.GetSceneUIBySceneId(bindObj.BindScenesId);
                    devicePic.UnSelectedImagePath = "Scene/SceneIcon.png";
                    if (curSceneUI == null)
                    {
                        if (string.IsNullOrEmpty(bindObj.ESName))
                        {
                            btnBindNameText = Language.StringByID(R.MyInternationalizationString.OffLineScene) + "_" + "ID" + "_" + bindObj.BindScenesId.ToString();
                        }
                        else
                        {
                            btnBindNameText = Language.StringByID(R.MyInternationalizationString.OffLineScene) + "_" + bindObj.ESName;
                        }
                        btnFloorRoomNameText = Language.StringByID(R.MyInternationalizationString.Undistributed);
                    }
                    else
                    {
                        btnBindNameText = curSceneUI.Name;
                        string myName = HdlSceneLogic.Current.GetZoneById(curSceneUI.Id);
                        if (myName != null)
                        {
                            btnFloorRoomNameText = myName;
                        }
                        else
                        {
                            btnFloorRoomNameText = Language.StringByID(R.MyInternationalizationString.Undistributed);
                        }
                    }
                }
                else
                {
                    //被绑定设备图片【可能和外面设备等图片不同,因为这里是以功能来绑定的】
                    //devicePic.UnSelectedImagePath = tempDev.IconPath;
                    var device = LocalDevice.Current.GetDevice(bindObj.BindMacAddr, bindObj.BindEpoint);
                    switch (curBindType)
                    {
                        case 1:
                            devicePic.UnSelectedImagePath = "BindPic/Switch.png";
                            break;
                        case 2:
                            devicePic.UnSelectedImagePath = "Device/Socket1.png";
                            break;
                        case 3:
                            devicePic.UnSelectedImagePath = "Device/Light.png";
                            break;
                        case 4:
                            if (device != null)
                            {
                                if (device.Type == DeviceType.WindowCoveringDevice)
                                {
                                    var tempCur = device as Rollershade;
                                    if (tempCur.WcdType == 4)
                                    {
                                        devicePic.UnSelectedImagePath = "BindPic/Curtain.png";
                                    }
                                    else
                                    {
                                        devicePic.UnSelectedImagePath = "BindPic/Roller.png";
                                    }
                                }
                            }
                            break;
                        case 5:
                            devicePic.UnSelectedImagePath = "Device/AirConditionerEpoint.png";
                            break;
                        case 6:
                            devicePic.UnSelectedImagePath = "Device/FreshAirEpoint.png";
                            break;
                    }
 
                    if (device != null)
                    {
                        //设备名字
                        btnBindNameText = Common.LocalDevice.Current.GetDeviceEpointName(device);
 
                        //获取设备所属房间
                        var tempDevRoom = HdlRoomLogic.Current.GetRoomByDevice(device);
 
                        if (tempDevRoom != null)
                        {
                            var tempDevFloorId = tempDevRoom.FloorId;
                            //获取房间的名字
                            var tempDevRoomName = tempDevRoom.Name;
                            //获取楼层的名字
                            var tempDevFloorName = HdlResidenceLogic.Current.GetFloorNameById(tempDevFloorId);
                            if (string.IsNullOrEmpty(tempDevFloorName))
                            {
                                if (string.IsNullOrEmpty(tempDevRoomName))
                                {
                                    btnFloorRoomNameText = Language.StringByID(R.MyInternationalizationString.Undistributed);
                                }
                                else
                                {
                                    btnFloorRoomNameText = tempDevRoomName;
                                }
                            }
                            else
                            {
                                if (string.IsNullOrEmpty(tempDevRoomName))
                                {
                                    btnFloorRoomNameText = Language.StringByID(R.MyInternationalizationString.Undistributed);
                                }
                                else
                                {
                                    btnFloorRoomNameText = tempDevFloorName + "," + tempDevRoomName;
                                }
                            }
                        }
                        else
                        {
                            btnFloorRoomNameText = Language.StringByID(R.MyInternationalizationString.Undistributed);
                        }
                    }
                    else
                    {
                        devicePic.TextAlignment = TextAlignment.CenterLeft;
                        devicePic.TextColor = UserCenterColor.Current.Gray;
                        devicePic.Text = Language.StringByID(R.MyInternationalizationString.uOffLine);
                    }
                }
 
                var btnBindName = rowLayout.frameTable.AddTopView(btnBindNameText, 800);
                var btnFloorRoomName = rowLayout.frameTable.AddBottomView(btnFloorRoomNameText, 800);
                rowLayout.frameTable.AddBottomLine();
                var btnDel = rowLayout.AddDeleteControl();
                btnDel.ButtonClickEvent += (sender, e) =>
                {
                    RemoveTargets(bindObj, btnDel);
                };
                #endregion
            }
 
            switch (curBindType)
            {
                case 1:
                    btnTipText.Text = MutilfunctionPanelMethod.MatchTypeBindTextTip(curBindType, MutilfunctionPanelMethod.curSwitchCount + MutilfunctionPanelMethod.curSocketCount + MutilfunctionPanelMethod.curLightFromRelayCount);
                    break;
                case 2:
                    btnTipText.Text = MutilfunctionPanelMethod.MatchTypeBindTextTip(curBindType, MutilfunctionPanelMethod.curSwitchCount + MutilfunctionPanelMethod.curSocketCount + MutilfunctionPanelMethod.curLightFromRelayCount);
                    break;
                case 3:
                    btnTipText.Text = MutilfunctionPanelMethod.MatchTypeBindTextTip(curBindType, MutilfunctionPanelMethod.curSwitchCount + MutilfunctionPanelMethod.curSocketCount + MutilfunctionPanelMethod.curLightFromRelayCount + MutilfunctionPanelMethod.curLightCount);
                    break;
                default:
                    btnTipText.Text = MutilfunctionPanelMethod.MatchTypeBindTextTip(curBindType, curBindTypeList.Count);
                    break;
            }
            midVerticalScrolViewLayout.AdjustTableHeight(Application.GetRealHeight(23));
        }
 
        #endregion
 
        #region 数据处理
        /// <summary>
        /// 获取本地列表
        /// </summary>
        void InitLocalDeviceList()
        {
            localDeviceList.Clear();
            scList.Clear();
            //设备
            foreach (var dev in Shared.Common.LocalDevice.Current.listAllDevice)
            {
                localDeviceList.Add(dev);
            }
            //场景
            scList = HdlSceneLogic.Current.GetAllRoomSceneList();
        }
        /// <summary>
        /// 初始化设备数据
        /// </summary>
        void InitData()
        {
            System.Threading.Tasks.Task.Run(async () =>
            {
                try
                {
                    //读取按键当前绑定目标  多功能面板目标总共需要读取本页的目标60个,3秒左右(3秒+200毫秒)
                    GetDeviceBindResponseAllData getBindList = null;
                    if (IsRead)
                    {
                        MutilfunctionPanelMethod.bindTargetsFromMutilfunctionPanelList.Clear();
                        var epointList = new List<int>();
                        for (int i = 2; i < 62; i++)
                        {
                            epointList.Add(i);
                        }
                        //读取上次没读全读目标
                        if (IsAgain)
                        {
                            epointList.Clear();
                            for (int i = oldReadEpoint; i < 62; i++)
                            {
                                epointList.Add(i);
                            }
                        }
 
                        foreach (var epoint in epointList)
                        {
                            curControlDev.DeviceEpoint = epoint;
                            getBindList = HdlDeviceBindLogic.Current.GetDeviceBindAsync(curControlDev);
                            if (getBindList != null && getBindList.getAllBindResponseData != null)
                            {
                                var bList = new List<BindListAllInfo>();
                                foreach (var dev in getBindList.getAllBindResponseData.BindList)
                                {
                                    var curD = new BindListAllInfo();
                                    curD.KeyMacAddr = curControlDev.DeviceAddr;
                                    curD.KeyEpoint = epoint;
                                    curD.BindCluster = dev.BindCluster;
                                    curD.BindScenesId = dev.BindScenesId;
                                    curD.BindMacAddr = dev.BindMacAddr;
                                    curD.BindEpoint = dev.BindEpoint;
                                    curD.ESName = dev.ESName;
                                    curD.BindType = dev.BindType;
                                    bList.Add(curD);
                                }
                                MutilfunctionPanelMethod.bindTargetsFromMutilfunctionPanelList.Add(curControlDev.DeviceAddr + curControlDev.DeviceEpoint, bList);
 
                                oldReadEpoint++;
                            }
                            else
                            {
                                if (oldReadEpoint < 62)
                                {
                                    IsAgain = true;
                                }
                                Application.RunOnMainThread(() =>
                                {
                                    RefreshBindListUI();
                                    midVerticalScrolViewLayout.EndHeaderRefreshing();
                                    CommonPage.Loading.Hide();
                                    new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.GwResponseOvertime) + "(" + "5007_1" + ")", Direction = AMPopTipDirection.None, CloseTime = 1 }.Show(Common.CommonPage.Instance);
                                });
                                break;
                            }
                        }
                        if (oldReadEpoint >= 61)
                        {
                            IsAgain = false;
                            oldReadEpoint = 2;
                        }
 
                        //获取所有类型的绑定目标个数
                        for (int i = 0; i < 7; i++)
                        {
                            curBindTypeList = MutilfunctionPanelMethod.GetMatchBindList(i);
                        }
 
                        Application.RunOnMainThread(() =>
                        {
                            RefreshBindListUI();
                            midVerticalScrolViewLayout.EndHeaderRefreshing();
                            CommonPage.Loading.Hide();
                        });
                    }
                    else
                    {
                        Application.RunOnMainThread(() =>
                        {
                            RefreshBindListUI();
                            CommonPage.Loading.Hide();
                        });
                    }
                }
                catch (Exception ex)
                {
                    var mess = ex.Message;
                }
            });
        }
 
        /// <summary>
        /// 保存目标
        /// </summary>
        /// <param name="curControlDev"></param>
        void SaveTarget()
        {
            RemoveFromParent();
        }
 
        /// <summary>
        /// 删除多功能面板的目标
        /// </summary>
        /// <param name="bindDevice"></param>
        /// <param name="btnDel"></param>
        /// <returns></returns>
        private void RemoveTargets(BindListAllInfo bindDevice, Button btnDel)
        {
            var delDevice = new DelDeviceBindData();
            delDevice.DeviceAddr = bindDevice.KeyMacAddr;
            delDevice.Epoint = bindDevice.KeyEpoint;
 
            if (bindDevice.BindType == 0 || bindDevice.BindType == 1)
            {
                var removeDevice = new RemoveBindListObj();
                removeDevice.BindCluster = bindDevice.BindCluster;
                removeDevice.BindType = 0;
                removeDevice.BindMacAddr = bindDevice.BindMacAddr;
                removeDevice.BindEpoint = bindDevice.BindEpoint;
                delDevice.RemoveBindList.Add(removeDevice);
 
                //部分目标需要二次绑定第二种功能 
                switch (curBindType)
                {
                    case 3:
                        var device = LocalDevice.Current.GetDevice(bindDevice.BindMacAddr, bindDevice.BindEpoint);
                        if (device != null)
                        {
                            if (device.Type == DeviceType.DimmableLight)
                            {
                                //灯光为调光时需要移除6,8
                                var removeDevice2 = new RemoveBindListObj();
                                removeDevice2.BindCluster = 6;
                                removeDevice2.BindType = 0;
                                removeDevice2.BindMacAddr = bindDevice.BindMacAddr;
                                removeDevice2.BindEpoint = bindDevice.BindEpoint;
                                delDevice.RemoveBindList.Add(removeDevice2);
                            }
                        }
                        break;
                    case 5:
                        //要移除空调:需要移除513,514
                        var removeDevice3 = new RemoveBindListObj();
                        removeDevice3.BindCluster = 514;
                        removeDevice3.BindType = 0;
                        removeDevice3.BindMacAddr = bindDevice.BindMacAddr;
                        removeDevice3.BindEpoint = bindDevice.BindEpoint;
                        delDevice.RemoveBindList.Add(removeDevice3);
                        break;
                }
            }
            else if (bindDevice.BindType == 2)
            {
                var removeDevice = new RemoveBindListObj();
                removeDevice.BindCluster = bindDevice.BindCluster;
                removeDevice.BindType = 1;
                removeDevice.BindScenesId = bindDevice.BindScenesId;
                delDevice.RemoveBindList.Add(removeDevice);
            }
 
            System.Threading.Tasks.Task.Run(() =>
            {
                try
                {
                    Application.RunOnMainThread(() =>
                    {
                        CommonPage.Loading.Start("");
                    });
                    var delResult = new DelDeviceBindResponseAllData();
                    delResult = HdlDeviceBindLogic.Current.DelDeviceBindAsync(delDevice);
                    if (delResult == null)
                    {
                        Application.RunOnMainThread(() =>
                        {
                            new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.GwResponseOvertime) + "(" + "5003" + ")", Direction = AMPopTipDirection.None, CloseTime = 2 }.Show(CommonPage.Instance);
                            CommonPage.Loading.Hide();
                        });
                        return;
                    }
                    else
                    {
                        if (delResult.removeBindResultResponseData == null)
                        {
                            if (delResult.delDeviceBindResponseData != null)
                            {
                                foreach (var d in delResult.delDeviceBindResponseData.RemoveBindList)
                                {
                                    if (d.Result == 0 || d.Result == 1)
                                    {
                                        if (MutilfunctionPanelMethod.bindTargetsFromMutilfunctionPanelList.ContainsKey(bindDevice.KeyMacAddr + bindDevice.KeyEpoint))
                                        {
                                            MutilfunctionPanelMethod.bindTargetsFromMutilfunctionPanelList.Remove(bindDevice.KeyMacAddr + bindDevice.KeyEpoint);
                                        }
                                        Application.RunOnMainThread(() =>
                                        {
                                            RefreshBindListUI();
                                            CommonPage.Loading.Hide();
                                        });
                                    }
                                    else
                                    {
                                        Application.RunOnMainThread(() =>
                                        {
                                            new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.uDeviceDeleteFail) + "(" + "5003_8" + ")", Direction = AMPopTipDirection.None, CloseTime = 2 }.Show(CommonPage.Instance);
                                            CommonPage.Loading.Hide();
                                        });
                                        return;
                                    }
                                }
                            }
                            else
                            {
                                Application.RunOnMainThread(() =>
                                {
                                    new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.GwResponseOvertime) + "(" + "5003_9" + ")", Direction = AMPopTipDirection.None, CloseTime = 2 }.Show(CommonPage.Instance);
                                    CommonPage.Loading.Hide();
                                });
                                return;
                            }
                        }
                        else
                        {
                            if (delResult.removeBindResultResponseData.Result == 0)
                            {
                                if (MutilfunctionPanelMethod.bindTargetsFromMutilfunctionPanelList.ContainsKey(bindDevice.KeyMacAddr + bindDevice.KeyEpoint))
                                {
                                    MutilfunctionPanelMethod.bindTargetsFromMutilfunctionPanelList.Remove(bindDevice.KeyMacAddr + bindDevice.KeyEpoint);
                                }
                                Application.RunOnMainThread(() =>
                                {
                                    RefreshBindListUI();
                                    CommonPage.Loading.Hide();
                                });
                            }
                            else
                            {
                                Application.RunOnMainThread(() =>
                                {
                                    new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.BindFailed), Direction = AMPopTipDirection.None, CloseTime = 1 }.Show(CommonPage.Instance);
                                    CommonPage.Loading.Hide();
                                });
                                return;
                            }
                        }
                    }
                }
                catch { }
                finally
                {
                    Application.RunOnMainThread(() =>
                    {
                        CommonPage.Loading.Hide();
                    });
                }
            });
        }
 
 
 
        /// <summary>
        /// 匹配的类型列表
        /// </summary>
        /// <returns></returns>
        private List<string> GetTypeList()
        {
            List<string> textTypelist = new List<string> { };
            textTypelist.Add(Language.StringByID(R.MyInternationalizationString.scene));
            textTypelist.Add(Language.StringByID(R.MyInternationalizationString.uDeviceBelongId13));
            textTypelist.Add(Language.StringByID(R.MyInternationalizationString.uDeviceBelongId14));
            textTypelist.Add(Language.StringByID(R.MyInternationalizationString.uDeviceBelongId15));
            textTypelist.Add(Language.StringByID(R.MyInternationalizationString.uDeviceBelongId100));
            textTypelist.Add(Language.StringByID(R.MyInternationalizationString.uDeviceBelongId3600));
            textTypelist.Add(Language.StringByID(R.MyInternationalizationString.uDeviceBelongId2310));
            return textTypelist;
        }
 
        #endregion
 
        #region 其他方法
        /// <summary>
        /// 显示绑定设备线程是否已经开启
        /// </summary>
        private bool isDeviceThreadStart = false;
        /// <summary>
        /// 主题超时的线程是否开启
        /// </summary>
        private bool isTopicTimeOutThreadStart = false;
        /// <summary>
        /// 等待设备的回馈的超时时间(单位:百毫秒)
        /// </summary>
        private int waitDeviceTimeOut = 20;
        /// <summary>
        /// 网关ID
        /// </summary>
        private string gatewayId = string.Empty;
        /// <summary>
        /// 接收个数
        /// </summary>
        private int countBind = 0;
        /// <summary>
        /// 新上报的设备
        /// </summary>
        private Dictionary<int, GetPanelBindResponseDataByMac> dicPanelResInfo = new Dictionary<int, GetPanelBindResponseDataByMac>();
 
        ///<summary >
        /// 发送获取面板命令[通过DeviceAddr获取]
        /// </summary>
        private void SendPanelCommand()
        {
            var jObject = new JObject { { "DeviceAddr", curControlDev.DeviceAddr }, { "Cluster_ID", 0 }, { "Command", 5009 } };
            curControlDev.Gateway.Send(("SearchNewDevice"), jObject.ToString());
        }
 
        /// <summary>
        /// 检测设备绑定的主题
        /// </summary>
        /// <param name="topic"></param>
        /// <param name="resultData"></param>
        /// <returns></returns>
        public bool CheckIsDeviceBindTopic(string topic)
        {
            if (topic == gatewayId + "Bind/GetDeviceLocalBind_Respon")
            {
                return true;
            }
            return false;
        }
 
        /// <summary>
        /// 处理面板绑定的设备,和端点没有关系
        /// </summary>
        /// <param name="topic">主题</param>
        /// <param name="resultData">上报数据</param>
        private void AdjustGatewayResultData(string topic, string resultData)
        {
 
            //接收绑定设备,开启接收绑定设备信息的线程(里面会等待三秒这样)
            this.ReceiveSuccessFormThread();
 
            var result = this.CheckIsDeviceBindTopic(topic);
            if (result)
            {
                lock (dicPanelResInfo)
                {
                    var jobject = Newtonsoft.Json.Linq.JObject.Parse(resultData);
                    var info = Newtonsoft.Json.JsonConvert.DeserializeObject<GetPanelBindResponseDataByMac>(jobject["Data"].ToString());
                    countBind = info.MaxNumItems;
                    if (info != null)
                    {
                        foreach (var bDev in info.BindList)
                        {
                            if (this.dicPanelResInfo.ContainsKey(bDev.ControllerEpoint) == false)
                            {
                                this.dicPanelResInfo[bDev.ControllerEpoint] = info;
                            }
                        }
                    }
 
                    if (this.dicPanelResInfo.Count == countBind)
                    {
                        //停止接收
                        curControlDev.Gateway.GwResDataAction -= this.AdjustGatewayResultData;
                        //刷新超时时间
                        this.waitDeviceTimeOut = -1;
                    }
                    else
                    {
                        //刷新超时时间
                        this.waitDeviceTimeOut = 20;
                    }
                }
            }
        }
 
        /// <summary>
        /// 开启接收绑定设备的超时线程  
        /// </summary>
        private void ReceiveSuccessFormThread()
        {
            if (this.isDeviceThreadStart == true)
            {
                //线程已经开启
                return;
            }
            this.isDeviceThreadStart = true;
 
            HdlThreadLogic.Current.RunThread(() =>
            {
                System.Console.WriteLine($"1AAAAA");
                while (this.waitDeviceTimeOut >= 0)
                {
                    //等待下一个回路
                    System.Threading.Thread.Sleep(100);
                    this.waitDeviceTimeOut--;
                    System.Console.WriteLine($"2AAAAA");
                }
                System.Console.WriteLine($"3AAAAA");
                //停止接收
                bindReceiveAction.Invoke();
                curControlDev.Gateway.GwResDataAction -= this.AdjustGatewayResultData;
                System.Console.WriteLine($"4AAAAA");
                System.Threading.Thread.Sleep(200);
                System.Console.WriteLine($"5AAAAA");
 
                //目前就弄一个
                Application.RunOnMainThread(() =>
                {
                    if (this.dicPanelResInfo.Count < countBind)
                    {
                        //响应超时,请重新下拉刷新获取绑定信息
                        new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.uResponseTimeoutsAndReAccessNetwork), Direction = AMPopTipDirection.None, CloseTime = 1 }.Show(Common.CommonPage.Instance);
                        //停止接收
                        curControlDev.Gateway.GwResDataAction -= this.AdjustGatewayResultData;
                    }
                    System.Console.WriteLine($"6AAAAA");
                });
            });
        }
        #endregion
 
    }
}