ConverterProgressBarDialogViewModel.cs 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. using ComPDFKit.PDFDocument;
  2. using ComPDFKit_Conversion.Converter;
  3. using ComPDFKit_Conversion.Options;
  4. using PDF_Office.Helper;
  5. using PDF_Office.Model;
  6. using PDF_Office.Model.Dialog.ConverterDialogs;
  7. using Prism.Commands;
  8. using Prism.Mvvm;
  9. using Prism.Services.Dialogs;
  10. using System;
  11. using System.Collections.Generic;
  12. using System.Diagnostics;
  13. using System.Linq;
  14. using System.Net.Mime;
  15. using System.Windows.Media;
  16. using static Dropbox.Api.Sharing.ListFileMembersIndividualResult;
  17. namespace PDF_Office.ViewModels.Dialog.ConverterDialogs
  18. {
  19. public class ConverterProgressBarDialogViewModel : BindableBase,IDialogAware
  20. {
  21. public string Title => "";
  22. public event Action<IDialogResult> RequestClose;
  23. #region 参数和属性
  24. private string _pageIndex = "0";
  25. /// <value>
  26. /// 当前页
  27. /// </value>
  28. public string PageIndex
  29. {
  30. get { return _pageIndex; }
  31. set
  32. {
  33. SetProperty(ref _pageIndex, value);
  34. }
  35. }
  36. private string _pageNumber = "";
  37. /// <value>
  38. /// 总页数
  39. /// </value>
  40. public string PageNumber
  41. {
  42. get { return _pageNumber; }
  43. set
  44. {
  45. SetProperty(ref _pageNumber, value);
  46. }
  47. }
  48. #endregion
  49. public ConverterProgressBarDialogViewModel()
  50. {
  51. }
  52. #region 逻辑函数
  53. private void SetProgress(int pageIndex)
  54. {
  55. PageIndex=pageIndex.ToString();
  56. }
  57. #endregion
  58. #region 构架行为
  59. public bool CanCloseDialog()
  60. {
  61. return true;
  62. }
  63. public void OnDialogClosed()
  64. {
  65. ConverterHelper.Clear();
  66. }
  67. public async void OnDialogOpened(IDialogParameters parameters)
  68. {
  69. bool result=false;
  70. string convertType="";
  71. OnProgress GetProgress = null;
  72. GetProgress += SetProgress;
  73. parameters.TryGetValue<string>(ParameterNames.ConverterType, out convertType);
  74. switch (convertType)
  75. {
  76. case "CSV":
  77. ConverterCSVDialogModel ConverterCSVModel;
  78. parameters.TryGetValue<ConverterCSVDialogModel>(ParameterNames.ConverterTypeModel, out ConverterCSVModel);
  79. if (ConverterCSVModel != null)
  80. {
  81. PageNumber = ConverterCSVModel.PageIndexLists.Count().ToString();
  82. for (int i = 0; ConverterCSVModel.PageIndexLists.Count > i; i++)
  83. {
  84. ConverterCSVModel.PageIndexLists[i] = ConverterCSVModel.PageIndexLists[i] + 1;
  85. }
  86. result = await ConverterHelper.CSVConvert(ConverterCSVModel.InputPath, ConverterCSVModel.OutputPath, GetProgress, ConverterCSVModel.PageIndexLists, ConverterCSVModel.Pawssword);
  87. }
  88. break;
  89. case "Excel":
  90. ConverterExcelDialogModel ConverterExcelModel;
  91. parameters.TryGetValue<ConverterExcelDialogModel>(ParameterNames.ConverterTypeModel, out ConverterExcelModel);
  92. if (ConverterExcelModel != null)
  93. {
  94. PageNumber = ConverterExcelModel.PageIndexLists.Count().ToString();
  95. for (int i = 0; ConverterExcelModel.PageIndexLists.Count > i; i++)
  96. {
  97. ConverterExcelModel.PageIndexLists[i] = ConverterExcelModel.PageIndexLists[i] + 1;
  98. }
  99. result = await ConverterHelper.ExcelConvert(ConverterExcelModel.InputPath, ConverterExcelModel.OutputPath, GetProgress, ConverterExcelModel.PageIndexLists, ConverterExcelModel.Pawssword, ConverterExcelModel.excelOption);
  100. }
  101. break;
  102. case "HTML":
  103. ConverterHTMLDialogModel ConverterHTMLModel;
  104. parameters.TryGetValue<ConverterHTMLDialogModel>(ParameterNames.ConverterTypeModel, out ConverterHTMLModel);
  105. if (ConverterHTMLModel != null)
  106. {
  107. PageNumber = ConverterHTMLModel.PageIndexLists.Count().ToString();
  108. for (int i = 0; ConverterHTMLModel.PageIndexLists.Count > i; i++)
  109. {
  110. ConverterHTMLModel.PageIndexLists[i] = ConverterHTMLModel.PageIndexLists[i] + 1;
  111. }
  112. result = await ConverterHelper.HTMLConvert(ConverterHTMLModel.InputPath, ConverterHTMLModel.OutputPath, GetProgress, ConverterHTMLModel.PageIndexLists, ConverterHTMLModel.Pawssword, ConverterHTMLModel.htmlOption);
  113. }
  114. break;
  115. case "Img":
  116. ConverterImgDialogModel ConverterImgModel;
  117. parameters.TryGetValue<ConverterImgDialogModel>(ParameterNames.ConverterTypeModel, out ConverterImgModel);
  118. if (ConverterImgModel != null)
  119. {
  120. PageNumber = ConverterImgModel.PageIndexLists.Count().ToString();
  121. for (int i=0; ConverterImgModel.PageIndexLists.Count>i;i++) {
  122. ConverterImgModel.PageIndexLists[i] = ConverterImgModel.PageIndexLists[i] + 1;
  123. }
  124. result = await ConverterHelper.ImgConvert(ConverterImgModel.InputPath, ConverterImgModel.OutputPath, GetProgress, ConverterImgModel.PageIndexLists, ConverterImgModel.Pawssword, ConverterImgModel.Type,ConverterImgModel.imageType);
  125. }
  126. break;
  127. case "PPT":
  128. ConverterPPTDialogModel ConverterPPTModel;
  129. parameters.TryGetValue<ConverterPPTDialogModel>(ParameterNames.ConverterTypeModel, out ConverterPPTModel);
  130. if (ConverterPPTModel != null)
  131. {
  132. PageNumber = ConverterPPTModel.PageIndexLists.Count().ToString();
  133. for (int i = 0; ConverterPPTModel.PageIndexLists.Count > i; i++)
  134. {
  135. ConverterPPTModel.PageIndexLists[i] = ConverterPPTModel.PageIndexLists[i] + 1;
  136. }
  137. result = await ConverterHelper.PPTConvert(ConverterPPTModel.InputPath, ConverterPPTModel.OutputPath, GetProgress, ConverterPPTModel.PageIndexLists, ConverterPPTModel.Pawssword);
  138. }
  139. break;
  140. case "RTF":
  141. ConverterRTFDialogModel ConverterRTFModel;
  142. parameters.TryGetValue<ConverterRTFDialogModel>(ParameterNames.ConverterTypeModel, out ConverterRTFModel);
  143. if (ConverterRTFModel != null)
  144. {
  145. PageNumber = ConverterRTFModel.PageIndexLists.Count().ToString();
  146. for (int i = 0; ConverterRTFModel.PageIndexLists.Count > i; i++)
  147. {
  148. ConverterRTFModel.PageIndexLists[i] = ConverterRTFModel.PageIndexLists[i] + 1;
  149. }
  150. result = await ConverterHelper.RTFConvert(ConverterRTFModel.InputPath, ConverterRTFModel.OutputPath, GetProgress, ConverterRTFModel.PageIndexLists, ConverterRTFModel.Pawssword);
  151. }
  152. break;
  153. case "Text":
  154. ConverterTextDialogModel ConverterTextModel;
  155. parameters.TryGetValue<ConverterTextDialogModel>(ParameterNames.ConverterTypeModel, out ConverterTextModel);
  156. if (ConverterTextModel != null)
  157. {
  158. PageNumber = ConverterTextModel.PageIndexLists.Count().ToString();
  159. for (int i = 0; ConverterTextModel.PageIndexLists.Count > i; i++)
  160. {
  161. ConverterTextModel.PageIndexLists[i] = ConverterTextModel.PageIndexLists[i] + 1;
  162. }
  163. result = await ConverterHelper.TxtConvert(ConverterTextModel.InputPath, ConverterTextModel.OutputPath, GetProgress, ConverterTextModel.PageIndexLists, ConverterTextModel.Pawssword);
  164. }
  165. break;
  166. case "Word":
  167. ConverterWordDialogModel ConverterWordModel;
  168. parameters.TryGetValue<ConverterWordDialogModel>(ParameterNames.ConverterTypeModel, out ConverterWordModel);
  169. if (ConverterWordModel != null) {
  170. PageNumber = ConverterWordModel.PageIndexLists.Count().ToString();
  171. for (int i = 0; ConverterWordModel.PageIndexLists.Count > i; i++)
  172. {
  173. ConverterWordModel.PageIndexLists[i] = ConverterWordModel.PageIndexLists[i] + 1;
  174. }
  175. result = await ConverterHelper.WordConvert(ConverterWordModel.InputPath, ConverterWordModel.OutputPath, GetProgress, ConverterWordModel.PageIndexLists, ConverterWordModel.Pawssword);
  176. }
  177. break;
  178. default:
  179. break;
  180. }
  181. RequestClose?.Invoke(new DialogResult(ButtonResult.OK));
  182. }
  183. #endregion
  184. }
  185. }