CPDFPageInsertWindow.xaml.cs 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. using Compdfkit_Tools.Helper;
  2. using Compdfkit_Tools.PDFControlUI;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Windows;
  6. namespace Compdfkit_Tools.PDFControl
  7. {
  8. public partial class CPDFPageInsertWindow : Window
  9. {
  10. public InsertEventClass Result = new InsertEventClass();
  11. public delegate void DialogCloseEventHandler(object sender, InsertDialogCloseEventArgs e);
  12. public event DialogCloseEventHandler DialogClosed;
  13. public CPDFPageInsertWindow()
  14. {
  15. InitializeComponent();
  16. }
  17. public void InitPageInsertWindow(int index, int maxPage)
  18. {
  19. if (index == -1)
  20. {
  21. CPDFPageInsertUI.PageInsertLocation = PageInsertLocation.HomePage;
  22. }
  23. else
  24. {
  25. CPDFPageInsertUI.PageInsertLocation = PageInsertLocation.CustomPage;
  26. CPDFPageInsertUI.CustomPageIndex = index + 1;
  27. Result.InsertIndex = index + 1;
  28. }
  29. CPDFPageInsertUI.MaxIndex = maxPage;
  30. }
  31. private void CPDFPageInsertUI_Loaded(object sender, RoutedEventArgs e)
  32. {
  33. CPDFPageInsertUI.InsertTypeChanged += CPDFPageInsertUI_InsertTypeChanged;
  34. CPDFPageInsertUI.SelectedFileChanged += CPDFPageInsertUI_SelectedFileChanged;
  35. CPDFPageInsertUI.InsertIndexChanged += CPDFPageInsertUI_InsertIndexChanged;
  36. CPDFPageInsertUI.TextChanged += CPDFPageInsertUI_TextChanged;
  37. CPDFPageInsertUI.CancelEvent += CPDFPageInsertUI_CancelEvent;
  38. CPDFPageInsertUI.InsertEvent += CPDFPageInsertUI_InsertEvent;
  39. CPDFPageInsertUI.PageSizeChanged += CPDFPageInsertUI_PageSizeChanged;
  40. CPDFPageInsertUI.PasswordChanged += CPDFPageInsertUI_PasswordChanged;
  41. }
  42. private void CPDFPageInsertUI_Unloaded(object sender, RoutedEventArgs e)
  43. {
  44. CPDFPageInsertUI.InsertTypeChanged -= CPDFPageInsertUI_InsertTypeChanged;
  45. CPDFPageInsertUI.SelectedFileChanged -= CPDFPageInsertUI_SelectedFileChanged;
  46. CPDFPageInsertUI.InsertIndexChanged -= CPDFPageInsertUI_InsertIndexChanged;
  47. CPDFPageInsertUI.TextChanged -= CPDFPageInsertUI_TextChanged;
  48. CPDFPageInsertUI.CancelEvent -= CPDFPageInsertUI_CancelEvent;
  49. CPDFPageInsertUI.InsertEvent -= CPDFPageInsertUI_InsertEvent;
  50. CPDFPageInsertUI.PageSizeChanged -= CPDFPageInsertUI_PageSizeChanged;
  51. CPDFPageInsertUI.PasswordChanged -= CPDFPageInsertUI_PasswordChanged;
  52. }
  53. private void CPDFPageInsertUI_PasswordChanged(object sender, string e)
  54. {
  55. Result.Password = e;
  56. }
  57. private void CPDFPageInsertUI_InsertEvent(object sender, EventArgs e)
  58. {
  59. if (Result.InsertType == InsertType.FromOtherPDF && Result.FilePath == string.Empty)
  60. {
  61. MessageBox.Show(" Please select a PDF file.", "Alert", MessageBoxButton.OK, MessageBoxImage.Warning);
  62. return;
  63. }
  64. List<int> pageRangeList = new List<int>();
  65. if (Result.InsertType == InsertType.FromOtherPDF && !CommonHelper.GetPagesInRange(ref pageRangeList, Result.PageRange, CPDFPageInsertUI.MaxIndex, new char[] { ',' }, new char[] { '-' }))
  66. {
  67. MessageBox.Show("Please check page range.", "Alert", MessageBoxButton.OK, MessageBoxImage.Warning);
  68. return;
  69. }
  70. CloseWindow(Result);
  71. }
  72. private void CPDFPageInsertUI_CancelEvent(object sender, EventArgs e)
  73. {
  74. CloseWindow(null);
  75. }
  76. private void CPDFPageInsertUI_TextChanged(object sender, string e)
  77. {
  78. Result.PageRange = e;
  79. }
  80. private void CPDFPageInsertUI_SelectedFileChanged(object sender, string e)
  81. {
  82. Result.FilePath = e;
  83. }
  84. private void CPDFPageInsertUI_InsertTypeChanged(object sender, string e)
  85. {
  86. if (e == "BlankPages")
  87. {
  88. Result.InsertType = InsertType.BlankPages;
  89. }
  90. else if (e == "CustomBlankPages")
  91. {
  92. Result.InsertType = InsertType.CustomBlankPages;
  93. }
  94. else
  95. {
  96. Result.InsertType = InsertType.FromOtherPDF;
  97. }
  98. }
  99. private void CPDFPageInsertUI_InsertIndexChanged(object sender, int e)
  100. {
  101. Result.InsertIndex = e;
  102. }
  103. private void CloseWindow(InsertEventClass dialogResult)
  104. {
  105. DialogClosed?.Invoke(this, new InsertDialogCloseEventArgs(dialogResult));
  106. Close();
  107. }
  108. private void CPDFPageInsertUI_PageSizeChanged(object sender, double[] e)
  109. {
  110. Result.PageWidth = e[0];
  111. Result.PageHeight = e[1];
  112. }
  113. }
  114. public class InsertDialogCloseEventArgs : EventArgs
  115. {
  116. public InsertEventClass DialogResult { get; set; }
  117. public InsertDialogCloseEventArgs(InsertEventClass dialogResult)
  118. {
  119. DialogResult = dialogResult;
  120. }
  121. }
  122. }