HomePageWatermarkCreateBaseContentViewModel.cs 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. using ComPDFKitViewer.PdfViewer;
  2. using PDF_Master.EventAggregators;
  3. using PDF_Master.Model;
  4. using PDFSettings;
  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.Linq;
  12. using System.Windows;
  13. using System.Windows.Controls;
  14. namespace PDF_Master.ViewModels.Dialog.HomePageToolsDialogs.HomePageBatchProcessing.HomePageWatermark
  15. {
  16. public class HomePageWatermarkCreateBaseContentViewModel : BindableBase, INavigationAware
  17. {
  18. IEventAggregator eventAggregator;
  19. IRegionManager watermarkCreateRegion;
  20. private CPDFViewer PDFViewer;
  21. public WatermarkItem WatermarkItem;
  22. public EnumTextOrFile CurrentTemplateListMod;
  23. private string watermarkCreateRegionName;
  24. public string WatermarkCreateRegionName
  25. {
  26. get => watermarkCreateRegionName;
  27. set => SetProperty(ref watermarkCreateRegionName, value);
  28. }
  29. private string _currentCreateModName;
  30. public string CurrentCreateModName
  31. {
  32. get => _currentCreateModName;
  33. set => _currentCreateModName = value;
  34. }
  35. public enum EnumCreateOrEdit
  36. {
  37. None,
  38. StatusCreate,
  39. StatusEdit
  40. }
  41. private EnumCreateOrEdit _createOrEdit;
  42. public EnumCreateOrEdit CreateOrEdit
  43. {
  44. get { return _createOrEdit; }
  45. set
  46. {
  47. _createOrEdit = value;
  48. if (value == EnumCreateOrEdit.StatusEdit)
  49. {
  50. EditBaseVisible = Visibility.Visible;
  51. SelectContentVisibility = Visibility.Collapsed;
  52. CreateBaseVisible = Visibility.Collapsed;
  53. }
  54. else if (value == EnumCreateOrEdit.StatusCreate)
  55. {
  56. CreateBaseVisible = Visibility.Visible;
  57. SelectContentVisibility= Visibility.Visible;
  58. EditBaseVisible = Visibility.Collapsed;
  59. }
  60. }
  61. }
  62. private Visibility watermarkCreateVisible;
  63. public Visibility WatermarkCreateVisible
  64. {
  65. get => watermarkCreateVisible;
  66. set => SetProperty(ref watermarkCreateVisible, value);
  67. }
  68. private Visibility _createBaseVisible;
  69. public Visibility CreateBaseVisible
  70. {
  71. get => _createBaseVisible;
  72. set => SetProperty(ref _createBaseVisible, value);
  73. }
  74. private Visibility _editBaseVisible;
  75. public Visibility EditBaseVisible
  76. {
  77. get => _editBaseVisible;
  78. set => SetProperty(ref _editBaseVisible, value);
  79. }
  80. private Visibility _selectContentVisibility;
  81. public Visibility SelectContentVisibility
  82. {
  83. get => _selectContentVisibility;
  84. set => SetProperty(ref _selectContentVisibility, value);
  85. }
  86. public DelegateCommand<object> ChangeCreateModCommand { get; set; }
  87. public DelegateCommand EnterTemplateListCommand { get; set; }
  88. public DelegateCommand SaveToTemplateListCommand { get; set; }
  89. public DelegateCommand SaveToCurrentTemplateListCommand { get; set; }
  90. public string Unicode = null;
  91. public HomePageWatermarkCreateBaseContentViewModel(IRegionManager regionManager, IEventAggregator eventAggregator)
  92. {
  93. this.eventAggregator = eventAggregator;
  94. this.watermarkCreateRegion = regionManager;
  95. WatermarkCreateRegionName = Guid.NewGuid().ToString();
  96. ChangeCreateModCommand = new DelegateCommand<object>(ChangeCreateMod);
  97. EnterTemplateListCommand = new DelegateCommand(EnterTemplateList);
  98. SaveToTemplateListCommand = new DelegateCommand(SaveToTemplateList);
  99. SaveToCurrentTemplateListCommand = new DelegateCommand(SaveToCurrentTemplateList);
  100. }
  101. public void SaveToTemplateList()
  102. {
  103. if (CurrentCreateModName == "HomePageWatermarkCreateTextContent")
  104. {
  105. this.eventAggregator.GetEvent<SaveWatermarkTemplateEvent>().Publish(new EnumTextOrFileUnicode
  106. {
  107. Unicode = Unicode,
  108. Status = EnumTextOrFile.StatusText
  109. });
  110. }
  111. if (CurrentCreateModName == "HomePageWatermarkCreateFileContent")
  112. {
  113. this.eventAggregator.GetEvent<SaveWatermarkTemplateEvent>().Publish(new EnumTextOrFileUnicode
  114. {
  115. Unicode = Unicode,
  116. Status = EnumTextOrFile.StatusFile
  117. });
  118. }
  119. }
  120. public void SaveToCurrentTemplateList()
  121. {
  122. if (CurrentCreateModName == "HomePageWatermarkCreateTextContent")
  123. {
  124. eventAggregator.GetEvent<ConfirmEditWatermarkTemplateItemEvent>().Publish(new EnumTextOrFileUnicode
  125. {
  126. Unicode = Unicode,
  127. Status = EnumTextOrFile.StatusText
  128. });
  129. }
  130. if (CurrentCreateModName == "HomePageWatermarkCreateFileContent")
  131. {
  132. eventAggregator.GetEvent<ConfirmEditWatermarkTemplateItemEvent>().Publish(new EnumTextOrFileUnicode
  133. {
  134. Unicode = Unicode,
  135. Status = EnumTextOrFile.StatusFile
  136. });
  137. }
  138. }
  139. public void EnterTemplateList()
  140. {
  141. this.eventAggregator.GetEvent<EnterTemplateListOrCreateEvent>().Publish(new EnumTemplateListOrCreateUnicode { Unicode = Unicode, Status = EnumTemplateListOrCreate.StatusTemplate });
  142. }
  143. public void EnterSelectedCreateMod(string currentCreateName)
  144. {
  145. NavigationParameters param = new NavigationParameters();
  146. param.Add(ParameterNames.PDFViewer, PDFViewer);
  147. param.Add("Unicode", Unicode);
  148. watermarkCreateRegion.RequestNavigate(WatermarkCreateRegionName, currentCreateName, param);
  149. watermarkCreateVisible = System.Windows.Visibility.Visible;
  150. }
  151. public void EditSelectedTemplateItem(string currentCreateName)
  152. {
  153. NavigationParameters param = new NavigationParameters();
  154. param.Add(ParameterNames.PDFViewer, PDFViewer);
  155. param.Add("Unicode", Unicode);
  156. param.Add("WatermarkItem", WatermarkItem);
  157. watermarkCreateRegion.RequestNavigate(WatermarkCreateRegionName, currentCreateName, param);
  158. watermarkCreateVisible = System.Windows.Visibility.Visible;
  159. }
  160. public void ChangeCreateMod(object e)
  161. {
  162. var args = e as Button;
  163. if (args != null)
  164. {
  165. if (CreateOrEdit == EnumCreateOrEdit.StatusCreate)
  166. {
  167. CurrentCreateModName = args.Name;
  168. EnterSelectedCreateMod(CurrentCreateModName);
  169. eventAggregator.GetEvent<SetCurrentCreateModEvent>().Publish(new stringUnicode
  170. {
  171. Unicode = Unicode,
  172. Status = CurrentCreateModName
  173. });
  174. }
  175. else if (CreateOrEdit == EnumCreateOrEdit.StatusEdit)
  176. {
  177. CurrentCreateModName = args.Name;
  178. EditSelectedTemplateItem(CurrentCreateModName);
  179. eventAggregator.GetEvent<SetCurrentCreateModEvent>().Publish(new stringUnicode
  180. {
  181. Unicode = Unicode,
  182. Status = CurrentCreateModName
  183. });
  184. }
  185. }
  186. }
  187. public bool IsNavigationTarget(NavigationContext navigationContext)
  188. {
  189. return true;
  190. }
  191. public void OnNavigatedFrom(NavigationContext navigationContext)
  192. {
  193. }
  194. public void OnNavigatedTo(NavigationContext navigationContext)
  195. {
  196. navigationContext.Parameters.TryGetValue<CPDFViewer>(ParameterNames.PDFViewer, out PDFViewer);
  197. navigationContext.Parameters.TryGetValue<string>("Unicode", out Unicode);
  198. navigationContext.Parameters.TryGetValue<EnumTextOrFile>("CurrentTemplateListModName", out CurrentTemplateListMod);
  199. if (CurrentTemplateListMod == EnumTextOrFile.StatusText)
  200. {
  201. CurrentCreateModName = "HomePageWatermarkCreateTextContent";
  202. }
  203. else
  204. {
  205. CurrentCreateModName = "HomePageWatermarkCreateFileContent";
  206. }
  207. if (navigationContext.Parameters.TryGetValue<WatermarkItem>("WatermarkItem", out WatermarkItem))
  208. {
  209. EditSelectedTemplateItem(CurrentCreateModName);
  210. CreateOrEdit = EnumCreateOrEdit.StatusEdit;
  211. }
  212. else
  213. {
  214. EnterSelectedCreateMod(CurrentCreateModName);
  215. CreateOrEdit = EnumCreateOrEdit.StatusCreate;
  216. }
  217. eventAggregator.GetEvent<SetCurrentCreateModEvent>().Publish(new stringUnicode
  218. {
  219. Unicode = Unicode,
  220. Status = CurrentCreateModName
  221. });
  222. }
  223. }
  224. }