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;
///
/// 属性设置Region
///
public string BatesSettingsRegionName
{
get { return _batesSettingsRegionName; }
set { _batesSettingsRegionName = value; }
}
private Visibility _batesSettingsVisible = Visibility.Visible;
///
/// 属性设置Region可见
///
public Visibility BatesSettingsVisible
{
get { return _batesSettingsVisible; }
set { _batesSettingsVisible = value; }
}
private string _batesDocumentRegionName;
///
/// 持有Document的Region,负责渲染和保存
///
public string BatesDocumentRegionName
{
get { return _batesDocumentRegionName; }
set { _batesDocumentRegionName = value; }
}
private Visibility _batesDocumentVisible = Visibility.Visible;
///
/// 持有Document的Region可见
///
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().Subscribe(EditBatesTemplateItem, e => e.Unicode == Unicode&&e.Type== BatesType);
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 DeleteBates()
{
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
});
}
}
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(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)
{
}
}
}