HomePageBackgroundCreateBaseContentViewModel.cs 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  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.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. SelectContentVisibility=Visibility.Collapsed;
  39. CreateBaseVisible = Visibility.Collapsed;
  40. }
  41. else if (value == EnumCreateOrEdit.StatusCreate)
  42. {
  43. CreateBaseVisible = Visibility.Visible;
  44. SelectContentVisibility=Visibility.Visible;
  45. EditBaseVisible = Visibility.Collapsed;
  46. }
  47. }
  48. }
  49. private string backgroundCreateRegionName;
  50. public string BackgroundCreateRegionName
  51. {
  52. get => backgroundCreateRegionName;
  53. set => SetProperty(ref backgroundCreateRegionName, value);
  54. }
  55. private string _currentCreateModName;
  56. public string CurrentCreateModName
  57. {
  58. get => _currentCreateModName;
  59. set => _currentCreateModName = value;
  60. }
  61. private System.Windows.Visibility backgroundCreateVisible;
  62. public System.Windows.Visibility BackgroundCreateVisible
  63. {
  64. get => backgroundCreateVisible;
  65. set => SetProperty(ref backgroundCreateVisible, value);
  66. }
  67. private bool isFirstEnter = true;
  68. public bool IsFirstEnter
  69. {
  70. get => isFirstEnter;
  71. set => isFirstEnter = value;
  72. }
  73. private Visibility _createBaseVisible;
  74. public Visibility CreateBaseVisible
  75. {
  76. get => _createBaseVisible;
  77. set => SetProperty(ref _createBaseVisible, value);
  78. }
  79. private Visibility _editBaseVisible;
  80. public Visibility EditBaseVisible
  81. {
  82. get => _editBaseVisible;
  83. set => SetProperty(ref _editBaseVisible, value);
  84. }
  85. private Visibility _selectContentVisibility;
  86. public Visibility SelectContentVisibility
  87. {
  88. get => _selectContentVisibility;
  89. set => SetProperty(ref _selectContentVisibility, value);
  90. }
  91. public EnumColorOrFile CurrentTemplateListMod;
  92. public DelegateCommand<object> ChangeCreateModCommand { get; set; }
  93. public DelegateCommand EnterTemplateListCommand { get; set; }
  94. public DelegateCommand SaveToTemplateListCommand { get; set; }
  95. public DelegateCommand SaveToCurrentTemplateListCommand { get; set; }
  96. public string unicode = null;
  97. public string Unicode = null;
  98. public HomePageBackgroundCreateBaseContentViewModel(IRegionManager regionManager, IEventAggregator eventAggregator)
  99. {
  100. this.eventAggregator = eventAggregator;
  101. this.backgroundCreateRegion = regionManager;
  102. BackgroundCreateRegionName = Guid.NewGuid().ToString();
  103. ChangeCreateModCommand = new DelegateCommand<object>(ChangeCreateMod);
  104. EnterTemplateListCommand = new DelegateCommand(EnterTemplateList);
  105. SaveToTemplateListCommand = new DelegateCommand(SaveToTemplateList);
  106. SaveToCurrentTemplateListCommand = new DelegateCommand(SaveToCurrentTemplateList);
  107. }
  108. public void SaveToTemplateList()
  109. {
  110. if (CurrentCreateModName == "HomePageBackgroundCreateColorContent")
  111. {
  112. this.eventAggregator.GetEvent<SaveBackgroundTemplateEvent>().Publish(new EnumColorOrFileUnicode { Unicode = Unicode, Status = EnumColorOrFile.StatusColor });
  113. }
  114. if (CurrentCreateModName == "HomePageBackgroundCreateFileContent")
  115. {
  116. this.eventAggregator.GetEvent<SaveBackgroundTemplateEvent>().Publish(new EnumColorOrFileUnicode
  117. {
  118. Unicode = Unicode,
  119. Status = EnumColorOrFile.StatusFile
  120. });
  121. }
  122. }
  123. public void SaveToCurrentTemplateList()
  124. {
  125. if (CurrentCreateModName == "HomePageBackgroundCreateColorContent")
  126. {
  127. eventAggregator.GetEvent<ConfirmEditBackgroundTemplateItemEvent>().Publish(new EnumColorOrFileUnicode
  128. {
  129. Unicode = Unicode,
  130. Status = EnumColorOrFile.StatusColor
  131. });
  132. }
  133. if (CurrentCreateModName == "HomePageBackgroundCreateFileContent")
  134. {
  135. eventAggregator.GetEvent<ConfirmEditBackgroundTemplateItemEvent>().Publish(new EnumColorOrFileUnicode
  136. {
  137. Unicode = Unicode,
  138. Status = EnumColorOrFile.StatusFile
  139. });
  140. }
  141. }
  142. public void EnterTemplateList()
  143. {
  144. this.eventAggregator.GetEvent<EnterTemplateListOrCreateEvent>().Publish(new EnumTemplateListOrCreateUnicode { Unicode = Unicode, Status = EnumTemplateListOrCreate.StatusTemplate });
  145. }
  146. public void EnterSelectedCreateMod(string currentCreateName)
  147. {
  148. NavigationParameters param = new NavigationParameters();
  149. param.Add("Unicode", Unicode);
  150. param.Add(ParameterNames.PDFViewer, PDFViewer);
  151. backgroundCreateRegion.RequestNavigate(BackgroundCreateRegionName, currentCreateName, param);
  152. backgroundCreateVisible = 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("Unicode", Unicode);
  159. param.Add("BackgroundItem", BackgroundItem);
  160. backgroundCreateRegion.RequestNavigate(BackgroundCreateRegionName, currentCreateName, param);
  161. backgroundCreateVisible = System.Windows.Visibility.Visible;
  162. }
  163. public void ChangeCreateMod(object e)
  164. {
  165. var args = e as Button;
  166. if (args != null)
  167. {
  168. if (CreateOrEdit == EnumCreateOrEdit.StatusCreate)
  169. {
  170. CurrentCreateModName = args.Name;
  171. EnterSelectedCreateMod(CurrentCreateModName);
  172. eventAggregator.GetEvent<SetCurrentCreateModEvent>().Publish(new stringUnicode
  173. {
  174. Unicode = Unicode,
  175. Status = CurrentCreateModName
  176. });
  177. }
  178. else if (CreateOrEdit == EnumCreateOrEdit.StatusEdit)
  179. {
  180. CurrentCreateModName = args.Name;
  181. EditSelectedTemplateItem(CurrentCreateModName);
  182. eventAggregator.GetEvent<SetCurrentCreateModEvent>().Publish(new stringUnicode
  183. {
  184. Unicode = Unicode,
  185. Status = CurrentCreateModName
  186. });
  187. }
  188. }
  189. }
  190. public bool IsNavigationTarget(NavigationContext navigationContext)
  191. {
  192. return true;
  193. }
  194. public void OnNavigatedFrom(NavigationContext navigationContext)
  195. {
  196. }
  197. public void OnNavigatedTo(NavigationContext navigationContext)
  198. {
  199. navigationContext.Parameters.TryGetValue<string>("Unicode", out Unicode);
  200. navigationContext.Parameters.TryGetValue<CPDFViewer>(ParameterNames.PDFViewer, out PDFViewer);
  201. navigationContext.Parameters.TryGetValue<EnumColorOrFile>("CurrentTemplateListModName", out CurrentTemplateListMod);
  202. if (CurrentTemplateListMod == EnumColorOrFile.StatusColor)
  203. {
  204. CurrentCreateModName = "HomePageBackgroundCreateColorContent";
  205. }
  206. else
  207. {
  208. CurrentCreateModName = "HomePageBackgroundCreateFileContent";
  209. }
  210. if (navigationContext.Parameters.TryGetValue<BackgroundItem>("BackgroundItem", out BackgroundItem))
  211. {
  212. EditSelectedTemplateItem(CurrentCreateModName);
  213. CreateOrEdit = EnumCreateOrEdit.StatusEdit;
  214. }
  215. else
  216. {
  217. EnterSelectedCreateMod(CurrentCreateModName);
  218. CreateOrEdit = EnumCreateOrEdit.StatusCreate;
  219. }
  220. eventAggregator.GetEvent<SetCurrentCreateModEvent>().Publish(new stringUnicode
  221. {
  222. Unicode = Unicode,
  223. Status = CurrentCreateModName
  224. });
  225. }
  226. }
  227. }