HomePagePrinterModPosterContentViewModel.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  1. using Microsoft.Office.Interop.Word;
  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.Printing;
  13. using System.Windows;
  14. using System.Windows.Controls;
  15. using System.Windows.Media;
  16. namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs.HomePagePrinter
  17. {
  18. public class HomePagePrinterModPosterContentViewModel : BindableBase, INavigationAware
  19. {
  20. private IEventAggregator eventAggregator;
  21. private string Unicode = null;
  22. private Visibility _pageRangeSettingVisibility = Visibility.Visible;
  23. public bool HasCutMarks = false;
  24. public bool HasLabel = false;
  25. private string _defaultLabel;
  26. public string DefaultLabel
  27. {
  28. get { return _defaultLabel; }
  29. set { _defaultLabel = value; }
  30. }
  31. private string _labelString;
  32. public string LabelString
  33. {
  34. get { return _labelString; }
  35. set {
  36. _labelString = value;
  37. eventAggregator.GetEvent<SendLabelEvent>().Publish(new LabelWithUnicode { Label = this.LabelString, Unicode = this.Unicode});
  38. }
  39. }
  40. public Visibility PageRangeSettingVisibility
  41. {
  42. get => _pageRangeSettingVisibility;
  43. set => SetProperty(ref _pageRangeSettingVisibility, value);
  44. }
  45. private Visibility _pagesPerSheetVisibility = Visibility.Hidden;
  46. public Visibility PagesPerSheetVisibility
  47. {
  48. get => _pagesPerSheetVisibility;
  49. set => SetProperty(ref _pagesPerSheetVisibility, value);
  50. }
  51. private string _tileRatio = "100";
  52. public string TileRatio
  53. {
  54. get => _tileRatio;
  55. set => SetProperty(ref _tileRatio, value);
  56. }
  57. private PosterInfo _posterInfo = new PosterInfo();
  58. public PosterInfo PosterInfo
  59. {
  60. get => _posterInfo;
  61. set => _posterInfo = value;
  62. }
  63. private List<string> _pageSheetList = new List<string>();
  64. /// <summary>
  65. /// <para>0: 1x2</para>
  66. /// <para>1: 2x2</para>
  67. /// <para>2: 3x2</para>
  68. /// <para>3: 3x3</para>
  69. /// <para>4: 4x4</para>
  70. /// <para>5: 自定义</para>
  71. /// </summary>
  72. public List<string> PageSheetList
  73. {
  74. get => _pageSheetList;
  75. set => _pageSheetList = value;
  76. }
  77. private bool _enableCustomSheet;
  78. public bool EnableCustomSheet
  79. {
  80. get { return _enableCustomSheet; }
  81. set
  82. {
  83. SetProperty(ref _enableCustomSheet, value);
  84. }
  85. }
  86. private int _pageSheetIndex = 0;
  87. public int PageSheetIndex
  88. {
  89. get { return _pageSheetIndex; }
  90. set
  91. {
  92. _pageSheetIndex = value;
  93. if (_pageSheetIndex < 5)
  94. {
  95. EnableCustomSheet = false;
  96. }
  97. else
  98. {
  99. EnableCustomSheet = true;
  100. }
  101. SetPageSheetValue(value);
  102. }
  103. }
  104. private int? _horizontalSheetNumber = 1;
  105. public int? HorizontalSheetNumber
  106. {
  107. get => _horizontalSheetNumber;
  108. set => SetProperty(ref _horizontalSheetNumber, value);
  109. }
  110. private int? _verticalSheetNumber = 2;
  111. public int? VerticalSheetNumber
  112. {
  113. get => _verticalSheetNumber;
  114. set => SetProperty(ref _verticalSheetNumber, value);
  115. }
  116. private double? _overlapNumber = 0;
  117. public double? OverlapNumber
  118. {
  119. get => _overlapNumber;
  120. set
  121. {
  122. if (value > 5.08)
  123. {
  124. SetProperty(ref _overlapNumber, 5.08);
  125. }
  126. else if (value < 0)
  127. {
  128. SetProperty(ref _overlapNumber, 0);
  129. }
  130. SetProperty(ref _overlapNumber, value);
  131. }
  132. }
  133. public DelegateCommand<object> SetModPosterStatusCommand { get; set; }
  134. public DelegateCommand<object> SetSheetCommand { get; set; }
  135. public DelegateCommand SetCustomSheetCommand { get; set; }
  136. public DelegateCommand SetOverlapCommand { get; set; }
  137. public DelegateCommand<object> SetCutMarksCommand { get; set; }
  138. public DelegateCommand<object> SetLabelCommand { get; set; }
  139. public DelegateCommand SetTileRatioCommand { get; set; }
  140. HomePagePrinterModPosterContentViewModel(IEventAggregator eventAggregator)
  141. {
  142. this.eventAggregator = eventAggregator;
  143. SetModPosterStatusCommand = new DelegateCommand<object>(SetModPosterStatus);
  144. SetSheetCommand = new DelegateCommand<object>(SetSheet);
  145. SetCustomSheetCommand = new DelegateCommand(SetCustomSheet);
  146. SetOverlapCommand = new DelegateCommand(SetOverlap);
  147. SetCutMarksCommand = new DelegateCommand<object>(SetCutMarks);
  148. SetLabelCommand = new DelegateCommand<object>(SetLabel);
  149. SetTileRatioCommand = new DelegateCommand(SetTileRatio);
  150. InitComponent();
  151. PosterInfo.EnumPrintMod = EnumPrintMod.StatusPoster;
  152. }
  153. public void InitPageSheetList()
  154. {
  155. PageSheetList.Clear();
  156. PageSheetList.Add("2");
  157. PageSheetList.Add("4");
  158. PageSheetList.Add("6");
  159. PageSheetList.Add("9");
  160. PageSheetList.Add("16");
  161. PageSheetList.Add("Custom");
  162. }
  163. public void InitComponent()
  164. {
  165. InitPageSheetList();
  166. }
  167. public void SetModPosterStatus(object e)
  168. {
  169. var rdo = e as RadioButton;
  170. if (rdo.Name == "StatusTileRdo")
  171. {
  172. PosterInfo.EnumPosterMod = EnumPosterMod.StatusTile;
  173. PageRangeSettingVisibility = Visibility.Visible;
  174. PagesPerSheetVisibility = Visibility.Hidden;
  175. }
  176. else
  177. {
  178. PosterInfo.EnumPosterMod = EnumPosterMod.StatusSplit;
  179. PageRangeSettingVisibility = Visibility.Hidden;
  180. PagesPerSheetVisibility = Visibility.Visible;
  181. }
  182. SendPosterInfo();
  183. }
  184. public void SetSheet(object e)
  185. {
  186. SendPosterInfo();
  187. }
  188. public void SetCustomSheet()
  189. {
  190. SendPosterInfo();
  191. }
  192. public void SetOverlap()
  193. {
  194. SendPosterInfo();
  195. }
  196. public void SetTileRatio()
  197. {
  198. int previousDisplayRatio = PosterInfo.TileRatio;
  199. PosterInfo.TileRatio = int.Parse(TileRatio);
  200. if (previousDisplayRatio != PosterInfo.TileRatio)
  201. {
  202. SendPosterInfo();
  203. }
  204. }
  205. public void SetPageSheetValue(int sheetIndex)
  206. {
  207. switch (sheetIndex)
  208. {
  209. case 0:
  210. HorizontalSheetNumber = 1;
  211. VerticalSheetNumber = 2;
  212. break;
  213. case 1:
  214. HorizontalSheetNumber = 2;
  215. VerticalSheetNumber = 2;
  216. break;
  217. case 2:
  218. HorizontalSheetNumber = 3;
  219. VerticalSheetNumber = 2;
  220. break;
  221. case 3:
  222. HorizontalSheetNumber = 3;
  223. VerticalSheetNumber = 3;
  224. break;
  225. case 4:
  226. HorizontalSheetNumber = 4;
  227. VerticalSheetNumber = 4;
  228. break;
  229. case 5:
  230. HorizontalSheetNumber = null;
  231. VerticalSheetNumber = null;
  232. break;
  233. }
  234. SendPosterInfo();
  235. }
  236. public void SendPosterInfo()
  237. {
  238. if (HorizontalSheetNumber == null)
  239. {
  240. HorizontalSheetNumber = 1;
  241. }
  242. if (VerticalSheetNumber == null)
  243. {
  244. VerticalSheetNumber = 1;
  245. }
  246. if (OverlapNumber == null)
  247. {
  248. OverlapNumber = 0;
  249. }
  250. else if (OverlapNumber < 0)
  251. {
  252. OverlapNumber = 0;
  253. }
  254. else if (OverlapNumber > 5.08)
  255. {
  256. OverlapNumber = 5.08;
  257. }
  258. if (PosterInfo != null)
  259. {
  260. if (PosterInfo.EnumPosterMod == EnumPosterMod.StatusTile)
  261. {
  262. PosterInfo.TileRatio = int.Parse(TileRatio);
  263. }
  264. else
  265. {
  266. PosterInfo.HorizontalSheetNumber = (int)HorizontalSheetNumber;
  267. PosterInfo.VerticalSheetNumber = (int)VerticalSheetNumber;
  268. }
  269. PosterInfo.OverLap = (double)OverlapNumber;
  270. PosterInfo.HasCutMarks = HasCutMarks;
  271. PosterInfo.HasLabel = HasLabel;
  272. }
  273. this.eventAggregator.GetEvent<SendPrintSettingsModInfoEvent>().Publish(new PrintModInfoWithUnicode { printModInfo = PosterInfo, Unicode = this.Unicode });
  274. }
  275. public void SetCutMarks(object e)
  276. {
  277. var chk = e as System.Windows.Controls.CheckBox;
  278. if(chk.IsChecked == true)
  279. {
  280. HasCutMarks = true;
  281. }
  282. else
  283. {
  284. HasCutMarks = false;
  285. }
  286. SendPosterInfo();
  287. }
  288. public void SetLabel(object e)
  289. {
  290. var chk = e as System.Windows.Controls.CheckBox;
  291. if (chk.IsChecked == true)
  292. {
  293. HasLabel = true;
  294. }
  295. else
  296. {
  297. HasLabel = false;
  298. }
  299. SendPosterInfo();
  300. }
  301. public bool IsNavigationTarget(NavigationContext navigationContext)
  302. {
  303. return true;
  304. }
  305. public void OnNavigatedFrom(NavigationContext navigationContext)
  306. {
  307. }
  308. public void OnNavigatedTo(NavigationContext navigationContext)
  309. {
  310. DefaultLabel = "(column, row) 1.pdf "+ DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  311. navigationContext.Parameters.TryGetValue<string>("Unicode", out Unicode);
  312. SendPosterInfo();
  313. }
  314. }
  315. }