liyijie 2 years ago
parent
commit
13d7a42e41

+ 2 - 0
PDF Office/Model/Dialog/HomePageToolsDialogs/HomePageBatchProcessing/HomePageBatchProcessingDialogModel.cs

@@ -10,6 +10,8 @@ namespace PDF_Office.Model.Dialog.HomePageToolsDialogs.HomePageBatchProcessing
     {
         public static int BatchProcessingIndex = 0;
 
+        public static bool closeDialog = false;
+
         public static List<string> FilePaths=new List<string>();
 
         public static List<string> GetBatchProcessing = new List<string> { "HomePageConverterDialog", "HomePageCompressDialog", "HomePageSetPasswordDialog", "HomePageWatermarkDialog", "HomePageBackgroundDialog", "HomePageHeaderFooterDialog", "HomePageBatesDialog", "HomePageRemoveDialog" };

+ 7 - 5
PDF Office/ViewModels/Dialog/HomePageToolsDialogs/HomePageBatchProcessing/HomePageBackground/HomePageBackgroundDialogViewModel.cs

@@ -248,7 +248,7 @@ namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs.HomePageBatchProcess
             PDFDataTable.Columns.Add("MaxPageRange");
             PDFDataTable.Columns.Add("FileSize");
             PDFDataTable.Columns.Add("FileState");
-            Unicode = Guid.NewGuid().ToString() ;
+            Unicode = Guid.NewGuid().ToString();
             BackgroundSettingsVisible = Visibility.Visible;
             ADDPDFCommand = new DelegateCommand(addpicture);
             ADDOpenedPDFCommand = new DelegateCommand(addOpenedPDFFiles);
@@ -260,7 +260,7 @@ namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs.HomePageBatchProcess
             eventAggregator.GetEvent<SetCurrentCreateModEvent>().Subscribe(SetCurrentCreateMod, e => e.Unicode == Unicode);
             eventAggregator.GetEvent<SetCurrentTemplateListModEvent>().Subscribe(SetCurrentTemplateListMod, e => e.Unicode == Unicode);
             eventAggregator.GetEvent<EditBackgroundTemplateItemEvent>().Subscribe(EditBackgroundTemplateItem, e => e.Unicode == Unicode);
-            
+
         }
         #region 逻辑函数
         public void EnterTemplateListOrCreate(EnumTemplateListOrCreateUnicode enumTemplateListOrCreateunicode)
@@ -339,6 +339,7 @@ namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs.HomePageBatchProcess
 
         private void create()
         {
+            HomePageBatchProcessingDialogModel.closeDialog = true;
             updateListview("wait");
             fileNamesIndex = 0;
             BackgroundGridIsEnabled = "False";
@@ -396,6 +397,7 @@ namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs.HomePageBatchProcess
                 fileNamesIndex++;
             }
             BackgroundGridIsEnabled = "True";
+            HomePageBatchProcessingDialogModel.closeDialog = false;
         }
 
         public void CreateBackground(CPDFDocument document)
@@ -559,7 +561,7 @@ namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs.HomePageBatchProcess
                 {
                     PDFCurrentDataTable.Rows[datatableindex]["FilePageRangeSelectIndex"] = "0";
                 }
-                pdfdatatable.Rows.Add(f.Name, PDFCurrentDataTable.Rows[datatableindex]["FilePageRangeText"], PDFCurrentDataTable.Rows[datatableindex]["FilePageRangeSelectIndex"], isEvenPage(fileName), pagecount, file_size, PDFCurrentDataTable.Rows[datatableindex]["FileState"]); 
+                pdfdatatable.Rows.Add(f.Name, PDFCurrentDataTable.Rows[datatableindex]["FilePageRangeText"], PDFCurrentDataTable.Rows[datatableindex]["FilePageRangeSelectIndex"], isEvenPage(fileName), pagecount, file_size, PDFCurrentDataTable.Rows[datatableindex]["FileState"]);
                 datatableindex++;
             }
             PDFDataTable = pdfdatatable;
@@ -571,7 +573,7 @@ namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs.HomePageBatchProcess
         /// 更新Currentlistview显示
         /// pagerangetext 自定义页面范围字符串  pagerangeselectindex combobox下拉索引(0全部页面 1奇数页 2偶数页 3自定义页面)isevenpageisenabled 偶数页状态 state 状态显示字符串
         /// </summary>
