HomePagePictureToPDFDialog.xaml.cs 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  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. private WindowState WindowState;
  31. public HomePagePictureToPDFDialog()
  32. {
  33. InitializeComponent();
  34. viewModel = this.DataContext as HomePagePictureToPDFDialogViewModel;
  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. }
  52. private void RemoveFileMenuItem_Click(object sender, System.Windows.RoutedEventArgs e)
  53. {
  54. viewModel.removepicturefile();
  55. }
  56. private void OpenFileMenuItem_Click(object sender, System.Windows.RoutedEventArgs e)
  57. {
  58. viewModel.openfiledialog();
  59. }
  60. private void RadioButton_Click(object sender, System.Windows.RoutedEventArgs e)
  61. {
  62. var radiobutton = sender as RadioButton;
  63. viewModel.ImageToPDFBtnIsEnable = "True";
  64. switch (radiobutton.Name.ToString())
  65. {
  66. case "NewFilesRadioButtom":
  67. {
  68. viewModel.pictureToPDFModel.Mode = HomePagePictureToPDFDialogModel.ToPDFFileMode.NewFiles;
  69. }
  70. break;
  71. case "OneNewFileNameRadioButtom":
  72. {
  73. viewModel.pictureToPDFModel.Mode = HomePagePictureToPDFDialogModel.ToPDFFileMode.OneNewFile;
  74. }
  75. break;
  76. case "SelectFileNameRadioButton":
  77. {
  78. viewModel.pictureToPDFModel.Mode = HomePagePictureToPDFDialogModel.ToPDFFileMode.SelectFileName;
  79. if (!File.Exists(viewModel.SelectFileName))
  80. {
  81. viewModel.ImageToPDFBtnIsEnable = "False";
  82. }
  83. }
  84. break;
  85. default:
  86. break;
  87. }
  88. }
  89. private void Grid_Drop(object sender, DragEventArgs e)
  90. {
  91. try
  92. {
  93. Point iconPoint = e.GetPosition(this);
  94. dropHelper?.Drop((System.Runtime.InteropServices.ComTypes.IDataObject)e.Data, ref iconPoint, e.Effects);
  95. }
  96. catch (Exception ex)
  97. {
  98. }
  99. string dropFile = "Drop";
  100. if (e.Data.GetDataPresent(System.Windows.DataFormats.FileDrop))
  101. {
  102. BtnBlank.IsEnabled = true;
  103. int count = ((System.Array)e.Data.GetData(System.Windows.DataFormats.FileDrop)).Length;
  104. for (int i = 0; i < count; i++)
  105. {
  106. dropFile = ((System.Array)e.Data.GetData(System.Windows.DataFormats.FileDrop)).GetValue(i).ToString(); ;
  107. //MessageBox.Show(dropFile);
  108. 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"))
  109. { viewModel.addPicture(dropFile); }
  110. }
  111. }
  112. }
  113. private void MainPage_DragEnter(object sender, DragEventArgs e)
  114. {
  115. BtnBlank.IsEnabled = false;
  116. string dropFile = "Drop";
  117. //dropFile = ((System.Array)e.Data.GetData(System.Windows.DataFormats.FileDrop)).GetValue(i).ToString(); ;
  118. //页面编辑和缩略图
  119. if ((e.OriginalSource as Image) != null)
  120. return;
  121. try
  122. {
  123. if (dropHelper == null)
  124. {
  125. dropHelper = Activator.CreateInstance(Type.GetTypeFromCLSID(new Guid("4657278A-411B-11D2-839A-00C04FD918D0"))) as IDropTargetHelper;
  126. }
  127. Point iconPoint = e.GetPosition(this);
  128. dropHelper?.DragEnter(new WindowInteropHelper(Window.GetWindow(this)).Handle, (System.Runtime.InteropServices.ComTypes.IDataObject)e.Data, ref iconPoint, e.Effects);
  129. }
  130. catch (Exception ex)
  131. {
  132. }
  133. }
  134. private void MainPage_DragOver(object sender, DragEventArgs e)
  135. {
  136. if ((e.OriginalSource as Image) != null)
  137. return;
  138. try
  139. {
  140. Point iconPoint = e.GetPosition(this);
  141. dropHelper?.DragOver(ref iconPoint, e.Effects);
  142. }
  143. catch (Exception ex)
  144. {
  145. }
  146. }
  147. private void MainPage_DragLeave(object sender, DragEventArgs e)
  148. {
  149. BtnBlank.IsEnabled = true;
  150. if ((e.OriginalSource as Image) != null)
  151. return;
  152. try
  153. {
  154. dropHelper?.DragLeave();
  155. }
  156. catch (Exception ex)
  157. {
  158. }
  159. }
  160. private void DeleteTemplateBtn_Click(object sender, RoutedEventArgs e)
  161. {
  162. Button deletetemplatebtn = sender as Button;
  163. var ls = deletetemplatebtn.DataContext as DataRowView;
  164. if (ls != null)
  165. {
  166. viewModel.removepdffile(viewModel.ImagesDataTable.Rows.IndexOf(ls.Row));
  167. }
  168. }
  169. private void BtnMiniSize_Click(object sender, RoutedEventArgs e)
  170. {
  171. System.Windows.SystemCommands.MinimizeWindow(Window.GetWindow(this));
  172. }
  173. private void BtnClose_Click(object sender, RoutedEventArgs e)
  174. {
  175. Window.GetWindow(this).Close();
  176. }
  177. private void BtnReStore_Click(object sender, RoutedEventArgs e)
  178. {
  179. if (Window.GetWindow(this).WindowState == WindowState.Maximized)
  180. {
  181. System.Windows.SystemCommands.RestoreWindow(Window.GetWindow(this));
  182. }
  183. else
  184. {
  185. System.Windows.SystemCommands.MaximizeWindow(Window.GetWindow(this));
  186. }
  187. }
  188. private void listView_PreviewKeyDown(object sender, KeyEventArgs e)
  189. {
  190. if (e.KeyStates == Keyboard.GetKeyStates(Key.Escape))
  191. {
  192. var a = sender as ListView;
  193. if (a.SelectedIndex != -1)
  194. {
  195. viewModel.fileNamesView.Clear();
  196. e.Handled = true;
  197. }
  198. a.SelectedIndex = -1;
  199. }
  200. }
  201. private void userControl_SizeChanged(object sender, SizeChangedEventArgs e)
  202. {
  203. if (Window.GetWindow(this).WindowState == WindowState.Maximized)
  204. {
  205. ico_max.Visibility = Visibility.Collapsed;
  206. }
  207. else
  208. {
  209. ico_max.Visibility = Visibility.Visible;
  210. }
  211. }
  212. }
  213. }