黄学彪
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
using System;
using System.Collections.Generic;
using Shared.Common;
using Shared.Phone.UserView;
using ZigBee.Device;
 
namespace Shared.Phone.UserCenter.DoorLock
{
    public class FunctionSetting : DoorLockCommonLayout
    {
        #region  构造函数 
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="doorLock"></param>
        public FunctionSetting(Room room, CommonDevice doorLock)
        {
            this.doorLock = doorLock as ZigBee.Device.DoorLock;
            currentRoom = room;
            deviceUI = doorLock;
            listNewDevice.Add(doorLock);
            BackgroundColor = Shared.Common.ZigbeeColor.Current.GXCTopViewBackgroundColor;
        }
        #endregion
 
        #region  变量申明 
        public ZigBee.Device.DoorLock doorLock = null;
        /// <summary>
        /// 当前房间
        /// </summary>
        Room currentRoom;
        /// <summary>
        /// 设备UI对象
        /// </summary>
        CommonDevice deviceUI;
        /// <summary>
        /// 设备需要保存的设备名字
        /// </summary>
        private Dictionary<int, string> dicDeviceSaveName = new Dictionary<int, string>();
        /// <summary>
        /// 当前选择的设备
        /// </summary>
        private CommonDevice nowSelectDevice = null;
        /// <summary>
        /// 设备备注的控件
        /// </summary>
        private FrameCaptionInputControl btnDeviceName = null;
        /// <summary>
        /// 设备的某一回路
        /// </summary>
        private CommonDevice deviceObj = null;
        /// <summary>
        /// 设备对象
        /// </summary>
        private List<CommonDevice> listNewDevice = new List<CommonDevice> { };
        Action action;
        Action actionNone;
        string modifyDeviceName = "";
        bool IsModifyName = true;
        public Action<string> devicNameAction;
        private VerticalListControl listview = null;//功能列表
        FrameLayout bottomFrameLayout;
        #endregion
 
        #region  UI显示  
        /// <summary>
        /// UI显示 
        /// </summary>
        public void Show()
        {
            this.TopFrameLayout(this, Language.StringByID(R.MyInternationalizationString.DoorLockFunctionSetting));
 
            EventHandler<MouseEventArgs> eHandlerBack = (sender, e) =>
            {
                RemoveFromParent();
            };
            this.btnBack.MouseUpEventHandler += eHandlerBack;
            this.btnBackFrameLayout.MouseUpEventHandler += eHandlerBack;
            this.MidFrameLayout(this);
 
            MidFrameLayoutContent();
 
        }
        #endregion
 
        #region  中部显示  
        public void MidFrameLayoutContent()
        {
            //图片
            var btnPic = new DeviceInfoIconControl();
            btnPic.Y = Application.GetRealHeight(92);
            btnPic.Gravity = Gravity.CenterHorizontal;
            this.midFrameLayout.AddChidren(btnPic);
            btnPic.InitControl(doorLock);
 
            var btnDeviceText = new Button()
            {
                Y = Application.GetRealHeight(288),
                Height = Application.GetRealHeight(60),
                Gravity = Gravity.CenterHorizontal,
                TextColor = ZigbeeColor.Current.XMBlack,
                TextSize = 15,
                Text = HdlDeviceCommonLogic.Current.GetDeviceMacName(doorLock),
            };
            this.midFrameLayout.AddChidren(btnDeviceText);
 
            BottomFrameLayout();
        }
        #endregion
 
        #region  底部显示 
        public void BottomFrameLayout()
        {
            #region  UI 
            bottomFrameLayout = new FrameLayout()
            {
                Height = Application.GetRealHeight(1319),
                Y = Application.GetRealHeight(418),
                BackgroundColor = ZigbeeColor.Current.XMWhite,
            };
            this.midFrameLayout.AddChidren(bottomFrameLayout);
            bottomFrameLayout.SetCornerWithSameRadius(Application.GetRealHeight(58), HDLUtils.RectCornerTopLeft | HDLUtils.RectCornerTopRight);
 
            var informationEdit = new Button()
            {
                Height = Application.GetRealHeight(60),
                X = Application.GetRealWidth(58),
                Y = Application.GetRealHeight(81),
                Text = Language.StringByID(R.MyInternationalizationString.InformationEdit),
                TextColor = Shared.Common.ZigbeeColor.Current.XMBlack,
                TextAlignment = TextAlignment.CenterLeft,
                TextSize = 15,
            };
            bottomFrameLayout.AddChidren(informationEdit);
 
            listview = new VerticalListControl()
            {
                Height = Application.GetRealHeight(1319 - 141),
                Y = Application.GetRealHeight(170),
            };
            bottomFrameLayout.AddChidren(listview);
            #endregion
 
            FunctionDetail(doorLock);
        }
        #endregion
 
