HeaderFooterContentViewModel.cs 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. using PDF_Master.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_Master.Model;
  12. using PDFSettings;
  13. using PDF_Master.CustomControl;
  14. using PDF_Master.Model.Dialog.HomePageToolsDialogs.HomePageBatchProcessing;
  15. using Prism.Services.Dialogs;
  16. namespace PDF_Master.ViewModels.EditTools.HeaderFooter
  17. {
  18. public class HeaderFooterContentViewModel : BindableBase, INavigationAware
  19. {
  20. public IEventAggregator eventAggregator;
  21. public IRegionManager headerFooterRegion;
  22. public IDialogService dialogs;
  23. private CPDFViewer PDFViewer;
  24. private ViewContentViewModel viewContentViewModel;
  25. public string TemplateListName = "HeaderFooterTemplateListContent";
  26. public string CreateName = "HeaderFooterCreateContent";
  27. public string HeaderFooterDocumentName = "HeaderFooterDocumentContent";
  28. public string HeaderFooterType = "HeaderFooterType";
  29. private string _headerFooterSettingsRegionName;
  30. /// <summary>
  31. /// 属性设置Region
  32. /// </summary>
  33. public string HeaderFooterSettingsRegionName
  34. {
  35. get { return _headerFooterSettingsRegionName; }
  36. set { _headerFooterSettingsRegionName = value; }
  37. }
  38. private Visibility _headerFooterSettingsVisible = Visibility.Visible;
  39. /// <summary>
  40. /// 属性设置Region可见
  41. /// </summary>
  42. public Visibility HeaderFooterSettingsVisible
  43. {
  44. get { return _headerFooterSettingsVisible; }
  45. set { _headerFooterSettingsVisible = value; }
  46. }
  47. private string _headerFooterDocumentRegionName;
  48. /// <summary>
  49. /// 持有Document的Region,负责渲染和保存
  50. /// </summary>
  51. public string HeaderFooterDocumentRegionName
  52. {
  53. get { return _headerFooterDocumentRegionName; }
  54. set { _headerFooterDocumentRegionName = value; }
  55. }
  56. private Visibility _headerFooterDocumentVisible = Visibility.Visible;
  57. /// <summary>
  58. /// 持有Document的Region可见
  59. /// </summary>
  60. public Visibility HeaderFooterDocumentVisible
  61. {
  62. get { return _headerFooterDocumentVisible; }
  63. set { _headerFooterDocumentVisible = value; }
  64. }
  65. public DelegateCommand CloseEditToolCommand { get; set; }
  66. public DelegateCommand ConfirmEditToolCommand { get; set; }
  67. public DelegateCommand BatchHeaderFooterCommand { get; set; }
  68. public DelegateCommand DeleteHeaderFooterCommand { get; set; }
  69. public string Unicode = null;
  70. public HeaderFooterContentViewModel(IRegionManager regionManager, IEventAggregator eventAggregator, IDialogService dialogs)
  71. {
  72. this.eventAggregator = eventAggregator;
  73. this.headerFooterRegion = regionManager;
  74. this.dialogs = dialogs;
  75. HeaderFooterSettingsRegionName = Guid.NewGuid().ToString();
  76. HeaderFooterDocumentRegionName = Guid.NewGuid().ToString();
  77. Unicode = App.mainWindowViewModel.SelectedItem.Unicode;
  78. CloseEditToolCommand = new DelegateCommand(CloseEditTool);
  79. ConfirmEditToolCommand = new DelegateCommand(ConfirmEditTool);
  80. DeleteHeaderFooterCommand = new DelegateCommand(DeleteHeaderFooter);
  81. BatchHeaderFooterCommand = new DelegateCommand(BatchHeaderFooter);
  82. eventAggregator.GetEvent<EditBatesHeaderFooterTemplateItemEvent>().Subscribe(EditHeaderFooterTemplateItem, e => e.Unicode == Unicode && e.Type == HeaderFooterType);
  83. eventAggregator.GetEvent<EnterTemplateListOrCreateEvent>().Subscribe(EnterTemplateListOrCreate, e => e.Unicode == Unicode);
  84. }
  85. public void CloseEditTool()
  86. {
  87. this.eventAggregator.GetEvent<CloseEditToolEvent>().Publish(new EnumCloseModeUnicode { Unicode = Unicode, Status = EnumCloseMode.StatusCancel });
  88. }
  89. public void ConfirmEditTool()
  90. {
  91. this.eventAggregator.GetEvent<ConfirmEditToolsHeaderFooterEvent>().Publish(Unicode);
  92. this.eventAggregator.GetEvent<CloseEditToolEvent>().Publish(new EnumCloseModeUnicode { Unicode = Unicode, Status = EnumCloseMode.StatusConfirm });
  93. }
  94. private void DeleteHeaderFooter()
  95. {
  96. AlertsMessage alertsMessage = new AlertsMessage();
  97. alertsMessage.ShowDialog("确定要删除页眉页脚吗?", "", "取消", "删除");
  98. if (alertsMessage.result == ContentResult.Ok)
  99. {
  100. this.eventAggregator.GetEvent<DeleteHeaderFooterEvent>().Publish(new EnumDeleteUnicode
  101. {
  102. Unicode = Unicode,
  103. Status = EnumDelete.StatusDeleteAll
  104. });
  105. }
  106. else
  107. {
  108. this.eventAggregator.GetEvent<DeleteHeaderFooterEvent>().Publish(new EnumDeleteUnicode
  109. {
  110. Unicode = Unicode,
  111. Status = EnumDelete.StatusCreate
  112. });
  113. }
  114. }
  115. private void BatchHeaderFooter()
  116. {
  117. DialogParameters headerFooterpdf = new DialogParameters();
  118. headerFooterpdf.Add(ParameterNames.BatchProcessing_Name, "5");
  119. HomePageBatchProcessingDialogModel.FilePaths = new List<string> { PDFViewer.Document.FilePath.ToString() };
  120. HomePageBatchProcessingDialogModel.BatchProcessingIndex = 5;
  121. headerFooterpdf.Add(ParameterNames.FilePath, new string[] { PDFViewer.Document.FilePath.ToString() });
  122. dialogs.ShowDialog(DialogNames.HomePageBatchProcessingDialog, headerFooterpdf, e => { EnterSelectedContent(TemplateListName); });
  123. }
  124. public void EnterSelectedContent(string SelectedContentName)
  125. {
  126. NavigationParameters param = new NavigationParameters();
  127. param.Add(ParameterNames.PDFViewer, PDFViewer);
  128. headerFooterRegion.RequestNavigate(HeaderFooterSettingsRegionName, SelectedContentName, param);
  129. HeaderFooterSettingsVisible = Visibility.Visible;
  130. }
  131. public void EnterDocumentContent()
  132. {
  133. NavigationParameters param = new NavigationParameters();
  134. param.Add(ParameterNames.PDFViewer, PDFViewer);
  135. param.Add(ParameterNames.ViewContentViewModel, viewContentViewModel);
  136. headerFooterRegion.RequestNavigate(HeaderFooterDocumentRegionName, HeaderFooterDocumentName, param);
  137. HeaderFooterDocumentVisible = Visibility.Visible;
  138. }
  139. public void EnterTemplateListOrCreate(EnumTemplateListOrCreateUnicode enumTemplateListOrCreateunicode)
  140. {
  141. EnumTemplateListOrCreate enumTemplateListOrCreate = enumTemplateListOrCreateunicode.Status;
  142. if (enumTemplateListOrCreate == EnumTemplateListOrCreate.StatusTemplate)
  143. {
  144. EnterSelectedContent(TemplateListName);
  145. }
  146. else
  147. {
  148. EnterSelectedContent(CreateName);
  149. }
  150. }
  151. public void EditHeaderFooterTemplateItem(BatesHeaderFooterItemUnicode headerfooterItemunicode)
  152. {
  153. BatesHeaderFooterItem headerfooterItem = headerfooterItemunicode.Status;
  154. NavigationParameters param = new NavigationParameters();
  155. param.Add(ParameterNames.PDFViewer, PDFViewer);
  156. param.Add("HeaderFooterItem", headerfooterItem);
  157. headerFooterRegion.RequestNavigate(HeaderFooterSettingsRegionName, CreateName, param);
  158. HeaderFooterSettingsVisible = Visibility.Visible;
  159. }
  160. public void OnNavigatedTo(NavigationContext navigationContext)
  161. {
  162. navigationContext.Parameters.TryGetValue<ViewContentViewModel>(ParameterNames.ViewContentViewModel, out viewContentViewModel);
  163. navigationContext.Parameters.TryGetValue<CPDFViewer>(ParameterNames.PDFViewer, out PDFViewer);
  164. EnterSelectedContent(TemplateListName);
  165. EnterDocumentContent();
  166. }
  167. public bool IsNavigationTarget(NavigationContext navigationContext)
  168. {
  169. return true;
  170. }
  171. public void OnNavigatedFrom(NavigationContext navigationContext)
  172. {
  173. }
  174. }
  175. }