123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236 |
- using ComPDFKitViewer.PdfViewer;
- using PDF_Master.EventAggregators;
- using PDF_Master.Helper;
- using PDF_Master.Model;
- using PDF_Master.Model.EditTools.Bates;
- using PDF_Master.Model.EditTools.HeaderFooter;
- using PDF_Master.Properties;
- using PDFSettings;
- using Prism.Commands;
- using Prism.Events;
- using Prism.Mvvm;
- using Prism.Regions;
- using System;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.Linq;
- using System.Windows;
- using System.Windows.Controls;
- namespace PDF_Master.ViewModels.EditTools.HeaderFooter
- {
- public class HeaderFooterTemplateListContentViewModel : BindableBase, INavigationAware
- {
- public IEventAggregator eventAggregator;
- private CPDFViewer PDFViewer;
- public HeaderFooterInfo HeaderFooterInfo = new HeaderFooterInfo();
- public BatesHeaderFooterItem HeaderFooterItem = new BatesHeaderFooterItem();
- public int TemplateIndex = 0;
- private ObservableCollection<BatesHeaderFooterItem> headerFooterModCollection = new ObservableCollection<BatesHeaderFooterItem>();
- public ObservableCollection<BatesHeaderFooterItem> HeaderFooterModCollection
- {
- get { return headerFooterModCollection; }
- set
- {
- headerFooterModCollection = value;
- RaisePropertyChanged();
- }
- }
- private Visibility _createTemplateVisible;
- public Visibility CreateTemplateVisible
- {
- get { return _createTemplateVisible; }
- set { SetProperty(ref _createTemplateVisible, value); }
- }
- public DelegateCommand AddTemplateCommand { get; set; }
- public DelegateCommand<object> DeleteTemplateItemCommand { get; set; }
- public DelegateCommand<object> EditTemplateItemCommand { get; set; }
- public DelegateCommand DeleteAllTemplateItemCommand { get; set; }
- public DelegateCommand<object> SelectTemplateItemCommand { get; set; }
- public DelegateCommand EnterCreateCommand { get; set; }
- public string Unicode = null;
- public HeaderFooterTemplateListContentViewModel(IEventAggregator eventAggregator)
- {
- this.eventAggregator = eventAggregator;
- Unicode = App.mainWindowViewModel.SelectedItem.Unicode;
- EnterCreateCommand = new DelegateCommand(EnterCreate);
- AddTemplateCommand = new DelegateCommand(AddTemplate);
- EditTemplateItemCommand = new DelegateCommand<object>(RequestEditTemplateItem);
- DeleteTemplateItemCommand = new DelegateCommand<object>(DeleteTemplateItem);
- DeleteAllTemplateItemCommand = new DelegateCommand(DeleteAllTemplateItem);
- SelectTemplateItemCommand = new DelegateCommand<object>(SelectTemplateItem);
- }
- private void InitBackgroundTemplateList()
- {
- if (Settings.Default.HeaderFooterTemplateList == null)
- {
- Settings.Default.HeaderFooterTemplateList = new HeaderFooterTemplateList();
- }
- GetHeaderFooterSource();
- }
- public void EnterCreate()
- {
- this.eventAggregator.GetEvent<EnterTemplateListOrCreateEvent>().Publish(new EnumTemplateListOrCreateUnicode { Unicode = Unicode, Status = EnumTemplateListOrCreate.StatusCreate });
- }
- public void AddTemplate()
- {
- this.eventAggregator.GetEvent<EnterTemplateListOrCreateEvent>().Publish(new EnumTemplateListOrCreateUnicode
- {
- Unicode = Unicode,
- Status = EnumTemplateListOrCreate.StatusCreate
- });
- }
- public void SaveEditedBatesTemplateItem(BatesHeaderFooterItemUnicode HeaderFooterItemunicode)
- {
- BatesHeaderFooterItem headerFooterItem = HeaderFooterItemunicode.Status;
- Settings.Default.HeaderFooterTemplateList[TemplateIndex] = headerFooterItem;
- Settings.Default.Save();
- GetHeaderFooterSource();
- }
- public void RequestEditTemplateItem(object e)
- {
- var control = e as Control;
- if (control == null)
- {
- return;
- }
- var template = control.DataContext as BatesHeaderFooterItem;
- if (template == null)
- {
- return;
- }
- TemplateIndex = Settings.Default.HeaderFooterTemplateList.IndexOf(template);
- template.listIndex = TemplateIndex;
- ConvertItemToInfo(template, ref HeaderFooterInfo);
- this.eventAggregator.GetEvent<EditBatesHeaderFooterTemplateItemEvent>().Publish(new BatesHeaderFooterItemUnicode
- {
- Unicode = Unicode,
- Type = "HeaderFooterType",
- Status = template
- });
- }
- public void DeleteTemplateItem(object e)
- {
- var btn = e as System.Windows.Controls.Control;
- if (btn == null)
- {
- return;
- }
- HeaderFooterItem = btn.DataContext as BatesHeaderFooterItem;
- if (HeaderFooterItem == null)
- {
- return;
- }
- Settings.Default.HeaderFooterTemplateList.Remove(HeaderFooterItem);
- Settings.Default.Save();
- HeaderFooterModCollection.Remove(HeaderFooterItem);
- GetHeaderFooterSource();
- }
- public void DeleteAllTemplateItem()
- {
- List<BatesHeaderFooterItem> removeheaderfooterItems = new List<BatesHeaderFooterItem>();
- for (int i = 0; i < Settings.Default.HeaderFooterTemplateList.Count; i++)
- {
- var template = Settings.Default.HeaderFooterTemplateList[i];
- removeheaderfooterItems.Add(template);
- }
- foreach (var removetemplate in removeheaderfooterItems)
- {
- Settings.Default.HeaderFooterTemplateList.Remove(removetemplate);
- Settings.Default.Save();
- HeaderFooterModCollection.Remove(removetemplate);
- }
- GetHeaderFooterSource();
- }
- public void SelectTemplateItem(object e)
- {
- var listBox = e as ListBox;
- BatesHeaderFooterItem HeaderFooterItem = listBox.SelectedItem as BatesHeaderFooterItem;
- SendTemplateItemToDocument(HeaderFooterItem);
- }
- public void SendTemplateItemToDocument(BatesHeaderFooterItem template)
- {
- if (template != null)
- {
- ConvertItemToInfo(template, ref HeaderFooterInfo);
- eventAggregator.GetEvent<SetHeaderFooterEvent>().Publish(new HeaderFooterInfoUnicode
- {
- Unicode = Unicode,
- Status = HeaderFooterInfo
- });
- }
- }
- private void GetHeaderFooterSource()
- {
- List<BatesHeaderFooterItem> headerFooterModColorTemplateList = new List<BatesHeaderFooterItem>();
- for (int temp = 0; temp < Settings.Default.HeaderFooterTemplateList.Count; temp++)
- {
- Settings.Default.HeaderFooterTemplateList[temp].ItemName = (temp + 1).ToString();
- headerFooterModColorTemplateList.Add(Settings.Default.HeaderFooterTemplateList[temp]);
- }
- HeaderFooterModCollection = new ObservableCollection<BatesHeaderFooterItem>(headerFooterModColorTemplateList);
- CheckTemplateListIsEmpty(headerFooterModColorTemplateList);
- }
- public void ConvertItemToInfo(BatesHeaderFooterItem headerFooterItem, ref HeaderFooterInfo headerFooterInfo)
- {
- headerFooterInfo.TextData = headerFooterItem.TextData;
- headerFooterInfo.ItemName=headerFooterItem.ItemName;
- headerFooterInfo.DateTimeFormat = headerFooterItem.DateTimeFormat;
- headerFooterInfo.StarPagetNumber = headerFooterItem.StarPagetNumber;
- headerFooterInfo.PageNumberFormat = headerFooterItem.PageNumberFormat;
- headerFooterInfo.margin = headerFooterItem.margin;
- headerFooterInfo.PageRangeIndex = headerFooterItem.PageRangeIndex;
- headerFooterInfo.PageRange=headerFooterItem.PageRange;
- }
- private void CheckTemplateListIsEmpty(List<BatesHeaderFooterItem> headerFooterTemplateList)
- {
- if (headerFooterTemplateList.Count() == 0)
- {
- CreateTemplateVisible = Visibility.Visible;
- }
- else
- {
- CreateTemplateVisible = Visibility.Collapsed;
- }
- }
- public bool IsNavigationTarget(NavigationContext navigationContext)
- {
- return true;
- }
- public void OnNavigatedFrom(NavigationContext navigationContext)
- {
- }
- public void OnNavigatedTo(NavigationContext navigationContext)
- {
- navigationContext.Parameters.TryGetValue<CPDFViewer>(ParameterNames.PDFViewer, out PDFViewer);
- InitBackgroundTemplateList();
-
- }
- }
- }
|