黄学彪
2021-01-28 1fcf2302f79f9cbea5ef17c3688311ed65cfabb4
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
using Shared;
using HDL_ON.Stan;
using System;
using System.Collections.Generic;
using System.Text;
using HDL_ON.UI.CSS;
using HDL_ON.Entity;
using HDL_ON.DriverLayer;
 
namespace HDL_ON.UI
{
    /// <summary>
    /// 涂鸦空气净化器的控制界面
    /// </summary>
    public class TuyaAirCleanerPage : DeviceFunctionCardCommonForm
    {
        #region ■ 变量声明___________________________
 
        /// <summary>
        /// 图片控件
        /// </summary>
        private PicViewControl btnPictrue = null;
        /// <summary>
        /// 滤芯使用率控件
        /// </summary>
        private NormalViewControl btnUsePersent = null;
        /// <summary>
        /// 温度
        /// </summary>
        private NormalViewControl btnTemperature = null;
        /// <summary>
        /// 湿度
        /// </summary>
        private NormalViewControl btnHumidity = null;
        /// <summary>
        /// PM2.5
        /// </summary>
        private NormalViewControl btnPm25 = null;
        /// <summary>
        /// 开关控件
        /// </summary>
        private IconViewControl btnSwitch = null;
        /// <summary>
        /// 模式控件
        /// </summary>
        private IconViewControl btnMode = null;
        /// <summary>
        /// 模式的显示文本控件
        /// </summary>
        private NormalViewControl btnModeView = null;
        /// <summary>
        /// 风速控件
        /// </summary>
        private IconViewControl btnFan = null;
        /// <summary>
        /// 风速的显示文本控件
        /// </summary>
        private NormalViewControl btnFanView = null;
        /// <summary>
        /// 定时控件
        /// </summary>
        private IconViewControl btnTime = null;
        /// <summary>
        /// 定时的显示文本控件
        /// </summary>
        private NormalViewControl btnTimeView = null;
        /// <summary>
        /// 童锁开关控件
        /// </summary>
        private MostRightIconControl btnLockSwitch = null;
        /// <summary>
        /// 负离子开关控件
        /// </summary>
        private MostRightIconControl btnAnionSwitch = null;
        /// <summary>
        /// 滤芯复位开关控件
        /// </summary>
        private MostRightIconControl btnResetSwitch = null;
        /// <summary>
        /// 空气质量数据
        /// </summary>
        private AirCleanerData airCleanerData = new AirCleanerData();
 
        #endregion
 
        #region ■ 初始化_____________________________
 
        /// <summary>
        /// 初始化白色区域的内容
        /// </summary>
        public override void InitFrameWhiteContent()
        {
            base.SetTitleText(Language.StringByID(StringId.AirCleaner));
 
            //添加第二索引页
            this.AddSecondPage();
            //初始化第一个索引页的内容
            this.InitFrameWhiteContent1();
            //初始化第二个索引页的内容
            this.InitFrameWhiteContent2();
 
            //刷新当前设备的状态缓存
            this.RefreshNowDeviceStatuMemory(this.device);
            //刷新界面状态
            this.RefreshFormStatu();
        }
 
