CPDFPageExtractWindow.xaml.cs 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. using Compdfkit_Tools.Helper;
  2. using Compdfkit_Tools.PDFControlUI;
  3. using Compdfkit_Tools.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_Tools.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 = PDFControlUI.PageRange.AllPages;
  28. extractEventClass.PageMode = 1;
  29. }
  30. else
  31. {
  32. CPDFPageExtractUI.PageRange = PDFControlUI.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. }
  53. private void CPDFPageExtractUI_CancelEvent(object sender, EventArgs e)
  54. {
  55. CloseWindow(null);
  56. }
  57. private void CPDFPageExtractUI_ExtractEvent(object sender, EventArgs e)
  58. {
  59. if (extractEventClass.PageMode != 4)
  60. {
  61. if (extractEventClass.PageMode == 1 && extractEventClass.DeleteAfterExtract)
  62. {
  63. MessageBox.Show(" Please keep at least one page.", "Alert", MessageBoxButton.OK, MessageBoxImage.Warning);
  64. return;
  65. }
  66. if (extractEventClass.PageMode == 3 && CPDFPageExtractUI.MaxIndex == 1)
  67. {
  68. MessageBox.Show(" No page will be extracted.", "Alert", MessageBoxButton.OK, MessageBoxImage.Warning);
  69. return;
  70. }
  71. CloseWindow(extractEventClass);
  72. }
  73. else if(extractEventClass.PageMode == 4 && CommonHelper.GetPagesInRange(ref pageRangeList, pageRangeString, CPDFPageExtractUI.MaxIndex, new char[] { ',' }, new char[] { '-' }))
  74. {
  75. if (pageRangeList.Count == CPDFPageExtractUI.MaxIndex && extractEventClass.DeleteAfterExtract)
  76. {
  77. MessageBox.Show(" Please keep at least one page.", "Alert", MessageBoxButton.OK, MessageBoxImage.Warning);
  78. return;
  79. }
  80. extractEventClass.PageName = pageRangeString;
  81. for (int i = 0; i < pageRangeList.Count; i++)
  82. {
  83. pageRangeList[i]++;
  84. }
  85. extractEventClass.PageParm = pageRangeList;
  86. CloseWindow(extractEventClass);
  87. }
  88. else
  89. {
  90. MessageBox.Show(LanguageHelper.DocEditorManager.GetString("Warn_PageRange"),
  91. LanguageHelper.CommonManager.GetString("Caption_Warning"), MessageBoxButton.OK, MessageBoxImage.Warning);
  92. }
  93. }
  94. private void CPDFPageExtractUI_CustomPageRangeChanged(object sender, string e)
  95. {
  96. pageRangeString = e;
  97. }
  98. private void CPDFPageExtractUI_DeleteChanged(object sender, bool e)
  99. {
  100. extractEventClass.DeleteAfterExtract = e;
  101. }
  102. private void CPDFPageExtractUI_SeparateChanged(object sender, bool e)
  103. {
  104. extractEventClass.ExtractToSingleFile = e;
  105. }
  106. private void CPDFPageExtractUI_PageRangeChanged(object sender, PDFControlUI.PageRange e)
  107. {
  108. extractEventClass.PageMode = (int)e;
  109. }
  110. private void CPDFPageExtractUI_Unloaded(object sender, RoutedEventArgs e)
  111. {
  112. CPDFPageExtractUI.PageRangeChanged -= CPDFPageExtractUI_PageRangeChanged;
  113. CPDFPageExtractUI.CustomPageRangeChanged -= CPDFPageExtractUI_CustomPageRangeChanged;
  114. CPDFPageExtractUI.SeparateChanged -= CPDFPageExtractUI_SeparateChanged;
  115. CPDFPageExtractUI.DeleteChanged -= CPDFPageExtractUI_DeleteChanged;
  116. CPDFPageExtractUI.ExtractEvent -= CPDFPageExtractUI_ExtractEvent;
  117. CPDFPageExtractUI.CancelEvent -= CPDFPageExtractUI_CancelEvent;
  118. }
  119. private void CloseWindow(ExtractEventClass dialogResult)
  120. {
  121. DialogClosed?.Invoke(this, new ExtractDialogCloseEventArgs(dialogResult));
  122. Close();
  123. }
  124. }
  125. public class ExtractDialogCloseEventArgs : EventArgs
  126. {
  127. public ExtractEventClass DialogResult { get; set; }
  128. public ExtractDialogCloseEventArgs(ExtractEventClass dialogResult)
  129. {
  130. DialogResult = dialogResult;
  131. }
  132. }
  133. }