HomePagePrinterModPosterContentViewModel.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  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 = 1;
  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 = 2;
  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. else
  131. {
  132. SetProperty(ref _overlapNumber, value);
  133. }
  134. }
  135. }
  136. public DelegateCommand<object> SetModPosterStatusCommand { get; set; }
  137. public DelegateCommand<object> SetSheetCommand { get; set; }
  138. public DelegateCommand SetCustomSheetCommand { get; set; }
  139. public DelegateCommand SetOverlapCommand { get; set; }
  140. public DelegateCommand<object> SetCutMarksCommand { get; set; }
  141. public DelegateCommand<object> SetLabelCommand { get; set; }
  142. public DelegateCommand SetTileRatioCommand { get; set; }
  143. HomePagePrinterModPosterContentViewModel(IEventAggregator eventAggregator)
  144. {
  145. this.eventAggregator = eventAggregator;
  146. SetModPosterStatusCommand = new DelegateCommand<object>(SetModPosterStatus);
  147. SetSheetCommand = new DelegateCommand<object>(SetSheet);
  148. SetCustomSheetCommand = new DelegateCommand(SetCustomSheet);
  149. SetOverlapCommand = new DelegateCommand(SetOverlap);
  150. SetCutMarksCommand = new DelegateCommand<object>(SetCutMarks);
  151. SetLabelCommand = new DelegateCommand<object>(SetLabel);
  152. SetTileRatioCommand = new DelegateCommand(SetTileRatio);
  153. InitComponent();
  154. PosterInfo.EnumPrintMod = EnumPrintMod.StatusPoster;
  155. }
  156. public void InitPageSheetList()
  157. {
  158. PageSheetList.Clear();
  159. PageSheetList.Add("2");
  160. PageSheetList.Add("4");
  161. PageSheetList.Add("6");
  162. PageSheetList.Add("9");
  163. PageSheetList.Add("16");
  164. PageSheetList.Add("Custom");
  165. }
  166. public void InitComponent()
  167. {
  168. InitPageSheetList();
  169. }
  170. public void SetModPosterStatus(object e)
  171. {
  172. var rdo = e as RadioButton;
  173. if (rdo.Name == "StatusTileRdo")
  174. {
  175. PosterInfo.EnumPosterMod = EnumPosterMod.StatusTile;
  176. PageRangeSettingVisibility = Visibility.Visible;
  177. PagesPerSheetVisibility = Visibility.Hidden;
  178. }
  179. else
  180. {
  181. PosterInfo.EnumPosterMod = EnumPosterMod.StatusSplit;
  182. PageRangeSettingVisibility = Visibility.Hidden;
  183. PagesPerSheetVisibility = Visibility.Visible;
  184. }
  185. SendPosterInfo();
  186. }
  187. public void SetSheet(object e)
  188. {
  189. SendPosterInfo();
  190. }
  191. public void SetCustomSheet()
  192. {
  193. SendPosterInfo();
  194. }
  195. public void SetOverlap()
  196. {
  197. SendPosterInfo();
  198. }
  199. public void SetTileRatio()
  200. {
  201. int previousDisplayRatio = PosterInfo.TileRatio;
  202. PosterInfo.TileRatio = int.Parse(TileRatio);
  203. if (previousDisplayRatio != PosterInfo.TileRatio)
  204. {
  205. SendPosterInfo();
  206. }
  207. }
  208. public void SetPageSheetValue(int sheetIndex)
  209. {
  210. switch (sheetIndex)
  211. {
  212. case 0:
  213. HorizontalSheetNumber = 1;
  214. VerticalSheetNumber = 2;
  215. break;
  216. case 1:
  217. HorizontalSheetNumber = 2;
  218. VerticalSheetNumber = 2;
  219. break;
  220. case 2:
  221. HorizontalSheetNumber = 3;
  222. VerticalSheetNumber = 2;
  223. break;
  224. case 3:
  225. HorizontalSheetNumber = 3;
  226. VerticalSheetNumber = 3;
  227. break;
  228. case 4:
  229. HorizontalSheetNumber = 4;
  230. VerticalSheetNumber = 4;
  231. break;
  232. case 5:
  233. HorizontalSheetNumber = null;
  234. VerticalSheetNumber = null;
  235. break;
  236. }
  237. SendPosterInfo();
  238. }
  239. public void SendPosterInfo()
  240. {
  241. if (HorizontalSheetNumber == null)
  242. {
  243. HorizontalSheetNumber = 1;
  244. }
  245. if (VerticalSheetNumber == null)
  246. {
  247. VerticalSheetNumber = 1;
  248. }
  249. if (OverlapNumber == null)
  250. {
  251. OverlapNumber = 0;
  252. }
  253. else if (OverlapNumber < 0)
  254. {
  255. OverlapNumber = 0;
  256. }
  257. else if (OverlapNumber > 5.08)
  258. {
  259. OverlapNumber = 5.08;
  260. }
  261. if (PosterInfo != null)
  262. {
  263. if (PosterInfo.EnumPosterMod == EnumPosterMod.StatusTile)
  264. {
  265. PosterInfo.TileRatio = int.Parse(TileRatio);
  266. }
  267. else
  268. {
  269. PosterInfo.HorizontalSheetNumber = (int)HorizontalSheetNumber;
  270. PosterInfo.VerticalSheetNumber = (int)VerticalSheetNumber;
  271. }
  272. PosterInfo.OverLap = (double)OverlapNumber;
  273. PosterInfo.HasCutMarks = HasCutMarks;
  274. PosterInfo.HasLabel = HasLabel;
  275. }
  276. this.eventAggregator.GetEvent<SendPrintSettingsModInfoEvent>().Publish(new PrintModInfoWithUnicode { printModInfo = PosterInfo, Unicode = this.Unicode });
  277. }
  278. public void SetCutMarks(object e)
  279. {
  280. var chk = e as System.Windows.Controls.CheckBox;
  281. if(chk.IsChecked == true)
  282. {
  283. HasCutMarks = true;
  284. }
  285. else
  286. {
  287. HasCutMarks = false;
  288. }
  289. SendPosterInfo();
  290. }
  291. public void SetLabel(object e)
  292. {
  293. var chk = e as System.Windows.Controls.CheckBox;
  294. if (chk.IsChecked == true)
  295. {
  296. HasLabel = true;
  297. }
  298. else
  299. {
  300. HasLabel = false;
  301. }
  302. SendPosterInfo();
  303. }
  304. public bool IsNavigationTarget(NavigationContext navigationContext)
  305. {
  306. return true;
  307. }
  308. public void OnNavigatedFrom(NavigationContext navigationContext)
  309. {
  310. }
  311. public void OnNavigatedTo(NavigationContext navigationContext)
  312. {
  313. DefaultLabel = "(column, row) 1.pdf "+ DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  314. navigationContext.Parameters.TryGetValue<string>("Unicode", out Unicode);
  315. SendPosterInfo();
  316. }
  317. }
  318. }