WatermarkCreateBaseContentViewModel.cs 9.0 KB

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