黄学彪
2020-12-16 0d9f64668fd7350d6a21fd157e32009a96d98134
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
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
using System;
using System.Collections.Generic;
using Newtonsoft.Json.Linq;
using ZigBee.Device;
using ZigBee.Common;
using Shared.Common;
using System.Collections.Specialized;
using System.Net;
using System.IO;
using Shared.R;
 
namespace Shared.Phone.Device.Logic
{
    public class Method
    {
 
        // <summary>
        /// 通过设备找到区域(房间)名称
        /// </summary>
        /// <param name="button">Btnregionname.</param>
        /// <param name="device">Device.</param>
        public static void RoomNmae(Button button, CommonDevice device)
        {
            button.Text = HdlRoomLogic.Current.GetRoomNameByDevice(device);
        }
        /// <summary>
        /// 返回楼层所有的房间的列表
        /// </summary>
        /// <param name="type">判断字符串</param>
        /// <param name="floorId">楼层ID</param>
        /// <returns></returns>
        public static List<Common.Room> GetRoomList(string type, string floorId = null)
        {
            var list = new List<Common.Room>();
            var listAllRoom = HdlRoomLogic.Current.GetAllListRooms();
            for (int i = 0; i < listAllRoom.Count; i++)
            {
                if (type == "action_logicscene" || type == "action_lockscene")
                {
                    if (listAllRoom[i].ListSceneId.Count == 0)
                    {   ///过滤掉没有场景的房间
                        continue;
                    }
                }
                else
                {
                    ///区分出输入条件和输出目标设备
                    var listdevicetype = GetDevice(type);
                    var listdevice = GetDeviceUIList(listAllRoom[i], listdevicetype, type);
                    if (listdevice.Count == 0)
                    {
                        ///过滤掉没有设备的房间
                        continue;
                    }
                }
                list.Add(listAllRoom[i]);
            }
            if (string.IsNullOrEmpty(floorId))
            {
                //没有楼层直接返回所有的房间;
                return list;
            }
            //某楼层所有的房间;
            return list.FindAll((obj) => obj.FloorId == floorId);
        }
        /// <summary>
        /// 获取房间的设备列表
        /// </summary>
        /// <param name="room">当前房间</param>
        /// <param name="deviceTypelist">设备类型</param>
        ///  /// <param name="type">逻辑类型</param>
        /// <returns></returns>
        public static List<CommonDevice> GetDeviceUIList(Common.Room room, List<DeviceType> deviceTypelist,string type)
        {
            var deviceUIlist = new List<CommonDevice>();
            foreach (var deviceKey in room.ListDevice)
            {
                var device = HdlDeviceCommonLogic.Current.GetDevice(deviceKey);
                if (device == null)
                {
                    continue;
                }
                if (!deviceTypelist.Contains(device.Type))
                {
                    //过滤掉不支持的设备
                    continue;
                }
                if (device.Type == DeviceType.DoorLock)
                {
                    var myInfo = HdlDeviceCommonLogic.Current.GetMyDeviceEnumInfo(new List<CommonDevice>() { device });
                    if (myInfo.ConcreteType == DeviceConcreteType.IntelligentLocks_Sone)
                    {
                        //暂时不支持S-one门锁;
                        //过滤掉不支持S-one门锁设备;
                        continue;
                    }
                }
                if (type == "condition_mould")
                {
                    if (device.Type == DeviceType.IASZone)
                    {
                        if (device.IasDeviceType != 13)
                        {//自动化模板只支持红外传感器
                            continue;
                        }
                        if (device.ModelIdentifier == "MSPIRB-ZB.10")
                        {
                            //自动化模板不支持光照度
                            continue;
                        }
 
                    }
                }
                deviceUIlist.Add(device);
            }
            return deviceUIlist;
        }
        /// <summary>
        /// 排列所有设备类型的列表
        /// </summary>
        /// <param name="devicelist">设备列表</param>
        /// <returns></returns>
        public static List<string> GetDeviceTypeList(List<CommonDevice> devicelist)
        {
            List<string> devicetypelist = new List<string>();
            devicetypelist.Clear();
 
            var lightjosn = devicelist.Find((device) => device.Type == DeviceType.DimmableLight || device.Type == DeviceType.OnOffOutput || device.Type == DeviceType.ColorTemperatureLight);
            if (lightjosn != null)
            {
                devicetypelist.Add(Language.StringByID(MyInternationalizationString.Lights));
            }
 
            var curtainjosn = devicelist.Find((device) => device.Type == DeviceType.WindowCoveringDevice);
            if (curtainjosn != null)
            {
                devicetypelist.Add(Language.StringByID(MyInternationalizationString.Curtains));
            }
 
            var ac = devicelist.Find((device) => device.Type == DeviceType.Thermostat);
            if (ac != null)
            {
                devicetypelist.Add(Language.StringByID(MyInternationalizationString.AC));
            }
 
            var onOffSwitchjson = devicelist.Find((device) => device.Type == DeviceType.OnOffSwitch);
            if (onOffSwitchjson != null)
            {
                devicetypelist.Add(Language.StringByID(MyInternationalizationString.OnOffSwitch));
            }
 
            var doorLock = devicelist.Find((device) => device.Type == DeviceType.DoorLock);
            if (doorLock != null)
            {
                devicetypelist.Add(Language.StringByID(MyInternationalizationString.doorLock));
            }
 
            var airSwitch = devicelist.Find((device) => device.Type == DeviceType.AirSwitch);
            if (airSwitch != null)
            {
                devicetypelist.Add(Language.StringByID(MyInternationalizationString.Airswitch));
            }
 
            var iASZonejosn = devicelist.Find((device) => device.Type == DeviceType.IASZone || device.Type == DeviceType.TemperatureSensor);
            if (iASZonejosn != null)
            {
                devicetypelist.Add(Language.StringByID(MyInternationalizationString.sensor));
            }
 
            return devicetypelist;
 
        }
        /// <summary>
        /// 某个设备类型的列表
        /// </summary>
        /// <param name="devicetype">判断字符串</param>
        /// <returns></returns>
        public static List<DeviceType> GetDeviceType(string devicetype)
        {
            List<DeviceType> DeviceTypeList = new List<DeviceType>();
            DeviceTypeList.Clear();
            if (devicetype == Language.StringByID(MyInternationalizationString.Lights))
            {
                DeviceTypeList.Add(DeviceType.OnOffOutput);//0x0101十进制257
                DeviceTypeList.Add(DeviceType.DimmableLight);
                DeviceTypeList.Add(DeviceType.ColorTemperatureLight);
            }
            else if (devicetype == Language.StringByID(MyInternationalizationString.Curtains))
            {
                DeviceTypeList.Add(DeviceType.WindowCoveringDevice);
            }
            else if (devicetype == Language.StringByID(MyInternationalizationString.OnOffSwitch))
            {
                DeviceTypeList.Add(DeviceType.OnOffSwitch);
            }
            else if (devicetype == Language.StringByID(MyInternationalizationString.sensor))
            {
                DeviceTypeList.Add(DeviceType.IASZone);
                DeviceTypeList.Add(DeviceType.TemperatureSensor);
            }
            else if (devicetype == Language.StringByID(MyInternationalizationString.doorLock))
            {
                DeviceTypeList.Add(DeviceType.DoorLock);
            }
            else if (devicetype == Language.StringByID(MyInternationalizationString.Curtains))
            {
                DeviceTypeList.Add(DeviceType.WindowCoveringDevice);
            }
            else if (devicetype == Language.StringByID(MyInternationalizationString.AC))
            {
                DeviceTypeList.Add(DeviceType.Thermostat);
            }
            else if (devicetype == Language.StringByID(MyInternationalizationString.Airswitch))
            {
                DeviceTypeList.Add(DeviceType.AirSwitch);
            }
            return DeviceTypeList;
        }
        /// <summary>
        /// 显示某个类型设备的图标
        /// </summary>
        /// <param name="devicetype">判断字符串</param>
        /// <returns></returns>
        public static string GetDeviceTypeIcon(string devicetype)
        {
            string patm = "";
            if (devicetype == Language.StringByID(MyInternationalizationString.OnOffSwitch))
            {
                patm = "ZigeeLogic/selectedpanel.png";
            }
            else if (devicetype == Language.StringByID(MyInternationalizationString.sensor))
            {
                patm = "ZigeeLogic/selectedsenor.png";
            }
            else if (devicetype == Language.StringByID(MyInternationalizationString.doorLock))
            {
                patm = "ZigeeLogic/selecteddoorlock.png";
            }
            else if (devicetype == Language.StringByID(MyInternationalizationString.Lights))
            {
                patm = "ZigeeLogic/selectedlight.png";
            }
            else if (devicetype == Language.StringByID(MyInternationalizationString.Curtains))
            {
                patm = "ZigeeLogic/selectedcurtain.png";
            }
            else if (devicetype == Language.StringByID(MyInternationalizationString.AC))
            {
                patm = "ZigeeLogic/selectedac.png";
            }
            else if (devicetype == Language.StringByID(MyInternationalizationString.Airswitch))
            {
                patm = "ZigeeLogic/selectedairswitch.png";
            }
            return patm;
        }
        /// <summary>
        /// 显示设备的图标
        /// </summary>
        /// <param name="device">设备对象</param>
        /// <param name="button">显示图标的控件</param>
        public static void GetDeviceIcon(CommonDevice device, Button button)
        {
            string patm = "";
            string selectedpatm = "";
            switch (device.Type)
            {
                case DeviceType.OnOffOutput:
                    {
                        patm = "ZigeeLogic/light.png";
                        selectedpatm = "ZigeeLogic/selectedlight.png";
                    }
                    break;
                case DeviceType.IASZone:
                    {
                        var iASZonedevice = device as IASZone;
                        if (iASZonedevice.DeviceID != 1026)
                        {
                            break;
                        }
 
                        if (device.ModelIdentifier == "MSPIRB-ZB.10")
                        {
                            patm = $"ZigeeLogic/sensor541.png";
                            selectedpatm = $"ZigeeLogic/selectedsensor541.png";
                        }
                        else
                        {
                            patm = $"ZigeeLogic/sensor{iASZonedevice.IasDeviceType}.png";
                            selectedpatm = $"ZigeeLogic/selectedsensor{iASZonedevice.IasDeviceType}.png";
                        }
                    }
                    break;
                case DeviceType.TemperatureSensor:
                    {
                        var temperatureSensor = device as TemperatureSensor;
                        if (temperatureSensor.SensorDiv == 1)
                        {
                            patm = $"ZigeeLogic/temperature.png";
                            selectedpatm = $"ZigeeLogic/selectedtemperature.png";
                        }
                        else
                        {
                            patm = "ZigeeLogic/humidity.png";
                            selectedpatm = "ZigeeLogic/selectedhumidity.png";
                        }
                    }
                    break;
                case DeviceType.OnOffSwitch:
                    {
                        patm = "ZigeeLogic/panel.png";
                        selectedpatm = "ZigeeLogic/selectedpanel.png";
                    }
                    break;
                case DeviceType.DoorLock:
                    {
                        patm = "ZigeeLogic/doorlock.png";
                        selectedpatm = "ZigeeLogic/selecteddoorlock.png";
                    }
                    break;
                case DeviceType.DimmableLight:
                    {
 
                        patm = "ZigeeLogic/dimmableLight.png";
                        selectedpatm = "ZigeeLogic/selecteddimmableLight.png";
                    }
                    break;
                case DeviceType.WindowCoveringDevice:
                    {
                        patm = "ZigeeLogic/curtain.png";
                        selectedpatm = "ZigeeLogic/selectedcurtain.png";
                    }
                    break;
                case DeviceType.Thermostat:
                    {
                        patm = "ZigeeLogic/ac.png";
                        selectedpatm = "ZigeeLogic/selectedac.png";
                    }
                    break;
                case DeviceType.AirSwitch:
                    {
                        patm = "ZigeeLogic/airswitch.png";
                        selectedpatm = "ZigeeLogic/selectedairswitch.png";
                    }
                    break;
                case DeviceType.ColorTemperatureLight:
                    {
                        patm = "ZigeeLogic/nightLight.png";
                        selectedpatm = "ZigeeLogic/nightLightSelected.png";
                    }
                    break;
            }
            button.UnSelectedImagePath = patm;
            button.SelectedImagePath = selectedpatm;
        }
        /// <summary>
        /// 支持的设备
        /// </summary>
        /// <param name="type">判断字符串</param>
        /// <returns></returns>
        public static List<DeviceType> GetDevice(string type)
        {
            /// 设备类型列表
            List<DeviceType> deviceTypeList = new List<DeviceType>();
            deviceTypeList.Clear();
            switch (type)
            {
                case "condition_logic":
                    {//自动化支持的条件设备
                        deviceTypeList.Add(DeviceType.IASZone);
                        deviceTypeList.Add(DeviceType.OnOffSwitch);
                        deviceTypeList.Add(DeviceType.OnOffOutput);
                        deviceTypeList.Add(DeviceType.DoorLock);
                        deviceTypeList.Add(DeviceType.TemperatureSensor);
                    }
                    break;
                case "action_logic":
                    {
 
                        //自动化支持的目标设备
                        deviceTypeList.Add(DeviceType.OnOffOutput);
                        deviceTypeList.Add(DeviceType.DimmableLight);
                        deviceTypeList.Add(DeviceType.WindowCoveringDevice);
                        deviceTypeList.Add(DeviceType.Thermostat);
                        deviceTypeList.Add(DeviceType.AirSwitch);
                        deviceTypeList.Add(DeviceType.ColorTemperatureLight);
                        ///门锁特殊
                       // deviceTypeList.Add(DeviceType.DoorLock);
                    }
                    break;
                case "condition_mould":
                    {
                        //自动化模板支持的条件设备
                        deviceTypeList.Add(DeviceType.IASZone);
                    }
                    break;
                case "action_mould":
                    { //自动化模板支持的目标设备
                        deviceTypeList.Add(DeviceType.OnOffOutput);
                    }
                    break;
                case "action_lockaction":
                    {//门锁联动事件支持的目标设备
                        deviceTypeList.Add(DeviceType.OnOffOutput);
                        deviceTypeList.Add(DeviceType.DimmableLight);
                        deviceTypeList.Add(DeviceType.WindowCoveringDevice);
                        deviceTypeList.Add(DeviceType.Thermostat);
                        deviceTypeList.Add(DeviceType.AirSwitch);
                        deviceTypeList.Add(DeviceType.ColorTemperatureLight);
                        ///门锁特殊
                      // deviceTypeList.Add(DeviceType.DoorLock);
                    }
                    break;
 
            }
            return deviceTypeList;
        }
 
