黄学彪
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
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 SiphonateDirectionAndLimitSettionForm : EditorCommonForm
    {
        #region ■ 变量声明___________________________
 
        /// <summary>
        ///窗帘的回路
        /// </summary>
        private Rollershade curtainDevice = null;
        /// <summary>
        /// 窗帘数据
        /// </summary>
        private CurtainData curtainData = null;
        /// <summary>
        /// 列表控件
        /// </summary>
        private VerticalListControl listView = null;
 
        #endregion
 
        #region ■ 初始化_____________________________
 
        /// <summary>
        /// 画面显示(底层会固定调用此方法,借以完成画面创建)
        /// </summary>
        /// <param name="i_listdevice">窗帘的回路</param>
        public void ShowForm(Rollershade i_CurtainDevice)
        {
            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);
 
                //添加方向行
                this.AddDirectionRow();
                //添加限位行
                this.AddLimitRow();
                //添加重置电机行
                this.AddElectricalMachineryRow();
                //保存
                var btnSave = new BottomClickButton();
                btnSave.TextID = R.MyInternationalizationString.uSave;
                bodyFrameLayout.AddChidren(btnSave);
                btnSave.ButtonClickEvent += (sender, e) =>
                {
                    //这个保存没啥意义
                    this.CloseForm();
                };
            });
        }
 
        #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;
                };
            };
        }
 
        #endregion
 
        #region ■ 限位行_____________________________
 
        /// <summary>
        /// 添加限位行
        /// </summary>
        private void AddLimitRow()
        {
            var frameBack = new FrameLayout();
            frameBack.Height = Application.GetRealHeight(714);
 
            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(714);
            };
            //底线
            rowLimit.AddBottomLine();
 
            listView.AddChidren(frameBack);
            //添加下限位控件
            this.AddDownLimitControl(frameBack);
            //添加开限位控件
            this.AddUpLimitControl(frameBack);
        }
 
        /// <summary>
        /// 添加下限位控件
        /// </summary>
        /// <param name="frameBack"></param>
        private void AddDownLimitControl(FrameLayout frameBack)
        {
            var frameIcon = new FrameLayout();
            frameIcon.X = Application.GetRealWidth(228);
            frameIcon.Y = Application.GetRealHeight(121);
            frameIcon.Width = this.GetPictrueRealSize(265);
            frameIcon.Height= this.GetPictrueRealSize(495);
            frameIcon.BackgroundImagePath = "Item/DeviceLimitGround.png";
            frameBack.AddChidren(frameIcon);
 
            var frameIconback = new FrameLayoutStatuControl();
            frameIconback.Height = this.GetPictrueRealSize(144);
            frameIconback.Width = this.GetPictrueRealSize(144);
            frameIconback.Radius = (uint)this.GetPictrueRealSize(144) / 2;
            frameIconback.BackgroundColor = 0xffeff2fb;
            frameIconback.Gravity = Gravity.CenterHorizontal;
            frameIconback.Y = this.GetPictrueRealSize(35);
            frameIcon.AddChidren(frameIconback);
            var btnIcon = new NormalViewControl(this.GetPictrueRealSize(69), this.GetPictrueRealSize(35), false);
            btnIcon.UnSelectedImagePath = "Item/DownTriangle.png";
            btnIcon.Gravity = Gravity.Center;
            frameIconback.AddChidren(btnIcon, ChidrenBindMode.BindEvent);
 
            var frameText = new FrameLayoutStatuControl();
            frameText.Y= this.GetPictrueRealSize(265);
            frameText.Height = this.GetPictrueRealSize(120);
            frameIcon.AddChidren(frameText);
 
            //确定
            var btnOk = new NormalViewControl(frameIcon.Width, this.GetPictrueRealSize(60), false);
            btnOk.TextID = R.MyInternationalizationString.uConfirm1;
            btnOk.TextAlignment = TextAlignment.Center;
            btnOk.TextColor = UserCenterColor.Current.TextOrangeColor;
            frameText.AddChidren(btnOk, ChidrenBindMode.BindEvent);
            //底线
            var btnLine1 = new NormalViewControl(this.GetPictrueRealSize(100), HdlControlResourse.BottomLineHeight, false);
            btnLine1.BackgroundColor = UserCenterColor.Current.TextOrangeColor;
            btnLine1.Gravity = Gravity.CenterHorizontal;
            btnLine1.Y = btnOk.Bottom - this.GetPictrueRealSize(8);
            frameText.AddChidren(btnLine1);
 
            //下限位
            var btnDown = new NormalViewControl(frameIcon.Width, this.GetPictrueRealSize(60), false);
            btnDown.TextID = R.MyInternationalizationString.uDownLimit;
            btnDown.Y = btnOk.Bottom;
            btnDown.TextAlignment = TextAlignment.Center;
            btnDown.TextColor = UserCenterColor.Current.TextOrangeColor;
            frameText.AddChidren(btnDown, ChidrenBindMode.BindEvent);
 
            //底线
            var btnLine2 = new NormalViewControl(this.GetPictrueRealSize(124), HdlControlResourse.BottomLineHeight, false);
            btnLine2.BackgroundColor = UserCenterColor.Current.TextOrangeColor;
            btnLine2.Gravity = Gravity.CenterHorizontal;
            btnLine2.Y = btnDown.Bottom - this.GetPictrueRealSize(8);
            frameText.AddChidren(btnLine2);
 
            //图标点击
            frameIconback.ButtonClickEvent += (sender, e) =>
            {
                curtainDevice.CurtainUpDownStopControl(1);
            };
            //展示模板或者虚拟住宅,则无效
            if (Config.Instance.Home.IsShowTemplate == true || Config.Instance.Home.IsVirtually == true)
            {
                frameIconback.CanClick = false;
            }
            //重写控件点击效果
            frameIconback.SelectStatuEvent += (select) =>
            {
                if (select == true)
                {
                    frameIconback.BackgroundColor = 0xfffef1ed;
                }
                else
                {
                    frameIconback.BackgroundColor = 0xffeff2fb;
                }
            };
 
            //限位确定
            frameText.ButtonClickEvent += (sender, e) =>
            {
                //确认当前位置为下限位?
                string msg = Language.StringByID(R.MyInternationalizationString.uCommitCurtainDownLimitMsg);
                this.ShowMassage(ShowMsgType.Confirm, msg, async () =>
                {
                    //执行确定及覆盖
                    await HdlDeviceCurtainLogic.Current.CommitCurtainLimitPoint(curtainDevice, Rollershade.CurtainPrivateInstalledLimi.DownLimit, -1, -1);
                });
            };
            //展示模板或者虚拟住宅,则无效
            if (Config.Instance.Home.IsShowTemplate == true || Config.Instance.Home.IsVirtually == true)
            {
                frameText.CanClick = false;
            }
            //重写控件点击效果
            frameText.SelectStatuEvent += (select) =>
            {
                if (select == true)
                {
                    frameIconback.BackgroundColor = UserCenterColor.Current.White;
                    btnOk.TextColor = UserCenterColor.Current.White;
                    btnDown.TextColor = UserCenterColor.Current.White;
                    frameIcon.BackgroundImagePath = "Item/DeviceLimitGroundSelected.png";
                }
                else
                {
                    frameIconback.BackgroundColor = 0xffeff2fb;
                    btnOk.TextColor = UserCenterColor.Current.TextOrangeColor;
                    btnDown.TextColor = UserCenterColor.Current.TextOrangeColor;
                    frameIcon.BackgroundImagePath = "Item/DeviceLimitGround.png";
                }
            };
        }
 
        /// <summary>
        /// 添加上限位控件
        /// </summary>
        /// <param name="frameBack"></param>
        private void AddUpLimitControl(FrameLayout frameBack)
        {
            var frameIcon = new FrameLayout();
            frameIcon.X = Application.GetRealWidth(619);
            frameIcon.Y = Application.GetRealHeight(121);
            frameIcon.Width = this.GetPictrueRealSize(265);
            frameIcon.Height = this.GetPictrueRealSize(495);
            frameIcon.BackgroundImagePath = "Item/DeviceLimitGround.png";
            frameBack.AddChidren(frameIcon);
 
            var frameIconback = new FrameLayoutStatuControl();
            frameIconback.Height = this.GetPictrueRealSize(144);
            frameIconback.Width = this.GetPictrueRealSize(144);
            frameIconback.Radius = (uint)this.GetPictrueRealSize(144) / 2;
            frameIconback.BackgroundColor = 0xffeff2fb;
            frameIconback.Gravity = Gravity.CenterHorizontal;
            frameIconback.Y = this.GetPictrueRealSize(35);
            frameIcon.AddChidren(frameIconback);
            var btnIcon = new NormalViewControl(this.GetPictrueRealSize(69), this.GetPictrueRealSize(35), false);
            btnIcon.UnSelectedImagePath = "Item/UpTriangle.png";
            btnIcon.Gravity = Gravity.Center;
            frameIconback.AddChidren(btnIcon, ChidrenBindMode.BindEvent);
 
            var frameText = new FrameLayoutStatuControl();
            frameText.Y = this.GetPictrueRealSize(265);
            frameText.Height = this.GetPictrueRealSize(120);
            frameIcon.AddChidren(frameText);
 
            //确定
            var btnOk = new NormalViewControl(frameIcon.Width, this.GetPictrueRealSize(60), false);
            btnOk.TextID = R.MyInternationalizationString.uConfirm1;
            btnOk.TextAlignment = TextAlignment.Center;
            btnOk.TextColor = UserCenterColor.Current.TextOrangeColor;
            frameText.AddChidren(btnOk, ChidrenBindMode.BindEvent);
            //底线
            var btnLine1 = new NormalViewControl(this.GetPictrueRealSize(100), HdlControlResourse.BottomLineHeight, false);
            btnLine1.BackgroundColor = UserCenterColor.Current.TextOrangeColor;
            btnLine1.Gravity = Gravity.CenterHorizontal;
            btnLine1.Y = btnOk.Bottom - this.GetPictrueRealSize(8);
            frameText.AddChidren(btnLine1);
 
            //上限位
            var btnDown = new NormalViewControl(frameIcon.Width, this.GetPictrueRealSize(60), false);
            btnDown.TextID = R.MyInternationalizationString.uUpLimit;
            btnDown.Y = btnOk.Bottom;
            btnDown.TextAlignment = TextAlignment.Center;
            btnDown.TextColor = UserCenterColor.Current.TextOrangeColor;
            frameText.AddChidren(btnDown, ChidrenBindMode.BindEvent);
 
            //底线
            var btnLine2 = new NormalViewControl(this.GetPictrueRealSize(124), HdlControlResourse.BottomLineHeight, false);
            btnLine2.BackgroundColor = UserCenterColor.Current.TextOrangeColor;
            btnLine2.Gravity = Gravity.CenterHorizontal;
            btnLine2.Y = btnDown.Bottom - this.GetPictrueRealSize(8);
            frameText.AddChidren(btnLine2);
 
            //图标点击
            frameIconback.ButtonClickEvent += (sender, e) =>
            {
                curtainDevice.CurtainUpDownStopControl(0);
            };
            //展示模板或者虚拟住宅,则无效
            if (Config.Instance.Home.IsShowTemplate == true || Config.Instance.Home.IsVirtually == true)
            {
                frameIconback.CanClick = false;
            }
            //重写控件点击效果
            frameIconback.SelectStatuEvent += (select) =>
            {
                if (select == true)
                {
                    frameIconback.BackgroundColor = 0xfffef1ed;
                }
                else
                {
                    frameIconback.BackgroundColor = 0xffeff2fb;
                }
            };
 
            //限位确定
            frameText.ButtonClickEvent += (sender, e) =>
            {
                //确认当前位置为上限位?
                string msg = Language.StringByID(R.MyInternationalizationString.uCommitCurtainUpLimitMsg);
                this.ShowMassage(ShowMsgType.Confirm, msg, async () =>
                {
                    //执行确定及覆盖
                    await HdlDeviceCurtainLogic.Current.CommitCurtainLimitPoint(curtainDevice, Rollershade.CurtainPrivateInstalledLimi.UpLimit, -1, -1);
                });
            };
            //展示模板或者虚拟住宅,则无效
            if (Config.Instance.Home.IsShowTemplate == true || Config.Instance.Home.IsVirtually == true)
            {
                frameText.CanClick = false;
            }
            //重写控件点击效果
            frameText.SelectStatuEvent += (select) =>
            {
                if (select == true)
                {
                    frameIconback.BackgroundColor = UserCenterColor.Current.White;
                    btnOk.TextColor = UserCenterColor.Current.White;
                    btnDown.TextColor = UserCenterColor.Current.White;
                    frameIcon.BackgroundImagePath = "Item/DeviceLimitGroundSelected.png";
                }
                else
                {
                    frameIconback.BackgroundColor = 0xffeff2fb;
                    btnOk.TextColor = UserCenterColor.Current.TextOrangeColor;
                    btnDown.TextColor = UserCenterColor.Current.TextOrangeColor;
                    frameIcon.BackgroundImagePath = "Item/DeviceLimitGround.png";
                }
            };
        }
 
        #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) =>
            {
                //重置电机将初始化{0}方向与限位设置,确认继续?
                string msg = Language.StringByID(R.MyInternationalizationString.uResetElectricalMachineryMsg);
                msg = msg.Replace("{0}", "\r\n");
                this.ShowMassage(ShowMsgType.Confirm, msg, () =>
                {
                    HdlThreadLogic.Current.RunThread(async () =>
                    {
                        //重置窗帘
                        var result = await HdlDeviceCurtainLogic.Current.RestoreCurtain(curtainDevice);
                        if (result == false)
                        {
                            return;
                        }
                        //重新初始化界面
                        this.InitMiddleFrame();
                    });
                });
            };
            //展示模板或者虚拟住宅,则无效
            if (Config.Instance.Home.IsShowTemplate == true || Config.Instance.Home.IsVirtually == true)
            {
                rowReset.CanClick = false;
            }
        }
 
        #endregion
 
        #region ■ 初始化窗帘数据_____________________
 
        /// <summary>
        /// 初始化窗帘数据
        /// </summary>
        /// <returns></returns>
        private bool InitCurtainDefultData()
        {
            this.curtainData = new CurtainData();
            //如果当前是虚拟住宅
            if (Common.Config.Instance.Home.IsVirtually == true)
            {
                var data = HdlTemplateDeviceDataLogic.Current.GetCurtainLimitPoint(curtainDevice);
                curtainData.Direction = data.Direction;
                return true;
            }
 
            //开启进度条
            this.ShowProgressBar();
 
            bool receiptData = false;
            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;
                        }
                        //数据接收结束
                        receiptData = true;
                    }
                }
            });
            //发送获取窗帘限位配置的命令
            HdlDeviceCurtainLogic.Current.SetGetCurtainLimitSettionComand(curtainDevice);
 
            int timeCount = 30;
            while (receiptData == false && 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>
        public override void CloseFormBefore()
        {
            HdlGatewayReceiveLogic.Current.RemoveEvent("CurtainDeviceAttribute");
 
            base.CloseFormBefore();
        }
 
        #endregion
 
        #region ■ 结构体_____________________________
 
        /// <summary>
        /// 窗帘数据
        /// </summary>
        private class CurtainData
        {
            /// <summary>
            /// false:电机方向正向;true:电机方向反向
            /// </summary>
            public bool Direction = false;
        }
 
        #endregion
    }
}