黄学彪
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
using Shared.Common;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using ZigBee.Device;
 
namespace Shared.Phone.UserCenter.DeviceCurtain
{
    /// <summary>
    /// 开合帘的方向与限位的配置界面
    /// </summary>
    public class AutoOpenDirectionAndLimitSettionForm : EditorCommonForm
    {
        #region ■ 变量声明___________________________
 
        /// <summary>
        ///窗帘的回路
        /// </summary>
        private Rollershade curtainDevice = null;
        /// <summary>
        /// 窗帘数据
        /// </summary>
        private CurtainData curtainData = null;
        /// <summary>
        /// 接收开限位 false:没有接收到 true:已经接收到
        /// </summary>
        private bool receiveOpenlimit = false;
        /// <summary>
        /// 接收合限位 false:没有接收到 true:已经接收到
        /// </summary>
        private bool receiveCloseLimit = false;
        /// <summary>
        /// 发送区分 1:开限位 2:合限位
        /// </summary>
        private int sendDiv = 0;
        /// <summary>
        /// 是否备份窗帘数据
        /// </summary>
        private bool backupCurtainData = false;
        /// <summary>
        /// 列表控件
        /// </summary>
        private VerticalListControl listView = null;
        /// <summary>
        /// 开限位的进度条
        /// </summary>
        private SeekBarControl openSeekBar = null;
        /// <summary>
        /// 合限位的进度条
        /// </summary>
        private SeekBarControl closeSeekBar = null;
 
        #endregion
 
        #region ■ 初始化_____________________________
 
        /// <summary>
        /// 画面显示(底层会固定调用此方法,借以完成画面创建)
        /// </summary>
        /// <param name="i_listdevice">窗帘的回路</param>
        public void ShowForm(Rollershade i_CurtainDevice)
        {
            this.ScrollEnabled = false;
 
            this.curtainDevice = i_CurtainDevice;
 
            //设置标题信息
            base.SetTitleText(Language.StringByID(R.MyInternationalizationString.uDirectionAndLimit));
 
            HdlThreadLogic.Current.RunThread(() =>
            {
                //初始化中部控件
                this.InitMiddleFrame();
            });
        }
 
        /// <summary>
        /// 初始化中部信息
        /// </summary>
        private void InitMiddleFrame()
        {
            //获取设备初始数据
            var result = this.InitCurtainDefultData();
            if (result == false)
            {
                //显示重新加载的界面
                this.ShowReLoadView();
                return;
            }
            HdlThreadLogic.Current.RunMain(() =>
            {
                //清空bodyFrame
                bodyFrameLayout.BackgroundColor = UserCenterColor.Current.White;
                this.ClearBodyFrame();
 
                this.listView = new VerticalListControl(29);
                listView.Y = Application.GetRealHeight(-6);
                listView.Height = bodyFrameLayout.Height;
                bodyFrameLayout.AddChidren(listView);
 
                //导轨长度为0时
                if (curtainData.CurtainLength <= 0)
                {
                    //电机数据异常,确认已经安装导轨后,请重置电机
                    this.ShowMassage(ShowMsgType.Error, Language.StringByID(R.MyInternationalizationString.uCurtainDataIsErrorPleaseResetCurtain));
                    try
                    {
                        //设备异常补救 -> 添加重置电机行
                        this.AddElectricalMachineryRow();
                        return;
                    }
                    catch (Exception ex2) 
                    {
                        HdlLogLogic.Current.WriteLog(ex2, "开合帘补救异常1");
                        return;
                    }
                }
 
                try
                {
                    //添加方向行
                    this.AddDirectionRow();
                    //添加限位行
                    this.AddLimitRow();
                    //添加重置电机行
                    this.AddElectricalMachineryRow();
 
                    //限位数据接收
                    this.ReceiveLimitData();
                }
                catch (Exception ex)
                {
                    //Log出力
                    string msg = "当前激活的界面[" + HdlFormLogic.Current.NowActionFormID + "]";
                    HdlLogLogic.Current.WriteLog(ex, msg);
                    //电机数据异常,确认已经安装导轨后,请重置电机
                    this.ShowMassage(ShowMsgType.Error, Language.StringByID(R.MyInternationalizationString.uCurtainDataIsErrorPleaseResetCurtain));
                    try
                    {
                        this.listView.RemoveAll();
                        //设备异常补救 -> 添加重置电机行
                        this.AddElectricalMachineryRow();
                    }
                    catch (Exception ex2) { HdlLogLogic.Current.WriteLog(ex2, "开合帘补救异常2"); }
                }
            });
        }
 