        #region  功能显示  
        void FunctionDetail(ZigBee.Device.DoorLock doorLock)
        {
            listview.RemoveAll();
            //设备备注
            string caption = Language.StringByID(R.MyInternationalizationString.DeviceRemarkXm);
            string deviceName = HdlDeviceCommonLogic.Current.GetDeviceMacName(doorLock);
            var btnNote = new FrameCaptionInputControl(caption, deviceName, listview.rowSpace / 2);
            btnNote.txtInput.MaxByte = 48;//限制只能输入48个字节
            listview.AddChidren(btnNote);
            btnNote.InitControl();
            //划线
            btnNote.AddBottomLine();
            btnNote.txtInput.FinishInputEvent += () =>
            {
                string oldName = HdlDeviceCommonLogic.Current.GetDeviceMacName(doorLock);
                if (btnNote.Text == string.Empty)
                {
                    btnNote.Text = oldName;
                }
                if (oldName != btnNote.Text)
                {
                    //修改名字
                    this.DeviceReName(btnNote.Text, false);
                }
            };
 
            //所属区域
            var rowBeloneArea = new BelongAreaControl(listview.rowSpace / 2);
            listview.AddChidren(rowBeloneArea);
            rowBeloneArea.InitControl(Language.StringByID(R.MyInternationalizationString.uBelongArea), this.listNewDevice);
            //底线
            rowBeloneArea.AddBottomLine();
 
            var listCheck = new List<string>();
            rowBeloneArea.SelectRoomEvent += (roomKeys) =>
            {
                //选择未分配时,清空
                if (roomKeys == string.Empty) { listCheck = new List<string>(); }
                foreach (var device in this.listNewDevice)
                {
                    if (roomKeys == string.Empty)
                    {
                        //如果选择的是未分配,则它的全部回路无条件全部清空房间
                        HdlRoomLogic.Current.ChangedRoom(device, roomKeys);
                        continue;
                    }
                    var room = HdlRoomLogic.Current.GetRoomByDevice(device);
                    string mainKeys = HdlDeviceCommonLogic.Current.GetDeviceMainKeys(device);
                    if (room == null)
                    {
                        //这里有点特殊,如果回路没有设置有区域的时候,才设置
                        listCheck.Add(mainKeys);
                        HdlRoomLogic.Current.ChangedRoom(device, roomKeys);
                    }
                    else if (listCheck.Contains(mainKeys) == true)
                    {
                        //如果这个回路之前都还没有区域,在本界面还没有关闭之前,可以无条件随便变更
                        HdlRoomLogic.Current.ChangedRoom(device, roomKeys);
                    }
                }
                //保存设备房间索引
                HdlRoomLogic.Current.SaveRealDeviceRoomId(this.listNewDevice, roomKeys);
            };
 
            //设备模块
            caption = Language.StringByID(R.MyInternationalizationString.BelongDevice);
            deviceName = HdlDeviceCommonLogic.Current.GetDeviceObjectText(listNewDevice);
            var btnType = new FrameCaptionViewControl(caption, deviceName, listview.rowSpace / 2);
            btnType.UseClickStatu = false;
            listview.AddChidren(btnType);
            btnType.InitControl();
            //划线
            btnType.AddBottomLine();
 
            //添加全部菜单
            this.AddAllMenuRow();
            FinishInitControl(bottomFrameLayout, this.listview);
            //保存
            var btnFinish = new BottomClickButton();
            btnFinish.Y = Application.GetRealHeight(1054);
            btnFinish.TextID = R.MyInternationalizationString.uSave;
            bottomFrameLayout.AddChidren(btnFinish);
            btnFinish.ButtonClickEvent += (sender, e) =>
            {
                string oldName = HdlDeviceCommonLogic.Current.GetDeviceMacName(listNewDevice[0]);
                if (btnNote.Text.Trim() == string.Empty)
                {
                    btnNote.Text = oldName;
                }
                if (oldName != btnNote.Text.Trim())
                {
                    //修改名字
                    this.DeviceReName(btnNote.Text.Trim(), true);
                }
                else
                {
                    //关闭自身
                    this.CloseForm();
                }
            };
        }
        #endregion
 