        /// <summary>
        /// 初始化第一个索引页的内容
        /// </summary>
        private void InitFrameWhiteContent1()
        {
            //图片控件
            this.btnPictrue = new PicViewControl(94, 130);
            btnPictrue.Y = Application.GetRealHeight(90);
            btnPictrue.Gravity = Gravity.CenterHorizontal;
            btnPictrue.UnSelectedImagePath = "FunctionIcon/Electrical/Fan/AirCleanerOff.png";
            btnPictrue.SelectedImagePath = "FunctionIcon/Electrical/Fan/AirCleanerOn.png";
            FrameWhiteCentet1.AddChidren(btnPictrue);
            btnPictrue.ButtonClickEvent += (sender, e) =>
            {
                //发送开关命令
                this.SendSwitchComand();
            };
 
            //滤芯使用
            this.btnUsePersent = new NormalViewControl(FrameWhiteCentet1.Width, Application.GetRealHeight(20), false);
            btnUsePersent.TextAlignment = TextAlignment.Center;
            btnUsePersent.Y = btnPictrue.Bottom + Application.GetRealHeight(16);
            btnUsePersent.TextColor = CSS.CSS_Color.MainColor;
            FrameWhiteCentet1.AddChidren(btnUsePersent);
            //温度
            this.btnTemperature = new NormalViewControl(106, 28, true);
            btnTemperature.Y = btnUsePersent.Bottom + Application.GetRealHeight(23);
            btnTemperature.TextSize = CSS.CSS_FontSize.EmphasisFontSize_Secondary;
            btnTemperature.TextAlignment = TextAlignment.Center;
            btnTemperature.Text = "22℃";
            FrameWhiteCentet1.AddChidren(btnTemperature);
            //室内温度
            var btnTemperatureView = new NormalViewControl(btnTemperature.Width, Application.GetRealHeight(14), false);
            btnTemperatureView.Y = btnTemperature.Bottom + Application.GetRealHeight(4);
            btnTemperatureView.TextSize = CSS.CSS_FontSize.PromptFontSize_SecondaryLevel;
            btnTemperatureView.TextAlignment = TextAlignment.Center;
            btnTemperatureView.TextID = StringId.IndoorTemp;
            FrameWhiteCentet1.AddChidren(btnTemperatureView);
            //一条竖线
            var btnLine1 = new NormalViewControl(1, Application.GetRealHeight(19), false);
            btnLine1.X = btnTemperature.Right;
            btnLine1.Y = btnTemperature.Y + (btnTemperature.Height - Application.GetRealHeight(19)) / 2;
            btnLine1.BackgroundColor = CSS.CSS_Color.TextualColor;
            FrameWhiteCentet1.AddChidren(btnLine1);
 
            //PM2.5
            this.btnPm25 = new NormalViewControl(106, 28, true);
            btnPm25.Y = btnTemperature.Y;
            btnPm25.X = btnLine1.Right;
            btnPm25.TextSize = CSS.CSS_FontSize.EmphasisFontSize_Secondary;
            btnPm25.TextAlignment = TextAlignment.Center;
            btnPm25.Text = "0";
            FrameWhiteCentet1.AddChidren(btnPm25);
            //PM2.5
            var btnPm25View = new NormalViewControl(btnPm25.Width, Application.GetRealHeight(14), false);
            btnPm25View.X = btnPm25.X;
            btnPm25View.Y = btnTemperatureView.Y;
            btnPm25View.TextSize = CSS.CSS_FontSize.PromptFontSize_SecondaryLevel;
            btnPm25View.TextAlignment = TextAlignment.Center;
            btnPm25View.Text = "PM2.5";
            FrameWhiteCentet1.AddChidren(btnPm25View);
 
            //一条竖线
            var btnLine2 = new NormalViewControl(1, btnLine1.Height, false);
            btnLine2.X = btnPm25.Right;
            btnLine2.Y = btnLine1.Y;
            btnLine2.BackgroundColor = CSS_Color.TextualColor;
            FrameWhiteCentet1.AddChidren(btnLine2);
 
            //湿度
            this.btnHumidity = new NormalViewControl(114, 28, true);
            btnHumidity.Y = btnTemperature.Y;
            btnHumidity.X = btnLine2.Right;
            btnHumidity.TextSize = CSS.CSS_FontSize.EmphasisFontSize_Secondary;
            btnHumidity.TextAlignment = TextAlignment.Center;
            btnHumidity.Text = "50%";
            FrameWhiteCentet1.AddChidren(btnHumidity);
            //室内湿度
            var btnHumidityView = new NormalViewControl(btnHumidity.Width, Application.GetRealHeight(14), false);
            btnHumidityView.X = btnHumidity.X;
            btnHumidityView.Y = btnTemperatureView.Y;
            btnHumidityView.TextSize = CSS_FontSize.PromptFontSize_SecondaryLevel;
            btnHumidityView.TextAlignment = TextAlignment.Center;
            btnHumidityView.TextID = StringId.IndoorHumidity;
            FrameWhiteCentet1.AddChidren(btnHumidityView);
 
            //2021.01.26 目前不用温度和湿度
            btnTemperature.RemoveFromParent();
            btnTemperatureView.RemoveFromParent();
            btnLine1.RemoveFromParent();
            btnLine2.RemoveFromParent();
            btnHumidity.RemoveFromParent();
            btnHumidityView.RemoveFromParent();
 
            //风速图标
            this.btnFan = new IconViewControl(38);
            btnFan.UnSelectedImagePath = "FunctionIcon/Electrical/Fan/Fan.png";
            btnFan.X = Application.GetRealWidth(40);
            btnFan.Y = btnPm25View.Bottom + Application.GetRealHeight(40);
            FrameWhiteCentet1.AddChidren(btnFan);
            btnFan.ButtonClickEvent += (sender, e) =>
            {
                //显示风速界面
                this.ShowFanSpeedView();
            };
            this.btnFanView = new NormalViewControl(80, 18, true);
            btnFanView.Y = btnFan.Bottom + Application.GetRealHeight(10);
            btnFanView.X = btnFan.X - (Application.GetRealWidth(80) - btnFan.Width) / 2;
            btnFanView.TextAlignment = TextAlignment.Center;
            btnFanView.TextSize = CSS_FontSize.PromptFontSize_FirstLevel;
            btnFanView.Text = Language.StringByID(StringId.FanSpeed);
            FrameWhiteCentet1.AddChidren(btnFanView);
 
            //定时图标
            this.btnTime = new IconViewControl(38);
            btnTime.UnSelectedImagePath = "FunctionIcon/Electrical/Fan/Time.png";
            btnTime.Y = btnFan.Y;
            btnTime.Gravity = Gravity.CenterHorizontal;
            FrameWhiteCentet1.AddChidren(btnTime);
            btnTime.ButtonClickEvent += (sender, e) =>
            {
                //显示定时界面
                this.ShowTimingSelectView();
            };
            this.btnTimeView = new NormalViewControl(80, 18, true);
            btnTimeView.Y = btnFanView.Y;
            btnTimeView.X = btnTime.X - (Application.GetRealWidth(80) - btnTime.Width) / 2;
            btnTimeView.TextAlignment = TextAlignment.Center;
            btnTimeView.TextSize = CSS_FontSize.PromptFontSize_FirstLevel;
            FrameWhiteCentet1.AddChidren(btnTimeView);
 
            //模式图标
            this.btnMode = new IconViewControl(38);
            btnMode.Y = btnFan.Y;
            btnMode.X = btnTime.Right + Application.GetRealWidth(66);
            FrameWhiteCentet1.AddChidren(btnMode);
            btnMode.ButtonClickEvent += (sender, e) =>
            {
                //显示模式界面
                this.ShowModeSelectView();
            };
            this.btnModeView = new NormalViewControl(80, 18, true);
            btnModeView.Y = btnFanView.Y;
            btnModeView.X = btnMode.X - (Application.GetRealWidth(80) - btnMode.Width) / 2;
            btnModeView.TextAlignment = TextAlignment.Center;
            btnModeView.TextSize = CSS_FontSize.PromptFontSize_FirstLevel;
            FrameWhiteCentet1.AddChidren(btnModeView);
 
            //开关图标
            this.btnSwitch = new IconViewControl(40);
            btnSwitch.Gravity = Gravity.CenterHorizontal;
            btnSwitch.Y = btnMode.Bottom + Application.GetRealHeight(61);
            btnSwitch.UnSelectedImagePath = "Public/PowerClose.png";
            btnSwitch.SelectedImagePath = "Public/PowerOpen.png";
            FrameWhiteCentet1.AddChidren(btnSwitch);
            btnSwitch.ButtonClickEvent += (sender, e) =>
            {
                //发送开关命令
                this.SendSwitchComand();
            };
        }
 