        #endregion
 
        #region ■ 方向行_____________________________
 
        /// <summary>
        /// 添加方向行
        /// </summary>
        private void AddDirectionRow()
        {
            var rowDirection = new FrameRowControl(listView.rowSpace / 2);
            listView.AddChidren(rowDirection);
            //方向
            rowDirection.AddLeftCaption(Language.StringByID(R.MyInternationalizationString.uDirection), 600);
            //右箭头
            rowDirection.AddRightArrow();
            //状态
            var btnStatu = rowDirection.AddMostRightView("", 300);
            btnStatu.TextID = curtainData.Direction == false ? R.MyInternationalizationString.uForwardDirection : R.MyInternationalizationString.uReverseDirection;
            //底线
            rowDirection.AddBottomLine();
 
            int nowSelectNo = curtainData.Direction == false ? 0 : 1;
            rowDirection.ButtonClickEvent += (sender, e) =>
            {
                var listText = new List<string>();
                listText.Add(Language.StringByID(R.MyInternationalizationString.uForwardDirection));//正向
                listText.Add(Language.StringByID(R.MyInternationalizationString.uReverseDirection));//反向
 
                var form = new BottomItemSelectForm();
                form.AddForm(Language.StringByID(R.MyInternationalizationString.uDirectionSelect), listText, null, nowSelectNo);
                form.FinishSelectEvent += (index) =>
                {
                    //变更方向
                    var result = HdlDeviceCurtainLogic.Current.SetCurtainDirection(curtainDevice, index == 0 ? false : true);
                    if (result == false)
                    {
                        return;
                    }
                    nowSelectNo = index;
                    btnStatu.Text = listText[index];
                    curtainData.Direction = index == 0 ? false : true;
                };
            };
            //如果当前是展示模板,则不能编辑
            if (Common.Config.Instance.Home.IsShowTemplate == true)
            {
                rowDirection.CanClick = false;
            }
        }
 
        #endregion
 
        #region ■ 限位行_____________________________
 
        /// <summary>
        /// 添加限位行
        /// </summary>
        private void AddLimitRow()
        {
            var frameBack = new FrameLayout();
            frameBack.Height = Application.GetRealHeight(956);
 
            var rowLimit = new FrameRowControl(listView.rowSpace / 2);
            rowLimit.UseClickStatu = false;
            listView.AddChidren(rowLimit);
            //限位
            rowLimit.AddLeftCaption(Language.StringByID(R.MyInternationalizationString.uLimit), 600);
            //右箭头
            var btnRinght = rowLimit.AddMostRightEmptyIcon(58, 58);
            rowLimit.ChangedChidrenBindMode(btnRinght, ChidrenBindMode.NotBind);
            btnRinght.UseClickStatu = false;
            btnRinght.UnSelectedImagePath = "Item/RightNext.png";
            btnRinght.SelectedImagePath = "Item/Down.png";
            btnRinght.IsSelected = true;
            btnRinght.ButtonClickEvent += (sender, e) =>
            {
                btnRinght.IsSelected = !btnRinght.IsSelected;
                //展开折叠
                frameBack.Height = frameBack.Height > 10 ? 0 : Application.GetRealHeight(956);
            };
            //底线
            rowLimit.AddBottomLine();
 
            listView.AddChidren(frameBack);
            //添加开限位进度条
            this.AddOpenLimitProgress(frameBack);
            //添加合限位进度条
            this.AddCloseLimitProgress(frameBack);
        }
 
