using ComPDFKit.PDFDocument; using PDF_Master.CustomControl; using PDF_Master.Helper; using PDF_Master.Model.Dialog.HomePageToolsDialogs.HomePageBatchProcessing; using PDF_Master.ViewModels.Dialog.HomePageToolsDialogs.HomePageBatchProcessing; using PDF_Master.ViewModels.Dialog.HomePageToolsDialogs.HomePageBatchProcessing.HomePageConverter; using Prism.Ioc; using Prism.Regions; using System; using System.Collections; using System.Collections.Generic; using System.Data; using System.Diagnostics; using System.Windows; using System.Windows.Controls; using System.Windows.Interop; namespace PDF_Master.Views.Dialog.HomePageToolsDialogs.HomePageBatchProcessing.HomePageConverter { /// /// Interaction logic for HomePageConverterDialog /// public partial class HomePageConverterDialog : UserControl { private IContainerProvider containerProvider; private IDropTargetHelper dropHelper; private HomePageConverterDialogViewModel viewModel; public HomePageConverterDialog(IContainerProvider containerProvider) { InitializeComponent(); this.containerProvider = containerProvider; var regionManager = containerProvider.Resolve(); RegionManager.SetRegionManager(this, regionManager); RegionManager.UpdateRegions(); viewModel=this.DataContext as HomePageConverterDialogViewModel; } 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)); } if (viewModel.fileNamesView.Count > 0) { viewModel.RemoveIsEnable = "True"; } else { viewModel.RemoveIsEnable = "False"; } } private void RemoveFileMenuItem_Click(object sender, System.Windows.RoutedEventArgs e) { viewModel.removepdffile(); } private void OpenFileMenuItem_Click(object sender, System.Windows.RoutedEventArgs e) { viewModel.openfiledialog(); } private void ConverterTypeComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { ((HomePageConverterDialogViewModel)this.DataContext).ChangeConverter(ConverterTypeComboBox.SelectedIndex); } 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("pdf")) { viewModel.addPDFFiles(dropFile); } } } } private void MainPage_DragEnter(object sender, DragEventArgs e) { BtnBlank.IsEnabled = false; //页面编辑和缩略图 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 PageRangeWritableComboBox_LostFocus(object sender, RoutedEventArgs e) { WritableComboBox writableComboBox = sender as WritableComboBox; var ls = writableComboBox.DataContext as DataRowView; if (ls != null) { List PageIndexLists = new List(); var index = viewModel.PDFDataTable.Rows.IndexOf(ls.Row); viewModel.PDFCurrentDataTable.Rows[index]["FilePageRangeSelectIndex"] = writableComboBox.SelectedIndex.ToString(); //viewModel.PDFCurrentDataTable.Rows[index]["FilePageRangeText"] = writableComboBox.Text; if (viewModel.PDFCurrentDataTable.Rows[index]["FilePageRangeSelectIndex"].ToString() == "3" && !CommonHelper.GetPagesInRange(ref PageIndexLists, viewModel.PDFDataTable.Rows[index]["FilePageRangeText"].ToString().ToString(), CPDFDocument.InitWithFilePath(HomePageBatchProcessingDialogModel.FilePaths[index]).PageCount, new char[] { ',' }, new char[] { '-' }, true)) { viewModel.PDFCurrentDataTable.Rows[index]["FilePageRangeSelectIndex"] = "0"; if (viewModel.PDFDataTable.Rows[index]["FilePageRangeText"].ToString() != "") { if (viewModel.PDFCurrentDataTable.Rows[index]["FilePageRangeText"].ToString() != viewModel.PDFDataTable.Rows[index]["FilePageRangeText"].ToString()) { viewModel.PDFCurrentDataTable.Rows[index]["FilePageRangeText"] = writableComboBox.SelectedIndex.ToString(); viewModel.updateListview("待确定"); } } } viewModel.PDFCurrentDataTable.Rows[index]["FilePageRangeText"] = writableComboBox.Text; } //viewModel.updateListview("待确定"); } 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.PDFDataTable.Rows.IndexOf(ls.Row)); } } } }