using System; using System.Text.RegularExpressions; namespace Shared.SimpleControl.Phone { //public class AccountRegistrationPageView : PageLayout //{ //override //} public class AccountRegistration : Dialog { PageLayout bodyPageView; public AccountRegistration () { BackgroundColor = SkinStyle.Current.MainColor; ShowRegisterView (); } public void ShowRegisterView () { FrameLayout topView = new FrameLayout () { Y = Application.GetRealHeight (36), Height = Application.GetRealHeight (90), BackgroundColor = SkinStyle.Current.MainColor, }; AddChidren (topView); Button title = new Button () { TextAlignment = TextAlignment.Center, Text = Language.StringByID (R.MyInternationalizationString.UserAccount), TextSize = 19, TextColor = SkinStyle.Current.TextColor1 }; topView.AddChidren (title); Button logo = new Button () { Width = Application.GetRealWidth (154), Height = Application.GetRealHeight (90), X = Application.GetRealWidth (486), UnSelectedImagePath = MainPage.LogoString, Gravity = Gravity.CenterVertical, }; topView.AddChidren (logo); Button 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) => { this.Close (); new AccountLogin ().Show (); }; 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); } }; 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.MailboxRegistration, TextAlignment = TextAlignment.Center, TextColor = SkinStyle.Current.TextColor1, IsSelected = true, }; 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.MobileRegistration, TextColor = SkinStyle.Current.TextColor1, TextAlignment = TextAlignment.Center, }; languageView.AddChidren (btnPhoneRegistration); FrameLayout registrationView = new FrameLayout () { Y = languageView.Bottom, Height = Application.GetRealHeight (Application.DesignHeight - 126 - 105), }; bodyView.AddChidren (registrationView); btnEmailRegistration.MouseUpEventHandler += (sender, e) => { btnEmailRegistration.IsSelected = true; btnPhoneRegistration.IsSelected = false; EmailRegistrationView (registrationView); }; btnPhoneRegistration.MouseUpEventHandler += (sender, e) => { btnEmailRegistration.IsSelected = false; btnPhoneRegistration.IsSelected = true; PhoneReagistrationView (registrationView); }; EmailRegistrationView (registrationView); #if longxi btnPhoneRegistration.RemoveFromParent (); btnEmailRegistration.IsSelected = false; btnEmailRegistration.BackgroundColor = SkinStyle.Current.Transparent; btnEmailRegistration.X = Application.GetRealWidth (125); #endif } void EmailRegistrationView (FrameLayout registrationView) { registrationView.RemoveAll (); Button btnEmail = new Button () { Width = Application.GetRealWidth (500), Height = Application.GetRealHeight (85), X = Application.GetRealWidth (70), Y = Application.GetRealHeight (20), TextID = R.MyInternationalizationString.Account, TextAlignment = TextAlignment.CenterLeft, TextSize = 12, TextColor = SkinStyle.Current.TextColor1, }; registrationView.AddChidren (btnEmail); EditText etEmailAddress = new EditText () { Width = Application.GetRealWidth (500), Height = Application.GetRealHeight (85), X = Application.GetRealWidth (70), Y = btnEmail.Bottom, TextAlignment = TextAlignment.Center, BorderWidth = 1, Radius = 5, BorderColor = SkinStyle.Current.BorderColor, TextColor = SkinStyle.Current.TextColor1, //Text = "wxr@hdlchina.com.cn" }; registrationView.AddChidren (etEmailAddress); Button btnPassword = new Button () { Width = Application.GetRealWidth (500), Height = Application.GetRealHeight (85), X = Application.GetRealWidth (70), Y = etEmailAddress.Bottom + Application.GetRealHeight (20), TextID = R.MyInternationalizationString.Password, TextAlignment = TextAlignment.CenterLeft, TextSize = 12, TextColor = SkinStyle.Current.TextColor1, }; registrationView.AddChidren (btnPassword); EditText etPasswrod = new EditText () { Width = Application.GetRealWidth (500), Height = Application.GetRealHeight (85), X = Application.GetRealWidth (70), Y = btnPassword.Bottom, BorderWidth = 1, Radius = 5, BorderColor = SkinStyle.Current.BorderColor, TextAlignment = TextAlignment.Center, TextColor = SkinStyle.Current.TextColor1, SecureTextEntry = true, //Text = "hdltest1985" }; registrationView.AddChidren (etPasswrod); Button btnConfirmpassword = new Button () { Width = Application.GetRealWidth (500), Height = Application.GetRealHeight (85), X = Application.GetRealWidth (70), Y = etPasswrod.Bottom + Application.GetRealHeight (20), TextID = R.MyInternationalizationString.RepeatPassword, TextAlignment = TextAlignment.CenterLeft, TextSize = 12, TextColor = SkinStyle.Current.TextColor1, }; registrationView.AddChidren (btnConfirmpassword); EditText etConfirmPassword = new EditText () { Width = Application.GetRealWidth (500), Height = Application.GetRealHeight (85), X = Application.GetRealWidth (70), Y = btnConfirmpassword.Bottom, BorderWidth = 1, Radius = 5, BorderColor = SkinStyle.Current.BorderColor, TextAlignment = TextAlignment.Center, TextColor = SkinStyle.Current.TextColor1, SecureTextEntry = true, //Text = "hdltest1985" }; registrationView.AddChidren (etConfirmPassword); Button btnOK = new Button () { Width = Application.GetRealWidth (247), Height = Application.GetRealHeight (89), X = Application.GetRealWidth ((640 - 247) / 2), Y = Application.GetRealHeight (700), BackgroundColor = SkinStyle.Current.ButtonColor, SelectedBackgroundColor = SkinStyle.Current.SelectedColor, TextID = R.MyInternationalizationString.OK, TextColor = SkinStyle.Current.TextColor1, Radius = 5, BorderColor = SkinStyle.Current.Transparent, BorderWidth = 0, TextSize = 18, }; registrationView.AddChidren (btnOK); btnOK.MouseDownEventHandler += (sender, e) => { btnOK.IsSelected = true; }; btnOK.MouseUpEventHandler += (sender, e) => { btnOK.IsSelected = false; }; btnOK.MouseUpEventHandler += (sender, e) => { var reg = new Regex ("^\\s*([A-Za-z0-9_-]+(\\.\\w+)*@(\\w+\\.)+\\w{2,5})\\s*$"); var ss = reg.Match (etEmailAddress.Text); string account = etEmailAddress.Text.Trim (); string passwordText = etPasswrod.Text.Trim (); if (!ss.Success) { new Alert (Language.StringByID (R.MyInternationalizationString.Tip), Language.StringByID (R.MyInternationalizationString.PleaseCheckEmailAddressCorrectly), Language.StringByID (R.MyInternationalizationString.Close)).Show (); return; } if (etPasswrod.Text.Trim ().Length < 6) { new Alert (Language.StringByID (R.MyInternationalizationString.Tip), Language.StringByID (R.MyInternationalizationString.PasswordLenghtTip), Language.StringByID (R.MyInternationalizationString.Close)).Show (); return; } if (etPasswrod.Text == "" && etConfirmPassword.Text == "") { new Alert (Language.StringByID (R.MyInternationalizationString.Tip), Language.StringByID (R.MyInternationalizationString.PleaseWriteTheCompleteContent), Language.StringByID (R.MyInternationalizationString.Close)).Show (); return; } if (string.IsNullOrEmpty(etConfirmPassword.Text.Trim ())) { new Alert (Language.StringByID (R.MyInternationalizationString.Tip), Language.StringByID (R.MyInternationalizationString.PleaseEnterConfirmationPassword), Language.StringByID (R.MyInternationalizationString.Close)).Show (); return; } if (etPasswrod.Text.Trim () != etConfirmPassword.Text.Trim ()) { new Alert (Language.StringByID (R.MyInternationalizationString.Tip), Language.StringByID (R.MyInternationalizationString.RepeatPasswordsDidNotmatch), Language.StringByID (R.MyInternationalizationString.Close)).Show (); return; } System.Threading.Tasks.Task.Run (() => { try { Application.RunOnMainThread (() => { MainPage.Loading.Start (Language.StringByID(R.MyInternationalizationString.load)); }); var requestObj = new SignInObj () { Account = account, Password = passwordText, Language = Language.CurrentLanguage,Company = MainPage.SoftSmsType }; var requestJson = Newtonsoft.Json.JsonConvert.SerializeObject (requestObj); var revertObj = MainPage.RequestHttps ("SignIn", requestJson,false); if (revertObj.StateCode == "SUCCESS") { Application.RunOnMainThread (() => { new Alert (Language.StringByID (R.MyInternationalizationString.Tip), Language.StringByID (R.MyInternationalizationString.AuthenticationMail),Language.StringByID (R.MyInternationalizationString.Close)).Show (); Close (); new AccountLogin (account, passwordText).Show (); }); } } catch { MainPage.FailureToServer (); } 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.TextColor1, }; registrationView.AddChidren (btnNext); btnNext.MouseUpEventHandler += (sender, e) => { string phoneNum = etPhoneNumber.Text.Trim (); Regex reg = new Regex ("^\\d+$"); var mFalg = reg.Match (etPhoneNumber.Text.Trim ()); if (!mFalg.Success) { new Alert (Language.StringByID (R.MyInternationalizationString.Tip), Language.StringByID (R.MyInternationalizationString.PhoneNumberErorr), Language.StringByID (R.MyInternationalizationString.Close)).Show (); etPhoneNumber.Text = ""; return; } MainPage.Loading.Start (Language.StringByID(R.MyInternationalizationString.load)); System.Threading.Tasks.Task.Run (() => { try { var requestObje = new IsExistingAccountObj () { Account = phoneNum }; var requesetJson2 = Newtonsoft.Json.JsonConvert.SerializeObject (requestObje); var requestRevertObje = MainPage.RequestHttps ("IsExistingAccount", requesetJson2, false); if (requestRevertObje.StateCode == "SUCCESS") { var requestObj = new SignPhoneObj () { Phone = phoneNum, Company = MainPage.SoftSmsType }; var requesetJson = Newtonsoft.Json.JsonConvert.SerializeObject (requestObj); var requestRevertObj = MainPage.RequestHttps ("SignPhone", requesetJson, false); 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; //var reg = new Regex ("^[0-9]*$"); 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); //btnNext.IsSelected = btnNext.Enable = false; } } 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, }; 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 (string.IsNullOrEmpty (etConfrimPassword.Text.Trim ())) { new Alert (Language.StringByID (R.MyInternationalizationString.Tip), Language.StringByID (R.MyInternationalizationString.PleaseEnterConfirmationPassword), 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; } MainPage.Loading.Start (Language.StringByID(R.MyInternationalizationString.load)); string passwordText = etPassword.Text.Trim (); System.Threading.Tasks.Task.Run (() => { try { var requestObj = new SignInObj () { Account = mobileNumber,Password = passwordText, Language = Language.CurrentLanguage }; var requestJson = Newtonsoft.Json.JsonConvert.SerializeObject (requestObj); var revertObj = MainPage.RequestHttps ("SignIn", requestJson, false); if (revertObj.StateCode == "SUCCESS") { Application.RunOnMainThread (() => { new Alert (Language.StringByID (R.MyInternationalizationString.Tip), Language.StringByID (R.MyInternationalizationString.TheAccountTegistrationIsSuccessful),Language.StringByID (R.MyInternationalizationString.Close)).Show (); Close (); new AccountLogin (mobileNumber, passwordText).Show (); }); } } catch { MainPage.FailureToServer (); } finally { Application.RunOnMainThread (() => { MainPage.Loading.Hide (); }); } }); }; } } }