|
@@ -1,54 +1,163 @@
|
|
using ComPDFKit.PDFDocument;
|
|
using ComPDFKit.PDFDocument;
|
|
|
|
+using PDF_Office.Helper;
|
|
using PDF_Office.Model;
|
|
using PDF_Office.Model;
|
|
-using PDF_Office.Model.Dialog.ToolsDialogs.SaftyDialogs;
|
|
|
|
using Prism.Commands;
|
|
using Prism.Commands;
|
|
using Prism.Mvvm;
|
|
using Prism.Mvvm;
|
|
using Prism.Services.Dialogs;
|
|
using Prism.Services.Dialogs;
|
|
using System;
|
|
using System;
|
|
-using System.Collections.Generic;
|
|
|
|
-using System.Linq;
|
|
|
|
-using System.Xml.Linq;
|
|
|
|
|
|
+using static PDF_Office.Model.Dialog.ToolsDialogs.SaftyDialogs.DeleteSafetySettintgsModel;
|
|
|
|
+
|
|
|
|
+using Visibility = System.Windows.Visibility;
|
|
|
|
|
|
namespace PDF_Office.ViewModels.Dialog.ToolsDialogs.SaftyDialogs
|
|
namespace PDF_Office.ViewModels.Dialog.ToolsDialogs.SaftyDialogs
|
|
{
|
|
{
|
|
- public class CheckPasswordDialogViewModel : BindableBase,IDialogAware
|
|
|
|
- {
|
|
|
|
|
|
+ public class CheckPasswordDialogViewModel : BindableBase, IDialogAware
|
|
|
|
+ {
|
|
#region 参数和属性
|
|
#region 参数和属性
|
|
private CPDFDocument document;
|
|
private CPDFDocument document;
|
|
|
|
+ private CPDFDocument tempDocument;
|
|
#endregion
|
|
#endregion
|
|
|
|
|
|
|
|
+ private EnumPasswordKind passwordKind = EnumPasswordKind.StatusOpenPassword;
|
|
|
|
+ private string _password = "";
|
|
|
|
+ public string Password
|
|
|
|
+ {
|
|
|
|
+ get { return _password; }
|
|
|
|
+ set
|
|
|
|
+ {
|
|
|
|
+ SetProperty(ref _password, value);
|
|
|
|
+ IsRightValue = "unknow";
|
|
|
|
+ if (!string.IsNullOrEmpty(value)){
|
|
|
|
+ ClearPasswordButtonVisibility = Visibility.Visible;
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ ClearPasswordButtonVisibility = Visibility.Collapsed;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private string _inputPasswordMsg;
|
|
|
|
+ public string InputPasswordMsg
|
|
|
|
+ {
|
|
|
|
+ get { return _inputPasswordMsg; }
|
|
|
|
+ set { SetProperty(ref _inputPasswordMsg, value); }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private string _checkPasswordMsg;
|
|
|
|
+ public string CheckPasswordMsg
|
|
|
|
+ {
|
|
|
|
+ get { return _checkPasswordMsg; }
|
|
|
|
+ set { SetProperty(ref _checkPasswordMsg, value); }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private string _errorPasswordMsg;
|
|
|
|
+ public string ErrorPasswordMsg
|
|
|
|
+ {
|
|
|
|
+ get { return _errorPasswordMsg; }
|
|
|
|
+ set { SetProperty(ref _errorPasswordMsg, value); }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private string _isRightValue = "unknown";
|
|
|
|
+ public string IsRightValue
|
|
|
|
+ {
|
|
|
|
+ get { return _isRightValue; }
|
|
|
|
+ set {
|
|
|
|
+ SetProperty(ref _isRightValue, value);
|
|
|
|
+ if(value == "false")
|
|
|
|
+ {
|
|
|
|
+ ErrorPasswordMsgVisibility = Visibility.Visible;
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ ErrorPasswordMsgVisibility = Visibility.Collapsed;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private Visibility _clearPasswordButtonVisibility = Visibility.Collapsed;
|
|
|
|
+ public Visibility ClearPasswordButtonVisibility
|
|
|
|
+ {
|
|
|
|
+ get { return _clearPasswordButtonVisibility; }
|
|
|
|
+ set { SetProperty(ref _clearPasswordButtonVisibility, value); }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private Visibility _errorPasswordMsgVisibility = Visibility.Collapsed;
|
|
|
|
+ public Visibility ErrorPasswordMsgVisibility
|
|
|
|
+ {
|
|
|
|
+ get { return _errorPasswordMsgVisibility; }
|
|
|
|
+ set { SetProperty(ref _errorPasswordMsgVisibility, value); }
|
|
|
|
+ }
|
|
#region 委托声明
|
|
#region 委托声明
|
|
- public DelegateCommand DelegateConfirmCheckPasswordCommand { get; set; }
|
|
|
|
- public DelegateCommand DelegateCancelCheckPasswordCommand { get; set; }
|
|
|
|
|
|
+ public DelegateCommand ConfirmCommand { get; set; }
|
|
|
|
+ public DelegateCommand CancelCommand { get; set; }
|
|
|
|
+
|
|
|
|
+ public DelegateCommand ClearPasswordCommand { get; set; }
|
|
#endregion
|
|
#endregion
|
|
|
|
|
|
public CheckPasswordDialogViewModel()
|
|
public CheckPasswordDialogViewModel()
|
|
{
|
|
{
|
|
- CheckPasswordDialogModel.Password = "";
|
|
|
|
- DelegateConfirmCheckPasswordCommand = new DelegateCommand(ConfirmCheckPassword);
|
|
|
|
- DelegateCancelCheckPasswordCommand = new DelegateCommand(CancelCheckPassword);
|
|
|
|
|
|
+ ConfirmCommand = new DelegateCommand(Confirm);
|
|
|
|
+ CancelCommand = new DelegateCommand(Cancel);
|
|
|
|
+ ClearPasswordCommand = new DelegateCommand(ClearPassword);
|
|
}
|
|
}
|
|
|
|
|
|
#region 逻辑函数
|
|
#region 逻辑函数
|
|
- private void ConfirmCheckPassword()
|
|
|
|
|
|
+ private void Confirm()
|
|
{
|
|
{
|
|
- if (false)//TODO: 用于检测输入密码的权限,以及是否输入了正确的密码
|
|
|
|
- { }
|
|
|
|
- var dialogResult = new DialogResult(ButtonResult.OK);
|
|
|
|
- dialogResult.Parameters.Add("CheckPassword", true);
|
|
|
|
- RequestClose.Invoke(dialogResult);
|
|
|
|
|
|
+ if (passwordKind == EnumPasswordKind.StatusOpenPassword)//TODO: 用于检测输入密码的权限,以及是否输入了正确的密码
|
|
|
|
+ {
|
|
|
|
+ if (tempDocument.UnlockWithPassword(Password))
|
|
|
|
+ {
|
|
|
|
+ var dialogResult = new DialogResult(ButtonResult.OK);
|
|
|
|
+ dialogResult.Parameters.Add("CheckPasswordResult", true);
|
|
|
|
+ RequestClose.Invoke(dialogResult);
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ IsRightValue = "false";
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ if (tempDocument.UnlockWithPassword(Password))
|
|
|
|
+ {
|
|
|
|
+ if (SecurityHelper.CheckHaveAllPermissions(tempDocument))
|
|
|
|
+ {
|
|
|
|
+ var dialogResult = new DialogResult(ButtonResult.OK);
|
|
|
|
+ dialogResult.Parameters.Add("CheckPasswordResult", true);
|
|
|
|
+ RequestClose.Invoke(dialogResult);
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ IsRightValue = "false";
|
|
|
|
+ tempDocument.Release();
|
|
|
|
+ tempDocument = CPDFDocument.InitWithFilePath(document.FilePath);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ IsRightValue = "false";
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
- private void CancelCheckPassword()
|
|
|
|
|
|
+ private void Cancel()
|
|
{
|
|
{
|
|
var dialogResult = new DialogResult(ButtonResult.Cancel);
|
|
var dialogResult = new DialogResult(ButtonResult.Cancel);
|
|
dialogResult.Parameters.Add("CheckPassword", false);
|
|
dialogResult.Parameters.Add("CheckPassword", false);
|
|
RequestClose.Invoke(dialogResult);
|
|
RequestClose.Invoke(dialogResult);
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ private void ClearPassword()
|
|
|
|
+ {
|
|
|
|
+ Password= "";
|
|
|
|
+ }
|
|
#endregion
|
|
#endregion
|
|
|
|
|
|
#region 框架相关
|
|
#region 框架相关
|
|
- public string Title =>"";
|
|
|
|
|
|
+ public string Title => "";
|
|
public event Action<IDialogResult> RequestClose;
|
|
public event Action<IDialogResult> RequestClose;
|
|
|
|
|
|
public bool CanCloseDialog()
|
|
public bool CanCloseDialog()
|
|
@@ -58,15 +167,24 @@ namespace PDF_Office.ViewModels.Dialog.ToolsDialogs.SaftyDialogs
|
|
|
|
|
|
public void OnDialogClosed()
|
|
public void OnDialogClosed()
|
|
{
|
|
{
|
|
|
|
+ if (tempDocument != null)
|
|
|
|
+ {
|
|
|
|
+ tempDocument.Release();
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
public void OnDialogOpened(IDialogParameters parameters)
|
|
public void OnDialogOpened(IDialogParameters parameters)
|
|
{
|
|
{
|
|
CPDFDocument doc = null;
|
|
CPDFDocument doc = null;
|
|
parameters.TryGetValue<CPDFDocument>(ParameterNames.PDFDocument, out doc);
|
|
parameters.TryGetValue<CPDFDocument>(ParameterNames.PDFDocument, out doc);
|
|
|
|
+ parameters.TryGetValue<EnumPasswordKind>(ParameterNames.PasswordKind, out passwordKind);
|
|
if (doc != null)
|
|
if (doc != null)
|
|
{
|
|
{
|
|
document = doc;
|
|
document = doc;
|
|
|
|
+ tempDocument = CPDFDocument.InitWithFilePath(document.FilePath);
|
|
|
|
+ InputPasswordMsg = "\"" + document.FileName + ".pdf\"" + " is protected, please enter a Document Open Password.";
|
|
|
|
+ CheckPasswordMsg = "Password";
|
|
|
|
+ ErrorPasswordMsg = "Tips Text";
|
|
}
|
|
}
|
|
}
|
|
}
|
|
#endregion
|
|
#endregion
|