ConverterCSVDialogViewModel.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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 CurrentPageIndex="1";
  30. public string PageRangeText { set; get; } = "0";
  31. public string PageRangeSelectIndex { set; get; } = "0";
  32. public DelegateCommand<string> RadioButtonCommand { get; set; }
  33. public DelegateCommand CancelCommand { get; set; }
  34. public DelegateCommand ConverterCommnad { get; set; }
  35. public ConverterCSVDialogViewModel(IDialogService dialogService)
  36. {
  37. CancelCommand = new DelegateCommand(cancel);
  38. ConverterCommnad = new DelegateCommand(converter);
  39. RadioButtonCommand = new DelegateCommand<string>(radiobutton);
  40. dialogs = dialogService;
  41. }
  42. private void cancel()
  43. {
  44. RequestClose.Invoke(new DialogResult(ButtonResult.Cancel));
  45. }
  46. private void converter()
  47. {
  48. FolderBrowserDialog dlg = new FolderBrowserDialog();
  49. if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  50. {
  51. ConverterCSVModel.OutputPath =dlg.SelectedPath.Trim();
  52. }
  53. HomePageEditHelper.GetPagerange(PageRangeSelectIndex, currentViewer, ref ConverterCSVModel.PageRange, PageRangeText, true, CurrentPageIndex);
  54. char[] enumerationSeparator = new char[] { ',' };
  55. char[] rangeSeparator = new char[] { '-' };
  56. if (!CommonHelper.GetPagesInRange(ref ConverterCSVModel.PageIndexLists, ConverterCSVModel.PageRange, currentViewer.Document.PageCount, enumerationSeparator, rangeSeparator))
  57. { //TODO
  58. Trace.WriteLine("输入不对");
  59. MessageBoxEx.Show("输入不对");
  60. return;
  61. }
  62. DialogParameters value = new DialogParameters();
  63. value.Add(ParameterNames.ConverterType,"CSV");
  64. value.Add(ParameterNames.ConverterTypeModel, ConverterCSVModel);
  65. RequestClose?.Invoke(new DialogResult(ButtonResult.OK));
  66. dialogs.ShowDialog(DialogNames.ConverterProgressBarDialog, value, e =>
  67. {
  68. });
  69. }
  70. private void radiobutton(string e)
  71. {
  72. string radioButton = e;
  73. if (radioButton != null)
  74. {
  75. switch (radioButton)
  76. {
  77. case "ForEachPageRadioBtn":
  78. break;
  79. case "OnlyTableRadioBtn":
  80. break;
  81. default:
  82. break;
  83. }
  84. }
  85. }
  86. private void SetProgress(int pageIndex)
  87. {
  88. }
  89. public string Title=>"";
  90. public event Action<IDialogResult> RequestClose;
  91. public bool CanCloseDialog()
  92. {
  93. return true;
  94. }
  95. public void OnDialogClosed()
  96. {
  97. }
  98. public void OnDialogOpened(IDialogParameters parameters)
  99. {
  100. CPDFViewer pdfViewer = null;
  101. parameters.TryGetValue<CPDFViewer>(ParameterNames.PDFViewer, out pdfViewer);
  102. if (pdfViewer != null)
  103. {
  104. currentViewer = pdfViewer;
  105. ConverterCSVModel.InputPath = pdfViewer.Document.FilePath;
  106. FileInfo fileinfo = new FileInfo(ConverterCSVModel.InputPath);
  107. ConverterCSVModel.OutputPath = fileinfo.DirectoryName;
  108. }
  109. }
  110. }
  111. }