-        public void updateCurrentListview(string pagerangetext = "1", string pagerangeselectindex = "0",bool isevenpageisenabled=true,string state = "wait")
+        public void updateCurrentListview(string pagerangetext = "1", string pagerangeselectindex = "0", bool isevenpageisenabled = true, string state = "wait")
         {
             if (fileNames.Count >= FileNameNumber)
             {
@@ -622,7 +624,7 @@ namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs.HomePageBatchProcess
         /// </summary>
         public bool isEvenPage(string filename)
         {
-            CPDFDocument document= CPDFDocument.InitWithFilePath(filename);
+            CPDFDocument document = CPDFDocument.InitWithFilePath(filename);
             bool isevenpage = false;
             if (document.PageCount > 1)
             {

+ 21 - 1
PDF Office/ViewModels/Dialog/HomePageToolsDialogs/HomePageBatchProcessing/HomePageBatchProcessingDialogViewModel.cs

@@ -1,5 +1,7 @@
 using ComPDFKitViewer.PdfViewer;
 using Microsoft.Office.Interop.Word;
+using PDF_Office.CustomControl;
+using PDF_Office.EventAggregators;
 using PDF_Office.Model;
 using PDF_Office.Model.Dialog.HomePageToolsDialogs.HomePageBatchProcessing;
 using Prism.Commands;
@@ -76,12 +78,30 @@ namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs.HomePageBatchProcess
 
         public bool CanCloseDialog()
         {
+            AlertsMessage alertsMessage = new AlertsMessage();
+            if (HomePageBatchProcessingDialogModel.closeDialog)
+            {
+                alertsMessage.ShowDialog("批量处理操作被中断,已完成的文件不受影响,是否确定要关闭弹窗", "", "取消", "确定");
+                if (alertsMessage.result == ContentResult.Ok)
+                {
+                    return true;
+                }
+                else
+                {
+                    //this.eventAggregator.GetEvent<DeleteWatermarkEvent>().Publish(new EnumDeleteUnicode
+                    //{
+                    //    Unicode = Unicode,
+                    //    Status = EnumDelete.StatusCreate
+                    //});
+                    return false;
+                }
+            }
             return true;
         }
 
         public void OnDialogClosed()
         {
-
+            
         }
 
         public void OnDialogOpened(IDialogParameters parameters)

+ 2 - 0
PDF Office/ViewModels/Dialog/HomePageToolsDialogs/HomePageBatchProcessing/HomePageBates/HomePageBatesDialogViewModel.cs

@@ -278,6 +278,7 @@ namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs.HomePageBatchProcess
 
         private void create()
         {
+            HomePageBatchProcessingDialogModel.closeDialog = true;
             updateListview("wait");
             fileNamesIndex = 0;
             BatesGridIsEnabled = "False";
@@ -335,6 +336,7 @@ namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs.HomePageBatchProcess
                 fileNamesIndex++;
             }
             BatesGridIsEnabled = "True";
+            HomePageBatchProcessingDialogModel.closeDialog = false ;
         }
 
         public void CreateBates(CPDFDocument document)

+ 2 - 0
PDF Office/ViewModels/Dialog/HomePageToolsDialogs/HomePageBatchProcessing/HomePageCompressDialogViewModel.cs

@@ -182,6 +182,7 @@ namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs.HomePageBatchProcess
         }
 
         private async void compress() {
+            HomePageBatchProcessingDialogModel.closeDialog = true;
             CompressGridIsEnabled = "False";
             //GC.KeepAlive(indexDelegate);
             fileNamesIndex = 0;
@@ -231,6 +232,7 @@ namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs.HomePageBatchProcess
                 document.Release();
             }
             CompressGridIsEnabled = "True";
+            HomePageBatchProcessingDialogModel.closeDialog = false;
         }
         #endregion
 

+ 22 - 0
PDF Office/ViewModels/Dialog/HomePageToolsDialogs/HomePageBatchProcessing/HomePageConverter/HomePageConverterDialogViewModel.cs

@@ -178,6 +178,8 @@ namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs.HomePageBatchProcess
         #region 委托声明
         public DelegateCommand ADDPDFCommand { get; set; }
 
+        public DelegateCommand ADDOpenedPDFCommand { get; set; }
+
         public DelegateCommand RemovePDFFileCommand { get; set; }
 
         public DelegateCommand ConvertCommand { get; set; }
@@ -202,6 +204,7 @@ namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs.HomePageBatchProcess
             PDFDataTable.Columns.Add("FileSize");
             PDFDataTable.Columns.Add("FileState");
             ADDPDFCommand = new DelegateCommand(addpicture);
+            ADDOpenedPDFCommand = new DelegateCommand(addOpenedPDFFiles);
             ADDPDFFilesCommand = new DelegateCommand(addpicturefiles);
             RemovePDFFileCommand = new DelegateCommand(removepdffile);
             ConvertCommand = new DelegateCommand(convert);
@@ -218,6 +221,7 @@ namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs.HomePageBatchProcess
 
         private async void convert()
         {
+            HomePageBatchProcessingDialogModel.closeDialog = true;
             updateListview("wait");
             bool result = false;
             OnProgress GetProgress = null;
@@ -358,6 +362,7 @@ namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs.HomePageBatchProcess
                 fileNamesIndex++;
             }
             ConverterGridIsEnabled = "True";
+            HomePageBatchProcessingDialogModel.closeDialog = true;
         }
         #endregion
 
