using System;
using System.Collections.Generic;
using System.Text;
namespace Shared.Phone.UserCenter.Password
{
///
/// 编辑二次验证的密码验证界面
///
public class EditorSecondaryPasswordForm : EditorCommonForm
{
#region ■ 变量声明___________________________
///
/// 当前界面模式
///
private FormMode formMode = FormMode.A新建密码;
///
/// 第一次密码
///
private string firstPssword = string.Empty;
#endregion
#region ■ 初始化_____________________________
///
/// 画面显示(底层会固定调用此方法,借以完成画面创建)
///
public void ShowForm()
{
//设置头部信息
base.SetTitleText(Language.StringByID(R.MyInternationalizationString.uPasswordAuthentication));
if (string.IsNullOrEmpty(UserCenterResourse.Option.PswAuthentication) == false)
{
formMode = FormMode.A验证前回密码;
}
//初始化中部信息
this.InitMiddleFrame();
}
///
/// 初始化中部信息
///
private void InitMiddleFrame()
{
//清空bodyFrame
this.ClearBodyFrame();
var btnMsg = new NormalViewControl(bodyFrameLayout.Width, Application.GetRealHeight(49), false);
btnMsg.Y = Application.GetRealHeight(311);
btnMsg.TextAlignment = TextAlignment.Center;
btnMsg.TextSize = 12;
bodyFrameLayout.AddChidren(btnMsg);
if (formMode == FormMode.A新建密码
|| formMode == FormMode.A验证前回密码)
{
//请输入密码
btnMsg.TextID = R.MyInternationalizationString.uPleaseInputPsw;
}
else if (formMode == FormMode.A确认新建密码
|| formMode == FormMode.A确认修改密码)
{
//请再次确认密码
btnMsg.TextID = R.MyInternationalizationString.uPleaseConfirmPswAgain;
}
else if (formMode == FormMode.A修改密码)
{
//修改密码,请输入新密码
btnMsg.TextID = R.MyInternationalizationString.uEditorPswPleaseInputNewPsw;
}
//错误信息
var msgControl = new NormalViewControl(bodyFrameLayout.Width, Application.GetRealHeight(58), false);
msgControl.Y = Application.GetRealHeight(660);
msgControl.TextAlignment = TextAlignment.Center;
msgControl.TextColor = 0xfff75858;
bodyFrameLayout.AddChidren(msgControl);
//初始化验证码控件
var btnCodeControl = new VerificationCodeControl(4);
btnCodeControl.Y = Application.GetRealHeight(464);
bodyFrameLayout.AddChidren(btnCodeControl);
btnCodeControl.InitControl();;
btnCodeControl.TxtCodeChangeEvent += (sender, e) =>
{
if (msgControl.Visible == true)
{
msgControl.Visible = false;
}
};
btnCodeControl.FinishInputEvent += (value) =>
{
//校验密码
this.DoAdjustPssword(value, msgControl);
};
if (formMode == FormMode.A验证前回密码)
{
//忘记密码?
var btnForgotPsw = new NormalViewControl(bodyFrameLayout.Width, Application.GetRealHeight(49), false);
btnForgotPsw.Y = Application.GetRealHeight(1492);
btnForgotPsw.TextSize = 12;
btnForgotPsw.TextColor = UserCenterColor.Current.TextOrangeColor;
btnForgotPsw.TextID = R.MyInternationalizationString.ForgotPasswordMsg;
btnForgotPsw.TextAlignment = TextAlignment.Center;
bodyFrameLayout.AddChidren(btnForgotPsw);
btnForgotPsw.ButtonClickEvent += (sender, e) =>
{
var form = new ForgotSecondaryPasswordForm();
form.AddForm();
};
//底线
int lineWidth = btnForgotPsw.GetRealWidthByText(12);
var btnLine = new NormalViewControl(lineWidth, ControlCommonResourse.BottomLineHeight, false);
btnLine.BackgroundColor = UserCenterColor.Current.TextOrangeColor;
btnLine.Gravity = Gravity.CenterHorizontal;
btnLine.Y = btnForgotPsw.Bottom - Application.GetRealHeight(8);
bodyFrameLayout.AddChidren(btnLine);
}
}
#endregion
#region ■ 校验密码___________________________
///
/// 校验密码
///
///
///
private void DoAdjustPssword(string i_Psw, NormalViewControl msgControl)
{
if (formMode == FormMode.A新建密码)
{
//输入二次密码
this.firstPssword = i_Psw;
formMode = FormMode.A确认新建密码;
this.InitMiddleFrame();
}
else if (formMode == FormMode.A确认新建密码)
{
if (this.firstPssword != i_Psw)
{
//确认密码错误,请重新设置
msgControl.Visible = true;
msgControl.TextID = R.MyInternationalizationString.SecondPswNotEqual2;
return;
}
UserCenterResourse.Option.PswAuthentication = i_Psw;
UserCenterResourse.Option.Save();
//关闭界面
this.CloseForm();
}
else if (formMode == FormMode.A验证前回密码)
{
if (UserCenterResourse.Option.PswAuthentication != i_Psw)
{
//密码错误,请重新输入
msgControl.Visible = true;
msgControl.TextID = R.MyInternationalizationString.uOldPsswordIsError;
return;
}
formMode = FormMode.A修改密码;
this.InitMiddleFrame();
}
else if (formMode == FormMode.A修改密码)
{
//输入二次密码
this.firstPssword = i_Psw;
formMode = FormMode.A确认修改密码;
this.InitMiddleFrame();
}
else if (formMode == FormMode.A确认修改密码)
{
if (this.firstPssword != i_Psw)
{
//确认密码错误,请重新设置
msgControl.Visible = true;
msgControl.TextID = R.MyInternationalizationString.SecondPswNotEqual2;
return;
}
UserCenterResourse.Option.PswAuthentication = i_Psw;
UserCenterResourse.Option.Save();
//关闭界面
this.CloseForm();
}
}
#endregion
#region ■ 外部指定模式_______________________
///
/// 强制指定新密码模式(由外部调用)
///
public void SetNewPasswordFormMode()
{
formMode = FormMode.A新建密码;
this.InitMiddleFrame();
}
#endregion
#region ■ 结构体_____________________________
///
/// 界面模式
///
private enum FormMode
{
A新建密码 = 1,
A确认新建密码 = 2,
A验证前回密码 = 3,
A修改密码 = 4,
A确认修改密码 = 5
}
#endregion
}
}