using System; //using service.hdlcontrol.com_push; namespace Shared.SimpleControl.Phone { public class AccountModifyPassword : FrameLayout { public AccountModifyPassword () { BackgroundColor = SkinStyle.Current.MainColor; } public void ShowAccountModifyPassword () { #region 标题 var topView = new FrameLayout () { Y = Application.GetRealHeight (36), Height = Application.GetRealHeight (90), }; AddChidren (topView); var title = new Button () { TextAlignment = TextAlignment.Center, Text = Language.StringByID (R.MyInternationalizationString.Account), TextSize = 19, TextColor = SkinStyle.Current.TextColor1 }; topView.AddChidren (title); var logo = new Button () { Width = Application.GetRealWidth (154), Height = Application.GetRealHeight (90), X = Application.GetRealWidth (486), UnSelectedImagePath = MainPage.LogoString, Gravity = Gravity.CenterVertical, }; topView.AddChidren (logo); var back = new Button () { Height = Application.GetRealHeight (90), Width = Application.GetRealWidth (85), UnSelectedImagePath = "Item/Back.png", Gravity = Gravity.CenterVertical, }; topView.AddChidren (back); back.MouseUpEventHandler += (sender, e) => { UserMiddle.SettingPageView.PageIndex = UserMiddle.SettingPageView.ChildrenCount - 2; }; #endregion var BodyView = new FrameLayout () { Width = LayoutParams.MatchParent, Height = Application.GetRealHeight (1136 - 126), Y = topView.Bottom, BackgroundColor = SkinStyle.Current.ViewColor, }; AddChidren (BodyView); Button btnCurEmail = new Button () { Height = Application.GetRealHeight (140), Text = MainPage.LoginUser.AccountString, Enable = false, TextColor = SkinStyle.Current.TextColor1 }; BodyView.AddChidren (btnCurEmail); var ResetPasswrodView = new FrameLayout () { Height = Application.GetRealHeight (1136 - 126 - 140) }; BodyView.AddChidren (ResetPasswrodView); var viewX = (Application.GetRealWidth (640) - Application.GetMinRealAverage (500)) / 2; var curPasswordView = new FrameLayout () { Width = Application.GetMinRealAverage (500), Height = Application.GetMinRealAverage (90), X = viewX, Y = Application.GetRealHeight (200), BackgroundImagePath = "Register/Register_Password_kuang.png", }; ResetPasswrodView.AddChidren (curPasswordView); var etCurPassword = new EditText () { Width = Application.GetRealWidth (400), X = Application.GetRealWidth (100), PlaceholderTextColor = SkinStyle.Current.PlaceholderTextColor, PlaceholderText = Language.StringByID (R.MyInternationalizationString.PleaseEnterOldPassword), TextAlignment = TextAlignment.CenterLeft, SecureTextEntry = true, TextColor = SkinStyle.Current.TextColor1, }; curPasswordView.AddChidren (etCurPassword); var newPasswordView = new FrameLayout () { Width = Application.GetMinRealAverage (500), Height = Application.GetMinRealAverage (90), X = viewX, Y = curPasswordView.Bottom + Application.GetRealHeight (70), BackgroundImagePath = "Register/Register_Password_kuang.png", Radius = (uint)Application.GetRealHeight (0), }; ResetPasswrodView.AddChidren (newPasswordView); var etNewPassword = new EditText () { Width = Application.GetRealWidth (400), X = Application.GetRealWidth (100), PlaceholderTextColor = SkinStyle.Current.PlaceholderTextColor, PlaceholderText = Language.StringByID (R.MyInternationalizationString.PleaseSetNewPasword), TextAlignment = TextAlignment.CenterLeft, TextColor = SkinStyle.Current.TextColor1, SecureTextEntry = true }; newPasswordView.AddChidren (etNewPassword); var confrimFpasswordView = new FrameLayout () { Width = Application.GetMinRealAverage (500), Height = Application.GetMinRealAverage (90), X = viewX, Y = newPasswordView.Bottom + Application.GetRealHeight (70), BackgroundImagePath = "Register/Register_Password_kuang.png", }; ResetPasswrodView.AddChidren (confrimFpasswordView); var etConfrimPassword = new EditText () { Width = Application.GetRealWidth (400), Height = Application.GetRealHeight (90), X = Application.GetRealWidth (100), PlaceholderTextColor = SkinStyle.Current.PlaceholderTextColor, PlaceholderText = Language.StringByID (R.MyInternationalizationString.PleaseConfirmNewPassword), TextAlignment = TextAlignment.CenterLeft, TextColor = SkinStyle.Current.TextColor1, SecureTextEntry = true }; confrimFpasswordView.AddChidren (etConfrimPassword); Button btnSave = new Button () { Width = Application.GetRealWidth (500), Height = Application.GetRealHeight (89), X = Application.GetRealWidth (70), Y = Application.GetRealHeight (750), BackgroundColor = SkinStyle.Current.ButtonColor, SelectedBackgroundColor = SkinStyle.Current.SelectedColor, TextID = R.MyInternationalizationString.SAVE, TextColor = SkinStyle.Current.TextColor1, TextSize = 16, }; ResetPasswrodView.AddChidren (btnSave); var tipConfrimPW = new Tip () { MaxWidth = 250, Text = Language.StringByID (R.MyInternationalizationString.NewCipherInconsistencies), Direction = AMPopTipDirection.Up, CloseTime = 20 }; var tipConfrimShort = new Tip () { MaxWidth = 250, Text = Language.StringByID (R.MyInternationalizationString.PasswordLenghtTip), Direction = AMPopTipDirection.Up, CloseTime = 3 }; etConfrimPassword.TextChangeEventHandler += (sender, e) => { if (etNewPassword.Text.Trim ().Length == etConfrimPassword.Text.Trim ().Length) { if (etNewPassword.Text.Trim () != etConfrimPassword.Text.Trim ()) { tipConfrimPW.Show (etConfrimPassword); } else { } } }; btnSave.MouseDownEventHandler += (sender, e) => { btnSave.IsSelected = true; }; btnSave.MouseUpEventHandler += (sender, e) => { try { btnSave.IsSelected = false; if (MainPage.LoginUser == null) { return; } if (string.IsNullOrEmpty (etNewPassword.Text.Trim ())) { new Alert ("", Language.StringByID (R.MyInternationalizationString.NewPasswordIsEmpty), Language.StringByID (R.MyInternationalizationString.Close)).Show (); } else if (!string.IsNullOrEmpty(MainPage.LoginUser.Name) && etNewPassword.Text.Trim ().Contains (MainPage.LoginUser.Name)) { //密码不能包含用户名 new Alert ("", ErrorCode.PasswordNotUsername, Language.StringByID (R.MyInternationalizationString.Close)).Show (); return; } else if (!CommonUtlis.Current.CheckPassword (etNewPassword.Text.Trim ())) { new Alert ("", ErrorCode.PasswordStrengthNotMatch, Language.StringByID (R.MyInternationalizationString.Close)).Show (); //return; } else if (etNewPassword.Text.Trim () != etConfrimPassword.Text.Trim ()) { new Alert ("", Language.StringByID (R.MyInternationalizationString.PleaseConfirmPasswordIsCorrect), Language.StringByID (R.MyInternationalizationString.Close)).Show (); } else { string oldPassword = etCurPassword.Text.Trim (); string newPassword = etNewPassword.Text.Trim (); ModifyPassword (oldPassword, newPassword); } } catch (Exception ex) { new Alert ("", Language.StringByID (R.MyInternationalizationString.CheckInternet), Language.StringByID (R.MyInternationalizationString.Close)).Show (); string mess = ex.Message; } }; etCurPassword.EditorEnterAction += (obj) => { etNewPassword.Foucs = true; }; etNewPassword.EditorEnterAction += (obj) => { Application.HideSoftInput (); etConfrimPassword.Foucs = true; }; etConfrimPassword.EditorEnterAction += (obj) => { Application.HideSoftInput (); }; } /// /// 修改密码 /// /// /// void ModifyPassword (string oldPassword, string newPassword) { MainPage.Loading.Start (""); System.Threading.Tasks.Task.Run (() => { try { var revertObj = HttpServerRequest.Current.ModifyPassword (oldPassword, newPassword); if (revertObj.Code == StateCode.SUCCESS) { //var md5Password = Utlis.MD5Encrypt (newPassword); MainPage.LoginUser.Password = newPassword; MainPage.LoginUser.SaveUserInfo (); Application.RunOnMainThread (() => { this.RemoveFromParent (); Utlis.ShowAlertOnMainThread (Language.StringByID (R.MyInternationalizationString.PasswordModificationSuccess)); //new Alert (Language.StringByID (R.MyInternationalizationString.Tip), Language.StringByID (R.MyInternationalizationString.PasswordModificationSuccess), Language.StringByID (R.MyInternationalizationString.Close)).Show (); }); } else { //提示错误 IMessageCommon.Current.ShowErrorInfoAlter (revertObj.Code); } } catch { MainPage.FailureToServer (); } finally { Application.RunOnMainThread (() => { MainPage.Loading.Hide (); }); } }); } } }