BatesContentViewModel.cs 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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.Bates
  17. {
  18. public class BatesContentViewModel : BindableBase,INavigationAware
  19. {
  20. public IEventAggregator eventAggregator;
  21. public IRegionManager batesRegion;
  22. public IDialogService dialogs;
  23. private CPDFViewer PDFViewer;
  24. private ViewContentViewModel viewContentViewModel;
  25. public string TemplateListName = "BatesTemplateListContent";
  26. public string CreateName = "BatesCreateContent";
  27. public string BatesDocumentName = "BatesDocumentContent";
  28. public string BatesType = "BatesType";
  29. private string _batesSettingsRegionName;
  30. /// <summary>
  31. /// 属性设置Region
  32. /// </summary>
  33. public string BatesSettingsRegionName
  34. {
  35. get { return _batesSettingsRegionName; }
  36. set { _batesSettingsRegionName = value; }
  37. }
  38. private Visibility _batesSettingsVisible = Visibility.Visible;
  39. /// <summary>
  40. /// 属性设置Region可见
  41. /// </summary>
  42. public Visibility BatesSettingsVisible
  43. {
  44. get { return _batesSettingsVisible; }
  45. set { _batesSettingsVisible = value; }
  46. }
  47. private string _batesDocumentRegionName;
  48. /// <summary>
  49. /// 持有Document的Region,负责渲染和保存
  50. /// </summary>
  51. public string BatesDocumentRegionName
  52. {
  53. get { return _batesDocumentRegionName; }
  54. set { _batesDocumentRegionName = value; }
  55. }
  56. private Visibility _batesDocumentVisible = Visibility.Visible;
  57. /// <summary>
  58. /// 持有Document的Region可见
  59. /// </summary>
  60. public Visibility BatesDocumentVisible
  61. {
  62. get { return _batesDocumentVisible; }
  63. set { _batesDocumentVisible = value; }
  64. }
  65. public DelegateCommand CloseEditToolCommand { get; set; }
  66. public DelegateCommand ConfirmEditToolCommand { get; set; }
  67. public DelegateCommand BatchBatesCommand { get; set; }
  68. public DelegateCommand DeleteBatesCommand { get; set; }
  69. public string Unicode = null;
  70. public BatesContentViewModel(IRegionManager regionManager, IEventAggregator eventAggregator, IDialogService dialogs)
  71. {
  72. this.eventAggregator = eventAggregator;
  73. this.batesRegion = regionManager;
  74. this.dialogs=dialogs;
  75. BatesSettingsRegionName = Guid.NewGuid().ToString();
  76. BatesDocumentRegionName = Guid.NewGuid().ToString();
  77. Unicode = App.mainWindowViewModel.SelectedItem.Unicode;
  78. CloseEditToolCommand = new DelegateCommand(CloseEditTool);
  79. ConfirmEditToolCommand = new DelegateCommand(ConfirmEditTool);
  80. DeleteBatesCommand = new DelegateCommand(DeleteBates);
  81. BatchBatesCommand = new DelegateCommand(BatchBates);
  82. eventAggregator.GetEvent<EditBatesHeaderFooterTemplateItemEvent>().Subscribe(EditBatesTemplateItem, e => e.Unicode == Unicode&&e.Type== BatesType);
  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<ConfirmEditToolsBatesEvent>().Publish(Unicode);
  92. this.eventAggregator.GetEvent<CloseEditToolEvent>().Publish(new EnumCloseModeUnicode { Unicode = Unicode, Status = EnumCloseMode.StatusConfirm });
  93. }
  94. private void DeleteBates()
  95. {
  96. AlertsMessage alertsMessage = new AlertsMessage();
  97. alertsMessage.ShowDialog("确定要删除Bates吗?", "", "取消", "删除");
  98. if (alertsMessage.result == ContentResult.Ok)
  99. {
  100. this.eventAggregator.GetEvent<DeleteBatesEvent>().Publish(new EnumDeleteUnicode
  101. {
  102. Unicode = Unicode,
  103. Status = EnumDelete.StatusDeleteAll
  104. });
  105. }
  106. else
  107. {
  108. this.eventAggregator.GetEvent<DeleteBatesEvent>().Publish(new EnumDeleteUnicode
  109. {
  110. Unicode = Unicode,
  111. Status = EnumDelete.StatusCreate
  112. });
  113. }
  114. }
  115. private void BatchBates() {
  116. DialogParameters bates = new DialogParameters();
  117. bates.Add(ParameterNames.BatchProcessing_Name, "6");
  118. HomePageBatchProcessingDialogModel.FilePaths = new List<string> { PDFViewer.Document.FilePath.ToString() };
  119. HomePageBatchProcessingDialogModel.BatchProcessingIndex = 6;
  120. bates.Add(ParameterNames.FilePath, new string[] { PDFViewer.Document.FilePath.ToString() });
  121. dialogs.ShowDialog(DialogNames.HomePageBatchProcessingDialog, bates, e => { EnterSelectedContent(TemplateListName); });
  122. }
  123. public void EnterSelectedContent(string SelectedContentName)
  124. {
  125. NavigationParameters param = new NavigationParameters();
  126. param.Add(ParameterNames.PDFViewer, PDFViewer);
  127. batesRegion.RequestNavigate(BatesSettingsRegionName, SelectedContentName, param);
  128. BatesSettingsVisible = Visibility.Visible;
  129. }
  130. public void EditBatesTemplateItem(BatesHeaderFooterItemUnicode batesItemunicode)
  131. {
  132. BatesHeaderFooterItem batesItem = batesItemunicode.Status;
  133. NavigationParameters param = new NavigationParameters();
  134. param.Add(ParameterNames.PDFViewer, PDFViewer);
  135. param.Add("BatesItem", batesItem);
  136. batesRegion.RequestNavigate(BatesSettingsRegionName, CreateName, param);
  137. BatesSettingsVisible = Visibility.Visible;
  138. }
  139. public void EnterDocumentContent()
  140. {
  141. NavigationParameters param = new NavigationParameters();
  142. param.Add(ParameterNames.PDFViewer, PDFViewer);
  143. param.Add(ParameterNames.ViewContentViewModel, viewContentViewModel);
  144. batesRegion.RequestNavigate(BatesDocumentRegionName, BatesDocumentName, param);
  145. BatesDocumentVisible = Visibility.Visible;
  146. }
  147. public void EnterTemplateListOrCreate(EnumTemplateListOrCreateUnicode enumTemplateListOrCreateunicode)
  148. {
  149. EnumTemplateListOrCreate enumTemplateListOrCreate = enumTemplateListOrCreateunicode.Status;
  150. if (enumTemplateListOrCreate == EnumTemplateListOrCreate.StatusTemplate)
  151. {
  152. EnterSelectedContent(TemplateListName);
  153. }
  154. else
  155. {
  156. EnterSelectedContent(CreateName);
  157. }
  158. }
  159. public void OnNavigatedTo(NavigationContext navigationContext)
  160. {
  161. navigationContext.Parameters.TryGetValue<ViewContentViewModel>(ParameterNames.ViewContentViewModel, out viewContentViewModel);
  162. navigationContext.Parameters.TryGetValue<CPDFViewer>(ParameterNames.PDFViewer, out PDFViewer);
  163. EnterSelectedContent(TemplateListName);
  164. EnterDocumentContent();
  165. }
  166. public bool IsNavigationTarget(NavigationContext navigationContext)
  167. {
  168. return true;
  169. }
  170. public void OnNavigatedFrom(NavigationContext navigationContext)
  171. {
  172. }
  173. }
  174. }