Browse Source

打印 - 虚拟打印机多重打印

liuaoran 1 year ago
parent
commit
7db345b215

+ 48 - 11
PDF Office/ViewModels/Dialog/HomePageToolsDialogs/HomePagePrinter/HomePagePrinterDialogViewModel.cs

@@ -244,6 +244,20 @@ namespace PDF_Master.ViewModels.Dialog.HomePageToolsDialogs.HomePagePrinter
             set => SetProperty(ref _maxCopiesNumber, value);
         }
 
+
+        private string _copiesNumber = "1";
+        public string CopiesNumber
+        {
+            get => _copiesNumber;
+            set
+            {
+                SetProperty(ref _copiesNumber, value);
+                PrintSettingsInfo.Copies = int.Parse(_copiesNumber);
+                PrintSettingsInfo.needRerendering = false;
+                this.printEvent.GetEvent<SendPrintSettingsInfoEvent>().Publish(new PrintSettingsInfoWithUnicode { printSettingsInfo = this.PrintSettingsInfo, Unicode = this.Unicode });
+            }
+        }
+
         private Visibility _printPageBorderVisibility = Visibility.Collapsed;
         public Visibility PrintPageBorderVisibility
         {
@@ -386,6 +400,7 @@ namespace PDF_Master.ViewModels.Dialog.HomePageToolsDialogs.HomePagePrinter
         public DelegateCommand<object> SetPrintBorderCommand { get; set; }
         public DelegateCommand<object> SetPrintOritationCommand { get; set; }
         public DelegateCommand<object> PageTextChangedCommand { get; set; }
+
         #endregion
 
         HomePagePrinterDialogViewModel(IRegionManager regionManager, IDialogService dialogService, IEventAggregator eventAggregator)
@@ -739,7 +754,7 @@ namespace PDF_Master.ViewModels.Dialog.HomePageToolsDialogs.HomePagePrinter
                     this.printEvent.GetEvent<SendPrintSettingsInfoEvent>().Publish(new PrintSettingsInfoWithUnicode { printSettingsInfo = this.PrintSettingsInfo, Unicode = this.Unicode });
                     return;
                 }
-                 
+
                 if (!isCurrentPage)
                 {
                     for (int temp = 0; temp < PDFViewer.Document.PageCount; temp++)
@@ -762,8 +777,6 @@ namespace PDF_Master.ViewModels.Dialog.HomePageToolsDialogs.HomePagePrinter
             }
         }
 
-
-
         public void SetCustomPageRange(object e)
         {
             if ((PrintSettingsInfo.EnumPageRange == (int)EnumPageRangeWithoutCurrentPage.StatusCustomizedRange && !isCurrentPage) || (PrintSettingsInfo.EnumPageRange == (int)EnumPageRangeWithCurrentPage.StatusCustomizedRange && isCurrentPage))
@@ -801,9 +814,17 @@ namespace PDF_Master.ViewModels.Dialog.HomePageToolsDialogs.HomePagePrinter
                         PrintSettingsInfo.PageRangeList.Add(temp);
                     }
                     this.printEvent.GetEvent<SendPrintSettingsInfoEvent>().Publish(new PrintSettingsInfoWithUnicode { printSettingsInfo = this.PrintSettingsInfo, Unicode = this.Unicode });
+                    if (PrintSettingsInfo.needReversePage)
+                    {
+                        PrintSettingsInfo.PageRangeList.Reverse();
+                    }
                     return;
                 }
                 PrintSettingsInfo.PageRangeList = DocumentTargetPages;
+                if (PrintSettingsInfo.needReversePage)
+                {
+                    PrintSettingsInfo.PageRangeList.Reverse();
+                }
                 this.printEvent.GetEvent<SendPrintSettingsInfoEvent>().Publish(new PrintSettingsInfoWithUnicode { printSettingsInfo = this.PrintSettingsInfo, Unicode = this.Unicode });
             }
         }
@@ -817,7 +838,8 @@ namespace PDF_Master.ViewModels.Dialog.HomePageToolsDialogs.HomePagePrinter
             }
             else
             {
-                PrintSettingsInfo.PrintDocument.DefaultPageSettings.Landscape = true;            }
+                PrintSettingsInfo.PrintDocument.DefaultPageSettings.Landscape = true;
+            }
 
             PrintSettingsInfo.EnumPrintOrientation = (EnumPrintOrientation)cmb.SelectedIndex;
             this.printEvent.GetEvent<SendPrintSettingsInfoEvent>().Publish(new PrintSettingsInfoWithUnicode { printSettingsInfo = this.PrintSettingsInfo, Unicode = this.Unicode });
