using System;
using System.Collections.Generic;
using System.Text;
namespace Shared.Phone.UserCenter.Password
{
///
/// 验证原手机的画面
///
public class CheckOldPhoneForm : EditorCommonForm
{
#region ■ 变量声明___________________________
///
/// 错误信息控件
///
private NormalViewControl btnErrorMsg = null;
///
/// 标记是否能够校验验证码了
///
private bool canCheckCode = false;
#endregion
#region ■ 初始化_____________________________
///
/// 画面显示(底层会固定调用此方法,借以完成画面创建)
///
public void ShowForm()
{
//设定标题
base.SetTitleText(Language.StringByID(R.MyInternationalizationString.uEditorPhoneNumber));
//初始化中部控件
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.uHadBindPhoneNumber;
bodyFrameLayout.AddChidren(btnMsg1);
//手机
var btnPhone = new NormalViewControl(bodyFrameLayout.Width, Application.GetRealHeight(55), false);
btnPhone.TextColor = UserCenterColor.Current.TextGrayColor3;
btnPhone.TextAlignment = TextAlignment.Center;
btnPhone.TextSize = 16;
btnPhone.Text = UserCenterResourse.UserInfo.Email;
btnPhone.Y = btnMsg1.Bottom + Application.GetRealHeight(12);
bodyFrameLayout.AddChidren(btnPhone);
if (UserCenterResourse.UserInfo.Phone.Length >= 11)
{
var phone = UserCenterResourse.UserInfo.Phone;
phone = phone.Substring(0, 3) + "".PadLeft(phone.Length - 7, '*') + phone.Substring(phone.Length - 4, 4);
btnPhone.Text = "+" + UserCenterResourse.UserInfo.AreaCode + " " + phone;
}
else
{
//或许这是国外的手机吧
var phone = UserCenterResourse.UserInfo.Phone;
phone = phone.Substring(0, 3) + "".PadLeft(phone.Length - 5, '*') + phone.Substring(phone.Length - 2, 2);
btnPhone.Text = "+" + UserCenterResourse.UserInfo.AreaCode + " " + phone;
}
//修改手机号前,请输入验证码确认您的身份
var btnMsg2 = new NormalViewControl(bodyFrameLayout.Width, Application.GetRealHeight(49), false);
btnMsg2.Y = btnPhone.Bottom + Application.GetRealHeight(37);
btnMsg2.TextAlignment = TextAlignment.Center;
btnMsg2.TextSize = 12;
btnMsg2.TextColor = UserCenterColor.Current.TextGrayColor1;
btnMsg2.TextID = R.MyInternationalizationString.uCheckAuthenticationBeforeEditorPhoneNumber;
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) =>
{
//校验验证码
this.CheckVerificationCode(value);
};
//验证码错误,请重新输入
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.SendCodeToPhone(btnNext);
};
}
#endregion
#region ■ 发送验证码到手机___________________
///
/// 发送验证码到手机
///
private void SendCodeToPhone(BottomClickButton btnNext)
{
var sendCodePra = new SendCodePra();
bool flage = UserCenterLogic.GetResultStatuByRequestHttps("ZigbeeUsers/LoginSendVerCode", false, sendCodePra);
if (flage == false)
{
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)
{
Application.RunOnMainThread(() =>
{
if (btnNext != null)
{
//获取验证码
btnNext.TextID = R.MyInternationalizationString.uGetVerificationCode;
//按键可以按下
btnNext.CanClick = true;
}
});
break;
}
Application.RunOnMainThread(() =>
{
if (btnNext != null)
{
btnNext.Text = waitime + "s" + repeat;
}
});
}
});
}
#endregion
#region ■ 校验验证码_________________________
///
/// 验证验证码
///
///
private void CheckVerificationCode(string code)
{
if (this.canCheckCode == false)
{
//验证码错误,请重新输入
this.btnErrorMsg.Visible = true;
return;
}
var checkCodePra = new CheckCodePra();
checkCodePra.Code = code;
bool flage = UserCenterLogic.GetResultStatuByRequestHttps("ZigbeeUsers/ValidatorCode", false, checkCodePra);
if (flage == false)
{
//验证码错误,请重新输入
this.btnErrorMsg.Visible = true;
return;
}
var from = new CheckNewPhoneForm();
base.AddFromAndRemoveNowForm(from);
}
#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 = 0;
}
#endregion
}
}