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
using System;
using System.Collections.Generic;
using System.Text;
 
namespace Shared.Phone.UserCenter
{
    /// <summary>
    /// 安防校验管理员密码的弹窗画面
    /// </summary>
    public class SafetyAdminValidatedControl : DialogInputFrameControl
    {
        /// <summary>
        /// 验证是否成功
        /// </summary>
        public bool IsSuccess = false;
        /// <summary>
        /// 安防校验管理员密码的弹窗画面
        /// </summary>
        public SafetyAdminValidatedControl() : base(null, DialogFrameMode.None)
        {
            //获取当前正在激活的画面
            UserCenterCommonForm form = UserCenterLogic.GetNowActionForm();
            if (form == null)
            {
                //这种情况应该不存在
                var contr = new ErrorMsgControl("ERROR:Not Found The ActionForm!");
                contr.Show();
                return;
            }
            form.AddChidren(this);
            //初始化框架
            this.InitframeControl(DialogFrameMode.None);
 
            //中间靠齐的一个框
            var frameCenter = new SpecialFrameLayout(this.InputControlWidth + 10, 200, 0);
            frameCenter.Gravity = Gravity.Center;
            base.frameMiddle.AddChidren(frameCenter);
 
            //输入框的边框
            SpecialFrameLayout frameLine = this.InitInputTextLine();
            frameLine.Gravity = Gravity.Frame;
            frameCenter.AddChidren(frameLine);
            frameLine.Radius = (uint)frameLine.Height / 2;
            //输入框
            EditInputText txtInput = this.InitInputControl(frameLine);
            txtInput.SecureTextEntry = true;
            txtInput.PlaceholderTextColor = UserCenterColor.Current.TextTipColor;
            txtInput.PlaceholderText = Language.StringByID(R.MyInternationalizationString.uPleaseInputAdministratorPassword);
            frameLine.AddChidren(txtInput, HeightAutoMode.IncreaseOnly);
 
            var frameCheck = new SpecialFrameLayout(this.InputControlWidth, 10, 0);
            frameCheck.Y = frameLine.Bottom + Application.GetRealHeight(50);
            frameCenter.AddChidren(frameCheck);
            //Check图标
            var btnCheck = new IconViewControl(80);
            btnCheck.UnSelectedImagePath = "Account/Check.png";
            btnCheck.SelectedImagePath = "Account/CheckSelected.png";
            frameCheck.AddChidren(btnCheck, HeightAutoMode.IncreaseAll);
            btnCheck.MouseUpEventHandler += (sender, e) =>
            {
                btnCheck.IsSelected = !btnCheck.IsSelected;
            };
 
            //本次登陆不再询问
            var btnView = new ViewNormalControl(frameCheck.Width - btnCheck.Width - Application.GetRealWidth(5));
            btnView.X = btnCheck.Right + Application.GetRealWidth(10);
            btnView.TextID = R.MyInternationalizationString.uCurrentLandingNotAskAgain;
            frameCheck.AddChidren(btnView, HeightAutoMode.IncreaseAll);
            btnView.MouseUpEventHandler += (sender, e) =>
            {
                btnCheck.IsSelected = !btnCheck.IsSelected;
            };
            //最后让图标居中
            btnCheck.Gravity = Gravity.CenterVertical;
 
            //完成最终初始化
            this.FinishInitControl();
 
            //设置输入框提示信息:管理员密码
            this.SetOkButtonText(Language.StringByID(R.MyInternationalizationString.uVerification));
            this.SetTitleText(Language.StringByID(R.MyInternationalizationString.uAdministratorPassword));
 
            this.ComfirmClickEvent += () =>
            {
                if (txtInput.Text == string.Empty)
                {
                    //请输入管理员密码
                    string msg = Language.StringByID(R.MyInternationalizationString.uPleaseInputAdministratorPassword);
                    var contr = new Phone.UserCenter.ErrorMsgControl(msg);
                    contr.Show();
                    return;
                }
                //尝试登陆
                this.DoLogin(txtInput.Text, btnCheck.IsSelected);
            };
        }
 
        /// <summary>
        /// 尝试登陆
        /// </summary>
        /// <param name="password"></param>
        /// <param name="NotAsk"></param>
        /// <returns></returns>
        private async void DoLogin(string password, bool NotAsk)
        {
            //尝试登陆
            bool result = await Common.LocalSafeguard.Current.AdminLogin(password);
            if (result == true)
            {
                this.IsSuccess = true;
                Common.LocalSafeguard.Current.NotAskAgain = NotAsk;
                if (NotAsk == true)
                {
                    Common.LocalSafeguard.Current.SetAdminPswInMenmory(password);
                }
                Application.RunOnMainThread(() =>
                {
                    this.CloseDialog();
                });
            }
        }
    }
}