UserDialogViewModel.cs 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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 _UserEmail = Settings.Default.UserDate.Email;
  114. public string UserEmail
  115. {
  116. get { return _UserEmail; }
  117. set { _UserEmail = value; }
  118. }
  119. private string _UserRegionName;
  120. public string UserRegionName
  121. {
  122. get { return _UserRegionName; }
  123. set { _UserRegionName = value; }
  124. }
  125. public DelegateCommand UserOutCommand { get; set; }
  126. public DelegateCommand LogOutCommand { get; set; }
  127. UserDialogViewModel(IRegionManager regionManager, IDialogService dialogService)
  128. {
  129. this.Region = regionManager;
  130. InitString();
  131. UserRegionName = Guid.NewGuid().ToString();
  132. UserOutCommand = new DelegateCommand(UserOut);
  133. LogOutCommand = new DelegateCommand(LogOut);
  134. UserEmail = Settings.Default.UserDate.Email;
  135. }
  136. public void UserOut()
  137. {
  138. AlertsMessage alertsMessage = new AlertsMessage();
  139. alertsMessage.ShowDialog(Text_userouttol, Text_useroutmsg, "Cancel", "Yes",IconType.Tip);
  140. if (alertsMessage.result == ContentResult.Ok)
  141. {
  142. ServiceHelper.Get_code("user_log_off", UserEmail);
  143. RegionMan("UserOutCodeRegion");
  144. }
  145. }
  146. public void LogOut()
  147. {
  148. ServiceHelper.Logout(uuid);
  149. Settings.Default.AppProperties.LoginToken = "";
  150. Settings.Default.Save();
  151. App.mainWindowViewModel.UserVis = Visibility.Collapsed;
  152. App.mainWindowViewModel.RegisterVis = Visibility.Collapsed;
  153. App.mainWindowViewModel.LoginVis = Visibility.Visible;
  154. Close();
  155. }
  156. public void RegionMan(string name)
  157. {
  158. NavigationParameters param = new NavigationParameters();
  159. param.Add("UserDialogViewModel", this);
  160. Region.RequestNavigate(UserRegionName, name, e => {
  161. var r = e.Result;
  162. }, param);
  163. }
  164. }
  165. }