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.Linq; using System.Management.Instrumentation; using System.Windows.Controls; namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs.HomePagePrinter { public class HomePagePrinterModSizeContentViewModel : BindableBase, INavigationAware { private IEventAggregator eventAggregator; private string Unicode = null; public string CurrentSelectedRdoName = "StatusAdaptiveRdo"; private string _displayRatio = "100"; public string DisplayRatio { get { return _displayRatio; } set { SetProperty(ref _displayRatio, value); } } private SizeInfo _sizeInfo; public SizeInfo SizeInfo { get { return _sizeInfo; } set { _sizeInfo = 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 SetModSizeStatusCommand { get; set; } public DelegateCommand SetDisplayRatioCommand { get; set; } public DelegateCommand UnlockDuplexCommand { get; set; } public DelegateCommand ChangeDuplexModCommand { get; set; } public DelegateCommand SendSizeInfoCommand { get; set; } public HomePagePrinterModSizeContentViewModel(IEventAggregator eventAggregator) { this.eventAggregator = eventAggregator; SizeInfo = new SizeInfo(); SizeInfo.EnumPrintMod = EnumPrintMod.StatusSize; SetModSizeStatusCommand = new DelegateCommand(SetModSizeStatus); SetDisplayRatioCommand = new DelegateCommand(SetDisplayRatio); UnlockDuplexCommand = new DelegateCommand(UnlockDuplex); ChangeDuplexModCommand = new DelegateCommand(ChangeDuplexMod); } 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 }); } } } public void SendSizeInfo() { if (SizeInfo != null) { this.eventAggregator.GetEvent().Publish(new PrintModInfoWithUnicode { printModInfo = SizeInfo, Unicode = this.Unicode}); } } public void SetModSizeStatus(object e) { var rdo = e as RadioButton; if (rdo.Name == CurrentSelectedRdoName) { return; } else { CurrentSelectedRdoName = rdo.Name; if (rdo.Name == "StatusAdaptiveRdo") { SizeInfo.EnumSizeType = EnumSizeType.StatusAdaptive; } else if (rdo.Name == "StatusActuralRdo") { SizeInfo.EnumSizeType = EnumSizeType.StatusActural; } else { SizeInfo.EnumSizeType = EnumSizeType.StatusCustomized; } if (SizeInfo.EnumSizeType == EnumSizeType.StatusAdaptive || SizeInfo.EnumSizeType == EnumSizeType.StatusActural || (SizeInfo.EnumSizeType == EnumSizeType.StatusCustomized)&& DisplayRatio != null) { SendSizeInfo(); } } } public void SetDisplayRatio() { int previousDisplayRatio = SizeInfo.DisplayRatio; SizeInfo.DisplayRatio = int.Parse(DisplayRatio); if (previousDisplayRatio != SizeInfo.DisplayRatio) { SendSizeInfo(); } } public bool IsNavigationTarget(NavigationContext navigationContext) { return true; } public void OnNavigatedFrom(NavigationContext navigationContext) { } public void OnNavigatedTo(NavigationContext navigationContext) { navigationContext.Parameters.TryGetValue("Unicode", out Unicode); SendSizeInfo(); } } }