ConverterCSVDialogViewModel.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. using ComPDFKit.PDFDocument;
  2. using ComPDFKit_Conversion.Options;
  3. using ComPDFKitViewer.PdfViewer;
  4. using Microsoft.Office.Interop.Excel;
  5. using Microsoft.Office.Interop.Word;
  6. using PDF_Office.CustomControl;
  7. using PDF_Office.Helper;
  8. using PDF_Office.Model;
  9. using PDF_Office.Model.Dialog.ConverterDialogs;
  10. using Prism.Commands;
  11. using Prism.Mvvm;
  12. using Prism.Services.Dialogs;
  13. using System;
  14. using System.Collections.Generic;
  15. using System.Diagnostics;
  16. using System.IO;
  17. using System.Linq;
  18. using System.Windows.Forms;
  19. using static Dropbox.Api.Files.FileCategory;
  20. using static System.Windows.Forms.VisualStyles.VisualStyleElement;
  21. using DialogResult = Prism.Services.Dialogs.DialogResult;
  22. namespace PDF_Office.ViewModels.Dialog.ConverterDialogs
  23. {
  24. public class ConverterCSVDialogViewModel : BindableBase,IDialogAware
  25. {
  26. public ConverterCSVDialogModel ConverterCSVModel = new ConverterCSVDialogModel();
  27. public CPDFViewer currentViewer;
  28. public IDialogService dialogs;
  29. public string PageRangeText { set; get; } = "0";
  30. public string PageRangeSelectIndex { set; get; } = "0";
  31. public DelegateCommand<string> RadioButtonCommand { get; set; }
  32. public DelegateCommand CancelCommand { get; set; }
  33. public DelegateCommand ConverterCommnad { get; set; }
  34. public ConverterCSVDialogViewModel(IDialogService dialogService)
  35. {
  36. CancelCommand = new DelegateCommand(cancel);
  37. ConverterCommnad = new DelegateCommand(converter);
  38. RadioButtonCommand = new DelegateCommand<string>(radiobutton);
  39. dialogs = dialogService;
  40. }
  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. ConverterCSVModel.OutputPath =dlg.SelectedPath.Trim();
  51. }
  52. HomePageEditHelper.GetPagerange(PageRangeSelectIndex, currentViewer, ref ConverterCSVModel.PageRange, PageRangeText, true);
  53. char[] enumerationSeparator = new char[] { ',' };
  54. char[] rangeSeparator = new char[] { '-' };
  55. if (!CommonHelper.GetPagesInRange(ref ConverterCSVModel.PageIndexLists, ConverterCSVModel.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,"CSV");
  63. value.Add(ParameterNames.ConverterTypeModel, ConverterCSVModel);
  64. RequestClose?.Invoke(new DialogResult(ButtonResult.OK));
  65. dialogs.ShowDialog(DialogNames.ConverterProgressBarDialog, value, e =>
  66. {
  67. });
  68. }
  69. private void radiobutton(string e)
  70. {
  71. string radioButton = e;
  72. if (radioButton != null)
  73. {
  74. switch (radioButton)
  75. {
  76. case "ForEachPageRadioBtn":
  77. break;
  78. case "OnlyTableRadioBtn":
  79. break;
  80. default:
  81. break;
  82. }
  83. }
  84. }
  85. private void SetProgress(int pageIndex)
  86. {
  87. }
  88. public string Title=>"";
  89. public event Action<IDialogResult> RequestClose;
  90. public bool CanCloseDialog()
  91. {
  92. return true;
  93. }
  94. public void OnDialogClosed()
  95. {
  96. }
  97. public void OnDialogOpened(IDialogParameters parameters)
  98. {
  99. CPDFViewer pdfViewer = null;
  100. parameters.TryGetValue<CPDFViewer>(ParameterNames.PDFViewer, out pdfViewer);
  101. if (pdfViewer != null)
  102. {
  103. currentViewer = pdfViewer;
  104. ConverterCSVModel.InputPath = pdfViewer.Document.FilePath;
  105. FileInfo fileinfo = new FileInfo(ConverterCSVModel.InputPath);
  106. ConverterCSVModel.OutputPath = fileinfo.DirectoryName;
  107. }
  108. }
  109. }
  110. }