using System; using System.Text.RegularExpressions; namespace Shared.SimpleControl.Phone { public class ForgotPassword : Dialog { PageLayout bodyPageView; /// /// 构造函数 /// public ForgotPassword () { BackgroundColor = SkinStyle.Current.MainColor; ForgotPasswordShow (); } void ForgotPasswordShow () { #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.ForgotPassword), 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", //SelectedImagePath = "Item/BackSelected.png", Gravity = Gravity.CenterVertical, }; topView.AddChidren (back); back.MouseUpEventHandler += (sender, e) => { new AccountLogin ().Show (); Close (); }; #endregion bodyPageView = new PageLayout () { Width = LayoutParams.MatchParent, Height = Application.GetRealHeight (Application.DesignHeight - 126), Y = topView.Bottom, BackgroundColor = SkinStyle.Current.ViewColor, }; AddChidren (bodyPageView); bodyPageView.PageChange += ( sender, e) => { if (bodyPageView.ChildrenCount - 2 == e) { bodyPageView.RemoveAt (bodyPageView.ChildrenCount - 1); } Console.WriteLine ("D" + e.ToString ()); }; FrameLayout bodyView = new FrameLayout (); bodyPageView.AddChidren (bodyView); bodyPageView.IsShowPoint = false; FrameLayout languageView = new FrameLayout () { Gravity = Gravity.CenterHorizontal, Y = Application.GetRealHeight (20), Width = Application.GetRealWidth (500), Height = Application.GetRealHeight (85), Radius = 5, BorderColor = SkinStyle.Current.Transparent, BorderWidth = 0, }; bodyView.AddChidren (languageView); Button btnEmailRegistration = new Button () { Width = Application.GetRealWidth (250), BackgroundColor = SkinStyle.Current.SubtitleView, SelectedBackgroundColor = SkinStyle.Current.SelectedColor, TextID = R.MyInternationalizationString.MailboxAccount, TextAlignment = TextAlignment.Center, IsSelected = true, TextColor = SkinStyle.Current.TextColor2, }; languageView.AddChidren (btnEmailRegistration); Button btnPhoneRegistration = new Button () { X = btnEmailRegistration.Right, Width = Application.GetRealWidth (250), BackgroundColor = SkinStyle.Current.SubtitleView, SelectedBackgroundColor = SkinStyle.Current.SelectedColor, TextID = R.MyInternationalizationString.MobileAccount, TextAlignment = TextAlignment.Center, TextColor = SkinStyle.Current.TextColor2, }; languageView.AddChidren (btnPhoneRegistration); FrameLayout FrameLayoutView = new FrameLayout () { Y = languageView.Bottom, Height = Application.GetRealHeight (Application.DesignHeight - 126 - 105), }; bodyView.AddChidren (FrameLayoutView); btnEmailRegistration.MouseUpEventHandler += (sender, e) => { btnEmailRegistration.IsSelected = true; btnPhoneRegistration.IsSelected = false; EmailForgot (FrameLayoutView); }; btnPhoneRegistration.MouseUpEventHandler += (sender, e) => { btnEmailRegistration.IsSelected = false; btnPhoneRegistration.IsSelected = true; PhoneReagistrationView (FrameLayoutView); }; EmailForgot (FrameLayoutView); #if longxi btnPhoneRegistration.RemoveFromParent (); btnEmailRegistration.IsSelected = false; btnEmailRegistration.BackgroundColor = SkinStyle.Current.Transparent; btnEmailRegistration.X = Application.GetRealWidth (125); #endif } void EmailForgot (FrameLayout FrameLayoutView) { FrameLayoutView.RemoveAll (); EditText Register_Email_Address = new EditText () { Width = Application.GetRealWidth (500), Height = Application.GetRealHeight (85), X = Application.GetRealWidth (70), Y = Application.GetRealHeight (100), UnSelectedImagePath = "Register/Register_Email_Address.png", PlaceholderText = Language.StringByID (R.MyInternationalizationString.EmailAddress), PlaceholderTextColor = SkinStyle.Current.PlaceholderTextColor, TextAlignment = TextAlignment.Center, Radius = (uint)Application.GetRealHeight (0), TextColor = SkinStyle.Current.TextColor1, }; FrameLayoutView.AddChidren (Register_Email_Address); Button Register_Send = new Button () { Width = Application.GetRealWidth (247), Height = Application.GetRealHeight (89), X = Application.GetRealWidth ((640 - 247) / 2), Y = Register_Email_Address.Bottom + Application.GetRealHeight (80), BackgroundColor = SkinStyle.Current.ButtonColor1, SelectedBackgroundColor = SkinStyle.Current.SelectedColor, TextID = R.MyInternationalizationString.Send, TextColor = SkinStyle.Current.TextColor2, TextAlignment = TextAlignment.Center, Radius = 5, BorderColor = SkinStyle.Current.Transparent, BorderWidth = 0, }; FrameLayoutView.AddChidren (Register_Send); Register_Send.MouseDownEventHandler += (sender, e) => { Register_Send.IsSelected = true; }; Register_Send.MouseUpEventHandler += (sender, e) => { try { MainPage.Loading.Start (Language.StringByID(R.MyInternationalizationString.load)); Register_Send.IsSelected = false; string emailAccount = Register_Email_Address.Text.Trim (); var reg = new Regex ("^\\s*([A-Za-z0-9_-]+(\\.\\w+)*@(\\w+\\.)+\\w{2,5})\\s*$"); var ss = reg.Match (emailAccount); if (!ss.Success) { new Alert (Language.StringByID (R.MyInternationalizationString.Tip), Language.StringByID (R.MyInternationalizationString.PleaseCheckEmailAddressCorrectly), Language.StringByID (R.MyInternationalizationString.Close)).Show (); } else { System.Threading.Tasks.Task.Run (() => { var requestObj = new ForgetPasswordObj () { Account = emailAccount ,Company = MainPage.SoftSmsType}; var requestJson = Newtonsoft.Json.JsonConvert.SerializeObject (requestObj); var requestRevertObj = MainPage.RequestHttps ("ForgetPassword", requestJson, false); if (requestRevertObj.StateCode == "SUCCESS") { Application.RunOnMainThread (() => { new Alert (Language.StringByID (R.MyInternationalizationString.Tip), Language.StringByID (R.MyInternationalizationString.AuthenticationMail), Language.StringByID (R.MyInternationalizationString.Close)).Show (); this.Close (); new AccountLogin (emailAccount, "").Show (); }); } }); } } catch { Application.RunOnMainThread (() => { new Alert (Language.StringByID (R.MyInternationalizationString.Tip), Language.StringByID (R.MyInternationalizationString.CheckInternet), Language.StringByID (R.MyInternationalizationString.Close)).Show (); }); } finally { Application.RunOnMainThread (() => { MainPage.Loading.Hide (); }); } }; } void PhoneReagistrationView (FrameLayout registrationView) { registrationView.RemoveAll (); Button btnPhone = new Button () { Width = Application.GetRealWidth (500), Height = Application.GetRealHeight (85), Gravity = Gravity.CenterHorizontal, Y = Application.GetRealHeight (20), TextID = R.MyInternationalizationString.PhoneNumber, TextAlignment = TextAlignment.CenterLeft, TextSize = 12, TextColor = SkinStyle.Current.TextColor1, }; registrationView.AddChidren (btnPhone); FrameLayout phoneNumView = new FrameLayout () { Width = Application.GetRealWidth (500), Height = Application.GetRealHeight (85), Gravity = Gravity.CenterHorizontal, Y = btnPhone.Bottom, BorderWidth = 1, Radius = 5, BorderColor = SkinStyle.Current.BorderColor, //Text = "1270166900@qq.com" }; registrationView.AddChidren (phoneNumView); EditText etPhoneNumber = new EditText () { TextAlignment = TextAlignment.Center, TextColor = SkinStyle.Current.TextColor1, }; phoneNumView.AddChidren (etPhoneNumber); Button btnNext = new Button () { Y = phoneNumView.Bottom + Application.GetRealHeight (20), Width = Application.GetRealWidth (500), Height = Application.GetRealHeight (85), Gravity = Gravity.CenterHorizontal, Radius = 5, BorderColor = SkinStyle.Current.Transparent, BorderWidth = 0, BackgroundColor = SkinStyle.Current.SubtitleView, SelectedBackgroundColor = SkinStyle.Current.MainColor, TextID = R.MyInternationalizationString.Next, TextAlignment = TextAlignment.Center, Enable = false, TextColor = SkinStyle.Current.TextColor2, }; registrationView.AddChidren (btnNext); btnNext.MouseUpEventHandler += (sender, e) => { string phoneNum = etPhoneNumber.Text.Trim (); MainPage.Loading.Start (Language.StringByID(R.MyInternationalizationString.load)); System.Threading.Tasks.Task.Run (() => { try { var requestObj = new SignPhoneObj () { Phone = phoneNum, Company = MainPage.SoftSmsType }; var requestJson = Newtonsoft.Json.JsonConvert.SerializeObject (requestObj); var requestRevertObj = MainPage.RequestHttps ("SignPhone", requestJson); if (requestRevertObj.StateCode == "SUCCESS") { Application.RunOnMainThread (() => { InitSMSView (phoneNum); bodyPageView.PageIndex = bodyPageView.ChildrenCount - 1; }); } } catch { MainPage.FailureToServer (); } finally { Application.RunOnMainThread (() => { MainPage.Loading.Hide (); }); } }); }; etPhoneNumber.TextChangeEventHandler += (sender, e) => { if (e.Length > 11) { etPhoneNumber.Text = e.Remove (11); return; } if (e.Length > 6) { btnNext.IsSelected = btnNext.Enable = true; Regex reg = new Regex ("^\\d+$"); var mFalg = reg.Match (etPhoneNumber.Text.Trim ()); if (mFalg.Success) { btnNext.IsSelected = btnNext.Enable = true; } else { new Tip () { CloseTime = 3, Text = Language.StringByID (R.MyInternationalizationString.PhoneNumberErorr), Direction = AMPopTipDirection.Down }.Show (etPhoneNumber); } } else if (e.Length < 6) { btnNext.IsSelected = btnNext.Enable = false; } }; } void InitSMSView (string mobileNumber) { FrameLayout smsChencView = new FrameLayout (); bodyPageView.AddChidren (smsChencView); Button btnTitle = new Button () { Gravity = Gravity.CenterHorizontal, Y = Application.GetRealHeight (50), Width = Application.GetRealWidth (500), Height = Application.GetRealHeight (85), TextID = R.MyInternationalizationString.MobileVerificationCode, TextColor = SkinStyle.Current.TextColor1, TextAlignment = TextAlignment.CenterLeft, }; smsChencView.AddChidren (btnTitle); EditText etCode = new EditText () { Width = Application.GetRealWidth (500), Height = Application.GetRealHeight (85), Gravity = Gravity.CenterHorizontal, Y = btnTitle.Bottom, BorderWidth = 1, Radius = 5, BorderColor = SkinStyle.Current.BorderColor, TextAlignment = TextAlignment.Center //Text = "1270166900@qq.com" }; smsChencView.AddChidren (etCode); Button btnNext = new Button () { Y = etCode.Bottom + Application.GetRealHeight (20), Width = Application.GetRealWidth (500), Height = Application.GetRealHeight (85), Gravity = Gravity.CenterHorizontal, Radius = 5, BorderColor = SkinStyle.Current.Transparent, BorderWidth = 0, BackgroundColor = SkinStyle.Current.SubtitleView, SelectedBackgroundColor = SkinStyle.Current.MainColor, TextID = R.MyInternationalizationString.Next, TextAlignment = TextAlignment.Center, Enable = false, TextColor = SkinStyle.Current.TextColor1, }; smsChencView.AddChidren (btnNext); etCode.TextChangeEventHandler += (sender, e) => { if (e.Length > 6) { etCode.Text = e.Remove (6); } else if (e.Length == 6) { btnNext.IsSelected = btnNext.Enable = true; } else { btnNext.IsSelected = btnNext.Enable = false; } }; btnNext.MouseUpEventHandler += (sender, e) => { string vCode = etCode.Text.Trim (); MainPage.Loading.Start (Language.StringByID(R.MyInternationalizationString.load)); System.Threading.Tasks.Task.Run (() => { try { var requestObj = new ValidateSmsCodeObj () { Phone = mobileNumber, Code = vCode }; var requestJson = Newtonsoft.Json.JsonConvert.SerializeObject (requestObj); var requestRevertObj = MainPage.RequestHttps ("ValidateSmsCode", requestJson, false); if (requestRevertObj.StateCode == "SUCCESS") { Application.RunOnMainThread (() => { InitMobilePasswrod (mobileNumber); bodyPageView.PageIndex = bodyPageView.ChildrenCount - 1; }); } } catch { MainPage.FailureToServer (); } finally { Application.RunOnMainThread (() => { MainPage.Loading.Hide (); }); } }); }; } void InitMobilePasswrod (string mobileNumber) { FrameLayout mobileChencView = new FrameLayout (); bodyPageView.AddChidren (mobileChencView); Button btnPassword = new Button () { Gravity = Gravity.CenterHorizontal, Y = Application.GetRealHeight (50), Width = Application.GetRealWidth (500), Height = Application.GetRealHeight (85), TextID = R.MyInternationalizationString.Password, TextColor = SkinStyle.Current.TextColor1, TextAlignment = TextAlignment.CenterLeft, }; mobileChencView.AddChidren (btnPassword); EditText etPassword = new EditText () { Width = Application.GetRealWidth (500), Height = Application.GetRealHeight (85), Gravity = Gravity.CenterHorizontal, Y = btnPassword.Bottom, BorderWidth = 1, Radius = 5, BorderColor = SkinStyle.Current.BorderColor, SecureTextEntry = true, TextAlignment = TextAlignment.Center //Text = "1270166900@qq.com" }; mobileChencView.AddChidren (etPassword); Button btnConfrimPassword = new Button () { Gravity = Gravity.CenterHorizontal, Y = etPassword.Bottom + Application.GetRealHeight (20), Width = Application.GetRealWidth (500), Height = Application.GetRealHeight (85), TextID = R.MyInternationalizationString.ConfirmPassword, TextColor = SkinStyle.Current.TextColor1, TextAlignment = TextAlignment.CenterLeft, }; mobileChencView.AddChidren (btnConfrimPassword); EditText etConfrimPassword = new EditText () { Width = Application.GetRealWidth (500), Height = Application.GetRealHeight (85), Gravity = Gravity.CenterHorizontal, Y = btnConfrimPassword.Bottom, BorderWidth = 1, Radius = 5, BorderColor = SkinStyle.Current.BorderColor, SecureTextEntry = true, TextAlignment = TextAlignment.Center }; mobileChencView.AddChidren (etConfrimPassword); Button btnConfirem = new Button () { Gravity = Gravity.CenterHorizontal, Y = etConfrimPassword.Bottom + Application.GetRealHeight (50), Width = Application.GetRealWidth (500), Height = Application.GetRealHeight (85), TextID = R.MyInternationalizationString.Confrim, TextColor = SkinStyle.Current.TextColor1, TextAlignment = TextAlignment.Center, BackgroundColor = SkinStyle.Current.MainColor }; mobileChencView.AddChidren (btnConfirem); btnConfirem.MouseUpEventHandler += (sender, e) => { if (etPassword.Text.Trim ().Length < 6) { new Alert (Language.StringByID (R.MyInternationalizationString.Tip), Language.StringByID (R.MyInternationalizationString.PasswordLenghtTip), Language.StringByID (R.MyInternationalizationString.Close)).Show (); return; } if (etPassword.Text.Trim () != etConfrimPassword.Text.Trim ()) { new Alert (Language.StringByID (R.MyInternationalizationString.Tip), Language.StringByID (R.MyInternationalizationString.RepeatPasswordsDidNotmatch), Language.StringByID (R.MyInternationalizationString.Close)).Show (); return; } string newpw = etConfrimPassword.Text.Trim (); MainPage.Loading.Start ("Lading..."); string passwordText = etPassword.Text.Trim (); System.Threading.Tasks.Task.Run (() => { try { var requestObj = new ForgetPasswordActionObj () { Account = mobileNumber, Password = newpw }; var requestJson = Newtonsoft.Json.JsonConvert.SerializeObject (requestObj); var revertObj = MainPage.RequestHttps ("ForgetPasswordAction", requestJson, false); if (revertObj.StateCode == "SUCCESS") { Application.RunOnMainThread (() => { new Alert (Language.StringByID (R.MyInternationalizationString.Tip), Language.StringByID (R.MyInternationalizationString.ThePerationWasSuccessful), Language.StringByID (R.MyInternationalizationString.Close)).Show (); Close (); new AccountLogin (mobileNumber, passwordText).Show (); }); } } catch { Application.RunOnMainThread (() => { new Alert (Language.StringByID (R.MyInternationalizationString.Tip), Language.StringByID (R.MyInternationalizationString.FailureToServer), Language.StringByID (R.MyInternationalizationString.Close)).Show (); }); } finally { Application.RunOnMainThread (() => { MainPage.Loading.Hide (); }); } }); }; } } }