using PDF_Master.Helper; using PDF_Master.Model; 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; namespace PDF_Master.ViewModels.Dialog.ServiceDialog { public class RegisterRegionViewModel : BindableBase, INavigationAware { private RegisterDialogViewModel RegisterDialogViewModel; 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("RegisterDialogViewModel", out RegisterDialogViewModel); } #region 文案 private string _Text_Signup = ""; public string Text_Signup { get { return _Text_Signup; } set { SetProperty(ref _Text_Signup, value); } } private string _registerText1 = ""; public string Registertext1 { get { return _registerText1; } set { SetProperty(ref _registerText1, value); } } private string _registerNextStep = ""; public string RegisterNextStep { get { return _registerNextStep; } set { SetProperty(ref _registerNextStep, value); } } private string _registerEmailMsg = ""; public string RegisterEmailMsg { get { return _registerEmailMsg; } set { SetProperty(ref _registerEmailMsg, value); } } private string _registerPasswordMsg = ""; public string RegisterPasswordMsg { get { return _registerPasswordMsg; } set { SetProperty(ref _registerPasswordMsg, value); } } private string _Text_Login = ""; public string Text_Login { get { return _Text_Login; } set { SetProperty(ref _Text_Login, value); } } private string _Text_remsg = ""; public string Text_remsg { get { return _Text_remsg; } set { SetProperty(ref _Text_remsg, value); } } private string _Text_privary = ""; public string Text_privary { get { return _Text_privary; } set { SetProperty(ref _Text_privary, value); } } private string _Text_and = ""; public string Text_and { get { return _Text_and; } set { SetProperty(ref _Text_and, value); } } private string _Text_licens = ""; public string Text_licens { get { return _Text_licens; } set { SetProperty(ref _Text_licens, value); } } private string _Containspaces = ""; public string Containspaces { get { return _Containspaces; } set { SetProperty(ref _Containspaces, value); } } private string _Codemax = ""; public string Codemax { get { return _Codemax; } set { SetProperty(ref _Codemax, value); } } private string _Codemin = ""; public string Codemin { get { return _Codemin; } set { SetProperty(ref _Codemin, value); } } private string _Mailerr = ""; public string Mailerr { get { return _Mailerr; } set { SetProperty(ref _Mailerr, value); } } private void InitString() { ErrorCodeHelper.InitString(); Containspaces = App.ServiceLoader.GetString("code327"); Text_Signup = App.ServiceLoader.GetString("Text_Signup"); Registertext1 = App.ServiceLoader.GetString("Registertext1"); RegisterEmailMsg = App.ServiceLoader.GetString("RegisterEmailMsg"); RegisterPasswordMsg = App.ServiceLoader.GetString("RegisterPasswordMsg"); RegisterNextStep = App.ServiceLoader.GetString("RegisterNextStep"); Text_Login = App.ServiceLoader.GetString("Text_Login"); Text_remsg = App.ServiceLoader.GetString("Text_remsg"); Text_privary = App.ServiceLoader.GetString("Text_privary"); Text_and = App.ServiceLoader.GetString("Text_and"); Text_licens = App.ServiceLoader.GetString("Text_licens"); Codemax = App.ServiceLoader.GetString("Codemax"); Codemin = App.ServiceLoader.GetString("Codemin"); Mailerr = App.ServiceLoader.GetString("Mailerr"); } #endregion private bool enableNextStep = false; public bool EnableNextStep { get { return enableNextStep; } set { SetProperty(ref enableNextStep, value); } } private string _registerEmaillook; public string RegisterEmaillook { get { return _registerEmaillook; } set { SetProperty(ref _registerEmaillook, value); } } private string _registerePasswordlook; public string RegisterePasswordlook { get { return _registerePasswordlook; } set { SetProperty(ref _registerePasswordlook, value); } } private string _uriPolivy = "https://www.pdfreaderpro.com/privacy-policy"; public string UriPolivy { get { return _uriPolivy; } set { SetProperty(ref _uriPolivy, value); } } private string _uriLicense = "https://www.pdfreaderpro.com/terms_of_service"; public string UriLicense { get { return _uriLicense; } set { SetProperty(ref _uriLicense, value); } } private bool _isRegisterPasswordDisplayed = false; public bool IsRegisterPasswordDisplayed { get { return _isRegisterPasswordDisplayed; } set { SetProperty(ref _isRegisterPasswordDisplayed, value); } } private string _registerPassword = ""; public string RegisterPassword { get { return _registerPassword; } set { SetProperty(ref _registerPassword, value); if (string.IsNullOrEmpty(RegisterPassword)) { ChkVis = Visibility.Collapsed; } else { ChkVis = Visibility.Visible; } CheckEnableNextStepEncrypt(); } } private string _registerEmail = ""; public string RegisterEmail { get { return _registerEmail; } set { SetProperty(ref _registerEmail, value); RegisterEmaillook = ""; //if (RegisterEmail=="") //{ // RegisterEmaillook = ""; //} //else //{ // CheckMail(RegisterEmail); //} CheckEnableNextStepEncrypt(); } } private Visibility _registerPasswordVisibility = Visibility.Visible; public Visibility RegisterPasswordVisibility { get { return _registerPasswordVisibility; } set { if (value == Visibility.Visible) { RegisterTextVisibility = Visibility.Collapsed; } else { RegisterTextVisibility = Visibility.Visible; } SetProperty(ref _registerPasswordVisibility, value); } } private Visibility _ChkVis = Visibility.Collapsed; public Visibility ChkVis { get { return _ChkVis; } set { SetProperty(ref _ChkVis, value); } } private Visibility _registerTextVisibility = Visibility.Collapsed; public Visibility RegisterTextVisibility { get { return _registerTextVisibility; } set { SetProperty(ref _registerTextVisibility, value); } } private bool _isPermissionsPasswordDisplayed = false; public bool IsPermissionsPasswordDisplayed { get { return _isPermissionsPasswordDisplayed; } set { SetProperty(ref _isPermissionsPasswordDisplayed, value); } } public DelegateCommand DisplayPasswordCommand { get; set; } public DelegateCommand LinkPolicyCommand { get; set; } public DelegateCommand RegisterNextCommand { get; set; } public DelegateCommand GoLoginCommand { get; set; } public DelegateCommand RegisterPasswordChangedCommand { get; set; } public DelegateCommand LinkLicenseCommand { get; set; } RegisterRegionViewModel(IRegionManager regionManager, IDialogService dialogService) { dialogs = dialogService; DisplayPasswordCommand = new DelegateCommand(DisplayPassword); LinkPolicyCommand = new DelegateCommand(LinkPolicy); LinkLicenseCommand = new DelegateCommand(LinkLicense); GoLoginCommand = new DelegateCommand(GoLogin); RegisterNextCommand = new DelegateCommand(RegisterNext); RegisterPasswordChangedCommand = new DelegateCommand(RegisterPasswordChanged); InitString(); } private void RegisterPasswordChanged() { if(RegisterPassword.Length<6&& RegisterPassword.Length>0) { RegisterePasswordlook = Codemin; } else if(RegisterPassword.Length>24) { RegisterePasswordlook = Codemax; } else if (RegisterPassword.Contains(" ") == true) { RegisterePasswordlook = Containspaces; } else { RegisterePasswordlook = ""; } } 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)) { RegisterEmaillook = ""; } else { RegisterEmaillook =Mailerr; } } private void RegisterNext() { //去掉前后空格 RegisterEmail = RegisterEmail.Trim(); string code = ServiceHelper.Ok_email(RegisterEmail, "2"); if (code == "200") { RegisterDialogViewModel.RegisterEmail = RegisterEmail; RegisterDialogViewModel.RegisterPassword = RegisterPassword; RegisterDialogViewModel.RegionMan("CodeRegion"); } else { RegisterEmaillook = ErrorCodeHelper.Ercode(code); } } public void SetOpenPassword(object e) { var chk = e as CheckBox; if (chk != null) { IsRegisterPasswordDisplayed = false; RegisterPasswordVisibility = Visibility.Visible; } CheckEnableNextStepEncrypt(); } private void GoLogin() { RegisterDialogViewModel.Close(); App.mainWindowViewModel.OpenLogin(); } private void LinkPolicy() { Process.Start(new ProcessStartInfo(UriPolivy)); } private void LinkLicense() { Process.Start(new ProcessStartInfo(UriLicense)); } private void CheckEnableNextStepEncrypt() { EnableNextStep = true; if (RegisterPassword.Length<6|| RegisterPassword.Length >24 || string.IsNullOrEmpty(RegisterEmail)|| RegisterEmaillook!= "" || RegisterPassword.Contains(" ") == true) { EnableNextStep = false; } } public void DisplayPassword(object e) { var chk = e as CheckBox; if (chk != null) { if (chk.IsChecked == true) { RegisterPasswordVisibility = Visibility.Collapsed; } else { RegisterPasswordVisibility = Visibility.Visible; } } } } }