using PDF_Master.Helper; using PDF_Master.Properties; using Prism.Commands; using Prism.Mvvm; using Prism.Regions; using Prism.Services.Dialogs; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Threading; namespace PDF_Master.ViewModels.Dialog.ServiceDialog { public class CodeRegionViewModel : BindableBase, INavigationAware { private string uuid = ServiceHelper.GetDeviceSerialNumber(); private RegisterDialogViewModel RegisterDialogViewModel; private LoginDialogViewModel LoginDialogViewModel; public IDialogService dialogs; //60秒倒计时 private int time = 60; private bool _EnableNextStep = true; public bool EnableNextStep { get { return _EnableNextStep; } set { SetProperty(ref _EnableNextStep, value); } } private string _CodeTypeName = "注册账号"; public string CodeTypeName { get { return _CodeTypeName; } set { SetProperty(ref _CodeTypeName, value); } } private string _CodeType = "user_register"; public string CodeType { get { return _CodeType; } set { SetProperty(ref _CodeType, value); } } private string _codetime = "60"; public string Codetime { get { return _codetime; } set { SetProperty(ref _codetime, value); } } private string _Codesum = ""; public string Codesum { get { return _Codesum; } set { SetProperty(ref _Codesum, value); } } private string _Code1 = ""; public string Code1 { get { return _Code1; } set { SetProperty(ref _Code1, value); if( CodeSum()) { Code6Changed(); } } } private string _Code2 = ""; public string Code2 { get { return _Code2; } set { SetProperty(ref _Code2, value); if (CodeSum()) { Code6Changed(); } } } private string _Code3 = ""; public string Code3 { get { return _Code3; } set { SetProperty(ref _Code3, value); if (CodeSum()) { Code6Changed(); } } } private string _Code4 = ""; public string Code4 { get { return _Code4; } set { SetProperty(ref _Code4, value); if (CodeSum()) { Code6Changed(); } } } private string _Code5 = ""; public string Code5 { get { return _Code5; } set { SetProperty(ref _Code5, value); if (CodeSum()) { Code6Changed(); } } } private string _Code6 = ""; public string Code6 { get { return _Code6; } set { SetProperty(ref _Code6, value); } } private string _RegisterCodemsg = ""; public string RegisterCodemsg { get { return _RegisterCodemsg; } set { SetProperty(ref _RegisterCodemsg, value); } } private Visibility _codeagin = Visibility.Collapsed; public Visibility Codeagin { get { return _codeagin; } set { SetProperty(ref _codeagin, value); } } private Visibility _RegisterCodemsgVis = Visibility.Collapsed; public Visibility RegisterCodemsgVis { get { return _RegisterCodemsgVis; } set { SetProperty(ref _RegisterCodemsgVis, value); } } public bool IsNavigationTarget(NavigationContext navigationContext) { return true; } public void OnNavigatedFrom(NavigationContext navigationContext) { } public void OnNavigatedTo(NavigationContext navigationContext) { navigationContext.Parameters.TryGetValue("RegisterDialogViewModel", out RegisterDialogViewModel); navigationContext.Parameters.TryGetValue("LoginDialogViewModel", out LoginDialogViewModel); if (LoginDialogViewModel!=null&&LoginDialogViewModel.IsReset == true) { CodeType = "user_reset_password"; LoginDialogViewModel.IsReset = false; } else { CodeType = "user_register"; } if (CodeType == "user_reset_password") { CodeTypeName = "重置密码"; } else { CodeTypeName = "注册账号"; } } public DelegateCommand BackRegisterLastCommand { get; set; } public DelegateCommand CodetooCommand { get; set; } public DelegateCommand Code6ChangedCommand { get; set; } public DelegateCommand RegisterNextCommand { get; set; } public CodeRegionViewModel(IRegionManager regionManager, IDialogService dialogService) { Timebegin(); dialogs = dialogService; BackRegisterLastCommand = new DelegateCommand(BackRegisterLast); CodetooCommand = new DelegateCommand(Codetoo); Code6ChangedCommand = new DelegateCommand(Code6Changed); RegisterNextCommand = new DelegateCommand(RegisterNext); if (LoginDialogViewModel != null && LoginDialogViewModel.IsReset == true) { CodeType = "user_reset_password"; LoginDialogViewModel.IsReset = false; } else { CodeType = "user_register"; } if (CodeType == "user_reset_password") { CodeTypeName = "重置密码"; } else { CodeTypeName = "注册账号"; } } private bool CodeSum() { Codesum = Code1 + Code2 + Code3 + Code4 + Code5 + Code6; if(Codesum.Length==6) { return true; } else { return false; } } //下一步按钮 private void RegisterNext() { Codesum = Code1 + Code2 + Code3 + Code4 + Code5 + Code6; if (Codesum.Length == 6) { if (CodeType == "user_register") { if (ServiceHelper.Ok_code(RegisterDialogViewModel.RegisterEmail, Codesum, CodeType) == "success") { if (ServiceHelper.Register_email(RegisterDialogViewModel.RegisterEmail, RegisterDialogViewModel.RegisterPassword, Codesum, uuid) == "success") { App.mainWindowViewModel.UserVis = Visibility.Visible; App.mainWindowViewModel.RegisterVis = Visibility.Collapsed; App.mainWindowViewModel.LoginVis = Visibility.Collapsed; App.mainWindowViewModel.OphVis = Visibility.Collapsed; Settings.Default.UserDate.Email = RegisterDialogViewModel.RegisterEmail; RegisterDialogViewModel.RegionMan("RegisterOKRegion"); } else { RegisterCodemsg = ServiceHelper.Register_email(RegisterDialogViewModel.RegisterEmail, RegisterDialogViewModel.RegisterPassword, Codesum, uuid); RegisterCodemsgVis = Visibility.Visible; } } else { RegisterCodemsg = ServiceHelper.Ok_code(RegisterDialogViewModel.RegisterEmail, Codesum, CodeType); RegisterCodemsgVis = Visibility.Visible; } } else { if (ServiceHelper.Ok_code(LoginDialogViewModel.LoginEmail, Codesum, CodeType) == "success") { LoginDialogViewModel.PasswordCode = Codesum; LoginDialogViewModel.RegionMan("PasswordUpdataRegion"); } else { RegisterCodemsg = ServiceHelper.Ok_code(LoginDialogViewModel.LoginEmail, Codesum, CodeType); RegisterCodemsgVis = Visibility.Visible; } } } else { RegisterCodemsg = "请输入六位数验证码"; } } //第六个密码框改变 private void Code6Changed() { if(Code6.Length==1) { ; if (CodeSum() ==true) { if (CodeType == "user_register") { if (ServiceHelper.Ok_code(RegisterDialogViewModel.RegisterEmail, Codesum, CodeType) == "success") { if (ServiceHelper.Register_email(RegisterDialogViewModel.RegisterEmail, RegisterDialogViewModel.RegisterPassword, Codesum, uuid) == "success") { App.mainWindowViewModel.UserVis = Visibility.Visible; App.mainWindowViewModel.RegisterVis = Visibility.Collapsed; App.mainWindowViewModel.LoginVis = Visibility.Collapsed; App.mainWindowViewModel.OphVis = Visibility.Collapsed; Settings.Default.UserDate.Email = RegisterDialogViewModel.RegisterEmail; RegisterDialogViewModel.RegionMan("RegisterOKRegion"); } else { RegisterCodemsg = ServiceHelper.Register_email(RegisterDialogViewModel.RegisterEmail, RegisterDialogViewModel.RegisterPassword, Codesum, uuid); RegisterCodemsgVis = Visibility.Visible; } } else { RegisterCodemsg = ServiceHelper.Ok_code(RegisterDialogViewModel.RegisterEmail, Codesum, CodeType); RegisterCodemsgVis = Visibility.Visible; } } else { if (ServiceHelper.Ok_code(LoginDialogViewModel.LoginEmail, Codesum, CodeType) == "success") { LoginDialogViewModel.PasswordCode = Codesum; LoginDialogViewModel.RegionMan("PasswordUpdataRegion"); } else { RegisterCodemsg = ServiceHelper.Ok_code(LoginDialogViewModel.LoginEmail, Codesum, CodeType); RegisterCodemsgVis = Visibility.Visible; } } } else { RegisterCodemsg = "请输入六位数验证码"; RegisterCodemsgVis = Visibility.Visible; } } } //重发密码 private void Codetoo() { time = 60; Codeagin = Visibility.Collapsed; if (CodeType == "user_register") { ServiceHelper.Get_code(CodeType, RegisterDialogViewModel.RegisterEmail); } else if (CodeType == "user_reset_password") { ServiceHelper.Get_code(CodeType, LoginDialogViewModel.LoginEmail); } } //计数 public void disTimer_Tick(object sender, EventArgs e) { if (time == 0) { Codeagin = Visibility.Visible; Codetime = ""; } else { time--; Codetime = "("+time.ToString()+")"; } } //计时器 private DispatcherTimer disTimer = new DispatcherTimer(); public void Timebegin() { time = 60; //设置定时器 disTimer.Tick += new EventHandler(disTimer_Tick);//每一秒执行的方法 disTimer.Interval = new TimeSpan(10000000); //时间间隔为一秒。 disTimer.Start();//计时开始 } //判断验证类型 private void BackRegisterLast() { if(CodeType== "user_register") { RegisterDialogViewModel.RegionMan("RegisterRegion"); } else if(CodeType == "user_reset_password") { LoginDialogViewModel.RegionMan("LoginPasswordRegion"); } } } }