@@ -852,7 +874,8 @@ namespace PDF_Master.ViewModels.Dialog.HomePageToolsDialogs.HomePagePrinter
         public void SetReversePage(object e)
         {
             var reversePageChk = e as CheckBox;
-            if ((bool)reversePageChk.IsChecked) {
+            if ((bool)reversePageChk.IsChecked)
+            {
                 PrintSettingsInfo.needReversePage = true;
             }
             else
@@ -1036,6 +1059,7 @@ namespace PDF_Master.ViewModels.Dialog.HomePageToolsDialogs.HomePagePrinter
                 ///那奇数页呢?
                 else
                 {
+                    AlertsMessage alertsMessage = new AlertsMessage();
                     if ((PrintSettingsInfo.PrintModInfo.EnumPrintMod == EnumPrintMod.StatusSize && PrintSettingsInfo.PageRangeList.Count == 1) || (PrintSettingsInfo.PrintModInfo.EnumPrintMod == EnumPrintMod.StatusBooklet && PrintSettingsInfo.PageRangeList.Count == 1))
                     {
                         this.printEvent.GetEvent<SendPrintQueueEvent>().Publish(new PrintQueueWithUnicode { printQueue = this.printQueue, EnumBothSidesStage = EnumBothSidesStage.StatusNone, Unicode = this.Unicode });
@@ -1050,24 +1074,37 @@ namespace PDF_Master.ViewModels.Dialog.HomePageToolsDialogs.HomePagePrinter
                         else
                         {
                             this.printEvent.GetEvent<SendPrintQueueEvent>().Publish(new PrintQueueWithUnicode { printQueue = this.printQueue, EnumBothSidesStage = EnumBothSidesStage.StatusFrontSide, Unicode = this.Unicode });
-                            if (FinishedFrontSideFlag && MessageBoxEx.Show("Printing on the front side of the paper is complete. Please reverse the paper, click 'OK' to print the reverse side", "", MessageBoxButtons.OKCancel) == System.Windows.Forms.DialogResult.OK)
+                            if (FinishedFrontSideFlag)
                             {
-
-                                this.printEvent.GetEvent<SendPrintQueueEvent>().Publish(new PrintQueueWithUnicode { printQueue = this.printQueue, EnumBothSidesStage = EnumBothSidesStage.StatusBackSide, Unicode = this.Unicode });
+                                alertsMessage.ShowDialog("Message", "Printing on the front side of the paper is complete. Please reverse the paper, click 'OK' to print the reverse side", "Cancel", "OK");
+                                if (alertsMessage.result == ContentResult.Ok)
+                                {
+                                    this.printEvent.GetEvent<SendPrintQueueEvent>().Publish(new PrintQueueWithUnicode { printQueue = this.printQueue, EnumBothSidesStage = EnumBothSidesStage.StatusBackSide, Unicode = this.Unicode });
+                                    FinishedFrontSideFlag = false;
+                                }
                             }
                         }
                     }
                     else
                     {
                         this.printEvent.GetEvent<SendPrintQueueEvent>().Publish(new PrintQueueWithUnicode { printQueue = this.printQueue, EnumBothSidesStage = EnumBothSidesStage.StatusFrontSide, Unicode = this.Unicode });
-                        if (FinishedFrontSideFlag && MessageBoxEx.Show("Printing on the front side of the paper is complete. Please reverse the paper, click 'OK' to print the reverse side", "", MessageBoxButtons.OKCancel) == System.Windows.Forms.DialogResult.OK)
+                        if (FinishedFrontSideFlag)
                         {
-                            this.printEvent.GetEvent<SendPrintQueueEvent>().Publish(new PrintQueueWithUnicode { printQueue = this.printQueue, EnumBothSidesStage = EnumBothSidesStage.StatusBackSide, Unicode = this.Unicode });
+                            alertsMessage.ShowDialog("Message", "Printing on the front side of the paper is complete. Please reverse the paper, click 'OK' to print the reverse side", "Cancel", "OK");
+                            if (alertsMessage.result == ContentResult.Ok)
+                            {
+                                this.printEvent.GetEvent<SendPrintQueueEvent>().Publish(new PrintQueueWithUnicode { printQueue = this.printQueue, EnumBothSidesStage = EnumBothSidesStage.StatusBackSide, Unicode = this.Unicode });
+                                FinishedFrontSideFlag = false;
+                            }
                         }
                     }
                 }
             }
-            RequestClose.Invoke(new Prism.Services.Dialogs.DialogResult(ButtonResult.OK));
+            try
+            {
+                RequestClose.Invoke(new Prism.Services.Dialogs.DialogResult(ButtonResult.OK));
+            }
+            catch { }
         }
 
 

