|
@@ -18,20 +18,12 @@ namespace PDF_Office.ViewModels.Dialog.ToolsDialogs.SaftyDialogs
|
|
|
{
|
|
|
public class SetPasswordDialogViewModel : BindableBase, IDialogAware
|
|
|
{
|
|
|
+ #region 参数和属性
|
|
|
private SetPasswordDialogModel setPasswordDialogModel = new SetPasswordDialogModel();
|
|
|
-
|
|
|
private CPDFDocument document;
|
|
|
|
|
|
- public DelegateCommand DelegateSetOpenCommand { get; set; }
|
|
|
- public DelegateCommand DelegateSetEditCommand { get; set; }
|
|
|
- public DelegateCommand DelegateCanOpenTextChangedCommand { get; set; }
|
|
|
- public DelegateCommand DelegateCanEditTextChangedCommand { get; set; }
|
|
|
- public DelegateCommand DelegateConfirmEncryptCommand { get; set; }
|
|
|
- public DelegateCommand DelegateCancelEncryptCommand { get; set; }
|
|
|
- public DelegateCommand InputPasswordCommand { get; set; }
|
|
|
-
|
|
|
private bool _canOpen;
|
|
|
- public bool CanOpen
|
|
|
+ public bool CanOpen
|
|
|
{
|
|
|
get { return _canOpen; }
|
|
|
set
|
|
@@ -52,7 +44,14 @@ namespace PDF_Office.ViewModels.Dialog.ToolsDialogs.SaftyDialogs
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private string _changeMod="0";
|
|
|
+ private string _changeMod = "0";
|
|
|
+ ///<value>
|
|
|
+ ///"0"为ChangeMod.None;
|
|
|
+ ///"1"为ChangeMod.ChangePage;
|
|
|
+ ///"2"为ChangeMod.FormAndSignature;
|
|
|
+ ///"3"为ChangeMod.AnnotAndFormAndSignature;
|
|
|
+ ///"4"为ChangeMod.ExceptAbstrat;
|
|
|
+ ///</value>
|
|
|
public string ChangeMod
|
|
|
{
|
|
|
get { return _changeMod; }
|
|
@@ -62,7 +61,12 @@ namespace PDF_Office.ViewModels.Dialog.ToolsDialogs.SaftyDialogs
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private string _printMod="0";
|
|
|
+ private string _printMod = "0";
|
|
|
+ ///<value>
|
|
|
+ ///"0"为PrintMod.None;
|
|
|
+ ///"1"为PrintMod.LowDpi;
|
|
|
+ ///"2"为PrintMod.HighDpi;
|
|
|
+ ///</value>
|
|
|
public string PrintMod
|
|
|
{
|
|
|
get { return _printMod; }
|
|
@@ -81,12 +85,21 @@ namespace PDF_Office.ViewModels.Dialog.ToolsDialogs.SaftyDialogs
|
|
|
SetProperty(ref _isEnableConfirm, value);
|
|
|
}
|
|
|
}
|
|
|
+ #endregion
|
|
|
|
|
|
+ #region 委托声明
|
|
|
+ public DelegateCommand DelegateSetOpenCommand { get; set; }
|
|
|
+ public DelegateCommand DelegateSetEditCommand { get; set; }
|
|
|
+ public DelegateCommand DelegateCanOpenTextChangedCommand { get; set; }
|
|
|
+ public DelegateCommand DelegateCanEditTextChangedCommand { get; set; }
|
|
|
+ public DelegateCommand DelegateConfirmEncryptCommand { get; set; }
|
|
|
+ public DelegateCommand DelegateCancelEncryptCommand { get; set; }
|
|
|
+ #endregion
|
|
|
|
|
|
public SetPasswordDialogViewModel()
|
|
|
{
|
|
|
- SetPasswordDialogModel.CanOpenPassword = "";
|
|
|
- SetPasswordDialogModel.CanEditPassword = "";
|
|
|
+ SetPasswordDialogModel.PasswordForOpen = "";
|
|
|
+ SetPasswordDialogModel.PasswordForEdit = "";
|
|
|
DelegateConfirmEncryptCommand = new DelegateCommand(ConfirmEncrypt);
|
|
|
DelegateCancelEncryptCommand = new DelegateCommand(CancelEncrypt);
|
|
|
DelegateSetOpenCommand = new DelegateCommand(SetCanOpen);
|
|
@@ -95,11 +108,12 @@ namespace PDF_Office.ViewModels.Dialog.ToolsDialogs.SaftyDialogs
|
|
|
DelegateCanEditTextChangedCommand = new DelegateCommand(CanEditTextChanged);
|
|
|
}
|
|
|
|
|
|
+ #region 检查和初始化
|
|
|
private void CheckCanConfirmEncrypt()
|
|
|
{
|
|
|
if (setPasswordDialogModel.CanOpen)
|
|
|
{
|
|
|
- if (SetPasswordDialogModel.CanOpenPassword.Length > 0)
|
|
|
+ if (SetPasswordDialogModel.PasswordForOpen.Length > 0)
|
|
|
{
|
|
|
IsEnabledConfirm = "True";
|
|
|
return;
|
|
@@ -107,7 +121,7 @@ namespace PDF_Office.ViewModels.Dialog.ToolsDialogs.SaftyDialogs
|
|
|
}
|
|
|
if (setPasswordDialogModel.CanEdit)
|
|
|
{
|
|
|
- if (SetPasswordDialogModel.CanEditPassword.Length > 0)
|
|
|
+ if (SetPasswordDialogModel.PasswordForEdit.Length > 0)
|
|
|
{
|
|
|
IsEnabledConfirm = "True";
|
|
|
return;
|
|
@@ -116,6 +130,21 @@ namespace PDF_Office.ViewModels.Dialog.ToolsDialogs.SaftyDialogs
|
|
|
IsEnabledConfirm = "False";
|
|
|
}
|
|
|
|
|
|
+ private void InitPermissionsDictionary(ref Dictionary<string, SetPasswordDialogModel.PrintMod> GetPrintMod, ref Dictionary<string, SetPasswordDialogModel.ChangeMod> GetChangeMod)
|
|
|
+ {
|
|
|
+ GetPrintMod.Add("0", SetPasswordDialogModel.PrintMod.None);
|
|
|
+ GetPrintMod.Add("1", SetPasswordDialogModel.PrintMod.LowDpi);
|
|
|
+ GetPrintMod.Add("2", SetPasswordDialogModel.PrintMod.HighDpi);
|
|
|
+
|
|
|
+ GetChangeMod.Add("0", SetPasswordDialogModel.ChangeMod.None);
|
|
|
+ GetChangeMod.Add("1", SetPasswordDialogModel.ChangeMod.ChangePage);
|
|
|
+ GetChangeMod.Add("2", SetPasswordDialogModel.ChangeMod.FormAndSignature);
|
|
|
+ GetChangeMod.Add("3", SetPasswordDialogModel.ChangeMod.AnnotAndFormAndSignature);
|
|
|
+ GetChangeMod.Add("4", SetPasswordDialogModel.ChangeMod.ExceptAbstrat);
|
|
|
+ }
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ #region 逻辑函数
|
|
|
public void SetCanOpen()
|
|
|
{
|
|
|
setPasswordDialogModel.CanOpen = CanOpen;
|
|
@@ -136,22 +165,7 @@ namespace PDF_Office.ViewModels.Dialog.ToolsDialogs.SaftyDialogs
|
|
|
public void CanEditTextChanged()
|
|
|
{
|
|
|
CheckCanConfirmEncrypt();
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- private void InitPermissionsDictionary(ref Dictionary<string, SetPasswordDialogModel.PrintMod> GetPrintMod,
|
|
|
- ref Dictionary<string, SetPasswordDialogModel.ChangeMod> GetChangeMod)
|
|
|
- {
|
|
|
- GetPrintMod.Add("0", SetPasswordDialogModel.PrintMod.None);
|
|
|
- GetPrintMod.Add("1", SetPasswordDialogModel.PrintMod.LowDpi);
|
|
|
- GetPrintMod.Add("2", SetPasswordDialogModel.PrintMod.HighDpi);
|
|
|
-
|
|
|
- GetChangeMod.Add("0", SetPasswordDialogModel.ChangeMod.None);
|
|
|
- GetChangeMod.Add("1", SetPasswordDialogModel.ChangeMod.ChangePage);
|
|
|
- GetChangeMod.Add("2", SetPasswordDialogModel.ChangeMod.FormAndSignature);
|
|
|
- GetChangeMod.Add("3", SetPasswordDialogModel.ChangeMod.AnnotAndFormAndSignature);
|
|
|
- GetChangeMod.Add("4", SetPasswordDialogModel.ChangeMod.ExceptAbstrat);
|
|
|
- }
|
|
|
+ }
|
|
|
|
|
|
public void ConfirmEncrypt()
|
|
|
{
|
|
@@ -176,39 +190,38 @@ namespace PDF_Office.ViewModels.Dialog.ToolsDialogs.SaftyDialogs
|
|
|
/*
|
|
|
* 做一些工作
|
|
|
*/
|
|
|
-
|
|
|
- CPDFPermissionsInfo permissionsInfo = new CPDFPermissionsInfo();
|
|
|
- if (setPasswordDialogModel.CanOpen)
|
|
|
+ CPDFPermissionsInfo permissionsInfo = new CPDFPermissionsInfo();
|
|
|
+ if (setPasswordDialogModel.CanOpen)
|
|
|
+ {
|
|
|
+ if (!string.IsNullOrEmpty(SetPasswordDialogModel.PasswordForOpen))
|
|
|
{
|
|
|
- if (!string.IsNullOrEmpty(SetPasswordDialogModel.CanOpenPassword))
|
|
|
- {
|
|
|
- openPassword = SetPasswordDialogModel.CanOpenPassword;
|
|
|
- }
|
|
|
+ openPassword = SetPasswordDialogModel.PasswordForOpen;
|
|
|
}
|
|
|
- if (setPasswordDialogModel.CanEdit)
|
|
|
+ }
|
|
|
+ if (setPasswordDialogModel.CanEdit)
|
|
|
+ {
|
|
|
+ if (!string.IsNullOrEmpty(SetPasswordDialogModel.PasswordForEdit))
|
|
|
{
|
|
|
- if (!string.IsNullOrEmpty(SetPasswordDialogModel.CanEditPassword))
|
|
|
- {
|
|
|
- editPassword = SetPasswordDialogModel.CanEditPassword;
|
|
|
- Dictionary<string, SetPasswordDialogModel.PrintMod> GetPrintMod = new Dictionary<string, SetPasswordDialogModel.PrintMod>();
|
|
|
- Dictionary<string, SetPasswordDialogModel.ChangeMod> GetChangeMod = new Dictionary<string, SetPasswordDialogModel.ChangeMod>(); ;
|
|
|
- InitPermissionsDictionary(ref GetPrintMod, ref GetChangeMod);
|
|
|
- permissionsInfo = setPasswordDialogModel.CreatePermissionsInfo(GetPrintMod[PrintMod], GetChangeMod[ChangeMod]);
|
|
|
- }
|
|
|
+ editPassword = SetPasswordDialogModel.PasswordForEdit;
|
|
|
+ Dictionary<string, SetPasswordDialogModel.PrintMod> GetPrintMod = new Dictionary<string, SetPasswordDialogModel.PrintMod>();
|
|
|
+ Dictionary<string, SetPasswordDialogModel.ChangeMod> GetChangeMod = new Dictionary<string, SetPasswordDialogModel.ChangeMod>(); ;
|
|
|
+ InitPermissionsDictionary(ref GetPrintMod, ref GetChangeMod);
|
|
|
+ permissionsInfo = setPasswordDialogModel.CreatePermissionsInfo(GetPrintMod[PrintMod], GetChangeMod[ChangeMod]);
|
|
|
}
|
|
|
- document.Encrypt(openPassword, editPassword, permissionsInfo);
|
|
|
+ }
|
|
|
+ document.Encrypt(openPassword, editPassword, permissionsInfo);
|
|
|
|
|
|
- document.WriteToFilePath(sfd.FileName);
|
|
|
- MessageBox.Show(sfd.FileName + " 保存成功");
|
|
|
- RequestClose?.Invoke(new Prism.Services.Dialogs.DialogResult(ButtonResult.Cancel));
|
|
|
+ document.WriteToFilePath(sfd.FileName);
|
|
|
+ MessageBox.Show(sfd.FileName + " 保存成功");
|
|
|
+ RequestClose?.Invoke(new Prism.Services.Dialogs.DialogResult(ButtonResult.Cancel));
|
|
|
}
|
|
|
}
|
|
|
public void CancelEncrypt() =>
|
|
|
RequestClose?.Invoke(new Prism.Services.Dialogs.DialogResult(ButtonResult.Cancel));
|
|
|
+ #endregion
|
|
|
|
|
|
-
|
|
|
+ #region 框架相关
|
|
|
public string Title => "";
|
|
|
-
|
|
|
public event Action<IDialogResult> RequestClose;
|
|
|
|
|
|
public bool CanCloseDialog()
|
|
@@ -229,5 +242,6 @@ namespace PDF_Office.ViewModels.Dialog.ToolsDialogs.SaftyDialogs
|
|
|
document = doc;
|
|
|
}
|
|
|
}
|
|
|
+ #endregion
|
|
|
}
|
|
|
}
|