|
@@ -0,0 +1,131 @@
|
|
|
+using ComPDFKit.PDFDocument;
|
|
|
+using PDF_Office.Model;
|
|
|
+using PDF_Office.Model.Dialog.ToolsDialogs.SaftyDialogs;
|
|
|
+using Prism.Commands;
|
|
|
+using Prism.Mvvm;
|
|
|
+using Prism.Services.Dialogs;
|
|
|
+using System;
|
|
|
+using System.Collections.Generic;
|
|
|
+using System.Diagnostics;
|
|
|
+using System.Linq;
|
|
|
+using System.Windows.Forms;
|
|
|
+
|
|
|
+namespace PDF_Office.ViewModels.Dialog.ToolsDialogs.SaftyDialogs
|
|
|
+{
|
|
|
+
|
|
|
+ public class DeleteSafetySettingsDialogViewModel : BindableBase, IDialogAware
|
|
|
+ {
|
|
|
+
|
|
|
+ DeleteSafetySettintgsModel deleteSafetySettintgsModel;
|
|
|
+ public IDialogService dialogs;
|
|
|
+
|
|
|
+ private CPDFDocument document;
|
|
|
+
|
|
|
+ public DelegateCommand CheckPasswordCommand { get; set; }
|
|
|
+
|
|
|
+ public DeleteSafetySettingsDialogViewModel(IDialogService dialogService)
|
|
|
+ {
|
|
|
+ dialogs = dialogService;
|
|
|
+ CheckPasswordCommand = new DelegateCommand(OpenCheckPassword);
|
|
|
+ }
|
|
|
+
|
|
|
+ private DeleteSafetySettintgsModel.EnumNeedPassword CheckNeedPassword()
|
|
|
+ {
|
|
|
+ if (document.IsLocked)
|
|
|
+ {
|
|
|
+ return DeleteSafetySettintgsModel.EnumNeedPassword.VerifyPassword;
|
|
|
+ }
|
|
|
+ else { }
|
|
|
+ if (document.IsEncrypted)
|
|
|
+ {
|
|
|
+ return DeleteSafetySettintgsModel.EnumNeedPassword.VerifyPassword;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ return DeleteSafetySettintgsModel.EnumNeedPassword.CannotDecrypt;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void OpenCheckPassword()
|
|
|
+ {
|
|
|
+ FolderBrowserDialog folderDialog = new FolderBrowserDialog();
|
|
|
+ System.Windows.Forms.SaveFileDialog sfd = new System.Windows.Forms.SaveFileDialog();
|
|
|
+ /*
|
|
|
+ *设置这个对话框的起始保存路径
|
|
|
+ */
|
|
|
+ sfd.InitialDirectory = document.FilePath;
|
|
|
+ /*
|
|
|
+ *设置保存的文件的类型,注意过滤器的语法 例子:“文件类型|*.后缀名;*.后缀名;”
|
|
|
+ */
|
|
|
+ sfd.Filter = "PDF|*.pdf;";
|
|
|
+ /*
|
|
|
+ *调用ShowDialog()方法显示该对话框,该方法的返回值代表用户是否点击了确定按钮
|
|
|
+ **/
|
|
|
+ sfd.FileName = document.FileName + "_CompressFile.pdf";
|
|
|
+ /*
|
|
|
+ * 做一些工作
|
|
|
+ */
|
|
|
+ if (CheckNeedPassword() == DeleteSafetySettintgsModel.EnumNeedPassword.VerifyPassword)
|
|
|
+ {
|
|
|
+ bool IfDiscryptied = false;
|
|
|
+ DialogParameters value = new DialogParameters();
|
|
|
+ RequestClose?.Invoke(new Prism.Services.Dialogs.DialogResult(ButtonResult.OK));
|
|
|
+ dialogs.ShowDialog(DialogNames.CheckPasswordDialog, value, e => { IfDiscryptied = e.Parameters.GetValue<bool>("CheckPassword"); });
|
|
|
+
|
|
|
+ if (sfd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
|
|
|
+ {
|
|
|
+ if (IfDiscryptied)
|
|
|
+ {
|
|
|
+ document.Descrypt(sfd.FileName);
|
|
|
+ }
|
|
|
+ else { }
|
|
|
+ MessageBox.Show("保存成功");
|
|
|
+ RequestClose?.Invoke(new Prism.Services.Dialogs.DialogResult(ButtonResult.OK));
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ MessageBox.Show("取消保存");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if (CheckNeedPassword() == DeleteSafetySettintgsModel.EnumNeedPassword.DirectDescrypt)
|
|
|
+ {
|
|
|
+ if (sfd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
|
|
|
+ {
|
|
|
+ document.Descrypt(sfd.FileName);
|
|
|
+ MessageBox.Show("Ok");
|
|
|
+ RequestClose?.Invoke(new Prism.Services.Dialogs.DialogResult(ButtonResult.OK));
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ MessageBox.Show("取消保存");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else { MessageBox.Show("无可用安全性设置"); }
|
|
|
+ RequestClose?.Invoke(new Prism.Services.Dialogs.DialogResult(ButtonResult.Cancel));
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public string Title => "";
|
|
|
+
|
|
|
+ public event Action<IDialogResult> RequestClose;
|
|
|
+
|
|
|
+ public bool CanCloseDialog()
|
|
|
+ {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void OnDialogClosed()
|
|
|
+ {
|
|
|
+ }
|
|
|
+
|
|
|
+ public void OnDialogOpened(IDialogParameters parameters)
|
|
|
+ {
|
|
|
+ CPDFDocument doc = null;
|
|
|
+ parameters.TryGetValue<CPDFDocument>(ParameterNames.PDFDocument, out doc);
|
|
|
+ if (doc != null)
|
|
|
+ {
|
|
|
+ document = doc;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|