HomePagePictureToPDFDialog.xaml.cs 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. using ComPDFKitViewer;
  2. using ComPDFKitViewer.PdfViewer;
  3. using DryIoc;
  4. using ImTools;
  5. using PDF_Master.Helper;
  6. using PDF_Master.Model.Dialog.HomePageToolsDialogs;
  7. using PDF_Master.ViewModels.Dialog.HomePageToolsDialogs;
  8. using PDF_Master.ViewModels.Dialog.HomePageToolsDialogs.HomePageBatchProcessing;
  9. using System;
  10. using System.Collections;
  11. using System.Collections.Generic;
  12. using System.Data;
  13. using System.Diagnostics;
  14. using System.IO;
  15. using System.Windows;
  16. using System.Windows.Controls;
  17. using System.Windows.Input;
  18. using System.Windows.Interop;
  19. using System.Xml.Linq;
  20. using static Dropbox.Api.Files.ThumbnailFormat;
  21. namespace PDF_Master.Views.Dialog.HomePageToolsDialogs
  22. {
  23. /// <summary>
  24. /// Interaction logic for HomePagePictureToPDFDialogs
  25. /// </summary>
  26. public partial class HomePagePictureToPDFDialog : UserControl
  27. {
  28. private IDropTargetHelper dropHelper;
  29. private HomePagePictureToPDFDialogViewModel viewModel;
  30. public HomePagePictureToPDFDialog()
  31. {
  32. InitializeComponent();
  33. viewModel = this.DataContext as HomePagePictureToPDFDialogViewModel;
  34. }
  35. private void Menu_Click(object sender, System.Windows.RoutedEventArgs e)
  36. {
  37. menuPop1.IsOpen = true;
  38. }
  39. private void listView_SelectionChanged(object sender, SelectionChangedEventArgs e)
  40. {
  41. IList list = listView.SelectedItems;
  42. var lists = listView.Items;
  43. System.Data.DataRowView a;
  44. viewModel.fileNamesView.Clear();
  45. foreach (var item in list)
  46. {
  47. a = (System.Data.DataRowView)item;
  48. viewModel.fileNamesView.Add(lists.IndexOf(a));
  49. }
  50. }
  51. private void RemoveFileMenuItem_Click(object sender, System.Windows.RoutedEventArgs e)
  52. {
  53. viewModel.removepicturefile();
  54. }
  55. private void OpenFileMenuItem_Click(object sender, System.Windows.RoutedEventArgs e)
  56. {
  57. viewModel.openfiledialog();
  58. }
  59. private void RadioButton_Click(object sender, System.Windows.RoutedEventArgs e)
  60. {
  61. var radiobutton = sender as RadioButton;
  62. viewModel.ImageToPDFBtnIsEnable = "True";
  63. switch (radiobutton.Name.ToString())
  64. {
  65. case "NewFilesRadioButtom":
  66. {
  67. viewModel.pictureToPDFModel.Mode = HomePagePictureToPDFDialogModel.ToPDFFileMode.NewFiles;
  68. }
  69. break;
  70. case "OneNewFileNameRadioButtom":
  71. {
  72. viewModel.pictureToPDFModel.Mode = HomePagePictureToPDFDialogModel.ToPDFFileMode.OneNewFile;
  73. }
  74. break;
  75. case "SelectFileNameRadioButton":
  76. {
  77. viewModel.pictureToPDFModel.Mode = HomePagePictureToPDFDialogModel.ToPDFFileMode.SelectFileName;
  78. if (!File.Exists(viewModel.SelectFileName))
  79. {
  80. viewModel.ImageToPDFBtnIsEnable = "False";
  81. }
  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
  96. {
  97. }
  98. string dropFile = "Drop";
  99. if (e.Data.GetDataPresent(System.Windows.DataFormats.FileDrop))
  100. {
  101. BtnBlank.IsEnabled = true;
  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") || dropFile.ToLower().EndsWith("jpeg"))
  108. { viewModel.addPicture(dropFile); }
  109. }
  110. }
  111. }
  112. private void MainPage_DragEnter(object sender, DragEventArgs e)
  113. {
  114. BtnBlank.IsEnabled = false;
  115. //dropFile = ((System.Array)e.Data.GetData(System.Windows.DataFormats.FileDrop)).GetValue(i).ToString(); ;
  116. //页面编辑和缩略图
  117. if ((e.OriginalSource as Image) != null)
  118. return;
  119. try
  120. {
  121. if (dropHelper == null)
  122. {
  123. dropHelper = Activator.CreateInstance(Type.GetTypeFromCLSID(new Guid("4657278A-411B-11D2-839A-00C04FD918D0"))) as IDropTargetHelper;
  124. }
  125. Point iconPoint = e.GetPosition(this);
  126. dropHelper?.DragEnter(new WindowInteropHelper(Window.GetWindow(this)).Handle, (System.Runtime.InteropServices.ComTypes.IDataObject)e.Data, ref iconPoint, e.Effects);
  127. }
  128. catch
  129. {
  130. }
  131. }
  132. private void MainPage_DragOver(object sender, DragEventArgs e)
  133. {
  134. if ((e.OriginalSource as Image) != null)
  135. return;
  136. try
  137. {
  138. Point iconPoint = e.GetPosition(this);
  139. dropHelper?.DragOver(ref iconPoint, e.Effects);
  140. }
  141. catch
  142. {
  143. }
  144. }
  145. private void MainPage_DragLeave(object sender, DragEventArgs e)
  146. {
  147. BtnBlank.IsEnabled = true;
  148. if ((e.OriginalSource as Image) != null)
  149. return;
  150. try
  151. {
  152. dropHelper?.DragLeave();
  153. }
  154. catch
  155. {
  156. }
  157. }
  158. private void DeleteTemplateBtn_Click(object sender, RoutedEventArgs e)
  159. {
  160. Button deletetemplatebtn = sender as Button;
  161. var ls = deletetemplatebtn.DataContext as DataRowView;
  162. if (ls != null)
  163. {
  164. viewModel.removepdffile(viewModel.ImagesDataTable.Rows.IndexOf(ls.Row));
  165. }
  166. }
  167. private void BtnMiniSize_Click(object sender, RoutedEventArgs e)
  168. {
  169. System.Windows.SystemCommands.MinimizeWindow(Window.GetWindow(this));
  170. }
  171. private void BtnClose_Click(object sender, RoutedEventArgs e)
  172. {
  173. Window.GetWindow(this).Close();
  174. }
  175. private void BtnReStore_Click(object sender, RoutedEventArgs e)
  176. {
  177. if (Window.GetWindow(this).WindowState == WindowState.Maximized)
  178. {
  179. System.Windows.SystemCommands.RestoreWindow(Window.GetWindow(this));
  180. }
  181. else
  182. {
  183. System.Windows.SystemCommands.MaximizeWindow(Window.GetWindow(this));
  184. }
  185. }
  186. private void listView_PreviewKeyDown(object sender, KeyEventArgs e)
  187. {
  188. if (e.KeyStates == Keyboard.GetKeyStates(Key.Escape))
  189. {
  190. var a = sender as ListView;
  191. if (a.SelectedIndex != -1)
  192. {
  193. viewModel.fileNamesView.Clear();
  194. e.Handled = true;
  195. }
  196. a.SelectedIndex = -1;
  197. }
  198. }
  199. private void userControl_SizeChanged(object sender, SizeChangedEventArgs e)
  200. {
  201. if (Window.GetWindow(this).WindowState == WindowState.Maximized)
  202. {
  203. ico_max.Visibility = Visibility.Collapsed;
  204. }
  205. else
  206. {
  207. ico_max.Visibility = Visibility.Visible;
  208. }
  209. }
  210. }
  211. }