Procházet zdrojové kódy

错误提示-标识

liyijie před 1 rokem
rodič
revize
c932247e57

+ 3 - 0
PDF Office/Helper/ChatGTPAIHelper.cs

@@ -174,6 +174,7 @@ namespace PDF_Master.Helper
             App.mainWindowViewModel.MaxValue = 10;
             App.mainWindowViewModel.Value = 0;
             App.mainWindowViewModel.IsProcessVisible = System.Windows.Visibility.Visible;
+            App.mainWindowViewModel.ProcessCloseBtnVisible= System.Windows.Visibility.Collapsed;
             FileInfo file = new FileInfo(content);
             string fileKey = await fileKeyTranslate(content, file.Name);
             App.mainWindowViewModel.Value = 2;
@@ -248,6 +249,7 @@ namespace PDF_Master.Helper
                         client.DownloadFile(translate, folderPath);
                         App.mainWindowViewModel.Value = 9;
                         App.mainWindowViewModel.IsProcessVisible = System.Windows.Visibility.Collapsed;
+                        App.mainWindowViewModel.ProcessCloseBtnVisible = System.Windows.Visibility.Visible;
                         return folderPath;
                     }
                     //return "200";
@@ -256,6 +258,7 @@ namespace PDF_Master.Helper
             catch
             {
                 App.mainWindowViewModel.IsProcessVisible = System.Windows.Visibility.Collapsed;
+                App.mainWindowViewModel.ProcessCloseBtnVisible = System.Windows.Visibility.Visible;
                 return "300";
             }
 

+ 9 - 4
PDF Office/ViewModels/Dialog/ChatGPTAIDialogs/DocumentaryTranslationDialogViewModel.cs

@@ -92,10 +92,15 @@ namespace PDF_Master.ViewModels.Dialog.ChatGPTAIDialogs
         public async void translate()
         {
             string newfile = "";
-                await Task.Run(async delegate
-                {
-                    newfile = await ChatGTPAIHelper.fileTranslate(pdfViewer.Document.FilePath, fromlanguage, tolanguage);
-                });
+            FileInfo fileInfo = new FileInfo(pdfViewer.Document.FilePath);
+            if ((((float)fileInfo.Length) / 1024 / 1024) > 30)
+            {
+                return;
+            }
+            await Task.Run(async delegate
+            {
+                newfile = await ChatGTPAIHelper.fileTranslate(pdfViewer.Document.FilePath, fromlanguage, tolanguage);
+            });
             if (!string.IsNullOrEmpty(newfile))
             {
                 if (File.Exists(newfile))

+ 24 - 1
PDF Office/ViewModels/HomePanel/ChatGPTAI/ChatGPTAITranslationContentViewModel.cs

@@ -2,15 +2,18 @@
 using Microsoft.Win32;
 using PDF_Master.Helper;
 using PDF_Master.Model;
+using PDF_Master.Properties;
 using Prism.Commands;
 using Prism.Mvvm;
 using Prism.Regions;
 using System;
 using System.Collections.Generic;
+using System.Diagnostics;
 using System.IO;
 using System.Linq;
 using System.Threading.Tasks;
 using System.Windows;
+using System.Windows.Threading;
 
 namespace PDF_Master.ViewModels.HomePanel.ChatGPTAI
 {
@@ -55,6 +58,9 @@ namespace PDF_Master.ViewModels.HomePanel.ChatGPTAI
             set
             {
                 SetProperty(ref errorTipVisible, value);
+                if (value == Visibility.Visible) {
+                    dispatcherTimer.Start();
+                }
             }
         }
 
@@ -78,6 +84,8 @@ namespace PDF_Master.ViewModels.HomePanel.ChatGPTAI
         }
         public List<string> TolanguageFamily { set; get; } = new List<string>();
 
+        private DispatcherTimer dispatcherTimer = new DispatcherTimer();
+
         private void GetTolanguageOrigin()
         {
             TolanguageFamily.Clear();
@@ -87,6 +95,9 @@ namespace PDF_Master.ViewModels.HomePanel.ChatGPTAI
         public ChatGPTAITranslationContentViewModel()
         {
             SelectFilesCommand = new DelegateCommand(selectFiles);
+
+            dispatcherTimer.Interval = TimeSpan.FromSeconds(5);
+            dispatcherTimer.Tick += Dispatchertimer_Tick;
             init();
         }
 
@@ -96,6 +107,12 @@ namespace PDF_Master.ViewModels.HomePanel.ChatGPTAI
             GetTolanguageOrigin();
         }
 
+        private void Dispatchertimer_Tick(object sender, EventArgs e)
+        {
+            ErrorTipVisible = Visibility.Collapsed;
+            dispatcherTimer.Stop();
+        }
+
         public async void selectFiles()
         {
             string word = Properties.Resources.wordex;
@@ -108,6 +125,11 @@ namespace PDF_Master.ViewModels.HomePanel.ChatGPTAI
            $"Microsoft Office Word({word})|{word}");
             if ((bool)dialog.ShowDialog())
             {
+                FileInfo fileInfo = new FileInfo(dialog.FileName);
+                if ((((float)fileInfo.Length) / 1024 / 1024) > 30) {
+                    ErrorTipVisible = Visibility.Visible;
+                    return;
+                }
                 string newfile = "";
                 await Task.Run(async delegate
                 {
@@ -121,11 +143,12 @@ namespace PDF_Master.ViewModels.HomePanel.ChatGPTAI
                         if (homeContentViewModel != null)
                         {
                             homeContentViewModel.OpenFile(new string[] { newfile });
+                            return;
                         }
                     }
                 }
+                ErrorTipVisible=Visibility.Visible;
             }
-
         }
 
         public void OnNavigatedTo(NavigationContext navigationContext)

