123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546 |
- 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;
- private ErrorCodeHelper ErrorCodeHelper = new ErrorCodeHelper();
- //60秒倒计时
- private int time = 60;
- #region 文案
- private string _Text_Signup = "";
- public string Text_Signup
- {
- get { return _Text_Signup; }
- set { SetProperty(ref _Text_Signup, value); }
- }
- private string _Text_toocode = "";
- public string Text_toocode
- {
- get { return _Text_toocode; }
- set { SetProperty(ref _Text_toocode, value); }
- }
- private string _Text_vcode = "";
- public string Text_vcode
- {
- get { return _Text_vcode; }
- set { SetProperty(ref _Text_vcode, value); }
- }
- private string _Text_novcode = "";
- public string Text_novcode
- {
- get { return _Text_novcode; }
- set { SetProperty(ref _Text_novcode, value); }
- }
- private string _Text_recode = "";
- public string Text_recode
- {
- get { return _Text_recode; }
- set { SetProperty(ref _Text_recode, value); }
- }
- private string _Text_back = "";
- public string Text_back
- {
- get { return _Text_back; }
- set { SetProperty(ref _Text_back, value); }
- }
-
- private string _Bordcolor = "#F3465B";
- public string Bordcolor
- {
- get { return _Bordcolor; }
- set { SetProperty(ref _Bordcolor, value); }
- }
- private string _BottomBackgroubd = "#FDC7C6";
- public string BottomBackgroubd
- {
- get { return _BottomBackgroubd; }
- set { SetProperty(ref _BottomBackgroubd, value); }
- }
-
- private void InitString()
- {
- Text_Signup = App.ServiceLoader.GetString("Text_Signup");
- Text_toocode = App.ServiceLoader.GetString("Text_toocode");
- Text_vcode = App.ServiceLoader.GetString("Text_vcode");
- Text_novcode = App.ServiceLoader.GetString("Text_novcode");
- Text_recode = App.ServiceLoader.GetString("Text_recode");
- Text_back = App.ServiceLoader.GetString("Text_back");
- }
- #endregion
- private bool _EnableNextStep = false;
- 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 = "";
- 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>("RegisterDialogViewModel", out RegisterDialogViewModel);
- navigationContext.Parameters.TryGetValue<LoginDialogViewModel>("LoginDialogViewModel", out LoginDialogViewModel);
- InitString();
- if (LoginDialogViewModel!=null&&LoginDialogViewModel.IsReset == true)
- {
- CodeType = "user_reset_password";
- LoginDialogViewModel.IsReset = false;
- string code = ServiceHelper.Get_code("user_reset_password", LoginDialogViewModel.LoginEmail);
- if (code == "315")
- {
- Codeagin = Visibility.Visible;
- Codetime = " ";
- disTimer.Stop();
- RegisterCodemsg = ErrorCodeHelper.Ercode("codehad");
- Bordcolor = "#FFAF25";
- BottomBackgroubd = "#FFF1C1";
- RegisterCodemsgVis = Visibility.Visible;
- }
- else if (code == "200")
- {
- Codeagin = Visibility.Collapsed;
- Timebegin();
- }
- else
- {
- RegisterCodemsg = ErrorCodeHelper.Ercode("codehad");
- Bordcolor = "#F3465B";
- BottomBackgroubd = "#FFF1C1";
- RegisterCodemsgVis = Visibility.Visible;
- }
- }
- else
- {
- CodeType = "user_register";
- string code = ServiceHelper.Get_code("user_register", RegisterDialogViewModel.RegisterEmail);
- if (code == "315")
- {
- Codeagin = Visibility.Visible;
- Codetime = " ";
- disTimer.Stop();
- RegisterCodemsg = ErrorCodeHelper.Ercode("codehad");
- RegisterCodemsgVis = Visibility.Visible;
- Bordcolor = "#FFAF25";
- BottomBackgroubd = "#FFF1C1";
- }
- else if (code == "200")
- {
- Codeagin = Visibility.Collapsed;
- Timebegin();
- }
- else
- {
- RegisterCodemsg = ErrorCodeHelper.Ercode("codehad");
- Bordcolor = "#F3465B";
- BottomBackgroubd = "#FFF1C1";
- RegisterCodemsgVis = Visibility.Visible;
- }
- }
- if (CodeType == "user_reset_password")
- {
- CodeTypeName = Text_toocode;
- }
- else
- {
- CodeTypeName = Text_Signup;
- }
-
- }
-
- 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)
- {
-
-
- dialogs = dialogService;
- BackRegisterLastCommand = new DelegateCommand(BackRegisterLast);
- CodetooCommand = new DelegateCommand(Codetoo);
- Code6ChangedCommand = new DelegateCommand(Code6Changed);
- RegisterNextCommand = new DelegateCommand(RegisterNext);
-
- if (CodeType == "user_reset_password")
- {
- CodeTypeName = Text_toocode;
- }
- else
- {
- CodeTypeName = Text_Signup;
- }
- }
- private void Codeclear()
- {
- Code1 = "";
- Code2 = "";
- Code3 = "";
- Code4 = "";
- Code5 = "";
- Code6= "";
- }
- private bool CodeSum()
- {
- Codesum = Code1 + Code2 + Code3 + Code4 + Code5 + Code6;
- if(Codesum.Length==6)
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- //下一步按钮
- private void RegisterNext()
- {
-
- if (CodeType == "user_register")
- {
- string code = ServiceHelper.Register_email(RegisterDialogViewModel.RegisterEmail, RegisterDialogViewModel.RegisterPassword, Codesum, uuid);
- if (code == "200")
- {
- 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");
- Codeclear();
- RegisterDialogViewModel.Close();
- App.mainWindowViewModel.OpenRegisterOK();
- }
- else
- {
- EnableNextStep = false;
- RegisterCodemsg = ErrorCodeHelper.Ercode(code);
- Bordcolor = "#F3465B";
- BottomBackgroubd = "#FDC7C6";
- RegisterCodemsgVis = Visibility.Visible;
- }
-
-
- }
- else
- {
-
- LoginDialogViewModel.PasswordCode = Codesum;
- LoginDialogViewModel.RegionMan("PasswordUpdataRegion");
- Codeclear();
- }
-
- }
- //第六个密码框改变
- private void Code6Changed()
- {
-
- Codesum = Code1 + Code2 + Code3 + Code4 + Code5 + Code6;
- if (CodeSum() ==true)
- {
- if (CodeType == "user_register")
- {
- string code = ServiceHelper.Ok_code(RegisterDialogViewModel.RegisterEmail, Codesum, CodeType);
- if (code == "200")
- {
-
-
- EnableNextStep = true;
- RegisterCodemsgVis = Visibility.Collapsed;
- }
- else
- {
- EnableNextStep = false;
- RegisterCodemsg = ErrorCodeHelper.Ercode(code);
- Bordcolor = "#F3465B";
- BottomBackgroubd = "#FDC7C6";
- RegisterCodemsgVis = Visibility.Visible;
- }
- }
- else
- {
- string code = ServiceHelper.Ok_code(LoginDialogViewModel.LoginEmail, Codesum, CodeType);
- if (code == "200")
- {
- EnableNextStep = true;
- }
- else
- {
- EnableNextStep = false;
- RegisterCodemsg = ErrorCodeHelper.Ercode(code);
- Bordcolor = "#F3465B";
- BottomBackgroubd = "#FDC7C6";
- RegisterCodemsgVis = Visibility.Visible;
- }
- }
-
-
- }
- else
- {
- EnableNextStep = false;
- }
- }
- //重发密码
- 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");
- }
- Codeclear();
- }
- }
- }
|