        /// <summary>
        /// 初始化第二个索引页的内容
        /// </summary>
        private void InitFrameWhiteContent2()
        {
            //开关
            var btnTitleName = new NormalViewControl(270, 37, true);
            btnTitleName.X = Application.GetRealWidth(16);
            btnTitleName.Y = Application.GetRealHeight(18);
            btnTitleName.TextColor = CSS_Color.FirstLevelTitleColor;
            btnTitleName.TextSize = CSS_FontSize.EmphasisFontSize_FirstLevel;
            btnTitleName.TextID = StringId.OnOff;
            FrameWhiteCentet2.AddChidren(btnTitleName);
 
            //童锁
            var rowLock = new FrameRowControl();
            rowLock.Height = Application.GetRealHeight(50);
            rowLock.Width = FrameWhiteCentet2.Width;
            rowLock.Y = Application.GetRealHeight(75);
            FrameWhiteCentet2.AddChidren(rowLock);
            rowLock.AddLeftCaption(Language.StringByID(StringId.V_chip), 200);
            rowLock.AddBottomLine();
            this.btnLockSwitch = rowLock.AddMostRightSwitchIcon();
            btnLockSwitch.IsSelected = this.airCleanerData.Lock;
            btnLockSwitch.ButtonClickEvent += (sender, e) =>
            {
                if (this.btnSwitch.IsSelected == false)
                {
                    //还没有打开开关
                    return;
                }
                //发送使能命令
                this.SendEnableComand(btnLockSwitch, "lock", btnLockSwitch.IsSelected == true ? "false" : "true");
            };
 
            //负离子
            var rowAnion = new FrameRowControl();
            rowAnion.Height = Application.GetRealHeight(50);
            rowAnion.Width = FrameWhiteCentet2.Width;
            rowAnion.Y = rowLock.Bottom;
            FrameWhiteCentet2.AddChidren(rowAnion);
            rowAnion.AddLeftCaption(Language.StringByID(StringId.Anion), 200);
            rowAnion.AddBottomLine();
            this.btnAnionSwitch = rowAnion.AddMostRightSwitchIcon();
            btnAnionSwitch.IsSelected = this.airCleanerData.Anion;
            btnAnionSwitch.ButtonClickEvent += (sender, e) =>
            {
                if (this.btnSwitch.IsSelected == false)
                {
                    //还没有打开开关
                    return;
                }
                //发送使能命令
                this.SendEnableComand(btnAnionSwitch, "anion", btnAnionSwitch.IsSelected == true ? "false" : "true");
            };
 
            //滤芯复位
            var rowReset = new FrameRowControl();
            rowReset.Height = Application.GetRealHeight(50);
            rowReset.Width = FrameWhiteCentet2.Width;
            rowReset.Y = rowAnion.Bottom;
            FrameWhiteCentet2.AddChidren(rowReset);
            rowReset.AddLeftCaption(Language.StringByID(StringId.FilterElementReset), 200);
            rowReset.AddBottomLine();
            this.btnResetSwitch = rowReset.AddMostRightSwitchIcon();
            btnResetSwitch.IsSelected = this.airCleanerData.FilterReset;
            btnResetSwitch.ButtonClickEvent += (sender, e) =>
            {
                if (this.btnSwitch.IsSelected == false)
                {
                    //还没有打开开关
                    return;
                }
                //请确认是否已实际重置滤芯并按{0}照说明书要求操作设备进行滤芯{0}寿命重新计时
                string msg = Language.StringByID(StringId.FilterElementResetMsg).Replace("{0}", "\r\n");
                this.ShowMassage(ShowMsgType.Confirm, msg, () =>
                {
                    //发送使能命令
                    this.SendEnableComand(btnResetSwitch, "filter_reset", btnResetSwitch.IsSelected == true ? "false" : "true");
                });
            };
        }
 