        #endregion
 
        #region ■ 开限位行___________________________
 
        /// <summary>
        /// 添加开限位进度条
        /// </summary>
        /// <param name="frameBack"></param>
        private void AddOpenLimitProgress(FrameLayout frameBack)
        {
            //开限位
            var btnProgressView = new NormalViewControl(200, 50, true);
            btnProgressView.X = HdlControlResourse.XXLeft;
            btnProgressView.Y = Application.GetRealHeight(78);
            btnProgressView.TextSize = 12;
            btnProgressView.TextColor = UserCenterColor.Current.TextGrayColor1;
            btnProgressView.TextID = R.MyInternationalizationString.uOpenLimit;
            frameBack.AddChidren(btnProgressView);
 
            int progressValue = (int)(curtainData.OpenLimitValue / (curtainData.CurtainLength * 1.0) * 100);
            //设置百分比的初始值
            curtainData.OpenLimitPersent = progressValue;
            var btnProgress1 = new NormalViewControl(200, 50, true);
            btnProgress1.X = Application.GetRealWidth(200);
            btnProgress1.Y = btnProgressView.Y;
            btnProgress1.TextSize = 12;
            btnProgress1.TextColor = UserCenterColor.Current.TextGrayColor1;
            btnProgress1.Text = progressValue + "%";
            frameBack.AddChidren(btnProgress1);
            //进度条
            this.openSeekBar = new SeekBarControl(965);
            openSeekBar.Y = btnProgressView.Bottom + Application.GetRealHeight(46);
            openSeekBar.ProgressBarColor = 0xff288bfd;
            openSeekBar.Progress = progressValue;
            frameBack.AddChidren(openSeekBar);
 
            var btnTemp1 = new NormalViewControl(200, 50, true);
            btnTemp1.X = HdlControlResourse.XXLeft;
            btnTemp1.Y = btnProgressView.Bottom + Application.GetRealHeight(115);
            btnTemp1.TextSize = 12;
            btnTemp1.TextColor = UserCenterColor.Current.TextGrayColor3;
            btnTemp1.Text = "0%";
            frameBack.AddChidren(btnTemp1);
            var btnTemp2 = new NormalViewControl(200, 50, true);
            btnTemp2.X = frameBack.Width - Application.GetRealWidth(200 + 50);
            btnTemp2.Y = btnTemp1.Y;
            btnTemp2.TextAlignment = TextAlignment.CenterRight;
            btnTemp2.TextSize = 12;
            btnTemp2.TextColor = UserCenterColor.Current.TextGrayColor3;
            btnTemp2.Text = "100%";
            frameBack.AddChidren(btnTemp2);
            //线
            var btnLine = new NormalViewControl(frameBack.Width - HdlControlResourse.XXLeft * 2, HdlControlResourse.BottomLineHeight, false);
            btnLine.X = HdlControlResourse.XXLeft;
            btnLine.Y = btnTemp2.Bottom + Application.GetRealHeight(156);
            btnLine.BackgroundColor = UserCenterColor.Current.ButtomLine;
            frameBack.AddChidren(btnLine);
 
            //减号
            var btnMinus = new IconViewControl(104);
            btnMinus.UseClickStatu = true;
            btnMinus.X = Application.GetRealWidth(847);
            btnMinus.Y = Application.GetRealHeight(46);
            btnMinus.UnSelectedImagePath = "Item/MinusSign2.png";
            btnMinus.SelectedImagePath = "Item/MinusSign2Selected.png";
            frameBack.AddChidren(btnMinus);
            btnMinus.ButtonClickEvent += (sender, e) =>
            {
                if (openSeekBar.Progress <= 0)
                {
                    return;
                }
                openSeekBar.Progress -= 5;
                openSeekBar.ProgressChangedEvent(1, openSeekBar.Progress);
            };
 
            //加号
            var btnPlus = new IconViewControl(104);
            btnPlus.UseClickStatu = true;
            btnPlus.X = btnMinus.Right;
            btnPlus.Y = btnMinus.Y;
            btnPlus.UnSelectedImagePath = "Item/PlusSign2.png";
            btnPlus.SelectedImagePath = "Item/PlusSign2Selected.png";
            frameBack.AddChidren(btnPlus);
            btnPlus.ButtonClickEvent += (sender, e) =>
            {
                if (openSeekBar.Progress >= 100)
                {
                    return;
                }
                openSeekBar.Progress += 5;
                openSeekBar.ProgressChangedEvent(1, openSeekBar.Progress);
            };
 
            //保存
            var btnSave = new NormalViewControl(150, 60, true);
            btnSave.X = Application.GetRealWidth(906);
            btnSave.Y = btnTemp1.Bottom + Application.GetRealHeight(68);
            btnSave.TextAlignment = TextAlignment.Center;
            btnSave.TextID = R.MyInternationalizationString.uSave;
            btnSave.TextColor = UserCenterColor.Current.TextOrangeColor;
            frameBack.AddChidren(btnSave);
            btnSave.ButtonClickEvent += (sender, e) =>
            {
                //2020.05.17:追加虚拟住宅可以直接点击
                if (this.receiveOpenlimit == true || Common.Config.Instance.Home.IsVirtually == true)
                {
                    //确认开限位点
                    this.SaveOpenLimit();
                }
            };
 
            int oldProValue = curtainData.OpenLimitPersent;
            openSeekBar.ProgressChangedEvent += (div, value) =>
            {
                //开限位不能大于合限位
                if (value > closeSeekBar.Progress)
                {
                    openSeekBar.Progress = closeSeekBar.Progress;
                    return;
                }
                btnProgress1.Text = value + "%";
                //数据变更,百分比
                curtainData.OpenLimitPersent = value;
            };
            //如果当前是展示模板,则不能编辑
            if (Common.Config.Instance.Home.IsShowTemplate == true)
            {
                openSeekBar.Enable = false;
                btnMinus.CanClick = false;
                btnPlus.CanClick = false;
                btnSave.CanClick = false;
            }
 
            //虚拟住宅不需要监听
            if (Common.Config.Instance.Home.IsVirtually == true)
            {
                return;
            }
 
            HdlThreadLogic.Current.RunThread(async () =>
            {
                while (openSeekBar.Parent != null)
                {
                    int nowValue = curtainData.OpenLimitPersent;
                    if (oldProValue == nowValue)
                    {
                        //值不等才处理
                        await Task.Delay(500);
                        continue;
                    }
                    oldProValue = nowValue;
 
                    //将窗帘调整到指定百分比
                    this.sendDiv = 1;
                    curtainDevice.WcdGoToTiltValue(nowValue);
                }
            });
        }
 
