HomePageWatermarkCreateBaseContentViewModel.cs 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. using ComPDFKitViewer.PdfViewer;
  2. using PDF_Office.EventAggregators;
  3. using PDF_Office.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_Office.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. CreateBaseVisible = Visibility.Collapsed;
  52. }
  53. else if (value == EnumCreateOrEdit.StatusCreate)
  54. {
  55. CreateBaseVisible = Visibility.Visible;
  56. EditBaseVisible = Visibility.Collapsed;
  57. }
  58. }
  59. }
  60. private Visibility watermarkCreateVisible;
  61. public Visibility WatermarkCreateVisible
  62. {
  63. get => watermarkCreateVisible;
  64. set => SetProperty(ref watermarkCreateVisible, value);
  65. }
  66. private Visibility _createBaseVisible;
  67. public Visibility CreateBaseVisible
  68. {
  69. get => _createBaseVisible;
  70. set => SetProperty(ref _createBaseVisible, value);
  71. }
  72. private Visibility _editBaseVisible;
  73. public Visibility EditBaseVisible
  74. {
  75. get => _editBaseVisible;
  76. set => SetProperty(ref _editBaseVisible, value);
  77. }
  78. public DelegateCommand<object> ChangeCreateModCommand { get; set; }
  79. public DelegateCommand EnterTemplateListCommand { get; set; }
  80. public DelegateCommand SaveToTemplateListCommand { get; set; }
  81. public DelegateCommand SaveToCurrentTemplateListCommand { get; set; }
  82. public string Unicode = null;
  83. public HomePageWatermarkCreateBaseContentViewModel(IRegionManager regionManager, IEventAggregator eventAggregator)
  84. {
  85. this.eventAggregator = eventAggregator;
  86. this.watermarkCreateRegion = regionManager;
  87. Unicode = App.mainWindowViewModel.SelectedItem.Unicode;
  88. WatermarkCreateRegionName = Guid.NewGuid().ToString();
  89. ChangeCreateModCommand = new DelegateCommand<object>(ChangeCreateMod);
  90. EnterTemplateListCommand = new DelegateCommand(EnterTemplateList);
  91. SaveToTemplateListCommand = new DelegateCommand(SaveToTemplateList);
  92. SaveToCurrentTemplateListCommand = new DelegateCommand(SaveToCurrentTemplateList);
  93. }
  94. public void SaveToTemplateList()
  95. {
  96. if (CurrentCreateModName == "HomePageWatermarkCreateTextContent")
  97. {
  98. this.eventAggregator.GetEvent<SaveWatermarkTemplateEvent>().Publish(new EnumTextOrFileUnicode
  99. {
  100. Unicode = Unicode,
  101. Status = EnumTextOrFile.StatusText
  102. });
  103. }
  104. if (CurrentCreateModName == "HomePageWatermarkCreateFileContent")
  105. {
  106. this.eventAggregator.GetEvent<SaveWatermarkTemplateEvent>().Publish(new EnumTextOrFileUnicode
  107. {
  108. Unicode = Unicode,
  109. Status = EnumTextOrFile.StatusFile
  110. });
  111. }
  112. }
  113. public void SaveToCurrentTemplateList()
  114. {
  115. if (CurrentCreateModName == "HomePageWatermarkCreateTextContent")
  116. {
  117. eventAggregator.GetEvent<ConfirmEditWatermarkTemplateItemEvent>().Publish(new EnumTextOrFileUnicode
  118. {
  119. Unicode = Unicode,
  120. Status = EnumTextOrFile.StatusText
  121. });
  122. }
  123. if (CurrentCreateModName == "HomePageWatermarkCreateFileContent")
  124. {
  125. eventAggregator.GetEvent<ConfirmEditWatermarkTemplateItemEvent>().Publish(new EnumTextOrFileUnicode
  126. {
  127. Unicode = Unicode,
  128. Status = EnumTextOrFile.StatusFile
  129. });
  130. }
  131. }
  132. public void EnterTemplateList()
  133. {
  134. this.eventAggregator.GetEvent<EnterTemplateListOrCreateEvent>().Publish(new EnumTemplateListOrCreateUnicode { Unicode = Unicode, Status = EnumTemplateListOrCreate.StatusTemplate });
  135. }
  136. public void EnterSelectedCreateMod(string currentCreateName)
  137. {
  138. NavigationParameters param = new NavigationParameters();
  139. param.Add(ParameterNames.PDFViewer, PDFViewer);
  140. watermarkCreateRegion.RequestNavigate(WatermarkCreateRegionName, currentCreateName, param);
  141. watermarkCreateVisible = System.Windows.Visibility.Visible;
  142. }
  143. public void EditSelectedTemplateItem(string currentCreateName)
  144. {
  145. NavigationParameters param = new NavigationParameters();
  146. param.Add(ParameterNames.PDFViewer, PDFViewer);
  147. param.Add("WatermarkItem", WatermarkItem);
  148. watermarkCreateRegion.RequestNavigate(WatermarkCreateRegionName, currentCreateName, param);
  149. watermarkCreateVisible = System.Windows.Visibility.Visible;
  150. }
  151. public void ChangeCreateMod(object e)
  152. {
  153. var args = e as Button;
  154. if (args != null)
  155. {
  156. if (CreateOrEdit == EnumCreateOrEdit.StatusCreate)
  157. {
  158. CurrentCreateModName = args.Name;
  159. EnterSelectedCreateMod(CurrentCreateModName);
  160. eventAggregator.GetEvent<SetCurrentCreateModEvent>().Publish(new stringUnicode
  161. {
  162. Unicode = Unicode,
  163. Status = CurrentCreateModName
  164. });
  165. }
  166. else if (CreateOrEdit == EnumCreateOrEdit.StatusEdit)
  167. {
  168. CurrentCreateModName = args.Name;
  169. EditSelectedTemplateItem(CurrentCreateModName);
  170. eventAggregator.GetEvent<SetCurrentCreateModEvent>().Publish(new stringUnicode
  171. {
  172. Unicode = Unicode,
  173. Status = CurrentCreateModName
  174. });
  175. }
  176. }
  177. }
  178. public bool IsNavigationTarget(NavigationContext navigationContext)
  179. {
  180. return true;
  181. }
  182. public void OnNavigatedFrom(NavigationContext navigationContext)
  183. {
  184. }
  185. public void OnNavigatedTo(NavigationContext navigationContext)
  186. {
  187. navigationContext.Parameters.TryGetValue<CPDFViewer>(ParameterNames.PDFViewer, out PDFViewer);
  188. navigationContext.Parameters.TryGetValue<EnumTextOrFile>("CurrentTemplateListModName", out CurrentTemplateListMod);
  189. if (CurrentTemplateListMod == EnumTextOrFile.StatusText)
  190. {
  191. CurrentCreateModName = "HomePageWatermarkCreateTextContent";
  192. }
  193. else
  194. {
  195. CurrentCreateModName = "HomePageWatermarkCreateFileContent";
  196. }
  197. if (navigationContext.Parameters.TryGetValue<WatermarkItem>("WatermarkItem", out WatermarkItem))
  198. {
  199. EditSelectedTemplateItem(CurrentCreateModName);
  200. CreateOrEdit = EnumCreateOrEdit.StatusEdit;
  201. }
  202. else
  203. {
  204. EnterSelectedCreateMod(CurrentCreateModName);
  205. CreateOrEdit = EnumCreateOrEdit.StatusCreate;
  206. }
  207. eventAggregator.GetEvent<SetCurrentCreateModEvent>().Publish(new stringUnicode
  208. {
  209. Unicode = Unicode,
  210. Status = CurrentCreateModName
  211. });
  212. }
  213. }
  214. }