HomePageInsertDialog.xaml.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. using PDF_Master.CustomControl;
  2. using PDF_Master.Helper;
  3. using PDF_Master.ViewModels.Dialog.HomePageToolsDialogs;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Diagnostics;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Text.RegularExpressions;
  10. using System.Threading.Tasks;
  11. using System.Windows;
  12. using System.Windows.Controls;
  13. using System.Windows.Data;
  14. using System.Windows.Documents;
  15. using System.Windows.Input;
  16. using System.Windows.Media;
  17. using System.Windows.Media.Imaging;
  18. using System.Windows.Navigation;
  19. using System.Windows.Shapes;
  20. namespace PDF_Master.Views.Dialog.HomePageToolsDialogs
  21. {
  22. /// <summary>
  23. /// MainPageInsertDialog.xaml 的交互逻辑
  24. /// </summary>
  25. public partial class HomePageInsertDialog : UserControl
  26. {
  27. public HomePageInsertDialog()
  28. {
  29. InitializeComponent();
  30. }
  31. private void PageInsertIndexTextBox_TextChanged(object sender, TextChangedEventArgs e)
  32. {
  33. if (this.PageInsertIndexTextBox.Text == "" || int.Parse(this.PageInsertIndexTextBox.Text) < 1)
  34. {
  35. this.PageInsertIndexTextBox.Text = "1";
  36. }
  37. if (this.PageCountText != null&&this.PageCountText.Text !="")
  38. {
  39. if (int.Parse(this.PageInsertIndexTextBox.Text) > int.Parse(this.PageCountText.Text))
  40. {
  41. this.PageInsertIndexTextBox.Text = this.PageCountText.Text;
  42. }
  43. }
  44. ((HomePageInsertDialogViewModel)this.DataContext).PageInsertIndex = this.PageInsertIndexTextBox.Text;
  45. }
  46. private void CountTextBox_PreviewTextInput(object sender, TextCompositionEventArgs e)
  47. {
  48. e.Handled = new Regex("[^0-9]+").IsMatch(e.Text);
  49. }
  50. private void PageTurningPreview_Loaded(object sender, RoutedEventArgs e)
  51. {
  52. InsertPreview.document = ((HomePageInsertDialogViewModel)this.DataContext).document;
  53. char[] enumerationSeparator = new char[] { ',' };
  54. char[] rangeSeparator = new char[] { '-' };
  55. if (!CommonHelper.GetPagesInRange(ref InsertPreview.PageIndexLists, "1-" + InsertPreview.document.PageCount.ToString(), InsertPreview.document.PageCount, enumerationSeparator, rangeSeparator))
  56. { //TODO
  57. Trace.WriteLine("输入不对");
  58. MessageBoxEx.Show("输入不对");
  59. return;
  60. }
  61. InsertPreview.AwaitRenderBitmap(InsertPreview.document);
  62. InsertPreview.PageIndex.Text = InsertPreview.document.PageCount.ToString();
  63. }
  64. }
  65. }