123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241 |
- using ComPDFKitViewer.PdfViewer;
- using Microsoft.Office.Interop.Word;
- 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.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.Control;
- 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()
- {
- List<BatesHeaderFooterItem> removebatesItems = new List<BatesHeaderFooterItem>();
- for (int i = 0; i < Settings.Default.BatesTemplateList.Count;i++)
- {
-
- var template = Settings.Default.BatesTemplateList[i];
- removebatesItems.Add(template);
-
- }
- foreach (var removetemplate in removebatesItems)
- {
- Settings.Default.BatesTemplateList.Remove(removetemplate);
- Settings.Default.Save();
- BatesModCollection.Remove(removetemplate);
- }
- 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;
- 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();
- }
- }
- }
|