HomePagePrinterModBookletContentViewModel.cs 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. using ComPDFKit.PDFDocument;
  2. using PDF_Office.EventAggregators;
  3. using PDF_Office.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_Office.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 HomePagePrinterModBookletContentViewModel(IEventAggregator eventAggregator)
  117. {
  118. this.eventAggregator = eventAggregator;
  119. SubsetList = new List<string>();
  120. InitSubsetList();
  121. BindingList = new List<string>();
  122. InitBindingList();
  123. BookletInfo = new BookletInfo();
  124. BookletInfo.EnumPrintMod = EnumPrintMod.StatusBooklet;
  125. SetSheetCommand = new DelegateCommand<object>(SetSheet);
  126. }
  127. private void InitSubsetList()
  128. {
  129. SubsetList.Clear();
  130. SubsetList.Add("双面");
  131. SubsetList.Add("仅正面");
  132. SubsetList.Add("仅背面");
  133. }
  134. private void InitBindingList()
  135. {
  136. BindingList.Clear();
  137. BindingList.Add("左");
  138. BindingList.Add("右");
  139. }
  140. private void InitBookletInfo()
  141. {
  142. BookletInfo.EnumBookletSubset = (EnumBookletSubset)SubsetIndex;
  143. BookletInfo.EnumBookletBinding = (EnumBookletBinding)BindingIndex;
  144. if (PaperFrom != null)
  145. {
  146. BookletInfo.BeginPaperIndex = (int)PaperFrom;
  147. }
  148. else
  149. {
  150. BookletInfo.BeginPaperIndex = 1;
  151. }
  152. if (PaperTo != null)
  153. {
  154. BookletInfo.EndPaperIndex = (int)PaperTo;
  155. }
  156. else
  157. {
  158. BookletInfo.EndPaperIndex = MaxPaperNumber;
  159. }
  160. BookletInfo.IsAutoRotate = IsAutoRotate;
  161. }
  162. public void SetSheet(object e)
  163. {
  164. var txt = e as TextBox;
  165. if (txt != null)
  166. {
  167. if (PaperFrom == null)
  168. {
  169. PaperFrom = 1;
  170. }
  171. if (PaperTo == null)
  172. {
  173. PaperTo = MaxPaperNumber;
  174. }
  175. if (txt.Name == "PaperFromTxt")
  176. {
  177. PaperFrom = int.Parse(txt.Text);
  178. }
  179. else
  180. {
  181. PaperTo= int.Parse(txt.Text);
  182. }
  183. BookletInfo.BeginPaperIndex=(int)PaperFrom;
  184. BookletInfo.EndPaperIndex=(int)PaperTo;
  185. SendBookletInfo();
  186. }
  187. }
  188. public void SendBookletInfo()
  189. {
  190. if (BookletInfo != null)
  191. {
  192. if (BookletInfo.BeginPaperIndex > BookletInfo.EndPaperIndex)
  193. {
  194. PaperFrom = PaperTo;
  195. BookletInfo.BeginPaperIndex = (int)PaperFrom;
  196. }
  197. this.eventAggregator.GetEvent<SendPrintSettingsModInfoEvent>().Publish(new PrintModInfoWithUnicode { printModInfo = BookletInfo, Unicode = this.Unicode });
  198. }
  199. }
  200. public bool IsNavigationTarget(NavigationContext navigationContext)
  201. {
  202. return true;
  203. }
  204. public void OnNavigatedFrom(NavigationContext navigationContext)
  205. {
  206. }
  207. public void OnNavigatedTo(NavigationContext navigationContext)
  208. {
  209. navigationContext.Parameters.TryGetValue<string>("Unicode", out Unicode);
  210. if (navigationContext.Parameters.ContainsKey("document"))
  211. {
  212. document = navigationContext.Parameters.GetValue<CPDFDocument>("document");
  213. MaxPaperNumber = (document.PageCount % 4 == 0) ? (document.PageCount / 4) : (document.PageCount / 4 + 1);
  214. if (PaperFrom == null)
  215. {
  216. PaperFrom = 1;
  217. }
  218. if (PaperTo == null)
  219. {
  220. PaperTo = MaxPaperNumber;
  221. }
  222. InitBookletInfo();
  223. SendBookletInfo();
  224. }
  225. else
  226. {
  227. Trace.WriteLine("No Key Named{0}", "document");
  228. }
  229. }
  230. }
  231. }