HomePageHeaderFooterDialog.xaml.cs 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. using ComPDFKit.PDFDocument;
  2. using PDF_Master.CustomControl;
  3. using PDF_Master.Helper;
  4. using PDF_Master.Model.Dialog.HomePageToolsDialogs.HomePageBatchProcessing;
  5. using PDF_Master.ViewModels.Dialog.HomePageToolsDialogs.HomePageBatchProcessing.HomePageHeaderFooter;
  6. using Prism.Ioc;
  7. using Prism.Regions;
  8. using System;
  9. using System.Collections;
  10. using System.Collections.Generic;
  11. using System.Data;
  12. using System.Diagnostics;
  13. using System.Windows;
  14. using System.Windows.Controls;
  15. using System.Windows.Interop;
  16. namespace PDF_Master.Views.Dialog.HomePageToolsDialogs.HomePageBatchProcessing.HomePageHeaderFooter
  17. {
  18. /// <summary>
  19. /// Interaction logic for HomePageHeaderFooterDialog
  20. /// </summary>
  21. public partial class HomePageHeaderFooterDialog : UserControl
  22. {
  23. private IContainerProvider containerProvider;
  24. private IDropTargetHelper dropHelper;
  25. private HomePageHeaderFooterDialogViewModel viewModel;
  26. public HomePageHeaderFooterDialog(IContainerProvider containerProvider)
  27. {
  28. InitializeComponent();
  29. this.containerProvider = containerProvider;
  30. var regionManager = containerProvider.Resolve<IRegionManager>();
  31. RegionManager.SetRegionManager(this, regionManager);
  32. RegionManager.UpdateRegions();
  33. viewModel = this.DataContext as HomePageHeaderFooterDialogViewModel;
  34. }
  35. private void Menu_Click(object sender, System.Windows.RoutedEventArgs e)
  36. {
  37. menuPop1.IsOpen = true;
  38. }
  39. private void listView_SelectionChanged(object sender, SelectionChangedEventArgs e)
  40. {
  41. IList list = listView.SelectedItems;
  42. var lists = listView.Items;
  43. System.Data.DataRowView a;
  44. viewModel.fileNamesView.Clear();
  45. foreach (var item in list)
  46. {
  47. a = (System.Data.DataRowView)item;
  48. viewModel.fileNamesView.Add(lists.IndexOf(a));
  49. }
  50. if (viewModel.fileNamesView.Count > 0)
  51. {
  52. viewModel.RemoveIsEnable = "True";
  53. }
  54. else
  55. {
  56. viewModel.RemoveIsEnable = "False";
  57. }
  58. }
  59. private void RemoveFileMenuItem_Click(object sender, System.Windows.RoutedEventArgs e)
  60. {
  61. viewModel.removepdffile();
  62. }
  63. private void OpenFileMenuItem_Click(object sender, System.Windows.RoutedEventArgs e)
  64. {
  65. viewModel.openfiledialog();
  66. }
  67. private void Grid_Drop(object sender, DragEventArgs e)
  68. {
  69. try
  70. {
  71. Point iconPoint = e.GetPosition(this);
  72. dropHelper?.Drop((System.Runtime.InteropServices.ComTypes.IDataObject)e.Data, ref iconPoint, e.Effects);
  73. }
  74. catch
  75. {
  76. }
  77. string dropFile = "Drop";
  78. if (e.Data.GetDataPresent(System.Windows.DataFormats.FileDrop))
  79. {
  80. BtnBlank.IsEnabled = true;
  81. int count = ((System.Array)e.Data.GetData(System.Windows.DataFormats.FileDrop)).Length;
  82. for (int i = 0; i < count; i++)
  83. {
  84. dropFile = ((System.Array)e.Data.GetData(System.Windows.DataFormats.FileDrop)).GetValue(i).ToString(); ;
  85. //MessageBox.Show(dropFile);
  86. if (dropFile.ToLower().EndsWith("pdf"))
  87. { viewModel.addPDFFiles(dropFile); }
  88. }
  89. }
  90. }
  91. private void MainPage_DragEnter(object sender, DragEventArgs e)
  92. {
  93. BtnBlank.IsEnabled = false;
  94. //页面编辑和缩略图
  95. if ((e.OriginalSource as Image) != null)
  96. return;
  97. try
  98. {
  99. if (dropHelper == null)
  100. {
  101. dropHelper = Activator.CreateInstance(Type.GetTypeFromCLSID(new Guid("4657278A-411B-11D2-839A-00C04FD918D0"))) as IDropTargetHelper;
  102. }
  103. Point iconPoint = e.GetPosition(this);
  104. dropHelper?.DragEnter(new WindowInteropHelper(Window.GetWindow(this)).Handle, (System.Runtime.InteropServices.ComTypes.IDataObject)e.Data, ref iconPoint, e.Effects);
  105. }
  106. catch
  107. {
  108. }
  109. }
  110. private void MainPage_DragOver(object sender, DragEventArgs e)
  111. {
  112. if ((e.OriginalSource as Image) != null)
  113. return;
  114. try
  115. {
  116. Point iconPoint = e.GetPosition(this);
  117. dropHelper?.DragOver(ref iconPoint, e.Effects);
  118. }
  119. catch
  120. {
  121. }
  122. }
  123. private void MainPage_DragLeave(object sender, DragEventArgs e)
  124. {
  125. BtnBlank.IsEnabled = true;
  126. if ((e.OriginalSource as Image) != null)
  127. return;
  128. try
  129. {
  130. dropHelper?.DragLeave();
  131. }
  132. catch
  133. {
  134. }
  135. }
  136. private void PageRangeWritableComboBox_LostFocus(object sender, RoutedEventArgs e)
  137. {
  138. WritableComboBox writableComboBox = sender as WritableComboBox;
  139. var ls = writableComboBox.DataContext as DataRowView;
  140. if (ls != null) {
  141. List<int> PageIndexLists = new List<int>();
  142. var index= viewModel.PDFDataTable.Rows.IndexOf(ls.Row);
  143. viewModel.PDFCurrentDataTable.Rows[index]["FilePageRangeSelectIndex"] = writableComboBox.SelectedIndex.ToString();
  144. //viewModel.PDFCurrentDataTable.Rows[index]["FilePageRangeText"] = writableComboBox.Text;
  145. if (viewModel.PDFCurrentDataTable.Rows[index]["FilePageRangeSelectIndex"].ToString() == "3" && !CommonHelper.GetPagesInRange(ref PageIndexLists, viewModel.PDFDataTable.Rows[index]["FilePageRangeText"].ToString().ToString(), CPDFDocument.InitWithFilePath(HomePageBatchProcessingDialogModel.FilePaths[index]).PageCount, new char[] { ',' }, new char[] { '-' }, true))
  146. {
  147. viewModel.PDFCurrentDataTable.Rows[index]["FilePageRangeSelectIndex"] = "0";
  148. if (viewModel.PDFDataTable.Rows[index]["FilePageRangeText"].ToString() != "") {
  149. if (viewModel.PDFCurrentDataTable.Rows[index]["FilePageRangeText"].ToString() != viewModel.PDFDataTable.Rows[index]["FilePageRangeText"].ToString())
  150. {
  151. viewModel.PDFCurrentDataTable.Rows[index]["FilePageRangeText"] = writableComboBox.SelectedIndex.ToString();
  152. viewModel.updateListview("待确定");
  153. }
  154. }
  155. }
  156. viewModel.PDFCurrentDataTable.Rows[index]["FilePageRangeText"] = writableComboBox.Text;
  157. }
  158. //viewModel.updateListview("待确定");
  159. }
  160. private void DeleteTemplateBtn_Click(object sender, RoutedEventArgs e)
  161. {
  162. Button deletetemplatebtn = sender as Button;
  163. var ls = deletetemplatebtn.DataContext as DataRowView;
  164. if (ls != null)
  165. {
  166. viewModel.removepdffile(viewModel.PDFDataTable.Rows.IndexOf(ls.Row));
  167. }
  168. }
  169. }
  170. }