HomePageRemoveDialog.xaml.cs 5.0 KB

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