Browse Source

Merge branch 'dev' of http://git.kdan.cc:8865/Windows/PDFOffice_Windows_exe into dev

ZhouJieSheng 1 year ago
parent
commit
3048f2be4c
20 changed files with 431 additions and 99 deletions
  1. 13 10
      PDF Office/CustomControl/CompositeControl/ColorContent.xaml
  2. 6 5
      PDF Office/CustomControl/CompositeControl/CustomComboControl.xaml.cs
  3. 134 50
      PDF Office/Helper/ChatGTPAIHelper.cs
  4. 5 1
      PDF Office/Model/AnnotPanel/FontBoard.cs
  5. 1 1
      PDF Office/Styles/WindowsStyle.xaml
  6. 32 1
      PDF Office/ViewModels/Dialog/ChatGPTAIDialogs/DocumentaryTranslationDialogViewModel.cs
  7. 56 3
      PDF Office/ViewModels/Dialog/ChatGPTAIDialogs/SelectedTranslationDialogViewModel.cs
  8. 6 0
      PDF Office/ViewModels/Dialog/NoviceGuidDialogViewModel.cs
  9. 7 1
      PDF Office/ViewModels/Dialog/ServiceDialog/LoginRegionViewModel.cs
  10. 45 1
      PDF Office/ViewModels/HomePanel/ChatGPTAI/ChatGPTAIErrorCorrectionContentViewModel.cs
  11. 43 1
      PDF Office/ViewModels/HomePanel/ChatGPTAI/ChatGPTAIRewritingContentViewModel.cs
  12. 33 1
      PDF Office/ViewModels/HomePanel/ChatGPTAI/ChatGPTAITranslationContentViewModel.cs
  13. 1 2
      PDF Office/ViewModels/Tools/AnnotToolContentViewModel.Layout.cs
  14. 10 7
      PDF Office/ViewModels/ViewContentViewModel.cs
  15. 1 1
      PDF Office/Views/Dialog/ChatGPTAIDialogs/DocumentaryTranslationDialog.xaml
  16. 5 5
      PDF Office/Views/Dialog/ChatGPTAIDialogs/SelectedTranslationDialog.xaml
  17. 4 4
      PDF Office/Views/HomePanel/ChatGPTAI/ChatGPTAIErrorCorrectionContent.xaml
  18. 4 4
      PDF Office/Views/HomePanel/ChatGPTAI/ChatGPTAIRewritingContent.xaml
  19. 1 1
      PDF Office/Views/HomePanel/ChatGPTAI/ChatGPTAITranslationContent.xaml
  20. 24 0
      PDFSettings/UserDate.cs

+ 13 - 10
PDF Office/CustomControl/CompositeControl/ColorContent.xaml

@@ -119,25 +119,28 @@
             BorderThickness="1"
             CornerRadius="4">
 
-            <StackPanel Orientation="Horizontal" >
-                <Border x:Name="Grid_Color"   CornerRadius="4"  Margin="0,0" MouseDown="Grid_MouseDown" Width="30"
-                        Height="30"  Background="Transparent" >
-                    <Grid >
+            <StackPanel Orientation="Horizontal">
+                <Border
+                    x:Name="Grid_Color"
+                    Width="30"
+                    Height="30"
+                    Margin="0,0"
+                    Background="Transparent"
+                    CornerRadius="4"
+                    MouseDown="Grid_MouseDown">
+                    <Grid>
                         <Ellipse
                             x:Name="defaultColor"
-                            Panel.ZIndex="2"
                             Width="20"
                             Height="20"
-                            Visibility="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=local:ColorContent}, Path=DefaultColorVisibility, Mode=TwoWay}"
+                            Panel.ZIndex="2"
                             Fill="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=local:ColorContent}, Path=DefaultColor, Mode=TwoWay}"
-                            />
+                            Visibility="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=local:ColorContent}, Path=DefaultColorVisibility, Mode=TwoWay}" />
                         <Ellipse
                             x:Name="ElcustomColor"
                             Width="20"
                             Height="20"
-
-                            Fill="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=local:ColorContent}, Path=SelectedColor, Mode=OneTime, Converter={StaticResource colorBrushConvert}}"
-                            />
+                            Fill="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=local:ColorContent}, Path=SelectedColor, Mode=OneTime, Converter={StaticResource colorBrushConvert}}" />
                     </Grid>
                 </Border>
                 <cus:ColorDropBox

+ 6 - 5
PDF Office/CustomControl/CompositeControl/CustomComboControl.xaml.cs

@@ -250,8 +250,8 @@ namespace PDF_Master.CustomControl.CompositeControl
         {
             get { return (bool)GetValue(IsSelectedEmptyProperty); }
             set { SetValue(IsSelectedEmptyProperty, value); }
-        }
-
+        }
+
         public static readonly DependencyProperty IsSelectedEmptyProperty =
         DependencyProperty.Register("IsSelectedEmpty", typeof(bool), typeof(CustomComboControl), new PropertyMetadata(false, IsSelectedEmptyPropertyChanged));
 
