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 检查函数 /// /// 检测是否需要输入密码 /// /// /// EnumNeedPassword.Status /// /// /// /// :需要确认密码; /// EnumNeedPassword.StatusDirectDescrypt:直接执行操作 /// EnumNeedPassword.StatusCannotDecrypt:无可执行操作。 /// 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 逻辑函数 ///// ///// 逻辑优化:判权操作放到密码弹窗里,所以一旦进入该状态,可以直接清除权限 ///// //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("取消保存"); // } //} /// /// 去除安全性设置2.0 /// 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 RequestClose; public bool CanCloseDialog() { return true; } public void OnDialogClosed() { } public void OnDialogOpened(IDialogParameters parameters) { CPDFDocument doc = null; parameters.TryGetValue(ParameterNames.PDFDocument, out doc); parameters.TryGetValue(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 } }