黄学彪
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
using System;
using System.Collections.Generic;
using System.Text;
 
namespace Shared.Phone.UserCenter.UserMain
{
    /// <summary>
    /// 二次安全验证
    /// </summary>
    public class SecondAuthenticationForm : EditorCommonForm
    {
        #region ■ 变量声明___________________________
 
        #endregion
 
        #region ■ 初始化_____________________________
 
        /// <summary>
        /// 画面显示(底层会固定调用此方法,借以完成画面创建)
        /// </summary>
        public void ShowForm()
        {
            //设置头部信息
            base.SetTitleText(Language.StringByID(R.MyInternationalizationString.uSecondAuthentication));
 
            var btntitle = (Button)topFrameLayout.GetTagByKey("txtTitle");
            btntitle.MouseLongEventHandler += (sender, e) =>
            {
                //显示数字命令窗口
                this.ShowKeyNumberComandDialog();
            };
 
            //初始化中部信息
            this.InitMiddleFrame();
        }
 
        /// <summary>
        /// 初始化中部信息
        /// </summary>
        private void InitMiddleFrame()
        {
            //清空bodyFrame
            this.ClearBodyFrame();
 
            var frameTop = new FrameListControl(12);
            frameTop.Height = Application.GetRealHeight(446);
            frameTop.BackgroundColor = UserCenterColor.Current.White;
            bodyFrameLayout.AddChidren(frameTop);
 
            MostRightIconControl btnFingerSwicth = null;
            var touchIDSupper = TouchIDUtils.getTouchIDSupperType();
            if (touchIDSupper == TouchIDUtils.TouchIDSupperType.TouchID)
            {
                var rowFinger = new FrameRowControl(frameTop.rowSpace / 2);
                rowFinger.UseClickStatu = false;
                frameTop.AddChidren(rowFinger);
                //指纹验证
                var btnFinger = rowFinger.AddLeftCaption(Language.StringByID(R.MyInternationalizationString.uFingerprintAuthentication), 400, 58);
                btnFinger.Y = Application.GetRealHeight(12) + rowFinger.chidrenYaxis;
                rowFinger.AddChidren(btnFinger, ChidrenBindMode.NotBind);
                //仅对本机有效
                var btnEffect = rowFinger.AddLeftCaption(Language.StringByID(R.MyInternationalizationString.uOnlyEffectToThisPhone), 400, 40);
                btnEffect.Y = Application.GetRealHeight(72) + rowFinger.chidrenYaxis;
                btnEffect.TextSize = 12;
                btnEffect.TextColor = UserCenterColor.Current.TextGrayColor1;
                rowFinger.AddChidren(btnEffect, ChidrenBindMode.NotBind);
                //开关按钮
                btnFingerSwicth = rowFinger.AddMostRightSwitchIcon();
                btnFingerSwicth.IsSelected = HdlUserCenterResourse.AccountOption.FingerprintAuthentication;
                //底线
                rowFinger.AddBottomLine();
            }
 
            var rowPsw = new FrameRowControl(frameTop.rowSpace / 2);
            frameTop.AddChidren(rowPsw);
            //如果这个手机不支持TouchId的话,则容器减去这个行的高度
            if (touchIDSupper != TouchIDUtils.TouchIDSupperType.TouchID)
            {
                frameTop.Height -= rowPsw.Height;
            }
            //密码验证
            rowPsw.AddLeftCaption(Language.StringByID(R.MyInternationalizationString.uPasswordAuthentication), 400);
            //右箭头
            rowPsw.AddRightArrow();
            //去设置
            var btnSettion1 = rowPsw.AddMostRightView(Language.StringByID(R.MyInternationalizationString.uGotoSettion), 400);
            if (string.IsNullOrEmpty(HdlUserCenterResourse.AccountOption.PswAuthentication) == false)
            {
                //去修改
                btnSettion1.TextID = R.MyInternationalizationString.uGotoEditor;
            }
            //底线
            rowPsw.AddBottomLine();
 
            var rowGesture = new FrameRowControl(frameTop.rowSpace / 2);
            frameTop.AddChidren(rowGesture);
            //手势验证
            rowGesture.AddLeftCaption(Language.StringByID(R.MyInternationalizationString.uGestureAuthentication), 400);
            //右箭头
            rowGesture.AddRightArrow();
            //去设置
            var btnSettion2 = rowGesture.AddMostRightView(Language.StringByID(R.MyInternationalizationString.uGotoSettion), 400);
            if (string.IsNullOrEmpty(HdlUserCenterResourse.AccountOption.GestureAuthentication) == false)
            {
                //去修改
                btnSettion2.TextID = R.MyInternationalizationString.uGotoEditor;
            }
 
            //二次安全验证将用于下列操作
            var btnTitle = new NormalViewControl(800, 50, true);
            btnTitle.X = HdlControlResourse.XXLeft;
            btnTitle.Y = frameTop.Bottom + Application.GetRealHeight(34);
            btnTitle.TextSize = 12;
            btnTitle.TextColor = UserCenterColor.Current.TextGrayColor3;
            btnTitle.TextID = R.MyInternationalizationString.uSecondarySecurityWillBeUsedForTheFollowingOperations;
            bodyFrameLayout.AddChidren(btnTitle);
            btnTitle.ButtonClickEvent += (sender, e) =>
            {
                //隐匿功能点击
                this.HideOptionClick(btnTitle);
            };
 
            var frameButtom = new FrameListControl(12);
            frameButtom.Y = btnTitle.Bottom + Application.GetRealHeight(23);
            frameButtom.Height = Application.GetRealHeight(449);
            frameButtom.BackgroundColor = UserCenterColor.Current.White;
            bodyFrameLayout.AddChidren(frameButtom);
 
            var rowAdmin = new FrameRowControl(frameButtom.rowSpace / 2);
            rowAdmin.UseClickStatu = false;
            frameButtom.AddChidren(rowAdmin);
            //管理员授权
            rowAdmin.AddLeftCaption(Language.StringByID(R.MyInternationalizationString.uAdministratorAuthorization), 400);
            //授权成员成为管理员
            var btnMsg = rowAdmin.AddMostRightView(Language.StringByID(R.MyInternationalizationString.uAuthorizedMembersBecomeAdministrators), 400);
            btnMsg.TextSize = 12;
            btnMsg.TextColor = UserCenterColor.Current.TextGrayColor2;
            //底线
            rowAdmin.AddBottomLine();
 
            var rowLock = new FrameRowControl(frameTop.rowSpace / 2);
            rowLock.UseClickStatu = false;
            frameButtom.AddChidren(rowLock);
            //远程开锁
            var btnUnLock = rowLock.AddLeftCaption(Language.StringByID(R.MyInternationalizationString.uRemoteUnLocks), 400, 58);
            btnUnLock.Y = Application.GetRealHeight(12) + rowLock.chidrenYaxis;
            rowLock.AddChidren(btnUnLock, ChidrenBindMode.NotBind);
            //通过APP开启门锁
            var btnUnLockByApp = rowLock.AddLeftCaption(Language.StringByID(R.MyInternationalizationString.uUnLockDoorByApp), 400, 40);
            btnUnLockByApp.Y = Application.GetRealHeight(72) + rowLock.chidrenYaxis;
            btnUnLockByApp.TextSize = 12;
            btnUnLockByApp.TextColor = UserCenterColor.Current.TextGrayColor1;
            rowLock.AddChidren(btnUnLockByApp, ChidrenBindMode.NotBind);
            //开关按钮
            var btnLockSwicth = rowLock.AddMostRightSwitchIcon();
            //底线
            rowLock.AddBottomLine();
            btnLockSwicth.IsSelected = HdlUserCenterResourse.AccountOption.DoorUnLockByRemote;
 
            var rowSafety = new FrameRowControl(frameButtom.rowSpace / 2);
            rowSafety.UseClickStatu = false;
            frameButtom.AddChidren(rowSafety);
            //安防设置
            rowSafety.AddLeftCaption(Language.StringByID(R.MyInternationalizationString.uSafetySettion), 400);
            //配置防区
            var btnMsg2 = rowSafety.AddMostRightView(Language.StringByID(R.MyInternationalizationString.uGarrisonConfiguration), 400);
            btnMsg2.TextSize = 12;
            btnMsg2.TextColor = UserCenterColor.Current.TextGrayColor2;
 
            //指纹验证
            if (btnFingerSwicth != null)
            {
                btnFingerSwicth.ButtonClickEvent += (sender, e) =>
                {
                    if (btnFingerSwicth.IsSelected == false)
                    {
                        TouchIDUtils.TouchIDSupperType type = TouchIDUtils.getTouchIDSupperType();
                        if (type == TouchIDUtils.TouchIDSupperType.None)
                        {
                            //开启指纹验证失败!请前往手机{0}设置开启指纹开锁验证
                            string msg = Language.StringByID(R.MyInternationalizationString.uUseFingerprintAuthenticationFailMsg);
                            msg = msg.Replace("{0}", "\r\n");
                            this.ShowMassage(ShowMsgType.Normal, msg);
                            return;
                        }
                        //将Touch ID用于「ZigBee」{0}更改安防设置和开启门锁时使用
                        string msg2 = Language.StringByID(R.MyInternationalizationString.uUseFingerprintAuthenticationMsg);
                        msg2 = msg2.Replace("{0}", "\r\n");
                        this.ShowMassage(ShowMsgType.Confirm, msg2, () =>
                        {
                            //如果设置有安全验证,想要修改它,必须先通过安全验证
                            //如果没有设置有安全验证,则无需验证
                            HdlCheckLogic.Current.CheckSecondarySecurity(
                                    () => { this.DoFingerprintAuthentication(btnFingerSwicth, btnLockSwicth); },//处理指纹验证
                                    () => { this.DoFingerprintAuthentication(btnFingerSwicth, btnLockSwicth); });//处理指纹验证
                        });
                    }
                    else
                    {
                        //如果设置有安全验证,想要修改它,必须先通过安全验证
                        //如果没有设置有安全验证,则无需验证
                        HdlCheckLogic.Current.CheckSecondarySecurity(
                                () => { this.DoFingerprintAuthentication(btnFingerSwicth, btnLockSwicth); },//处理指纹验证
                                () => { this.DoFingerprintAuthentication(btnFingerSwicth, btnLockSwicth); });//处理指纹验证
                    }
                };
            }
            //密码验证
            rowPsw.ButtonClickEvent += (sender, e) =>
            {
                //如果没有密码验证
                if (string.IsNullOrEmpty(HdlUserCenterResourse.AccountOption.PswAuthentication) == true)
                {
                    //如果设置有其他验证方式,则需要验证,否则直接跳过验证
                    HdlCheckLogic.Current.CheckSecondarySecurity(
                   () => { var form = new Password.EditorSecondaryPasswordForm(); form.AddForm(); },
                   () => { var form = new Password.EditorSecondaryPasswordForm(); form.AddForm(); });
                }
                else
                {
                    var form = new Password.EditorSecondaryPasswordForm();
                    form.AddForm();
                }
            };
            //手势验证
            rowGesture.ButtonClickEvent += (sender, e) =>
            {
                //如果没有手势验证
                if (string.IsNullOrEmpty(HdlUserCenterResourse.AccountOption.GestureAuthentication) == true)
                {
                    //如果设置有其他验证方式,则需要验证,否则直接跳过验证
                    HdlCheckLogic.Current.CheckSecondarySecurity(
                   () => { var form = new Password.EditorGesturePasswordForm(); form.AddForm(); },
                   () => { var form = new Password.EditorGesturePasswordForm(); form.AddForm(); });
                }
                else
                {
                    var form = new Password.EditorGesturePasswordForm();
                    form.AddForm();
                }
            };
            //远程开锁
            btnLockSwicth.ButtonClickEvent += (sender, e) =>
            {
                //如果设置有安全验证,想要修改它,必须先通过安全验证
                //如果没有设置有安全验证,则无需验证
                HdlCheckLogic.Current.CheckSecondarySecurity(
                    () => { this.DoRemoteUnLocks(btnLockSwicth); },//处理远程开锁
                    () => { this.DoRemoteUnLocks(btnLockSwicth); });//处理远程开锁
            };
        }
 
