HomeFilesContentViewModel.cs 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. using Microsoft.Office.Interop.Word;
  2. using Microsoft.Win32;
  3. using PDF_Master.Helper;
  4. using PDF_Master.Model;
  5. using PDFReader_WPF.Helper;
  6. using Prism.Commands;
  7. using Prism.Mvvm;
  8. using Prism.Regions;
  9. using System;
  10. using System.Collections.Generic;
  11. using System.Linq;
  12. namespace PDF_Master.ViewModels.HomePanel.PDFTools
  13. {
  14. public class HomeFilesContentViewModel : BindableBase, INavigationAware
  15. {
  16. #region 文案
  17. private string T_openPDFTitle;
  18. public string T_OpenPDFTitle
  19. {
  20. get { return T_openPDFTitle; }
  21. set
  22. {
  23. SetProperty(ref T_openPDFTitle, value);
  24. }
  25. }
  26. private string T_openPDFBtn;
  27. public string T_OpenPDFBtn
  28. {
  29. get { return T_openPDFBtn; }
  30. set
  31. {
  32. SetProperty(ref T_openPDFBtn, value);
  33. }
  34. }
  35. private string T_openPDFDropTip;
  36. public string T_OpenPDFDropTip
  37. {
  38. get { return T_openPDFDropTip; }
  39. set
  40. {
  41. SetProperty(ref T_openPDFDropTip, value);
  42. }
  43. }
  44. private string T_createPDFTitle;
  45. public string T_CreatePDFTitle
  46. {
  47. get { return T_createPDFTitle; }
  48. set
  49. {
  50. SetProperty(ref T_createPDFTitle, value);
  51. }
  52. }
  53. private string T_createPDFNewFromFilesBtn;
  54. public string T_CreatePDFNewFromFilesBtn
  55. {
  56. get { return T_createPDFNewFromFilesBtn; }
  57. set
  58. {
  59. SetProperty(ref T_createPDFNewFromFilesBtn, value);
  60. }
  61. }
  62. private string T_createPDFNewBlankPageBtn;
  63. public string T_CreatePDFNewBlankPageBtn
  64. {
  65. get { return T_createPDFNewBlankPageBtn; }
  66. set
  67. {
  68. SetProperty(ref T_createPDFNewBlankPageBtn, value);
  69. }
  70. }
  71. private string T_createPDFFromScannerBtn;
  72. public string T_CreatePDFFromScannerBtn
  73. {
  74. get { return T_createPDFFromScannerBtn; }
  75. set
  76. {
  77. SetProperty(ref T_createPDFFromScannerBtn, value);
  78. }
  79. }
  80. private void InitString()
  81. {
  82. T_OpenPDFTitle = App.HomePageLoader.GetString("HomeBtn_OpenPDFTitle");
  83. T_OpenPDFBtn = App.HomePageLoader.GetString("HomeBtn_OpenPDFBtn");
  84. T_OpenPDFDropTip = App.HomePageLoader.GetString("HomeBtn_OpenPDFDropTip");
  85. T_CreatePDFTitle = App.HomePageLoader.GetString("HomeBtn_CreatePDFTitle");
  86. T_CreatePDFNewFromFilesBtn = App.HomePageLoader.GetString("HomeBtn_CreatePDFNewFromFilesBtn");
  87. T_CreatePDFNewBlankPageBtn = App.HomePageLoader.GetString("HomeBtn_CreatePDFNewBlankPageBtn");
  88. T_CreatePDFFromScannerBtn = App.HomePageLoader.GetString("HomeBtn_CreatePDFFromScannerBtn");
  89. }
  90. #endregion
  91. #region 属性和参数
  92. HomeContentViewModel homeContentViewModel = null;
  93. private int creatGridRowIndex = 0;
  94. public int CreatGridRowIndex
  95. {
  96. get { return creatGridRowIndex; }
  97. set
  98. {
  99. SetProperty(ref creatGridRowIndex, value);
  100. }
  101. }
  102. private int creatGridColumnIndex = 1;
  103. public int CreatGridColumnIndex
  104. {
  105. get { return creatGridColumnIndex; }
  106. set
  107. {
  108. SetProperty(ref creatGridColumnIndex, value);
  109. }
  110. }
  111. #endregion
  112. #region 委托声明
  113. public DelegateCommand OpenFileCommand { get; set; }
  114. public DelegateCommand CreateBlackPDFCommand { get; set; }
  115. public DelegateCommand CreateFromOtherFile { get; set; }
  116. public DelegateCommand<string> CreateFromScanner { get; set; }
  117. #endregion
  118. public HomeFilesContentViewModel()
  119. {
  120. OpenFileCommand = new DelegateCommand(OpenFile);
  121. CreateBlackPDFCommand = new DelegateCommand(CreatBlankPDF);
  122. CreateFromOtherFile = new DelegateCommand(createFromOtherFile);
  123. CreateFromScanner = new DelegateCommand<string>(createFromScanner);
  124. InitString();
  125. }
  126. #region 函数逻辑
  127. /// <summary>
  128. /// 从扫描仪创建
  129. /// </summary>
  130. private void createFromScanner(string args)
  131. {
  132. if (homeContentViewModel != null)
  133. {
  134. DataTrackingHelper.SendEvent(DataTrackingHelper.EventType.Home, "Create_Btn", "Import From Scanner");
  135. homeContentViewModel.createFromScanner("");
  136. }
  137. }
  138. /// <summary>
  139. /// 打开文件
  140. /// </summary>
  141. public void OpenFile()
  142. {
  143. if (homeContentViewModel != null)
  144. {
  145. homeContentViewModel.OpenFile();
  146. }
  147. }
  148. /// <summary>
  149. /// 创建空白文档
  150. /// </summary>
  151. public void CreatBlankPDF()
  152. {
  153. if (homeContentViewModel != null)
  154. {
  155. DataTrackingHelper.SendEvent(DataTrackingHelper.EventType.Home, "Create_Btn", "New Blank Page");
  156. homeContentViewModel.CreatBlankPDF();
  157. }
  158. }
  159. /// <summary>
  160. /// 从其他格式文件创建PDF
  161. /// </summary>
  162. private void createFromOtherFile()
  163. {
  164. if (homeContentViewModel != null)
  165. {
  166. DataTrackingHelper.SendEvent(DataTrackingHelper.EventType.Home, "Create_Btn", "New From File");
  167. homeContentViewModel.createFromOtherFile();
  168. }
  169. }
  170. #endregion
  171. #region 框架行为
  172. public void OnNavigatedTo(NavigationContext navigationContext)
  173. {
  174. navigationContext.Parameters.TryGetValue<HomeContentViewModel>(ParameterNames.HomeContentViewModel, out homeContentViewModel);
  175. }
  176. public bool IsNavigationTarget(NavigationContext navigationContext)
  177. {
  178. return true;
  179. }
  180. public void OnNavigatedFrom(NavigationContext navigationContext)
  181. {
  182. }
  183. #endregion
  184. }
  185. }