HomePagePictureToPDFDialog.xaml.cs 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. using ComPDFKitViewer;
  2. using DryIoc;
  3. using ImTools;
  4. using PDF_Office.Helper;
  5. using PDF_Office.Model.Dialog.HomePageToolsDialogs;
  6. using PDF_Office.ViewModels.Dialog.HomePageToolsDialogs;
  7. using PDF_Office.ViewModels.Dialog.HomePageToolsDialogs.HomePageBatchProcessing;
  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.Input;
  16. using System.Windows.Interop;
  17. using System.Xml.Linq;
  18. namespace PDF_Office.Views.Dialog.HomePageToolsDialogs
  19. {
  20. /// <summary>
  21. /// Interaction logic for HomePagePictureToPDFDialogs
  22. /// </summary>
  23. public partial class HomePagePictureToPDFDialog : UserControl
  24. {
  25. private IDropTargetHelper dropHelper;
  26. private HomePagePictureToPDFDialogViewModel viewModel;
  27. public HomePagePictureToPDFDialog()
  28. {
  29. InitializeComponent();
  30. viewModel = this.DataContext as HomePagePictureToPDFDialogViewModel;
  31. }
  32. private void Menu_Click(object sender, System.Windows.RoutedEventArgs e)
  33. {
  34. menuPop1.IsOpen = true;
  35. }
  36. private void listView_SelectionChanged(object sender, SelectionChangedEventArgs e)
  37. {
  38. IList list = listView.SelectedItems;
  39. var lists = listView.Items;
  40. System.Data.DataRowView a;
  41. viewModel.fileNamesView.Clear();
  42. foreach (var item in list)
  43. {
  44. a = (System.Data.DataRowView)item;
  45. viewModel.fileNamesView.Add(lists.IndexOf(a));
  46. }
  47. if (viewModel.fileNamesView.Count > 0)
  48. {
  49. viewModel.RemoveIsEnable = "True";
  50. }
  51. else
  52. {
  53. viewModel.RemoveIsEnable = "False";
  54. }
  55. }
  56. private void RemoveFileMenuItem_Click(object sender, System.Windows.RoutedEventArgs e)
  57. {
  58. viewModel.removepicturefile();
  59. }
  60. private void OpenFileMenuItem_Click(object sender, System.Windows.RoutedEventArgs e)
  61. {
  62. viewModel.openfiledialog();
  63. }
  64. private void RadioButton_Click(object sender, System.Windows.RoutedEventArgs e)
  65. {
  66. var radiobutton = sender as RadioButton;
  67. switch (radiobutton.Name.ToString())
  68. {
  69. case "NewFilesRadioButtom":
  70. {
  71. viewModel.pictureToPDFModel.Mode = HomePagePictureToPDFDialogModel.ToPDFFileMode.NewFiles;
  72. }
  73. break;
  74. case "OneNewFileNameRadioButtom":
  75. {
  76. viewModel.pictureToPDFModel.Mode = HomePagePictureToPDFDialogModel.ToPDFFileMode.OneNewFile;
  77. }
  78. break;
  79. case "SelectFileNameRadioButton":
  80. {
  81. viewModel.pictureToPDFModel.Mode = HomePagePictureToPDFDialogModel.ToPDFFileMode.SelectFileName;
  82. }
  83. break;
  84. default:
  85. break;
  86. }
  87. }
  88. private void Grid_Drop(object sender, DragEventArgs e)
  89. {
  90. try
  91. {
  92. Point iconPoint = e.GetPosition(this);
  93. dropHelper?.Drop((System.Runtime.InteropServices.ComTypes.IDataObject)e.Data, ref iconPoint, e.Effects);
  94. }
  95. catch (Exception ex)
  96. {
  97. }
  98. string dropFile = "Drop";
  99. if (e.Data.GetDataPresent(System.Windows.DataFormats.FileDrop))
  100. {
  101. DropGrid.Visibility = Visibility.Collapsed;
  102. int count = ((System.Array)e.Data.GetData(System.Windows.DataFormats.FileDrop)).Length;
  103. for (int i = 0; i < count; i++)
  104. {
  105. dropFile = ((System.Array)e.Data.GetData(System.Windows.DataFormats.FileDrop)).GetValue(i).ToString(); ;
  106. //MessageBox.Show(dropFile);
  107. if (dropFile.ToLower().EndsWith("png")|| dropFile.ToLower().EndsWith("jpg")|| dropFile.ToLower().EndsWith("bmp")|| dropFile.ToLower().EndsWith("gif")|| dropFile.ToLower().EndsWith("tiff"))
  108. { viewModel.addPicture(dropFile); }
  109. }
  110. }
  111. }
  112. private void MainPage_DragEnter(object sender, DragEventArgs e)
  113. {
  114. DropGrid.Visibility = Visibility.Visible;
  115. //页面编辑和缩略图
  116. if ((e.OriginalSource as Image) != null)
  117. return;
  118. try
  119. {
  120. if (dropHelper == null)
  121. {
  122. dropHelper = Activator.CreateInstance(Type.GetTypeFromCLSID(new Guid("4657278A-411B-11D2-839A-00C04FD918D0"))) as IDropTargetHelper;
  123. }
  124. Point iconPoint = e.GetPosition(this);
  125. dropHelper?.DragEnter(new WindowInteropHelper(Window.GetWindow(this)).Handle, (System.Runtime.InteropServices.ComTypes.IDataObject)e.Data, ref iconPoint, e.Effects);
  126. }
  127. catch (Exception ex)
  128. {
  129. }
  130. }
  131. private void MainPage_DragOver(object sender, DragEventArgs e)
  132. {
  133. if ((e.OriginalSource as Image) != null)
  134. return;
  135. try
  136. {
  137. Point iconPoint = e.GetPosition(this);
  138. dropHelper?.DragOver(ref iconPoint, e.Effects);
  139. }
  140. catch (Exception ex)
  141. {
  142. }
  143. }
  144. private void MainPage_DragLeave(object sender, DragEventArgs e)
  145. {
  146. DropGrid.Visibility = Visibility.Collapsed;
  147. if ((e.OriginalSource as Image) != null)
  148. return;
  149. try
  150. {
  151. dropHelper?.DragLeave();
  152. }
  153. catch (Exception ex)
  154. {
  155. }
  156. }
  157. private void DeleteTemplateBtn_Click(object sender, RoutedEventArgs e)
  158. {
  159. Button deletetemplatebtn = sender as Button;
  160. var ls = deletetemplatebtn.DataContext as DataRowView;
  161. if (ls != null)
  162. {
  163. viewModel.removepdffile(viewModel.ImagesDataTable.Rows.IndexOf(ls.Row));
  164. }
  165. }
  166. }
  167. }