123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216 |
- using ComPDFKit.PDFDocument;
- using PDF_Master.CustomControl;
- using PDF_Master.Helper;
- using PDF_Master.Model;
- using PDF_Master.Model.Dialog.ToolsDialogs.SaftyDialogs;
- using PDF_Master.Properties;
- using Prism.Commands;
- using Prism.Mvvm;
- using Prism.Services.Dialogs;
- using System;
- using System.Windows;
- using System.Windows.Forms;
- using static PDF_Master.Model.Dialog.ToolsDialogs.SaftyDialogs.DeleteSafetySettintgsModel;
- using static PDF_Master.Model.Dialog.ToolsDialogs.SaftyDialogs.SetPasswordDialogModel;
- namespace PDF_Master.ViewModels.Dialog.ToolsDialogs.SaftyDialogs
- {
- public class DeleteSafetySettingsDialogViewModel : BindableBase, IDialogAware
- {
- #region 文案
- private string T_yes;
- public string T_YES
- {
- get { return T_yes; }
- set
- {
- SetProperty(ref T_yes, value);
- }
- }
- private string T_no;
- public string T_No
- {
- get { return T_no; }
- set
- {
- SetProperty(ref T_no, value);
- }
- }
- private ViewContentViewModel viewContentViewModel;
- private void InitString()
- {
- T_YES = App.MainPageLoader.GetString("RemovePassword_YES");
- T_No = App.MainPageLoader.GetString("RemovePassword_No");
- }
- #endregion
- #region 参数和属性
- 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)
- {
- InitString();
- 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 DeleteSafetySettintgsModel.EnumNeedPassword.StatusCannotDecrypt;
- }
- }
- #endregion
- #region 逻辑函数
- ///// <summary>
- ///// 逻辑优化:判权操作放到密码弹窗里,所以一旦进入该状态,可以直接清除权限
- ///// </summary>
- //public void RemoveSecuritySettings()
- //{
- // //付费锁
- // //if (!App.IsLogin)
- // //{
- // // dialogs.ShowDialog(DialogNames.IAPCompareDialog);
- // // return;
- // //}
- // 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("取消保存");
- // }
- //}
- /// <summary>
- /// 去除安全性设置2.0
- /// </summary>
- public void RemoveSecuritySettings()
- {
- viewContentViewModel.SecurityInfo.NeedOpenPassword = false;
- viewContentViewModel.SecurityInfo.NeedPermissionsPassword = false;
- viewContentViewModel.SecurityInfo.OpenPassword = string.Empty;
- viewContentViewModel.SecurityInfo.PermissionsPassword = string.Empty;
- viewContentViewModel.SecurityInfo.CPDFPermissionsInfo = CreateDefaultPermissionsInfo();
- viewContentViewModel.SecurityInfo.IsPasswordRemoved = true;
- viewContentViewModel.SecurityInfo.IsPasswordChanged = false;
- RequestClose?.Invoke(new Prism.Services.Dialogs.DialogResult(ButtonResult.OK));
- }
- 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);
- parameters.TryGetValue<ViewContentViewModel>(ParameterNames.ViewContentViewModel, out viewContentViewModel);
- if (doc != null)
- {
- document = doc;
- string info = App.MainPageLoader.GetString("RemovePassword_Context");
- string mas = string.Format(info, document.FileName);
- DeleteSecurityMsg = mas;
- }
- }
- #endregion
- }
- }
|