        #endregion
 
        #region ■ 指纹验证___________________________
 
        /// <summary>
        /// 指纹验证
        /// </summary>
        /// <param name="btnFingerSwicth"></param>
        /// <param name="btnLockSwicth"></param>
        private void DoFingerprintAuthentication(MostRightIconControl btnFingerSwicth, MostRightIconControl btnLockSwicth)
        {
            if (btnFingerSwicth.IsSelected == false)
            {
                TouchIDUtils.TouchIDSupperType type = TouchIDUtils.getTouchIDSupperType();
                if (type == TouchIDUtils.TouchIDSupperType.None)
                {
                    //开启指纹验证失败!请前往手机{0}设置开启指纹开锁验证
                    string msg = Language.StringByID(R.MyInternationalizationString.uUseFingerprintAuthenticationFailMsg);
                    if (msg.Contains("{0}") == true)
                    {
                        msg = string.Format(msg, "\r\n");
                    }
                    this.ShowMassage(ShowMsgType.Normal, msg);
                    return;
                }
 
                HdlUserCenterResourse.AccountOption.FingerprintAuthentication = !btnFingerSwicth.IsSelected;
                HdlUserCenterResourse.AccountOption.Save();
                //重新刷新界面
                this.InitMiddleFrame();
            }
            else
            {
                if (string.IsNullOrEmpty(HdlUserCenterResourse.AccountOption.GestureAuthentication) == true
                    && string.IsNullOrEmpty(HdlUserCenterResourse.AccountOption.PswAuthentication) == true
                    && btnLockSwicth.IsSelected == true)
                {
                    //所有验证都取消了,则取消远程开锁功能
                    HdlUserCenterResourse.AccountOption.DoorUnLockByRemote = false;
                }
                HdlUserCenterResourse.AccountOption.FingerprintAuthentication = !btnFingerSwicth.IsSelected;
                HdlUserCenterResourse.AccountOption.Save();
                //重新刷新界面
                this.InitMiddleFrame();
            }
        }
 
