HomePagePrinterModBookletContentViewModel.cs 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. using ComPDFKit.PDFDocument;
  2. using PDF_Master.EventAggregators;
  3. using PDF_Master.Model.Dialog.HomePageToolsDialogs.HomePagePrinter;
  4. using Prism.Commands;
  5. using Prism.Events;
  6. using Prism.Mvvm;
  7. using Prism.Regions;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Diagnostics;
  11. using System.Linq;
  12. using System.Management.Instrumentation;
  13. using System.Windows.Controls;
  14. namespace PDF_Master.ViewModels.Dialog.HomePageToolsDialogs.HomePagePrinter
  15. {
  16. public class HomePagePrinterModBookletContentViewModel : BindableBase, INavigationAware
  17. {
  18. private IEventAggregator eventAggregator;
  19. private string Unicode = null;
  20. private CPDFDocument document;
  21. private bool _isAutoRotate;
  22. public bool IsAutoRotate
  23. {
  24. get { return _isAutoRotate; }
  25. set { _isAutoRotate = value; }
  26. }
  27. private int? _paperFrom = 1;
  28. public int? PaperFrom
  29. {
  30. get
  31. {
  32. return _paperFrom;
  33. }
  34. set
  35. {
  36. if (PaperTo == null)
  37. {
  38. SetProperty(ref _paperFrom, 1);
  39. }
  40. else if (value < PaperTo)
  41. {
  42. SetProperty(ref _paperFrom, value);
  43. }
  44. else
  45. {
  46. SetProperty(ref _paperFrom, PaperTo);
  47. }
  48. }
  49. }
  50. private int? _paperTo;
  51. public int? PaperTo
  52. {
  53. get
  54. {
  55. return _paperTo;
  56. }
  57. set
  58. {
  59. if (value < MaxPaperNumber)
  60. {
  61. SetProperty(ref _paperTo, value);
  62. }
  63. else
  64. {
  65. SetProperty(ref _paperTo, MaxPaperNumber);
  66. }
  67. }
  68. }
  69. private List<string> _subsetList;
  70. public List<string> SubsetList
  71. {
  72. get { return _subsetList; }
  73. set { _subsetList = value; }
  74. }
  75. private int _subsetIndex = 0;
  76. public int SubsetIndex
  77. {
  78. get { return _subsetIndex; }
  79. set
  80. {
  81. _subsetIndex = value;
  82. InitBookletInfo();
  83. SendBookletInfo();
  84. }
  85. }
  86. private List<string> _bindingList;
  87. public List<string> BindingList
  88. {
  89. get { return _bindingList; }
  90. set { _bindingList = value; }
  91. }
  92. private int _bindingIndex = 0;
  93. public int BindingIndex
  94. {
  95. get { return _bindingIndex; }
  96. set
  97. {
  98. _bindingIndex = value;
  99. InitBookletInfo();
  100. SendBookletInfo();
  101. }
  102. }
  103. private BookletInfo _bookletInfo;
  104. public BookletInfo BookletInfo
  105. {
  106. get { return _bookletInfo; }
  107. set { _bookletInfo = value; }
  108. }
  109. private int _maxPaperNumber;
  110. public int MaxPaperNumber
  111. {
  112. get { return _maxPaperNumber; }
  113. set { _maxPaperNumber = value; }
  114. }
  115. public DelegateCommand<object> SetSheetCommand { get; set; }
  116. public DelegateCommand SetAutoRotateCommand { get; set; }
  117. public HomePagePrinterModBookletContentViewModel(IEventAggregator eventAggregator)
  118. {
  119. this.eventAggregator = eventAggregator;
  120. SubsetList = new List<string>();
  121. InitSubsetList();
  122. BindingList = new List<string>();
  123. InitBindingList();
  124. BookletInfo = new BookletInfo();
  125. BookletInfo.EnumPrintMod = EnumPrintMod.StatusBooklet;
  126. SetSheetCommand = new DelegateCommand<object>(SetSheet);
  127. SetAutoRotateCommand = new DelegateCommand(SetAutoRotate);
  128. }
  129. private void InitSubsetList()
  130. {
  131. SubsetList.Clear();
  132. SubsetList.Add("双面");
  133. SubsetList.Add("仅正面");
  134. SubsetList.Add("仅背面");
  135. }
  136. private void InitBindingList()
  137. {
  138. BindingList.Clear();
  139. BindingList.Add("左");
  140. BindingList.Add("右");
  141. }
  142. private void InitBookletInfo()
  143. {
  144. BookletInfo.EnumBookletSubset = (EnumBookletSubset)SubsetIndex;
  145. BookletInfo.EnumBookletBinding = (EnumBookletBinding)BindingIndex;
  146. if (PaperFrom != null)
  147. {
  148. BookletInfo.BeginPaperIndex = (int)PaperFrom;
  149. }
  150. else
  151. {
  152. BookletInfo.BeginPaperIndex = 1;
  153. }
  154. if (PaperTo != null)
  155. {
  156. BookletInfo.EndPaperIndex = (int)PaperTo;
  157. }
  158. else
  159. {
  160. BookletInfo.EndPaperIndex = MaxPaperNumber;
  161. }
  162. BookletInfo.IsAutoRotate = IsAutoRotate;
  163. }
  164. public void SetSheet(object e)
  165. {
  166. var txt = e as TextBox;
  167. if (txt != null)
  168. {
  169. if (PaperFrom == null)
  170. {
  171. PaperFrom = 1;
  172. }
  173. if (PaperTo == null)
  174. {
  175. PaperTo = MaxPaperNumber;
  176. }
  177. if (txt.Name == "PaperFromTxt")
  178. {
  179. PaperFrom = int.Parse(txt.Text);
  180. }
  181. else
  182. {
  183. PaperTo= int.Parse(txt.Text);
  184. }
  185. BookletInfo.BeginPaperIndex=(int)PaperFrom;
  186. BookletInfo.EndPaperIndex=(int)PaperTo;
  187. SendBookletInfo();
  188. }
  189. }
  190. public void SetAutoRotate()
  191. {
  192. BookletInfo.IsAutoRotate = IsAutoRotate;
  193. SendBookletInfo();
  194. }
  195. public void SendBookletInfo()
  196. {
  197. if (BookletInfo != null)
  198. {
  199. if (BookletInfo.BeginPaperIndex > BookletInfo.EndPaperIndex)
  200. {
  201. PaperFrom = PaperTo;
  202. BookletInfo.BeginPaperIndex = (int)PaperFrom;
  203. }
  204. this.eventAggregator.GetEvent<SendPrintSettingsModInfoEvent>().Publish(new PrintModInfoWithUnicode { printModInfo = BookletInfo, Unicode = this.Unicode });
  205. }
  206. }
  207. public bool IsNavigationTarget(NavigationContext navigationContext)
  208. {
  209. return true;
  210. }
  211. public void OnNavigatedFrom(NavigationContext navigationContext)
  212. {
  213. }
  214. public void OnNavigatedTo(NavigationContext navigationContext)
  215. {
  216. navigationContext.Parameters.TryGetValue<string>("Unicode", out Unicode);
  217. if (navigationContext.Parameters.ContainsKey("document"))
  218. {
  219. document = navigationContext.Parameters.GetValue<CPDFDocument>("document");
  220. MaxPaperNumber = (document.PageCount % 4 == 0) ? (document.PageCount / 4) : (document.PageCount / 4 + 1);
  221. if (PaperFrom == null)
  222. {
  223. PaperFrom = 1;
  224. }
  225. if (PaperTo == null)
  226. {
  227. PaperTo = MaxPaperNumber;
  228. }
  229. InitBookletInfo();
  230. SendBookletInfo();
  231. }
  232. }
  233. }
  234. }