        /// <summary>
        /// 确认开限位点
        /// </summary>
        private void SaveOpenLimit()
        {
            //确认当前位置为开限位?
            string msg = Language.StringByID(R.MyInternationalizationString.uCommitCurtainOpenLimitMsg);
            this.ShowMassage(ShowMsgType.Confirm, msg, () =>
            {
                decimal openValue = ((decimal)curtainData.OpenLimitPersent / 100) * curtainData.CurtainLength;
                decimal closeValue = ((decimal)curtainData.CloseLimitPersent / 100) * curtainData.CurtainLength;
                if (openValue < 0) { openValue = 0; }
                if (closeValue < 0) { closeValue = curtainData.CurtainLength; }
                //执行确认及覆盖上限位点
                var result = HdlDeviceCurtainLogic.Current.SetAutoOpenCurtainLimitPoint(curtainDevice, (int)openValue, (int)closeValue, curtainData.CurtainLength);
                if (result == true)
                {
                    this.receiveOpenlimit = false;
                }
            });
        }
 
        #endregion
 
        #region ■ 合限位行___________________________
 
        /// <summary>
        /// 添加合限位进度条
        /// </summary>
        /// <param name="frameBack"></param>
        private void AddCloseLimitProgress(FrameLayout frameBack)
        {
            //合限位
            var btnProgressView = new NormalViewControl(200, 50, true);
            btnProgressView.X = HdlControlResourse.XXLeft;
            btnProgressView.Y = Application.GetRealHeight(536);
            btnProgressView.TextSize = 12;
            btnProgressView.TextColor = UserCenterColor.Current.TextGrayColor1;
            btnProgressView.TextID = R.MyInternationalizationString.uCloseLimit;
            frameBack.AddChidren(btnProgressView);
 
            int progressValue = (int)(curtainData.CloseLimitValue / (curtainData.CurtainLength * 1.0) * 100);
            //设置百分比的初始值
            curtainData.CloseLimitPersent = progressValue;
            var btnProgress1 = new NormalViewControl(200, 50, true);
            btnProgress1.X = Application.GetRealWidth(200);
            btnProgress1.Y = btnProgressView.Y;
            btnProgress1.TextSize = 12;
            btnProgress1.TextColor = UserCenterColor.Current.TextGrayColor1;
            btnProgress1.Text = progressValue + "%";
            frameBack.AddChidren(btnProgress1);
            //进度条
            this.closeSeekBar = new SeekBarControl(965);
            closeSeekBar.Y = btnProgressView.Bottom + Application.GetRealHeight(46);
            closeSeekBar.ProgressBarColor = 0xff288bfd;
            closeSeekBar.Progress = progressValue;
            frameBack.AddChidren(closeSeekBar);
 
            var btnTemp1 = new NormalViewControl(200, 50, true);
            btnTemp1.X = HdlControlResourse.XXLeft;
            btnTemp1.Y = btnProgressView.Bottom + Application.GetRealHeight(115);
            btnTemp1.TextSize = 12;
            btnTemp1.TextColor = UserCenterColor.Current.TextGrayColor3;
            btnTemp1.Text = "0%";
            frameBack.AddChidren(btnTemp1);
            var btnTemp2 = new NormalViewControl(200, 50, true);
            btnTemp2.X = frameBack.Width - Application.GetRealWidth(200 + 50);
            btnTemp2.Y = btnTemp1.Y;
            btnTemp2.TextAlignment = TextAlignment.CenterRight;
            btnTemp2.TextSize = 12;
            btnTemp2.TextColor = UserCenterColor.Current.TextGrayColor3;
            btnTemp2.Text = "100%";
            frameBack.AddChidren(btnTemp2);
            //线
            var btnLine = new NormalViewControl(frameBack.Width - HdlControlResourse.XXLeft * 2, HdlControlResourse.BottomLineHeight, false);
            btnLine.X = HdlControlResourse.XXLeft;
            btnLine.Y = btnTemp2.Bottom + Application.GetRealHeight(156);
            btnLine.BackgroundColor = UserCenterColor.Current.ButtomLine;
            frameBack.AddChidren(btnLine);
 
            //减号
            var btnMinus = new IconViewControl(104);
            btnMinus.UseClickStatu = true;
            btnMinus.X = Application.GetRealWidth(847);
            btnMinus.Y = Application.GetRealHeight(504);
            btnMinus.UnSelectedImagePath = "Item/MinusSign2.png";
            btnMinus.SelectedImagePath = "Item/MinusSign2Selected.png";
            frameBack.AddChidren(btnMinus);
            btnMinus.ButtonClickEvent += (sender, e) =>
            {
                if (closeSeekBar.Progress <= 0)
                {
                    return;
                }
                closeSeekBar.Progress -= 5;
                closeSeekBar.ProgressChangedEvent(1, closeSeekBar.Progress);
            };
 
            //加号
            var btnPlus = new IconViewControl(104);
            btnPlus.UseClickStatu = true;
            btnPlus.X = btnMinus.Right;
            btnPlus.Y = btnMinus.Y;
            btnPlus.UnSelectedImagePath = "Item/PlusSign2.png";
            btnPlus.SelectedImagePath = "Item/PlusSign2Selected.png";
            frameBack.AddChidren(btnPlus);
            btnPlus.ButtonClickEvent += (sender, e) =>
            {
                if (closeSeekBar.Progress >= 100)
                {
                    return;
                }
                closeSeekBar.Progress += 5;
                closeSeekBar.ProgressChangedEvent(1, closeSeekBar.Progress);
            };
 
            //保存
            var btnSave = new NormalViewControl(150, 60, true);
            btnSave.X = Application.GetRealWidth(906);
            btnSave.Y = btnTemp1.Bottom + Application.GetRealHeight(68);
            btnSave.TextAlignment = TextAlignment.Center;
            btnSave.TextID = R.MyInternationalizationString.uSave;
            btnSave.TextColor = UserCenterColor.Current.TextOrangeColor;
            frameBack.AddChidren(btnSave);
            btnSave.ButtonClickEvent += (sender, e) =>
            {
                //2020.05.17:追加虚拟住宅可以直接点击
                if (this.receiveCloseLimit == true || Common.Config.Instance.Home.IsVirtually == true)
                {
                    //保存合限位点
                    this.SaveCloseLimit();
                }
            };
 
            int oldProValue = curtainData.CloseLimitPersent;
            closeSeekBar.ProgressChangedEvent += (div, value) =>
            {
                if (value < curtainData.OpenLimitPersent)
                {
                    //合限位不能小于合限位
                    closeSeekBar.Progress = openSeekBar.Progress;
                    return;
                }
                btnProgress1.Text = value + "%";
                //数据变更,百分比
                curtainData.CloseLimitPersent = value;
            };
            //如果当前是展示模板,则不能编辑
            if (Common.Config.Instance.Home.IsShowTemplate == true)
            {
                closeSeekBar.Enable = false;
                btnMinus.CanClick = false;
                btnPlus.CanClick = false;
                btnSave.CanClick = false;
            }
            //虚拟住宅不需要监听
            if (Common.Config.Instance.Home.IsVirtually == true)
            {
                return;
            }
 
            HdlThreadLogic.Current.RunThread(async () =>
            {
                while (closeSeekBar.Parent != null)
                {
                    int nowValue = curtainData.CloseLimitPersent;
                    if (oldProValue == nowValue)
                    {
                        //值不等才处理
                        await Task.Delay(500);
                        continue;
                    }
                    oldProValue = nowValue;
 
                    //将窗帘调整到指定百分比
                    this.sendDiv = 2;
                    curtainDevice.WcdGoToTiltValue(nowValue);
                }
            });
        }
 