@@ -377,13 +377,14 @@ namespace PDF_Master.CustomControl.CompositeControl
             var selectedIndex = (int)e.NewValue;
             if (control != null /*&& control.IsSelectedEmpty == false*/)
             {
-                if (control.comBox.Items != null && control.comBox.Items.Count > 0 && selectedIndex != -1)
+                //删掉了selectedIndex != -1,设置不选中任何选项的情况
+                //删掉了control.SelectedItems = null;避免崩溃
+                if (control.comBox.Items != null && control.comBox.Items.Count > 0 )
                 {
                     control.comBox.SelectedIndex = selectedIndex;
                     if (control.comBox.SelectedItem != null)
                         control.SelectedItems = (ComboDataItem)control.comBox.SelectedItem;
-                    else
-                        control.SelectedItems = null;
+                  
                 }
                 control.UpdateSelectedIndex();
             }

+ 134 - 50
PDF Office/Helper/ChatGTPAIHelper.cs

@@ -3,18 +3,21 @@ using Newtonsoft.Json.Linq;
 using PDF_Master.Properties;
 using System;
 using System.Collections.Generic;
+using System.Diagnostics;
 using System.IO;
 using System.Linq;
 using System.Net;
+using System.Net.Http;
 using System.Text;
 using System.Text.RegularExpressions;
 using System.Threading.Tasks;
