BatesContentViewModel.cs 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. using PDF_Office.EventAggregators;
  2. using Prism.Commands;
  3. using Prism.Events;
  4. using Prism.Mvvm;
  5. using Prism.Regions;
  6. using System.Windows;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Linq;
  10. using ComPDFKitViewer.PdfViewer;
  11. using PDF_Office.Model;
  12. using PDFSettings;
  13. using PDF_Office.CustomControl;
  14. namespace PDF_Office.ViewModels.EditTools.Bates
  15. {
  16. public class BatesContentViewModel : BindableBase,INavigationAware
  17. {
  18. public IEventAggregator eventAggregator;
  19. public IRegionManager batesRegion;
  20. private CPDFViewer PDFViewer;
  21. private ViewContentViewModel viewContentViewModel;
  22. public string TemplateListName = "BatesTemplateListContent";
  23. public string CreateName = "BatesCreateContent";
  24. public string BatesDocumentName = "BatesDocumentContent";
  25. public string BatesType = "BatesType";
  26. private string _batesSettingsRegionName;
  27. /// <summary>
  28. /// 属性设置Region
  29. /// </summary>
  30. public string BatesSettingsRegionName
  31. {
  32. get { return _batesSettingsRegionName; }
  33. set { _batesSettingsRegionName = value; }
  34. }
  35. private Visibility _batesSettingsVisible = Visibility.Visible;
  36. /// <summary>
  37. /// 属性设置Region可见
  38. /// </summary>
  39. public Visibility BatesSettingsVisible
  40. {
  41. get { return _batesSettingsVisible; }
  42. set { _batesSettingsVisible = value; }
  43. }
  44. private string _batesDocumentRegionName;
  45. /// <summary>
  46. /// 持有Document的Region,负责渲染和保存
  47. /// </summary>
  48. public string BatesDocumentRegionName
  49. {
  50. get { return _batesDocumentRegionName; }
  51. set { _batesDocumentRegionName = value; }
  52. }
  53. private Visibility _batesDocumentVisible = Visibility.Visible;
  54. /// <summary>
  55. /// 持有Document的Region可见
  56. /// </summary>
  57. public Visibility BatesDocumentVisible
  58. {
  59. get { return _batesDocumentVisible; }
  60. set { _batesDocumentVisible = value; }
  61. }
  62. public DelegateCommand CloseEditToolCommand { get; set; }
  63. public DelegateCommand ConfirmEditToolCommand { get; set; }
  64. public DelegateCommand DeleteBatesCommand { get; set; }
  65. public string Unicode = null;
  66. public BatesContentViewModel(IRegionManager regionManager, IEventAggregator eventAggregator)
  67. {
  68. this.eventAggregator = eventAggregator;
  69. this.batesRegion = regionManager;
  70. BatesSettingsRegionName = Guid.NewGuid().ToString();
  71. BatesDocumentRegionName = Guid.NewGuid().ToString();
  72. Unicode = App.mainWindowViewModel.SelectedItem.Unicode;
  73. CloseEditToolCommand = new DelegateCommand(CloseEditTool);
  74. ConfirmEditToolCommand = new DelegateCommand(ConfirmEditTool);
  75. DeleteBatesCommand = new DelegateCommand(DeleteBates);
  76. eventAggregator.GetEvent<EditBatesHeaderFooterTemplateItemEvent>().Subscribe(EditBatesTemplateItem, e => e.Unicode == Unicode&&e.Type== BatesType);
  77. eventAggregator.GetEvent<EnterTemplateListOrCreateEvent>().Subscribe(EnterTemplateListOrCreate, e => e.Unicode == Unicode);
  78. }
  79. public void CloseEditTool()
  80. {
  81. this.eventAggregator.GetEvent<CloseEditToolEvent>().Publish(new EnumCloseModeUnicode { Unicode = Unicode, Status = EnumCloseMode.StatusCancel });
  82. }
  83. public void ConfirmEditTool()
  84. {
  85. this.eventAggregator.GetEvent<ConfirmEditToolsBatesEvent>().Publish(Unicode);
  86. this.eventAggregator.GetEvent<CloseEditToolEvent>().Publish(new EnumCloseModeUnicode { Unicode = Unicode, Status = EnumCloseMode.StatusConfirm });
  87. }
  88. private void DeleteBates()
  89. {
  90. AlertsMessage alertsMessage = new AlertsMessage();
  91. alertsMessage.ShowDialog("确定要删除背景吗?", "", "取消", "删除");
  92. if (alertsMessage.result == ContentResult.Ok)
  93. {
  94. this.eventAggregator.GetEvent<DeleteBatesEvent>().Publish(new EnumDeleteUnicode
  95. {
  96. Unicode = Unicode,
  97. Status = EnumDelete.StatusDeleteAll
  98. });
  99. }
  100. else
  101. {
  102. this.eventAggregator.GetEvent<DeleteBatesEvent>().Publish(new EnumDeleteUnicode
  103. {
  104. Unicode = Unicode,
  105. Status = EnumDelete.StatusCreate
  106. });
  107. }
  108. }
  109. public void EnterSelectedContent(string SelectedContentName)
  110. {
  111. NavigationParameters param = new NavigationParameters();
  112. param.Add(ParameterNames.PDFViewer, PDFViewer);
  113. batesRegion.RequestNavigate(BatesSettingsRegionName, SelectedContentName, param);
  114. BatesSettingsVisible = Visibility.Visible;
  115. }
  116. public void EditBatesTemplateItem(BatesHeaderFooterItemUnicode batesItemunicode)
  117. {
  118. BatesHeaderFooterItem batesItem = batesItemunicode.Status;
  119. NavigationParameters param = new NavigationParameters();
  120. param.Add(ParameterNames.PDFViewer, PDFViewer);
  121. param.Add("BatesItem", batesItem);
  122. batesRegion.RequestNavigate(BatesSettingsRegionName, CreateName, param);
  123. BatesSettingsVisible = Visibility.Visible;
  124. }
  125. public void EnterDocumentContent()
  126. {
  127. NavigationParameters param = new NavigationParameters();
  128. param.Add(ParameterNames.PDFViewer, PDFViewer);
  129. param.Add(ParameterNames.ViewContentViewModel, viewContentViewModel);
  130. batesRegion.RequestNavigate(BatesDocumentRegionName, BatesDocumentName, param);
  131. BatesDocumentVisible = Visibility.Visible;
  132. }
  133. public void EnterTemplateListOrCreate(EnumTemplateListOrCreateUnicode enumTemplateListOrCreateunicode)
  134. {
  135. EnumTemplateListOrCreate enumTemplateListOrCreate = enumTemplateListOrCreateunicode.Status;
  136. if (enumTemplateListOrCreate == EnumTemplateListOrCreate.StatusTemplate)
  137. {
  138. EnterSelectedContent(TemplateListName);
  139. }
  140. else
  141. {
  142. EnterSelectedContent(CreateName);
  143. }
  144. }
  145. public void OnNavigatedTo(NavigationContext navigationContext)
  146. {
  147. navigationContext.Parameters.TryGetValue<ViewContentViewModel>(ParameterNames.ViewContentViewModel, out viewContentViewModel);
  148. navigationContext.Parameters.TryGetValue<CPDFViewer>(ParameterNames.PDFViewer, out PDFViewer);
  149. EnterSelectedContent(TemplateListName);
  150. EnterDocumentContent();
  151. }
  152. public bool IsNavigationTarget(NavigationContext navigationContext)
  153. {
  154. return true;
  155. }
  156. public void OnNavigatedFrom(NavigationContext navigationContext)
  157. {
  158. }
  159. }
  160. }