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
using Shared.Common;
using System;
 
namespace Shared.Phone.UserCenter.User
{
    /// <summary>
    /// 个人信息画面
    /// </summary>
    public class UserInformationForm : UserCenterCommonForm
    {
        #region ■ 变量声明___________________________
 
        /// <summary>
        /// 列表控件的FrameLayout
        /// </summary>
        private FrameLayout ListViewframeLayout = null;
 
        #endregion
 
        #region ■ 初始化_____________________________
 
        /// <summary>
        /// 画面显示(底层会固定调用此方法,借以完成画面创建)
        /// </summary>
        public void ShowForm()
        {
            //因为别的画面会调用这个函数,然后刷新画面
            bodyFrameLayout.RemoveAll();
 
            //设置头部信息
            base.SetTitleText(Language.StringByID(R.MyInternationalizationString.uPersonalInfo));
 
            //为了能够显示模块图样
            bodyFrameLayout.BackgroundColor = UserCenterColor.Current.TopFrameLayout;
 
            ListViewframeLayout = new FrameLayout();
            bodyFrameLayout.AddChidren(ListViewframeLayout);
 
            //初始化上部的信息
            var topFrame = this.InitTopBodyFrame();
 
            //初始化中部的信息
            var midll = this.InitMiddleBodyFrame(topFrame);
 
            //初始化底部部的信息
            this.InitBottomBodyFrame(midll);
        }
 
        #endregion
 
        #region ■ 初始化上段控件_____________________
 
        /// <summary>
        /// 初始化上部的信息
        /// </summary>
        private SpecialFrameLayout InitTopBodyFrame()
        {
            var specialTopFrame = new SpecialFrameLayout(340, 20);
            specialTopFrame.BackgroundColor = UserCenterColor.Current.BodyFrameLayout;
            ListViewframeLayout.AddChidren(specialTopFrame);
 
            //用户图标
            var btnUserIcon = new ProfilePhotoControl();
            btnUserIcon.Y = Application.GetRealHeight(40);
            btnUserIcon.Gravity = Gravity.CenterHorizontal;
            btnUserIcon.UnSelectedImagePath = "Account/Admin.png";
            specialTopFrame.AddChidren(btnUserIcon);
 
            //身份
            var btnAuthority = new ViewNormalControl(specialTopFrame.Width);
            btnAuthority.TextAlignment = TextAlignment.Center;
            btnAuthority.Y = btnUserIcon.Bottom + Application.GetRealHeight(20);
            btnAuthority.TextColor = UserCenterColor.Current.TextGrayColor;
            btnAuthority.Gravity = Gravity.CenterHorizontal;
            btnAuthority.Text = UserCenterResourse.UserInfo.AuthorityText;
            specialTopFrame.AddChidren(btnAuthority);
 
            return specialTopFrame;
        }
 
        #endregion
 
        #region ■ 初始化中段控件_____________________
 