+using static Dropbox.Api.Files.SearchMatchType;
 
 namespace PDF_Master.Helper
 {
     public static class ChatGTPAIHelper
     {
-        private static string host = "http://api-us-east-1.compdf.com:8082";
+        private static string host = "https://ai.compdf.com";
 
         private static string translate = "http://101.132.103.13:8030";
 
@@ -64,19 +67,97 @@ namespace PDF_Master.Helper
         /// <param name="content"></param>
         /// <param name="language">1=中文 2=英文 3=法语 4=汉语</param>
         /// <returns></returns>
-        public async static Task<string> fileKeyTranslate(string content, int language)
+        public async static Task<string> fileKeyTranslate(string content,string filename)
         {
-            System.Collections.Specialized.NameValueCollection namevalue = new System.Collections.Specialized.NameValueCollection();
-            //需要翻译的内容
-            namevalue["file"] = content;
-            //1=中文 2=英文 3=法语 4=汉语
-            namevalue["projectId"] = "2";
-            namevalue["version"] = "1.0.1";
+            
+            HttpWebResponse response = null;
+            ServicePointManager.DefaultConnectionLimit = 200;
+            HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(Uri_fileKeytranslate);
+            request.Method = "Post";
+
+            var formData = new MultipartFormDataContent();
+            byte[] data = File.ReadAllBytes(@content);
+            MemoryStream stream = new MemoryStream(data);
+            formData.Add(new ByteArrayContent(data), "file", filename);
+            formData.Add(new StringContent("2"), "projectId");
+            formData.Add(new StringContent("1.0.1"), "version");
             if (!string.IsNullOrEmpty(Settings.Default.UserDate.id))
             {
-                namevalue["userId"] = Settings.Default.UserDate.id;
+                formData.Add(new StringContent(Settings.Default.UserDate.id), "userId");
+            }
+            else
+            {
+                formData.Add(new StringContent("1"), "userId");
+            }
+
+            // 设置请求体格式
+            request.ContentType = formData.Headers.ContentType.ToString();
+            request.ContentLength = formData.Headers.ContentLength.Value;
+
+            // 将FormData写入请求体
+            using (var requestStream = request.GetRequestStream())
+            {
+              await formData.CopyToAsync(requestStream);
+            }
+            try
+            {
+                
+                // 获取HTTP响应
+                HttpWebResponse response2 = (HttpWebResponse)request.GetResponse();
+                using (StreamReader reader = new StreamReader(response2.GetResponseStream()))
+                {
+                    string responseData = reader.ReadToEnd();
+                    Console.WriteLine(responseData);
+                    reader.Close();
+                    JObject jobject = (JObject)JsonConvert.DeserializeObject(responseData);
+                    if (response2 != null)
+                    {
+                        response2.Close();
+                    }
+                    if (request != null)
+                    {
+                        request.Abort();
+                    }
+
+                    if (jobject["code"].ToObject<string>().ToLower() == "200")
+                    {
+                        translate = jobject["data"]["fileKey"].ToObject<string>().ToLower();
+                    }
+                    //return jobject["code"].ToObject<string>().ToLower();
+
+                    return translate;
+                }
+                return "";
+            }
+            catch (WebException ex)
+            {
+                Console.WriteLine("HTTP异常:" + ex.Message);
+                return "";
             }
-            return await PostString(Uri_fileKeytranslate, namevalue);
+        }
+
+        public static string HttpDownloadFile(string url, string path)
+        {
+            // 设置参数
+            HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
+            //发送请求并获取相应回应数据
+            HttpWebResponse response = request.GetResponse() as HttpWebResponse;
+            //直到request.GetResponse()程序才开始向目标网页发送Post请求
+            Stream responseStream = response.GetResponseStream();
+
+            //创建本地文件写入流
+            Stream stream = new FileStream(path, FileMode.Create);
+
+            byte[] bArr = new byte[1024];
+            int size = responseStream.Read(bArr, 0, (int)bArr.Length);
+            while (size > 0)
+            {
+                stream.Write(bArr, 0, size);
+                size = responseStream.Read(bArr, 0, (int)bArr.Length);
+            }
+            stream.Close();
+            responseStream.Close();
+            return path;
         }
 
         /// <summary>
@@ -86,9 +167,11 @@ namespace PDF_Master.Helper
         /// <param name="fromlanguage">文本语言</param>
         /// <param name="tolanguage">需要翻译的语言</param>
         /// <returns></returns>
-        public static String fileTranslate(string fileKey, string fromlanguage, string tolanguage)
+        public static async Task<string> fileTranslate(string content, string fromlanguage, string tolanguage)
         {
 
+            FileInfo file = new FileInfo(content);
+            string fileKey = await fileKeyTranslate(content, file.Name);
             HttpWebResponse response = null;
             ServicePointManager.DefaultConnectionLimit = 200;
             HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(Uri_filetranslate);
@@ -143,10 +226,28 @@ namespace PDF_Master.Helper
 
                     if (jobject["code"].ToObject<string>().ToLower() == "200")
                     {
-
+                        translate = jobject["data"]["ossDownUrl"].ToObject<string>().ToLower();
                     }
                     //return jobject["code"].ToObject<string>().ToLower();
-
+                    using (var client = new WebClient())
+                    {
+                        string folderPath = Path.Combine(App.CurrentPath, "DownloadFile");
+                        //有可能因为其他原因存在同名文件,导致创建文件夹失败,需要先删除同名文件
+                        if (File.Exists(folderPath))
+                        {
+                            File.Delete(folderPath);
+                        }
+                        DirectoryInfo tempfolder = new DirectoryInfo(folderPath);
+                        if (!tempfolder.Exists)
+                        {
+                            tempfolder.Create();
+                        }
+                        client.DownloadProgressChanged += (sender, e) =>
+                        {
+                            
+                        };
+                        client.DownloadFile(translate, folderPath+"\\" +file.Name);
+                    }
                     return "200";
                 }
             }
@@ -165,12 +266,12 @@ namespace PDF_Master.Helper
         /// <param name="fromlanguage">文本语言</param>
         /// <param name="tolanguage">需要翻译的语言</param>
         /// <returns></returns>
-        public static String textTranslate(string content, string fromlanguage, string tolanguage)
+        public static String textTranslate(string content, string fromlanguage, string tolanguage,ref string translate)
         {
 
             HttpWebResponse response = null;
             ServicePointManager.DefaultConnectionLimit = 200;
-            HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(Uri_filetranslate);
+            HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(Uri_texttranslate);
             request.Method = "Post";
             request.ContentType = "application/json";
             //request.Accept = "application/vnd.api+json;version=1";
@@ -222,7 +323,7 @@ namespace PDF_Master.Helper
 
                     if (jobject["code"].ToObject<string>().ToLower() == "200")
                     {
-
+                        translate = jobject["data"]["dst"].ToObject<string>().ToLower();
                     }
                     //return jobject["code"].ToObject<string>().ToLower();
 
@@ -236,26 +337,6 @@ namespace PDF_Master.Helper
 
         }
 
-        public async static Task<string> textTranslate(string content, int language)
-        {
-            System.Collections.Specialized.NameValueCollection namevalue = new System.Collections.Specialized.NameValueCollection();
-            //需要翻译的内容
-            namevalue["q"] = content;
-            //1=中文 2=英文 3=法语 4=汉语
-            namevalue["from"] = "auto";
-            namevalue["to"] = "en";
-            namevalue["projectId"] = "2";
-            namevalue["version"] = "1.0.1";
-            if (!string.IsNullOrEmpty(Settings.Default.UserDate.id))
-            {
-                namevalue["userId"] = Settings.Default.UserDate.id;
-            }
-            return await PostString(Uri_filetranslate, namevalue);
-        }
-
-        
-
-
         /// <summary>
         /// 纠错
         /// </summary>
@@ -265,14 +346,17 @@ namespace PDF_Master.Helper
         {
             System.Collections.Specialized.NameValueCollection namevalue = new System.Collections.Specialized.NameValueCollection();
             //需要纠错的内容
-            namevalue["project_id"] = "3";
+            namevalue["project_id"] = "2";
             namevalue["version"] = "1.0.1";
             if (!string.IsNullOrEmpty(Settings.Default.UserDate.id))
             {
                 namevalue["user_id"] = Settings.Default.UserDate.id;
             }
+            else {
+                namevalue["user_id"] = "3";
+            }
             namevalue["content"] = content;
-            return await PostString(Uri_Correction, namevalue);
+            return await PostString(Uri_Correction, namevalue, "content");
         }
 
         /// <summary>
@@ -284,14 +368,18 @@ namespace PDF_Master.Helper
         {
             System.Collections.Specialized.NameValueCollection namevalue = new System.Collections.Specialized.NameValueCollection();
             //需要纠错的内容
-            namevalue["project_id"] = "3";
+            namevalue["project_id"] = "2";
             namevalue["version"] = "1.0.1";
             if (!string.IsNullOrEmpty(Settings.Default.UserDate.id))
             {
                 namevalue["user_id"] = Settings.Default.UserDate.id;
             }
+            else
+            {
+                namevalue["user_id"] = "3";
+            }
             namevalue["content"] = content;
-            return await PostString(Uri_Rewrite, namevalue);
+            return await PostString(Uri_Rewrite, namevalue, "content");
         }
 
 
@@ -351,19 +439,15 @@ namespace PDF_Master.Helper
                     //转换成字符串类型
                     var json = Encoding.Default.GetString(bytes);
                     //将Json格式字符串转换成键值对
-                    var values = JsonConvert.DeserializeObject<Dictionary<string, string>>(json);
-
+                    //var values = JsonConvert.DeserializeObject<Dictionary<string, string>>(json);
+                    JObject jobject = (JObject)JsonConvert.DeserializeObject(json);
                     string unicode = "";
                     // 遍历字典对象输出键值对
-                    foreach (KeyValuePair<string, string> item in values)
-                    {
-                        if (item.Key == key)
-                        {
-                            unicode = item.Value;
-                        }
-                    }
+                    unicode = jobject["data"][key].ToObject<string>().ToLower();
+
                     //将Unicode格式转换成String
-                    repsonseData = Regex.Unescape(unicode);
+                    //repsonseData = Regex.Unescape(unicode);
+                    repsonseData = unicode;
                 }
             }
             catch (Exception ex)

