UserDialogViewModel.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459
  1. using System;
  2. using System.Diagnostics;
  3. using System.Runtime.InteropServices;
  4. using System.Windows;
  5. using System.Windows.Controls;
  6. using System.Windows.Media;
  7. using PDF_Master.CustomControl;
  8. using PDF_Master.Helper;
  9. using PDF_Master.Properties;
  10. using Prism.Commands;
  11. using Prism.Mvvm;
  12. using Prism.Regions;
  13. using Prism.Services.Dialogs;
  14. namespace PDF_Master.ViewModels.Dialog.ServiceDialog
  15. {
  16. public class UserDialogViewModel : BindableBase, IDialogAware
  17. {
  18. private string uuid = ServiceHelper.GetDeviceSerialNumber();
  19. public IRegionManager Region;
  20. public string Title => "";
  21. public event Action<IDialogResult> RequestClose;
  22. public void Close()
  23. {
  24. RequestClose?.Invoke(new Prism.Services.Dialogs.DialogResult(ButtonResult.Cancel));
  25. }
  26. public bool CanCloseDialog()
  27. {
  28. return true;
  29. }
  30. public void OnDialogClosed()
  31. {
  32. App.UserOpen = false;
  33. }
  34. public void OnDialogOpened(IDialogParameters parameters)
  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_cancel = "";
  66. public string Text_cancel
  67. {
  68. get { return _Text_cancel; }
  69. set
  70. {
  71. SetProperty(ref _Text_cancel, value);
  72. }
  73. }
  74. private string _Text_no = "";
  75. public string Text_no
  76. {
  77. get { return _Text_no; }
  78. set
  79. {
  80. SetProperty(ref _Text_no, value);
  81. }
  82. }
  83. private string _Text_yes = "";
  84. public string Text_yes
  85. {
  86. get { return _Text_yes; }
  87. set
  88. {
  89. SetProperty(ref _Text_yes, value);
  90. }
  91. }
  92. private string _Text_useroutmsg = "";
  93. public string Text_useroutmsg
  94. {
  95. get { return _Text_useroutmsg; }
  96. set
  97. {
  98. SetProperty(ref _Text_useroutmsg, value);
  99. }
  100. }
  101. private string _Text_userouttol = "";
  102. public string Text_userouttol
  103. {
  104. get { return _Text_userouttol; }
  105. set
  106. {
  107. SetProperty(ref _Text_userouttol, value);
  108. }
  109. }
  110. private Brush _TextSubscribeStateColor = (Brush)new BrushConverter().ConvertFromString("#252629");
  111. public Brush TextSubscribeStateColor
  112. {
  113. get { return _TextSubscribeStateColor; }
  114. set
  115. {
  116. SetProperty(ref _TextSubscribeStateColor, value);
  117. }
  118. }
  119. private string _TextSubscribeState = "";
  120. public string TextSubscribeState
  121. {
  122. get { return _TextSubscribeState; }
  123. set
  124. {
  125. SetProperty(ref _TextSubscribeState, value);
  126. }
  127. }
  128. private string _TextSubscribeEndtime = "";
  129. public string TextSubscribeEndtime
  130. {
  131. get { return _TextSubscribeEndtime; }
  132. set
  133. {
  134. SetProperty(ref _TextSubscribeEndtime, value);
  135. }
  136. }
  137. private string _TextSubscribetimetext = "";
  138. public string TextSubscribetimetext
  139. {
  140. get { return _TextSubscribetimetext; }
  141. set
  142. {
  143. SetProperty(ref _TextSubscribetimetext, value);
  144. }
  145. }
  146. private string _TextStatus;
  147. public string TextStatus
  148. {
  149. get { return _TextStatus; }
  150. set { _TextStatus = value; }
  151. }
  152. private string _TextOnTrial;
  153. public string TextOnTrial
  154. {
  155. get { return _TextOnTrial; }
  156. set { _TextOnTrial = value; }
  157. }
  158. private string _TextTrialExpired;
  159. public string TextTrialExpired
  160. {
  161. get { return _TextTrialExpired; }
  162. set { _TextTrialExpired = value; }
  163. }
  164. private string _TextSubscriptionExpired;
  165. public string TextSubscriptionExpired
  166. {
  167. get { return _TextSubscriptionExpired; }
  168. set { _TextSubscriptionExpired = value; }
  169. }
  170. private string _TextAutorenewal;
  171. public string TextAutorenewal
  172. {
  173. get { return _TextAutorenewal; }
  174. set { _TextAutorenewal = value; }
  175. }
  176. private string _TextSubscription;
  177. public string TextSubscription
  178. {
  179. get { return _TextSubscription; }
  180. set { _TextSubscription = value; }
  181. }
  182. private string _TextOrderInformation;
  183. public string TextOrderInformation
  184. {
  185. get { return _TextOrderInformation; }
  186. set { _TextOrderInformation = value; }
  187. }
  188. private string _BtnTextSubscribe;
  189. public string BtnTextSubscribe
  190. {
  191. get { return _BtnTextSubscribe; }
  192. set { _BtnTextSubscribe = value; }
  193. }
  194. private void InitString()
  195. {
  196. Text_useracc = App.ServiceLoader.GetString("Text_useracc");
  197. Text_admail = App.ServiceLoader.GetString("Text_admail");
  198. Text_logout = App.ServiceLoader.GetString("Text_logout");
  199. Text_cancel = App.ServiceLoader.GetString("Text_cancel");
  200. Text_userouttol = App.ServiceLoader.GetString("Text_userouttol");
  201. Text_useroutmsg = App.ServiceLoader.GetString("Text_useroutmsg");
  202. Text_yes = App.ServiceLoader.GetString("Text_yes");
  203. Text_no = App.ServiceLoader.GetString("Text_no");
  204. TextStatus = App.ServiceLoader.GetString("TextStatus");
  205. TextOnTrial = App.ServiceLoader.GetString("TextOnTrial");
  206. TextTrialExpired = App.ServiceLoader.GetString("TextTrialExpired");
  207. TextSubscriptionExpired = App.ServiceLoader.GetString("TextSubscriptionExpired");
  208. TextAutorenewal = App.ServiceLoader.GetString("TextAutorenewal");
  209. TextSubscription = App.ServiceLoader.GetString("TextSubscription");
  210. TextOrderInformation = App.ServiceLoader.GetString("TextOrderInformation");
  211. BtnTextSubscribe = App.ServiceLoader.GetString("BtnTextSubscribe");
  212. }
  213. #endregion
  214. private string _Useremailchar = Settings.Default.UserDate.Email.Substring(0, 1);
  215. public string Useremailchar
  216. {
  217. get { return _Useremailchar; }
  218. set
  219. {
  220. SetProperty(ref _Useremailchar, value);
  221. }
  222. }
  223. private string _UserEmail = Settings.Default.UserDate.Email;
  224. public string UserEmail
  225. {
  226. get { return _UserEmail; }
  227. set { _UserEmail = value; }
  228. }
  229. private string _UserRegionName;
  230. public string UserRegionName
  231. {
  232. get { return _UserRegionName; }
  233. set { _UserRegionName = value; }
  234. }
  235. private Visibility _LinkuserdataVis = Visibility.Collapsed;
  236. public Visibility LinkuserdataVis
  237. {
  238. get { return _LinkuserdataVis; }
  239. set { _LinkuserdataVis = value; }
  240. }
  241. private Visibility _Subscriptionbox =Visibility.Collapsed;
  242. public Visibility Subscriptionbox
  243. {
  244. get { return _Subscriptionbox; }
  245. set { _Subscriptionbox = value; }
  246. }
  247. private Visibility _Subscriptionbtn = Visibility.Collapsed;
  248. public Visibility Subscriptionbtn
  249. {
  250. get { return _Subscriptionbtn; }
  251. set { _Subscriptionbtn = value; }
  252. }
  253. private Visibility _Subscriptionauto = Visibility.Collapsed;
  254. public Visibility Subscriptionauto
  255. {
  256. get { return _Subscriptionauto; }
  257. set { _Subscriptionauto = value; }
  258. }
  259. private string _uristore = ServiceHelper.WebHost + "/windows/store/master-subscription?email=" + Settings.Default.UserDate.Email;
  260. public string Uristore
  261. {
  262. get { return _uristore; }
  263. set
  264. {
  265. SetProperty(ref _uristore, value);
  266. }
  267. }
  268. private string _Uriuserdata = ServiceHelper.WebHost + "/windows/account/master-subscription?appid=16&productId=22&token=" + Settings.Default.AppProperties.LoginToken;
  269. public string Uriuserdata
  270. {
  271. get { return _Uriuserdata; }
  272. set
  273. {
  274. SetProperty(ref _Uriuserdata, value);
  275. }
  276. }
  277. public DelegateCommand LinkstoreCommand { get; set; }
  278. public DelegateCommand UserOutCommand { get; set; }
  279. public DelegateCommand LogOutCommand { get; set; }
  280. public DelegateCommand LinkuserdataCommand { get; set; }
  281. UserDialogViewModel(IRegionManager regionManager, IDialogService dialogService)
  282. {
  283. this.Region = regionManager;
  284. InitString();
  285. UserRegionName = Guid.NewGuid().ToString();
  286. UserOutCommand = new DelegateCommand(UserOut);
  287. LogOutCommand = new DelegateCommand(LogOut);
  288. LinkstoreCommand = new DelegateCommand(Linkstore);
  289. LinkuserdataCommand = new DelegateCommand(Linkuserdata);
  290. TextSubscribeEndtime = Settings.Default.UserDate.subscribeendDate;
  291. UserEmail = Settings.Default.UserDate.Email;
  292. if(Settings.Default.UserDate.subscribestatus==1&& Settings.Default.UserDate.subscribepayType==1)
  293. {
  294. LinkuserdataVis = Visibility.Collapsed;
  295. Subscriptionbox = Visibility.Visible;
  296. Subscriptionauto= Visibility.Visible;
  297. TextSubscribeState= App.ServiceLoader.GetString("TextSubscribeStateOnTrial");
  298. TextSubscribeStateColor = (Brush)new BrushConverter().ConvertFromString("#252629");
  299. TextSubscribetimetext = App.ServiceLoader.GetString("TextSubscribetimetextOnTrial");
  300. }
  301. else if(Settings.Default.UserDate.subscribestatus == 1 && Settings.Default.UserDate.subscribepayType == 0)
  302. {
  303. LinkuserdataVis = Visibility.Collapsed;
  304. Subscriptionbox = Visibility.Visible;
  305. Subscriptionbtn = Visibility.Visible;
  306. Subscriptionauto = Visibility.Hidden;
  307. TextSubscribeState = App.ServiceLoader.GetString("TextSubscribeStateOnTrial");
  308. TextSubscribeStateColor = (Brush)new BrushConverter().ConvertFromString("#252629");
  309. TextSubscribetimetext = App.ServiceLoader.GetString("TextSubscribetimeExpired");
  310. }
  311. else if (Settings.Default.UserDate.subscribestatus == 2 )
  312. {
  313. LinkuserdataVis = Visibility.Collapsed;
  314. Subscriptionbox = Visibility.Visible;
  315. Subscriptionbtn = Visibility.Visible;
  316. Subscriptionauto = Visibility.Hidden;
  317. TextSubscribeState = App.ServiceLoader.GetString("TextSubscribeStateExpired");
  318. TextSubscribeStateColor= (Brush)new BrushConverter().ConvertFromString("#F3465B");
  319. TextSubscribetimetext = App.ServiceLoader.GetString("TextSubscribetimeExpired");
  320. }
  321. else
  322. {
  323. LinkuserdataVis = Visibility.Visible;
  324. Subscriptionbox = Visibility.Collapsed;
  325. Subscriptionbtn = Visibility.Collapsed;
  326. TextSubscribeState = App.ServiceLoader.GetString("TextSubscribeStateExpired");
  327. TextSubscribeStateColor = (Brush)new BrushConverter().ConvertFromString("#F3465B");
  328. TextSubscribetimetext = App.ServiceLoader.GetString("TextSubscribetimeExpired");
  329. }
  330. }
  331. private void Linkstore()
  332. {
  333. Process.Start(new ProcessStartInfo(Uristore));
  334. }
  335. private void Linkuserdata()
  336. {
  337. Process.Start(new ProcessStartInfo(Uriuserdata));
  338. }
  339. public void UserOut()
  340. {
  341. if(Settings.Default.UserDate.subscribestatus == 1)
  342. {
  343. AlertsMessage alertsMessage = new AlertsMessage();
  344. alertsMessage.ShowDialog(App.ServiceLoader.GetString("TextCancellationtop"), App.ServiceLoader.GetString("TextCancellation"), App.ServiceLoader.GetString("Text_ok"),IconType.Tip);
  345. }
  346. else
  347. {
  348. AlertsMessage alertsMessage = new AlertsMessage();
  349. alertsMessage.ShowDialog(Text_userouttol, Text_useroutmsg, App.ServiceLoader.GetString("Text_yes"), App.ServiceLoader.GetString("Text_no"), IconType.Tip);
  350. //调整按钮显示位置,cancel按钮表示确认退出
  351. //目的是尽量引导用户不注销
  352. if (alertsMessage.result == ContentResult.MiddleCancel)
  353. {
  354. RegionMan("UserOutCodeRegion");
  355. }
  356. }
  357. }
  358. public void LogOut()
  359. {
  360. ServiceHelper.Logout(uuid);
  361. Settings.Default.AppProperties.LoginToken = "";
  362. Settings.Default.Save();
  363. App.mainWindowViewModel.UserVis = Visibility.Collapsed;
  364. App.mainWindowViewModel.RegisterVis = Visibility.Collapsed;
  365. App.mainWindowViewModel.LoginVis = Visibility.Visible;
  366. Close();
  367. }
  368. public void RegionMan(string name)
  369. {
  370. NavigationParameters param = new NavigationParameters();
  371. param.Add("UserDialogViewModel", this);
  372. Region.RequestNavigate(UserRegionName, name, e => {
  373. var r = e.Result;
  374. }, param);
  375. }
  376. }
  377. }