HomePageBackgroundCreateBaseContentViewModel.cs 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  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.HomePageBackground
  15. {
  16. public class HomePageBackgroundCreateBaseContentViewModel : BindableBase, INavigationAware
  17. {
  18. IEventAggregator eventAggregator;
  19. IRegionManager backgroundCreateRegion;
  20. private CPDFViewer PDFViewer;
  21. public BackgroundItem BackgroundItem;
  22. public enum EnumCreateOrEdit
  23. {
  24. None,
  25. StatusCreate,
  26. StatusEdit
  27. }
  28. private EnumCreateOrEdit _createOrEdit;
  29. public EnumCreateOrEdit CreateOrEdit
  30. {
  31. get { return _createOrEdit; }
  32. set
  33. {
  34. _createOrEdit = value;
  35. if (value == EnumCreateOrEdit.StatusEdit)
  36. {
  37. EditBaseVisible = Visibility.Visible;
  38. CreateBaseVisible = Visibility.Collapsed;
  39. }
  40. else if (value == EnumCreateOrEdit.StatusCreate)
  41. {
  42. CreateBaseVisible = Visibility.Visible;
  43. EditBaseVisible = Visibility.Collapsed;
  44. }
  45. }
  46. }
  47. private string backgroundCreateRegionName;
  48. public string BackgroundCreateRegionName
  49. {
  50. get => backgroundCreateRegionName;
  51. set => SetProperty(ref backgroundCreateRegionName, value);
  52. }
  53. private string _currentCreateModName;
  54. public string CurrentCreateModName
  55. {
  56. get => _currentCreateModName;
  57. set => _currentCreateModName = value;
  58. }
  59. private System.Windows.Visibility backgroundCreateVisible;
  60. public System.Windows.Visibility BackgroundCreateVisible
  61. {
  62. get => backgroundCreateVisible;
  63. set => SetProperty(ref backgroundCreateVisible, value);
  64. }
  65. private bool isFirstEnter = true;
  66. public bool IsFirstEnter
  67. {
  68. get => isFirstEnter;
  69. set => isFirstEnter = 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. public EnumColorOrFile CurrentTemplateListMod;
  84. public DelegateCommand<object> ChangeCreateModCommand { get; set; }
  85. public DelegateCommand EnterTemplateListCommand { get; set; }
  86. public DelegateCommand SaveToTemplateListCommand { get; set; }
  87. public DelegateCommand SaveToCurrentTemplateListCommand { get; set; }
  88. public string unicode = null;
  89. public string Unicode = null;
  90. public HomePageBackgroundCreateBaseContentViewModel(IRegionManager regionManager, IEventAggregator eventAggregator)
  91. {
  92. this.eventAggregator = eventAggregator;
  93. this.backgroundCreateRegion = regionManager;
  94. Unicode = App.mainWindowViewModel.SelectedItem.Unicode;
  95. BackgroundCreateRegionName = 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 == "HomePageBackgroundCreateColorContent")
  104. {
  105. this.eventAggregator.GetEvent<SaveBackgroundTemplateEvent>().Publish(new EnumColorOrFileUnicode { Unicode = Unicode, Status = EnumColorOrFile.StatusColor });
  106. }
  107. if (CurrentCreateModName == "HomePageBackgroundCreateFileContent")
  108. {
  109. this.eventAggregator.GetEvent<SaveBackgroundTemplateEvent>().Publish(new EnumColorOrFileUnicode
  110. {
  111. Unicode = Unicode,
  112. Status = EnumColorOrFile.StatusFile
  113. });
  114. }
  115. }
  116. public void SaveToCurrentTemplateList()
  117. {
  118. if (CurrentCreateModName == "HomePageBackgroundCreateColorContent")
  119. {
  120. eventAggregator.GetEvent<ConfirmEditBackgroundTemplateItemEvent>().Publish(new EnumColorOrFileUnicode
  121. {
  122. Unicode = Unicode,
  123. Status = EnumColorOrFile.StatusColor
  124. });
  125. }
  126. if (CurrentCreateModName == "HomePageBackgroundCreateFileContent")
  127. {
  128. eventAggregator.GetEvent<ConfirmEditBackgroundTemplateItemEvent>().Publish(new EnumColorOrFileUnicode
  129. {
  130. Unicode = Unicode,
  131. Status = EnumColorOrFile.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. backgroundCreateRegion.RequestNavigate(BackgroundCreateRegionName, currentCreateName, param);
  144. backgroundCreateVisible = 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("BackgroundItem", BackgroundItem);
  151. backgroundCreateRegion.RequestNavigate(BackgroundCreateRegionName, currentCreateName, param);
  152. backgroundCreateVisible = 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<EnumColorOrFile>("CurrentTemplateListModName", out CurrentTemplateListMod);
  192. if (CurrentTemplateListMod == EnumColorOrFile.StatusColor)
  193. {
  194. CurrentCreateModName = "HomePageBackgroundCreateColorContent";
  195. }
  196. else
  197. {
  198. CurrentCreateModName = "HomePageBackgroundCreateFileContent";
  199. }
  200. if (navigationContext.Parameters.TryGetValue<BackgroundItem>("BackgroundItem", out BackgroundItem))
  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. }