+ 5 - 1
PDF Office/Model/AnnotPanel/FontBoard.cs

@@ -205,6 +205,9 @@ namespace PDF_Master.Model.AnnotPanel
                         case "Times New Roman":
                             FontFamilySelectedIndex = 2;
                             break;
+                        default:
+                                FontFamilySelectedIndex = -1;                            
+                            break;
                     }
                 }
                 else
@@ -215,7 +218,8 @@ namespace PDF_Master.Model.AnnotPanel
             }
         }
 
-        private int fontFamilySelectedIndex = 0;
+
+        private int fontFamilySelectedIndex = -1;
 
         public int FontFamilySelectedIndex
         {

+ 1 - 1
PDF Office/Styles/WindowsStyle.xaml

@@ -106,7 +106,7 @@
                                 HorizontalAlignment="Center"
                                 VerticalAlignment="Center"
                                 Background="Transparent"
-                                IsCancel="True" />
+                                IsCancel="True" Width="0" Height="0"/>
                             <AdornerDecorator>
                                 <ContentPresenter x:Name="win_content" />
                             </AdornerDecorator>

+ 32 - 1
PDF Office/ViewModels/Dialog/ChatGPTAIDialogs/DocumentaryTranslationDialogViewModel.cs

@@ -1,4 +1,6 @@
-using Prism.Commands;
+using Microsoft.Win32;
+using PDF_Master.Helper;
+using Prism.Commands;
 using Prism.Mvvm;
 using Prism.Services.Dialogs;
 using System;
@@ -9,16 +11,45 @@ namespace PDF_Master.ViewModels.Dialog.ChatGPTAIDialogs
 {
     public class DocumentaryTranslationDialogViewModel : BindableBase, IDialogAware
     {
+        public DelegateCommand TranslateCommand { get; set; }
         public DelegateCommand CancelCommand { get; set; }
         public DocumentaryTranslationDialogViewModel()
         {
             CancelCommand = new DelegateCommand(cancel);
+            TranslateCommand = new DelegateCommand(translate);
         }
 
         private void cancel()
         {
             RequestClose.Invoke(new DialogResult(ButtonResult.Cancel));
         }
+        public async void translate()
+        {
+            string txt = Properties.Resources.txtex;
+            string word = Properties.Resources.wordex;
+            string ppt = Properties.Resources.pptex;
+            string excel = Properties.Resources.excelex;
+            string html = Properties.Resources.htmlex;
+            string image = Properties.Resources.imageex;
+            string pdf = Properties.Resources.pdf;
+            string allfiles = pdf + txt + word + excel + ppt + image + html;
+            OpenFileDialog dialog = new OpenFileDialog();
+            //dialog.Multiselect = true;
+            dialog.Filter = string.Format($"Files({allfiles.Replace(";", ",")}|{allfiles})|" +
+           $"Pdf({pdf})|{pdf}|" +
+           $"Microsoft Office Word({word})|{word}|" +
+           $"Microsoft Office Excel({excel})|{excel}|" +
+           $"Microsoft Office PowerPoint({ppt})|{ppt}|" +
+           $"Txt({txt})|{txt}|" +
+           $"Picture({image})|{image}|" +
+           $"Html({html})|{html}");
+
+            if ((bool)dialog.ShowDialog())
+            {
+                await ChatGTPAIHelper.fileTranslate(dialog.FileName, "en", "zh");
+            }
+
+        }
 
         public string Title => "";
 

+ 56 - 3
PDF Office/ViewModels/Dialog/ChatGPTAIDialogs/SelectedTranslationDialogViewModel.cs

@@ -1,21 +1,68 @@
-using Prism.Commands;
+using ComPDFKitViewer.PdfViewer;
+using PDF_Master.Model;
+using Prism.Commands;
 using Prism.Mvvm;
 using Prism.Services.Dialogs;
+using PDF_Master.Helper;
 using System;
 using System.Collections.Generic;
 using System.Linq;
+using static System.Resources.ResXFileRef;
+using static System.Net.Mime.MediaTypeNames;
+using System.Windows.Forms;
 
 namespace PDF_Master.ViewModels.Dialog.ChatGPTAIDialogs
 {
     public class SelectedTranslationDialogViewModel : BindableBase, IDialogAware
     {
-        public SelectedTranslationDialogViewModel()
+        public string Title => "";
+
+        private string selectedText;
+
+        public string SelectedText
         {
+            get { return selectedText; }
+            set
+            {
+                SetProperty(ref selectedText, value);
+            }
+        }
 
+
+        private string translateText;
+
+        public string TranslateText
+        {
+            get { return translateText; }
+            set
+            {
+                SetProperty(ref translateText, value);
+            }
         }
 
-        public string Title => "";
+        public DelegateCommand TranslateCommand { get; set; }
+        public DelegateCommand CopyCommand { get; set; }
+        public SelectedTranslationDialogViewModel()
+        {
+            TranslateCommand = new DelegateCommand(translate);
+            CopyCommand = new DelegateCommand(copy);
+        }
+
+        public void translate()
+        {
+            string translatetext = "";
+            ChatGTPAIHelper.textTranslate(SelectedText, "en", "zh", ref translatetext);
+            TranslateText = translatetext;
+        }
+        public void copy()
+        {
+            try
+            {
+                Clipboard.SetText(TranslateText);
+            }
+            catch { }
 
+        }
         public event Action<IDialogResult> RequestClose;
 
         public bool CanCloseDialog()
@@ -29,6 +76,12 @@ namespace PDF_Master.ViewModels.Dialog.ChatGPTAIDialogs
 
         public void OnDialogOpened(IDialogParameters parameters)
         {
+            CPDFViewer pdfViewer = null;
+            parameters.TryGetValue<CPDFViewer>(ParameterNames.PDFViewer, out pdfViewer);
+            if (pdfViewer != null)
+            {
+                SelectedText = pdfViewer.GetSelectedText();
+            }
         }
     }
 }

+ 6 - 0
PDF Office/ViewModels/Dialog/NoviceGuidDialogViewModel.cs

@@ -1,5 +1,6 @@
 using PDF_Master.Model;
 using PDF_Master.Model.Dialog;
+using PDF_Master.Properties;
 using Prism.Commands;
 using Prism.Mvvm;
 using Prism.Services.Dialogs;
@@ -227,7 +228,12 @@ namespace PDF_Master.ViewModels.Dialog
         /// </summary>
         private void SignUp()
         {
+            
             RequestClose.Invoke(new DialogResult());
+            Settings.Default.UserDate.TodayRegister = true;
+            DateTime currentTime = DateTime.Now;
+            Settings.Default.UserDate.TodayRegisterTime = currentTime.ToString();
+            Settings.Default.Save();
             dialog.ShowDialog(DialogNames.RegisterDialog);
         }
 

+ 7 - 1
PDF Office/ViewModels/Dialog/ServiceDialog/LoginRegionViewModel.cs

@@ -1,6 +1,7 @@
 using PDF_Master.CustomControl;
 using PDF_Master.Helper;
 using PDF_Master.Model;
+using PDF_Master.Properties;
 using PDF_Master.Views.Dialog.ServiceDialog;
 using Prism.Commands;
 using Prism.Mvvm;
@@ -294,9 +295,14 @@ namespace PDF_Master.ViewModels.Dialog.ServiceDialog
         {
 
 
-            LoginDialogViewModel.Close();
+                LoginDialogViewModel.Close();
+                Settings.Default.UserDate.TodayRegister = true;
+                DateTime currentTime = DateTime.Now;
+                Settings.Default.UserDate.TodayRegisterTime = currentTime.ToString();
+                Settings.Default.Save();
             App.mainWindowViewModel.OpenRegister();
 
+
         }
 
         private void CheckEnableNextStepEncrypt()

+ 45 - 1
PDF Office/ViewModels/HomePanel/ChatGPTAI/ChatGPTAIErrorCorrectionContentViewModel.cs

@@ -1,16 +1,60 @@
-using Prism.Commands;
+using PDF_Master.Helper;
+using Prism.Commands;
 using Prism.Mvvm;
 using System;
 using System.Collections.Generic;
 using System.Linq;
+using System.Windows.Forms;
 
 namespace PDF_Master.ViewModels.HomePanel.ChatGPTAI
 {
     public class ChatGPTAIErrorCorrectionContentViewModel : BindableBase
     {
+
+        private string inputText;
+
+        public string InputText
+        {
+            get { return inputText; }
+            set
+            {
+                SetProperty(ref inputText, value);
+            }
+        }
+
+        private string errorCorrectionText;
+
+        public string ErrorCorrectionText
+        {
+            get { return errorCorrectionText; }
+            set
+            {
+                SetProperty(ref errorCorrectionText, value);
+            }
+        }
+
+        public DelegateCommand CopyCommand { get; set; }
+
+        public DelegateCommand ErrorCorrectionCommand { get; set; }
         public ChatGPTAIErrorCorrectionContentViewModel()
         {
+            CopyCommand = new DelegateCommand(copy);
+            ErrorCorrectionCommand = new DelegateCommand(errorCorrection);
+        }
+
+        public void copy()
+        {
+            try
+            {
+                Clipboard.SetText(ErrorCorrectionText);
+            }
+            catch { }
+
+        }
 
+        public async void errorCorrection()
+        {
+            ErrorCorrectionText = await ChatGTPAIHelper.Correction(InputText);
         }
     }
 }

+ 43 - 1
PDF Office/ViewModels/HomePanel/ChatGPTAI/ChatGPTAIRewritingContentViewModel.cs

@@ -1,16 +1,58 @@
-using Prism.Commands;
+using PDF_Master.Helper;
+using Prism.Commands;
 using Prism.Mvvm;
 using System;
 using System.Collections.Generic;
 using System.Linq;
+using System.Windows.Forms;
 
 namespace PDF_Master.ViewModels.HomePanel.ChatGPTAI
 {
     public class ChatGPTAIRewritingContentViewModel : BindableBase
     {
+
+        private string inputText;
+
+        public string InputText
+        {
+            get { return inputText; }
+            set
+            {
+                SetProperty(ref inputText, value);
+            }
+        }
+
+        private string rewriteText;
+
+        public string RewriteText
+        {
+            get { return rewriteText; }
+            set
+            {
+                SetProperty(ref rewriteText, value);
+            }
+        }
+        public DelegateCommand CopyCommand { get; set; }
+
+        public DelegateCommand RewriteCommand { get; set; }
         public ChatGPTAIRewritingContentViewModel()
         {
+            CopyCommand = new DelegateCommand(copy);
+            RewriteCommand = new DelegateCommand(rewrite);
+        }
+
+        public void copy()
+        {
+            try
+            {
+                Clipboard.SetText(RewriteText);
+            }
+            catch { }
+
+        }
 
+        public async void rewrite() {
+            RewriteText= await ChatGTPAIHelper.Rewrite(InputText);
         }
     }
 }

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

@@ -1,16 +1,48 @@
-using Prism.Commands;
+using Microsoft.Win32;
+using PDF_Master.Helper;
+using Prism.Commands;
 using Prism.Mvvm;
 using System;
 using System.Collections.Generic;
+using System.IO;
 using System.Linq;
 
 namespace PDF_Master.ViewModels.HomePanel.ChatGPTAI
 {
     public class ChatGPTAITranslationContentViewModel : BindableBase
     {
+
+        public DelegateCommand SelectFilesCommand { get; set; }
         public ChatGPTAITranslationContentViewModel()
         {
+            SelectFilesCommand = new DelegateCommand(selectFiles);
+        }
+
+        public async void selectFiles() {
+            string txt = Properties.Resources.txtex;
+            string word = Properties.Resources.wordex;
+            string ppt = Properties.Resources.pptex;
+            string excel = Properties.Resources.excelex;
+            string html = Properties.Resources.htmlex;
+            string image = Properties.Resources.imageex;
+            string pdf= Properties.Resources.pdf;
+            string allfiles = pdf+txt + word + excel + ppt + image + html;
+            OpenFileDialog dialog = new OpenFileDialog();
+            //dialog.Multiselect = true;
+            dialog.Filter = string.Format($"Files({allfiles.Replace(";", ",")}|{allfiles})|" +
+           $"Pdf({pdf})|{pdf}|" +
+           $"Microsoft Office Word({word})|{word}|" +
+           $"Microsoft Office Excel({excel})|{excel}|" +
+           $"Microsoft Office PowerPoint({ppt})|{ppt}|" +
+           $"Txt({txt})|{txt}|" +
+           $"Picture({image})|{image}|" +
+           $"Html({html})|{html}");
 
+            if ((bool)dialog.ShowDialog())
+            {
+                await ChatGTPAIHelper.fileTranslate( dialog.FileName , "en", "zh");
+            }
+                
         }
     }
 }

+ 1 - 2
PDF Office/ViewModels/Tools/AnnotToolContentViewModel.Layout.cs

@@ -493,8 +493,7 @@ namespace PDF_Master.ViewModels.Tools
 
 
         private void MenuTranslate_Click(object sender, RoutedEventArgs eventArgs)
-        {
-            string selectedText = PDFViewer.GetSelectedText();
+        {
             DialogParameters printValue = new DialogParameters();
             printValue.Add(ParameterNames.PDFViewer, PDFViewer);
             dialogs.ShowDialog(DialogNames.SelectedTranslation, printValue, e => { });

+ 10 - 7
PDF Office/ViewModels/ViewContentViewModel.cs

@@ -2343,7 +2343,8 @@ namespace PDF_Master.ViewModels
             }
 
             //付费锁
-            if (!App.IsLogin || Settings.Default.UserDate.isInFreeUseTime == false)
+            //删掉 Settings.Default.UserDate.isInFreeUseTime == false,没有试用期了;
+            if (!App.IsLogin )
             {
                 dialogs.ShowDialog(DialogNames.IAPCompareDialog);
                 return false;
@@ -2714,7 +2715,8 @@ namespace PDF_Master.ViewModels
         {
             try
             {
-                if (!App.IsLogin || Settings.Default.UserDate.isInFreeUseTime == false)
+               //删掉Settings.Default.UserDate.isInFreeUseTime == false,没有试用期策略了
+                if (!App.IsLogin)
                 {
                     dialogs.ShowDialog(DialogNames.SubscriptionDialog);
                     return false;
@@ -3285,15 +3287,16 @@ namespace PDF_Master.ViewModels
 
             //弹窗需要放到最后(确保在各字段赋值语句的后面),弹窗显示会触发控件的Loaded事件,会导致后续段没有赋值,而加载等事件继续往后跑了
             //例如这里的问题  会因为显示注册弹窗,导致其他模块没有接受到正常的PDFviewer对象
+            Settings.Default.UserDate.CheckRegisterStatus();
             App.mainWindowViewModel.OphVis = Visibility.Collapsed;
-            if (Settings.Default.IsNewInViewContent == true && App.IsLogin == false)
+            if (Settings.Default.UserDate.TodayRegister== false && App.IsLogin == false)
             {
-                App.mainWindowViewModel.OpenRegister();
-
-                Settings.Default.IsNewInViewContent = false;
+                Settings.Default.UserDate.TodayRegister = true;
+                DateTime currentTime = DateTime.Now;
+                Settings.Default.UserDate.TodayRegisterTime = currentTime.ToString();
                 Settings.Default.Save();
+                App.mainWindowViewModel.OpenRegister();
             }
-
             //需要在pdfview赋值后绑定
             GlobalCommands.FullWindowCommand.RegisterCommand(new DelegateCommand(() => { OpenFullWindow(); }));
         }

+ 1 - 1
PDF Office/Views/Dialog/ChatGPTAIDialogs/DocumentaryTranslationDialog.xaml

@@ -88,7 +88,7 @@
                     Height="32"
                     Margin="124,0"
                     HorizontalAlignment="Right"
-                    Command="{Binding ConverterCommnad}"
+                    Command="{Binding TranslateCommand}"
                     Content="{Binding T_YES}" 
                      Style="{StaticResource Btn.cta}"/>
             </Grid>

+ 5 - 5
PDF Office/Views/Dialog/ChatGPTAIDialogs/SelectedTranslationDialog.xaml

@@ -63,16 +63,16 @@
                 <StackPanel Orientation="Horizontal" Margin="0,16,0,0">
                     <StackPanel>
                         <Grid Width="250" Height="180" Margin="16,0,0,0">
-                            <TextBox Name="textBoxEnterCharacters" Width="250" Height="180" >
+                            <TextBox Name="textBoxEnterCharacters" Width="250" Height="180" Text="{Binding SelectedText}">
                             </TextBox>
-                            <TextBlock Text="{Binding ElementName=textBoxEnterCharacters,Path=Text.Length,StringFormat={}{0:/150}}" Panel.ZIndex="1" Height="22" FontSize="14" HorizontalAlignment="Right" VerticalAlignment="Bottom" Margin="0,0,12,8"/>
+                            <TextBlock Text="{Binding ElementName=textBoxEnterCharacters,Path=Text.Length,StringFormat={}{0:0/150}}" Panel.ZIndex="1" Height="22" FontSize="14" HorizontalAlignment="Right" VerticalAlignment="Bottom" Margin="0,0,12,8"/>
                         </Grid>
-                        <Button HorizontalAlignment="Right" Width="97" Height="24" Content="Translate" VerticalAlignment="Bottom" Style="{StaticResource Btn.cta}" Margin="0,8,0,0"></Button>
+                        <Button HorizontalAlignment="Right" Width="97" Height="24" Content="Translate" VerticalAlignment="Bottom" Style="{StaticResource Btn.cta}" Margin="0,8,0,0" Command="{Binding TranslateCommand}"></Button>
                     </StackPanel>
                     <StackPanel>
-                        <TextBox  Width="250" Height="180" Margin="16,0,0,0">
+                        <TextBox  Width="250" Height="180" Margin="16,0,0,0" Text="{Binding TranslateText}">
                         </TextBox>
-                        <Button HorizontalAlignment="Right" Width="97" Height="24" Content="Copy" VerticalAlignment="Bottom"  Margin="0,8,0,0"></Button>
+                        <Button HorizontalAlignment="Right" Width="97" Height="24" Content="Copy" VerticalAlignment="Bottom"  Margin="0,8,0,0" Command="{Binding CopyCommand}"></Button>
                     </StackPanel>
                 </StackPanel>
             </StackPanel>

+ 4 - 4
PDF Office/Views/HomePanel/ChatGPTAI/ChatGPTAIErrorCorrectionContent.xaml

@@ -33,10 +33,10 @@
                         TextWrapping="Wrap"
                         />
                 </StackPanel>
-                <Button HorizontalAlignment="Right" Width="104" Height="32" Content="Rewrite" VerticalAlignment="Bottom" Style="{StaticResource Btn.cta}"></Button>
+                <Button HorizontalAlignment="Right" Width="104" Height="32" Content="ErrorCorrection" VerticalAlignment="Bottom" Style="{StaticResource Btn.cta}" Command="{Binding ErrorCorrectionCommand}"></Button>
             </Grid>
             <Grid Width="968" Height="260" Margin="0,12,0,0">
-                <TextBox Name="textBoxEnterCharacters" Width="968" Height="260" >
+                <TextBox Name="textBoxEnterCharacters" Width="968" Height="260" Text="{Binding InputText}">
                 </TextBox>
                 <TextBlock Text="{Binding ElementName=textBoxEnterCharacters,Path=Text.Length,StringFormat={}{0:/150}}" Panel.ZIndex="1" Height="22" FontSize="14" HorizontalAlignment="Right" VerticalAlignment="Bottom" Margin="0,0,12,8"/>
             </Grid>
@@ -47,9 +47,9 @@
             FontSize="20"
             FontWeight="Bold"
             Foreground="{StaticResource color.sys.text.neutral.lv1}" Height="28" HorizontalAlignment="Left"></TextBlock>
-                <Button HorizontalAlignment="Right" Width="104" Height="32" Content="Copy" Background="White"></Button>
+                <Button HorizontalAlignment="Right" Width="104" Height="32" Content="Copy" Background="White" Command="{Binding CopyCommand}"></Button>
             </Grid>
-            <TextBox Width="968" Height="260" Margin="0,12,0,0">
+            <TextBox Width="968" Height="260" Margin="0,12,0,0" Text="{Binding ErrorCorrectionText}">
 
             </TextBox>
         </StackPanel>

+ 4 - 4
PDF Office/Views/HomePanel/ChatGPTAI/ChatGPTAIRewritingContent.xaml

@@ -33,10 +33,10 @@
                         TextWrapping="Wrap"
                         />
                 </StackPanel>
-                <Button HorizontalAlignment="Right" Width="104" Height="32" Content="Rewrite" VerticalAlignment="Bottom" Style="{StaticResource Btn.cta}"></Button>
+                <Button HorizontalAlignment="Right" Width="104" Height="32" Content="Rewrite" VerticalAlignment="Bottom" Style="{StaticResource Btn.cta}" Command="{Binding RewriteCommand}"></Button>
             </Grid>
             <Grid Width="968" Height="260" Margin="0,12,0,0">
-                <TextBox Name="textBoxEnterCharacters" Width="968" Height="260" >
+                <TextBox Name="textBoxEnterCharacters" Width="968" Height="260" Text="{Binding InputText}">
                 </TextBox>
                 <TextBlock Text="{Binding ElementName=textBoxEnterCharacters,Path=Text.Length,StringFormat={}{0:/150}}" Panel.ZIndex="1" Height="22" FontSize="14" HorizontalAlignment="Right" VerticalAlignment="Bottom" Margin="0,0,12,8"/>
             </Grid>
@@ -47,9 +47,9 @@
             FontSize="20"
             FontWeight="Bold"
             Foreground="{StaticResource color.sys.text.neutral.lv1}" Height="28" HorizontalAlignment="Left"></TextBlock>
-                <Button HorizontalAlignment="Right" Width="104" Height="32" Content="Copy" Background="White"></Button>
+                <Button HorizontalAlignment="Right" Width="104" Height="32" Content="Copy" Background="White" Command="{Binding CopyCommand}" ></Button>
             </Grid>
-            <TextBox Width="968" Height="260" Margin="0,12,0,0">
+            <TextBox Width="968" Height="260" Margin="0,12,0,0" Text="{Binding RewriteText}">
 
             </TextBox>
         </StackPanel>

File diff suppressed because it is too large
+ 1 - 1
PDF Office/Views/HomePanel/ChatGPTAI/ChatGPTAITranslationContent.xaml


+ 24 - 0
PDFSettings/UserDate.cs

@@ -1,5 +1,6 @@
 using System;
 using System.Collections.Generic;
+using System.Globalization;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
@@ -11,6 +12,10 @@ using System.Threading.Tasks;
     /// </summary>
     public class UserDate
     {
+
+        public bool TodayRegister { get; set; } = false;
+        public string TodayRegisterTime { get; set; } = "2023-06-01 08:00:00";
+
         public string id { get; set; }
         public string companyId { get; set; }
         public string appId { get; set; }
@@ -46,6 +51,25 @@ using System.Threading.Tasks;
         public List<string> subscriptionInfoList { get; set; }
         public string freeDate { get; set; } = "2023-06-01 08:00:00";
         public bool isInFreeUseTime { get; set; } = false;
+
+
+        public void CheckRegisterStatus()
+        {
+            DateTime currentTime = DateTime.Now;
+            DateTime thresholdTime = DateTime.Parse(TodayRegisterTime).Date.AddDays(1);
+
+
+
+
+            if (currentTime > thresholdTime)
+            {
+                TodayRegister = false;
+            }
+            else
+            {
+                TodayRegister = true;
+            }
+        }
     }