123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348 |
- using Microsoft.Office.Interop.Word;
- using PDF_Office.EventAggregators;
- using PDF_Office.Model.Dialog.HomePageToolsDialogs.HomePagePrinter;
- using Prism.Commands;
- using Prism.Events;
- using Prism.Mvvm;
- using Prism.Regions;
- using System;
- using System.Collections.Generic;
- using System.Diagnostics;
- using System.Linq;
- using System.Printing;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Media;
- namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs.HomePagePrinter
- {
- public class HomePagePrinterModPosterContentViewModel : BindableBase, INavigationAware
- {
- private IEventAggregator eventAggregator;
- private string Unicode = null;
- private Visibility _pageRangeSettingVisibility = Visibility.Visible;
- public bool HasCutMarks = false;
- public bool HasLabel = false;
- private string _defaultLabel;
- public string DefaultLabel
- {
- get { return _defaultLabel; }
- set { _defaultLabel = value; }
- }
- private string _labelString;
- public string LabelString
- {
- get { return _labelString; }
- set {
- _labelString = value;
- eventAggregator.GetEvent<SendLabelEvent>().Publish(new LabelWithUnicode { Label = this.LabelString, Unicode = this.Unicode});
- }
- }
- public Visibility PageRangeSettingVisibility
- {
- get => _pageRangeSettingVisibility;
- set => SetProperty(ref _pageRangeSettingVisibility, value);
- }
- private Visibility _pagesPerSheetVisibility = Visibility.Hidden;
- public Visibility PagesPerSheetVisibility
- {
- get => _pagesPerSheetVisibility;
- set => SetProperty(ref _pagesPerSheetVisibility, value);
- }
- private string _tileRatio = "100";
- public string TileRatio
- {
- get => _tileRatio;
- set => SetProperty(ref _tileRatio, value);
- }
- private PosterInfo _posterInfo = new PosterInfo();
- public PosterInfo PosterInfo
- {
- get => _posterInfo;
- set => _posterInfo = value;
- }
- private List<string> _pageSheetList = new List<string>();
- /// <summary>
- /// <para>0: 1x2</para>
- /// <para>1: 2x2</para>
- /// <para>2: 3x2</para>
- /// <para>3: 3x3</para>
- /// <para>4: 4x4</para>
- /// <para>5: 自定义</para>
- /// </summary>
- public List<string> PageSheetList
- {
- get => _pageSheetList;
- set => _pageSheetList = value;
- }
- private bool _enableCustomSheet;
- public bool EnableCustomSheet
- {
- get { return _enableCustomSheet; }
- set
- {
- SetProperty(ref _enableCustomSheet, value);
- }
- }
- private int _pageSheetIndex = 0;
- public int PageSheetIndex
- {
- get { return _pageSheetIndex; }
- set
- {
- _pageSheetIndex = value;
- if (_pageSheetIndex < 5)
- {
- EnableCustomSheet = false;
- }
- else
- {
- EnableCustomSheet = true;
- }
- SetPageSheetValue(value);
- }
- }
- private int? _horizontalSheetNumber = 1;
- public int? HorizontalSheetNumber
- {
- get => _horizontalSheetNumber;
- set => SetProperty(ref _horizontalSheetNumber, value);
- }
- private int? _verticalSheetNumber = 2;
- public int? VerticalSheetNumber
- {
- get => _verticalSheetNumber;
- set => SetProperty(ref _verticalSheetNumber, value);
- }
- private double? _overlapNumber = 0;
- public double? OverlapNumber
- {
- get => _overlapNumber;
- set
- {
- if (value > 5.08)
- {
- SetProperty(ref _overlapNumber, 5.08);
- }
- else if (value < 0)
- {
- SetProperty(ref _overlapNumber, 0);
- }
- SetProperty(ref _overlapNumber, value);
- }
- }
- public DelegateCommand<object> SetModPosterStatusCommand { get; set; }
- public DelegateCommand<object> SetSheetCommand { get; set; }
- public DelegateCommand SetCustomSheetCommand { get; set; }
- public DelegateCommand SetOverlapCommand { get; set; }
- public DelegateCommand<object> SetCutMarksCommand { get; set; }
- public DelegateCommand<object> SetLabelCommand { get; set; }
- public DelegateCommand SetTileRatioCommand { get; set; }
- HomePagePrinterModPosterContentViewModel(IEventAggregator eventAggregator)
- {
- this.eventAggregator = eventAggregator;
- SetModPosterStatusCommand = new DelegateCommand<object>(SetModPosterStatus);
- SetSheetCommand = new DelegateCommand<object>(SetSheet);
- SetCustomSheetCommand = new DelegateCommand(SetCustomSheet);
- SetOverlapCommand = new DelegateCommand(SetOverlap);
- SetCutMarksCommand = new DelegateCommand<object>(SetCutMarks);
- SetLabelCommand = new DelegateCommand<object>(SetLabel);
- SetTileRatioCommand = new DelegateCommand(SetTileRatio);
- InitComponent();
- PosterInfo.EnumPrintMod = EnumPrintMod.StatusPoster;
- }
- public void InitPageSheetList()
- {
- PageSheetList.Clear();
- PageSheetList.Add("2");
- PageSheetList.Add("4");
- PageSheetList.Add("6");
- PageSheetList.Add("9");
- PageSheetList.Add("16");
- PageSheetList.Add("Custom");
- }
- public void InitComponent()
- {
- InitPageSheetList();
- }
- public void SetModPosterStatus(object e)
- {
- var rdo = e as RadioButton;
- if (rdo.Name == "StatusTileRdo")
- {
- PosterInfo.EnumPosterMod = EnumPosterMod.StatusTile;
- PageRangeSettingVisibility = Visibility.Visible;
- PagesPerSheetVisibility = Visibility.Hidden;
- }
- else
- {
- PosterInfo.EnumPosterMod = EnumPosterMod.StatusSplit;
- PageRangeSettingVisibility = Visibility.Hidden;
- PagesPerSheetVisibility = Visibility.Visible;
- }
- SendPosterInfo();
- }
- public void SetSheet(object e)
- {
- SendPosterInfo();
- }
- public void SetCustomSheet()
- {
- SendPosterInfo();
- }
- public void SetOverlap()
- {
- SendPosterInfo();
- }
- public void SetTileRatio()
- {
- int previousDisplayRatio = PosterInfo.TileRatio;
- PosterInfo.TileRatio = int.Parse(TileRatio);
- if (previousDisplayRatio != PosterInfo.TileRatio)
- {
- SendPosterInfo();
- }
- }
- public void SetPageSheetValue(int sheetIndex)
- {
- switch (sheetIndex)
- {
- case 0:
- HorizontalSheetNumber = 1;
- VerticalSheetNumber = 2;
- break;
- case 1:
- HorizontalSheetNumber = 2;
- VerticalSheetNumber = 2;
- break;
- case 2:
- HorizontalSheetNumber = 3;
- VerticalSheetNumber = 2;
- break;
- case 3:
- HorizontalSheetNumber = 3;
- VerticalSheetNumber = 3;
- break;
- case 4:
- HorizontalSheetNumber = 4;
- VerticalSheetNumber = 4;
- break;
- case 5:
- HorizontalSheetNumber = null;
- VerticalSheetNumber = null;
- break;
- }
- SendPosterInfo();
- }
- public void SendPosterInfo()
- {
- if (HorizontalSheetNumber == null)
- {
- HorizontalSheetNumber = 1;
- }
- if (VerticalSheetNumber == null)
- {
- VerticalSheetNumber = 1;
- }
- if (OverlapNumber == null)
- {
- OverlapNumber = 0;
- }
- else if (OverlapNumber < 0)
- {
- OverlapNumber = 0;
- }
- else if (OverlapNumber > 5.08)
- {
- OverlapNumber = 5.08;
- }
- if (PosterInfo != null)
- {
- if (PosterInfo.EnumPosterMod == EnumPosterMod.StatusTile)
- {
- PosterInfo.TileRatio = int.Parse(TileRatio);
- }
- else
- {
- PosterInfo.HorizontalSheetNumber = (int)HorizontalSheetNumber;
- PosterInfo.VerticalSheetNumber = (int)VerticalSheetNumber;
- }
- PosterInfo.OverLap = (double)OverlapNumber;
- PosterInfo.HasCutMarks = HasCutMarks;
- PosterInfo.HasLabel = HasLabel;
- }
- this.eventAggregator.GetEvent<SendPrintSettingsModInfoEvent>().Publish(new PrintModInfoWithUnicode { printModInfo = PosterInfo, Unicode = this.Unicode });
- }
- public void SetCutMarks(object e)
- {
- var chk = e as System.Windows.Controls.CheckBox;
- if(chk.IsChecked == true)
- {
- HasCutMarks = true;
- }
- else
- {
- HasCutMarks = false;
- }
- SendPosterInfo();
- }
- public void SetLabel(object e)
- {
- var chk = e as System.Windows.Controls.CheckBox;
- if (chk.IsChecked == true)
- {
- HasLabel = true;
- }
- else
- {
- HasLabel = false;
- }
- SendPosterInfo();
- }
- public bool IsNavigationTarget(NavigationContext navigationContext)
- {
- return true;
- }
- public void OnNavigatedFrom(NavigationContext navigationContext)
- {
- }
- public void OnNavigatedTo(NavigationContext navigationContext)
- {
- DefaultLabel = "(column, row) 1.pdf "+ DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
- navigationContext.Parameters.TryGetValue<string>("Unicode", out Unicode);
- SendPosterInfo();
- }
- }
- }
|