        /// <summary>
        /// 保存合限位点
        /// </summary>
        private void SaveCloseLimit()
        {
            //确认当前位置为合限位?
            string msg = Language.StringByID(R.MyInternationalizationString.uCommitCurtainCloseLimitMsg);
            this.ShowMassage(ShowMsgType.Confirm, msg, () =>
            {
                decimal openValue = ((decimal)curtainData.OpenLimitPersent / 100) * curtainData.CurtainLength;
                decimal closeValue = ((decimal)curtainData.CloseLimitPersent / 100) * curtainData.CurtainLength;
                if (openValue < 0) { openValue = 0; }
                if (closeValue < 0) { closeValue = curtainData.CurtainLength; }
                //执行确认及覆盖上限位点
                var result = HdlDeviceCurtainLogic.Current.SetAutoOpenCurtainLimitPoint(curtainDevice, (int)openValue, (int)closeValue, curtainData.CurtainLength);
 
                if (result == true)
                {
                    this.receiveCloseLimit = false;
                }
            });
        }
 
        #endregion
 
        #region ■ 重置电机___________________________
 
        /// <summary>
        /// 添加重置电机行
        /// </summary>
        private void AddElectricalMachineryRow()
        {
            var rowReset = new FrameRowControl(listView.rowSpace / 2);
            listView.AddChidren(rowReset);
            //重置电机
            rowReset.AddLeftCaption(Language.StringByID(R.MyInternationalizationString.uResetElectricalMachinery), 600);
            //底线
            rowReset.AddBottomLine();
            rowReset.ButtonClickEvent += (sender, e) =>
            {
                //如果当前是虚拟住宅
                if (Common.Config.Instance.Home.IsVirtually == true)
                {
                    return;
                }
                //重置电机将初始化{0}方向与限位设置,确认继续?
                string msg = Language.StringByID(R.MyInternationalizationString.uResetElectricalMachineryMsg);
                msg = msg.Replace("{0}", "\r\n");
                this.ShowMassage(ShowMsgType.Confirm, msg, () =>
                {
                    //开启进度条
                    ProgressFormBar.Current.Start();
                    //正在重置电机
                    ProgressFormBar.Current.SetMsg(Language.StringByID(R.MyInternationalizationString.uElectricalMachineryResetting));
                    //重置窗帘
                    HdlThreadLogic.Current.RunThread(async () =>
                    {
                        var result = await HdlDeviceCurtainLogic.Current.RestoreCurtain(curtainDevice);
                        if (result == false)
                        {
                            //关闭进度条
                            ProgressFormBar.Current.Close();
                            return;
                        }
 
                        //每10的长度大概是2秒,多预留1次出来
                        int waitCount = ((curtainData.CurtainLength / 10) + 1) * 3;
                        if (waitCount < 12)
                        {
                            waitCount = 12;
                        }
 
                        int timeCount = 0;
                        while (timeCount <= waitCount)
                        {
                            //进度条值
                            ProgressFormBar.Current.SetValue(timeCount, waitCount);
                            timeCount++;
                            System.Threading.Thread.Sleep(1000);
                        }
                        //关闭进度条
                        ProgressFormBar.Current.Close();
 
                        //获取数据后,备份窗帘数据
                        this.backupCurtainData = true;
                        //重新初始化界面
                        this.InitMiddleFrame();
                    });
                });
            };
        }
 