        #region  添加全部菜单 
        /// <summary>
        /// 添加全部菜单
        /// </summary>
        private void AddAllMenuRow()
        {
            if (HdlUserCenterResourse.ResidenceOption.AuthorityNo == 1)
            {
                //添加【临时密码】行
                this.AddTempPasswordRow();
                //添加【远程开锁】行
                this.AddRemoteUnLocksRow();
                //添加【门锁时间】行
                this.AddDoorLocksTimeRow();
            }
            else
            {
                //添加【远程开锁】行
                this.AddRemoteUnLocksRow();
            }
        }
        #endregion
 
        #region 临时密码 
        /// <summary>
        /// 临时密码
        /// </summary>
        private void AddTempPasswordRow()
        {
            //用户管理
            string caption = Language.StringByID(R.MyInternationalizationString.TemporaryPassword);
            var btnRow = new FrameRowControl(listview.rowSpace / 2);
            listview.AddChidren(btnRow);
            btnRow.AddLeftCaption(caption, 600);
            //向右图标
            btnRow.AddRightArrow();
            //底线
            btnRow.AddBottomLine();
            btnRow.ButtonClickEvent += async (sender, e) =>
            {
                action = async () =>
                {
                    var temporaryPassword = new Shared.Phone.UserCenter.DoorLock.TemporaryPassword(doorLock);
                    Shared.Phone.UserView.HomePage.Instance.AddChidren(temporaryPassword);
                    Shared.Phone.UserView.HomePage.Instance.PageIndex += 1;
                    temporaryPassword.Show();
                };
                actionNone = async () =>
                {
                    Shared.Phone.UserCenter.DoorLock.DoorLockCommonLayout.SecurityRequest(doorLock);
                };
                HdlCheckLogic.Current.CheckSecondarySecurity(action, actionNone);
            };
        }
 
        #endregion
 
        #region 远程开锁 
        /// <summary>
        /// 添加【远程开锁】行(门锁专用)
        /// </summary>
        private void AddRemoteUnLocksRow()
        {
            //远程开锁
            string caption = Language.StringByID(R.MyInternationalizationString.uRemoteUnLocks);
            var btnRow = new FrameRowControl(listview.rowSpace / 2);
            btnRow.UseClickStatu = false;
            listview.AddChidren(btnRow);
            btnRow.AddLeftCaption(caption, 600);
            //开关图标
            var btnswitch = btnRow.AddMostRightSwitchIcon();
            //底线
            btnRow.AddBottomLine();
 
            var doorLock = (ZigBee.Device.DoorLock)listNewDevice[0];
            if (string.IsNullOrEmpty(doorLock.RemoteUnlockPassword) == false)
            {
                btnswitch.IsSelected = true;
            }
 
            btnswitch.ButtonClickEvent += async (sender, e) =>
            {
                if (HdlUserCenterResourse.ResidenceOption.AuthorityNo == 1)
                {
                    if (btnswitch.IsSelected == true)
                    {
                        btnswitch.IsSelected = false;
                        doorLock.RemoteUnlockPassword = string.Empty;
                        return;
                    }
                    var frame = new DoorLock.DoorLockCommonLayout();
                    frame.RemotePasswordDialog((ZigBee.Device.DoorLock)listNewDevice[0], btnswitch.btnIcon);
                    frame = null;
                }
                else
                {
                    var result = await Shared.Phone.UserCenter.DoorLock.DoorLockCommonInfo.GetDoorLockOperateAccess(doorLock, Shared.Common.Config.Instance.Guid);
                    if (result == false)
                    {
                        var result1 = await Shared.Phone.UserCenter.DoorLock.DoorLockCommonInfo.GetDoorLockUnlockAccess(doorLock, Shared.Common.Config.Instance.Guid);
                        if (result1 == true)
                        {
                            if (btnswitch.IsSelected == true)
                            {
                                btnswitch.IsSelected = false;
                                doorLock.RemoteUnlockPassword = string.Empty;
                                return;
                            }
                            var frame = new DoorLock.DoorLockCommonLayout();
                            frame.RemotePasswordDialog((ZigBee.Device.DoorLock)listNewDevice[0], btnswitch.btnIcon);
                            frame = null;
                        }
                        else
                        {
                            this.ShowMassage(ShowMsgType.Tip, Language.StringByID(R.MyInternationalizationString.NoAccess));
                        }
                    }
                    else
                    {
                        this.ShowMassage(ShowMsgType.Tip, Language.StringByID(R.MyInternationalizationString.AccountIsFreezed));
                    }
                }
            };
        }
 
