HomePagePrinterModMultipleContentViewModel.cs 8.2 KB

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