ConverterBarContentViewModel.cs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  1. using ComPDFKit_Conversion.Converter;
  2. using ComPDFKitViewer.PdfViewer;
  3. using DryIoc;
  4. using Microsoft.Office.Interop.Word;
  5. using PDF_Master.Helper;
  6. using PDF_Master.Model;
  7. using PDF_Master.Model.Dialog.ConverterDialogs;
  8. using PDF_Master.Properties;
  9. using PDFReader_WPF.Helper;
  10. using Prism.Commands;
  11. using Prism.Mvvm;
  12. using Prism.Regions;
  13. using Prism.Services.Dialogs;
  14. using System;
  15. using System.Collections.Generic;
  16. using System.Linq;
  17. using System.Windows;
  18. using System.Windows.Controls;
  19. namespace PDF_Master.ViewModels.Tools
  20. {
  21. public class ConverterBarContentViewModel : BindableBase, INavigationAware
  22. {
  23. private CPDFViewer PDFViewer;
  24. public IDialogService dialogs;
  25. private ViewContentViewModel viewContentViewModel;
  26. ///// <value>
  27. ///// 当前页
  28. ///// </value>
  29. //public string PageIndex
  30. //{
  31. // get { return _pageIndex; }
  32. // set
  33. // {
  34. // SetProperty(ref _pageIndex, value);
  35. // App.mainWindowViewModel.Value = int.Parse(PageIndex);
  36. // }
  37. //}
  38. //private string _pageNumber = "0";
  39. ///// <value>
  40. ///// 总页数
  41. ///// </value>
  42. //public string PageNumber
  43. //{
  44. // get { return _pageNumber; }
  45. // set
  46. // {
  47. // SetProperty(ref _pageNumber, value);
  48. // App.mainWindowViewModel.MaxValue = int.Parse(PageNumber);
  49. // }
  50. //}
  51. /// <summary>
  52. /// 防止自动保存异步导致弹窗出现两次
  53. /// </summary>
  54. private bool _isPopupInProgress;
  55. public bool IsPopupInProgress
  56. {
  57. get { return _isPopupInProgress; }
  58. set { SetProperty(ref _isPopupInProgress, value); }
  59. }
  60. public DelegateCommand<object> ToConverterCommand { get; set; }
  61. public ConverterBarContentViewModel(IDialogService dialogService)
  62. {
  63. dialogs = dialogService;
  64. ToConverterCommand = new DelegateCommand<object>(toconverter);
  65. }
  66. private async void toconverter(object sender)
  67. {
  68. if (IsPopupInProgress)
  69. {
  70. return;
  71. }
  72. IsPopupInProgress = true;
  73. DataTrackingHelper.SetSendInformation(DataTrackingHelper.EventType.Purchase_Converter, DataTrackingHelper.EntryPathKeyType.SubTbr_Converter);
  74. var args = sender as Button;
  75. if (args != null)
  76. {
  77. toConverterDataTracking(args.Name);
  78. //转档前 如果需要 自动保存
  79. if (!await viewContentViewModel.SaveBeforeOption())
  80. {
  81. IsPopupInProgress = false;
  82. return;
  83. }
  84. IsPopupInProgress = false;
  85. DialogParameters value = new DialogParameters();
  86. value.Add(ParameterNames.PDFViewer, PDFViewer);
  87. switch (args.Name)
  88. {
  89. case "ConverterWordBtn":
  90. dialogs.ShowDialog(DialogNames.ConverterWordDialog, value, e =>
  91. {
  92. ConverterDialogsModel converterDialogsModel = new ConverterDialogsModel();
  93. converterDialogsModel.OnOpened((DialogResult)e);
  94. });
  95. break;
  96. case "ConverterExcelBtn":
  97. dialogs.ShowDialog(DialogNames.ConverterExcelDialog, value, e =>
  98. {
  99. ConverterDialogsModel converterDialogsModel = new ConverterDialogsModel();
  100. converterDialogsModel.OnOpened((DialogResult)e);
  101. });
  102. break;
  103. case "ConverterPPTBtn":
  104. dialogs.ShowDialog(DialogNames.ConverterPPTDialog, value, e =>
  105. {
  106. ConverterDialogsModel converterDialogsModel = new ConverterDialogsModel();
  107. converterDialogsModel.OnOpened((DialogResult)e);
  108. });
  109. break;
  110. case "ConverterRTFBtn":
  111. dialogs.ShowDialog(DialogNames.ConverterRTFDialog, value, e =>
  112. {
  113. ConverterDialogsModel converterDialogsModel = new ConverterDialogsModel();
  114. converterDialogsModel.OnOpened((DialogResult)e);
  115. });
  116. break;
  117. case "ConverterCSVBtn":
  118. dialogs.ShowDialog(DialogNames.ConverterCSVDialog, value, e =>
  119. {
  120. ConverterDialogsModel converterDialogsModel = new ConverterDialogsModel();
  121. converterDialogsModel.OnOpened((DialogResult)e);
  122. });
  123. break;
  124. case "ConverterHTMLBtn":
  125. dialogs.ShowDialog(DialogNames.ConverterHTMLDialog, value, e =>
  126. {
  127. ConverterDialogsModel converterDialogsModel = new ConverterDialogsModel();
  128. converterDialogsModel.OnOpened((DialogResult)e);
  129. });
  130. break;
  131. case "ConverterTextBtn":
  132. dialogs.ShowDialog(DialogNames.ConverterTextDialog, value, e =>
  133. {
  134. ConverterDialogsModel converterDialogsModel = new ConverterDialogsModel();
  135. converterDialogsModel.OnOpened((DialogResult)e);
  136. });
  137. break;
  138. case "ConverterImgBtn":
  139. dialogs.ShowDialog(DialogNames.ConverterImgDialog, value, e =>
  140. {
  141. ConverterDialogsModel converterDialogsModel = new ConverterDialogsModel();
  142. converterDialogsModel.OnOpened((DialogResult)e);
  143. });
  144. break;
  145. default:
  146. break;
  147. }
  148. }
  149. IsPopupInProgress = false;
  150. }
  151. /// <summary>
  152. /// 埋点
  153. /// </summary>
  154. /// <param name="sender"></param>
  155. private async void toConverterDataTracking(string sender)
  156. {
  157. switch (sender)
  158. {
  159. case "ConverterWordBtn":
  160. DataTrackingHelper.AddFirstAndSecondaryPath(DataTrackingHelper.FirstPath.Reading, DataTrackingHelper.SecondaryPath.toWord);
  161. DataTrackingHelper.SendEvent(DataTrackingHelper.EventType.SubTbr_Converter, "SubTbr_Btn", "Btn_SubTbr_toWord");
  162. break;
  163. case "ConverterExcelBtn":
  164. DataTrackingHelper.AddFirstAndSecondaryPath(DataTrackingHelper.FirstPath.Reading, DataTrackingHelper.SecondaryPath.toExcel);
  165. DataTrackingHelper.SendEvent(DataTrackingHelper.EventType.SubTbr_Converter, "SubTbr_Btn", "Btn_SubTbr_toExcel");
  166. break;
  167. case "ConverterPPTBtn":
  168. DataTrackingHelper.AddFirstAndSecondaryPath(DataTrackingHelper.FirstPath.Reading, DataTrackingHelper.SecondaryPath.toPPT);
  169. DataTrackingHelper.SendEvent(DataTrackingHelper.EventType.SubTbr_Converter, "SubTbr_Btn", "Btn_SubTbr_toPPT");
  170. break;
  171. case "ConverterRTFBtn":
  172. DataTrackingHelper.AddFirstAndSecondaryPath(DataTrackingHelper.FirstPath.Reading, DataTrackingHelper.SecondaryPath.toRTF);
  173. DataTrackingHelper.SendEvent(DataTrackingHelper.EventType.SubTbr_Converter, "SubTbr_Btn", "Btn_SubTbr_toRTF");
  174. break;
  175. case "ConverterCSVBtn":
  176. DataTrackingHelper.AddFirstAndSecondaryPath(DataTrackingHelper.FirstPath.Reading, DataTrackingHelper.SecondaryPath.toCSV);
  177. DataTrackingHelper.SendEvent(DataTrackingHelper.EventType.SubTbr_Converter, "SubTbr_Btn", "Btn_SubTbr_toCSV");
  178. break;
  179. case "ConverterHTMLBtn":
  180. DataTrackingHelper.AddFirstAndSecondaryPath(DataTrackingHelper.FirstPath.Reading, DataTrackingHelper.SecondaryPath.toHTML);
  181. DataTrackingHelper.SendEvent(DataTrackingHelper.EventType.SubTbr_Converter, "SubTbr_Btn", "Btn_SubTbr_toHTML");
  182. break;
  183. case "ConverterTextBtn":
  184. DataTrackingHelper.AddFirstAndSecondaryPath(DataTrackingHelper.FirstPath.Reading, DataTrackingHelper.SecondaryPath.toText);
  185. DataTrackingHelper.SendEvent(DataTrackingHelper.EventType.SubTbr_Converter, "SubTbr_Btn", "Btn_SubTbr_toText");
  186. break;
  187. case "ConverterImgBtn":
  188. DataTrackingHelper.AddFirstAndSecondaryPath(DataTrackingHelper.FirstPath.Reading, DataTrackingHelper.SecondaryPath.toImage);
  189. DataTrackingHelper.SendEvent(DataTrackingHelper.EventType.SubTbr_Converter, "SubTbr_Btn", "Btn_SubTbr_toImage");
  190. break;
  191. default:
  192. break;
  193. }
  194. }
  195. //private void ConverterClear() {
  196. // ConverterHelper.Clear();
  197. // App.mainWindowViewModel.IsProcessVisible = System.Windows.Visibility.Collapsed;
  198. //}
  199. //private void SetProgress(int pageIndex)
  200. //{
  201. // PageIndex = pageIndex.ToString();
  202. // App.mainWindowViewModel.IsProcessVisible=System.Windows.Visibility.Visible;
  203. // if (PageIndex == PageNumber) { App.mainWindowViewModel.IsProcessVisible = System.Windows.Visibility.Collapsed; }
  204. //}
  205. //public async void OnOpened(Prism.Services.Dialogs.DialogResult e)
  206. //{
  207. // if (e.Result == Prism.Services.Dialogs.ButtonResult.Cancel) { return; }
  208. // bool result = false;
  209. // string convertType = "";
  210. // OnProgress GetProgress = null;
  211. // GetProgress += SetProgress;
  212. // App.mainWindowViewModel.ProcessCloseAction= ConverterClear;
  213. // convertType = e.Parameters.GetValue<string>(ParameterNames.ConverterType).ToString();
  214. // switch (convertType)
  215. // {
  216. // case "CSV":
  217. // ConverterCSVDialogModel ConverterCSVModel=e.Parameters.GetValue<ConverterCSVDialogModel>(ParameterNames.ConverterTypeModel);
  218. // if (ConverterCSVModel != null)
  219. // {
  220. // PageNumber = ConverterCSVModel.PageIndexLists.Count().ToString();
  221. // for (int i = 0; ConverterCSVModel.PageIndexLists.Count > i; i++)
  222. // {
  223. // ConverterCSVModel.PageIndexLists[i] = ConverterCSVModel.PageIndexLists[i] + 1;
  224. // }
  225. // result = await ConverterHelper.CSVConvert(ConverterCSVModel.InputPath, ConverterCSVModel.OutputPath, GetProgress, ConverterCSVModel.PageIndexLists, ConverterCSVModel.Pawssword, ConverterCSVModel.csvOptions);
  226. // }
  227. // break;
  228. // case "Excel":
  229. // ConverterExcelDialogModel ConverterExcelModel = e.Parameters.GetValue<ConverterExcelDialogModel>(ParameterNames.ConverterTypeModel);
  230. // if (ConverterExcelModel != null)
  231. // {
  232. // PageNumber = ConverterExcelModel.PageIndexLists.Count().ToString();
  233. // for (int i = 0; ConverterExcelModel.PageIndexLists.Count > i; i++)
  234. // {
  235. // ConverterExcelModel.PageIndexLists[i] = ConverterExcelModel.PageIndexLists[i] + 1;
  236. // }
  237. // result = await ConverterHelper.ExcelConvert(ConverterExcelModel.InputPath, ConverterExcelModel.OutputPath, GetProgress, ConverterExcelModel.PageIndexLists, ConverterExcelModel.Pawssword, ConverterExcelModel.excelOptions);
  238. // }
  239. // break;
  240. // case "HTML":
  241. // ConverterHTMLDialogModel ConverterHTMLModel = e.Parameters.GetValue<ConverterHTMLDialogModel>(ParameterNames.ConverterTypeModel);
  242. // if (ConverterHTMLModel != null)
  243. // {
  244. // PageNumber = ConverterHTMLModel.PageIndexLists.Count().ToString();
  245. // for (int i = 0; ConverterHTMLModel.PageIndexLists.Count > i; i++)
  246. // {
  247. // ConverterHTMLModel.PageIndexLists[i] = ConverterHTMLModel.PageIndexLists[i] + 1;
  248. // }
  249. // result = await ConverterHelper.HTMLConvert(ConverterHTMLModel.InputPath, ConverterHTMLModel.OutputPath, GetProgress, ConverterHTMLModel.PageIndexLists, ConverterHTMLModel.Pawssword, ConverterHTMLModel.htmlOptions);
  250. // }
  251. // break;
  252. // case "Img":
  253. // ConverterImgDialogModel ConverterImgModel = e.Parameters.GetValue<ConverterImgDialogModel>(ParameterNames.ConverterTypeModel);
  254. // if (ConverterImgModel != null)
  255. // {
  256. // PageNumber = ConverterImgModel.PageIndexLists.Count().ToString();
  257. // for (int i = 0; ConverterImgModel.PageIndexLists.Count > i; i++)
  258. // {
  259. // ConverterImgModel.PageIndexLists[i] = ConverterImgModel.PageIndexLists[i] + 1;
  260. // }
  261. // result = await ConverterHelper.ImgConvert(ConverterImgModel.InputPath, ConverterImgModel.OutputPath, GetProgress, ConverterImgModel.PageIndexLists, ConverterImgModel.Pawssword, ConverterImgModel.imageType, ConverterImgModel.imgOptions);
  262. // }
  263. // break;
  264. // case "PPT":
  265. // ConverterPPTDialogModel ConverterPPTModel = e.Parameters.GetValue<ConverterPPTDialogModel>(ParameterNames.ConverterTypeModel);
  266. // if (ConverterPPTModel != null)
  267. // {
  268. // PageNumber = ConverterPPTModel.PageIndexLists.Count().ToString();
  269. // for (int i = 0; ConverterPPTModel.PageIndexLists.Count > i; i++)
  270. // {
  271. // ConverterPPTModel.PageIndexLists[i] = ConverterPPTModel.PageIndexLists[i] + 1;
  272. // }
  273. // result = await ConverterHelper.PPTConvert(ConverterPPTModel.InputPath, ConverterPPTModel.OutputPath, GetProgress, ConverterPPTModel.PageIndexLists, ConverterPPTModel.Pawssword, ConverterPPTModel.pPTOptions);
  274. // }
  275. // break;
  276. // case "RTF":
  277. // ConverterRTFDialogModel ConverterRTFModel = e.Parameters.GetValue<ConverterRTFDialogModel>(ParameterNames.ConverterTypeModel);
  278. // if (ConverterRTFModel != null)
  279. // {
  280. // PageNumber = ConverterRTFModel.PageIndexLists.Count().ToString();
  281. // for (int i = 0; ConverterRTFModel.PageIndexLists.Count > i; i++)
  282. // {
  283. // ConverterRTFModel.PageIndexLists[i] = ConverterRTFModel.PageIndexLists[i] + 1;
  284. // }
  285. // result = await ConverterHelper.RTFConvert(ConverterRTFModel.InputPath, ConverterRTFModel.OutputPath, GetProgress, ConverterRTFModel.PageIndexLists, ConverterRTFModel.Pawssword, ConverterRTFModel.rTFOptions);
  286. // }
  287. // break;
  288. // case "Text":
  289. // ConverterTextDialogModel ConverterTextModel = e.Parameters.GetValue<ConverterTextDialogModel>(ParameterNames.ConverterTypeModel);
  290. // if (ConverterTextModel != null)
  291. // {
  292. // PageNumber = ConverterTextModel.PageIndexLists.Count().ToString();
  293. // for (int i = 0; ConverterTextModel.PageIndexLists.Count > i; i++)
  294. // {
  295. // ConverterTextModel.PageIndexLists[i] = ConverterTextModel.PageIndexLists[i] + 1;
  296. // }
  297. // result = await ConverterHelper.TxtConvert(ConverterTextModel.InputPath, ConverterTextModel.OutputPath, GetProgress, ConverterTextModel.PageIndexLists, ConverterTextModel.Pawssword, ConverterTextModel.txtOptions);
  298. // }
  299. // break;
  300. // case "Word":
  301. // ConverterWordDialogModel ConverterWordModel = e.Parameters.GetValue<ConverterWordDialogModel>(ParameterNames.ConverterTypeModel);
  302. // if (ConverterWordModel != null)
  303. // {
  304. // PageNumber = ConverterWordModel.PageIndexLists.Count().ToString();
  305. // for (int i = 0; ConverterWordModel.PageIndexLists.Count > i; i++)
  306. // {
  307. // ConverterWordModel.PageIndexLists[i] = ConverterWordModel.PageIndexLists[i] + 1;
  308. // }
  309. // result = await ConverterHelper.WordConvert(ConverterWordModel.InputPath, ConverterWordModel.OutputPath, GetProgress, ConverterWordModel.PageIndexLists, ConverterWordModel.Pawssword, ConverterWordModel.wordOptions);
  310. // }
  311. // break;
  312. // default:
  313. // break;
  314. // }
  315. //}
  316. public bool IsNavigationTarget(NavigationContext navigationContext)
  317. {
  318. return true;
  319. }
  320. public void OnNavigatedFrom(NavigationContext navigationContext)
  321. {
  322. }
  323. public void OnNavigatedTo(NavigationContext navigationContext)
  324. {
  325. navigationContext.Parameters.TryGetValue<ViewContentViewModel>(ParameterNames.ViewContentViewModel, out viewContentViewModel);
  326. navigationContext.Parameters.TryGetValue<CPDFViewer>(ParameterNames.PDFViewer, out PDFViewer);
  327. if (PDFViewer != null)
  328. {
  329. viewContentViewModel.IsPropertyOpen = false;
  330. PDFViewer.SetMouseMode(MouseModes.PanTool);
  331. }
  332. }
  333. }
  334. }