ConverterBarContentViewModel.cs 15 KB

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