+ 27 - 12
PDF Office/Views/HomePanel/ChatGPTAI/ChatGPTAITranslationContent.xaml.cs

@@ -22,6 +22,8 @@ namespace PDF_Master.Views.HomePanel.ChatGPTAI
     public partial class ChatGPTAITranslationContent : UserControl
     {
         private ChatGPTAITranslationContentViewModel viewModel;
+
+        private bool isFirst=false;
         private IDropTargetHelper dropHelper;
         public ChatGPTAITranslationContent()
         {
@@ -51,23 +53,36 @@ namespace PDF_Master.Views.HomePanel.ChatGPTAI
                     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")) 
                     {
-                        string newfile = "";
-                        await Task.Run(async delegate
-                        {
-                            newfile = await ChatGTPAIHelper.fileTranslate(dropFile, viewModel.fromlanguage, viewModel.tolanguage);
-                        });
-                        if (!string.IsNullOrEmpty(newfile))
+                        if (!isFirst)
                         {
-                            if (File.Exists(newfile))
+                            isFirst = true;
+                            FileInfo fileInfo = new FileInfo(dropFile);
+                            if ((((float)fileInfo.Length) / 1024 / 1024) > 30)
+                            {
+                                viewModel.ErrorTipVisible = Visibility.Visible;
+                                isFirst = false;
+                                return;
+                            }
+                            string newfile = "";
+                            await Task.Run(async delegate
+                            {
+                                newfile = await ChatGTPAIHelper.fileTranslate(dropFile, viewModel.fromlanguage, viewModel.tolanguage);
+                            });
+                            if (!string.IsNullOrEmpty(newfile))
                             {
-                                if (viewModel.homeContentViewModel != null)
-                                { 
-                                    viewModel.homeContentViewModel.OpenFile(new string[] { newfile }); 
-                                
+                                if (File.Exists(newfile))
+                                {
+                                    if (viewModel.homeContentViewModel != null)
+                                    {
+                                        viewModel.homeContentViewModel.OpenFile(new string[] { newfile });
+                                        isFirst = false;
+                                        return;
+                                    }
                                 }
                             }
+                            isFirst = false;
+                            viewModel.ErrorTipVisible = Visibility.Visible;
                         }
-                                    
                     }
                 }
             }