SplitDialogViewModel.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. using ComPDFKitViewer.PdfViewer;
  2. using PDF_Office.CustomControl;
  3. using PDF_Office.Helper;
  4. using PDF_Office.Model;
  5. using PDF_Office.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_Office.ViewModels.Dialog.PageEditDialogs
  15. {
  16. public class SplitDialogViewModel : BindableBase, IDialogAware
  17. {
  18. public string Title => "";
  19. private CPDFViewer pdfViewer;
  20. private double pageCount;
  21. //页面总数
  22. public double PageCount
  23. {
  24. get { return pageCount; }
  25. set
  26. {
  27. SetProperty(ref pageCount, value);
  28. }
  29. }
  30. private string customPageText;
  31. /// <summary>
  32. /// 自定义的输入内容
  33. /// </summary>
  34. public string CustomPageText
  35. {
  36. get { return customPageText; }
  37. set
  38. {
  39. SetProperty(ref customPageText, value);
  40. }
  41. }
  42. private HomePageSplitDialogModel model;
  43. public HomePageSplitDialogModel Model
  44. {
  45. get { return model; }
  46. set
  47. {
  48. SetProperty(ref model, value);
  49. }
  50. }
  51. public event Action<IDialogResult> RequestClose;
  52. public DelegateCommand CancelCommand { get; set; }
  53. public DelegateCommand SplitCommnad { get; set; }
  54. public SplitDialogViewModel()
  55. {
  56. CancelCommand = new DelegateCommand(cancel);
  57. SplitCommnad = new DelegateCommand(split);
  58. Model = new HomePageSplitDialogModel();
  59. }
  60. private void cancel()
  61. {
  62. RequestClose.Invoke(new DialogResult(ButtonResult.Cancel));
  63. }
  64. private void split()
  65. {
  66. List<int> pages = new List<int>();
  67. var result = CommonHelper.GetPagesInRange(ref pages,CustomPageText,(int)pageCount,new char[]{ '-'},new char[] { ','});
  68. if(!result)
  69. {
  70. AlertsMessage alertsMessage = new AlertsMessage();
  71. alertsMessage.ShowDialog("","请输入有效范围","OK");
  72. return;
  73. }
  74. Model.PageRange = customPageText;
  75. DialogParameters valuePairs = new DialogParameters();
  76. valuePairs.Add(ParameterNames.DataModel,Model);
  77. RequestClose.Invoke(new DialogResult(ButtonResult.OK, valuePairs));
  78. }
  79. #region
  80. public bool CanCloseDialog()
  81. {
  82. return true;
  83. }
  84. public void OnDialogClosed()
  85. {
  86. }
  87. public void OnDialogOpened(IDialogParameters parameters)
  88. {
  89. parameters.TryGetValue<CPDFViewer>(ParameterNames.PDFViewer,out pdfViewer);
  90. if(pdfViewer!=null)
  91. {
  92. PageCount = pdfViewer.Document.PageCount;
  93. Model.SourceFileName = System.IO.Path.GetFileName(pdfViewer.Document.FileName);
  94. }
  95. }
  96. #endregion
  97. }
  98. }