UserDialogViewModel.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. public DelegateCommand CloseDialogCommand { get; set; }
  53. UserDialogViewModel(IRegionManager regionManager, IDialogService dialogService)
  54. {
  55. this.Region = regionManager;
  56. UserRegionName = Guid.NewGuid().ToString();
  57. UserOutCommand = new DelegateCommand(UserOut);
  58. LogOutCommand = new DelegateCommand(LogOut);
  59. CloseDialogCommand = new DelegateCommand(CloseDialog);
  60. if (ServiceHelper.ALLEmail!="")
  61. {
  62. UserEmail = ServiceHelper.ALLEmail;
  63. }
  64. }
  65. private void CloseDialog()
  66. {
  67. this.Close();
  68. }
  69. public void UserOut()
  70. {
  71. AlertsMessage alertsMessage = new AlertsMessage();
  72. 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");
  73. if (alertsMessage.result == ContentResult.Ok)
  74. {
  75. ServiceHelper.Get_code("user_log_off", UserEmail);
  76. RegionMan("UserOutCodeRegion");
  77. }
  78. }
  79. public void LogOut()
  80. {
  81. ServiceHelper.Logout(uuid);
  82. Settings.Default.AppProperties.LoginToken = "";
  83. Settings.Default.Save();
  84. App.mainWindowViewModel.UserVis = Visibility.Collapsed;
  85. App.mainWindowViewModel.RegisterVis = Visibility.Collapsed;
  86. App.mainWindowViewModel.LoginVis = Visibility.Visible;
  87. Close();
  88. }
  89. public void RegionMan(string name)
  90. {
  91. NavigationParameters param = new NavigationParameters();
  92. param.Add("UserDialogViewModel", this);
  93. Region.RequestNavigate(UserRegionName, name, e => {
  94. var r = e.Result;
  95. }, param);
  96. }
  97. }
  98. }