123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236 |
- using ComPDFKitViewer.PdfViewer;
- using PDF_Office.EventAggregators;
- using PDF_Office.Helper;
- using PDF_Office.Model;
- using PDF_Office.Model.EditTools.Bates;
- using PDF_Office.Model.EditTools.Bates;
- using PDF_Office.Model.EditTools.HeaderFooter;
- using PDF_Office.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_Office.ViewModels.EditTools.Bates
- {
- public class BatesTemplateListContentViewModel : BindableBase, INavigationAware
- {
- private CPDFViewer PDFViewer;
- public IEventAggregator eventAggregator;
- public BatesInfo BatesInfo = new BatesInfo();
- public BatesHeaderFooterItem BatesItem = new BatesHeaderFooterItem();
- public int TemplateIndex = 0;
- private ObservableCollection<BatesHeaderFooterItem> batesModCollection = new ObservableCollection<BatesHeaderFooterItem>();
- public ObservableCollection<BatesHeaderFooterItem> BatesModCollection
- {
- get { return batesModCollection; }
- set
- {
- batesModCollection = 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 BatesTemplateListContentViewModel(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.BatesTemplateList == null)
- {
- Settings.Default.BatesTemplateList = new BatesTemplateList();
- }
- GetBatesSource();
- }
- 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 BatesItemunicode)
- {
- BatesHeaderFooterItem batesItem = BatesItemunicode.Status;
- Settings.Default.BatesTemplateList[TemplateIndex] = batesItem;
- Settings.Default.Save();
- GetBatesSource();
- }
- 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.BatesTemplateList.IndexOf(template);
- template.listIndex = TemplateIndex;
- ConvertItemToInfo(template, ref BatesInfo);
- this.eventAggregator.GetEvent<EditBatesHeaderFooterTemplateItemEvent>().Publish(new BatesHeaderFooterItemUnicode
- {
- Unicode = Unicode,
- Type = "BatesType",
- Status = template
- });
- }
- public void DeleteTemplateItem(object e)
- {
- var btn = e as System.Windows.Controls.Button;
- if (btn == null)
- {
- return;
- }
- BatesItem = btn.DataContext as BatesHeaderFooterItem;
- if (BatesItem == null)
- {
- return;
- }
- Settings.Default.BatesTemplateList.Remove(BatesItem);
- Settings.Default.Save();
- BatesModCollection.Remove(BatesItem);
- GetBatesSource();
- }
- public void DeleteAllTemplateItem()
- {
- while (Settings.Default.BatesTemplateList.Count != 0)
- {
- int temp = 0;
- var template = Settings.Default.BatesTemplateList[temp];
- Settings.Default.BatesTemplateList.Remove(template);
- Settings.Default.Save();
- BatesModCollection.Remove(template);
- }
- GetBatesSource();
- }
- public void SelectTemplateItem(object e)
- {
- var listBox = e as ListBox;
- BatesHeaderFooterItem BatesItem = listBox.SelectedItem as BatesHeaderFooterItem;
- SendTemplateItemToDocument(BatesItem);
- }
- public void SendTemplateItemToDocument(BatesHeaderFooterItem template)
- {
- if (template != null)
- {
- ConvertItemToInfo(template, ref BatesInfo);
- eventAggregator.GetEvent<SetBatesEvent>().Publish(new BatesInfoUnicode
- {
- Unicode = Unicode,
- Status = BatesInfo
- });
- }
- }
- private void GetBatesSource()
- {
- List<BatesHeaderFooterItem> batesModColorTemplateList = new List<BatesHeaderFooterItem>();
- for (int temp = 0; temp < Settings.Default.BatesTemplateList.Count; temp++)
- {
- Settings.Default.BatesTemplateList[temp].ItemName = (temp + 1).ToString();
- batesModColorTemplateList.Add(Settings.Default.BatesTemplateList[temp]);
- }
- BatesModCollection = new ObservableCollection<BatesHeaderFooterItem>(batesModColorTemplateList);
- CheckTemplateListIsEmpty(batesModColorTemplateList);
- }
- public void ConvertItemToInfo(BatesHeaderFooterItem batesItem, ref BatesInfo batesInfo)
- {
- batesInfo.TextData = batesItem.TextData;
- batesInfo.ItemName = batesItem.ItemName;
- batesInfo.DigitNumber = batesItem.DigitNumber;
- batesInfo.Prefix=batesItem.Prefix;
- batesInfo.Suffix=batesItem.Suffix;
- batesInfo.StarPagetNumber = batesItem.StarPagetNumber;
- batesInfo.margin = batesItem.margin;
- batesInfo.PageRangeIndex = batesItem.PageRangeIndex;
- EditToolsHelper.GetPageRange(batesInfo.PageRangeIndex, PDFViewer.Document, ref batesInfo.PageRange, batesItem.PageRange);
- }
- private void CheckTemplateListIsEmpty(List<BatesHeaderFooterItem> batesTemplateList)
- {
- if (batesTemplateList.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();
- }
- }
- }
|