UserDialogViewModel.cs 5.7 KB

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