        #endregion
 
        #region ■ 显示风速界面_______________________
 
        /// <summary>
        /// 显示风速界面
        /// </summary>
        private void ShowFanSpeedView()
        {
            //整个灰色界面
            var frameBack = new Dialog();
 
            var dialogBody = new NormalFrameLayout();
            frameBack.AddChidren(dialogBody);
            dialogBody.ButtonClickEvent = (sender, e) =>
            {
                frameBack.Close();
            };
            frameBack.Show();
 
            //菜单控件(选择风速)
            var menuContr = new DialogTitleMenuControl(4, Language.StringByID(StringId.WindSpeedSelection));
            menuContr.X = Application.GetRealWidth(5);
            menuContr.Y = Application.GetRealHeight(240);
            menuContr.Width = Application.GetRealWidth(160);
            menuContr.Height = Application.GetRealHeight(200);
            dialogBody.AddChidren(menuContr);
 
            //低档
            var iconPath = this.airCleanerData.Gear == "1" ? "FunctionIcon/Electrical/Fan/LowGearSelect.png" : "FunctionIcon/Electrical/Fan/LowGear.png";
            menuContr.AddRowMenu(Language.StringByID(StringId.LowGear), iconPath, this.airCleanerData.Gear == "1", () =>
            {
                frameBack.Close();
                //发送风速命令
                this.SendFanSpeedComand("1");
            });
 
            //中档
            iconPath = this.airCleanerData.Gear == "2" ? "FunctionIcon/Electrical/Fan/MidGearSelect.png" : "FunctionIcon/Electrical/Fan/MidGear.png";
            menuContr.AddRowMenu(Language.StringByID(StringId.MidGear), iconPath, this.airCleanerData.Gear == "2", () =>
            {
                frameBack.Close();
                //发送风速命令
                this.SendFanSpeedComand("2");
            });
 
            //高档
            iconPath = this.airCleanerData.Gear == "3" ? "FunctionIcon/Electrical/Fan/HeightGearSelect.png" : "FunctionIcon/Electrical/Fan/HeightGear.png";
            menuContr.AddRowMenu(Language.StringByID(StringId.HeightGear), iconPath, this.airCleanerData.Gear == "3", () =>
            {
                frameBack.Close();
                //发送风速命令
                this.SendFanSpeedComand("3");
            });
        }
 
