using ComPDFKitViewer.PdfViewer; using Microsoft.Office.Interop.Word; 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.Printing; using System.Windows; using System.Windows.Controls; using System.Windows.Media; namespace PDF_Master.ViewModels.Dialog.HomePageToolsDialogs.HomePagePrinter { public class HomePagePrinterModPosterContentViewModel : BindableBase, INavigationAware { private IEventAggregator eventAggregator; private string Unicode = null; private Visibility _pageRangeSettingVisibility = Visibility.Visible; public bool HasCutMarks = false; public bool HasLabel = false; private string _defaultLabel; public string DefaultLabel { get { return _defaultLabel; } set { _defaultLabel = value; } } private string _labelString; public string LabelString { get { return _labelString; } set { _labelString = value; eventAggregator.GetEvent().Publish(new LabelWithUnicode { Label = this.LabelString, Unicode = this.Unicode}); } } public Visibility PageRangeSettingVisibility { get => _pageRangeSettingVisibility; set => SetProperty(ref _pageRangeSettingVisibility, value); } private Visibility _pagesPerSheetVisibility = Visibility.Hidden; public Visibility PagesPerSheetVisibility { get => _pagesPerSheetVisibility; set => SetProperty(ref _pagesPerSheetVisibility, value); } private string _tileRatio = "100"; public string TileRatio { get => _tileRatio; set => SetProperty(ref _tileRatio, value); } private PosterInfo _posterInfo = new PosterInfo(); public PosterInfo PosterInfo { get => _posterInfo; set => _posterInfo = value; } private List _pageSheetList = new List(); /// /// 0: 1x2 /// 1: 2x2 /// 2: 3x2 /// 3: 3x3 /// 4: 4x4 /// 5: 自定义 /// public List PageSheetList { get => _pageSheetList; set => _pageSheetList = value; } private bool _enableCustomSheet; public bool EnableCustomSheet { get { return _enableCustomSheet; } set { SetProperty(ref _enableCustomSheet, value); } } private int _pageSheetIndex = 1; public int PageSheetIndex { get { return _pageSheetIndex; } set { _pageSheetIndex = value; if (_pageSheetIndex < 5) { EnableCustomSheet = false; } else { EnableCustomSheet = true; } SetPageSheetValue(value); } } private int? _horizontalSheetNumber = 2; public int? HorizontalSheetNumber { get => _horizontalSheetNumber; set { if (value > 8) { SetProperty(ref _horizontalSheetNumber, 8); }else if (value < 1) { SetProperty(ref _horizontalSheetNumber, 1); } else { SetProperty(ref _horizontalSheetNumber, value); } } } private int? _verticalSheetNumber = 2; public int? VerticalSheetNumber { get => _verticalSheetNumber; set { if (value > 8) { SetProperty(ref _verticalSheetNumber, 8); } else if (value < 1) { SetProperty(ref _verticalSheetNumber, 1); } else { SetProperty(ref _verticalSheetNumber, value); } } } private double? _overlapNumber = 0; public double? OverlapNumber { get => _overlapNumber; set { if (value > 5.08) { SetProperty(ref _overlapNumber, 5.08); } else if (value < 0) { SetProperty(ref _overlapNumber, 0); } else { SetProperty(ref _overlapNumber, value); } } } public DelegateCommand SetModPosterStatusCommand { get; set; } public DelegateCommand SetSheetCommand { get; set; } public DelegateCommand SetCustomSheetCommand { get; set; } public DelegateCommand SetOverlapCommand { get; set; } public DelegateCommand SetCutMarksCommand { get; set; } public DelegateCommand SetLabelCommand { get; set; } public DelegateCommand SetTileRatioCommand { get; set; } HomePagePrinterModPosterContentViewModel(IEventAggregator eventAggregator) { this.eventAggregator = eventAggregator; SetModPosterStatusCommand = new DelegateCommand(SetModPosterStatus); SetSheetCommand = new DelegateCommand(SetSheet); SetCustomSheetCommand = new DelegateCommand(SetCustomSheet); SetOverlapCommand = new DelegateCommand(SetOverlap); SetCutMarksCommand = new DelegateCommand(SetCutMarks); SetLabelCommand = new DelegateCommand(SetLabel); SetTileRatioCommand = new DelegateCommand(SetTileRatio); InitComponent(); PosterInfo.EnumPrintMod = EnumPrintMod.StatusPoster; } public void InitPageSheetList() { PageSheetList.Clear(); PageSheetList.Add("2"); PageSheetList.Add("4"); PageSheetList.Add("6"); PageSheetList.Add("9"); PageSheetList.Add("16"); PageSheetList.Add("Custom"); } public void InitComponent() { InitPageSheetList(); } public void SetModPosterStatus(object e) { var rdo = e as RadioButton; if (rdo.Name == "StatusTileRdo") { PosterInfo.EnumPosterMod = EnumPosterMod.StatusTile; PageRangeSettingVisibility = Visibility.Visible; PagesPerSheetVisibility = Visibility.Hidden; } else { PosterInfo.EnumPosterMod = EnumPosterMod.StatusSplit; PageRangeSettingVisibility = Visibility.Hidden; PagesPerSheetVisibility = Visibility.Visible; } SendPosterInfo(); } public void SetSheet(object e) { SendPosterInfo(); } public void SetCustomSheet() { SendPosterInfo(); } public void SetOverlap() { SendPosterInfo(); } public void SetTileRatio() { int previousDisplayRatio = PosterInfo.TileRatio; PosterInfo.TileRatio = int.Parse(TileRatio); if (previousDisplayRatio != PosterInfo.TileRatio) { SendPosterInfo(); } } public void SetPageSheetValue(int sheetIndex) { switch (sheetIndex) { case 0: HorizontalSheetNumber = 1; VerticalSheetNumber = 2; break; case 1: HorizontalSheetNumber = 2; VerticalSheetNumber = 2; break; case 2: HorizontalSheetNumber = 3; VerticalSheetNumber = 2; break; case 3: HorizontalSheetNumber = 3; VerticalSheetNumber = 3; break; case 4: HorizontalSheetNumber = 4; VerticalSheetNumber = 4; break; case 5: HorizontalSheetNumber = null; VerticalSheetNumber = null; break; } SendPosterInfo(); } public void SendPosterInfo() { if (HorizontalSheetNumber == null) { HorizontalSheetNumber = 1; } if (VerticalSheetNumber == null) { VerticalSheetNumber = 1; } if (OverlapNumber == null) { OverlapNumber = 0; } else if (OverlapNumber < 0) { OverlapNumber = 0; } else if (OverlapNumber > 5.08) { OverlapNumber = 5.08; } if (PosterInfo != null) { if (PosterInfo.EnumPosterMod == EnumPosterMod.StatusTile) { PosterInfo.TileRatio = int.Parse(TileRatio); } else { PosterInfo.HorizontalSheetNumber = (int)HorizontalSheetNumber; PosterInfo.VerticalSheetNumber = (int)VerticalSheetNumber; } PosterInfo.OverLap = (double)OverlapNumber; PosterInfo.HasCutMarks = HasCutMarks; PosterInfo.HasLabel = HasLabel; } this.eventAggregator.GetEvent().Publish(new PrintModInfoWithUnicode { printModInfo = PosterInfo, Unicode = this.Unicode }); } public void SetCutMarks(object e) { var chk = e as System.Windows.Controls.CheckBox; if(chk.IsChecked == true) { HasCutMarks = true; } else { HasCutMarks = false; } SendPosterInfo(); } public void SetLabel(object e) { var chk = e as System.Windows.Controls.CheckBox; if (chk.IsChecked == true) { HasLabel = true; } else { HasLabel = false; } SendPosterInfo(); } public bool IsNavigationTarget(NavigationContext navigationContext) { return true; } public void OnNavigatedFrom(NavigationContext navigationContext) { } public void OnNavigatedTo(NavigationContext navigationContext) { DefaultLabel = "(Column, Row) -Page -xxx.pdf - yyyy/MM/dd hh-mm-ss"; navigationContext.Parameters.TryGetValue("Unicode", out Unicode); SendPosterInfo(); } } }