using PDF_Master.CustomControl; using PDF_Master.Helper; using PDF_Master.Model; using PDF_Master.Views.Dialog.ServiceDialog; using Prism.Commands; using Prism.Mvvm; using Prism.Regions; using Prism.Services.Dialogs; using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Documents; using System.Windows.Navigation; namespace PDF_Master.ViewModels.Dialog.ServiceDialog { public class LoginRegionViewModel : BindableBase, INavigationAware { private LoginDialogViewModel LoginDialogViewModel; private ErrorCodeHelper ErrorCodeHelper = new ErrorCodeHelper(); public IDialogService dialogs; public bool IsNavigationTarget(NavigationContext navigationContext) { return true; } public void OnNavigatedFrom(NavigationContext navigationContext) { } public void OnNavigatedTo(NavigationContext navigationContext) { navigationContext.Parameters.TryGetValue("LoginDialogViewModel", out LoginDialogViewModel); } #region 文案 private string _Text_Login = ""; public string Text_Login { get { return _Text_Login; } set { SetProperty(ref _Text_Login, value); } } private string _Text_emailac = ""; public string Text_emailac { get { return _Text_emailac; } set { SetProperty(ref _Text_emailac, value); } } private string _Text_next = ""; public string Text_next { get { return _Text_next; } set { SetProperty(ref _Text_next, value); } } private string _Text_noacc = ""; public string Text_noacc { get { return _Text_noacc; } set { SetProperty(ref _Text_noacc, value); } } private string _Text_toregister = ""; public string Text_toregister { get { return _Text_toregister; } set { SetProperty(ref _Text_toregister, value); } } private string _LoginEmailMsg = ""; public string LoginEmailMsg { get { return _LoginEmailMsg; } set { SetProperty(ref _LoginEmailMsg, value); } } private string _Mailerr = ""; public string Mailerr { get { return _Mailerr; } set { SetProperty(ref _Mailerr, value); } } private void InitString() { Text_Login = App.ServiceLoader.GetString("Text_Login"); Text_emailac = App.ServiceLoader.GetString("Text_emailac"); Text_next = App.ServiceLoader.GetString("RegisterNextStep"); Text_noacc = App.ServiceLoader.GetString("Text_noacc"); Text_toregister = App.ServiceLoader.GetString("Text_Signup"); Mailerr = App.ServiceLoader.GetString("Mailerr"); LoginEmailMsg = App.ServiceLoader.GetString("RegisterEmailMsg"); } #endregion private bool enableNextStep = false; public bool EnableNextStep { get { return enableNextStep; } set { SetProperty(ref enableNextStep, value); } } private string _LoginEmaillook; public string LoginEmaillook { get { return _LoginEmaillook; } set { SetProperty(ref _LoginEmaillook, value);} } private string _LoginEmail = ""; public string LoginEmail { get { return _LoginEmail; } set { SetProperty(ref _LoginEmail, value); if (LoginEmail == "") { LoginEmaillook = ""; } else { CheckMail(LoginEmail); } CheckEnableNextStepEncrypt(); } } public DelegateCommand LoginNextCommand { get; set; } public DelegateCommand GoLoginCommand { get; set; } LoginRegionViewModel(IRegionManager regionManager, IDialogService dialogService) { dialogs = dialogService; LoginNextCommand = new DelegateCommand(LoginNext); GoLoginCommand = new DelegateCommand(GoLogin); InitString(); } private void LoginNext() { if (ServiceHelper.Ok_email(LoginEmail, "1") == "200") { LoginDialogViewModel.LoginEmail = LoginEmail; LoginDialogViewModel.RegionMan("LoginPasswordRegion"); } else if (ServiceHelper.Ok_email(LoginEmail, "1") == "300") { LoginDialogViewModel.RegionMan("NOInternetRegion"); } else if (ServiceHelper.Ok_email(LoginEmail, "1") == "318") { dialogs.ShowDialog(DialogNames.UserOutingLogin, new DialogParameters(""), r => { }); } else { LoginEmaillook = ErrorCodeHelper.Ercode(ServiceHelper.Ok_email(LoginEmail, "1")); } } private void CheckMail(string mail) { string str = "^([a-z0-9_\\.-]+)@([\\da-z\\.-]+)\\.([a-z\\.]{2,6})$"; Regex mReg = new Regex(str); if (mReg.IsMatch(mail)) { LoginEmaillook = ""; } else { LoginEmaillook = Mailerr; } } private void GoLogin() { LoginDialogViewModel.Close(); App.mainWindowViewModel.OpenRegister(); } private void CheckEnableNextStepEncrypt() { EnableNextStep = true; if (string.IsNullOrEmpty(LoginEmail)||LoginEmaillook!="") { EnableNextStep = false; } } } }