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.Linq; using System.Windows.Controls; namespace PDF_Master.ViewModels.Dialog.HomePageToolsDialogs.HomePagePrinter { public class HomePagePrinterModMultipleContentViewModel : BindableBase, INavigationAware { private IEventAggregator eventAggregator; private string Unicode = null; private int? _verticalPageNumber; public int? VerticalPageNumber { get { return _verticalPageNumber; } set { SetProperty(ref _verticalPageNumber, value); } } private int? _horizontalPageNumber; public int? HorizontalPageNumber { get { return _horizontalPageNumber; } set { SetProperty(ref _horizontalPageNumber, value); } } private bool _isAutoRotate; public bool IsAutoRotate { get { return _isAutoRotate; } set { _isAutoRotate = value; } } private List _pageMatrixList; public List PageMatrixList { get { return _pageMatrixList; } set { _pageMatrixList = value; } } private int _pageMatrixIndex = 1; /// /// 0: 1x2 /// 1: 2x2 /// 2: 3x2 /// 3: 3x3 /// 4: 4x4 /// 5: 自定义 /// public int PageMatrixIndex { get { return _pageMatrixIndex; } set { _pageMatrixIndex = value; if (_pageMatrixIndex < 5) { EnableCustomiseMatrix = false; } else { EnableCustomiseMatrix = true; } SetPageMatrixValue(value); } } private List _pageOrderList; public List PageOrderList { get { return _pageOrderList; } set { _pageOrderList = value; } } private int _pageOrderIndex; /// /// 0: Horizontal /// 1: HorizontalReversed /// 0: Vertical /// 0: VerticalReversed /// public int PageOrderIndex { get { return _pageOrderIndex; } set { _pageOrderIndex = value; SetMultipleInfo(); SendMultipleInfo(); } } private bool _enableCustomiseMatrix; public bool EnableCustomiseMatrix { get { return _enableCustomiseMatrix; } set { SetProperty(ref _enableCustomiseMatrix, value); } } private MultipleInfo _multipleInfo; /// /// 多页参数 /// public MultipleInfo MultipleInfo { get { return _multipleInfo; } set { _multipleInfo = value; } } private bool _isDuplexModLongEdge = true; public bool IsDuplexModLongEdge { get { return _isDuplexModLongEdge; } set { _isDuplexModLongEdge = value; } } private bool _isDuplexModShortEdge = false; public bool IsDuplexModShortEdge { get { return _isDuplexModShortEdge; } set { _isDuplexModShortEdge = value; } } public DelegateCommand SetPageMatrixCommand { get; set; } public DelegateCommand SetCustomMatrixCommand { get; set; } public DelegateCommand SetPageOrderCommand { get; set; } public DelegateCommand SetAutoRotateCommand { get; set; } public DelegateCommand UnlockDuplexCommand { get; set; } public DelegateCommand ChangeDuplexModCommand { get; set; } public HomePagePrinterModMultipleContentViewModel(IEventAggregator eventAggregator) { this.eventAggregator = eventAggregator; PageMatrixIndex = 0; PageOrderIndex = 0; PageMatrixList = new List(); InitPageMatrixList(); PageOrderList = new List(); InitPageOrderList(); SetPageMatrixCommand = new DelegateCommand(SetPageMatrix); SetCustomMatrixCommand = new DelegateCommand(SetCustomMatrix); SetPageOrderCommand = new DelegateCommand(SetPageOrder); SetAutoRotateCommand = new DelegateCommand(SetAutoRotate); UnlockDuplexCommand = new DelegateCommand(UnlockDuplex); ChangeDuplexModCommand = new DelegateCommand(ChangeDuplexMod); MultipleInfo = new MultipleInfo(); MultipleInfo.EnumPrintMod = EnumPrintMod.StatusMultiple; } public void SetPageMatrix(object e) { SetMultipleInfo(); SendMultipleInfo(); } public void SetCustomMatrix(object e) { SetMultipleInfo(); SendMultipleInfo(); } public void SetPageOrder() { SetMultipleInfo(); SendMultipleInfo(); } public void SetAutoRotate() { SetMultipleInfo(); SendMultipleInfo(); } public void SendMultipleInfo() { if (MultipleInfo != null) { this.eventAggregator.GetEvent().Publish(new PrintModInfoWithUnicode { printModInfo = MultipleInfo, Unicode = this.Unicode }); } } public void UnlockDuplex(object e) { var chk = e as CheckBox; if (chk != null) { if (chk.IsChecked == false) { this.eventAggregator.GetEvent().Publish(new EnumDuplexPrintModWithUnicode { enumDuplexPrintMod = EnumDuplexPrintMod.StatusNone, Unicode = this.Unicode }); } else { if (IsDuplexModLongEdge) { this.eventAggregator.GetEvent().Publish(new EnumDuplexPrintModWithUnicode { enumDuplexPrintMod = EnumDuplexPrintMod.StatusFlipLongEdge, Unicode = this.Unicode }); } else { this.eventAggregator.GetEvent().Publish(new EnumDuplexPrintModWithUnicode { enumDuplexPrintMod = EnumDuplexPrintMod.StatusFlipShortEdge, Unicode = this.Unicode }); } } } } public void ChangeDuplexMod(object e) { var rdo = e as RadioButton; if (rdo != null) { if (rdo.Name == "DuplexModLongEdgeRdo") { this.eventAggregator.GetEvent().Publish(new EnumDuplexPrintModWithUnicode { enumDuplexPrintMod = EnumDuplexPrintMod.StatusFlipLongEdge, Unicode = this.Unicode }); } else { this.eventAggregator.GetEvent().Publish(new EnumDuplexPrintModWithUnicode { enumDuplexPrintMod = EnumDuplexPrintMod.StatusFlipShortEdge, Unicode = this.Unicode }); } } } private void InitPageMatrixList() { PageMatrixList.Clear(); PageMatrixList.Add("2"); PageMatrixList.Add("4"); PageMatrixList.Add("6"); PageMatrixList.Add("9"); PageMatrixList.Add("16"); PageMatrixList.Add("自定义"); } private void InitPageOrderList() { PageOrderList.Clear(); PageOrderList.Add("横向"); PageOrderList.Add("横向倒序"); PageOrderList.Add("纵向"); PageOrderList.Add("纵向倒序"); } private void SetPageMatrixValue(int pageMatrixIndex) { switch (pageMatrixIndex) { case 0: HorizontalPageNumber = 1; VerticalPageNumber = 2; SetMultipleInfo(); SendMultipleInfo(); break; case 1: HorizontalPageNumber = 2; VerticalPageNumber = 2; SetMultipleInfo(); SendMultipleInfo(); break; case 2: HorizontalPageNumber = 3; VerticalPageNumber = 2; SetMultipleInfo(); SendMultipleInfo(); break; case 3: HorizontalPageNumber = 3; VerticalPageNumber = 3; SetMultipleInfo(); SendMultipleInfo(); break; case 4: HorizontalPageNumber = 4; VerticalPageNumber = 4; SetMultipleInfo(); SendMultipleInfo(); break; case 5: HorizontalPageNumber = null; VerticalPageNumber = null; break; } } private void SetMultipleInfo() { if (HorizontalPageNumber == null) { HorizontalPageNumber = 1; } if (VerticalPageNumber == null) { VerticalPageNumber = 1; } if (MultipleInfo != null) { MultipleInfo.VerticalPageNumber = (int)VerticalPageNumber; MultipleInfo.HorizontalPageNumber = (int)HorizontalPageNumber; MultipleInfo.IsAutoRotate = IsAutoRotate; MultipleInfo.EnumPageOrder = (EnumPageOrder)PageOrderIndex; } } public bool IsNavigationTarget(NavigationContext navigationContext) { return true; } public void OnNavigatedFrom(NavigationContext navigationContext) { } public void OnNavigatedTo(NavigationContext navigationContext) { SetMultipleInfo(); SendMultipleInfo(); navigationContext.Parameters.TryGetValue("Unicode", out Unicode); } } }