ConverterPPTDialogViewModel.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. using ComPDFKitViewer.PdfViewer;
  2. using PDF_Office.CustomControl;
  3. using PDF_Office.Helper;
  4. using PDF_Office.Model;
  5. using PDF_Office.Model.Dialog.ConverterDialogs;
  6. using Prism.Commands;
  7. using Prism.Mvvm;
  8. using Prism.Services.Dialogs;
  9. using System;
  10. using System.Collections.Generic;
  11. using System.Diagnostics;
  12. using System.IO;
  13. using System.Linq;
  14. using System.Windows.Forms;
  15. using DialogResult = Prism.Services.Dialogs.DialogResult;
  16. namespace PDF_Office.ViewModels.Dialog.ConverterDialogs
  17. {
  18. public class ConverterPPTDialogViewModel : BindableBase, IDialogAware
  19. {
  20. public string Title => "";
  21. public event Action<IDialogResult> RequestClose;
  22. #region 参数和属性
  23. public ConverterPPTDialogModel ConverterPPTModel = new ConverterPPTDialogModel();
  24. public CPDFViewer currentViewer;
  25. public IDialogService dialogs;
  26. public string CurrentPageIndex = "1";
  27. public string PageRangeText { set; get; } = "0";
  28. public string PageRangeSelectIndex { set; get; } = "0";
  29. #endregion
  30. #region 委托声明
  31. public DelegateCommand CancelCommand { get; set; }
  32. public DelegateCommand ConverterCommnad { get; set; }
  33. #endregion
  34. public ConverterPPTDialogViewModel(IDialogService dialogService)
  35. {
  36. CancelCommand = new DelegateCommand(cancel);
  37. ConverterCommnad = new DelegateCommand(converter);
  38. dialogs = dialogService;
  39. }
  40. #region 逻辑函数
  41. private void cancel()
  42. {
  43. RequestClose.Invoke(new DialogResult(ButtonResult.Cancel));
  44. }
  45. private void converter()
  46. {
  47. FolderBrowserDialog dlg = new FolderBrowserDialog();
  48. if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  49. {
  50. ConverterPPTModel.OutputPath = dlg.SelectedPath.Trim();
  51. }
  52. HomePageEditHelper.GetPagerange(PageRangeSelectIndex, currentViewer, ref ConverterPPTModel.PageRange, PageRangeText, true, CurrentPageIndex);
  53. char[] enumerationSeparator = new char[] { ',' };
  54. char[] rangeSeparator = new char[] { '-' };
  55. if (!CommonHelper.GetPagesInRange(ref ConverterPPTModel.PageIndexLists, ConverterPPTModel.PageRange, currentViewer.Document.PageCount, enumerationSeparator, rangeSeparator))
  56. { //TODO
  57. Trace.WriteLine("输入不对");
  58. MessageBoxEx.Show("输入不对");
  59. return;
  60. }
  61. DialogParameters value = new DialogParameters();
  62. value.Add(ParameterNames.ConverterType, "PPT");
  63. value.Add(ParameterNames.ConverterTypeModel, ConverterPPTModel);
  64. RequestClose?.Invoke(new DialogResult(ButtonResult.OK));
  65. dialogs.ShowDialog(DialogNames.ConverterProgressBarDialog, value, e =>
  66. {
  67. });
  68. }
  69. #endregion
  70. #region 构架行为
  71. public bool CanCloseDialog()
  72. {
  73. return true;
  74. }
  75. public void OnDialogClosed()
  76. {
  77. }
  78. public void OnDialogOpened(IDialogParameters parameters)
  79. {
  80. CPDFViewer pdfViewer = null;
  81. parameters.TryGetValue<CPDFViewer>(ParameterNames.PDFViewer, out pdfViewer);
  82. if (pdfViewer != null)
  83. {
  84. currentViewer = pdfViewer;
  85. ConverterPPTModel.InputPath = pdfViewer.Document.FilePath;
  86. FileInfo fileinfo = new FileInfo(ConverterPPTModel.InputPath);
  87. ConverterPPTModel.OutputPath = fileinfo.DirectoryName;
  88. }
  89. }
  90. #endregion
  91. }
  92. }