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. DisplayRatio = "100";
  54. SetModSizeStatusCommand = new DelegateCommand<object>(SetModSizeStatus);
  55. SetDisplayRatioCommand = new DelegateCommand(SetDisplayRatio);
  56. UnlockDuplexCommand = new DelegateCommand<object>(UnlockDuplex);
  57. ChangeDuplexModCommand = new DelegateCommand<object>(ChangeDuplexMod);
  58. }
  59. public void UnlockDuplex(object e)
  60. {
  61. var chk = e as CheckBox;
  62. if (chk != null)
  63. {
  64. if (chk.IsChecked == false)
  65. {
  66. this.eventAggregator.GetEvent<SendDuplexPrintModEvent>().Publish(new EnumDuplexPrintModWithUnicode { enumDuplexPrintMod = EnumDuplexPrintMod.StatusNone, Unicode = this.Unicode });
  67. }
  68. else
  69. {
  70. if (IsDuplexModLongEdge)
  71. {
  72. this.eventAggregator.GetEvent<SendDuplexPrintModEvent>().Publish(new EnumDuplexPrintModWithUnicode { enumDuplexPrintMod = EnumDuplexPrintMod.StatusFlipLongEdge, Unicode = this.Unicode });
  73. }
  74. else
  75. {
  76. this.eventAggregator.GetEvent<SendDuplexPrintModEvent>().Publish(new EnumDuplexPrintModWithUnicode { enumDuplexPrintMod = EnumDuplexPrintMod.StatusFlipShortEdge, Unicode = this.Unicode });
  77. }
  78. }
  79. }
  80. }
  81. public void ChangeDuplexMod(object e)
  82. {
  83. var rdo = e as RadioButton;
  84. if (rdo != null)
  85. {
  86. if (rdo.Name == "DuplexModLongEdgeRdo")
  87. {
  88. this.eventAggregator.GetEvent<SendDuplexPrintModEvent>().Publish(new EnumDuplexPrintModWithUnicode { enumDuplexPrintMod = EnumDuplexPrintMod.StatusFlipLongEdge, Unicode = this.Unicode });
  89. }
  90. else
  91. {
  92. this.eventAggregator.GetEvent<SendDuplexPrintModEvent>().Publish(new EnumDuplexPrintModWithUnicode { enumDuplexPrintMod = EnumDuplexPrintMod.StatusFlipShortEdge, Unicode = this.Unicode });
  93. }
  94. }
  95. }
  96. public void SendSizeInfo()
  97. {
  98. if (SizeInfo != null)
  99. {
  100. this.eventAggregator.GetEvent<SendPrintSettingsModInfoEvent>().Publish(new PrintModInfoWithUnicode { printModInfo = SizeInfo, Unicode = this.Unicode});
  101. }
  102. }
  103. public void SetModSizeStatus(object e)
  104. {
  105. var rdo = e as RadioButton;
  106. if (rdo.Name == CurrentSelectedRdoName)
  107. {
  108. return;
  109. }
  110. else
  111. {
  112. CurrentSelectedRdoName = rdo.Name;
  113. if (rdo.Name == "StatusAdaptiveRdo")
  114. {
  115. SizeInfo.EnumSizeType = EnumSizeType.StatusAdaptive;
  116. }
  117. else if (rdo.Name == "StatusActuralRdo")
  118. {
  119. SizeInfo.EnumSizeType = EnumSizeType.StatusActural;
  120. }
  121. else
  122. {
  123. SizeInfo.EnumSizeType = EnumSizeType.StatusCustomized;
  124. }
  125. if (SizeInfo.EnumSizeType == EnumSizeType.StatusAdaptive || SizeInfo.EnumSizeType == EnumSizeType.StatusActural || (SizeInfo.EnumSizeType == EnumSizeType.StatusCustomized)&& DisplayRatio != null)
  126. {
  127. SendSizeInfo();
  128. }
  129. }
  130. }
  131. public void SetDisplayRatio()
  132. {
  133. int previousDisplayRatio = SizeInfo.DisplayRatio;
  134. SizeInfo.DisplayRatio = int.Parse(DisplayRatio);
  135. if (previousDisplayRatio != SizeInfo.DisplayRatio)
  136. {
  137. SendSizeInfo();
  138. }
  139. }
  140. public bool IsNavigationTarget(NavigationContext navigationContext)
  141. {
  142. return true;
  143. }
  144. public void OnNavigatedFrom(NavigationContext navigationContext)
  145. {
  146. }
  147. public void OnNavigatedTo(NavigationContext navigationContext)
  148. {
  149. navigationContext.Parameters.TryGetValue<string>("Unicode", out Unicode);
  150. SendSizeInfo();
  151. }
  152. }
  153. }