123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154 |
- using ComPDFKit.PDFDocument;
- using PDF_Office.CustomControl;
- using PDF_Office.Helper;
- 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.Windows.Forms;
- using static PDF_Office.Model.Dialog.ToolsDialogs.SaftyDialogs.DeleteSafetySettintgsModel;
- namespace PDF_Office.ViewModels.Dialog.ToolsDialogs.SaftyDialogs
- {
- public class DeleteSafetySettingsDialogViewModel : BindableBase, IDialogAware
- {
- #region 参数和属性
- DeleteSafetySettintgsModel deleteSafetySettintgsModel;
- public IDialogService dialogs;
- private CPDFDocument document;
- private string _deleteSecurityMsg;
- public string DeleteSecurityMsg
- {
- get { return _deleteSecurityMsg; }
- set { SetProperty(ref _deleteSecurityMsg, value); }
- }
- #endregion
- #region 委托声明
- public DelegateCommand CancelCommand { get; set; }
- public DelegateCommand RemoveSecuritySettingsCommand { get; set; }
- #endregion
- public DeleteSafetySettingsDialogViewModel(IDialogService dialogService)
- {
- dialogs = dialogService;
- RemoveSecuritySettingsCommand = new DelegateCommand(RemoveSecuritySettings);
- CancelCommand = new DelegateCommand(Cancel);
- }
- #region 检查函数
- /// <summary>
- /// 检测是否需要输入密码
- /// </summary>
- /// <returns>
- /// EnumNeedPassword.Status
- ///
- ///
- ///
- /// :需要确认密码;
- /// EnumNeedPassword.StatusDirectDescrypt:直接执行操作
- /// EnumNeedPassword.StatusCannotDecrypt:无可执行操作。
- /// </returns>
- private DeleteSafetySettintgsModel.EnumNeedPassword CheckNeedPassword()
- {
- try
- {
- if (document.IsLocked)
- {
- return DeleteSafetySettintgsModel.EnumNeedPassword.StatusVerifyPassword;
- }
- else
- {
- if (SecurityHelper.CheckHaveAllPermissions(document))
- {
- return DeleteSafetySettintgsModel.EnumNeedPassword.StatusDirectDescrypt;
- }
- else
- {
- return DeleteSafetySettintgsModel.EnumNeedPassword.StatusVerifyPassword;
- }
- }
- }
- catch
- {
- return EnumNeedPassword.StatusCannotDecrypt;
- }
- }
- #endregion
- #region 逻辑函数
- /// <summary>
- /// 逻辑优化:判权操作放到密码弹窗里,所以一旦进入该状态,可以直接清除权限
- /// </summary>
- public void RemoveSecuritySettings()
- {
- System.Windows.Forms.SaveFileDialog sfd = new System.Windows.Forms.SaveFileDialog();
- /*
- *设置这个对话框的起始保存路径
- */
- sfd.InitialDirectory = document.FilePath;
- /*
- *设置保存的文件的类型,注意过滤器的语法 例子:“文件类型|*.后缀名;*.后缀名;”
- */
- sfd.Filter = "PDF|*.pdf;";
- /*
- *调用ShowDialog()方法显示该对话框,该方法的返回值代表用户是否点击了确定按钮
- */
- sfd.FileName = document.FileName + "_DecryptedFile.pdf";
- /*
- * 做一些工作
- */
- if (sfd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
- {
- if(document.Descrypt(sfd.FileName)){
- MessageBoxEx.Show("保存成功");
- RequestClose?.Invoke(new Prism.Services.Dialogs.DialogResult(ButtonResult.OK));
- }
- else
- {
- ///TODO 不明原因干扰
- }
- }
- else
- {
- MessageBox.Show("取消保存");
- }
- }
-
- private void Cancel()
- {
- RequestClose?.Invoke(new Prism.Services.Dialogs.DialogResult(ButtonResult.Cancel));
- }
- #endregion
- #region 框架相关
- 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;
- DeleteSecurityMsg = "Are you sure you want to remove the security settings for”" + document.FileName + "” documents?";
- }
- }
- #endregion
- }
- }
|