HomeGuidContentViewModel.cs 5.3 KB

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