using System;
using System.Collections.Generic;
using System.Text;
namespace Shared.Phone.UserCenter.Password
{
///
/// 忘记二次验证的密码界面
///
public class ForgotSecondaryPasswordForm : EditorCommonForm
{
#region ■ 变量声明___________________________
///
/// 标记是否能够校验验证码了
///
private bool canCheckCode = false;
///
/// 手机或者邮箱
///
private string strPhoneEmail = string.Empty;
///
/// 错误信息控件
///
private NormalViewControl btnMsgControl = null;
#endregion
#region ■ 初始化_____________________________
///
/// 画面显示(底层会固定调用此方法,借以完成画面创建)
///
public void ShowForm()
{
//设置头部信息
base.SetTitleText(Language.StringByID(R.MyInternationalizationString.ForgotPassword));
//初始化中部信息
this.InitMiddleFrame();
}
///
/// 初始化中部信息
///
private void InitMiddleFrame()
{
//清空bodyFrame
this.ClearBodyFrame();
var frameBack = new FrameLayout();
frameBack.Height = Application.GetRealHeight(323);
frameBack.BackgroundColor = UserCenterColor.Current.White;
bodyFrameLayout.AddChidren(frameBack);
var rowPhone = new FrameRowControl();
//右边偏移量->增加宽度
rowPhone.RightOffset = -HdlControlResourse.XXLeft;
rowPhone.Y = Application.GetRealHeight(23);
rowPhone.Width = this.GetPictrueRealSize(628);
bodyFrameLayout.AddChidren(rowPhone);
//请输入邮箱或手机号
string phoneValue = string.IsNullOrEmpty(HdlUserCenterResourse.UserInfo.UserPhone) == true ? string.Empty : "+" + HdlUserCenterResourse.UserInfo.PhoneAreaCode + " " + HdlUserCenterResourse.UserInfo.UserPhone;
var txtPhone = rowPhone.AddLeftCaption(string.IsNullOrEmpty(phoneValue) == true ? HdlUserCenterResourse.UserInfo.UserEmail : phoneValue, 600);
txtPhone.TextColor = UserCenterColor.Current.TextGrayColor2;
//底线
rowPhone.AddBottomLine();
//当前选择的方式
this.strPhoneEmail = txtPhone.Text;
var rowCode = new FrameRowControl();
rowCode.Y = rowPhone.Bottom + Application.GetRealHeight(20);
rowCode.Width = this.GetPictrueRealSize(628);
bodyFrameLayout.AddChidren(rowCode);
//请输入验证码
var txtCode = rowCode.AddLeftInput("", 600);
txtCode.PlaceholderText = Language.StringByID(R.MyInternationalizationString.uPleaseInputVerificationCode);
txtCode.TextChangeEventHandler += this.txtCodeValueChangedEvent;
//获取验证码
var btnCode = new NormalViewControl(302, 127, true);
btnCode.X = rowPhone.Right + Application.GetRealWidth(35);
btnCode.Y = Application.GetRealHeight(23);
btnCode.RadiusEx = 12;
btnCode.TextID = R.MyInternationalizationString.uGetVerificationCode;
btnCode.TextColor = UserCenterColor.Current.White;
btnCode.BackgroundColor = UserCenterColor.Current.TextOrangeColor;
btnCode.TextAlignment = TextAlignment.Center;
bodyFrameLayout.AddChidren(btnCode);
btnCode.ButtonClickEvent += (sender, e) =>
{
//发送验证码
this.SetVerificationCode(btnCode);
};
//错误信息控件
btnMsgControl = new NormalViewControl(800, 58, true);
btnMsgControl.X = HdlControlResourse.XXLeft;
btnMsgControl.Y = rowCode.Bottom + Application.GetRealHeight(46);
btnMsgControl.TextColor = 0xfff75858;
btnMsgControl.TextID = R.MyInternationalizationString.uVerificationCodeErrorInputAgain;
bodyFrameLayout.AddChidren(btnMsgControl);
btnMsgControl.Visible = false;
if (string.IsNullOrEmpty(HdlUserCenterResourse.UserInfo.UserPhone) == true
|| string.IsNullOrEmpty(HdlUserCenterResourse.UserInfo.UserEmail) == true)
{
rowPhone.UseClickStatu = false;
return;
}
//显示可以切换邮箱->一个可以遮住Body的东西
var frameTran = new FrameLayoutStatuControl();
frameTran.UseClickStatu = false;
frameTran.BackgroundColor = UserCenterColor.Current.Transparent;
bodyFrameLayout.AddChidren(frameTran);
frameTran.Visible = false;
frameTran.ButtonClickEvent += (sender, e) =>
{
frameTran.Visible = false;
};
var frameList = new FrameLayout();
frameList.X = HdlControlResourse.XXLeft - Application.GetRealWidth(17);
frameList.Y = rowPhone.Bottom - HdlControlResourse.BottomLineHeight - 1;
frameList.Width = this.GetPictrueRealSize(628);
frameList.Height = this.GetPictrueRealSize(176);
frameTran.AddChidren(frameList);
//动画用
var frameAnimate = new FrameLayoutStatuControl();
frameAnimate.UseClickStatu = false;
frameList.AddChidren(frameAnimate);
var btnPic = new PicViewControl(frameList.Width, frameList.Height, false);
btnPic.UnSelectedImagePath = "Item/ForgotPswList.png";
frameAnimate.AddChidren(btnPic);
var btnEmail = new NormalViewControl(450, 58, true);
btnEmail.X = this.GetPictrueRealSize(46);
btnEmail.Y = this.GetPictrueRealSize(32);
btnEmail.TextColor = UserCenterColor.Current.TextGrayColor3;
btnEmail.Text = HdlUserCenterResourse.UserInfo.UserEmail;
frameAnimate.AddChidren(btnEmail);
frameAnimate.ButtonClickEvent += (sender, e) =>
{
frameTran.Visible = false;
string oldValue = txtPhone.Text;
txtPhone.Text = btnEmail.Text;
btnEmail.Text = oldValue;
//当前选择的方式
this.strPhoneEmail = txtPhone.Text;
};
rowPhone.ButtonClickEvent += (sender, e) =>
{
if (frameTran.Visible == false)
{
frameTran.Visible = true;
}
};
}
#endregion
#region ■ 发送验证码_________________________
///
/// 发送验证码
///
///
private void SetVerificationCode(NormalViewControl btnCode)
{
var errorMsg = string.Empty;
if (this.strPhoneEmail.StartsWith("+") == true)
{
//手机
errorMsg = HdlAccountLogic.Current.SendVeriCodeToPhone(HdlUserCenterResourse.UserInfo.PhoneAreaCode, HdlUserCenterResourse.UserInfo.UserPhone, VerCodeType.A其他);
}
else
{
//邮箱
errorMsg = HdlAccountLogic.Current.SendVeriCodeToEmail(HdlUserCenterResourse.UserInfo.UserEmail, VerCodeType.A其他);
}
if (errorMsg != null)
{
this.ShowMassage(ShowMsgType.Tip, errorMsg);
return;
}
//可以开始校验验证码了
this.canCheckCode = true;
//控件不能再次按下
btnCode.CanClick = false;
btnCode.BackgroundColor = 0xfffebca9;
//?s后重发
string repeat = Language.StringByID(R.MyInternationalizationString.RepeatSend1);
//有效时间60秒
int waitime = 60;
btnCode.Text = waitime + "s" + repeat;
HdlThreadLogic.Current.RunThread(() =>
{
while (this.Parent != null)
{
waitime--;
System.Threading.Thread.Sleep(1000);
if (waitime == 0)
{
HdlThreadLogic.Current.RunMain(() =>
{
if (btnCode != null)
{
//获取验证码
btnCode.TextID = R.MyInternationalizationString.uGetVerificationCode;
//按键可以按下
btnCode.CanClick = true;
btnCode.BackgroundColor = UserCenterColor.Current.TextOrangeColor;
}
});
break;
}
HdlThreadLogic.Current.RunMain(() =>
{
if (btnCode != null)
{
btnCode.Text = waitime + "s" + repeat;
}
}, ShowErrorMode.NO);
}
});
}
#endregion
#region ■ 验证码事件_________________________
///
/// 验证码事件
///
///
///
private void txtCodeValueChangedEvent(View control, string value)
{
if (btnMsgControl.Visible == true)
{
btnMsgControl.Visible = false;
}
//验证码长度
int CodeLength = 6;
if (value.Length < CodeLength)
{
return;
}
if (value.Length == CodeLength)
{
//还不能检测验证码
if (this.canCheckCode == false)
{
btnMsgControl.Visible = true;
return;
}
var txtCode = (TextInputControl)control;
//终止事件
txtCode.TextChangeEventHandler -= this.txtCodeValueChangedEvent;
//验证验证码
this.CheckVerificationCode(txtCode, value);
}
}
#endregion
#region ■ 校验验证码_________________________
///
/// 验证验证码
///
///
private void CheckVerificationCode(TextInputControl txtCode, string code)
{
string account = this.strPhoneEmail.StartsWith("+") == true ? HdlUserCenterResourse.UserInfo.UserPhone : HdlUserCenterResourse.UserInfo.UserEmail;
var result = HdlAccountLogic.Current.CheckVeriCode(account, VerCodeType.A其他, code);
if (result == false)
{
//验证码错误,请重新输入
this.btnMsgControl.Visible = true;
//事件还原
txtCode.TextChangeEventHandler += this.txtCodeValueChangedEvent;
return;
}
//自身关闭
this.CloseForm();
//指定新建密码模式
this.LoadFormMethodByName("EditorSecondaryPasswordForm", "SetNewPasswordFormMode");
this.LoadFormMethodByName("EditorGesturePasswordForm", "SetNewPasswordFormMode");
}
#endregion
}
}