using ComPDFKitViewer; using PDF_Master.Helper; using System.Data; using System.Windows; using System; using System.Windows.Controls; using System.Windows.Interop; using PDF_Master.ViewModels.Dialog.HomePageToolsDialogs.HomePageBatchProcessing; using PDF_Master.ViewModels.HomePanel.ChatGPTAI; using Microsoft.Office.Core; using PDF_Master.ViewModels; using System.IO; using Point = System.Windows.Point; using Window = System.Windows.Window; using System.Threading.Tasks; using PDF_Master.Model; using PDF_Master.Properties; using Prism.Services.Dialogs; using ComPDFKit.PDFDocument; using Microsoft.Office.Interop.Word; using PDFReader_WPF.Helper; namespace PDF_Master.Views.HomePanel.ChatGPTAI { /// /// Interaction logic for ChatGPTAITranslationContent /// public partial class ChatGPTAITranslationContent : UserControl { private ChatGPTAITranslationContentViewModel viewModel; private bool isFirst = false; private IDropTargetHelper dropHelper; public ChatGPTAITranslationContent() { InitializeComponent(); viewModel = this.DataContext as ChatGPTAITranslationContentViewModel; } private async void Grid_Drop(object sender, DragEventArgs e) { DropColorBorder.Visibility = Visibility.Hidden; NormalColorBorder.Visibility = Visibility.Visible; try { Point iconPoint = e.GetPosition(this); dropHelper?.Drop((System.Runtime.InteropServices.ComTypes.IDataObject)e.Data, ref iconPoint, e.Effects); } catch { } 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(); if (dropFile.ToLower().EndsWith("pdf") || dropFile.ToLower().EndsWith(".doc") || dropFile.ToLower().EndsWith(".docx") || dropFile.ToLower().EndsWith(".docm") || dropFile.ToLower().EndsWith(".dot") || dropFile.ToLower().EndsWith(".dotx") || dropFile.ToLower().EndsWith(".dotm")) { if (!isFirst) { DataTrackingHelper.SetSendInformation(DataTrackingHelper.EventType.Purchase_AI, DataTrackingHelper.EntryPathKeyType.Home_Tools); DataTrackingHelper.AddFirstAndSecondaryPath(DataTrackingHelper.FirstPath.Home, DataTrackingHelper.SecondaryPath.AITranslate); //权益弹窗 bool flg = false; if (!App.IsLogin || Settings.Default.UserDate.subscribestatus != 1) { DialogParameters value = new DialogParameters(); value.Add(ParameterNames.Open, "AI"); App.mainWindowViewModel.dialogs.ShowDialog(DialogNames.SubscriptionDialog, value, dialogResult => { if (dialogResult.Result == ButtonResult.OK) { flg = true; } else { flg = false; } }); if (flg == false) { return; } } isFirst = true; viewModel.ErrorTipVisible = Visibility.Collapsed; FileInfo fileInfo = new FileInfo(dropFile); //判断文件大小 if ((((float)fileInfo.Length) / 1024 / 1024) > 10) { viewModel.ErrorTipText = "The uploaded file cannot exceed 10MB"; viewModel.ErrorTipVisible = Visibility.Visible; isFirst = false; return; } //判断文件页数 if (fileInfo.Extension.ToLower() == ".pdf") { CPDFDocument cPDFDocument = CPDFDocument.InitWithFilePath(dropFile); if (cPDFDocument.PageCount > 30) { viewModel.ErrorTipText = "The uploaded file cannot exceed 30Pages"; viewModel.ErrorTipVisible = Visibility.Visible; isFirst = false; return; } } string newfile = ""; await System.Threading.Tasks.Task.Run(async delegate { newfile = await ChatGTPAIHelper.fileTranslate(dropFile, viewModel.fromlanguage, viewModel.tolanguage); }); if (!string.IsNullOrEmpty(newfile)) { if (File.Exists(newfile)) { if (viewModel.homeContentViewModel != null) { viewModel.homeContentViewModel.OpenFile(new string[] { newfile }); isFirst = false; return; } } } isFirst = false; if (newfile == "-1") { return; } viewModel.ErrorTipText = ChatGTPAIHelper.GetBaiduTranslationCode(newfile); viewModel.ErrorTipVisible = Visibility.Visible; } } } } } private void MainPage_DragEnter(object sender, DragEventArgs e) { DropColorBorder.Visibility = Visibility.Visible; NormalColorBorder.Visibility = Visibility.Hidden; //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 { } } 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 { } } private void MainPage_DragLeave(object sender, DragEventArgs e) { DropColorBorder.Visibility = Visibility.Hidden; NormalColorBorder.Visibility = Visibility.Visible; // BtnBlank.IsEnabled = true; if ((e.OriginalSource as Image) != null) return; try { dropHelper?.DragLeave(); } catch { } } } }