using System;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace Shared.Phone.UserCenter.Password
{
///
/// 验证原邮箱的画面
///
public class CheckOldEmailForm : EditorCommonForm
{
#region ■ 变量声明___________________________
///
/// 错误信息控件
///
private NormalViewControl btnErrorMsg = null;
///
/// 标记是否能够校验验证码了
///
private bool canCheckCode = false;
#endregion
#region ■ 初始化_____________________________
///
/// 画面显示(底层会固定调用此方法,借以完成画面创建)
///
public void ShowForm()
{
//设定标题
base.SetTitleText(Language.StringByID(R.MyInternationalizationString.uEditorEmail));
//初始化中部控件
this.InitMiddleFrame();
}
///
/// 初始化中部控件
///
private void InitMiddleFrame()
{
//清空bodyFrame
this.ClearBodyFrame();
//已绑定邮箱
var btnMsg1 = new NormalViewControl(bodyFrameLayout.Width, Application.GetRealHeight(63), false);
btnMsg1.Y = Application.GetRealHeight(167);
btnMsg1.TextAlignment = TextAlignment.Center;
btnMsg1.TextSize = 16;
btnMsg1.TextColor = UserCenterColor.Current.TextGrayColor3;
btnMsg1.TextID = R.MyInternationalizationString.uHadBindEmail;
bodyFrameLayout.AddChidren(btnMsg1);
//邮箱
var btnEmail = new NormalViewControl(bodyFrameLayout.Width, Application.GetRealHeight(55), false);
btnEmail.TextColor = UserCenterColor.Current.TextGrayColor3;
btnEmail.TextAlignment = TextAlignment.Center;
btnEmail.TextSize = 16;
btnEmail.Text = HdlUserCenterResourse.UserInfo.UserEmail;
btnEmail.Y = btnMsg1.Bottom + Application.GetRealHeight(12);
bodyFrameLayout.AddChidren(btnEmail);
//修改邮箱前,请输入验证码确认您的身份
var btnMsg2 = new NormalViewControl(bodyFrameLayout.Width, Application.GetRealHeight(49), false);
btnMsg2.Y = btnEmail.Bottom + Application.GetRealHeight(37);
btnMsg2.TextAlignment = TextAlignment.Center;
btnMsg2.TextSize = 12;
btnMsg2.TextColor = UserCenterColor.Current.TextGrayColor1;
btnMsg2.TextID = R.MyInternationalizationString.uCheckAuthenticationBeforeEditorEmail;
bodyFrameLayout.AddChidren(btnMsg2);
//初始化验证码控件
var btnCodeControl = new VerificationCodeControl(6);
btnCodeControl.Y = Application.GetRealHeight(475);
bodyFrameLayout.AddChidren(btnCodeControl);
btnCodeControl.InitControl();
btnCodeControl.TxtCodeChangeEvent += (sender, e) =>
{
if (btnErrorMsg.Visible == true)
{
btnErrorMsg.Visible = false;
}
};
btnCodeControl.FinishInputEvent += (value) =>
{
//校验验证码
if (this.CheckVerificationCode(value) == false)
{
//清空验证码
btnCodeControl.ClearInputValue();
}
};
//验证码错误,请重新输入
this.btnErrorMsg = new NormalViewControl(bodyFrameLayout.Width, Application.GetRealHeight(58), false);
btnErrorMsg.Y = Application.GetRealHeight(677);
btnErrorMsg.TextAlignment = TextAlignment.Center;
btnErrorMsg.TextColor = 0xfff75858;
btnErrorMsg.TextID = R.MyInternationalizationString.uVerificationCodeErrorInputAgain;
btnErrorMsg.IsBold = true;
bodyFrameLayout.AddChidren(btnErrorMsg);
btnErrorMsg.Visible = false;
//获取验证码
var btnNext = new BottomClickButton(688);
btnNext.Y = Application.GetRealHeight(792);
btnNext.TextID = R.MyInternationalizationString.uGetVerificationCode;
bodyFrameLayout.AddChidren(btnNext);
btnNext.ButtonClickEvent += (sender, e) =>
{
//清空输入的值
btnCodeControl.ClearInputValue();
//发送验证码到邮箱
this.SendCodeToEmail(btnNext);
};
}
#endregion
#region ■ 发送验证码到邮箱___________________
///
/// 发送验证码到邮箱
///
private void SendCodeToEmail(BottomClickButton btnNext)
{
var errorMsg = HdlAccountLogic.Current.SendVeriCodeToEmail(HdlUserCenterResourse.UserInfo.UserEmail, VerCodeType.A其他);
if (errorMsg != null)
{
HdlMessageLogic.Current.ShowMassage(ShowMsgType.Tip, errorMsg);
return;
}
//可以开始校验验证码了
this.canCheckCode = true;
//控件不能再次按下
btnNext.CanClick = false;
//?s后重发
string repeat = Language.StringByID(R.MyInternationalizationString.RepeatSend1);
//有效时间60秒
int waitime = 60;
btnNext.Text = waitime + "s" + repeat;
HdlThreadLogic.Current.RunThread(() =>
{
while (this.Parent != null)
{
waitime--;
System.Threading.Thread.Sleep(1000);
if (waitime == 0)
{
HdlThreadLogic.Current.RunMain(() =>
{
if (btnNext != null)
{
//获取验证码
btnNext.TextID = R.MyInternationalizationString.uGetVerificationCode;
//按键可以按下
btnNext.CanClick = true;
}
});
break;
}
HdlThreadLogic.Current.RunMain(() =>
{
if (btnNext != null)
{
btnNext.Text = waitime + "s" + repeat;
}
}, ShowErrorMode.NO);
}
});
}
#endregion
#region ■ 校验验证码_________________________
///
/// 验证验证码
///
///
private bool CheckVerificationCode(string code)
{
if (this.canCheckCode == false)
{
//验证码错误,请重新输入
this.btnErrorMsg.Visible = true;
return false;
}
var result = HdlAccountLogic.Current.CheckVeriCode(HdlUserCenterResourse.UserInfo.UserEmail, VerCodeType.A其他, code);
if (result == false)
{
//验证码错误,请重新输入
this.btnErrorMsg.Visible = true;
return false;
}
var from = new CheckNewEmailForm();
base.AddFormAndCloseNowForm(from);
return true;
}
#endregion
}
}