+ 30 - 24
PDF Office/ViewModels/Dialog/HomePageToolsDialogs/HomePagePrinter/HomePagePrinterDocumentContentViewModel.cs

@@ -93,9 +93,8 @@ namespace PDF_Master.ViewModels.Dialog.HomePageToolsDialogs.HomePagePrinter
         public double PosterRatio = 0;
 
         #endregion
-        /// <summary>
-        /// 转存防卡顿
-        /// </summary>
+
+        bool canOnlyOneCopy = false;
 
         public class DocumentSettingsInfo
         {
@@ -108,6 +107,9 @@ namespace PDF_Master.ViewModels.Dialog.HomePageToolsDialogs.HomePagePrinter
             public bool IsSettingsChanged = true;
         }
 
+        /// <summary>
+        /// 转存防卡顿
+        /// </summary>
         public DocumentSettingsInfo documentSettingsInfo = new DocumentSettingsInfo();
 
         /// <summary>
@@ -239,6 +241,7 @@ namespace PDF_Master.ViewModels.Dialog.HomePageToolsDialogs.HomePagePrinter
         {
             if (printQueueWithUnicode.printQueue != null)
             {
+                canOnlyOneCopy = false;
                 PrintIndex = 0;
                 this.documentPrintQueue = printQueueWithUnicode.printQueue;
                 var printDocument = new PrintDocument();
@@ -315,8 +318,12 @@ namespace PDF_Master.ViewModels.Dialog.HomePageToolsDialogs.HomePagePrinter
                 {
                     printDocument.DefaultPageSettings.PaperSource = paperSources[0];
                 }
-
-                if (PrintSettingsInfo.Copies <= printQueueWithUnicode.printQueue.GetPrintCapabilities().MaxCopyCount && PrintSettingsInfo.Copies > 0)
+                //虚拟打印机:仅有一份的情况下
+                if (printQueueWithUnicode.printQueue.GetPrintCapabilities().MaxCopyCount == 1)
+                {
+                    printDocument.PrinterSettings.Copies = (short)PrintSettingsInfo.Copies;
+                }
+                else if (PrintSettingsInfo.Copies <= printQueueWithUnicode.printQueue.GetPrintCapabilities().MaxCopyCount && PrintSettingsInfo.Copies > 0)
                 {
                     printDocument.PrinterSettings.Copies = (short)PrintSettingsInfo.Copies;
                 }
@@ -338,7 +345,8 @@ namespace PDF_Master.ViewModels.Dialog.HomePageToolsDialogs.HomePagePrinter
                 }
                 catch
                 {
-                    MessageBoxEx.Show("另一个进程正在占用该打印机或发生未知错误");
+                    AlertsMessage alertsMessage = new AlertsMessage();
+                    alertsMessage.ShowDialog("错误", "另一个线程正在占用该打印机,或发生未知错误", "确定");
                 }
                 finally
                 {
@@ -350,8 +358,6 @@ namespace PDF_Master.ViewModels.Dialog.HomePageToolsDialogs.HomePagePrinter
 
         private void RecvLabel(LabelWithUnicode labelWithUnicode)
         {
-
-
             if (PrintSettingsInfo.PrintModInfo.EnumPrintMod == EnumPrintMod.StatusPoster)
             {
                 var posterInfo = (PosterInfo)PrintSettingsInfo.PrintModInfo;
@@ -1617,23 +1623,23 @@ namespace PDF_Master.ViewModels.Dialog.HomePageToolsDialogs.HomePagePrinter
 
         private void PrintDocumentByCurrentSettings(object sender, PrintPageEventArgs e)
         {
-            switch (PrintSettingsInfo.PrintModInfo.EnumPrintMod)
-            {
+                switch (PrintSettingsInfo.PrintModInfo.EnumPrintMod)
+                {
 
-                case EnumPrintMod.StatusPoster:
-                    PrintDocumentModPoster(e);
-                    break;
-                case EnumPrintMod.StatusMultiple:
-                    PrintDocumentModMultiple(e);
-                    break;
-                case EnumPrintMod.StatusBooklet:
-                    PrintDocumentModBooklet(e);
-                    break;
-                case EnumPrintMod.StatusSize:
-                default:
-                    PrintDocumentModSize(e);
-                    break;
-            }
+                    case EnumPrintMod.StatusPoster:
+                        PrintDocumentModPoster(e);
+                        break;
+                    case EnumPrintMod.StatusMultiple:
+                        PrintDocumentModMultiple(e);
+                        break;
+                    case EnumPrintMod.StatusBooklet:
+                        PrintDocumentModBooklet(e);
+                        break;
+                    case EnumPrintMod.StatusSize:
+                    default:
+                        PrintDocumentModSize(e);
+                        break;
+                }
         }
 
         //跳转指定页

+ 1 - 1
PDF Office/ViewModels/Dialog/HomePageToolsDialogs/HomePagePrinter/HomePagePrinterModSizeContentViewModel.cs

@@ -60,7 +60,7 @@ namespace PDF_Master.ViewModels.Dialog.HomePageToolsDialogs.HomePagePrinter
             this.eventAggregator = eventAggregator;
             SizeInfo = new SizeInfo();
             SizeInfo.EnumPrintMod = EnumPrintMod.StatusSize;
-
+            DisplayRatio = "100";
             SetModSizeStatusCommand = new DelegateCommand<object>(SetModSizeStatus);
             SetDisplayRatioCommand = new DelegateCommand(SetDisplayRatio);
             UnlockDuplexCommand = new DelegateCommand<object>(UnlockDuplex);   

+ 2 - 2
PDF Office/Views/Dialog/HomePageToolsDialogs/HomePagePrinter/HomePagePrinterDialog.xaml

@@ -1,7 +1,7 @@
 <UserControl x:Class="PDF_Master.Views.Dialog.HomePageToolsDialogs.HomePagePrinter.HomePagePrinterDialog"
              xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
              xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
-             xmlns:prism="http://prismlibrary.com/" xmlns:cus="clr-namespace:PDF_Master.CustomControl" xmlns:homepageprinter="clr-namespace:PDF_Master.ViewModels.Dialog.HomePageToolsDialogs.HomePagePrinter" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:i="http://schemas.microsoft.com/xaml/behaviors" xmlns:DataContext="{d:DesignInstance Type=homepageprinter:HomePagePrinterDialogViewModel}" 
+             xmlns:prism="http://prismlibrary.com/" xmlns:cus="clr-namespace:PDF_Master.CustomControl" xmlns:homepageprinter="clr-namespace:PDF_Master.ViewModels.Dialog.HomePageToolsDialogs.HomePagePrinter" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
              prism:ViewModelLocator.AutoWireViewModel="True" 
              prism:Dialog.WindowStyle="{StaticResource DialogWindowStyle}">
 
@@ -101,7 +101,7 @@
                                 <StackPanel Orientation="Horizontal" Margin="0,8,0,0">
                                     <StackPanel Orientation="Horizontal">
                                         <TextBlock Height="22" Text="{Binding T_Copies}" FontFamily="Segoe UI" FontSize="14"></TextBlock>
-                                        <cus:NumericUpDown Height="32" Width="132" Margin="16,0,0,0" Minimum="1" Text="{Binding CopiesNumber}"></cus:NumericUpDown>
+                                        <cus:NumericUpDown Height="32" Width="132" Margin="16,0,0,0" Minimum="1" Text="{Binding CopiesNumber, Mode=TwoWay}"></cus:NumericUpDown>
                                     </StackPanel>
                                     <CheckBox Name="GrayscaleChk" VerticalAlignment="Center" Margin="17,0,0,0" Command="{Binding SetGrayscaleCommand}" CommandParameter="{Binding ElementName=GrayscaleChk}">
                                         <TextBlock Text="{Binding T_BlackAndWhite}"  Foreground="#252629" FontFamily="Segoe UI" FontSize="14"/>