HomePageBatchProcessingDialogViewModel.cs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. using ComPDFKitViewer.PdfViewer;
  2. using Microsoft.Office.Interop.Word;
  3. using PDF_Master.CustomControl;
  4. using PDF_Master.EventAggregators;
  5. using PDF_Master.Model;
  6. using PDF_Master.Model.Dialog.HomePageToolsDialogs.HomePageBatchProcessing;
  7. using Prism.Commands;
  8. using Prism.Mvvm;
  9. using Prism.Regions;
  10. using Prism.Services.Dialogs;
  11. using System;
  12. using System.Collections.Generic;
  13. using System.Drawing;
  14. using System.Linq;
  15. using System.Windows;
  16. using System.Windows.Controls;
  17. namespace PDF_Master.ViewModels.Dialog.HomePageToolsDialogs.HomePageBatchProcessing
  18. {
  19. public class HomePageBatchProcessingDialogViewModel : BindableBase, IDialogAware, INavigationAware
  20. {
  21. #region 参数和属性
  22. private List<string> fileNames;
  23. public IRegionManager BatchProcessingRegion;
  24. int convertertypeindex = 0;
  25. private string batchProcessingRegionName;
  26. public string BatchProcessingRegionName
  27. {
  28. get
  29. {
  30. return batchProcessingRegionName;
  31. }
  32. set
  33. {
  34. SetProperty(ref batchProcessingRegionName, value);
  35. }
  36. }
  37. private Visibility batchProcessingVisible = Visibility.Collapsed;
  38. public Visibility BatchProcessingVisible
  39. {
  40. get { return batchProcessingVisible; }
  41. set { SetProperty(ref batchProcessingVisible, value); }
  42. }
  43. #endregion
  44. #region 委托声明
  45. public DelegateCommand<string> DelegateChangeBatchProcessingCommand { get; set; }
  46. #endregion
  47. public HomePageBatchProcessingDialogViewModel(IRegionManager regionManager)
  48. {
  49. BatchProcessingRegion = regionManager;
  50. BatchProcessingRegionName = Guid.NewGuid().ToString();
  51. DelegateChangeBatchProcessingCommand= new DelegateCommand<string>(ChangeBatchProcessing);
  52. }
  53. #region 逻辑函数
  54. public void ChangeBatchProcessing(string index) {
  55. NavigationParameters param = new NavigationParameters();
  56. param.Add(ParameterNames.FilePath, HomePageBatchProcessingDialogModel.FilePaths);
  57. BatchProcessingVisible = Visibility.Collapsed;
  58. if (index =="0") {
  59. param.Add("ConverterTypeIndex", convertertypeindex);
  60. }
  61. BatchProcessingRegion.RequestNavigate(BatchProcessingRegionName, HomePageBatchProcessingDialogModel.GetBatchProcessing[int.Parse(index)], param);
  62. BatchProcessingVisible = Visibility.Visible;
  63. }
  64. #endregion
  65. public string Title => "PDF批量工具";
  66. public event Action<IDialogResult> RequestClose;
  67. #region 构架行为
  68. public bool CanCloseDialog()
  69. {
  70. AlertsMessage alertsMessage = new AlertsMessage();
  71. if (HomePageBatchProcessingDialogModel.closeDialog)
  72. {
  73. alertsMessage.ShowDialog("批量处理操作被中断,已完成的文件不受影响,是否确定要关闭弹窗", "", "取消", "确定");
  74. if (alertsMessage.result == ContentResult.Ok)
  75. {
  76. return true;
  77. }
  78. else
  79. {
  80. //this.eventAggregator.GetEvent<DeleteWatermarkEvent>().Publish(new EnumDeleteUnicode
  81. //{
  82. // Unicode = Unicode,
  83. // Status = EnumDelete.StatusCreate
  84. //});
  85. return false;
  86. }
  87. }
  88. return true;
  89. }
  90. public void OnDialogClosed()
  91. {
  92. RequestClose.Invoke(new DialogResult());
  93. }
  94. public void OnDialogOpened(IDialogParameters parameters)
  95. {
  96. string batchprocessingname = "";
  97. string[] filepath = null;
  98. int convertertypeindex=0;
  99. parameters.TryGetValue<string>(ParameterNames.BatchProcessing_Name, out batchprocessingname);
  100. parameters.TryGetValue<string[]>(ParameterNames.FilePath, out filepath);
  101. parameters.TryGetValue<int>("ConverterTypeIndex", out convertertypeindex);
  102. if (batchprocessingname != null || filepath != null) {
  103. fileNames = filepath.ToList();
  104. this.convertertypeindex = convertertypeindex;
  105. ChangeBatchProcessing(batchprocessingname);
  106. }
  107. }
  108. public void OnNavigatedTo(NavigationContext navigationContext)
  109. {
  110. }
  111. public bool IsNavigationTarget(NavigationContext navigationContext)
  112. {
  113. return true;
  114. }
  115. public void OnNavigatedFrom(NavigationContext navigationContext)
  116. {
  117. }
  118. #endregion
  119. }
  120. }