        #endregion
 
        #region ■ 显示定时界面_______________________
 
        /// <summary>
        /// 显示定时界面
        /// </summary>
        private void ShowTimingSelectView()
        {
            var listText = new List<string>();
            listText.Add(Language.StringByID(StringId.CancelTiming));
            listText.Add("1" + Language.StringByID(StringId.Hour1));
            listText.Add("2" + Language.StringByID(StringId.Hour1));
            listText.Add("4" + Language.StringByID(StringId.Hour1));
            listText.Add("8" + Language.StringByID(StringId.Hour1));
 
            //默认选择
            int defultIndex = this.airCleanerData.Timing == string.Empty ? -1 : Convert.ToInt32(this.airCleanerData.Timing);
            if (defultIndex == 0) { defultIndex = -1; }
 
            var contr = new BottomItemSelectControl(5, Language.StringByID(StringId.TimingSetting));
            contr.AddRowMenu(listText, new List<int> { defultIndex });
            contr.FinishOnlyEvent += (div, selectIndex) =>
            {
                if (div == 1)
                {
                    if (selectIndex == 0)
                    {
                        //发送定时命令
                        this.SendTimingComand("cancel");
                    }
                    else
                    {
                        //发送定时命令
                        this.SendTimingComand(selectIndex.ToString());
                    }
 
                }
            };
        }
 
        #endregion
 
        #region ■ 显示模式界面_______________________
 
        /// <summary>
        /// 显示模式界面
        /// </summary>
        private void ShowModeSelectView()
        {
            //整个灰色界面
            var frameBack = new Dialog();
 
            var dialogBody = new NormalFrameLayout();
            frameBack.AddChidren(dialogBody);
            dialogBody.ButtonClickEvent = (sender, e) =>
            {
                frameBack.Close();
            };
            frameBack.Show();
 
            //菜单控件
            var menuContr = new DialogTitleMenuControl(4, Language.StringByID(StringId.ChooseMode));
            menuContr.X = Application.GetRealWidth(210);
            menuContr.Y = Application.GetRealHeight(197);
            menuContr.Width = Application.GetRealWidth(160);
            menuContr.Height = Application.GetRealHeight(243);
            dialogBody.AddChidren(menuContr);
 
            //自动模式
            var iconPath = this.airCleanerData.Mode == "auto" ? "FunctionIcon/Electrical/Fan/AutoModeSelect.png" : "FunctionIcon/Electrical/Fan/AutoMode.png";
            menuContr.AddRowMenu(Language.StringByID(StringId.AutoMode), iconPath, this.airCleanerData.Mode == "auto", () =>
            {
                frameBack.Close();
                //发送模式命令
                this.SendModeComand("auto");
            });
 
            //手动模式
            iconPath = this.airCleanerData.Mode == "manual" ? "FunctionIcon/Electrical/Fan/HandModeSelect.png" : "FunctionIcon/Electrical/Fan/HandMode.png";
            menuContr.AddRowMenu(Language.StringByID(StringId.HandMode), iconPath, this.airCleanerData.Mode == "manual", () =>
            {
                frameBack.Close();
                //发送模式命令
                this.SendModeComand("manual");
            });
 
            //强劲模式
            iconPath = this.airCleanerData.Mode == "strong" ? "FunctionIcon/Electrical/Fan/ComfortableModeSelect.png" : "FunctionIcon/Electrical/Fan/ComfortableMode.png";
            menuContr.AddRowMenu(Language.StringByID(StringId.StrongMode), iconPath, this.airCleanerData.Mode == "strong", () =>
            {
                frameBack.Close();
                //发送模式命令
                this.SendModeComand("strong");
            });
 
            //睡眠模式
            iconPath = this.airCleanerData.Mode == "sleep" ? "FunctionIcon/Electrical/Fan/SleepModeSelect.png" : "FunctionIcon/Electrical/Fan/SleepMode.png";
            menuContr.AddRowMenu(Language.StringByID(StringId.SleepMode), iconPath, this.airCleanerData.Mode == "sleep", () =>
            {
                frameBack.Close();
                //发送模式命令
                this.SendModeComand("sleep");
            });
        }
 
