using ComPDFKit.PDFDocument; using PDF_Office.EventAggregators; using PDF_Office.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_Office.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 _subsetList; public List SubsetList { get { return _subsetList; } set { _subsetList = value; } } private int _subsetIndex = 0; public int SubsetIndex { get { return _subsetIndex; } set { _subsetIndex = value; InitBookletInfo(); SendBookletInfo(); } } private List _bindingList; public List 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 SetSheetCommand { get; set; } public DelegateCommand SetAutoRotateCommand { get; set; } public HomePagePrinterModBookletContentViewModel(IEventAggregator eventAggregator) { this.eventAggregator = eventAggregator; SubsetList = new List(); InitSubsetList(); BindingList = new List(); InitBindingList(); BookletInfo = new BookletInfo(); BookletInfo.EnumPrintMod = EnumPrintMod.StatusBooklet; SetSheetCommand = new DelegateCommand(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().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("Unicode", out Unicode); if (navigationContext.Parameters.ContainsKey("document")) { document = navigationContext.Parameters.GetValue("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(); } else { Trace.WriteLine("No Key Named{0}", "document"); } } } }