HomePagePrinterModSizeContentViewModel.cs 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. using PDF_Master.EventAggregators;
  2. using PDF_Master.Model.Dialog.HomePageToolsDialogs.HomePagePrinter;
  3. using Prism.Commands;
  4. using Prism.Events;
  5. using Prism.Mvvm;
  6. using Prism.Regions;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Linq;
  10. using System.Management.Instrumentation;
  11. using System.Windows.Controls;
  12. namespace PDF_Master.ViewModels.Dialog.HomePageToolsDialogs.HomePagePrinter
  13. {
  14. public class HomePagePrinterModSizeContentViewModel : BindableBase, INavigationAware
  15. {
  16. private IEventAggregator eventAggregator;
  17. private string Unicode = null;
  18. public string CurrentSelectedRdoName = "StatusAdaptiveRdo";
  19. private string _displayRatio = "100";
  20. public string DisplayRatio
  21. {
  22. get { return _displayRatio; }
  23. set { SetProperty(ref _displayRatio, value); }
  24. }
  25. private SizeInfo _sizeInfo;
  26. public SizeInfo SizeInfo
  27. {
  28. get { return _sizeInfo; }
  29. set { _sizeInfo = value; }
  30. }
  31. private bool _isDuplexModLongEdge = true;
  32. public bool IsDuplexModLongEdge
  33. {
  34. get { return _isDuplexModLongEdge;}
  35. set { _isDuplexModLongEdge = value; }
  36. }
  37. private bool _isDuplexModShortEdge = false;
  38. public bool IsDuplexModShortEdge
  39. {
  40. get { return _isDuplexModShortEdge;}
  41. set { _isDuplexModShortEdge = value;}
  42. }
  43. public DelegateCommand<object> SetModSizeStatusCommand { get; set; }
  44. public DelegateCommand SetDisplayRatioCommand { get; set; }
  45. public DelegateCommand<object> UnlockDuplexCommand { get; set; }
  46. public DelegateCommand<object> ChangeDuplexModCommand { get; set; }
  47. public DelegateCommand SendSizeInfoCommand { get; set; }
  48. public HomePagePrinterModSizeContentViewModel(IEventAggregator eventAggregator)
  49. {
  50. this.eventAggregator = eventAggregator;
  51. SizeInfo = new SizeInfo();
  52. SizeInfo.EnumPrintMod = EnumPrintMod.StatusSize;
  53. SetModSizeStatusCommand = new DelegateCommand<object>(SetModSizeStatus);
  54. SetDisplayRatioCommand = new DelegateCommand(SetDisplayRatio);
  55. UnlockDuplexCommand = new DelegateCommand<object>(UnlockDuplex);
  56. ChangeDuplexModCommand = new DelegateCommand<object>(ChangeDuplexMod);
  57. }
  58. public void UnlockDuplex(object e)
  59. {
  60. var chk = e as CheckBox;
  61. if (chk != null)
  62. {
  63. if (chk.IsChecked == false)
  64. {
  65. this.eventAggregator.GetEvent<SendDuplexPrintModEvent>().Publish(new EnumDuplexPrintModWithUnicode { enumDuplexPrintMod = EnumDuplexPrintMod.StatusNone, Unicode = this.Unicode });
  66. }
  67. else
  68. {
  69. if (IsDuplexModLongEdge)
  70. {
  71. this.eventAggregator.GetEvent<SendDuplexPrintModEvent>().Publish(new EnumDuplexPrintModWithUnicode { enumDuplexPrintMod = EnumDuplexPrintMod.StatusFlipLongEdge, Unicode = this.Unicode });
  72. }
  73. else
  74. {
  75. this.eventAggregator.GetEvent<SendDuplexPrintModEvent>().Publish(new EnumDuplexPrintModWithUnicode { enumDuplexPrintMod = EnumDuplexPrintMod.StatusFlipShortEdge, Unicode = this.Unicode });
  76. }
  77. }
  78. }
  79. }
  80. public void ChangeDuplexMod(object e)
  81. {
  82. var rdo = e as RadioButton;
  83. if (rdo != null)
  84. {
  85. if (rdo.Name == "DuplexModLongEdgeRdo")
  86. {
  87. this.eventAggregator.GetEvent<SendDuplexPrintModEvent>().Publish(new EnumDuplexPrintModWithUnicode { enumDuplexPrintMod = EnumDuplexPrintMod.StatusFlipLongEdge, Unicode = this.Unicode });
  88. }
  89. else
  90. {
  91. this.eventAggregator.GetEvent<SendDuplexPrintModEvent>().Publish(new EnumDuplexPrintModWithUnicode { enumDuplexPrintMod = EnumDuplexPrintMod.StatusFlipShortEdge, Unicode = this.Unicode });
  92. }
  93. }
  94. }
  95. public void SendSizeInfo()
  96. {
  97. if (SizeInfo != null)
  98. {
  99. this.eventAggregator.GetEvent<SendPrintSettingsModInfoEvent>().Publish(new PrintModInfoWithUnicode { printModInfo = SizeInfo, Unicode = this.Unicode});
  100. }
  101. }
  102. public void SetModSizeStatus(object e)
  103. {
  104. var rdo = e as RadioButton;
  105. if (rdo.Name == CurrentSelectedRdoName)
  106. {
  107. return;
  108. }
  109. else
  110. {
  111. CurrentSelectedRdoName = rdo.Name;
  112. if (rdo.Name == "StatusAdaptiveRdo")
  113. {
  114. SizeInfo.EnumSizeType = EnumSizeType.StatusAdaptive;
  115. }
  116. else if (rdo.Name == "StatusActuralRdo")
  117. {
  118. SizeInfo.EnumSizeType = EnumSizeType.StatusActural;
  119. }
  120. else
  121. {
  122. SizeInfo.EnumSizeType = EnumSizeType.StatusCustomized;
  123. }
  124. if (SizeInfo.EnumSizeType == EnumSizeType.StatusAdaptive || SizeInfo.EnumSizeType == EnumSizeType.StatusActural || (SizeInfo.EnumSizeType == EnumSizeType.StatusCustomized)&& DisplayRatio != null)
  125. {
  126. SendSizeInfo();
  127. }
  128. }
  129. }
  130. public void SetDisplayRatio()
  131. {
  132. int previousDisplayRatio = SizeInfo.DisplayRatio;
  133. SizeInfo.DisplayRatio = int.Parse(DisplayRatio);
  134. if (previousDisplayRatio != SizeInfo.DisplayRatio)
  135. {
  136. SendSizeInfo();
  137. }
  138. }
  139. public bool IsNavigationTarget(NavigationContext navigationContext)
  140. {
  141. return true;
  142. }
  143. public void OnNavigatedFrom(NavigationContext navigationContext)
  144. {
  145. }
  146. public void OnNavigatedTo(NavigationContext navigationContext)
  147. {
  148. navigationContext.Parameters.TryGetValue<string>("Unicode", out Unicode);
  149. SendSizeInfo();
  150. }
  151. }
  152. }