HomeGuidContentViewModel.cs 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. using ComPDFKit.PDFDocument;
  2. using ComPDFKitViewer.PdfViewer;
  3. using PDF_Office.CustomControl;
  4. using PDF_Office.Helper;
  5. using PDF_Office.Model;
  6. using PDF_Office.Model.Dialog.HomePageToolsDialogs.HomePageBatchProcessing;
  7. using PDF_Office.Model.PDFTool;
  8. using PDF_Office.Views.HomePanel.PDFTools;
  9. using PDFSettings;
  10. using Prism.Commands;
  11. using Prism.Mvvm;
  12. using Prism.Services.Dialogs;
  13. using System;
  14. using System.Collections.Generic;
  15. using System.Linq;
  16. using System.Text;
  17. using System.Threading.Tasks;
  18. using System.Windows.Forms;
  19. using System.Xml.Linq;
  20. namespace PDF_Office.ViewModels.HomePanel
  21. {
  22. public class HomeGuidContentViewModel : BindableBase
  23. {
  24. public IDialogService dialogs;
  25. public DelegateCommand<ToolItem> QuickToolsCommand { get; set; }
  26. public HomeGuidContentViewModel(IDialogService dialogService)
  27. {
  28. QuickToolsCommand = new DelegateCommand<ToolItem>(QuickTools_Click);
  29. dialogs = dialogService;
  30. }
  31. public void QuickTools_Click(ToolItem toolItem)
  32. {
  33. /*
  34. *设置这个对话框的起始保存路径
  35. */
  36. System.Windows.Forms.OpenFileDialog dlg = new System.Windows.Forms.OpenFileDialog();
  37. dlg.Multiselect = false;
  38. dlg.Filter = "PDF|*.pdf;*.PDF;";
  39. if (toolItem.FnType == (int)PDFFnType.Compress || toolItem.FnType == (int)PDFFnType.Security)
  40. {
  41. dlg.Multiselect = true;
  42. }
  43. if (toolItem.FnType == (int)PDFFnType.Merge)
  44. {
  45. dlg.Multiselect = true;
  46. dlg.Filter = "Picture|*.png;*.PNG;*.jpg;*.JPG;*bmp;*jpeg;*gif;*tiff;";
  47. }
  48. if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  49. {
  50. CPDFViewer viewer = new CPDFViewer();
  51. switch ((PDFFnType)toolItem.FnType)
  52. {
  53. case PDFFnType.Split:
  54. viewer.InitDocument(dlg.FileName);
  55. DialogParameters splitvalue = new DialogParameters();
  56. splitvalue.Add(ParameterNames.PDFViewer, viewer);
  57. splitvalue.Add(ParameterNames.FilePath, dlg.FileName);
  58. dialogs.ShowDialog(DialogNames.HomePageSplitDialog, splitvalue, e => { });
  59. break;
  60. case PDFFnType.Extract:
  61. viewer.InitDocument(dlg.FileName);
  62. DialogParameters extractvalue = new DialogParameters();
  63. extractvalue.Add(ParameterNames.PDFViewer, viewer);
  64. extractvalue.Add(ParameterNames.FilePath, dlg.FileName);
  65. dialogs.ShowDialog(DialogNames.HomePageExtractDialog, extractvalue, e => { });
  66. break;
  67. case PDFFnType.Insert:
  68. viewer.InitDocument(dlg.FileName);
  69. DialogParameters insertvalue = new DialogParameters();
  70. insertvalue.Add(ParameterNames.PDFViewer, viewer);
  71. insertvalue.Add(ParameterNames.FilePath, dlg.FileName);
  72. dialogs.ShowDialog(DialogNames.HomePageInsertDialog, insertvalue, e => { });
  73. break;
  74. case PDFFnType.Compress:
  75. DialogParameters compresspdf = new DialogParameters();
  76. compresspdf.Add(ParameterNames.BatchProcessing_Name, "1");
  77. HomePageBatchProcessingDialogModel.FilePaths = dlg.FileNames.ToList();
  78. HomePageBatchProcessingDialogModel.BatchProcessingIndex = 1;
  79. compresspdf.Add(ParameterNames.FilePath, dlg.FileNames);
  80. dialogs.ShowDialog(DialogNames.HomePageBatchProcessingDialog, compresspdf, e => { });
  81. break;
  82. case PDFFnType.Merge:
  83. DialogParameters picturetopdf = new DialogParameters();
  84. picturetopdf.Add(ParameterNames.FilePath, dlg.FileNames);
  85. dialogs.ShowDialog(DialogNames.HomePagePictureToPDFDialog, picturetopdf, e => { });
  86. break;
  87. case PDFFnType.Print:
  88. viewer.InitDocument(dlg.FileName);
  89. DialogParameters printvalue = new DialogParameters();
  90. printvalue.Add(ParameterNames.PDFViewer, viewer);
  91. printvalue.Add(ParameterNames.FilePath, dlg.FileName);
  92. dialogs.ShowDialog(DialogNames.HomePagePrinterDialog, printvalue, e => { });
  93. break;
  94. case PDFFnType.Security:
  95. DialogParameters securitypdf = new DialogParameters();
  96. securitypdf.Add(ParameterNames.BatchProcessing_Name, "2");
  97. HomePageBatchProcessingDialogModel.FilePaths = dlg.FileNames.ToList();
  98. HomePageBatchProcessingDialogModel.BatchProcessingIndex = 2;
  99. securitypdf.Add(ParameterNames.FilePath, dlg.FileNames);
  100. dialogs.ShowDialog(DialogNames.HomePageBatchProcessingDialog, securitypdf, e => { });
  101. break;
  102. case PDFFnType.ConvertPDF:
  103. DialogParameters convertpdf = new DialogParameters();
  104. convertpdf.Add(ParameterNames.BatchProcessing_Name, "0");
  105. HomePageBatchProcessingDialogModel.FilePaths = dlg.FileNames.ToList();
  106. HomePageBatchProcessingDialogModel.BatchProcessingIndex = 0;
  107. convertpdf.Add(ParameterNames.FilePath, dlg.FileNames);
  108. dialogs.ShowDialog(DialogNames.HomePageBatchProcessingDialog, convertpdf, e => { });
  109. break;
  110. }
  111. }
  112. }
  113. }
  114. }