SplitDialogViewModel.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. using ComPDFKitViewer.PdfViewer;
  2. using PDF_Master.CustomControl;
  3. using PDF_Master.Helper;
  4. using PDF_Master.Model;
  5. using PDF_Master.Model.HomePageToolsDialogs;
  6. using Prism.Commands;
  7. using Prism.Mvvm;
  8. using Prism.Services.Dialogs;
  9. using System;
  10. using System.Collections.Generic;
  11. using System.Linq;
  12. using System.Text;
  13. using System.Threading.Tasks;
  14. namespace PDF_Master.ViewModels.Dialog.PageEditDialogs
  15. {
  16. public class SplitDialogViewModel : BindableBase, IDialogAware
  17. {
  18. public string Title => "";
  19. private CPDFViewer pdfViewer;
  20. private int listSelectedIndex;
  21. private double pageCount;
  22. private string pageEditSelectedItems;
  23. //页面总数
  24. public double PageCount
  25. {
  26. get { return pageCount; }
  27. set
  28. {
  29. SetProperty(ref pageCount, value);
  30. }
  31. }
  32. private string customPageText;
  33. /// <summary>
  34. /// 自定义的输入内容
  35. /// </summary>
  36. public string CustomPageText
  37. {
  38. get { return customPageText; }
  39. set
  40. {
  41. SetProperty(ref customPageText, value);
  42. }
  43. }
  44. private HomePageSplitDialogModel model;
  45. public HomePageSplitDialogModel Model
  46. {
  47. get { return model; }
  48. set
  49. {
  50. SetProperty(ref model, value);
  51. }
  52. }
  53. public event Action<IDialogResult> RequestClose;
  54. public DelegateCommand CancelCommand { get; set; }
  55. public DelegateCommand SplitCommnad { get; set; }
  56. public SplitDialogViewModel()
  57. {
  58. CancelCommand = new DelegateCommand(cancel);
  59. SplitCommnad = new DelegateCommand(split);
  60. Model = new HomePageSplitDialogModel();
  61. }
  62. private void cancel()
  63. {
  64. RequestClose.Invoke(new DialogResult(ButtonResult.Cancel));
  65. }
  66. private void split()
  67. {
  68. List<int> pages = new List<int>();
  69. Model.PageRange = model.CustomPageText;
  70. DialogParameters valuePairs = new DialogParameters();
  71. valuePairs.Add(ParameterNames.DataModel, Model);
  72. RequestClose.Invoke(new DialogResult(ButtonResult.OK, valuePairs));
  73. }
  74. #region
  75. public bool CanCloseDialog()
  76. {
  77. return true;
  78. }
  79. public void OnDialogClosed()
  80. {
  81. }
  82. public void OnDialogOpened(IDialogParameters parameters)
  83. {
  84. parameters.TryGetValue<CPDFViewer>(ParameterNames.PDFViewer, out pdfViewer);
  85. parameters.TryGetValue<int>(ParameterNames.PageEditSelectedIndex, out listSelectedIndex);
  86. parameters.TryGetValue<string>(ParameterNames.PageEditSelectedItems, out pageEditSelectedItems);
  87. if (pdfViewer != null)
  88. {
  89. PageCount = pdfViewer.Document.PageCount;
  90. Model.SourceFileName = System.IO.Path.GetFileName(pdfViewer.Document.FileName);
  91. //"拆分方式
  92. //若未选择要拆分的页面,则默认选中【平均每X页拆分为一个PDF文件】,默认参数为 1
  93. //若先选择了页面再点击【拆分】,则默认选中【按页面范围拆分】,默认参数为当前所选页面范围"
  94. if (listSelectedIndex == -1)
  95. {
  96. Model.IsAveragePages = true;
  97. }
  98. else
  99. {
  100. Model.IsCustomRange = true;
  101. if (pageEditSelectedItems != null)
  102. {
  103. model.CustomPageText = pageEditSelectedItems;
  104. }
  105. Model.PageSelectedIndex = 3;
  106. }
  107. }
  108. }
  109. #endregion
  110. }
  111. }