using PDF_Master.EventAggregators; using Prism.Commands; using Prism.Events; using Prism.Mvvm; using Prism.Regions; using System.Windows; using System; using System.Collections.Generic; using System.Linq; using ComPDFKitViewer.PdfViewer; using PDF_Master.Model; using PDFSettings; using PDF_Master.CustomControl; using PDF_Master.Model.Dialog.HomePageToolsDialogs.HomePageBatchProcessing; using Prism.Services.Dialogs; namespace PDF_Master.ViewModels.EditTools.HeaderFooter { public class HeaderFooterContentViewModel : BindableBase, INavigationAware { public IEventAggregator eventAggregator; public IRegionManager headerFooterRegion; public IDialogService dialogs; private CPDFViewer PDFViewer; private ViewContentViewModel viewContentViewModel; public string TemplateListName = "HeaderFooterTemplateListContent"; public string CreateName = "HeaderFooterCreateContent"; public string HeaderFooterDocumentName = "HeaderFooterDocumentContent"; public string HeaderFooterType = "HeaderFooterType"; private string _headerFooterSettingsRegionName; /// /// 属性设置Region /// public string HeaderFooterSettingsRegionName { get { return _headerFooterSettingsRegionName; } set { _headerFooterSettingsRegionName = value; } } private Visibility _headerFooterSettingsVisible = Visibility.Visible; /// /// 属性设置Region可见 /// public Visibility HeaderFooterSettingsVisible { get { return _headerFooterSettingsVisible; } set { _headerFooterSettingsVisible = value; } } private string _headerFooterDocumentRegionName; /// /// 持有Document的Region,负责渲染和保存 /// public string HeaderFooterDocumentRegionName { get { return _headerFooterDocumentRegionName; } set { _headerFooterDocumentRegionName = value; } } private Visibility _headerFooterDocumentVisible = Visibility.Visible; /// /// 持有Document的Region可见 /// public Visibility HeaderFooterDocumentVisible { get { return _headerFooterDocumentVisible; } set { _headerFooterDocumentVisible = value; } } public DelegateCommand CloseEditToolCommand { get; set; } public DelegateCommand ConfirmEditToolCommand { get; set; } public DelegateCommand BatchHeaderFooterCommand { get; set; } public DelegateCommand DeleteHeaderFooterCommand { get; set; } public string Unicode = null; public HeaderFooterContentViewModel(IRegionManager regionManager, IEventAggregator eventAggregator, IDialogService dialogs) { this.eventAggregator = eventAggregator; this.headerFooterRegion = regionManager; this.dialogs = dialogs; HeaderFooterSettingsRegionName = Guid.NewGuid().ToString(); HeaderFooterDocumentRegionName = Guid.NewGuid().ToString(); Unicode = App.mainWindowViewModel.SelectedItem.Unicode; CloseEditToolCommand = new DelegateCommand(CloseEditTool); ConfirmEditToolCommand = new DelegateCommand(ConfirmEditTool); DeleteHeaderFooterCommand = new DelegateCommand(DeleteHeaderFooter); BatchHeaderFooterCommand = new DelegateCommand(BatchHeaderFooter); eventAggregator.GetEvent().Subscribe(EditHeaderFooterTemplateItem, e => e.Unicode == Unicode && e.Type == HeaderFooterType); eventAggregator.GetEvent().Subscribe(EnterTemplateListOrCreate, e => e.Unicode == Unicode); } public void CloseEditTool() { this.eventAggregator.GetEvent().Publish(new EnumCloseModeUnicode { Unicode = Unicode, Status = EnumCloseMode.StatusCancel }); } public void ConfirmEditTool() { this.eventAggregator.GetEvent().Publish(Unicode); this.eventAggregator.GetEvent().Publish(new EnumCloseModeUnicode { Unicode = Unicode, Status = EnumCloseMode.StatusConfirm }); } private void DeleteHeaderFooter() { AlertsMessage alertsMessage = new AlertsMessage(); alertsMessage.ShowDialog("确定要删除页眉页脚吗?", "", "取消", "删除"); if (alertsMessage.result == ContentResult.Ok) { this.eventAggregator.GetEvent().Publish(new EnumDeleteUnicode { Unicode = Unicode, Status = EnumDelete.StatusDeleteAll }); } else { this.eventAggregator.GetEvent().Publish(new EnumDeleteUnicode { Unicode = Unicode, Status = EnumDelete.StatusCreate }); } } private void BatchHeaderFooter() { DialogParameters headerFooterpdf = new DialogParameters(); headerFooterpdf.Add(ParameterNames.BatchProcessing_Name, "5"); HomePageBatchProcessingDialogModel.FilePaths = new List { PDFViewer.Document.FilePath.ToString() }; HomePageBatchProcessingDialogModel.BatchProcessingIndex = 5; headerFooterpdf.Add(ParameterNames.FilePath, new string[] { PDFViewer.Document.FilePath.ToString() }); dialogs.ShowDialog(DialogNames.HomePageBatchProcessingDialog, headerFooterpdf, e => { EnterSelectedContent(TemplateListName); }); } public void EnterSelectedContent(string SelectedContentName) { NavigationParameters param = new NavigationParameters(); param.Add(ParameterNames.PDFViewer, PDFViewer); headerFooterRegion.RequestNavigate(HeaderFooterSettingsRegionName, SelectedContentName, param); HeaderFooterSettingsVisible = Visibility.Visible; } public void EnterDocumentContent() { NavigationParameters param = new NavigationParameters(); param.Add(ParameterNames.PDFViewer, PDFViewer); param.Add(ParameterNames.ViewContentViewModel, viewContentViewModel); headerFooterRegion.RequestNavigate(HeaderFooterDocumentRegionName, HeaderFooterDocumentName, param); HeaderFooterDocumentVisible = Visibility.Visible; } public void EnterTemplateListOrCreate(EnumTemplateListOrCreateUnicode enumTemplateListOrCreateunicode) { EnumTemplateListOrCreate enumTemplateListOrCreate = enumTemplateListOrCreateunicode.Status; if (enumTemplateListOrCreate == EnumTemplateListOrCreate.StatusTemplate) { EnterSelectedContent(TemplateListName); } else { EnterSelectedContent(CreateName); } } public void EditHeaderFooterTemplateItem(BatesHeaderFooterItemUnicode headerfooterItemunicode) { BatesHeaderFooterItem headerfooterItem = headerfooterItemunicode.Status; NavigationParameters param = new NavigationParameters(); param.Add(ParameterNames.PDFViewer, PDFViewer); param.Add("HeaderFooterItem", headerfooterItem); headerFooterRegion.RequestNavigate(HeaderFooterSettingsRegionName, CreateName, param); HeaderFooterSettingsVisible = Visibility.Visible; } public void OnNavigatedTo(NavigationContext navigationContext) { navigationContext.Parameters.TryGetValue(ParameterNames.ViewContentViewModel, out viewContentViewModel); navigationContext.Parameters.TryGetValue(ParameterNames.PDFViewer, out PDFViewer); EnterSelectedContent(TemplateListName); EnterDocumentContent(); } public bool IsNavigationTarget(NavigationContext navigationContext) { return true; } public void OnNavigatedFrom(NavigationContext navigationContext) { } } }