HomePagePrinterModPosterContentViewModel.cs 11 KB

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