xm
2020-12-14 d6fb0646531172f23648441c224cdcccd721b894
ZigbeeApp/Shared/Phone/UserCenter/UserMain/SecondAuthenticationForm.cs
New file
@@ -0,0 +1,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 = UserCenterResourse.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(UserCenterResourse.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(UserCenterResourse.AccountOption.GestureAuthentication) == false)
            {
                //去修改
                btnSettion2.TextID = R.MyInternationalizationString.uGotoEditor;
            }
            //二次安全验证将用于下列操作
            var btnTitle = new NormalViewControl(800, 50, true);
            btnTitle.X = ControlCommonResourse.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 = UserCenterResourse.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(UserCenterResourse.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(UserCenterResourse.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;
                }
                UserCenterResourse.AccountOption.FingerprintAuthentication = !btnFingerSwicth.IsSelected;
                UserCenterResourse.AccountOption.Save();
                //重新刷新界面
                this.InitMiddleFrame();
            }
            else
            {
                if (string.IsNullOrEmpty(UserCenterResourse.AccountOption.GestureAuthentication) == true
                    && string.IsNullOrEmpty(UserCenterResourse.AccountOption.PswAuthentication) == true
                    && btnLockSwicth.IsSelected == true)
                {
                    //所有验证都取消了,则取消远程开锁功能
                    UserCenterResourse.AccountOption.DoorUnLockByRemote = false;
                }
                UserCenterResourse.AccountOption.FingerprintAuthentication = !btnFingerSwicth.IsSelected;
                UserCenterResourse.AccountOption.Save();
                //重新刷新界面
                this.InitMiddleFrame();
            }
        }
        #endregion
        #region ■ 远程开锁___________________________
        /// <summary>
        /// 远程开锁
        /// </summary>
        /// <param name="btnLockSwicth"></param>
        private void DoRemoteUnLocks(MostRightIconControl btnLockSwicth)
        {
            if (btnLockSwicth.IsSelected == false
                && string.IsNullOrEmpty(UserCenterResourse.AccountOption.GestureAuthentication) == true
                && string.IsNullOrEmpty(UserCenterResourse.AccountOption.PswAuthentication) == true)
            {
                TouchIDUtils.TouchIDSupperType type = TouchIDUtils.getTouchIDSupperType();
                if (type == TouchIDUtils.TouchIDSupperType.None || UserCenterResourse.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;
                }
            }
            UserCenterResourse.AccountOption.DoorUnLockByRemote = !btnLockSwicth.IsSelected;
            UserCenterResourse.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)
                    {
                        //开启隐藏菜单
                        UserCenterResourse.HideOption.CenterHideMenu = 1;
                    }
                }
                if (textValue == "84651666")
                {
                    //显示设备历史版本
                    UserCenterResourse.HideOption.DeviceHistory = 1;
                }
                if (textValue == "12349")
                {
                    //强制跳转真实设备界面
                    UserCenterResourse.HideOption.GotoRealDeviceForm = 1;
                }
                if (textValue == "12348")
                {
                    //强制跳转网关界面
                    UserCenterResourse.HideOption.GotoGatewayProductInfoForm = 1;
                }
                if (textValue == "abcdef1")
                {
                    //强制变更常开模式的时间为分钟
                    UserCenterResourse.HideOption.DoorLockNomallyOpenTimeMode = 1;
                }
                this.ShowMassage(ShowMsgType.Tip, "Ok!");
            });
        }
        #endregion
    }
}