瀏覽代碼

no message

liyijie 2 年之前
父節點
當前提交
a5003e1707

+ 29 - 6
PDF Office/ViewModels/Dialog/HomePageToolsDialogs/HomePagePictureToPDFDialogViewModel.cs

@@ -27,6 +27,8 @@ namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs
         private int fileNamesIndex = 0;
         private int FileNameNumber = 0;
 
+        public IDialogService dialogs;
+
         public List<int> fileNamesView = new List<int>();
 
         public HomePagePictureToPDFDialogModel pictureToPDFModel=new HomePagePictureToPDFDialogModel();
@@ -124,8 +126,9 @@ namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs
         public DelegateCommand SelectFileCommand { get; set; }
 
         #endregion
-        public HomePagePictureToPDFDialogViewModel()
+        public HomePagePictureToPDFDialogViewModel(IDialogService dialogs)
         {
+            this.dialogs = dialogs;
             ToPDFCommand = new DelegateCommand(topdf);
             ADDPictureCommand = new DelegateCommand(addpicture);
             ADDPictureFilesCommand = new DelegateCommand(addpicturefiles);
@@ -201,14 +204,34 @@ namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs
                     Trace.WriteLine("Document==null");
                     //TODO
                     MessageBoxEx.Show("文档为空");
+                    PictureToPDFGridIsEnabled = "True";
                     return;
+
                 }
-                if (topdfdoc.IsEncrypted)
+                if (topdfdoc.IsLocked)
                 {
-                    Trace.WriteLine("youmima");
-                    MessageBoxEx.Show("文档加密");
-                    //TODO
-                    return;
+                    DialogParameters value = new DialogParameters();
+                    value.Add(ParameterNames.PDFDocument, topdfdoc);
+                    dialogs.ShowDialog(DialogNames.VerifyPassWordDialog, value, e =>
+                    {
+                        if (e.Result == ButtonResult.OK)
+                        {
+                            if (e.Parameters.ContainsKey(ParameterNames.PassWord) && e.Parameters.GetValue<string>(ParameterNames.PassWord) != null)
+                            {
+                                topdfdoc.UnlockWithPassword(e.Parameters.GetValue<string>(ParameterNames.PassWord).ToString());
+                            }
+                        }
+                    });
+
+                    if (topdfdoc.IsLocked)
+                    {
+                        //未成功解密文档时,释放Document对象,返回
+                        ImagesDataTable.Rows[fileNamesIndex]["FileState"] = "文件出错";
+                        ImagesCurrentDataTable.Rows[fileNamesIndex]["FileState"] = "文件出错";
+                        fileNamesIndex++;
+                        PictureToPDFGridIsEnabled = "True";
+                        return;
+                    }
                 }
                 int pageindex = topdfdoc.PageCount;
                 foreach (var filename in fileNames)