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 = -ControlCommonResourse.XXLeft;
rowPhone.Y = Application.GetRealHeight(23);
rowPhone.Width = this.GetPictrueRealSize(628);
bodyFrameLayout.AddChidren(rowPhone);
//请输入邮箱或手机号
string phoneValue = string.IsNullOrEmpty(UserCenterResourse.UserInfo.Phone) == true ? string.Empty : "+" + UserCenterResourse.UserInfo.AreaCode + " " + UserCenterResourse.UserInfo.Phone;
var txtPhone = rowPhone.AddLeftCaption(string.IsNullOrEmpty(phoneValue) == true ? UserCenterResourse.UserInfo.Email : 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 = ControlCommonResourse.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(UserCenterResourse.UserInfo.Phone) == true
|| string.IsNullOrEmpty(UserCenterResourse.UserInfo.Email) == 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 = ControlCommonResourse.XXLeft - Application.GetRealWidth(17);
frameList.Y = rowPhone.Bottom - ControlCommonResourse.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 = UserCenterResourse.UserInfo.Email;
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)
{
string account = this.strPhoneEmail.StartsWith("+") == true ? UserCenterResourse.UserInfo.Phone : UserCenterResourse.UserInfo.Email;
var sendCodePra = new SendCodePra();
sendCodePra.Account = account;
sendCodePra.AreaCode = Convert.ToInt32(UserCenterResourse.UserInfo.AreaCode);
bool flage = UserCenterLogic.GetResultStatuByRequestHttps("ZigbeeUsers/ForgetPassword", false, sendCodePra);
if (flage == false)
{
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)
{
Application.RunOnMainThread(() =>
{
if (btnCode != null)
{
//获取验证码
btnCode.TextID = R.MyInternationalizationString.uGetVerificationCode;
//按键可以按下
btnCode.CanClick = true;
btnCode.BackgroundColor = UserCenterColor.Current.TextOrangeColor;
}
});
break;
}
Application.RunOnMainThread(() =>
{
if (btnCode != null)
{
btnCode.Text = waitime + "s" + repeat;
}
});
}
});
}
#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 ? UserCenterResourse.UserInfo.Phone : UserCenterResourse.UserInfo.Email;
var checkCodePra = new CheckCodePra();
checkCodePra.Code = code;
checkCodePra.Account = account;
bool flage = UserCenterLogic.GetResultStatuByRequestHttps("ZigbeeUsers/ValidatorCode", false, checkCodePra);
if (flage == false)
{
//验证码错误,请重新输入
this.btnMsgControl.Visible = true;
//事件还原
txtCode.TextChangeEventHandler += this.txtCodeValueChangedEvent;
return;
}
//自身关闭
this.CloseForm();
//指定新建密码模式
this.LoadFormMethodByName("EditorSecondaryPasswordForm", "SetNewPasswordFormMode");
this.LoadFormMethodByName("EditorGesturePasswordForm", "SetNewPasswordFormMode");
}
#endregion
#region ■ 结构体_____________________________
///
/// 发送验证码的启动参数
///
private class SendCodePra
{
///
/// 用户账号
///
public string Account = UserCenterResourse.UserInfo.Phone;
///
/// 公司编号,国内使用手机短信验证码时,此字段填入0,国外手机短信验证码,此字段填入4
///
public int Company = Common.CommonPage.PhoneZoneStr == "86" ? 0 : 4;
///
/// 语言
///
public string Language = Shared.Language.CurrentLanguage;
///
/// 国家地区代码,手机号发送验证码时使用
///
public int AreaCode = 0;
}
///
/// 发送验证码的启动参数
///
private class CheckCodePra
{
///
/// 用户账号
///
public string Account = UserCenterResourse.UserInfo.Phone;
///
/// 验证码
///
public string Code = "0";
///
/// 语言
///
public string Language = Shared.Language.CurrentLanguage;
///
/// 国家地区代码,手机号发送验证码时使用
///
public int AreaCode = Convert.ToInt32(UserCenterResourse.UserInfo.AreaCode);
}
#endregion
}
}