        /// <summary>
        /// 更新执行周期的方法
        /// </summary>
        /// <param name="button">显示周期文本</param>
        /// <param name="currentLogic">当前逻辑对象</param>
        public static void UpdateWeek(Button button, Common.Logic currentLogic)
        {
 
            switch (currentLogic.TimeAttribute.Repeat)
            {
                ///0:只执行一次,执行后IsEnable值置;1,今年内执行;2:每天执行;3:每月执行;4:每年执行;5:周重复。
                case 0:
                    {
                        button.Text = Language.StringByID(MyInternationalizationString.executeonce);
                    }; break;
                case 1: { }; break;
                case 2:
                    {
                        button.Text = Language.StringByID(MyInternationalizationString.everyday);
                    }; break;
                case 3:
                    {
 
                        string len = "", value = "";
                        var stringvalue = Convert.ToString(currentLogic.TimeAttribute.MonthDate, 2);
                        var str = stringvalue.Insert(0, new string('0', 32 - stringvalue.Length));
                        for (int j = 31; j >= 0; j--)
                        {
                            len += str.Substring(j, 1);
                        }
                        for (int j = 0; j < len.Length; j++)
                        {
                            var strvalue = len.Substring(j, 1);
                            if (strvalue == "1")
                            {
                                value += (j + 1).ToString() + ",";
                            }
                        }
                        button.Text = Language.StringByID(MyInternationalizationString.monthly) + value.TrimEnd(',') + Language.StringByID(MyInternationalizationString.day);
 
                    }; break;
                case 4:
                    {
 
                        Dictionary<int, int> dictionary = new Dictionary<int, int>();
                        ///找出执行的月份和天数
                        if (currentLogic.TimeAttribute.SelectMonDate.Count != 0)
                        {
                            for (int i = 0; i < currentLogic.TimeAttribute.SelectMonDate.Count; i++)
                            {
                                var dayvalue = currentLogic.TimeAttribute.SelectMonDate[i];
                                if (dayvalue != 0)
                                {
                                    dictionary.Add(i + 1, dayvalue);
                                }
                            }
                        }
                        if (dictionary.Count != 0 && dictionary.Count == 1)
                        {
                            string len = "", leng = "";
                            int minvalue = 0, Maximum = 0;
                            foreach (var value in dictionary)
                            {
                                ///取出月份
                                var month = value.Key;
                                ///取出日数
                                var day = value.Value;
                                var maxvalue = Convert.ToString(day, 2);
                                var str = maxvalue.Insert(0, new string('0', 32 - maxvalue.Length));
                                for (int j = 31; j >= 0; j--)
                                {
                                    len += str.Substring(j, 1);
                                }
 
                                for (int j = 0; j < len.Length; j++)
                                {
                                    var strvalue = len.Substring(j, 1);
                                    if (strvalue == "1")
                                    {
                                        minvalue = j + 1;
                                        break;
                                    }
                                }
                                for (int j = 0; j < len.Length; j++)
                                {
                                    var strvalue = len.Substring(j, 1);
                                    if (strvalue == "1")
                                    {
                                        Maximum = j + 1;
                                    }
                                }
 
                                if (month.ToString().Length < 2)
                                {
                                    leng = "0" + month.ToString();
                                }
                                else
                                {
                                    leng = month.ToString();
                                }
                                if (minvalue == Maximum)
                                {
                                    button.Text = Language.StringByID(MyInternationalizationString.everyyear) + leng + "/" + (minvalue.ToString().Length < 2 ? "0" + minvalue.ToString() : minvalue.ToString());
                                }
                                else
                                {
                                    button.Text = Language.StringByID(MyInternationalizationString.everyyear) + leng + "/" + (minvalue.ToString().Length < 2 ? "0" + minvalue.ToString() : minvalue.ToString()) + "-" + leng + "/" + (Maximum.ToString().Length < 2 ? "0" + Maximum.ToString() : Maximum.ToString());
                                }
                            }
 
                        }
                        else
                        {
                            int b = 0;
                            string stringtext = "";
                            foreach (var value in dictionary)
                            {
                                string len = "", leng = "";
                                int minvalue = 0, Maximum = 0;
                                ///取出月份
                                var month = value.Key;
                                ///取出日数
                                var day = value.Value;
                                var maxvalue = Convert.ToString(day, 2);
                                var str = maxvalue.Insert(0, new string('0', 32 - maxvalue.Length));
                                for (int j = 31; j >= 0; j--)
                                {
                                    len += str.Substring(j, 1);
                                }
 
 
                                if (month.ToString().Length < 2)
                                {
                                    leng = "0" + month.ToString();
                                }
                                else
                                {
                                    leng = month.ToString();
                                }
 
 
 
                                if (b == 0)
                                {
                                    for (int j = 0; j < len.Length; j++)
                                    {
                                        var strvalue = len.Substring(j, 1);
                                        if (strvalue == "1")
                                        {
                                            minvalue = j + 1;
                                            break;
                                        }
                                    }
                                    stringtext += leng + "/" + (minvalue.ToString().Length < 2 ? "0" + minvalue.ToString() : minvalue.ToString()) + "-";
 
                                }
 
                                if (b == dictionary.Count - 1)
                                {
                                    for (int j = 0; j < len.Length; j++)
                                    {
                                        var strvalue = len.Substring(j, 1);
                                        if (strvalue == "1")
                                        {
                                            Maximum = j + 1;
                                        }
                                    }
                                    stringtext += leng + "/" + (Maximum.ToString().Length < 2 ? "0" + Maximum.ToString() : Maximum.ToString());
 
                                }
                                b++;
                            }
                            button.Text = Language.StringByID(MyInternationalizationString.everyyear) + stringtext;
                        }
 
                    }; break;
                case 5:
                    {
                        string len = "";
                         string   text = "";
                        string weekStr = Language.StringByID(MyInternationalizationString.week1);
                        List<int> listvalueInt = new List<int>();
                        listvalueInt.Clear();
                        var maxvalue = Convert.ToString(currentLogic.TimeAttribute.WeekDay, 2);
                        var str = maxvalue.Insert(0, new string('0', 8 - maxvalue.Length));
                        for (int j = 7; j >= 0; j--)
                        {
                            len += str.Substring(j, 1);
                        }
 
                        for (int j = 0; j < len.Length; j++)
                        {
                            var strvalue = len.Substring(j, 1);
                            if (strvalue == "1")
                            {
                                listvalueInt.Add(j + 1);
                                switch ((j + 1)) {
                                    case 1: {
                                            text += weekStr + Language.StringByID(MyInternationalizationString.mon1) + ",";
                                        }
                                        break;
                                    case 2: {
                                            text += weekStr + Language.StringByID(MyInternationalizationString.tue1) + ",";
                                        }
                                        break;
                                    case 3: {
                                            text += weekStr + Language.StringByID(MyInternationalizationString.wed1) + ",";
                                        }
                                        break;
                                    case 4: {
                                            text += weekStr + Language.StringByID(MyInternationalizationString.thu1) + ",";
                                        }
                                        break;
                                    case 5: {
                                            text += weekStr + Language.StringByID(MyInternationalizationString.frl1) + ",";
                                        }
                                        break;
                                    case 6: {
                                            text += weekStr + Language.StringByID(MyInternationalizationString.sat1) + ",";
                                        }
                                        break;
                                    case 7: {
                                            text += weekStr + Language.StringByID(MyInternationalizationString.sun1) + ",";
                                        }
                                        break;
                                }
 
                            }
                        }
                        //暂时隐藏掉,需要显示周末和工作日再放开;
                        //if (listvalueInt.Count == 5 && !listvalueInt.Contains(6) && !listvalueInt.Contains(7))
                        //{
                        //    btndisplaycycle.Text = Language.StringByID(MyInternationalizationString.workingday);
                        //}
                        //else if (listvalueInt.Count == 2 && listvalueInt.Contains(6) && listvalueInt.Contains(7))
                        //{
                        //    btndisplaycycle.Text = Language.StringByID(MyInternationalizationString.weekend);
                        //}
                        //else if (listvalueInt.Count == 7)
                        //{
                        //    btndisplaycycle.Text = Language.StringByID(MyInternationalizationString.everyday);
                        //}
                        //else
                        //{
                        //    btndisplaycycle.Text = Language.StringByID(MyInternationalizationString.week1) + text.Replace(Language.StringByID(MyInternationalizationString.week1), "").TrimEnd(',');
                        //}
                        button.Text = weekStr + text.Replace(weekStr, "").TrimEnd(',');
                    }; break;
            }
 
 
        }
        /// <summary>
        ///返回设备的方法
        /// </summary>
        /// <param name="DeviceAddr">设备Mac</param>
        /// <param name="Epoint">设备端口</param>
        /// <returns></returns>
        public static ZigBee.Device.CommonDevice GetCommonDevice(string DeviceAddr, string Epoint)
        {
 
            var device = Common.Logic.LogicDviceList.Find((obj) => { return ((obj.DeviceAddr == DeviceAddr) && (obj.DeviceEpoint.ToString() == Epoint)); });
            if (device == null)
            {
                device = new ZigBee.Device.CommonDevice();
            }
            return device;
        }
        /// <summary>
        /// 推送设置的方法
        /// </summary>
        /// <param name="middle"></param>
        public static void Push(VerticalScrolViewLayout middle)
        {
            LogicView.Addview pushview = new LogicView.Addview();
            pushview.switchBtn.Visible = true;
            pushview.titleBtn.TextID = MyInternationalizationString.pushswitch;
            middle.AddChidren(pushview.AddDeviceView());
 
            LogicView.Addview custompushview = new LogicView.Addview();
            custompushview.iconBtn.Visible = true;
            custompushview.iconBtn.UnSelectedImagePath = "ZigeeLogic/next.png";
            custompushview.titleBtn.TextID = MyInternationalizationString.custompush;
            custompushview.lineBtn.BackgroundColor = ZigbeeColor.Current.LogicBlankBackgroundColor;
            middle.AddChidren(custompushview.AddDeviceView());
 
            EventHandler<MouseEventArgs> customclick = (sender, e) =>
            {
                var CustomText = new CustomText();
                UserView.HomePage.Instance.AddChidren(CustomText);
                UserView.HomePage.Instance.PageIndex += 1;
                CustomText.Show();
            };
            custompushview.frameLayout.MouseUpEventHandler += customclick;
            custompushview.clickBtn.MouseUpEventHandler += customclick;
            // bool tag = false;//标记开关状态;
            pushview.clickBtn.MouseUpEventHandler += (sender1, e1) =>
            {
                pushview.switchBtn.IsSelected = !pushview.switchBtn.IsSelected;
                if (pushview.switchBtn.IsSelected)
                {
                    LogicView.IfString.Tag = true;
                    custompushview.frameLayout.Height = Application.GetRealHeight(160);
                    Common.Logic.CurrentLogic.LogicIsCustomPushText = 1;
                    pushview.lineBtn.BackgroundColor = ZigbeeColor.Current.LogicRowLayoutLineColor;
 
                }
                else
                {
                    LogicView.IfString.Tag = false;
                    custompushview.frameLayout.Height = Application.GetRealHeight(0);
                    Common.Logic.CurrentLogic.LogicIsCustomPushText = 0;
                    pushview.lineBtn.BackgroundColor = ZigbeeColor.Current.LogicBlankBackgroundColor;
                }
                if (!Config.Instance.Home.IsVirtually)
                {
                    Send.Zj(LogicView.IfString.Tag, Common.Logic.CurrentLogic);
 
                }
            };
 
            if (Common.Logic.CurrentLogic.LogicIsCustomPushText == 0)
            {
                LogicView.IfString.Tag = false;
                pushview.switchBtn.IsSelected = false;
                custompushview.frameLayout.Height = Application.GetRealHeight(0);
                pushview.lineBtn.BackgroundColor = ZigbeeColor.Current.LogicBlankBackgroundColor;
            }
            else
            {
                LogicView.IfString.Tag = true;
                pushview.switchBtn.IsSelected = true;
                custompushview.frameLayout.Height = Application.GetRealHeight(160);
                pushview.lineBtn.BackgroundColor = ZigbeeColor.Current.LogicRowLayoutLineColor;
            }
        }
        /// <summary>
        /// 保存自动化的方法
        /// </summary>
        /// <param name="if_logic">判断跳转界面的字符串</param>
        /// <param name="name">逻辑名称</param>
        /// <param name="tag"></param>
        /// <param name="CurrentLogic">当前逻辑</param>
        public async static void SaveLogic(string if_logic, string name, bool tag, Common.Logic CurrentLogic)
        {
 
            if (CurrentLogic.Conditions.Count == 0 || CurrentLogic.Actions.Count == 0)
            {
                var alert = new ShowMsgControl(ShowMsgType.Normal,
                  Language.StringByID(MyInternationalizationString.addnull),
                  Language.StringByID(MyInternationalizationString.confrim));
                alert.Show();
                return;
            }
 
            if (string.IsNullOrEmpty(name))
            {
                var alert = new ShowMsgControl(ShowMsgType.Normal,
                  Language.StringByID(MyInternationalizationString.PleaseEnterLogicName),
                  Language.StringByID(MyInternationalizationString.confrim));
                alert.Show();
                return;
            }
            ///先隐藏判断名字相同的功能;
            //var logicname = Common.Logic.LogicList.Find((logic) => Common.Logic.CurrentLogic.LogicId != logic.LogicId && logic.LogicName == name);
            //if (logicname != null)
            //{
            //    new Alert(Language.StringByID(MyInternationalizationString.Tip), Language.StringByID(MyInternationalizationString.Rename), Language.StringByID(MyInternationalizationString.Close)).Show();
            //    return;
            //}
 
            CurrentLogic.LogicName = name;
            bool succeed = false;
            //判断是新添加逻辑(默认0)还是修改逻辑
            CommonPage.Loading.Start();
 
            if (Config.Instance.Home.IsVirtually)
            {
                if (Common.Logic.LogicList.Count == 0)
                {
                    CurrentLogic.LogicId = 1;
                    Common.Logic.LogicList.Add(CurrentLogic);
                }
 
                if (CurrentLogic.LogicId == 0)
                {
                    bool d = false;
                    for (int i = 1; i < 50; i++)
                    {
                       
                        for (int j = 0; j < Common.Logic.LogicList.Count; j++)
                        {
                            if (i != Common.Logic.LogicList[j].LogicId)
                            {
                                CurrentLogic.LogicId = i;
                                Common.Logic.LogicList.Add(CurrentLogic);
                                d = true;
                                break;
                            }
                        }
                        if (d)
                        {
                            break;
                        }
                    }
 
                }
                else
                {
                    for (int j = 0; j < Common.Logic.LogicList.Count; j++)
                    {
                        if (CurrentLogic.LogicId == Common.Logic.LogicList[j].LogicId)
                        {
                            Common.Logic.LogicList.RemoveAt(j);
                            Common.Logic.LogicList.Insert(j,CurrentLogic);
                            break;
                        }
                    }
 
                }
 
                //自动化逻辑列表
            }
            else
            {
                if (CurrentLogic.LogicId == 0)
                {
                    //发送添加逻辑命令
                    var logicifon = await Send.AddModifyLogic(CurrentLogic);
                    if (logicifon != null && logicifon.LogicId != 0)
                    {
                        succeed = true;
                        CurrentLogic.LogicId = logicifon.LogicId;
                        if (LogicView.IfString._Logic == if_logic || LogicView.IfString._SoneLogic == if_logic)
                        {
                            //自动化逻辑列表
                            Common.Logic.LogicList.Add(CurrentLogic);
                        }
                        if (LogicView.IfString._LockLogic == if_logic)
                        {
                            //门锁联动事件逻辑列表
                            Common.Logic.LockLogicList.Add(CurrentLogic);
                        }
                        if (LogicView.IfString._SoneLogic == if_logic)
                        {
                            //Sone门锁常开模式逻辑列表
                            Common.Logic.SoneLogicList.Add(CurrentLogic);
 
                        }
                        if (tag)
                        {
                            Send.Zj(tag, CurrentLogic);
                        }
                    }
                }
                else
                {
                    //发送修改逻辑命令;
                    //修改命令不需要等待回复;
                    Send.AddModifyLogic(CurrentLogic);
                    //编辑默认成功(不考虑网络情况);
                    succeed = true;
                }
            }
            CommonPage.Loading.Hide();
 
            if (!succeed)//succeed标记是添加成功还是失败
            {
                //网关回复失败,不关闭界面,让它停留当前界面;
                //(原因:考虑到失败重新编辑原来数据给用户带来了麻烦)
                ///提示:添加自动化失败;
                //TipView("添加自动化失败");
                //return;
            }
 
            UserView.HomePage.Instance.RemoveViewByTag("Logic");//移除所有标记Logic界面
            if (LogicView.IfString._Logic == if_logic)
            {
 
                //查询-当前逻辑-是否添加地理位置作为条件
                var exist = Common.Logic.CurrentLogic.Conditions.Find((obj) => obj["Type"] == "7");
                if (exist==null)
                {
                    bool if_type = false;
                    //查询-逻辑列表-是否添加过地理位置作为条件
                    for (int a = 0; a < Common.Logic.LogicList.Count; a++)
                    {
                        var logic = Common.Logic.LogicList[a];
                        var exist_logic = logic.Conditions.Find((obj) => obj["Type"] == "7");
                        if (exist_logic != null)
                        {
                            //是否存在地理位置条件
                            if_type = true;
                            //退出for循环
                            break;
                        }
                    }
                    if (if_type)
                    {
                        //查询之前状态是否已经开启GPS服务(以本地存储状态为主 0:没开启; 1:开启)
                        if (Send.If_Exist == "0")
                        {
                            //开启GPS服务
                            Application.StartGPSLocationService();
                            //保存GPS服务开启状态
                            Send.SaveLocalFile(Config.Instance.HomeId + "_GPS_File", "1");
                        }
 
                    }
                    else
                    {
                        //如果找不到地理位置作为条件的话,关闭GPS服务(减少耗电)
                        if (Send.If_Exist == "1")
                        {
                            //关闭GPS服务
                            Application.StopGPSLocationService();
                            //保存GPS服务关闭状态
                            Send.SaveLocalFile(Config.Instance.HomeId + "_GPS_File", "0");
                        }
                    }
                }
                else
                {
                    //查询之前状态是否已经开启GPS服务(以本地存储状态为主 0:没开启; 1:开启)
                    if (Send.If_Exist == "0")
                    {
                        //开启GPS服务
                        Application.StartGPSLocationService();
                        //保存GPS服务开启状态
                        Send.SaveLocalFile(Config.Instance.HomeId + "_GPS_File", "1");
                    }
                }
                //只刷新分类-自动化上下滑动view;
                Phone.Category.CategoryMainForm.instance?.RefreshBodyView();
                // Category.Category.instance?.RefreshBodyView();
            }
            else if (LogicView.IfString._LockLogic == if_logic)
            {
                //跳到门锁联动事件列表界面
                UserView.HomePage.Instance.RemoveViewByTag("LockListView");//移除所有标记LockListView界面
                var doorLockLogicList = new DoorLockLogic.LockLogicList();
                UserView.HomePage.Instance.AddChidren(doorLockLogicList);
                UserView.HomePage.Instance.PageIndex += 1;
                doorLockLogicList.Show();
            }
            else if (LogicView.IfString._SoneLogic == if_logic)
            {
                //跳到Sone门锁联动事件列表界面
                //UserView.HomePage.Instance.RemoveViewByTag("SoneLogic");//移除所有标记LockListView界面
                //var soneLogicList = new SoneLogicList();
                //UserView.HomePage.Instance.AddChidren(soneLogicList);
                //UserView.HomePage.Instance.PageIndex += 1;
                //soneLogicList.Show();
 
                SoneLogicList.soneLogicList?.RefreshView();
            }
 
        }
        /// <summary>
        /// 跳入输出目标功能界面的方法
        /// </summary>
        /// <param name="str1">设备界面识别字符串</param>
        /// <param name="str2">场景界面识别字符串</param>
        public static void View(string str1, string str2)
        {
            var deviceTarget = new DeviceTarget();
            UserView.HomePage.Instance.AddChidren(deviceTarget);
            UserView.HomePage.Instance.PageIndex += 1;
            deviceTarget.Show(str1, str2);
        }
 
        /// <summary>
        /// 界面高度
        /// </summary>
        public static int H = 1922;
 
 
 
    }
}