@@ -391,6 +396,22 @@ namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs.HomePageBatchProcess
             updateListview("wait");
         }
 
+        /// <summary>
+        /// 添加已打开PDF文件
+        /// </summary>
+        public void addOpenedPDFFiles()
+        {
+            FileNameNumber = fileNames.Count;
+            foreach (var filename in App.OpenedFileList)
+            {
+                fileNames.Add(filename);
+            }
+            RemoveExcess(ref fileNames);
+            SetConverterGridIsEnabled = "True";
+            AddFileVisibility = Visibility.Collapsed;
+            updateListview("wait");
+        }
+
         /// <summary>
         /// 删除重复的文件
         /// </summary>
@@ -442,6 +463,7 @@ namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs.HomePageBatchProcess
         /// </summary>
         public void updateListview(string state)
         {
+           
             updateCurrentListview();
             DataTable pdfdatatable = new DataTable();
             pdfdatatable.Columns.Add("FileName");

+ 2 - 0
PDF Office/ViewModels/Dialog/HomePageToolsDialogs/HomePageBatchProcessing/HomePageHeaderFooter/HomePageHeaderFooterDialogViewModel.cs

@@ -284,6 +284,7 @@ namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs.HomePageBatchProcess
 
         private  void create()
         {
+            HomePageBatchProcessingDialogModel.closeDialog = true;
             updateListview("wait");
             fileNamesIndex = 0;
             HeaderFooterGridIsEnabled = "False";
@@ -341,6 +342,7 @@ namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs.HomePageBatchProcess
                 fileNamesIndex++;
             }
             HeaderFooterGridIsEnabled = "True";
+            HomePageBatchProcessingDialogModel.closeDialog = false;
         }
 
         public void CreateHeaderFooter(CPDFDocument document)

+ 3 - 0
PDF Office/ViewModels/Dialog/HomePageToolsDialogs/HomePageBatchProcessing/HomePageRemoveDialogViewModel.cs

