123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154 |
- using ComPDFKit.PDFDocument;
- using PDF_Office.Model;
- using PDF_Office.Model.Dialog.ToolsDialogs.SaftyDialogs;
- using PDF_Office.Views.HomePanel.RecentFiles;
- using Prism.Commands;
- using Prism.Mvvm;
- using Prism.Services.Dialogs;
- using System;
- using System.Collections.Generic;
- using System.Diagnostics;
- using System.Linq;
- using System.Windows.Controls;
- using System.Windows.Forms;
- using Forms = System.Windows.Forms;
- namespace PDF_Office.ViewModels.Dialog.ToolsDialogs.SaftyDialogs
- {
- public class SetPasswordDialogViewModel : BindableBase, IDialogAware
- {
-
- private CPDFDocument document;
- public DelegateCommand ConfirmPasswordCommand { get; set; }
- public DelegateCommand InputPasswordCommand { get; set; }
- private PasswordModel passwordModel = new PasswordModel();
- private string _permissionPassword;
- public string PermissionPassword
- {
- get { return _permissionPassword; }
- set
- {
- _permissionPassword = value;
- RaisePropertyChanged("UserPassword");
- }
- }
- private string _allowsCopying;
- public string AllowsCopying
- {
- get { return _allowsCopying; }
- set
- {
- _allowsCopying = value;
- RaisePropertyChanged("UserPassword");
- }
- }
- private string _allowsPrinting;
- public string AllowsPrinting
- {
- get { return _allowsPrinting; }
- set
- {
- _allowsPrinting = value;
- RaisePropertyChanged("PermissionPassword");
- }
- }
- public SetPasswordDialogViewModel()
- {
- ConfirmPasswordCommand = new DelegateCommand(ConfirmPassword);
- InputPasswordCommand = new DelegateCommand(InputPassword);
- }
- public void ConfirmPassword()
- {
- FolderBrowserDialog folderDialog = new FolderBrowserDialog();
- Forms.SaveFileDialog sfd = new Forms.SaveFileDialog();
- /*
- *设置这个对话框的起始保存路径
- */
- sfd.InitialDirectory = @"D:\";
- /*
- *设置保存的文件的类型,注意过滤器的语法 例子:“文件类型|*.后缀名;*.后缀名;”
- */
- sfd.Filter = "PDF|*.pdf;";
- /*
- *调用ShowDialog()方法显示该对话框,该方法的返回值代表用户是否点击了确定按钮
- **/
- sfd.FileName = document.FileName + "_SetPassword.pdf";
- if (sfd.ShowDialog() == Forms.DialogResult.OK)
- {
-
- /*
- * 做一些工作
- */
- if (AllowsCopying == "True")
- {
- Trace.WriteLine("111111111"+"True");
- passwordModel.PermissionsInfo.AllowsCopying = true;
- }
- else {
- passwordModel.PermissionsInfo.AllowsCopying = false;
- }
- if (AllowsPrinting == "True")
- {
- passwordModel.PermissionsInfo.AllowsPrinting = true;
- }
- else {
- Trace.WriteLine("2222222"+"false");
- passwordModel.PermissionsInfo.AllowsPrinting = false;
- }
- passwordModel.PermissionPassword=PermissionPassword;
- document.Encrypt(PasswordModel.UserPassword, passwordModel.PermissionPassword, passwordModel.PermissionsInfo);
- document.WriteToFilePath(sfd.FileName);
- Trace.WriteLine(PasswordModel.UserPassword + "nouser"+ passwordModel.PermissionPassword + "copy"+passwordModel.PermissionsInfo.AllowsCopying+ "print"+ passwordModel.PermissionsInfo.AllowsPrinting);
- MessageBox.Show(sfd.FileName + " Saved Successfully.");
- }
- else
- {
- MessageBox.Show("Cancel.");
- }
- }
- public void InputPassword()
- {
- //UserPassword = PasswordModel.UserPassword;
- Trace.WriteLine("0_0");
- }
- 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;
- }
- }
- }
- }
|