        /// <summary>
        /// 初始化中部的信息
        /// </summary>
        private SpecialFrameLayout InitMiddleBodyFrame(SpecialFrameLayout specialTopFrame)
        {
            var specialMidFrame = new SpecialFrameLayout(450, 0);
            specialMidFrame.BackgroundColor = UserCenterColor.Current.BodyFrameLayout;
            specialMidFrame.Y = specialTopFrame.Bottom + Application.GetRealHeight(50);
            ListViewframeLayout.AddChidren(specialMidFrame);
 
            //用户名称
            string caption = Language.StringByID(R.MyInternationalizationString.uUserName);
            string nameValue = UserCenterResourse.UserInfo.UserName;
            var btnUserName = new EditorNameValueRow(caption, nameValue);
            specialMidFrame.AddChidren(btnUserName);
            btnUserName.InitControl();
            //请输入用户名称
            btnUserName.SetEmptyNameTip(Language.StringByID(R.MyInternationalizationString.uPleaseInputUserName));
            //编辑用户名称
            btnUserName.SetDialogTitle(Language.StringByID(R.MyInternationalizationString.uEditorUserName));
            btnUserName.ActionNameChangedEvent += (userName) =>
            {
                //更新用户名
                this.SaveUserName(userName);
            };
            
            var rowEmail = new RowLayout();
            rowEmail.Y = btnUserName.Bottom;
            rowEmail.Height = ControlCommonResourse.ListViewRowHeight;
            specialMidFrame.AddChidren(rowEmail);
            //Email
            var btnEmailView = new RowTopGrayView(false);
            btnEmailView.TextID = R.MyInternationalizationString.uEmail;
            rowEmail.AddChidren(btnEmailView);
            var btnEmail = new RowBottomGrayView(false);
            btnEmail.Text = UserCenterResourse.UserInfo.Email;
            rowEmail.AddChidren(btnEmail);
            //修改/绑定邮箱
            var btnEmailEditor = new RowMostRightTextView();
            btnEmailEditor.TextColor = UserCenterColor.Current.TextBlueColor;
            //绑定
            btnEmailEditor.TextID = string.IsNullOrEmpty(btnEmail.Text) == true ? R.MyInternationalizationString.uBinding : R.MyInternationalizationString.uEditor2;
            rowEmail.AddChidren(btnEmailEditor);
            btnEmailEditor.ReSetYaxis(UViewAlignment.Bottom);
            btnEmailEditor.MouseUpEventHandler += (sender, e) =>
            {
                if (string.IsNullOrEmpty(btnEmail.Text) == true)
                {
                    var form = new CheckNewEmailForm();
                    //身份验证,然后才能打开界面
                    this.CheckUserAuthenticationAndShowForm(form);
                }
                else
                {
                    var form = new CheckOldEmailForm();
                    this.AddForm(form);
                }
            };
 
            var rowPhone = new RowLayout();
            rowPhone.Y = rowEmail.Bottom;
            rowPhone.Height = ControlCommonResourse.ListViewRowHeight;
            specialMidFrame.AddChidren(rowPhone, HeightAutoMode.IncreaseOnly);
            //手机号码
            var btnPhoneView = new RowTopGrayView(false);
            btnPhoneView.TextID = R.MyInternationalizationString.uPhone;
            rowPhone.AddChidren(btnPhoneView);
 
            var btnPhone = new RowBottomGrayView(false);
            btnPhone.Text = UserCenterResourse.UserInfo.Phone;
            rowPhone.AddChidren(btnPhone);
            //修改/绑定手机号
            var btnPhoneEditor = new RowMostRightTextView();
            btnPhoneEditor.TextColor = UserCenterColor.Current.TextBlueColor;
            //绑定
            btnPhoneEditor.TextID = string.IsNullOrEmpty(btnPhone.Text) == true ? R.MyInternationalizationString.uBinding : R.MyInternationalizationString.uEditor2;
            rowPhone.AddChidren(btnPhoneEditor);
            btnPhoneEditor.ReSetYaxis(UViewAlignment.Bottom);
            btnPhoneEditor.MouseUpEventHandler += (sender, e) =>
            {
                if (string.IsNullOrEmpty(btnPhone.Text) == true)
                {
                    var form = new CheckNewPhoneNumForm();
                    //身份验证,然后才能打开界面
                    this.CheckUserAuthenticationAndShowForm(form);
                }
                else
                {
                    var form = new CheckOldPhoneNumForm();
                    this.AddForm(form);
                }
            };
            return specialMidFrame;
        }
        #endregion
 
        #region ■ 初始化下段控件_____________________
 
        /// <summary>
        /// 初始化底部部的信息
        /// </summary>
        private void InitBottomBodyFrame(SpecialFrameLayout specialMidFrame)
        {
            var specialBomFrame = new SpecialFrameLayout(ControlCommonResourse.ListViewRowHeight * 2, 0, false);
            specialBomFrame.Y = specialMidFrame.Bottom + Application.GetRealHeight(50);
            specialBomFrame.BackgroundColor = UserCenterColor.Current.BodyFrameLayout;
            ListViewframeLayout.AddChidren(specialBomFrame);
 
            //修改密码(行)
            var rowPsw = new StatuRowLayout();
            specialBomFrame.AddChidren(rowPsw, HeightAutoMode.AutoOnly);
            //修改密码
            var btnPsw = new RowCenterView(false);
            btnPsw.TextID = R.MyInternationalizationString.uChangedPassword;
            rowPsw.AddChidren(btnPsw);
            //向右图标
            var btnRinght = rowPsw.AddRightIconControl();
            rowPsw.MouseUpEvent += (sender, e) =>
            {
                var form = new EditorPasswordForm();
                this.AddForm(form);
            };
 
            ////Touch ID验证(行)
            //var rowTouch = new RowLayout();
            //rowTouch.Y = rowPsw.Bottom;
            //rowTouch.Height = ControlCommonResourse.ListViewRowHeight;
            //specialBomFrame.AddChidren(rowTouch, HeightAutoMode.IncreaseOnly);
            ////Touch ID验证
            //var btnTouchView = new RowTopBlackView(false);
            //btnTouchView.TextID = R.MyInternationalizationString.uTouchIDCheck;
            //btnTouchView.TextAlignment = TextAlignment.CenterLeft;
            //rowTouch.AddChidren(btnTouchView);
 
            ////Msg:开启后,每次打开程序时都需要指纹验证
            //var btnTouchMsg = new RowBottomGrayView(false);
            //btnTouchMsg.TextID = R.MyInternationalizationString.uNeedFingerprintAfterActionProgram;
            //btnTouchMsg.TextAlignment = TextAlignment.CenterLeft;
            //rowTouch.AddChidren(btnTouchMsg);
 
            ////开关按钮
            //var btnSwich = new SwichControl();
            //rowTouch.AddChidren(btnSwich);
            //btnSwich.MouseUpEventHandler += (sender, e) =>
            //{
            //    btnSwich.IsSelected = !btnSwich.IsSelected;
            //};
 
            //初始化退出账号的FrameLayout
            this.InitLogoutFrameLayout(specialBomFrame.Bottom + Application.GetRealHeight(50));
        }
 
