WatermarkCreateBaseContentViewModel.cs 9.4 KB

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