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 UserOutCodeRegionViewModel : BindableBase, INavigationAware { private string uuid = ServiceHelper.GetDeviceSerialNumber(); private ErrorCodeHelper ErrorCodeHelper = new ErrorCodeHelper(); public IDialogService dialogs; private UserDialogViewModel UserDialogViewModel; private int time = 60; #region 文案 private string _Text_userout = ""; public string Text_userout { get { return _Text_userout; } set { SetProperty(ref _Text_userout, value); } } private string _Text_Cancellatio = ""; public string Text_Cancellatio { get { return _Text_Cancellatio; } set { SetProperty(ref _Text_Cancellatio, 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 _BtText_cancel = ""; public string BtText_cancel { get { return _BtText_cancel; } set { SetProperty(ref _BtText_cancel, value); } } private void InitString() { Text_userout = App.ServiceLoader.GetString("Text_userout"); Text_Cancellatio = App.ServiceLoader.GetString("Text_Cancellatio"); Text_vcode = App.ServiceLoader.GetString("Text_vcode"); Text_novcode = App.ServiceLoader.GetString("Text_novcode"); Text_recode = App.ServiceLoader.GetString("Text_recode"); BtText_cancel = App.ServiceLoader.GetString("Text_cancel"); } #endregion private bool _EnableNextStep =false; public bool EnableNextStep { get { return _EnableNextStep; } set { SetProperty(ref _EnableNextStep, 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 _UserCodemsg = ""; public string UserCodemsg { get { return _UserCodemsg; } set { SetProperty(ref _UserCodemsg, value); } } private Visibility _codeagin = Visibility.Collapsed; public Visibility Codeagin { get { return _codeagin; } set { SetProperty(ref _codeagin, value); } } private Visibility _UserCodemsgVis = Visibility.Collapsed; public Visibility UserCodemsgVis { get { return _UserCodemsgVis; } set { SetProperty(ref _UserCodemsgVis, value); } } public bool IsNavigationTarget(NavigationContext navigationContext) { return true; } public void OnNavigatedFrom(NavigationContext navigationContext) { } public void OnNavigatedTo(NavigationContext navigationContext) { navigationContext.Parameters.TryGetValue("UserDialogViewModel", out UserDialogViewModel); } public DelegateCommand UserOutCancelCommand { get; set; } public DelegateCommand CodetooCommand { get; set; } public DelegateCommand Code6ChangedCommand { get; set; } public DelegateCommand UserOutCommand { get; set; } public UserOutCodeRegionViewModel(IRegionManager regionManager, IDialogService dialogService) { dialogs = dialogService; UserOutCancelCommand = new DelegateCommand(UserOutCancel); CodetooCommand = new DelegateCommand(Codetoo); Code6ChangedCommand = new DelegateCommand(Code6Changed); UserOutCommand = new DelegateCommand(UserOut); InitString(); string code = ServiceHelper.Get_code("user_log_off", Settings.Default.UserDate.Email); if (code=="315") { Codeagin = Visibility.Visible; Codetime = " "; disTimer.Stop(); UserCodemsg = ErrorCodeHelper.Ercode("codehad"); UserCodemsgVis = Visibility.Visible; } else if (code == "200") { Codeagin = Visibility.Collapsed; Timebegin(); } } private void UserOutCancel() { UserDialogViewModel.Close(); } //注销 private void UserOut() { Codesum = Code1 + Code2 + Code3 + Code4 + Code5 + Code6; if (CodeSum()==true) { string code = ServiceHelper.Usergout(Codesum); if (code == "200") { Settings.Default.AppProperties.LoginToken = ""; App.IsLogin = false; Settings.Default.Save(); App.mainWindowViewModel.UserVis = Visibility.Collapsed; App.mainWindowViewModel.RegisterVis = Visibility.Collapsed; App.mainWindowViewModel.LoginVis = Visibility.Visible; UserDialogViewModel.RegionMan("UserOutOKRegion"); } else { EnableNextStep = false; UserCodemsg = ErrorCodeHelper.Ercode(code); UserCodemsgVis = Visibility.Visible; } } } //第六个密码框改变 private void Code6Changed() { Codesum = Code1 + Code2 + Code3 + Code4 + Code5 + Code6; if (CodeSum() == true) { string code = ServiceHelper.Ok_code(UserDialogViewModel.UserEmail, Codesum, "user_log_off"); if ( code== "200") { EnableNextStep = true; UserCodemsgVis = Visibility.Collapsed; } else { EnableNextStep = false; UserCodemsg = ErrorCodeHelper.Ercode(code); UserCodemsgVis = Visibility.Visible; } } else { EnableNextStep = false; } } private bool CodeSum() { Codesum = Code1 + Code2 + Code3 + Code4 + Code5 + Code6; if (Codesum.Length == 6) { return true; } else { return false; } } private void Codetoo() { string code = ServiceHelper.Get_code("user_log_off", Settings.Default.UserDate.Email); if (code == "315") { Codeagin = Visibility.Visible; Codetime = " "; disTimer.Stop(); UserCodemsg = ErrorCodeHelper.Ercode("codehad"); UserCodemsgVis = Visibility.Visible; } else if (code == "200") { Codeagin = Visibility.Collapsed; Timebegin(); } } private DispatcherTimer disTimer = new DispatcherTimer(); public void disTimer_Tick(object sender, EventArgs e) { if (time == 0) { Codeagin = Visibility.Visible; Codetime = " "; disTimer.Stop(); } else { time--; Codetime = " (" + time.ToString() + ")"; } } public void Timebegin() { time = 60; //设置定时器 disTimer.Tick += new EventHandler(disTimer_Tick);//每一秒执行的方法 disTimer.Interval = new TimeSpan(10000000); //时间间隔为一秒。 disTimer.Start();//计时开始 } } }