123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185 |
- 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;
- namespace PDF_Office.ViewModels.EditTools.Bates
- {
- public class BatesContentViewModel : BindableBase,INavigationAware
- {
- public IEventAggregator eventAggregator;
- public IRegionManager batesRegion;
- private CPDFViewer PDFViewer;
- private ViewContentViewModel viewContentViewModel;
- public string TemplateListName = "BatesTemplateListContent";
- public string CreateName = "BatesCreateContent";
- public string BatesDocumentName = "BatesDocumentContent";
- public string BatesType = "BatesType";
- private string _batesSettingsRegionName;
- /// <summary>
- /// 属性设置Region
- /// </summary>
- public string BatesSettingsRegionName
- {
- get { return _batesSettingsRegionName; }
- set { _batesSettingsRegionName = value; }
- }
- private Visibility _batesSettingsVisible = Visibility.Visible;
- /// <summary>
- /// 属性设置Region可见
- /// </summary>
- public Visibility BatesSettingsVisible
- {
- get { return _batesSettingsVisible; }
- set { _batesSettingsVisible = value; }
- }
- private string _batesDocumentRegionName;
- /// <summary>
- /// 持有Document的Region,负责渲染和保存
- /// </summary>
- public string BatesDocumentRegionName
- {
- get { return _batesDocumentRegionName; }
- set { _batesDocumentRegionName = value; }
- }
- private Visibility _batesDocumentVisible = Visibility.Visible;
- /// <summary>
- /// 持有Document的Region可见
- /// </summary>
- public Visibility BatesDocumentVisible
- {
- get { return _batesDocumentVisible; }
- set { _batesDocumentVisible = value; }
- }
- public DelegateCommand CloseEditToolCommand { get; set; }
- public DelegateCommand ConfirmEditToolCommand { get; set; }
- public DelegateCommand DeleteBatesCommand { get; set; }
- public string Unicode = null;
- public BatesContentViewModel(IRegionManager regionManager, IEventAggregator eventAggregator)
- {
- this.eventAggregator = eventAggregator;
- this.batesRegion = regionManager;
- BatesSettingsRegionName = Guid.NewGuid().ToString();
- BatesDocumentRegionName = Guid.NewGuid().ToString();
- Unicode = App.mainWindowViewModel.SelectedItem.Unicode;
- CloseEditToolCommand = new DelegateCommand(CloseEditTool);
- ConfirmEditToolCommand = new DelegateCommand(ConfirmEditTool);
- DeleteBatesCommand = new DelegateCommand(DeleteBates);
- eventAggregator.GetEvent<EditBatesHeaderFooterTemplateItemEvent>().Subscribe(EditBatesTemplateItem, e => e.Unicode == Unicode&&e.Type== BatesType);
- 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<ConfirmEditToolsBatesEvent>().Publish(Unicode);
- this.eventAggregator.GetEvent<CloseEditToolEvent>().Publish(new EnumCloseModeUnicode { Unicode = Unicode, Status = EnumCloseMode.StatusConfirm });
- }
- private void DeleteBates()
- {
- AlertsMessage alertsMessage = new AlertsMessage();
- alertsMessage.ShowDialog("确定要删除背景吗?", "", "取消", "删除");
- if (alertsMessage.result == ContentResult.Ok)
- {
- this.eventAggregator.GetEvent<DeleteBatesEvent>().Publish(new EnumDeleteUnicode
- {
- Unicode = Unicode,
- Status = EnumDelete.StatusDeleteAll
- });
- }
- else
- {
- this.eventAggregator.GetEvent<DeleteBatesEvent>().Publish(new EnumDeleteUnicode
- {
- Unicode = Unicode,
- Status = EnumDelete.StatusCreate
- });
- }
- }
- public void EnterSelectedContent(string SelectedContentName)
- {
- NavigationParameters param = new NavigationParameters();
- param.Add(ParameterNames.PDFViewer, PDFViewer);
- batesRegion.RequestNavigate(BatesSettingsRegionName, SelectedContentName, param);
- BatesSettingsVisible = Visibility.Visible;
- }
- public void EditBatesTemplateItem(BatesHeaderFooterItemUnicode batesItemunicode)
- {
- BatesHeaderFooterItem batesItem = batesItemunicode.Status;
- NavigationParameters param = new NavigationParameters();
- param.Add(ParameterNames.PDFViewer, PDFViewer);
- param.Add("BatesItem", batesItem);
- batesRegion.RequestNavigate(BatesSettingsRegionName, CreateName, param);
- BatesSettingsVisible = Visibility.Visible;
- }
- public void EnterDocumentContent()
- {
- NavigationParameters param = new NavigationParameters();
- param.Add(ParameterNames.PDFViewer, PDFViewer);
- param.Add(ParameterNames.ViewContentViewModel, viewContentViewModel);
- batesRegion.RequestNavigate(BatesDocumentRegionName, BatesDocumentName, param);
- BatesDocumentVisible = Visibility.Visible;
- }
- public void EnterTemplateListOrCreate(EnumTemplateListOrCreateUnicode enumTemplateListOrCreateunicode)
- {
- EnumTemplateListOrCreate enumTemplateListOrCreate = enumTemplateListOrCreateunicode.Status;
- if (enumTemplateListOrCreate == EnumTemplateListOrCreate.StatusTemplate)
- {
- EnterSelectedContent(TemplateListName);
- }
- else
- {
- EnterSelectedContent(CreateName);
- }
- }
- 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)
- {
- }
- }
- }
|