        #endregion
 
        #region ■ 远程开锁___________________________
 
        /// <summary>
        /// 远程开锁
        /// </summary>
        /// <param name="btnLockSwicth"></param>
        private void DoRemoteUnLocks(MostRightIconControl btnLockSwicth)
        {
            if (btnLockSwicth.IsSelected == false
                && string.IsNullOrEmpty(HdlUserCenterResourse.AccountOption.GestureAuthentication) == true
                && string.IsNullOrEmpty(HdlUserCenterResourse.AccountOption.PswAuthentication) == true)
            {
                TouchIDUtils.TouchIDSupperType type = TouchIDUtils.getTouchIDSupperType();
                if (type == TouchIDUtils.TouchIDSupperType.None || HdlUserCenterResourse.AccountOption.FingerprintAuthentication == false)
                {
                    //远程开锁开启失败,请先设置{0}二次安全验证方式
                    string msg = Language.StringByID(R.MyInternationalizationString.uUseUnLockByRemoteFailMsg);
                    if (msg.Contains("{0}") == true)
                    {
                        msg = string.Format(msg, "\r\n");
                    }
                    this.ShowMassage(ShowMsgType.Normal, msg);
                    return;
                }
            }
            HdlUserCenterResourse.AccountOption.DoorUnLockByRemote = !btnLockSwicth.IsSelected;
            HdlUserCenterResourse.AccountOption.Save();
            //重新刷新界面
            this.InitMiddleFrame();
        }
 
