Explorar el Código

其他-同步代码

liyijie hace 2 años
padre
commit
f3a2a12638

+ 3 - 3
PDF Office/Model/Dialog/ToolsDialogs/SaftyDialogs/PasswordModel.cs

@@ -7,12 +7,12 @@ using System.Threading.Tasks;
 
 namespace PDF_Office.Model.Dialog.ToolsDialogs.SaftyDialogs
 {
-    public static class PasswordModel
+    public class PasswordModel
     {
         public static string UserPassword { get; set; }
 
-        public static string PermissionPassword { get; set; }
+        public string PermissionPassword { get; set; }
 
-        public static CPDFPermissionsInfo PermissionsInfo = new CPDFPermissionsInfo();
+        public CPDFPermissionsInfo PermissionsInfo = new CPDFPermissionsInfo();
     }
 }

+ 31 - 2
PDF Office/ViewModels/Dialog/ToolsDialogs/CompressDialogViewModel.cs

@@ -9,9 +9,38 @@ namespace PDF_Office.ViewModels.Dialog.ToolsDialogs
 {
     public class CompressDialogViewModel : BindableBase,IDialogAware
     {
-        public CompressDialogViewModel()
-        {
+        public DelegateCommand LargeQualityCommand { get; set; }
+
+        public DelegateCommand StandardQualityCommand { get; set; }
+
+        public DelegateCommand LittleQualityCommand { get; set; }
 
+        public DelegateCommand MicroQualityCommand { get; set; }
+
+        public DelegateCommand WhiteSmokeCommand { get; set; }
+
+    public CompressDialogViewModel()
+        {
+            LargeQualityCommand = new DelegateCommand(LargeQuality);
+            StandardQualityCommand = new DelegateCommand(StandardQuality);
+            LittleQualityCommand = new DelegateCommand(LittleQuality);
+            MicroQualityCommand = new DelegateCommand(MicroQuality);
+            WhiteSmokeCommand = new DelegateCommand(MicroQuality);
+        }
+        private void LargeQuality() { 
+        
+        }
+        private void StandardQuality()
+        {
+
+        }
+        private void LittleQuality()
+        {
+
+        }
+        private void MicroQuality()
+        {
+
         }
 
         public string Title => "";

+ 2 - 1
PDF Office/ViewModels/Dialog/ToolsDialogs/SaftyDialogs/CancelPasswordDialogViewModel.cs

@@ -29,8 +29,9 @@ namespace PDF_Office.ViewModels.Dialog.ToolsDialogs.SaftyDialogs
 
         private void OpenCheckPassword()
         {
-            DialogParameters value = new DialogParameters();
+            DialogParameters value = new DialogParameters(); 
             value.Add("1", 1);
+            RequestClose?.Invoke(new DialogResult(ButtonResult.OK));
             dialogs.ShowDialog(DialogNames.CheckPasswordDialog, value, e => {
             }); 
         }

+ 9 - 8
PDF Office/ViewModels/Dialog/ToolsDialogs/SaftyDialogs/SetPasswordDialogViewModel.cs

@@ -85,27 +85,28 @@ namespace PDF_Office.ViewModels.Dialog.ToolsDialogs.SaftyDialogs
             sfd.FileName = document.FileName + "_SetPassword.pdf";
             if (sfd.ShowDialog() == Forms.DialogResult.OK)
             {
+                PasswordModel passwordModel = new PasswordModel();
                 /*
                  * 做一些工作
                  */
                 if (AllowsCopying == "True")
                 {
-                    PasswordModel.PermissionsInfo.AllowsCopying = true;
+                    passwordModel.PermissionsInfo.AllowsCopying = true;
                 }
                 else {
-                    PasswordModel.PermissionsInfo.AllowsCopying = false;
+                    passwordModel.PermissionsInfo.AllowsCopying = false;
                 }
                 if (AllowsPrinting == "True")
                 {
-                    PasswordModel.PermissionsInfo.AllowsPrinting = true;
+                    passwordModel.PermissionsInfo.AllowsPrinting = true;
                 }
-                else { 
-                    PasswordModel.PermissionsInfo.AllowsPrinting = false; 
+                else {
+                    passwordModel.PermissionsInfo.AllowsPrinting = false; 
                 }
-                PasswordModel.PermissionPassword=PermissionPassword;
-                document.Encrypt(PasswordModel.UserPassword, PasswordModel.PermissionPassword, PasswordModel.PermissionsInfo);
+                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);
+                Trace.WriteLine(PasswordModel.UserPassword + "nouser"+ passwordModel.PermissionPassword + "copy"+passwordModel.PermissionsInfo.AllowsCopying+ "print"+ passwordModel.PermissionsInfo.AllowsPrinting);
 
                 MessageBox.Show(sfd.FileName + " Saved Successfully.");
             }

+ 79 - 79
PDF Office/ViewModels/Tools/ToolsBarContentViewModel.cs

@@ -1,82 +1,82 @@
 using ComPDFKitViewer.PdfViewer;
-using PDF_Office.Model;
-using Prism.Commands;
-using Prism.Mvvm;
-using Prism.Regions;
-using Prism.Services.Dialogs;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Security.Cryptography.X509Certificates;
-
-namespace PDF_Office.ViewModels.Tools
-{
-    public class ToolsBarContentViewModel : BindableBase,INavigationAware
-    {
-        private CPDFViewer PDFViewer;
-
-        private ViewContentViewModel viewContentViewModel;
-
-        public IDialogService dialogs;
-
-        /// <summary>
-        /// 是否是第一次加载
-        /// </summary>
-        private bool isFirstLoad = true;
-
-        public DelegateCommand CompressCommand { get; set; }
-
-        public DelegateCommand SetPasswordCommand { get; set; }
-
-        public DelegateCommand CancelPasswordCommand { get; set; }
-
-        public ToolsBarContentViewModel(IDialogService dialogService)
-        {
-            dialogs= dialogService;
-
-            CompressCommand = new DelegateCommand(OpenCompressDialog);
-            SetPasswordCommand = new DelegateCommand(OpenSetPasswordDialog);
-            CancelPasswordCommand = new DelegateCommand(OpenCancelPasswordDialog);
-        }
-
-        private void OpenCompressDialog()
-        {
+using PDF_Office.Model;
+using Prism.Commands;
+using Prism.Mvvm;
+using Prism.Regions;
+using Prism.Services.Dialogs;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Security.Cryptography.X509Certificates;
+
+namespace PDF_Office.ViewModels.Tools
+{
+    public class ToolsBarContentViewModel : BindableBase,INavigationAware
+    {
+        private CPDFViewer PDFViewer;
+
+        private ViewContentViewModel viewContentViewModel;
+
+        public IDialogService dialogs;
+
+        /// <summary>
+        /// 是否是第一次加载
+        /// </summary>
+        private bool isFirstLoad = true;
+
+        public DelegateCommand CompressCommand { get; set; }
+
+        public DelegateCommand SetPasswordCommand { get; set; }
+
+        public DelegateCommand CancelPasswordCommand { get; set; }
+
+        public ToolsBarContentViewModel(IDialogService dialogService)
+        {
+            dialogs= dialogService;
+
+            CompressCommand = new DelegateCommand(OpenCompressDialog);
+            SetPasswordCommand = new DelegateCommand(OpenSetPasswordDialog);
+            CancelPasswordCommand = new DelegateCommand(OpenCancelPasswordDialog);
+        }
+
+        private void OpenCompressDialog()
+        {
+            DialogParameters value = new DialogParameters();
+            value.Add(ParameterNames.PDFDocument, PDFViewer.Document);
+            dialogs.ShowDialog(DialogNames.CompressDialog, value, e => {   });
+        }
+
+        private void OpenSetPasswordDialog()
+        {
             DialogParameters value = new DialogParameters();
-            value.Add(ParameterNames.PDFDocument, PDFViewer.Document);
-            dialogs.ShowDialog(DialogNames.CompressDialog, value, e => {   });
-        }
-
-        private void OpenSetPasswordDialog()
-        {
-            DialogParameters value = new DialogParameters();
-            value.Add(ParameterNames.PDFDocument, PDFViewer.Document);
-            dialogs.ShowDialog(DialogNames.SetPasswordDialog, value, e => { });
-        }
-
-        private void OpenCancelPasswordDialog()
-        {
-            DialogParameters value = new DialogParameters();
-            value.Add(ParameterNames.PDFDocument, PDFViewer.Document);
-            dialogs.ShowDialog(DialogNames.CancelPasswordDialog, value, e => { });
-        }
-
-        public bool IsNavigationTarget(NavigationContext navigationContext)
-        {
-            return true;
-        }
-
-        public void OnNavigatedFrom(NavigationContext navigationContext)
-        {
-        }
-
-        public void OnNavigatedTo(NavigationContext navigationContext)
+            value.Add(ParameterNames.PDFDocument, PDFViewer.Document);
+            dialogs.ShowDialog(DialogNames.SetPasswordDialog, value, e => { });
+        }
+
+        private void OpenCancelPasswordDialog()
+        {
+            DialogParameters value = new DialogParameters();
+            value.Add(ParameterNames.PDFDocument, PDFViewer.Document);
+            dialogs.ShowDialog(DialogNames.CancelPasswordDialog, value, e => { });
+        }
+
+        public bool IsNavigationTarget(NavigationContext navigationContext)
+        {
+            return true;
+        }
+
+        public void OnNavigatedFrom(NavigationContext navigationContext)
+        {
+        }
+
+        public void OnNavigatedTo(NavigationContext navigationContext)
         {
-            navigationContext.Parameters.TryGetValue<ViewContentViewModel>(ParameterNames.ViewContentViewModel, out viewContentViewModel);
-            navigationContext.Parameters.TryGetValue<CPDFViewer>(ParameterNames.PDFViewer, out PDFViewer);
-            if (PDFViewer != null)
-            {
-                isFirstLoad = false;
-            }
-        }
-    }
-}
+            navigationContext.Parameters.TryGetValue<ViewContentViewModel>(ParameterNames.ViewContentViewModel, out viewContentViewModel);
+            navigationContext.Parameters.TryGetValue<CPDFViewer>(ParameterNames.PDFViewer, out PDFViewer);
+            if (PDFViewer != null)
+            {
+                isFirstLoad = false;
+            }
+        }
+    }
+}

+ 5 - 5
PDF Office/Views/Dialog/ToolsDialogs/CompressDialog.xaml

@@ -17,7 +17,7 @@
         <TextBlock Grid.Row="0" Text="压缩PDF" FontSize="20" FontWeight="ExtraBlack" VerticalAlignment="Center" HorizontalAlignment="Left"  Margin="20,0,0,0" Height="28" Width="120"/>
         <Border Grid.Row="1" BorderBrush="Gray" BorderThickness="0,1,0,1">
             <StackPanel>
-                <Button HorizontalAlignment="Center" Width="528" Height="64" Margin="0,10,0,16" Background="WhiteSmoke">
+                <Button HorizontalAlignment="Center" Width="528" Height="64" Margin="0,10,0,16" Background="WhiteSmoke" Command="{Binding LargeQualityCommand}">
                     <StackPanel Orientation="Horizontal" >
                         <Border HorizontalAlignment="Right" Margin="0,0,350,0">
                             <TextBlock Text="大型文件" FontSize="18"></TextBlock>
@@ -27,7 +27,7 @@
                         </Border>
                     </StackPanel>
                 </Button>
-                <Button HorizontalAlignment="Center" Width="528" Height="64" Margin="0,0,0,16" Background="WhiteSmoke">
+                <Button HorizontalAlignment="Center" Width="528" Height="64" Margin="0,0,0,16" Background="WhiteSmoke" Command="{Binding StandardQualityCommand}">
                     <StackPanel Orientation="Horizontal" >
                         <Border HorizontalAlignment="Right" Margin="0,0,350,0">
                             <TextBlock Text="标准文件" FontSize="18" Foreground="Black" ></TextBlock>
@@ -37,7 +37,7 @@
                         </Border>
                     </StackPanel>
                 </Button>
-                <Button HorizontalAlignment="Center" Width="528" Height="64" Margin="0,0,0,16" Background="WhiteSmoke">
+                <Button HorizontalAlignment="Center" Width="528" Height="64" Margin="0,0,0,16" Background="WhiteSmoke" Command="{Binding LittleQualityCommand}">
                     <StackPanel Orientation="Horizontal" >
                         <Border HorizontalAlignment="Right" Margin="0,0,280,0">
                             <TextBlock Text="小型文件(推荐)" FontSize="18" Foreground="Black"></TextBlock>
@@ -47,7 +47,7 @@
                         </Border>
                     </StackPanel>
                 </Button>
-                <Button HorizontalAlignment="Center" Width="528" Height="64" Margin="0,0,0,64" Background="WhiteSmoke">
+                <Button HorizontalAlignment="Center" Width="528" Height="64" Margin="0,0,0,64" Background="WhiteSmoke" Command="{Binding MicroQualityCommand}">
                     <StackPanel Orientation="Horizontal" >
                         <Border HorizontalAlignment="Right" Margin="0,0,350,0">
                             <TextBlock Text="微型文件" FontSize="18" Foreground="Black"></TextBlock>
@@ -68,7 +68,7 @@
                 </Button>
             </StackPanel>
             <StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
-                <Button Background="WhiteSmoke" Width="100" Height="25" Margin="0,0,10,0">
+                <Button Background="WhiteSmoke" Width="100" Height="25" Margin="0,0,10,0" Command="{Binding WhiteSmokeCommand}">
                     <Border>
                         <TextBlock Text="压缩"></TextBlock>
                     </Border>

+ 4 - 1
PDF Office/Views/Dialog/ToolsDialogs/SaftyDialogs/SetPasswordDialog.xaml.cs

@@ -61,13 +61,16 @@ namespace PDF_Office.Views.Dialog.ToolsDialogs.SaftyDialogs
 
         private void HidePasswordBox_PasswordChanged(object sender, RoutedEventArgs e)
         {
+            if (PasswordDisplayHasFocus)
+            { return; }
             PasswordDisplay.Text = PasswordHidden.Password;
             PasswordModel.UserPassword = PasswordHidden.Password;
         }
 
         private void DisplayTextBox_TextChanged(object sender, TextChangedEventArgs e)
         {
-            
+            if (PasswordHiddenHasFocus)
+            { return; }
             PasswordHidden.Password= PasswordDisplay.Text;
             PasswordModel.UserPassword = PasswordDisplay.Text;
         }