UserDialogViewModel.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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_Office.CustomControl;
  8. using PDF_Office.Helper;
  9. using PDF_Office.Properties;
  10. using PDF_Office.Views.Dialog.ServiceDialog;
  11. using Prism.Commands;
  12. using Prism.Mvvm;
  13. using Prism.Regions;
  14. using Prism.Services.Dialogs;
  15. namespace PDF_Office.ViewModels.Dialog.ServiceDialog
  16. {
  17. public class UserDialogViewModel : BindableBase, IDialogAware
  18. {
  19. private static Guid myuuid = Guid.NewGuid();
  20. private string uuid = myuuid.ToString();
  21. public IRegionManager Region;
  22. public string Title => "用户窗口";
  23. public event Action<IDialogResult> RequestClose;
  24. private string _UserEmail=ServiceHelper.GetUser() ;
  25. public string UserEmail
  26. {
  27. get { return _UserEmail; }
  28. set { _UserEmail = value; }
  29. }
  30. private string _UserRegionName;
  31. public string UserRegionName
  32. {
  33. get { return _UserRegionName; }
  34. set { _UserRegionName = value; }
  35. }
  36. public void Close()
  37. {
  38. RequestClose?.Invoke(new Prism.Services.Dialogs.DialogResult(ButtonResult.Cancel));
  39. }
  40. public bool CanCloseDialog()
  41. {
  42. return true;
  43. }
  44. public void OnDialogClosed()
  45. {
  46. }
  47. public void OnDialogOpened(IDialogParameters parameters)
  48. {
  49. }
  50. public DelegateCommand UserOutCommand { get; set; }
  51. public DelegateCommand LogOutCommand { get; set; }
  52. UserDialogViewModel(IRegionManager regionManager, IDialogService dialogService)
  53. {
  54. this.Region = regionManager;
  55. UserRegionName = Guid.NewGuid().ToString();
  56. UserOutCommand = new DelegateCommand(UserOut);
  57. LogOutCommand = new DelegateCommand(LogOut);
  58. if (ServiceHelper.ALLEmail!="")
  59. {
  60. UserEmail = ServiceHelper.ALLEmail;
  61. }
  62. }
  63. public void UserOut()
  64. {
  65. AlertsMessage alertsMessage = new AlertsMessage();
  66. 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");
  67. if (alertsMessage.result == ContentResult.Ok)
  68. {
  69. ServiceHelper.Get_code("user_log_off", UserEmail);
  70. RegionMan("UserOutCodeRegion");
  71. }
  72. }
  73. public void LogOut()
  74. {
  75. ServiceHelper.Logout(uuid);
  76. Settings.Default.AppProperties.LoginToken = "";
  77. Settings.Default.Save();
  78. App.mainWindowViewModel.UserVis = Visibility.Collapsed;
  79. App.mainWindowViewModel.RegisterVis = Visibility.Collapsed;
  80. App.mainWindowViewModel.LoginVis = Visibility.Visible;
  81. Close();
  82. }
  83. public void RegionMan(string name)
  84. {
  85. NavigationParameters param = new NavigationParameters();
  86. param.Add("UserDialogViewModel", this);
  87. Region.RequestNavigate(UserRegionName, name, e => {
  88. var r = e.Result;
  89. }, param);
  90. }
  91. }
  92. }