ConverterBarContentViewModel.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. using ComPDFKit_Conversion.Converter;
  2. using ComPDFKitViewer.PdfViewer;
  3. using Microsoft.Office.Interop.Word;
  4. using PDF_Master.Helper;
  5. using PDF_Master.Model;
  6. using PDF_Master.Model.Dialog.ConverterDialogs;
  7. using PDF_Master.Properties;
  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.Linq;
  15. using System.Windows;
  16. using System.Windows.Controls;
  17. namespace PDF_Master.ViewModels.Tools
  18. {
  19. public class ConverterBarContentViewModel : BindableBase, INavigationAware
  20. {
  21. private bool isFirstLoad = true;
  22. private CPDFViewer PDFViewer;
  23. public IDialogService dialogs;
  24. private ViewContentViewModel viewContentViewModel;
  25. private string _pageIndex = "0";
  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. public DelegateCommand<object> ToConverterCommand { get; set; }
  52. public ConverterBarContentViewModel(IDialogService dialogService)
  53. {
  54. dialogs = dialogService;
  55. ToConverterCommand = new DelegateCommand<object>(toconverter);
  56. }
  57. private async void toconverter(object sender)
  58. {
  59. if (!viewContentViewModel.IAPBeforeFunction())
  60. {
  61. return;
  62. }
  63. //转档前 如果需要 自动保存
  64. if(!await viewContentViewModel.SaveBeforeOption())
  65. {
  66. return;
  67. }
  68. var args = sender as Button;
  69. if (args != null)
  70. {
  71. DialogParameters value = new DialogParameters();
  72. value.Add(ParameterNames.PDFViewer, PDFViewer);
  73. switch (args.Name)
  74. {
  75. case "ConverterWordBtn":
  76. dialogs.ShowDialog(DialogNames.ConverterWordDialog, value, e =>
  77. {
  78. ConverterDialogsModel converterDialogsModel = new ConverterDialogsModel();
  79. converterDialogsModel. OnOpened((DialogResult)e);
  80. });
  81. break;
  82. case "ConverterExcelBtn":
  83. dialogs.ShowDialog(DialogNames.ConverterExcelDialog, value, e => {
  84. ConverterDialogsModel converterDialogsModel = new ConverterDialogsModel();
  85. converterDialogsModel.OnOpened((DialogResult)e);
  86. });
  87. break;
  88. case "ConverterPPTBtn":
  89. dialogs.ShowDialog(DialogNames.ConverterPPTDialog, value, e => {
  90. ConverterDialogsModel converterDialogsModel = new ConverterDialogsModel();
  91. converterDialogsModel.OnOpened((DialogResult)e);
  92. });
  93. break;
  94. case "ConverterRTFBtn":
  95. dialogs.ShowDialog(DialogNames.ConverterRTFDialog, value, e => {
  96. ConverterDialogsModel converterDialogsModel = new ConverterDialogsModel();
  97. converterDialogsModel.OnOpened((DialogResult)e);
  98. });
  99. break;
  100. case "ConverterCSVBtn":
  101. dialogs.ShowDialog(DialogNames.ConverterCSVDialog, value, e => {
  102. ConverterDialogsModel converterDialogsModel = new ConverterDialogsModel();
  103. converterDialogsModel.OnOpened((DialogResult)e);
  104. });
  105. break;
  106. case "ConverterHTMLBtn":
  107. dialogs.ShowDialog(DialogNames.ConverterHTMLDialog, value, e => {
  108. ConverterDialogsModel converterDialogsModel = new ConverterDialogsModel();
  109. converterDialogsModel.OnOpened((DialogResult)e);
  110. });
  111. break;
  112. case "ConverterTextBtn":
  113. dialogs.ShowDialog(DialogNames.ConverterTextDialog, value, e => {
  114. ConverterDialogsModel converterDialogsModel = new ConverterDialogsModel();
  115. converterDialogsModel.OnOpened((DialogResult)e);
  116. });
  117. break;
  118. case "ConverterImgBtn":
  119. dialogs.ShowDialog(DialogNames.ConverterImgDialog, value, e => {
  120. ConverterDialogsModel converterDialogsModel = new ConverterDialogsModel();
  121. converterDialogsModel.OnOpened((DialogResult)e);
  122. });
  123. break;
  124. default:
  125. break;
  126. }
  127. }
  128. }
  129. //private void ConverterClear() {
  130. // ConverterHelper.Clear();
  131. // App.mainWindowViewModel.IsProcessVisible = System.Windows.Visibility.Collapsed;
  132. //}
  133. //private void SetProgress(int pageIndex)
  134. //{
  135. // PageIndex = pageIndex.ToString();
  136. // App.mainWindowViewModel.IsProcessVisible=System.Windows.Visibility.Visible;
  137. // if (PageIndex == PageNumber) { App.mainWindowViewModel.IsProcessVisible = System.Windows.Visibility.Collapsed; }
  138. //}
  139. //public async void OnOpened(Prism.Services.Dialogs.DialogResult e)
  140. //{
  141. // if (e.Result == Prism.Services.Dialogs.ButtonResult.Cancel) { return; }
  142. // bool result = false;
  143. // string convertType = "";
  144. // OnProgress GetProgress = null;
  145. // GetProgress += SetProgress;
  146. // App.mainWindowViewModel.ProcessCloseAction= ConverterClear;
  147. // convertType = e.Parameters.GetValue<string>(ParameterNames.ConverterType).ToString();
  148. // switch (convertType)
  149. // {
  150. // case "CSV":
  151. // ConverterCSVDialogModel ConverterCSVModel=e.Parameters.GetValue<ConverterCSVDialogModel>(ParameterNames.ConverterTypeModel);
  152. // if (ConverterCSVModel != null)
  153. // {
  154. // PageNumber = ConverterCSVModel.PageIndexLists.Count().ToString();
  155. // for (int i = 0; ConverterCSVModel.PageIndexLists.Count > i; i++)
  156. // {
  157. // ConverterCSVModel.PageIndexLists[i] = ConverterCSVModel.PageIndexLists[i] + 1;
  158. // }
  159. // result = await ConverterHelper.CSVConvert(ConverterCSVModel.InputPath, ConverterCSVModel.OutputPath, GetProgress, ConverterCSVModel.PageIndexLists, ConverterCSVModel.Pawssword, ConverterCSVModel.csvOptions);
  160. // }
  161. // break;
  162. // case "Excel":
  163. // ConverterExcelDialogModel ConverterExcelModel = e.Parameters.GetValue<ConverterExcelDialogModel>(ParameterNames.ConverterTypeModel);
  164. // if (ConverterExcelModel != null)
  165. // {
  166. // PageNumber = ConverterExcelModel.PageIndexLists.Count().ToString();
  167. // for (int i = 0; ConverterExcelModel.PageIndexLists.Count > i; i++)
  168. // {
  169. // ConverterExcelModel.PageIndexLists[i] = ConverterExcelModel.PageIndexLists[i] + 1;
  170. // }
  171. // result = await ConverterHelper.ExcelConvert(ConverterExcelModel.InputPath, ConverterExcelModel.OutputPath, GetProgress, ConverterExcelModel.PageIndexLists, ConverterExcelModel.Pawssword, ConverterExcelModel.excelOptions);
  172. // }
  173. // break;
  174. // case "HTML":
  175. // ConverterHTMLDialogModel ConverterHTMLModel = e.Parameters.GetValue<ConverterHTMLDialogModel>(ParameterNames.ConverterTypeModel);
  176. // if (ConverterHTMLModel != null)
  177. // {
  178. // PageNumber = ConverterHTMLModel.PageIndexLists.Count().ToString();
  179. // for (int i = 0; ConverterHTMLModel.PageIndexLists.Count > i; i++)
  180. // {
  181. // ConverterHTMLModel.PageIndexLists[i] = ConverterHTMLModel.PageIndexLists[i] + 1;
  182. // }
  183. // result = await ConverterHelper.HTMLConvert(ConverterHTMLModel.InputPath, ConverterHTMLModel.OutputPath, GetProgress, ConverterHTMLModel.PageIndexLists, ConverterHTMLModel.Pawssword, ConverterHTMLModel.htmlOptions);
  184. // }
  185. // break;
  186. // case "Img":
  187. // ConverterImgDialogModel ConverterImgModel = e.Parameters.GetValue<ConverterImgDialogModel>(ParameterNames.ConverterTypeModel);
  188. // if (ConverterImgModel != null)
  189. // {
  190. // PageNumber = ConverterImgModel.PageIndexLists.Count().ToString();
  191. // for (int i = 0; ConverterImgModel.PageIndexLists.Count > i; i++)
  192. // {
  193. // ConverterImgModel.PageIndexLists[i] = ConverterImgModel.PageIndexLists[i] + 1;
  194. // }
  195. // result = await ConverterHelper.ImgConvert(ConverterImgModel.InputPath, ConverterImgModel.OutputPath, GetProgress, ConverterImgModel.PageIndexLists, ConverterImgModel.Pawssword, ConverterImgModel.imageType, ConverterImgModel.imgOptions);
  196. // }
  197. // break;
  198. // case "PPT":
  199. // ConverterPPTDialogModel ConverterPPTModel = e.Parameters.GetValue<ConverterPPTDialogModel>(ParameterNames.ConverterTypeModel);
  200. // if (ConverterPPTModel != null)
  201. // {
  202. // PageNumber = ConverterPPTModel.PageIndexLists.Count().ToString();
  203. // for (int i = 0; ConverterPPTModel.PageIndexLists.Count > i; i++)
  204. // {
  205. // ConverterPPTModel.PageIndexLists[i] = ConverterPPTModel.PageIndexLists[i] + 1;
  206. // }
  207. // result = await ConverterHelper.PPTConvert(ConverterPPTModel.InputPath, ConverterPPTModel.OutputPath, GetProgress, ConverterPPTModel.PageIndexLists, ConverterPPTModel.Pawssword, ConverterPPTModel.pPTOptions);
  208. // }
  209. // break;
  210. // case "RTF":
  211. // ConverterRTFDialogModel ConverterRTFModel = e.Parameters.GetValue<ConverterRTFDialogModel>(ParameterNames.ConverterTypeModel);
  212. // if (ConverterRTFModel != null)
  213. // {
  214. // PageNumber = ConverterRTFModel.PageIndexLists.Count().ToString();
  215. // for (int i = 0; ConverterRTFModel.PageIndexLists.Count > i; i++)
  216. // {
  217. // ConverterRTFModel.PageIndexLists[i] = ConverterRTFModel.PageIndexLists[i] + 1;
  218. // }
  219. // result = await ConverterHelper.RTFConvert(ConverterRTFModel.InputPath, ConverterRTFModel.OutputPath, GetProgress, ConverterRTFModel.PageIndexLists, ConverterRTFModel.Pawssword, ConverterRTFModel.rTFOptions);
  220. // }
  221. // break;
  222. // case "Text":
  223. // ConverterTextDialogModel ConverterTextModel = e.Parameters.GetValue<ConverterTextDialogModel>(ParameterNames.ConverterTypeModel);
  224. // if (ConverterTextModel != null)
  225. // {
  226. // PageNumber = ConverterTextModel.PageIndexLists.Count().ToString();
  227. // for (int i = 0; ConverterTextModel.PageIndexLists.Count > i; i++)
  228. // {
  229. // ConverterTextModel.PageIndexLists[i] = ConverterTextModel.PageIndexLists[i] + 1;
  230. // }
  231. // result = await ConverterHelper.TxtConvert(ConverterTextModel.InputPath, ConverterTextModel.OutputPath, GetProgress, ConverterTextModel.PageIndexLists, ConverterTextModel.Pawssword, ConverterTextModel.txtOptions);
  232. // }
  233. // break;
  234. // case "Word":
  235. // ConverterWordDialogModel ConverterWordModel = e.Parameters.GetValue<ConverterWordDialogModel>(ParameterNames.ConverterTypeModel);
  236. // if (ConverterWordModel != null)
  237. // {
  238. // PageNumber = ConverterWordModel.PageIndexLists.Count().ToString();
  239. // for (int i = 0; ConverterWordModel.PageIndexLists.Count > i; i++)
  240. // {
  241. // ConverterWordModel.PageIndexLists[i] = ConverterWordModel.PageIndexLists[i] + 1;
  242. // }
  243. // result = await ConverterHelper.WordConvert(ConverterWordModel.InputPath, ConverterWordModel.OutputPath, GetProgress, ConverterWordModel.PageIndexLists, ConverterWordModel.Pawssword, ConverterWordModel.wordOptions);
  244. // }
  245. // break;
  246. // default:
  247. // break;
  248. // }
  249. //}
  250. public bool IsNavigationTarget(NavigationContext navigationContext)
  251. {
  252. return true;
  253. }
  254. public void OnNavigatedFrom(NavigationContext navigationContext)
  255. {
  256. }
  257. public void OnNavigatedTo(NavigationContext navigationContext)
  258. {
  259. navigationContext.Parameters.TryGetValue<ViewContentViewModel>(ParameterNames.ViewContentViewModel, out viewContentViewModel);
  260. navigationContext.Parameters.TryGetValue<CPDFViewer>(ParameterNames.PDFViewer, out PDFViewer);
  261. if (PDFViewer != null)
  262. {
  263. isFirstLoad = false;
  264. viewContentViewModel.IsPropertyOpen = false;
  265. PDFViewer.SetMouseMode(MouseModes.PanTool);
  266. }
  267. }
  268. }
  269. }