SubscriptionDialogViewModel.cs 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  1. using ComPDFKit.PDFWatermark;
  2. using ComPDFKitViewer.PdfViewer;
  3. using PDF_Master.Helper;
  4. using PDF_Master.Model;
  5. using PDF_Master.Model.EditTools.Watermark;
  6. using PDF_Master.Properties;
  7. using PDFReader_WPF.Helper;
  8. using Prism.Commands;
  9. using Prism.Mvvm;
  10. using Prism.Regions;
  11. using Prism.Services.Dialogs;
  12. using System;
  13. using System.Collections.Generic;
  14. using System.Diagnostics;
  15. using System.IO;
  16. using System.Linq;
  17. using System.Text;
  18. using System.Threading.Tasks;
  19. using System.Windows;
  20. using System.Windows.Media.Imaging;
  21. using System.Windows.Resources;
  22. namespace PDF_Master.ViewModels.Dialog.ServiceDialog
  23. {
  24. public class SubscriptionDialogViewModel : BindableBase, IDialogAware
  25. {
  26. public string Title => "";
  27. private ViewContentViewModel viewContentViewModel;
  28. private string open;
  29. public event Action<IDialogResult> RequestClose;
  30. #region 文案
  31. #endregion
  32. /// <summary>
  33. /// 价格优惠bord
  34. /// </summary>
  35. private Visibility _Vishalfprice = Visibility.Visible;
  36. public Visibility Vishalfprice
  37. {
  38. get { return _Vishalfprice; }
  39. set
  40. {
  41. SetProperty(ref _Vishalfprice, value);
  42. }
  43. }
  44. private double _RightBtnWidth = 192;
  45. public double RightBtnWidth
  46. {
  47. get { return _RightBtnWidth; }
  48. set
  49. {
  50. SetProperty(ref _RightBtnWidth, value);
  51. }
  52. }
  53. /// <summary>
  54. /// 左边按钮的vis
  55. /// </summary>
  56. private Visibility _LeftBtnVis = Visibility.Visible;
  57. public Visibility LeftBtnVis
  58. {
  59. get { return _LeftBtnVis; }
  60. set
  61. {
  62. SetProperty(ref _LeftBtnVis, value);
  63. }
  64. }
  65. /// <summary>
  66. /// 价格优惠
  67. /// </summary>
  68. private string _Textprice = "$39.99/year";
  69. public string Textprice
  70. {
  71. get { return _Textprice; }
  72. set
  73. {
  74. SetProperty(ref _Textprice, value);
  75. }
  76. }
  77. private string _TextSubscriptionBenefit;
  78. public string TextSubscriptionBenefit
  79. {
  80. get { return _TextSubscriptionBenefit; }
  81. set { SetProperty(ref _TextSubscriptionBenefit, value); }
  82. }
  83. private string _TextSavewithout;
  84. public string TextSavewithout
  85. {
  86. get { return _TextSavewithout; }
  87. set { SetProperty(ref _TextSavewithout, value); }
  88. }
  89. private string _TextWhenyou;
  90. public string TextWhenyou
  91. {
  92. get { return _TextWhenyou; }
  93. set { SetProperty(ref _TextWhenyou, value); }
  94. }
  95. private string _TextConvertPDF;
  96. public string TextConvertPDF
  97. {
  98. get { return _TextConvertPDF; }
  99. set { SetProperty(ref _TextConvertPDF, value); }
  100. }
  101. private string _TextConvertPDFto;
  102. public string TextConvertPDFto
  103. {
  104. get { return _TextConvertPDFto; }
  105. set { SetProperty(ref _TextConvertPDFto, value); }
  106. }
  107. private string _TextAIassitant;
  108. public string TextAIassitant
  109. {
  110. get { return _TextAIassitant; }
  111. set { SetProperty(ref _TextAIassitant, value); }
  112. }
  113. private string _TextSupportAI;
  114. public string TextSupportAI
  115. {
  116. get { return _TextSupportAI; }
  117. set { SetProperty(ref _TextSupportAI, value); }
  118. }
  119. private string _BtnTextSavewithWatermark;
  120. public string BtnTextSavewithWatermark
  121. {
  122. get { return _BtnTextSavewithWatermark; }
  123. set { SetProperty(ref _BtnTextSavewithWatermark, value); }
  124. }
  125. private string _Textoff;
  126. public string Textoff
  127. {
  128. get { return _Textoff; }
  129. set { SetProperty(ref _Textoff, value); }
  130. }
  131. private string _BtnTextSubscribe;
  132. public string BtnTextSubscribe
  133. {
  134. get { return _BtnTextSubscribe; }
  135. set { SetProperty(ref _BtnTextSubscribe, value); }
  136. }
  137. private string _uristore = "https://www.pdfreaderpro.com/windows/store/permanent";
  138. public string Uristore
  139. {
  140. get { return _uristore; }
  141. set
  142. {
  143. SetProperty(ref _uristore, value);
  144. }
  145. }
  146. public DelegateCommand LinkstoreCommand { get; set; }
  147. public DelegateCommand WarermarkSavingCommand { get; set; }
  148. public DelegateCommand RefreshCommand { get; set; }
  149. private void InitString()
  150. {
  151. TextSubscriptionBenefit = App.ServiceLoader.GetString("TextSubscriptionBenefit");
  152. TextSavewithout = App.ServiceLoader.GetString("TextSavewithout");
  153. TextWhenyou = App.ServiceLoader.GetString("TextWhenyou");
  154. TextConvertPDF = App.ServiceLoader.GetString("TextConvertPDFwithout");
  155. TextConvertPDFto = App.ServiceLoader.GetString("TextConvertPDFto");
  156. TextAIassitant = App.ServiceLoader.GetString("TextAIassitant");
  157. TextSupportAI = App.ServiceLoader.GetString("TextSupportAI");
  158. Textoff = App.ServiceLoader.GetString("Textoff");
  159. BtnTextSubscribe = App.ServiceLoader.GetString("BtnTextSubscribe");
  160. }
  161. public SubscriptionDialogViewModel(IRegionManager regionManager, IDialogService dialogService)
  162. {
  163. RefreshCommand = new DelegateCommand(Refresh);
  164. LinkstoreCommand = new DelegateCommand(Linkstore);
  165. WarermarkSavingCommand = new DelegateCommand(WarermarkSaving);
  166. InitString();
  167. if (Settings.Default.UserDate.subscribestatus == 2)
  168. {
  169. Textprice = "$79.99/year";
  170. Vishalfprice = Visibility.Collapsed;
  171. }
  172. else
  173. {
  174. Textprice = "$39.99/year";
  175. Vishalfprice = Visibility.Visible;
  176. }
  177. }
  178. private void Linkstore()
  179. {
  180. DataTrackingHelper.AddThirdPath();
  181. DataTrackingHelper.SendPurchaseEvent();
  182. DataTrackingHelper.SendEvent(DataTrackingHelper.EventType.PUW, "Sub_PUW", "PUW_Sub_Subscribe");
  183. Process.Start(new ProcessStartInfo(Uristore));
  184. }
  185. /// <summary>
  186. /// 水印保存
  187. /// </summary>
  188. private void WarermarkSaving()
  189. {
  190. DataTrackingHelper.SendEvent(DataTrackingHelper.EventType.PUW, "Sub_PUW", "PUW_Sub_SaveWatermark");
  191. String IsFormSave = "FormSave";
  192. if(open== "saveAs")
  193. {
  194. RequestClose?.Invoke(new Prism.Services.Dialogs.DialogResult(ButtonResult.OK));
  195. }
  196. else
  197. {
  198. if(viewContentViewModel != null&&viewContentViewModel.saveAsFile(null, IsFormSave)==false)
  199. {
  200. RequestClose?.Invoke(new Prism.Services.Dialogs.DialogResult(ButtonResult.Cancel));
  201. }
  202. else
  203. {
  204. RequestClose?.Invoke(new Prism.Services.Dialogs.DialogResult(ButtonResult.OK));
  205. }
  206. }
  207. }
  208. /// <summary>
  209. /// 刷新订阅状态按钮
  210. /// </summary>
  211. private void Refresh()
  212. {
  213. if (Settings.Default.AppProperties.LoginToken != "")
  214. {
  215. string code = ServiceHelper.GetUser();
  216. if (code == "330" || code == "304")
  217. {
  218. App.mainWindowViewModel.UserVis = Visibility.Collapsed;
  219. App.mainWindowViewModel.LoginVis = Visibility.Visible;
  220. App.mainWindowViewModel.OphVis = Visibility.Visible;
  221. if (Settings.Default.UserDate.IsLoginoff == false)
  222. {
  223. App.mainWindowViewModel.OpenLoginoff();
  224. Settings.Default.UserDate.IsLoginoff = true;
  225. Settings.Default.Save();
  226. }
  227. }
  228. }
  229. else
  230. {
  231. App.mainWindowViewModel.UserVis = Visibility.Collapsed;
  232. App.mainWindowViewModel.LoginVis = Visibility.Visible;
  233. App.mainWindowViewModel.OphVis = Visibility.Visible;
  234. }
  235. if (Settings.Default.UserDate.subscribestatus == 1&&App.IsLogin == true)
  236. {
  237. Close();
  238. }
  239. }
  240. public void Close()
  241. {
  242. RequestClose?.Invoke(new Prism.Services.Dialogs.DialogResult(ButtonResult.Cancel));
  243. }
  244. public bool CanCloseDialog()
  245. {
  246. return true;
  247. }
  248. public void OnDialogClosed()
  249. {
  250. }
  251. public void OnDialogOpened(IDialogParameters parameters)
  252. {
  253. parameters.TryGetValue<ViewContentViewModel>(ParameterNames.ViewContentViewModel, out viewContentViewModel);
  254. parameters.TryGetValue<String>(ParameterNames.Open, out open);
  255. if (open == "AI")
  256. {
  257. LeftBtnVis = Visibility.Collapsed;
  258. RightBtnWidth = 280;
  259. }
  260. if (open == "Auto")
  261. {
  262. BtnTextSavewithWatermark = App.ServiceLoader.GetString("BtnTextContinue");
  263. }
  264. else
  265. {
  266. BtnTextSavewithWatermark = App.ServiceLoader.GetString("BtnTextSavewithWatermark");
  267. }
  268. }
  269. }
  270. }