        #endregion
 
        #region ■ 设备状态反馈_______________________
 
        /// <summary>
        /// 设备状态反馈
        /// </summary>
        /// <param name="i_LocalDevice"></param>
        public override void DeviceStatuPush(Function i_LocalDevice)
        {
            //不是同一个东西
            if (this.device.sid != i_LocalDevice.sid) { return; }
 
            //刷新当前设备的状态缓存
            this.RefreshNowDeviceStatuMemory(i_LocalDevice);
            //刷新界面状态
            this.RefreshFormStatu();
        }
 
        #endregion
 
        #region ■ 发送各种命令_______________________
 
        /// <summary>
        /// 发送模式命令
        /// </summary>
        /// <param name="value">auto:自动  sleep:睡眠  manual:手动  strong:强烈</param>
        private void SendModeComand(string value)
        {
            this.btnMode.CanClick = false;
            HdlThreadLogic.Current.RunThread(() =>
            {
                var dic = new Dictionary<string, string>();
                dic.Add("mode", value);
                Control.Ins.SendWriteCommand(this.device, dic, true);
                HdlThreadLogic.Current.RunMain(() =>
                {
                    this.btnMode.CanClick = true;
                });
            });
        }
 
        /// <summary>
        /// 发送定时命令
        /// </summary>
        /// <param name="value">canel:取消 1:1小时 2:2小时 3:4小时 4:8小时</param>
        private void SendTimingComand(string value)
        {
            this.btnTime.CanClick = false;
            HdlThreadLogic.Current.RunThread(() =>
            {
                var dic = new Dictionary<string, string>();
                dic.Add("countdown", value);
                Control.Ins.SendWriteCommand(this.device, dic, true);
                HdlThreadLogic.Current.RunMain(() =>
                {
                    this.btnTime.CanClick = true;
                });
            });
        }
 
        /// <summary>
        /// 发送风速命令
        /// </summary>
        /// <param name="value">1:低档 2:中档 3:高档</param>
        private void SendFanSpeedComand(string value)
        {
            this.btnFan.CanClick = false;
            HdlThreadLogic.Current.RunThread(() =>
            {
                var dic = new Dictionary<string, string>();
                dic.Add("speed", value);
                Control.Ins.SendWriteCommand(this.device, dic, true);
                HdlThreadLogic.Current.RunMain(() =>
                {
                    this.btnFan.CanClick = true;
                });
            });
        }
 
        /// <summary>
        /// 发送开关命令
        /// </summary>
        private void SendSwitchComand()
        {
            this.btnPictrue.CanClick = false;
            this.btnSwitch.CanClick = false;
 
            //其他三个按钮的点击也要控制
            this.btnFan.CanClick = this.btnSwitch.IsSelected;
            this.btnMode.CanClick = this.btnSwitch.IsSelected;
            this.btnTime.CanClick = this.btnSwitch.IsSelected;
 
            string statu = this.btnSwitch.IsSelected == true ? "off" : "on";
            HdlThreadLogic.Current.RunThread(() =>
            {
                var dic = new Dictionary<string, string>();
                dic.Add(FunctionAttributeKey.OnOff, statu);
                Control.Ins.SendWriteCommand(this.device, dic, true);
                HdlThreadLogic.Current.RunMain(() =>
                {
                    this.btnPictrue.CanClick = true;
                    this.btnSwitch.CanClick = true;
                });
            });
        }
 