        #endregion
 
        #region ■ 初始化窗帘数据_____________________
 
        /// <summary>
        /// 初始化窗帘数据
        /// </summary>
        /// <returns></returns>
        private bool InitCurtainDefultData()
        {
            this.curtainData = new CurtainData();
            this.receiveOpenlimit = false;
            this.receiveCloseLimit = false;
            this.sendDiv = 0;
 
            //如果当前是虚拟住宅
            if (Common.Config.Instance.Home.IsVirtually == true)
            {
                var data = HdlTemplateDeviceDataLogic.Current.GetCurtainLimitPoint(curtainDevice);
                curtainData.Direction = data.Direction;
                curtainData.CurtainLength = data.curtainLength;
                curtainData.OpenLimitValue = data.upLimit;
                curtainData.CloseLimitValue = data.downLimit;
                return true;
            }
 
            //开启进度条
            this.ShowProgressBar();
 
            int receiptDataCount = 0;
            string mainkeys = HdlDeviceCommonLogic.Current.GetDeviceMainKeys(curtainDevice);
            HdlGatewayReceiveLogic.Current.AddAttributeEvent("CurtainDeviceAttribute", ReceiveComandDiv.A设备属性上报, (device) =>
            {
                string checkKey = HdlDeviceCommonLogic.Current.GetDeviceMainKeys(device);
                if (mainkeys != checkKey || device.DeviceStatusReport.CluterID != 258)
                {
                    return;
                }
                foreach (var attriBute in device.DeviceStatusReport.AttriBute)
                {
                    if (attriBute.AttributeId == 23)
                    {
                        //开合帘方向
                        if (0 < (attriBute.AttriButeData & 0x01))
                        {
                            //反向
                            curtainData.Direction = true;
                        }
                        else
                        {
                            //正向
                            curtainData.Direction = false;
                        }
                        receiptDataCount++;
                    }
                    else if (attriBute.AttributeId == 1)
                    {
                        //窗帘总长
                        curtainData.CurtainLength = attriBute.AttriButeData;
                        receiptDataCount++;
                    }
                    else if (attriBute.AttributeId == 16)
                    {
                        //开限位
                        curtainData.OpenLimitValue = attriBute.AttriButeData;
                        receiptDataCount++;
                    }
                    else if (attriBute.AttributeId == 17)
                    {
                        //合限位
                        curtainData.CloseLimitValue = attriBute.AttriButeData;
                        receiptDataCount++;
                    }
                }
            });
            //发送获取窗帘限位配置的命令
            HdlDeviceCurtainLogic.Current.SetGetCurtainLimitSettionComand(curtainDevice);
 
            int timeCount = 30;
            while (receiptDataCount != 4 && timeCount >= 0)
            {
                System.Threading.Thread.Sleep(100);
                timeCount--;
            }
            //关闭进度条
            this.CloseProgressBar();
 
            if (timeCount <= 0)
            {
                //获取窗帘方向与限位设置失败
                string msg = Language.StringByID(R.MyInternationalizationString.uGetCurtainDirectionAndLimitSettionFail);
                //拼接上【网关回复超时】的Msg
                msg = HdlCommonLogic.Current.CombineGatewayTimeOutMsg(msg, null, "回复超时");
                this.ShowMassage(ShowMsgType.Tip, msg);
                return false;
            }
            //移除监听
            HdlGatewayReceiveLogic.Current.RemoveEvent("CurtainDeviceAttribute");
 
            return true;
        }
 