        #endregion
 
        #region 门锁时间 
 
        /// <summary>
        /// 添加【门锁时间】行(门锁专用)
        /// </summary>
        private void AddDoorLocksTimeRow()
        {
            //门锁时间
            string caption = Language.StringByID(R.MyInternationalizationString.uDoorLocksTime);
            var btnRow = new FrameRowControl(listview.rowSpace / 2);
            listview.AddChidren(btnRow);
            btnRow.AddLeftCaption(caption, 600);
            //向右图标
            btnRow.AddRightArrow();
            //底线
            btnRow.AddBottomLine();
            var doorLock = this.listNewDevice[0] as ZigBee.Device.DoorLock;
            btnRow.ButtonClickEvent += async (sender, e) =>
            {
                if (HdlUserCenterResourse.ResidenceOption.AuthorityNo == 1)
                {
                    var tempPage = new Shared.Phone.UserCenter.DoorLock.TimeSettignPage(doorLock, "DoorLockTime");
                    Shared.Phone.UserView.HomePage.Instance.AddChidren(tempPage);
                    Shared.Phone.UserView.HomePage.Instance.PageIndex += 1;
                    tempPage.Show();
                }
                else
                {
                    var result = await Shared.Phone.UserCenter.DoorLock.DoorLockCommonInfo.GetDoorLockOperateAccess(doorLock, Shared.Common.Config.Instance.Guid);
                    if (result == false)
                    {
                        var tempPage = new Shared.Phone.UserCenter.DoorLock.TimeSettignPage(doorLock, "DoorLockTime");
                        Shared.Phone.UserView.HomePage.Instance.AddChidren(tempPage);
                        Shared.Phone.UserView.HomePage.Instance.PageIndex += 1;
                        tempPage.Show();
                    }
                    else
                    {
                        this.ShowMassage(ShowMsgType.Tip, Language.StringByID(R.MyInternationalizationString.AccountIsFreezed));
                    }
                }
            };
        }
 
        #endregion
 
        #region  设备重命名 
        /// <summary>
        /// 设备重命名
        /// </summary>
        /// <param name="i_deviceName">deviceName.</param>
        private void DeviceReName(string i_deviceName, bool closeForm)
        {
            //开启进度条
            this.ShowProgressBar();
 
            //修改MAC名
            string deviceName = i_deviceName.Trim();
            var result = HdlDeviceCommonLogic.Current.ReMacName(listNewDevice, deviceName);
            //关闭进度条
            this.CloseProgressBar();
 
            if (result == false)
            {
                return;
            }
            else
            {
                if (devicNameAction != null)
                {
                    devicNameAction(deviceName);
                }
            }
            if (closeForm == true)
            {
                //关闭界面
                this.CloseForm();
            }
            else
            {
                //设备备注修改成功!
                string msg = Language.StringByID(R.MyInternationalizationString.uDeviceReNoteSuccess);
                this.ShowMassage(ShowMsgType.Tip, msg);
            }
        }
        #endregion
 
        #region  行数超过容器时,补一个空白FrameLayout 
        /// <summary>
        /// 行数超过容器时,补一个空白FrameLayout,使之能滑动
        /// </summary> 
        void FinishInitControl(FrameLayout bodyFrameLayout, VerticalListControl listview)
        {
            if (listview.ChildrenCount > 0)
            {
                var realHeight = listview.GetChildren(0).Height * listview.ChildrenCount;
 
                if (bodyFrameLayout.Height - Application.GetRealHeight(1054) + realHeight > listview.Height)
                {
                    //促使被挡住的菜单能够向上滑动
                    var frameTemp = new FrameLayout();
                    frameTemp.Height = bodyFrameLayout.Height - Application.GetRealHeight(1054) + Application.GetRealHeight(115);
                    listview.AddChidren(frameTemp);
                }
            }
        }
        #endregion
 
        #region 移除方法
        /// <summary>
        /// 重写移除方法
        /// </summary>
        public override void RemoveFromParent()
        {
            base.RemoveFromParent();
        }
        #endregion
    }
}