        /// <summary>
        /// 发送使能命令
        /// </summary>
        private void SendEnableComand(MostRightIconControl btnSwitch, string sendKey, string value)
        {
            btnSwitch.CanClick = false;
            HdlThreadLogic.Current.RunThread(() =>
            {
                var dic = new Dictionary<string, string>();
                dic.Add(sendKey, value);
                Control.Ins.SendWriteCommand(this.device, dic, true);
                HdlThreadLogic.Current.RunMain(() =>
                {
                    btnSwitch.CanClick = true;
                });
            });
        }
 
        #endregion
 
        #region ■ 刷新界面状态_______________________
 
        /// <summary>
        /// 刷新界面状态
        /// </summary>
        private void RefreshFormStatu()
        {
            //=======模式=======
            //强劲模式
            if (this.airCleanerData.Mode == "strong")
            {
                if (this.btnModeView.TextID != StringId.StrongMode)
                {
                    //相同不变更
                    this.btnMode.UnSelectedImagePath = "FunctionIcon/Electrical/Fan/ComfortableModeSelect.png";
                    this.btnModeView.TextID = StringId.StrongMode;
                }
            }
            //睡眠模式
            else if (this.airCleanerData.Mode == "sleep")
            {
                if (this.btnModeView.TextID != StringId.SleepMode)
                {
                    //相同不变更
                    this.btnMode.UnSelectedImagePath = "FunctionIcon/Electrical/Fan/SleepModeSelect.png";
                    this.btnModeView.TextID = StringId.SleepMode;
                }
            }
            //手动模式
            else if (this.airCleanerData.Mode == "manual")
            {
                if (this.btnModeView.TextID != StringId.HandMode)
                {
                    //相同不变更
                    this.btnMode.UnSelectedImagePath = "FunctionIcon/Electrical/Fan/HandModeSelect.png";
                    this.btnModeView.TextID = StringId.HandMode;
                }
            }
            //自动模式
            else
            {
                if (this.btnModeView.TextID != StringId.AutoMode)
                {
                    //相同不变更
                    this.btnMode.UnSelectedImagePath = "FunctionIcon/Electrical/Fan/AutoModeSelect.png";
                    this.btnModeView.TextID = StringId.AutoMode;
                }
            }
 
            //开关
            if (this.btnSwitch.IsSelected != this.airCleanerData.Open)
            {
                //相同不变更
                this.btnSwitch.IsSelected = this.airCleanerData.Open;
                this.btnPictrue.IsSelected = this.airCleanerData.Open;
                //其他三个按钮的点击也要控制
                this.btnFan.CanClick = this.airCleanerData.Open;
                this.btnMode.CanClick = this.airCleanerData.Open;
                this.btnTime.CanClick = this.airCleanerData.Open;
            }
 
            //=====风速=====
            //高档
            if (airCleanerData.Gear == "3")
            {
                if (this.btnFanView.TextID != StringId.HeightGear)
                {
                    //相同不变更
                    this.btnFan.UnSelectedImagePath = "FunctionIcon/Electrical/Fan/HeightGearSelect.png";
                    this.btnFanView.TextID = StringId.HeightGear;
                }
            }
            //中档
            else if (airCleanerData.Gear == "2")
            {
                if (this.btnFanView.TextID != StringId.MidGear)
                {
                    //相同不变更
                    this.btnFan.UnSelectedImagePath = "FunctionIcon/Electrical/Fan/MidGearSelect.png";
                    this.btnFanView.TextID = StringId.MidGear;
                }
            }
            //低档
            else
            {
                if (this.btnFanView.TextID != StringId.LowGear)
                {
                    //相同不变更
                    this.btnFan.UnSelectedImagePath = "FunctionIcon/Electrical/Fan/LowGearSelect.png";
                    this.btnFanView.TextID = StringId.LowGear;
                }
            }
 
            //定时
            if (airCleanerData.Timing == "1")
            {
                btnTimeView.Text = "1" + Language.StringByID(StringId.Hour1);
            }
            else if (airCleanerData.Timing == "2")
            {
                btnTimeView.Text = "2" + Language.StringByID(StringId.Hour1);
            }
            else if (airCleanerData.Timing == "3")
            {
                btnTimeView.Text = "4" + Language.StringByID(StringId.Hour1);
            }
            else if (airCleanerData.Timing == "4")
            {
                btnTimeView.Text = "8" + Language.StringByID(StringId.Hour1);
            }
            else
            {
                btnTimeView.Text = Language.StringByID(StringId.Timing);
            }
 
            //滤芯使用
            this.btnUsePersent.Text = Language.StringByID(StringId.UseOfFilterElement) + airCleanerData.FilterPersent + "%";
            //PM2.5
            this.btnPm25.Text = airCleanerData.PM25Value.ToString();
            //童锁
            if (this.btnLockSwitch.IsSelected != this.airCleanerData.Lock)
            {
                this.btnLockSwitch.IsSelected = this.airCleanerData.Lock;
            }
            //负离子
            if (this.btnAnionSwitch.IsSelected != this.airCleanerData.Anion)
            {
                this.btnAnionSwitch.IsSelected = this.airCleanerData.Anion;
            }
            //滤芯复位
            if (this.btnResetSwitch.IsSelected != this.airCleanerData.FilterReset)
            {
                this.btnResetSwitch.IsSelected = this.airCleanerData.FilterReset;
            }
        }
 
