123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255 |
- using ComPDFKit.PDFDocument;
- using PDF_Master.EventAggregators;
- using PDF_Master.Model.Dialog.HomePageToolsDialogs.HomePagePrinter;
- using Prism.Commands;
- using Prism.Events;
- using Prism.Mvvm;
- using Prism.Regions;
- using System;
- using System.Collections.Generic;
- using System.Diagnostics;
- using System.Linq;
- using System.Management.Instrumentation;
- using System.Windows.Controls;
- namespace PDF_Master.ViewModels.Dialog.HomePageToolsDialogs.HomePagePrinter
- {
- public class HomePagePrinterModBookletContentViewModel : BindableBase, INavigationAware
- {
- private IEventAggregator eventAggregator;
- private string Unicode = null;
- private CPDFDocument document;
- private bool _isAutoRotate;
- public bool IsAutoRotate
- {
- get { return _isAutoRotate; }
- set { _isAutoRotate = value; }
- }
- private int? _paperFrom = 1;
- public int? PaperFrom
- {
- get
- {
- return _paperFrom;
- }
- set
- {
- if (PaperTo == null)
- {
- SetProperty(ref _paperFrom, 1);
- }
- else if (value < PaperTo)
- {
- SetProperty(ref _paperFrom, value);
- }
- else
- {
- SetProperty(ref _paperFrom, PaperTo);
- }
- }
- }
- private int? _paperTo;
- public int? PaperTo
- {
- get
- {
- return _paperTo;
- }
- set
- {
- if (value < MaxPaperNumber)
- {
- SetProperty(ref _paperTo, value);
- }
- else
- {
- SetProperty(ref _paperTo, MaxPaperNumber);
- }
- }
- }
- private List<string> _subsetList;
- public List<string> SubsetList
- {
- get { return _subsetList; }
- set { _subsetList = value; }
- }
- private int _subsetIndex = 0;
- public int SubsetIndex
- {
- get { return _subsetIndex; }
- set
- {
- _subsetIndex = value;
- InitBookletInfo();
- SendBookletInfo();
- }
- }
- private List<string> _bindingList;
- public List<string> BindingList
- {
- get { return _bindingList; }
- set { _bindingList = value; }
- }
- private int _bindingIndex = 0;
- public int BindingIndex
- {
- get { return _bindingIndex; }
- set
- {
- _bindingIndex = value;
- InitBookletInfo();
- SendBookletInfo();
- }
- }
- private BookletInfo _bookletInfo;
- public BookletInfo BookletInfo
- {
- get { return _bookletInfo; }
- set { _bookletInfo = value; }
- }
- private int _maxPaperNumber;
- public int MaxPaperNumber
- {
- get { return _maxPaperNumber; }
- set { _maxPaperNumber = value; }
- }
- public DelegateCommand<object> SetSheetCommand { get; set; }
- public DelegateCommand SetAutoRotateCommand { get; set; }
- public HomePagePrinterModBookletContentViewModel(IEventAggregator eventAggregator)
- {
- this.eventAggregator = eventAggregator;
- SubsetList = new List<string>();
- InitSubsetList();
- BindingList = new List<string>();
- InitBindingList();
- BookletInfo = new BookletInfo();
- BookletInfo.EnumPrintMod = EnumPrintMod.StatusBooklet;
- SetSheetCommand = new DelegateCommand<object>(SetSheet);
- SetAutoRotateCommand = new DelegateCommand(SetAutoRotate);
- }
- private void InitSubsetList()
- {
- SubsetList.Clear();
- SubsetList.Add("双面");
- SubsetList.Add("仅正面");
- SubsetList.Add("仅背面");
- }
- private void InitBindingList()
- {
- BindingList.Clear();
- BindingList.Add("左");
- BindingList.Add("右");
- }
- private void InitBookletInfo()
- {
- BookletInfo.EnumBookletSubset = (EnumBookletSubset)SubsetIndex;
- BookletInfo.EnumBookletBinding = (EnumBookletBinding)BindingIndex;
- if (PaperFrom != null)
- {
- BookletInfo.BeginPaperIndex = (int)PaperFrom;
- }
- else
- {
- BookletInfo.BeginPaperIndex = 1;
- }
- if (PaperTo != null)
- {
- BookletInfo.EndPaperIndex = (int)PaperTo;
- }
- else
- {
- BookletInfo.EndPaperIndex = MaxPaperNumber;
- }
- BookletInfo.IsAutoRotate = IsAutoRotate;
- }
- public void SetSheet(object e)
- {
- var txt = e as TextBox;
- if (txt != null)
- {
- if (PaperFrom == null)
- {
- PaperFrom = 1;
- }
- if (PaperTo == null)
- {
- PaperTo = MaxPaperNumber;
- }
- if (txt.Name == "PaperFromTxt")
- {
- PaperFrom = int.Parse(txt.Text);
- }
- else
- {
- PaperTo= int.Parse(txt.Text);
- }
- BookletInfo.BeginPaperIndex=(int)PaperFrom;
- BookletInfo.EndPaperIndex=(int)PaperTo;
- SendBookletInfo();
- }
- }
- public void SetAutoRotate()
- {
- BookletInfo.IsAutoRotate = IsAutoRotate;
- SendBookletInfo();
- }
- public void SendBookletInfo()
- {
- if (BookletInfo != null)
- {
- if (BookletInfo.BeginPaperIndex > BookletInfo.EndPaperIndex)
- {
- PaperFrom = PaperTo;
- BookletInfo.BeginPaperIndex = (int)PaperFrom;
- }
- this.eventAggregator.GetEvent<SendPrintSettingsModInfoEvent>().Publish(new PrintModInfoWithUnicode { printModInfo = BookletInfo, Unicode = this.Unicode });
- }
- }
- public bool IsNavigationTarget(NavigationContext navigationContext)
- {
- return true;
- }
- public void OnNavigatedFrom(NavigationContext navigationContext)
- {
- }
- public void OnNavigatedTo(NavigationContext navigationContext)
- {
- navigationContext.Parameters.TryGetValue<string>("Unicode", out Unicode);
- if (navigationContext.Parameters.ContainsKey("document"))
- {
- document = navigationContext.Parameters.GetValue<CPDFDocument>("document");
- MaxPaperNumber = (document.PageCount % 4 == 0) ? (document.PageCount / 4) : (document.PageCount / 4 + 1);
- if (PaperFrom == null)
- {
- PaperFrom = 1;
- }
- if (PaperTo == null)
- {
- PaperTo = MaxPaperNumber;
- }
- InitBookletInfo();
- SendBookletInfo();
- }
- }
- }
- }
|