HomeGuidContentViewModel.cs 6.0 KB

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