HomePageCompressDialog.xaml.cs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. using PDF_Master.Helper;
  2. using PDF_Master.ViewModels.Dialog.HomePageToolsDialogs;
  3. using PDF_Master.ViewModels.Dialog.HomePageToolsDialogs.HomePageBatchProcessing;
  4. using System;
  5. using System.Collections;
  6. using System.Data;
  7. using System.Windows;
  8. using System.Windows.Controls;
  9. using System.Windows.Interop;
  10. namespace PDF_Master.Views.Dialog.HomePageToolsDialogs.HomePageBatchProcessing
  11. {
  12. /// <summary>
  13. /// Interaction logic for HomePageCompressDialog
  14. /// </summary>
  15. public partial class HomePageCompressDialog : UserControl
  16. {
  17. private HomePageCompressDialogViewModel viewModel;
  18. private IDropTargetHelper dropHelper;
  19. public HomePageCompressDialog()
  20. {
  21. InitializeComponent();
  22. viewModel=this.DataContext as HomePageCompressDialogViewModel;
  23. }
  24. private void Menu_Click(object sender, System.Windows.RoutedEventArgs e)
  25. {
  26. menuPop1.IsOpen = true;
  27. }
  28. private void listView_SelectionChanged(object sender, SelectionChangedEventArgs e)
  29. {
  30. IList list = listView.SelectedItems;
  31. var lists = listView.Items;
  32. System.Data.DataRowView a;
  33. viewModel.fileNamesView.Clear();
  34. foreach (var item in list)
  35. {
  36. a = (System.Data.DataRowView)item;
  37. viewModel.fileNamesView.Add(lists.IndexOf(a));
  38. }
  39. if (viewModel.fileNamesView.Count > 0)
  40. {
  41. viewModel.RemoveIsEnable = "True";
  42. }
  43. else
  44. {
  45. viewModel.RemoveIsEnable = "False";
  46. }
  47. }
  48. private void RemoveFileMenuItem_Click(object sender, System.Windows.RoutedEventArgs e)
  49. {
  50. viewModel.removepdffile();
  51. }
  52. private void OpenFileMenuItem_Click(object sender, System.Windows.RoutedEventArgs e)
  53. {
  54. viewModel.openfiledialog();
  55. }
  56. private void Grid_Drop(object sender, DragEventArgs e)
  57. {
  58. try
  59. {
  60. Point iconPoint = e.GetPosition(this);
  61. dropHelper?.Drop((System.Runtime.InteropServices.ComTypes.IDataObject)e.Data, ref iconPoint, e.Effects);
  62. }
  63. catch (Exception ex)
  64. {
  65. }
  66. string dropFile = "Drop";
  67. if (e.Data.GetDataPresent(System.Windows.DataFormats.FileDrop))
  68. {
  69. BtnBlank.IsEnabled = true;
  70. int count = ((System.Array)e.Data.GetData(System.Windows.DataFormats.FileDrop)).Length;
  71. for (int i = 0; i < count; i++)
  72. {
  73. dropFile = ((System.Array)e.Data.GetData(System.Windows.DataFormats.FileDrop)).GetValue(i).ToString(); ;
  74. //MessageBox.Show(dropFile);
  75. if (dropFile.ToLower().EndsWith("pdf"))
  76. { viewModel.addPDFFiles(dropFile); }
  77. }
  78. }
  79. }
  80. private void MainPage_DragEnter(object sender, DragEventArgs e)
  81. {
  82. BtnBlank.IsEnabled = false;
  83. //页面编辑和缩略图
  84. if ((e.OriginalSource as Image) != null)
  85. return;
  86. try
  87. {
  88. if (dropHelper == null)
  89. {
  90. dropHelper = Activator.CreateInstance(Type.GetTypeFromCLSID(new Guid("4657278A-411B-11D2-839A-00C04FD918D0"))) as IDropTargetHelper;
  91. }
  92. Point iconPoint = e.GetPosition(this);
  93. dropHelper?.DragEnter(new WindowInteropHelper(Window.GetWindow(this)).Handle, (System.Runtime.InteropServices.ComTypes.IDataObject)e.Data, ref iconPoint, e.Effects);
  94. }
  95. catch (Exception ex)
  96. {
  97. }
  98. }
  99. private void MainPage_DragOver(object sender, DragEventArgs e)
  100. {
  101. if ((e.OriginalSource as Image) != null)
  102. return;
  103. try
  104. {
  105. Point iconPoint = e.GetPosition(this);
  106. dropHelper?.DragOver(ref iconPoint, e.Effects);
  107. }
  108. catch (Exception ex)
  109. {
  110. }
  111. }
  112. private void MainPage_DragLeave(object sender, DragEventArgs e)
  113. {
  114. BtnBlank.IsEnabled = true;
  115. if ((e.OriginalSource as Image) != null)
  116. return;
  117. try
  118. {
  119. dropHelper?.DragLeave();
  120. }
  121. catch (Exception ex)
  122. {
  123. }
  124. }
  125. private void DeleteTemplateBtn_Click(object sender, RoutedEventArgs e)
  126. {
  127. Button deletetemplatebtn = sender as Button;
  128. var ls = deletetemplatebtn.DataContext as DataRowView;
  129. if (ls != null)
  130. {
  131. viewModel.removepdffile(viewModel.PDFDataTable.Rows.IndexOf(ls.Row));
  132. }
  133. }
  134. }
  135. }