CPDFPageExtractWindow.xaml.cs 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. using ComPDFKit.Controls.Helper;
  2. using ComPDFKit.Controls.PDFControlUI;
  3. using ComPDFKit.Controls.Properties;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Reflection;
  7. using System.Windows;
  8. using MessageBox = System.Windows.MessageBox;
  9. namespace ComPDFKit.Controls.PDFControl
  10. {
  11. public partial class CPDFPageExtractWindow : Window
  12. {
  13. private string pageRangeString = string.Empty;
  14. private List<int> pageRangeList = new List<int>();
  15. public ExtractEventClass extractEventClass = new ExtractEventClass();
  16. public delegate void DialogCloseEventHandler(object sender, ExtractDialogCloseEventArgs e);
  17. public event DialogCloseEventHandler DialogClosed;
  18. public CPDFPageExtractWindow()
  19. {
  20. InitializeComponent();
  21. Title = LanguageHelper.DocEditorManager.GetString("Title_Extract");
  22. }
  23. public void InitPageExtractWindow(string customPageRange, int maxPage)
  24. {
  25. if (customPageRange == string.Empty)
  26. {
  27. CPDFPageExtractUI.PageRange = PageRange.AllPages;
  28. extractEventClass.PageMode = 1;
  29. }
  30. else
  31. {
  32. CPDFPageExtractUI.PageRange = PageRange.CustomPages;
  33. extractEventClass.PageMode = 4;
  34. pageRangeString = customPageRange;
  35. CommonHelper.GetPagesInRange(ref pageRangeList, pageRangeString, CPDFPageExtractUI.MaxIndex, new char[] { ',' }, new char[] { '-' });
  36. for (int i = 0; i < pageRangeList.Count; i++)
  37. {
  38. pageRangeList[i]++;
  39. }
  40. }
  41. CPDFPageExtractUI.MaxIndex = maxPage;
  42. CPDFPageExtractUI.CurrentPageRange = customPageRange;
  43. }
  44. private void CPDFPageExtractUI_Loaded(object sender, RoutedEventArgs e)
  45. {
  46. CPDFPageExtractUI.PageRangeChanged -= CPDFPageExtractUI_PageRangeChanged;
  47. CPDFPageExtractUI.CustomPageRangeChanged -= CPDFPageExtractUI_CustomPageRangeChanged;
  48. CPDFPageExtractUI.SeparateChanged -= CPDFPageExtractUI_SeparateChanged;
  49. CPDFPageExtractUI.DeleteChanged -= CPDFPageExtractUI_DeleteChanged;
  50. CPDFPageExtractUI.ExtractEvent -= CPDFPageExtractUI_ExtractEvent;
  51. CPDFPageExtractUI.CancelEvent -= CPDFPageExtractUI_CancelEvent;
  52. CPDFPageExtractUI.PageRangeChanged += CPDFPageExtractUI_PageRangeChanged;
  53. CPDFPageExtractUI.CustomPageRangeChanged += CPDFPageExtractUI_CustomPageRangeChanged;
  54. CPDFPageExtractUI.SeparateChanged += CPDFPageExtractUI_SeparateChanged;
  55. CPDFPageExtractUI.DeleteChanged += CPDFPageExtractUI_DeleteChanged;
  56. CPDFPageExtractUI.ExtractEvent += CPDFPageExtractUI_ExtractEvent;
  57. CPDFPageExtractUI.CancelEvent += CPDFPageExtractUI_CancelEvent;
  58. }
  59. private void CPDFPageExtractUI_CancelEvent(object sender, EventArgs e)
  60. {
  61. CloseWindow(null);
  62. }
  63. private void CPDFPageExtractUI_ExtractEvent(object sender, EventArgs e)
  64. {
  65. if (extractEventClass.PageMode != 4)
  66. {
  67. if (extractEventClass.PageMode == 1 && extractEventClass.DeleteAfterExtract)
  68. {
  69. MessageBox.Show(" Please keep at least one page.", "Alert", MessageBoxButton.OK, MessageBoxImage.Warning);
  70. return;
  71. }
  72. if (extractEventClass.PageMode == 3 && CPDFPageExtractUI.MaxIndex == 1)
  73. {
  74. MessageBox.Show(" No page will be extracted.", "Alert", MessageBoxButton.OK, MessageBoxImage.Warning);
  75. return;
  76. }
  77. CloseWindow(extractEventClass);
  78. }
  79. else if(extractEventClass.PageMode == 4 && CommonHelper.GetPagesInRange(ref pageRangeList, pageRangeString, CPDFPageExtractUI.MaxIndex, new char[] { ',' }, new char[] { '-' }))
  80. {
  81. if (pageRangeList.Count == CPDFPageExtractUI.MaxIndex && extractEventClass.DeleteAfterExtract)
  82. {
  83. MessageBox.Show(" Please keep at least one page.", "Alert", MessageBoxButton.OK, MessageBoxImage.Warning);
  84. return;
  85. }
  86. extractEventClass.PageName = pageRangeString;
  87. for (int i = 0; i < pageRangeList.Count; i++)
  88. {
  89. pageRangeList[i]++;
  90. }
  91. extractEventClass.PageParm = pageRangeList;
  92. CloseWindow(extractEventClass);
  93. }
  94. else
  95. {
  96. MessageBox.Show(LanguageHelper.DocEditorManager.GetString("Warn_PageRange"),
  97. LanguageHelper.CommonManager.GetString("Caption_Warning"), MessageBoxButton.OK, MessageBoxImage.Warning);
  98. }
  99. }
  100. private void CPDFPageExtractUI_CustomPageRangeChanged(object sender, string e)
  101. {
  102. pageRangeString = e;
  103. }
  104. private void CPDFPageExtractUI_DeleteChanged(object sender, bool e)
  105. {
  106. extractEventClass.DeleteAfterExtract = e;
  107. }
  108. private void CPDFPageExtractUI_SeparateChanged(object sender, bool e)
  109. {
  110. extractEventClass.ExtractToSingleFile = e;
  111. }
  112. private void CPDFPageExtractUI_PageRangeChanged(object sender, PageRange e)
  113. {
  114. extractEventClass.PageMode = (int)e;
  115. }
  116. private void CPDFPageExtractUI_Unloaded(object sender, RoutedEventArgs e)
  117. {
  118. CPDFPageExtractUI.PageRangeChanged -= CPDFPageExtractUI_PageRangeChanged;
  119. CPDFPageExtractUI.CustomPageRangeChanged -= CPDFPageExtractUI_CustomPageRangeChanged;
  120. CPDFPageExtractUI.SeparateChanged -= CPDFPageExtractUI_SeparateChanged;
  121. CPDFPageExtractUI.DeleteChanged -= CPDFPageExtractUI_DeleteChanged;
  122. CPDFPageExtractUI.ExtractEvent -= CPDFPageExtractUI_ExtractEvent;
  123. CPDFPageExtractUI.CancelEvent -= CPDFPageExtractUI_CancelEvent;
  124. }
  125. private void CloseWindow(ExtractEventClass dialogResult)
  126. {
  127. DialogClosed?.Invoke(this, new ExtractDialogCloseEventArgs(dialogResult));
  128. Close();
  129. }
  130. }
  131. public class ExtractDialogCloseEventArgs : EventArgs
  132. {
  133. public ExtractEventClass DialogResult { get; set; }
  134. public ExtractDialogCloseEventArgs(ExtractEventClass dialogResult)
  135. {
  136. DialogResult = dialogResult;
  137. }
  138. }
  139. }