UserDialogViewModel.cs 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. using System;
  2. using System.Runtime.InteropServices;
  3. using System.Windows;
  4. using PDF_Master.CustomControl;
  5. using PDF_Master.Helper;
  6. using PDF_Master.Properties;
  7. using Prism.Commands;
  8. using Prism.Mvvm;
  9. using Prism.Regions;
  10. using Prism.Services.Dialogs;
  11. namespace PDF_Master.ViewModels.Dialog.ServiceDialog
  12. {
  13. public class UserDialogViewModel : BindableBase, IDialogAware
  14. {
  15. private string uuid = ServiceHelper.GetDeviceSerialNumber();
  16. public IRegionManager Region;
  17. public string Title => "";
  18. public event Action<IDialogResult> RequestClose;
  19. public void Close()
  20. {
  21. RequestClose?.Invoke(new Prism.Services.Dialogs.DialogResult(ButtonResult.Cancel));
  22. }
  23. public bool CanCloseDialog()
  24. {
  25. return true;
  26. }
  27. public void OnDialogClosed()
  28. {
  29. }
  30. public void OnDialogOpened(IDialogParameters parameters)
  31. {
  32. if (ServiceHelper. IsConnectInternet()==false)
  33. {
  34. RegionMan("NOInternetRegion");
  35. }
  36. }
  37. #region 文案
  38. private string _Text_useracc = "";
  39. public string Text_useracc
  40. {
  41. get { return _Text_useracc; }
  42. set
  43. {
  44. SetProperty(ref _Text_useracc, value);
  45. }
  46. }
  47. private string _Text_admail = "";
  48. public string Text_admail
  49. {
  50. get { return _Text_admail; }
  51. set
  52. {
  53. SetProperty(ref _Text_admail, value);
  54. }
  55. }
  56. private string _Text_logout = "";
  57. public string Text_logout
  58. {
  59. get { return _Text_logout; }
  60. set
  61. {
  62. SetProperty(ref _Text_logout, value);
  63. }
  64. }
  65. private string _Text_no = "";
  66. public string Text_no
  67. {
  68. get { return _Text_no; }
  69. set
  70. {
  71. SetProperty(ref _Text_no, value);
  72. }
  73. }
  74. private string _Text_yes = "";
  75. public string Text_yes
  76. {
  77. get { return _Text_yes; }
  78. set
  79. {
  80. SetProperty(ref _Text_yes, value);
  81. }
  82. }
  83. private string _Text_useroutmsg = "";
  84. public string Text_useroutmsg
  85. {
  86. get { return _Text_useroutmsg; }
  87. set
  88. {
  89. SetProperty(ref _Text_useroutmsg, value);
  90. }
  91. }
  92. private string _Text_userouttol = "";
  93. public string Text_userouttol
  94. {
  95. get { return _Text_userouttol; }
  96. set
  97. {
  98. SetProperty(ref _Text_userouttol, value);
  99. }
  100. }
  101. private void InitString()
  102. {
  103. Text_useracc = App.ServiceLoader.GetString("Text_useracc");
  104. Text_admail = App.ServiceLoader.GetString("Text_admail");
  105. Text_logout = App.ServiceLoader.GetString("Text_logout");
  106. Text_userouttol = App.ServiceLoader.GetString("Text_userouttol");
  107. Text_useroutmsg = App.ServiceLoader.GetString("Text_useroutmsg");
  108. Text_yes = App.ServiceLoader.GetString("Text_yes");
  109. Text_no = App.ServiceLoader.GetString("Text_no");
  110. }
  111. #endregion
  112. private string _UserEmail = Settings.Default.UserDate.Email;
  113. public string UserEmail
  114. {
  115. get { return _UserEmail; }
  116. set { _UserEmail = value; }
  117. }
  118. private string _UserRegionName;
  119. public string UserRegionName
  120. {
  121. get { return _UserRegionName; }
  122. set { _UserRegionName = value; }
  123. }
  124. public DelegateCommand UserOutCommand { get; set; }
  125. public DelegateCommand LogOutCommand { get; set; }
  126. UserDialogViewModel(IRegionManager regionManager, IDialogService dialogService)
  127. {
  128. this.Region = regionManager;
  129. InitString();
  130. UserRegionName = Guid.NewGuid().ToString();
  131. UserOutCommand = new DelegateCommand(UserOut);
  132. LogOutCommand = new DelegateCommand(LogOut);
  133. UserEmail = Settings.Default.UserDate.Email;
  134. }
  135. public void UserOut()
  136. {
  137. AlertsMessage alertsMessage = new AlertsMessage();
  138. alertsMessage.ShowDialog(Text_userouttol, Text_useroutmsg, Text_no, Text_yes);
  139. if (alertsMessage.result == ContentResult.Ok)
  140. {
  141. ServiceHelper.Get_code("user_log_off", UserEmail);
  142. RegionMan("UserOutCodeRegion");
  143. }
  144. }
  145. public void LogOut()
  146. {
  147. ServiceHelper.Logout(uuid);
  148. Settings.Default.AppProperties.LoginToken = "";
  149. Settings.Default.Save();
  150. App.mainWindowViewModel.UserVis = Visibility.Collapsed;
  151. App.mainWindowViewModel.RegisterVis = Visibility.Collapsed;
  152. App.mainWindowViewModel.LoginVis = Visibility.Visible;
  153. Close();
  154. }
  155. public void RegionMan(string name)
  156. {
  157. NavigationParameters param = new NavigationParameters();
  158. param.Add("UserDialogViewModel", this);
  159. Region.RequestNavigate(UserRegionName, name, e => {
  160. var r = e.Result;
  161. }, param);
  162. }
  163. }
  164. }