using System;
using Shared;
using HDL_ON.UI.CSS;
using HDL_ON.DAL.Server;
using System.Threading;
namespace HDL_ON.UI
{
public partial class ResetPasswordPage : FrameLayout
{
///
/// 是否手机
///
public bool isPhone;
///
/// 账号
///
public string account;
///
/// 验证码
///
public string verCode;
#region 控件View
///
/// 密码文本框
///
EditText etPassword;
///
/// 确认密码文本框
///
EditText etRepeatPassword;
///
/// 修改按钮
///
Button btnReset;
///
///
///
FrameLayout bodyView;
///
/// 是否点击了返回,用于屏蔽EditText失去焦点检测事件
///
bool isHitBack;
#endregion
public ResetPasswordPage()
{
bodyView = this;
}
public void LoadPage()
{
bodyView.BackgroundColor = CSS_Color.BackgroundColor;
Action backAction = () =>
{
isHitBack = true;
};
new TopViewDiv(bodyView, Language.StringByID(StringId.ModifyPassword)).LoadTopView(backAction);
#region 新密码
FrameLayout rowView = new FrameLayout()
{
Y = Application.GetRealHeight(64),
Height = Application.GetRealHeight(50),
BackgroundColor = CSS_Color.MainBackgroundColor,
};
bodyView.AddChidren(rowView);
//新密码
Button btnTitle = new Button()
{
X = Application.GetRealWidth(16),
Width = Application.GetRealWidth(180),
TextColor = CSS_Color.FirstLevelTitleColor,
TextSize = CSS_FontSize.SubheadingFontSize,
TextAlignment = TextAlignment.CenterLeft,
Text = Language.StringByID(StringId.NewPassword) + ":"
};
rowView.AddChidren(btnTitle);
etPassword = new EditText()
{
Width = Application.GetRealWidth(359),
TextColor = CSS_Color.PromptingColor1,
TextSize = CSS_FontSize.TextFontSize,
SecureTextEntry = true,
TextAlignment = TextAlignment.CenterRight,
Foucs = true
};
rowView.AddChidren(etPassword);
var lineView = new LineView(rowView.Height);
rowView.AddChidren(lineView);
#endregion
#region 再次输入新密码
FrameLayout rowView2 = new FrameLayout()
{
Y = rowView.Bottom,
Height = Application.GetRealHeight(50),
BackgroundColor = CSS_Color.MainBackgroundColor,
};
bodyView.AddChidren(rowView2);
//再次输入新密码
Button btnTitle2 = new Button()
{
X = Application.GetRealWidth(16),
Width = Application.GetRealWidth(180),
TextColor = CSS_Color.FirstLevelTitleColor,
TextSize = CSS_FontSize.SubheadingFontSize,
TextAlignment = TextAlignment.CenterLeft,
//TextID = StringId.NewPasswordAgain,
Text = Language.StringByID(StringId.NewPasswordAgain) + ":"
};
rowView2.AddChidren(btnTitle2);
etRepeatPassword = new EditText()
{
Width = Application.GetRealWidth(359),
TextColor = CSS_Color.PromptingColor1,
TextSize = CSS_FontSize.TextFontSize,
SecureTextEntry = true,
TextAlignment = TextAlignment.CenterRight,
};
rowView2.AddChidren(etRepeatPassword);
#endregion
btnReset = new Button()
{
Gravity = Gravity.CenterHorizontal,
Y = Application.GetRealHeight(224),
Width = Application.GetRealWidth(220),
Height = Application.GetRealWidth(44),
Radius = (uint)Application.GetRealWidth(22),
SelectedBackgroundColor = CSS_Color.MainColor,
BackgroundColor = CSS_Color.PromptingColor1,
TextID = StringId.Confirm,
TextSize = CSS_FontSize.SubheadingFontSize,
TextColor = CSS_Color.MainBackgroundColor,
TextAlignment = TextAlignment.Center,
};
bodyView.AddChidren(btnReset);
LoadEvent_Reset();
LoadEvent_EditTextFcousChange();
}
}
public partial class ResetPasswordPage
{
///
/// 指定关闭页面个数
///
///
void ClosePageWithCount(int countPage)
{
//关闭多少个页面
for (int i = 0; i < countPage; i++)
{
MainPage.BasePageView.GetChildren(MainPage.BasePageView.ChildrenCount - 1).RemoveFromParent();
}
}
///
///
///
///
void ResetPassword(string password)
{
//校验密码是否符合要求
if (etPassword.Text.Trim().Length < 6 || etPassword.Text.Trim().Length > 13)
{
new Tip()
{
CloseTime = 1,
Direction = AMPopTipDirection.None,
Text = Language.StringByID(StringId.PasswordIsUnqualified)
}.Show(bodyView);
return;
}
//校验两次输入的密码是否一致
if (etPassword.Text.Trim() != etRepeatPassword.Text.Trim())
{
new Tip()
{
CloseTime = 1,
Direction = AMPopTipDirection.None,
MaxWidth = Application.GetRealWidth(300),
Text = Language.StringByID(StringId.IncorrectRepeatPassword)
}.Show(bodyView);
return;
}
var waitPage = new Loading();
bodyView.AddChidren(waitPage);
waitPage.Start(Language.StringByID(StringId.PleaseWait));
new Thread(() =>
{
try
{
// 忘记密码
var resultObj = new HttpServerRequest().ForgetPassword(account, password, verCode, isPhone);
if (resultObj.Code == StateCode.SUCCESS)
{
Application.RunOnMainThread(() =>
{
Utlis.ShowTip(Language.StringByID(StringId.PasswordChangeSuccessfully));
ClosePageWithCount(2);
});
}
else
{
// 提示错误
IMessageCommon.Current.ShowErrorInfoAlter(resultObj.Code);
}
}
catch { }
finally
{
Application.RunOnMainThread(() =>
{
if (waitPage != null)
{
waitPage.RemoveFromParent();
waitPage = null;
}
});
}
})
{ IsBackground = true }.Start();
}
///
/// 加载方式按钮事件
///
void LoadEvent_Reset()
{
btnReset.MouseUpEventHandler += (sender, e) =>
{
if (btnReset.IsSelected)
{
ResetPassword(etPassword.Text.ToString());
}
};
}
///
/// 加载文本框焦点变化事件
///
void LoadEvent_EditTextFcousChange() {
//密码文本框焦点变化事件
etPassword.FoucsChanged += (sender, e) =>
{
if (etPassword.Foucs)
{
}
else
{
if (isHitBack) return;//点击返回关闭页面不检测提示
if (etPassword.Text.Length == 0) return;//没输入不检测提示
//校验密码是否符合要求
if (etPassword.Text.Trim().Length < 6 || etPassword.Text.Trim().Length > 13)
{
new Tip()
{
CloseTime = 1,
Direction = AMPopTipDirection.None,
Text = Language.StringByID(StringId.PasswordIsUnqualified)
}.Show(bodyView);
}
else
{
LoadMothed_EnableResetButton();
}
}
};
//确认密码文本框焦点变化事件
etRepeatPassword.FoucsChanged += (sender, e) =>
{
if (etRepeatPassword.Foucs)
{
}
else
{
if (isHitBack) return;//点击返回关闭页面不检测提示
if (etRepeatPassword.Text.Length == 0) return;//没输入不检测提示
//校验两次输入的密码是否一致
if (etPassword.Text.Trim() != etRepeatPassword.Text.Trim())
{
new Tip()
{
CloseTime = 1,
Direction = AMPopTipDirection.None,
MaxWidth = Application.GetRealWidth(300),
Text = Language.StringByID(StringId.IncorrectRepeatPassword)
}.Show(bodyView);
}
else
{
LoadMothed_EnableResetButton();
}
}
};
Action textChangeEventHandler = (view, textStr) =>
{
LoadMothed_EnableResetButton();
};
etPassword.TextChangeEventHandler += textChangeEventHandler;
etRepeatPassword.TextChangeEventHandler += textChangeEventHandler;
}
///
/// 使能修改确定按钮
///
void LoadMothed_EnableResetButton()
{
if (!string.IsNullOrEmpty(etPassword.Text) && (etPassword.Text.Trim() == etRepeatPassword.Text.Trim()))
{
btnReset.IsSelected = true;
}
else
{
btnReset.IsSelected = false;
}
}
}
}