123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201 |
- using PDF_Office.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_Office.Model;
- using PDFSettings;
- using PDF_Office.CustomControl;
- using PDF_Office.Model.Dialog.HomePageToolsDialogs.HomePageBatchProcessing;
- using Prism.Services.Dialogs;
- namespace PDF_Office.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;
- /// <summary>
- /// 属性设置Region
- /// </summary>
- public string HeaderFooterSettingsRegionName
- {
- get { return _headerFooterSettingsRegionName; }
- set { _headerFooterSettingsRegionName = value; }
- }
- private Visibility _headerFooterSettingsVisible = Visibility.Visible;
- /// <summary>
- /// 属性设置Region可见
- /// </summary>
- public Visibility HeaderFooterSettingsVisible
- {
- get { return _headerFooterSettingsVisible; }
- set { _headerFooterSettingsVisible = value; }
- }
- private string _headerFooterDocumentRegionName;
- /// <summary>
- /// 持有Document的Region,负责渲染和保存
- /// </summary>
- public string HeaderFooterDocumentRegionName
- {
- get { return _headerFooterDocumentRegionName; }
- set { _headerFooterDocumentRegionName = value; }
- }
- private Visibility _headerFooterDocumentVisible = Visibility.Visible;
- /// <summary>
- /// 持有Document的Region可见
- /// </summary>
- 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<EditBatesHeaderFooterTemplateItemEvent>().Subscribe(EditHeaderFooterTemplateItem, e => e.Unicode == Unicode && e.Type == HeaderFooterType);
- eventAggregator.GetEvent<EnterTemplateListOrCreateEvent>().Subscribe(EnterTemplateListOrCreate, e => e.Unicode == Unicode);
-
- }
- public void CloseEditTool()
- {
- this.eventAggregator.GetEvent<CloseEditToolEvent>().Publish(new EnumCloseModeUnicode { Unicode = Unicode, Status = EnumCloseMode.StatusCancel });
- }
- public void ConfirmEditTool()
- {
- this.eventAggregator.GetEvent<ConfirmEditToolsHeaderFooterEvent>().Publish(Unicode);
- this.eventAggregator.GetEvent<CloseEditToolEvent>().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<DeleteHeaderFooterEvent>().Publish(new EnumDeleteUnicode
- {
- Unicode = Unicode,
- Status = EnumDelete.StatusDeleteAll
- });
- }
- else
- {
- this.eventAggregator.GetEvent<DeleteHeaderFooterEvent>().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<string> { 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<ViewContentViewModel>(ParameterNames.ViewContentViewModel, out viewContentViewModel);
- navigationContext.Parameters.TryGetValue<CPDFViewer>(ParameterNames.PDFViewer, out PDFViewer);
- EnterSelectedContent(TemplateListName);
- EnterDocumentContent();
- }
- public bool IsNavigationTarget(NavigationContext navigationContext)
- {
- return true;
- }
- public void OnNavigatedFrom(NavigationContext navigationContext)
- {
- }
- }
- }
|