using ComPDFKitViewer; using ComPDFKitViewer.PdfViewer; using DryIoc; using ImTools; using PDF_Office.Helper; using PDF_Office.Model.Dialog.HomePageToolsDialogs; using PDF_Office.ViewModels.Dialog.HomePageToolsDialogs; using PDF_Office.ViewModels.Dialog.HomePageToolsDialogs.HomePageBatchProcessing; using System; using System.Collections; using System.Collections.Generic; using System.Data; using System.Diagnostics; using System.IO; using System.Windows; using System.Windows.Controls; using System.Windows.Input; using System.Windows.Interop; using System.Xml.Linq; using static Dropbox.Api.Files.ThumbnailFormat; namespace PDF_Office.Views.Dialog.HomePageToolsDialogs { /// /// Interaction logic for HomePagePictureToPDFDialogs /// public partial class HomePagePictureToPDFDialog : UserControl { private IDropTargetHelper dropHelper; private HomePagePictureToPDFDialogViewModel viewModel; private WindowState WindowState; public HomePagePictureToPDFDialog() { InitializeComponent(); viewModel = this.DataContext as HomePagePictureToPDFDialogViewModel; } private void Menu_Click(object sender, System.Windows.RoutedEventArgs e) { menuPop1.IsOpen = true; } private void listView_SelectionChanged(object sender, SelectionChangedEventArgs e) { IList list = listView.SelectedItems; var lists = listView.Items; System.Data.DataRowView a; viewModel.fileNamesView.Clear(); foreach (var item in list) { a = (System.Data.DataRowView)item; viewModel.fileNamesView.Add(lists.IndexOf(a)); } } private void RemoveFileMenuItem_Click(object sender, System.Windows.RoutedEventArgs e) { viewModel.removepicturefile(); } private void OpenFileMenuItem_Click(object sender, System.Windows.RoutedEventArgs e) { viewModel.openfiledialog(); } private void RadioButton_Click(object sender, System.Windows.RoutedEventArgs e) { var radiobutton = sender as RadioButton; viewModel.ImageToPDFBtnIsEnable = "True"; switch (radiobutton.Name.ToString()) { case "NewFilesRadioButtom": { viewModel.pictureToPDFModel.Mode = HomePagePictureToPDFDialogModel.ToPDFFileMode.NewFiles; } break; case "OneNewFileNameRadioButtom": { viewModel.pictureToPDFModel.Mode = HomePagePictureToPDFDialogModel.ToPDFFileMode.OneNewFile; } break; case "SelectFileNameRadioButton": { viewModel.pictureToPDFModel.Mode = HomePagePictureToPDFDialogModel.ToPDFFileMode.SelectFileName; if (!File.Exists(viewModel.SelectFileName)) { viewModel.ImageToPDFBtnIsEnable = "False"; } } break; default: break; } } private void Grid_Drop(object sender, DragEventArgs e) { try { Point iconPoint = e.GetPosition(this); dropHelper?.Drop((System.Runtime.InteropServices.ComTypes.IDataObject)e.Data, ref iconPoint, e.Effects); } catch (Exception ex) { } string dropFile = "Drop"; if (e.Data.GetDataPresent(System.Windows.DataFormats.FileDrop)) { BtnBlank.IsEnabled = true; int count = ((System.Array)e.Data.GetData(System.Windows.DataFormats.FileDrop)).Length; for (int i = 0; i < count; i++) { dropFile = ((System.Array)e.Data.GetData(System.Windows.DataFormats.FileDrop)).GetValue(i).ToString(); ; //MessageBox.Show(dropFile); 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")) { viewModel.addPicture(dropFile); } } } } private void MainPage_DragEnter(object sender, DragEventArgs e) { BtnBlank.IsEnabled = false; string dropFile = "Drop"; //dropFile = ((System.Array)e.Data.GetData(System.Windows.DataFormats.FileDrop)).GetValue(i).ToString(); ; //页面编辑和缩略图 if ((e.OriginalSource as Image) != null) return; try { if (dropHelper == null) { dropHelper = Activator.CreateInstance(Type.GetTypeFromCLSID(new Guid("4657278A-411B-11D2-839A-00C04FD918D0"))) as IDropTargetHelper; } Point iconPoint = e.GetPosition(this); dropHelper?.DragEnter(new WindowInteropHelper(Window.GetWindow(this)).Handle, (System.Runtime.InteropServices.ComTypes.IDataObject)e.Data, ref iconPoint, e.Effects); } catch (Exception ex) { } } private void MainPage_DragOver(object sender, DragEventArgs e) { if ((e.OriginalSource as Image) != null) return; try { Point iconPoint = e.GetPosition(this); dropHelper?.DragOver(ref iconPoint, e.Effects); } catch (Exception ex) { } } private void MainPage_DragLeave(object sender, DragEventArgs e) { BtnBlank.IsEnabled = true; if ((e.OriginalSource as Image) != null) return; try { dropHelper?.DragLeave(); } catch (Exception ex) { } } private void DeleteTemplateBtn_Click(object sender, RoutedEventArgs e) { Button deletetemplatebtn = sender as Button; var ls = deletetemplatebtn.DataContext as DataRowView; if (ls != null) { viewModel.removepdffile(viewModel.ImagesDataTable.Rows.IndexOf(ls.Row)); } } private void BtnMiniSize_Click(object sender, RoutedEventArgs e) { System.Windows.SystemCommands.MinimizeWindow(Window.GetWindow(this)); } private void BtnClose_Click(object sender, RoutedEventArgs e) { Window.GetWindow(this).Close(); } private void BtnReStore_Click(object sender, RoutedEventArgs e) { if (Window.GetWindow(this).WindowState == WindowState.Maximized) { ico_max.Visibility = Visibility.Collapsed; System.Windows.SystemCommands.RestoreWindow(Window.GetWindow(this)); } else { ico_max.Visibility = Visibility.Visible; System.Windows.SystemCommands.MaximizeWindow(Window.GetWindow(this)); } } private void listView_PreviewKeyDown(object sender, KeyEventArgs e) { if (e.KeyStates == Keyboard.GetKeyStates(Key.Escape)) { var a = sender as ListView; if (a.SelectedIndex != -1) { viewModel.fileNamesView.Clear(); e.Handled = true; } a.SelectedIndex = -1; } } } }