UserDialogViewModel.cs 15 KB

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