using System;
namespace Shared.Phone.UserCenter
{
///
/// 密码错误信息提示控件
///
public class PswErrorRowLayout : RowLayout
{
///
/// 现阶段是否错误
///
public bool IsError = true;
///
/// 密码长度不低于8位数
///
private Button btnLength = null;
///
/// 至少有一个大写字母
///
private Button btnUpper = null;
///
/// 至少有一个小写字母
///
private Button btnLower = null;
///
/// 至少有一个数字或符号
///
private Button btnNumber = null;
///
/// 其它
///
private Button btnOther = null;
///
/// 正确的图标
///
private string rightIcon = "√ ";
///
/// 错误的图标
///
private string wrongIcon = "× ";
///
/// 密码长度不低于8位数
///
private string LengthMsg = Language.StringByID(R.MyInternationalizationString.PswLengthMsg);
///
/// 至少有一个大写字母
///
private string UpperMsg = Language.StringByID(R.MyInternationalizationString.PswLowerMsg);
///
/// 至少有一个小写字母
///
private string LowerMsg = Language.StringByID(R.MyInternationalizationString.PswLowerMsg);
///
/// 至少有一个数字或符号
///
private string NumberMsg = Language.StringByID(R.MyInternationalizationString.PswNumberMsg);
///
/// 初始化
///
/// Width.
/// Height.
public void Init(int width = 300, int height = 35)
{
//X轴偏移量
//int XX = UserCenterResourse.XXLeft;
//btnLength = UserCenterControls.MakeViewButton(width, height, true);
//btnLength.X = XX;
//btnLength.Y = Application.GetRealHeight(6);
//btnLength.TextAlignment = TextAlignment.CenterLeft;
//btnLength.TextColor = UserCenterColor.Current.Red;
//btnLength.Text = wrongIcon + LengthMsg;
//this.AddChidren(btnLength);
//btnUpper = UserCenterControls.MakeViewButton(width, height, true);
//btnUpper.X = XX;
//btnUpper.Y = btnLength.Bottom + Application.GetRealHeight(6);
//btnUpper.TextAlignment = TextAlignment.CenterLeft;
//btnUpper.TextColor = UserCenterColor.Current.Red;
//btnUpper.Text = wrongIcon + UpperMsg;
//this.AddChidren(btnUpper);
//btnLower = UserCenterControls.MakeViewButton(width, height, true);
//btnLower.X = XX;
//btnLower.Y = btnUpper.Bottom + Application.GetRealHeight(6);
//btnLower.TextAlignment = TextAlignment.CenterLeft;
//btnLower.TextColor = UserCenterColor.Current.Red;
//btnLower.Text = wrongIcon + LowerMsg;
//this.AddChidren(btnLower);
//btnNumber = UserCenterControls.MakeViewButton(width, height, true);
//btnNumber.X = XX;
//btnNumber.Y = btnLower.Bottom + Application.GetRealHeight(6);
//btnNumber.TextAlignment = TextAlignment.CenterLeft;
//btnNumber.TextColor = UserCenterColor.Current.Red;
//btnNumber.Text = wrongIcon + NumberMsg;
//this.AddChidren(btnNumber);
//btnOther = UserCenterControls.MakeViewButton(width, height, true);
//btnOther.X = XX;
//btnOther.Y = btnNumber.Bottom + Application.GetRealHeight(6);
//btnOther.TextAlignment = TextAlignment.CenterLeft;
//btnOther.TextColor = UserCenterColor.Current.Red;
//this.AddChidren(btnOther);
}
///
/// 密码检测
///
/// true, if password was checked, false otherwise.
/// Password.
public bool CheckPassword(string password)
{
btnOther.Visible = false;
//判断密码长度
bool flag1 = password.Length >= 8;
if (flag1)
{
btnLength.TextColor = UserCenterColor.Current.Green;
btnLength.Text = rightIcon + LengthMsg;
}
else
{
btnLength.TextColor = UserCenterColor.Current.Red;
btnLength.Text = wrongIcon + LengthMsg;
}
//判断是否包含大写字母
bool flag2 = UserCenterLogic.CheckContainUpper(password);
if (flag2 == true)
{
btnUpper.TextColor = UserCenterColor.Current.Green;
btnUpper.Text = rightIcon + UpperMsg;
}
else
{
btnUpper.TextColor = UserCenterColor.Current.Red;
btnUpper.Text = wrongIcon + UpperMsg;
}
//判断是否包含小写字母
bool flag3 = UserCenterLogic.CheckContainLower(password);
if (flag3 == true)
{
btnLower.TextColor = UserCenterColor.Current.Green;
btnLower.Text = rightIcon + LowerMsg;
}
else
{
btnLower.TextColor = UserCenterColor.Current.Red;
btnLower.Text = wrongIcon + LowerMsg;
}
//判断是否包含数字或者符号
bool flag4 = UserCenterLogic.CheckContainNum(password);
bool flag5 = UserCenterLogic.CheckContainSymbol(password);
if (flag4 == true && flag5 == true)
{
btnNumber.TextColor = UserCenterColor.Current.Green;
btnNumber.Text = rightIcon + NumberMsg;
}
else
{
btnNumber.TextColor = UserCenterColor.Current.Red;
btnNumber.Text = wrongIcon + NumberMsg;
}
IsError = flag1 && flag2 && flag3 && flag4 && flag5;
return IsError;
}
///
/// 在最后一行显示其它错误信息
///
/// Error.
public void ShowOtherError(string error)
{
IsError = true;
btnOther.Text = wrongIcon + error;
btnOther.Visible = true;
}
}
}