        #endregion
 
        #region ■ 限位数据接收_______________________
 
        /// <summary>
        /// 限位数据接收
        /// </summary>
        private void ReceiveLimitData()
        {
            //如果当前是展示模板,则需要处理
            if (Common.Config.Instance.Home.IsShowTemplate == true)
            {
                return;
            }
            if (HdlGatewayReceiveLogic.Current.IsEsixt("ReceiveLimitData") == true)
            {
                HdlGatewayReceiveLogic.Current.RemoveEvent("ReceiveLimitData");
            }
            string mainkeys = HdlDeviceCommonLogic.Current.GetDeviceMainKeys(curtainDevice);
            HdlGatewayReceiveLogic.Current.AddAttributeEvent("ReceiveLimitData", ReceiveComandDiv.A设备属性上报, (device) =>
            {
                string checkKey = HdlDeviceCommonLogic.Current.GetDeviceMainKeys(device);
                if (mainkeys != checkKey || device.DeviceStatusReport.CluterID != 258)
                {
                    return;
                }
                foreach (var attriBute in device.DeviceStatusReport.AttriBute)
                {
                    //窗帘百分比推送
                    if (attriBute.AttributeId == 8)
                    {
                        //开限位
                        if (sendDiv == 1)
                        {
                            receiveOpenlimit = true;
                        }
                        //合限位
                        else if (sendDiv == 2)
                        {
                            receiveCloseLimit = true;
                        }
                    }
                }
            });
        }
 