        #endregion
 
        #region ■ 界面重新激活事件___________________
 
        /// <summary>
        /// 自身的上层界面关闭后,它自身处于最上层时,触发的事件
        /// </summary>
        public override int FormActionAgainEvent()
        {
            //重新刷新界面
            this.InitMiddleFrame();
 
            return 1;
        }
 
        #endregion
 
        #region ■ 隐匿功能___________________________
 
        /// <summary>
        /// 点击合计
        /// </summary>
        private int clickCount = 0;
        /// <summary>
        /// 点击的那瞬间的时间
        /// </summary>
        private DateTime clickTime;
        /// <summary>
        /// 隐匿功能
        /// </summary>
        private void HideOptionClick(NormalViewControl btnTitle)
        {
            if (clickCount == 0)
            {
                clickTime = DateTime.Now;
            }
            clickCount++;
            if (clickCount >= 10)
            {
                if ((DateTime.Now - clickTime).TotalSeconds > 3)
                {
                    clickCount = 0;
                    return;
                }
                btnTitle.CanClick = false;
                HdlThreadLogic.Current.RunThread(() =>
                {
                    this.ShowProgressBar();
                    var result = HdlBackupLogic.Current.LoadHideOption();
                    this.CloseProgressBar();
                    if (result == true)
                    {
                        this.ShowMassage(ShowMsgType.Tip, "刷新隐匿配置成功");
                    }
                    else
                    {
                        this.ShowMassage(ShowMsgType.Tip, "刷新隐匿配置失败");
                    }
                });
            }
        }
 
