UserDialogViewModel.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Windows;
  7. using PDF_Master.CustomControl;
  8. using PDF_Master.Helper;
  9. using PDF_Master.Properties;
  10. using PDF_Master.Views.Dialog.ServiceDialog;
  11. using Prism.Commands;
  12. using Prism.Mvvm;
  13. using Prism.Regions;
  14. using Prism.Services.Dialogs;
  15. namespace PDF_Master.ViewModels.Dialog.ServiceDialog
  16. {
  17. public class UserDialogViewModel : BindableBase, IDialogAware
  18. {
  19. private string uuid = ServiceHelper.GetDeviceSerialNumber();
  20. public IRegionManager Region;
  21. public string Title => "用户窗口";
  22. public event Action<IDialogResult> RequestClose;
  23. private string _UserEmail = Settings.Default.UserDate.Email;
  24. public string UserEmail
  25. {
  26. get { return _UserEmail; }
  27. set { _UserEmail = value; }
  28. }
  29. private string _UserRegionName;
  30. public string UserRegionName
  31. {
  32. get { return _UserRegionName; }
  33. set { _UserRegionName = value; }
  34. }
  35. public void Close()
  36. {
  37. RequestClose?.Invoke(new Prism.Services.Dialogs.DialogResult(ButtonResult.Cancel));
  38. }
  39. public bool CanCloseDialog()
  40. {
  41. return true;
  42. }
  43. public void OnDialogClosed()
  44. {
  45. }
  46. public void OnDialogOpened(IDialogParameters parameters)
  47. {
  48. }
  49. public DelegateCommand UserOutCommand { get; set; }
  50. public DelegateCommand LogOutCommand { get; set; }
  51. UserDialogViewModel(IRegionManager regionManager, IDialogService dialogService)
  52. {
  53. this.Region = regionManager;
  54. UserRegionName = Guid.NewGuid().ToString();
  55. UserOutCommand = new DelegateCommand(UserOut);
  56. LogOutCommand = new DelegateCommand(LogOut);
  57. UserEmail = Settings.Default.UserDate.Email;
  58. }
  59. public void UserOut()
  60. {
  61. AlertsMessage alertsMessage = new AlertsMessage();
  62. alertsMessage.ShowDialog("Are you sure you want to cancel?", "Cancellation cannot be withdrawn, it will be completed within 3 working days, until then your account will be frozen and cannot be logged in, are you sure you want to cancel your account?", "Cancel", "OK");
  63. if (alertsMessage.result == ContentResult.Ok)
  64. {
  65. ServiceHelper.Get_code("user_log_off", UserEmail);
  66. RegionMan("UserOutCodeRegion");
  67. }
  68. }
  69. public void LogOut()
  70. {
  71. ServiceHelper.Logout(uuid);
  72. Settings.Default.AppProperties.LoginToken = "";
  73. Settings.Default.Save();
  74. App.mainWindowViewModel.UserVis = Visibility.Collapsed;
  75. App.mainWindowViewModel.RegisterVis = Visibility.Collapsed;
  76. App.mainWindowViewModel.LoginVis = Visibility.Visible;
  77. Close();
  78. }
  79. public void RegionMan(string name)
  80. {
  81. NavigationParameters param = new NavigationParameters();
  82. param.Add("UserDialogViewModel", this);
  83. Region.RequestNavigate(UserRegionName, name, e => {
  84. var r = e.Result;
  85. }, param);
  86. }
  87. }
  88. }