        /// <summary>
        /// 初始化退出账号的FrameLayout
        /// </summary>
        private void InitLogoutFrameLayout(int YY)
        {
            var specialFrame = new SpecialFrameLayout(bodyFrameLayout.Height - YY, 0, false);
            specialFrame.Y = YY;
            specialFrame.BackgroundColor = UserCenterColor.Current.BodyFrameLayout;
            ListViewframeLayout.AddChidren(specialFrame);
 
            //退出账号(行)
            var rowLogout = new StatuRowLayout();
            specialFrame.AddChidren(rowLogout, HeightAutoMode.IncreaseAll);
            //退出账号
            var btnLogout = new RowCenterView(false);
            btnLogout.TextID = R.MyInternationalizationString.uLogoutAccount;
            rowLogout.AddChidren(btnLogout);
            //向右图标
            var btnRinght2 = rowLogout.AddRightIconControl();
            rowLogout.MouseUpEvent += (sender, e) =>
            {
                //确定退出当前账号?
                string msg = Language.StringByID(R.MyInternationalizationString.uLogoutAccountMsg);
                this.ShowConfirmMsg(msg, "DoLogoutAccount");
            };
        }
 
        /// <summary>
        /// 退出账号
        /// </summary>
        public void DoLogoutAccount()
        {
            UserCenterLogic.ReLoginAgain(Common.Config.Instance.Account);
        }
 
        #endregion
 
        #region ■ 更新用户名_________________________
 
        /// <summary>
        /// 更新用户名
        /// </summary>
        /// <param name="userName">昵称</param>
        private async void SaveUserName(string userName)
        {
            if (UserCenterResourse.UserInfo.UserName == userName)
            {
                return;
            }
            //打开进度条
            this.ShowProgressBar();
 
            var pra = new SaveUserNamePra();
            pra.UserName = userName;
 
            bool result = await UserCenterLogic.GetResultStatuByRequestHttps("ZigbeeUsers/UpdateUserName", pra);
            //关闭进度条
            this.CloseProgressBar();
            if (result == false)
            {
                return;
            }
 
            //用户名称修改成功!
            string msg = Language.StringByID(R.MyInternationalizationString.uUserNameSaveSuccess);
            this.ShowTip(msg);
 
            UserCenterResourse.UserInfo.UserName = userName;
        }
 
        #endregion
 
        #region ■ 身份验证___________________________
 
        /// <summary>
        /// 身份验证
        /// </summary>
        /// <param name="form"></param>
        /// <returns></returns>
        private void CheckUserAuthenticationAndShowForm(UserCenterCommonForm form)
        {
            var dialog = new DialogInputFrameControl(this, DialogFrameMode.OnlyPassword);
            dialog.SetTipText(Language.StringByID(R.MyInternationalizationString.PleaseInputOldPsw));
            dialog.SetTitleText(Language.StringByID(R.MyInternationalizationString.uUserAuthentication));
            dialog.ComfirmClickEvent += () =>
            {
                if (dialog.InputText != Config.Instance.Password)
                {
                    //原密码错误
                    string msg = Language.StringByID(R.MyInternationalizationString.UpdatePassword_OldPwdNoYes);
                    this.ShowErrorMsg(msg);
                    return;
                }
                dialog.CloseDialog();
 
                this.AddForm(form);
            };
        }
 
        #endregion
 
        #region ■ 界面重新激活事件___________________
 
        /// <summary>
        /// 自身的上层界面关闭后,它自身处于最上层时,触发的事件
        /// </summary>
        public override void FormActionAgainEvent()
        {
            //重新刷新界面
            this.ShowForm();
        }
 
        #endregion
    }
}