        /// <summary>
        /// 显示数字命令窗口
        /// </summary>
        private void ShowKeyNumberComandDialog()
        {
            //生成一个弹窗画面
            var dialogForm = new DialogInputControl();
            dialogForm.SetTitleText("?????");
 
            //按下确认按钮
            dialogForm.ComfirmClickEvent += ((textValue) =>
            {
                dialogForm.CloseDialog();
                if (textValue.StartsWith("2887") == true)
                {
                    var myTime = DateTime.Now;
                    string strTime1 = myTime.ToString("HHmm");
                    int value1 = Convert.ToInt32(strTime1.Substring(3, 1));
                    string check1 = "2887" + strTime1 + (7 + value1).ToString();
 
                    myTime = myTime.AddMinutes(-1);
                    string strTime2 = myTime.ToString("HHmm");
                    int value2 = Convert.ToInt32(strTime2.Substring(3, 1));
                    string check2 = "2887" + strTime2 + (7 + value2).ToString();
 
                    myTime = myTime.AddMinutes(2);
                    string strTime3 = myTime.ToString("HHmm");
                    int value3 = Convert.ToInt32(strTime3.Substring(3, 1));
                    string check3 = "2887" + strTime3 + (7 + value3).ToString();
 
                    if (textValue == check1 || textValue == check2 || textValue == check3)
                    {
                        //开启隐藏菜单
                        HdlUserCenterResourse.HideOption.CenterHideMenu = 1;
                    }
                }
                if (textValue == "84651666")
                {
                    //显示设备历史版本
                    HdlUserCenterResourse.HideOption.DeviceHistory = 1;
                }
                if (textValue == "12349")
                {
                    //强制跳转真实设备界面
                    HdlUserCenterResourse.HideOption.GotoRealDeviceForm = 1;
                }
                if (textValue == "12348")
                {
                    //强制跳转网关界面
                    HdlUserCenterResourse.HideOption.GotoGatewayProductInfoForm = 1;
                }
                if (textValue == "abcdef1")
                {
                    //强制变更常开模式的时间为分钟
                    HdlUserCenterResourse.HideOption.DoorLockNomallyOpenTimeMode = 1;
                }
 
                this.ShowMassage(ShowMsgType.Tip, "Ok!");
            });
        }
 
        #endregion
    }
}