        #endregion
 
        #region ■ 界面关闭___________________________
 
        /// <summary>
        /// 界面关闭
        /// </summary>
        public override void CloseFormBefore()
        {
            HdlGatewayReceiveLogic.Current.RemoveEvent("CurtainDeviceAttribute");
            HdlGatewayReceiveLogic.Current.RemoveEvent("ReceiveLimitData");
 
            base.CloseFormBefore();
        }
 
        #endregion
 
        #region ■ 结构体_____________________________
 
        /// <summary>
        /// 窗帘数据
        /// </summary>
        private class CurtainData
        {
            /// <summary>
            /// false:电机方向正向;true:电机方向反向
            /// </summary>
            public bool Direction = false;
            /// <summary>
            /// 开限位的值
            /// </summary>
            public int OpenLimitValue = -1;
            /// <summary>
            /// 开限位的百分比
            /// </summary>
            public int OpenLimitPersent = -1;
            /// <summary>
            /// 合限位的值
            /// </summary>
            public int CloseLimitValue = -1;
            /// <summary>
            /// 合限位的百分比
            /// </summary>
            public int CloseLimitPersent = -1;
            /// <summary>
            /// 窗帘总长
            /// </summary>
            public int CurtainLength = -1;
        }
 
        #endregion
    }
}