HomePagePrinterModMultipleContentViewModel.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  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.Windows.Controls;
  11. namespace PDF_Master.ViewModels.Dialog.HomePageToolsDialogs.HomePagePrinter
  12. {
  13. public class HomePagePrinterModMultipleContentViewModel : BindableBase, INavigationAware
  14. {
  15. private IEventAggregator eventAggregator;
  16. private string Unicode = null;
  17. private int? _verticalPageNumber;
  18. public int? VerticalPageNumber
  19. {
  20. get { return _verticalPageNumber; }
  21. set { SetProperty(ref _verticalPageNumber, value); }
  22. }
  23. private int? _horizontalPageNumber;
  24. public int? HorizontalPageNumber
  25. {
  26. get { return _horizontalPageNumber; }
  27. set { SetProperty(ref _horizontalPageNumber, value); }
  28. }
  29. private bool _isAutoRotate;
  30. public bool IsAutoRotate
  31. {
  32. get { return _isAutoRotate; }
  33. set { _isAutoRotate = value; }
  34. }
  35. private List<string> _pageMatrixList;
  36. public List<string> PageMatrixList
  37. {
  38. get { return _pageMatrixList; }
  39. set { _pageMatrixList = value; }
  40. }
  41. private int _pageMatrixIndex = 1;
  42. /// <summary>
  43. /// <para>0: 1x2</para>
  44. /// <para>1: 2x2</para>
  45. /// <para>2: 3x2</para>
  46. /// <para>3: 3x3</para>
  47. /// <para>4: 4x4</para>
  48. /// <para>5: 自定义</para>
  49. /// </summary>
  50. public int PageMatrixIndex
  51. {
  52. get { return _pageMatrixIndex; }
  53. set
  54. {
  55. _pageMatrixIndex = value;
  56. if (_pageMatrixIndex < 5)
  57. {
  58. EnableCustomiseMatrix = false;
  59. }
  60. else
  61. {
  62. EnableCustomiseMatrix = true;
  63. }
  64. SetPageMatrixValue(value);
  65. }
  66. }
  67. private List<string> _pageOrderList;
  68. public List<string> PageOrderList
  69. {
  70. get { return _pageOrderList; }
  71. set { _pageOrderList = value; }
  72. }
  73. private int _pageOrderIndex;
  74. /// <summary>
  75. /// <para>0: Horizontal</para>
  76. /// <para>1: HorizontalReversed</para>
  77. /// <para>0: Vertical</para>
  78. /// <para>0: VerticalReversed</para>
  79. /// </summary>
  80. public int PageOrderIndex
  81. {
  82. get { return _pageOrderIndex; }
  83. set
  84. {
  85. _pageOrderIndex = value;
  86. SetMultipleInfo();
  87. SendMultipleInfo();
  88. }
  89. }
  90. private bool _enableCustomiseMatrix;
  91. public bool EnableCustomiseMatrix
  92. {
  93. get { return _enableCustomiseMatrix; }
  94. set
  95. {
  96. SetProperty(ref _enableCustomiseMatrix, value);
  97. }
  98. }
  99. private MultipleInfo _multipleInfo;
  100. /// <summary>
  101. /// 多页参数
  102. /// </summary>
  103. public MultipleInfo MultipleInfo
  104. {
  105. get { return _multipleInfo; }
  106. set { _multipleInfo = value; }
  107. }
  108. private bool _isDuplexModLongEdge = true;
  109. public bool IsDuplexModLongEdge
  110. {
  111. get { return _isDuplexModLongEdge; }
  112. set { _isDuplexModLongEdge = value; }
  113. }
  114. private bool _isDuplexModShortEdge = false;
  115. public bool IsDuplexModShortEdge
  116. {
  117. get { return _isDuplexModShortEdge; }
  118. set { _isDuplexModShortEdge = value; }
  119. }
  120. public DelegateCommand<object> SetPageMatrixCommand { get; set; }
  121. public DelegateCommand<object> SetCustomMatrixCommand { get; set; }
  122. public DelegateCommand SetPageOrderCommand { get; set; }
  123. public DelegateCommand SetAutoRotateCommand { get; set; }
  124. public DelegateCommand<object> UnlockDuplexCommand { get; set; }
  125. public DelegateCommand<object> ChangeDuplexModCommand { get; set; }
  126. public HomePagePrinterModMultipleContentViewModel(IEventAggregator eventAggregator)
  127. {
  128. this.eventAggregator = eventAggregator;
  129. PageMatrixIndex = 0;
  130. PageOrderIndex = 0;
  131. PageMatrixList = new List<string>();
  132. InitPageMatrixList();
  133. PageOrderList = new List<string>();
  134. InitPageOrderList();
  135. SetPageMatrixCommand = new DelegateCommand<object>(SetPageMatrix);
  136. SetCustomMatrixCommand = new DelegateCommand<object>(SetCustomMatrix);
  137. SetPageOrderCommand = new DelegateCommand(SetPageOrder);
  138. SetAutoRotateCommand = new DelegateCommand(SetAutoRotate);
  139. UnlockDuplexCommand = new DelegateCommand<object>(UnlockDuplex);
  140. ChangeDuplexModCommand = new DelegateCommand<object>(ChangeDuplexMod);
  141. MultipleInfo = new MultipleInfo();
  142. MultipleInfo.EnumPrintMod = EnumPrintMod.StatusMultiple;
  143. }
  144. public void SetPageMatrix(object e)
  145. {
  146. SetMultipleInfo();
  147. SendMultipleInfo();
  148. }
  149. public void SetCustomMatrix(object e)
  150. {
  151. SetMultipleInfo();
  152. SendMultipleInfo();
  153. }
  154. public void SetPageOrder()
  155. {
  156. SetMultipleInfo();
  157. SendMultipleInfo();
  158. }
  159. public void SetAutoRotate()
  160. {
  161. SetMultipleInfo();
  162. SendMultipleInfo();
  163. }
  164. public void SendMultipleInfo()
  165. {
  166. if (MultipleInfo != null)
  167. {
  168. this.eventAggregator.GetEvent<SendPrintSettingsModInfoEvent>().Publish(new PrintModInfoWithUnicode { printModInfo = MultipleInfo, Unicode = this.Unicode });
  169. }
  170. }
  171. public void UnlockDuplex(object e)
  172. {
  173. var chk = e as CheckBox;
  174. if (chk != null)
  175. {
  176. if (chk.IsChecked == false)
  177. {
  178. this.eventAggregator.GetEvent<SendDuplexPrintModEvent>().Publish(new EnumDuplexPrintModWithUnicode { enumDuplexPrintMod = EnumDuplexPrintMod.StatusNone, Unicode = this.Unicode });
  179. }
  180. else
  181. {
  182. if (IsDuplexModLongEdge)
  183. {
  184. this.eventAggregator.GetEvent<SendDuplexPrintModEvent>().Publish(new EnumDuplexPrintModWithUnicode { enumDuplexPrintMod = EnumDuplexPrintMod.StatusFlipLongEdge, Unicode = this.Unicode });
  185. }
  186. else
  187. {
  188. this.eventAggregator.GetEvent<SendDuplexPrintModEvent>().Publish(new EnumDuplexPrintModWithUnicode { enumDuplexPrintMod = EnumDuplexPrintMod.StatusFlipShortEdge, Unicode = this.Unicode });
  189. }
  190. }
  191. }
  192. }
  193. public void ChangeDuplexMod(object e)
  194. {
  195. var rdo = e as RadioButton;
  196. if (rdo != null)
  197. {
  198. if (rdo.Name == "DuplexModLongEdgeRdo")
  199. {
  200. this.eventAggregator.GetEvent<SendDuplexPrintModEvent>().Publish(new EnumDuplexPrintModWithUnicode { enumDuplexPrintMod = EnumDuplexPrintMod.StatusFlipLongEdge, Unicode = this.Unicode });
  201. }
  202. else
  203. {
  204. this.eventAggregator.GetEvent<SendDuplexPrintModEvent>().Publish(new EnumDuplexPrintModWithUnicode { enumDuplexPrintMod = EnumDuplexPrintMod.StatusFlipShortEdge, Unicode = this.Unicode });
  205. }
  206. }
  207. }
  208. private void InitPageMatrixList()
  209. {
  210. PageMatrixList.Clear();
  211. PageMatrixList.Add("2");
  212. PageMatrixList.Add("4");
  213. PageMatrixList.Add("6");
  214. PageMatrixList.Add("9");
  215. PageMatrixList.Add("16");
  216. PageMatrixList.Add("自定义");
  217. }
  218. private void InitPageOrderList()
  219. {
  220. PageOrderList.Clear();
  221. PageOrderList.Add("横向");
  222. PageOrderList.Add("横向倒序");
  223. PageOrderList.Add("纵向");
  224. PageOrderList.Add("纵向倒序");
  225. }
  226. private void SetPageMatrixValue(int pageMatrixIndex)
  227. {
  228. switch (pageMatrixIndex)
  229. {
  230. case 0:
  231. HorizontalPageNumber = 1;
  232. VerticalPageNumber = 2;
  233. SetMultipleInfo();
  234. SendMultipleInfo();
  235. break;
  236. case 1:
  237. HorizontalPageNumber = 2;
  238. VerticalPageNumber = 2;
  239. SetMultipleInfo();
  240. SendMultipleInfo();
  241. break;
  242. case 2:
  243. HorizontalPageNumber = 3;
  244. VerticalPageNumber = 2;
  245. SetMultipleInfo();
  246. SendMultipleInfo();
  247. break;
  248. case 3:
  249. HorizontalPageNumber = 3;
  250. VerticalPageNumber = 3;
  251. SetMultipleInfo();
  252. SendMultipleInfo();
  253. break;
  254. case 4:
  255. HorizontalPageNumber = 4;
  256. VerticalPageNumber = 4;
  257. SetMultipleInfo();
  258. SendMultipleInfo();
  259. break;
  260. case 5:
  261. HorizontalPageNumber = null;
  262. VerticalPageNumber = null;
  263. break;
  264. }
  265. }
  266. private void SetMultipleInfo()
  267. {
  268. if (HorizontalPageNumber == null)
  269. {
  270. HorizontalPageNumber = 1;
  271. }
  272. if (VerticalPageNumber == null)
  273. {
  274. VerticalPageNumber = 1;
  275. }
  276. if (MultipleInfo != null)
  277. {
  278. MultipleInfo.VerticalPageNumber = (int)VerticalPageNumber;
  279. MultipleInfo.HorizontalPageNumber = (int)HorizontalPageNumber;
  280. MultipleInfo.IsAutoRotate = IsAutoRotate;
  281. MultipleInfo.EnumPageOrder = (EnumPageOrder)PageOrderIndex;
  282. }
  283. }
  284. public bool IsNavigationTarget(NavigationContext navigationContext)
  285. {
  286. return true;
  287. }
  288. public void OnNavigatedFrom(NavigationContext navigationContext)
  289. {
  290. }
  291. public void OnNavigatedTo(NavigationContext navigationContext)
  292. {
  293. SetMultipleInfo();
  294. SendMultipleInfo();
  295. navigationContext.Parameters.TryGetValue<string>("Unicode", out Unicode);
  296. }
  297. }
  298. }