HomePageConverterDialog.xaml.cs 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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;
  6. using PDF_Master.ViewModels.Dialog.HomePageToolsDialogs.HomePageBatchProcessing.HomePageConverter;
  7. using Prism.Ioc;
  8. using Prism.Regions;
  9. using System;
  10. using System.Collections;
  11. using System.Collections.Generic;
  12. using System.Data;
  13. using System.Diagnostics;
  14. using System.Windows;
  15. using System.Windows.Controls;
  16. using System.Windows.Interop;
  17. namespace PDF_Master.Views.Dialog.HomePageToolsDialogs.HomePageBatchProcessing.HomePageConverter
  18. {
  19. /// <summary>
  20. /// Interaction logic for HomePageConverterDialog
  21. /// </summary>
  22. public partial class HomePageConverterDialog : UserControl
  23. {
  24. private IContainerProvider containerProvider;
  25. private IDropTargetHelper dropHelper;
  26. private HomePageConverterDialogViewModel viewModel;
  27. public HomePageConverterDialog(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 HomePageConverterDialogViewModel;
  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 ConverterTypeComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
  69. {
  70. ((HomePageConverterDialogViewModel)this.DataContext).ChangeConverter(ConverterTypeComboBox.SelectedIndex);
  71. }
  72. private void Grid_Drop(object sender, DragEventArgs e)
  73. {
  74. try
  75. {
  76. Point iconPoint = e.GetPosition(this);
  77. dropHelper?.Drop((System.Runtime.InteropServices.ComTypes.IDataObject)e.Data, ref iconPoint, e.Effects);
  78. }
  79. catch
  80. {
  81. }
  82. string dropFile = "Drop";
  83. if (e.Data.GetDataPresent(System.Windows.DataFormats.FileDrop))
  84. {
  85. BtnBlank.IsEnabled = true;
  86. int count = ((System.Array)e.Data.GetData(System.Windows.DataFormats.FileDrop)).Length;
  87. for (int i = 0; i < count; i++)
  88. {
  89. dropFile = ((System.Array)e.Data.GetData(System.Windows.DataFormats.FileDrop)).GetValue(i).ToString(); ;
  90. //MessageBox.Show(dropFile);
  91. if (dropFile.ToLower().EndsWith("pdf"))
  92. { viewModel.addPDFFiles(dropFile); }
  93. }
  94. }
  95. }
  96. private void MainPage_DragEnter(object sender, DragEventArgs e)
  97. {
  98. BtnBlank.IsEnabled = false;
  99. //页面编辑和缩略图
  100. if ((e.OriginalSource as Image) != null)
  101. return;
  102. try
  103. {
  104. if (dropHelper == null)
  105. {
  106. dropHelper = Activator.CreateInstance(Type.GetTypeFromCLSID(new Guid("4657278A-411B-11D2-839A-00C04FD918D0"))) as IDropTargetHelper;
  107. }
  108. Point iconPoint = e.GetPosition(this);
  109. dropHelper?.DragEnter(new WindowInteropHelper(Window.GetWindow(this)).Handle, (System.Runtime.InteropServices.ComTypes.IDataObject)e.Data, ref iconPoint, e.Effects);
  110. }
  111. catch
  112. {
  113. }
  114. }
  115. private void MainPage_DragOver(object sender, DragEventArgs e)
  116. {
  117. if ((e.OriginalSource as Image) != null)
  118. return;
  119. try
  120. {
  121. Point iconPoint = e.GetPosition(this);
  122. dropHelper?.DragOver(ref iconPoint, e.Effects);
  123. }
  124. catch
  125. {
  126. }
  127. }
  128. private void MainPage_DragLeave(object sender, DragEventArgs e)
  129. {
  130. BtnBlank.IsEnabled = true;
  131. if ((e.OriginalSource as Image) != null)
  132. return;
  133. try
  134. {
  135. dropHelper?.DragLeave();
  136. }
  137. catch
  138. {
  139. }
  140. }
  141. private void PageRangeWritableComboBox_LostFocus(object sender, RoutedEventArgs e)
  142. {
  143. WritableComboBox writableComboBox = sender as WritableComboBox;
  144. var ls = writableComboBox.DataContext as DataRowView;
  145. if (ls != null)
  146. {
  147. List<int> PageIndexLists = new List<int>();
  148. var index = viewModel.PDFDataTable.Rows.IndexOf(ls.Row);
  149. viewModel.PDFCurrentDataTable.Rows[index]["FilePageRangeSelectIndex"] = writableComboBox.SelectedIndex.ToString();
  150. //viewModel.PDFCurrentDataTable.Rows[index]["FilePageRangeText"] = writableComboBox.Text;
  151. 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))
  152. {
  153. viewModel.PDFCurrentDataTable.Rows[index]["FilePageRangeSelectIndex"] = "0";
  154. if (viewModel.PDFDataTable.Rows[index]["FilePageRangeText"].ToString() != "")
  155. {
  156. if (viewModel.PDFCurrentDataTable.Rows[index]["FilePageRangeText"].ToString() != viewModel.PDFDataTable.Rows[index]["FilePageRangeText"].ToString())
  157. {
  158. viewModel.PDFCurrentDataTable.Rows[index]["FilePageRangeText"] = writableComboBox.SelectedIndex.ToString();
  159. viewModel.updateListview("待确定");
  160. }
  161. }
  162. }
  163. viewModel.PDFCurrentDataTable.Rows[index]["FilePageRangeText"] = writableComboBox.Text;
  164. }
  165. //viewModel.updateListview("待确定");
  166. }
  167. private void DeleteTemplateBtn_Click(object sender, RoutedEventArgs e)
  168. {
  169. Button deletetemplatebtn = sender as Button;
  170. var ls = deletetemplatebtn.DataContext as DataRowView;
  171. if (ls != null)
  172. {
  173. viewModel.removepdffile(viewModel.PDFDataTable.Rows.IndexOf(ls.Row));
  174. }
  175. }
  176. }
  177. }