@@ -241,6 +241,7 @@ namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs.HomePageBatchProcess
 
         private void OptionsRemove()
         {
+
             if (!(WatermarkIsRemove || BackgroundIsRemove || HeaderFooterIsRemove || BatesIsRemove || SecurityIsRemove)) {
                 MessageBoxEx.Show("没选");
                 return;
@@ -249,6 +250,7 @@ namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs.HomePageBatchProcess
             OptionsRemoveGridIsEnabled = "False";
             //GC.KeepAlive(indexDelegate);
             fileNamesIndex = 0;
+            HomePageBatchProcessingDialogModel.closeDialog = true;
             foreach (var filename in fileNames)
             {
                 PDFDataTable.Rows[fileNamesIndex]["FileState"] = "wait";
@@ -318,6 +320,7 @@ namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs.HomePageBatchProcess
                 document.Release();
             }
             OptionsRemoveGridIsEnabled = "True";
+            HomePageBatchProcessingDialogModel.closeDialog = false;
         }
         #endregion
 

+ 31 - 7
PDF Office/ViewModels/Dialog/HomePageToolsDialogs/HomePageBatchProcessing/HomePageSetPasswordDialogViewModel.cs

@@ -21,6 +21,8 @@ namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs.HomePageBatchProcess
         #region 参数和属性
         private List<string> fileNames;
 
+        public IDialogService dialogs;
+
         private int fileNamesIndex = 0;
 
         private int FileNameNumber = 0;
@@ -195,7 +197,7 @@ namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs.HomePageBatchProcess
         public DelegateCommand ADDPDFFilesCommand { get; set; }
         #endregion
 
-        public HomePageSetPasswordDialogViewModel()
+        public HomePageSetPasswordDialogViewModel(IDialogService dialogs)
         {
             PDFCurrentDataTable.Columns.Add("FileState");
             PDFDataTable.Columns.Add("FileName");
@@ -212,6 +214,7 @@ namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs.HomePageBatchProcess
             ADDOpenedPDFCommand = new DelegateCommand(addOpenedPDFFiles);
             ADDPDFFilesCommand = new DelegateCommand(addpdffiles);
             RemovePDFFileCommand = new DelegateCommand(removepdffile);
+            this.dialogs = dialogs;
         }
 
         #region 检查和初始化
@@ -274,6 +277,7 @@ namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs.HomePageBatchProcess
 
         public void ConfirmEncrypt()
         {
+            HomePageBatchProcessingDialogModel.closeDialog = true;
             SafetyGridIsEnabled = "False";
             string openPassword = "";
             string editPassword = "";
@@ -301,28 +305,48 @@ namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs.HomePageBatchProcess
             {
                 PDFDataTable.Rows[fileNamesIndex]["FileState"] = "wait";
                 CPDFDocument document = CPDFDocument.InitWithFilePath(filename);
-                if (document == null || document.IsEncrypted)
+                if(document == null)
                 {
                     PDFDataTable.Rows[fileNamesIndex]["FileState"] = "error";
                     PDFCurrentDataTable.Rows[fileNamesIndex]["FileState"] = "error";
                     fileNamesIndex++;
                     continue;
                 }
-                FileInfo fileinfo = new FileInfo(filename);
-                string file_size = (((float)fileinfo.Length) / 1024).ToString() + " K";
-                if (document == null)
+                if (document.IsLocked)
                 {
-                    return;
+                    DialogParameters value = new DialogParameters();
+                    value.Add(ParameterNames.PDFDocument, document);
+                    dialogs.ShowDialog(DialogNames.VerifyPassWordDialog, value, e =>
+                    {
+                        if (e.Result == ButtonResult.OK)
+                        {
+                            if (e.Parameters.ContainsKey(ParameterNames.PassWord) && e.Parameters.GetValue<string>(ParameterNames.PassWord) != null)
+                            {
+                                document.UnlockWithPassword(e.Parameters.GetValue<string>(ParameterNames.PassWord).ToString());
+                            }
+                        }
+                    });
+
+                    if (document.IsLocked)
+                    {
+                        //未成功解密文档时,释放Document对象,返回
+                        PDFDataTable.Rows[fileNamesIndex]["FileState"] = "error";
+                        PDFCurrentDataTable.Rows[fileNamesIndex]["FileState"] = "error";
+                        fileNamesIndex++;
+                        continue;
+                    }
                 }
+                //FileInfo fileinfo = new FileInfo(filename);
+                //string file_size = (((float)fileinfo.Length) / 1024).ToString() + " K";
                 document.Encrypt(openPassword, editPassword, permissionsInfo);
                 document.WriteToFilePath(filename + "SetPassword");
-
                 PDFDataTable.Rows[fileNamesIndex]["FileState"] = "complete";
                 PDFCurrentDataTable.Rows[fileNamesIndex]["FileState"] = "complete";
                 fileNamesIndex++;
                 document.Release();
             }
             SafetyGridIsEnabled = "True";
+            HomePageBatchProcessingDialogModel.closeDialog = false;
         }
         #endregion
 

+ 2 - 0
PDF Office/ViewModels/Dialog/HomePageToolsDialogs/HomePageBatchProcessing/HomePageWatermark/HomePageWatermarkDialogViewModel.cs

@@ -341,6 +341,7 @@ namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs.HomePageBatchProcess
 
         private void create()
         {
+            HomePageBatchProcessingDialogModel.closeDialog = true;
             updateListview("wait");
             fileNamesIndex = 0;
             WatermarkGridIsEnabled = "False";
@@ -398,6 +399,7 @@ namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs.HomePageBatchProcess
                 fileNamesIndex++;
             }
             WatermarkGridIsEnabled = "True";
+            HomePageBatchProcessingDialogModel.closeDialog = false;
         }
 
         public void CreateWatermark(CPDFDocument document)