HomePageBatesDialog.xaml.cs 7.4 KB

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