        #endregion
 
        #region ■ 一般方法___________________________
 
        /// <summary>
        /// 刷新当前设备的状态缓存
        /// </summary>
        private void RefreshNowDeviceStatuMemory(Function i_LocalDevice)
        {
            foreach (var data in i_LocalDevice.attributes)
            {
                //模式
                if (data.key == "mode") { this.airCleanerData.Mode = data.realValue; }
                //风速档位
                else if (data.key == "speed") { this.airCleanerData.Gear = data.realValue; }
                //开关
                else if (data.key == "on_off") { this.airCleanerData.Open = data.realValue.ToLower() == "on"; }
                //童锁
                else if (data.key == "lock") { this.airCleanerData.Lock = data.realValue.ToLower() == "true"; }
                //滤芯复位
                else if (data.key == "filter_reset") { this.airCleanerData.FilterReset = data.realValue.ToLower() == "true"; }
                //负离子
                else if (data.key == "anion") { this.airCleanerData.Anion = data.realValue.ToLower() == "true"; }
                //定时
                else if (data.key == "countdown")
                {
                    this.airCleanerData.Timing = data.realValue;
                    if (this.airCleanerData.Timing == "cancel")
                    {
                        this.airCleanerData.Timing = "0";
                    }
                }
                //空气质量
                else if (data.key == "pm25")
                {
                    var value = data.realValue;
                    if (value != string.Empty)
                    {
                        this.airCleanerData.PM25Value = Convert.ToInt32(value);
                    }
                }
                //滤芯使用率
                else if (data.key == "filter")
                {
                    var value = data.realValue;
                    if (value != string.Empty)
                    {
                        this.airCleanerData.FilterPersent = Convert.ToInt32(value);
                    }
                }
            }
        }
 
        #endregion
 
        #region ■ 结构体_____________________________
 
        /// <summary>
        /// 空气净化器的数据
        /// </summary>
        private class AirCleanerData
        {
            /// <summary>
            /// 是否打开
            /// </summary>
            public bool Open = true;
            /// <summary>
            /// 档位 1:低档 2:中档 3:高档
            /// </summary>
            public string Gear = "0";
            /// <summary>
            /// auto:自动  sleep:睡眠  manual:手动  strong:强烈
            /// </summary>
            public string Mode = string.Empty;
            /// <summary>
            /// cancel:取消 1:1小时 2:2小时 3:4小时 4:8小时
            /// </summary>
            public string Timing = "0";
            /// <summary>
            /// 童锁
            /// </summary>
            public bool Lock = false;
            /// <summary>
            /// 滤芯复位
            /// </summary>
            public bool FilterReset = false;
            /// <summary>
            /// 负离子
            /// </summary>
            public bool Anion = false;
            /// <summary>
            /// PM2.5的值
            /// </summary>
            public int PM25Value = 0;
            /// <summary>
            /// 滤芯使用率 0-100
            /// </summary>
            public int FilterPersent = 0;
        }
 
        #endregion
    }
}