using System;
|
using System.Text.RegularExpressions;
|
|
namespace Shared.SimpleControl.Phone
|
{
|
public class AccountRegistration_Crabtree : Dialog
|
{
|
public AccountRegistration_Crabtree ()
|
{
|
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 = "Sign up",
|
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 ();
|
};
|
|
var bodyView = new FrameLayout () {
|
Width = LayoutParams.MatchParent,
|
Height = Application.GetRealHeight (1136 - 126),
|
Y = topView.Bottom,
|
BackgroundColor = SkinStyle.Current.ViewColor,
|
};
|
AddChidren (bodyView);
|
bodyView.MouseDownEventHandler += (sender, e) => {
|
Application.HideSoftInput ();
|
};
|
|
EmailRegistrationView (bodyView);
|
}
|
|
void EmailRegistrationView (FrameLayout registrationView)
|
{
|
Button btnName = new Button () {
|
Width = Application.GetRealWidth (500),
|
Height = Application.GetRealHeight (85),
|
X = Application.GetRealWidth (70),
|
Y = Application.GetRealHeight (20),
|
TextID = R.MyInternationalizationString.Name,
|
TextAlignment = TextAlignment.CenterLeft,
|
TextSize = 12,
|
TextColor = SkinStyle.Current.TextColor1,
|
};
|
registrationView.AddChidren (btnName);
|
|
EditText etName = new EditText () {
|
Width = Application.GetRealWidth (500),
|
Height = Application.GetRealHeight (85),
|
X = Application.GetRealWidth (70),
|
Y = btnName.Bottom,
|
TextAlignment = TextAlignment.Center,
|
BorderWidth = 1,
|
Radius = 5,
|
BorderColor = SkinStyle.Current.BorderColor,
|
TextColor = SkinStyle.Current.TextColor1,
|
//Text = "wxr@hdlchina.com.cn"
|
};
|
registrationView.AddChidren (etName);
|
|
Button btnEmail = new Button () {
|
Width = Application.GetRealWidth (500),
|
Height = Application.GetRealHeight (85),
|
X = Application.GetRealWidth (70),
|
Y = etName.Bottom + Application.GetRealHeight (20),
|
Text= "Email ID",
|
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 btnShowPassword = new Button () {
|
X = etPasswrod.Right - Application.GetRealWidth (80),
|
Y = etPasswrod.Y + Application.GetRealHeight (12),
|
Width = Application.GetRealWidth (73),
|
Height = Application.GetRealHeight (60),
|
SelectedImagePath = "CrabtreeAdd/ShowPW.png",
|
UnSelectedImagePath = "CrabtreeAdd/HidePW.png",
|
BorderColor = SkinStyle.Current.Transparent,
|
BorderWidth = 1,
|
Radius = 1
|
};
|
registrationView.AddChidren (btnShowPassword);
|
btnShowPassword.MouseUpEventHandler += (dd, ff) => {
|
btnShowPassword.IsSelected = !btnShowPassword.IsSelected;
|
etPasswrod.SecureTextEntry = !btnShowPassword.IsSelected;
|
};
|
|
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 btnShowPassword2 = new Button () {
|
X = etPasswrod.Right - Application.GetRealWidth (80),
|
Y = etConfirmPassword.Y + Application.GetRealHeight (12),
|
Width = Application.GetRealWidth (73),
|
Height = Application.GetRealHeight (60),
|
SelectedImagePath = "CrabtreeAdd/ShowPW.png",
|
UnSelectedImagePath = "CrabtreeAdd/HidePW.png",
|
BorderColor = SkinStyle.Current.Transparent,
|
BorderWidth = 1,
|
Radius = 1
|
};
|
registrationView.AddChidren (btnShowPassword2);
|
btnShowPassword2.MouseUpEventHandler += (dd, ff) => {
|
btnShowPassword2.IsSelected = !btnShowPassword2.IsSelected;
|
etConfirmPassword.SecureTextEntry = !btnShowPassword2.IsSelected;
|
};
|
|
Button btnOK = new Button () {
|
Width = Application.GetRealWidth (247),
|
Height = Application.GetRealHeight (89),
|
X = Application.GetRealWidth ((640 - 247) / 2),
|
Y = Application.GetRealHeight (800),
|
BackgroundColor = SkinStyle.Current.ButtonColor,
|
SelectedBackgroundColor = SkinStyle.Current.SelectedColor,
|
Text = "Sign up",
|
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 ();
|
string userName = etName.Text.Trim ();
|
var regName = new Regex (@"^[~!0-9@#$%^&=*\x22]+");
|
|
if (userName.Length == 0) {
|
new Alert ("", "Please fill in the Name.", Language.StringByID (R.MyInternationalizationString.Close)).Show ();
|
return;
|
} else if (regName.Match (userName).Success) {
|
new Alert ("", "Protect Your Illegal Characters in Name", Language.StringByID (R.MyInternationalizationString.Close)).Show ();
|
return;
|
} else if (!ss.Success) {
|
new Alert ("", Language.StringByID (R.MyInternationalizationString.PleaseCheckEmailAddressCorrectly),
|
Language.StringByID (R.MyInternationalizationString.Close)).Show ();
|
return;
|
} else if (etPasswrod.Text.Trim ().Length < 6) {
|
new Alert ("", Language.StringByID (R.MyInternationalizationString.PasswordLenghtTip), Language.StringByID (R.MyInternationalizationString.Close)).Show ();
|
return;
|
} else if (etPasswrod.Text == "" && etConfirmPassword.Text == "") {
|
new Alert ("", Language.StringByID (R.MyInternationalizationString.PleaseWriteTheCompleteContent), Language.StringByID (R.MyInternationalizationString.Close)).Show ();
|
return;
|
} else if (etPasswrod.Text.Trim () != etConfirmPassword.Text.Trim ()) {
|
new Alert ("", Language.StringByID (R.MyInternationalizationString.RepeatPasswordsDidNotmatch),
|
Language.StringByID (R.MyInternationalizationString.Close)).Show ();
|
return;
|
}
|
|
System.Threading.Tasks.Task.Run (() => {
|
try {
|
Application.RunOnMainThread (() => {
|
MainPage.Loading.Start ("Please wait...");
|
});
|
string isExistingAccount = "{\"Account\":\"" + account + "\"}";
|
var isExistingAccountObj = MainPage.RequestHttps ("IsExistingAccount", isExistingAccount, false);
|
if (isExistingAccountObj.StateCode == "EXIST") {
|
string sssd = "这个账号已经注册。";
|
if (Language.CurrentLanguage == "English")
|
sssd = "This account has been registered.";
|
Application.RunOnMainThread (() => {
|
new Alert ("", sssd, Language.StringByID (R.MyInternationalizationString.Close)).Show ();
|
});
|
return;
|
} else {
|
var requestObj = new SignInObj () { Account = account, Password = passwordText, Contact = userName, 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.AuthenticationMail), Language.StringByID (R.MyInternationalizationString.Close)).Show ();
|
Close ();
|
new AccountLogin (account, passwordText).Show ();
|
});
|
}
|
}
|
} catch {
|
MainPage.FailureToServer ();
|
} finally {
|
Application.RunOnMainThread (() => {
|
MainPage.Loading.Hide ();
|
});
|
}
|
});
|
};
|
|
etName.EditorEnterAction += (obj) => {
|
//Application.HideSoftInput ();
|
etEmailAddress.Foucs = true;
|
};
|
etEmailAddress.EditorEnterAction += (obj) => {
|
//Application.HideSoftInput ();
|
etPasswrod.Foucs = true;
|
};
|
etPasswrod.EditorEnterAction += (obj) => {
|
Application.HideSoftInput ();
|
etConfirmPassword.Foucs = true;
|
};
|
etConfirmPassword.EditorEnterAction += (obj) => {
|
//etConfirmPassword.Foucs = false;
|
Application.HideSoftInput ();
|
};
|
//etConfirmPassword.MouseDownEventHandler += (dd, dds) => {
|
// etConfirmPassword.Foucs = true;
|
//};
|
btnName.MouseDownEventHandler += (sender, e) => {
|
Application.HideSoftInput ();
|
};
|
btnEmail.MouseDownEventHandler += (sender, e) => {
|
Application.HideSoftInput ();
|
};
|
btnPassword.MouseDownEventHandler += (sender, e) => {
|
Application.HideSoftInput ();
|
};
|
btnConfirmpassword.MouseDownEventHandler += (sender, e) => {
|
Application.HideSoftInput ();
|
};
|
}
|
|
}
|
}
|