123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182 |
- using Microsoft.Win32;
- using PDF_Master.Model;
- using PDF_Master.Model.Dialog.HomePageToolsDialogs;
- using Prism.Commands;
- using Prism.Mvvm;
- using Prism.Services.Dialogs;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace PDF_Master.ViewModels.Dialog.HomePageToolsDialogs
- {
- public class CreateFromHtmlDialogViewModel : BindableBase, IDialogAware
- {
- public string Title => "";
- public event Action<IDialogResult> RequestClose;
- private string filepath = "";
- public string FilePath
- {
- get { return filepath; }
- set
- {
- SetProperty(ref filepath, value);
- if(!string.IsNullOrEmpty(value))
- {
- Model.FilePath = value;
- }
- }
- }
- private double margin = 0;
- public double Margin
- {
- get { return margin; }
- set
- {
- SetProperty(ref margin, value);
- Model.Margin = value;
- }
- }
- private int selectedIndex = 0;
- public int SelectedIndex
- {
- get { return selectedIndex; }
- set
- {
- SetProperty(ref selectedIndex, value);
- if (value>0)
- {
- Model.PageSize = (Microsoft.Office.Interop.Word.WdPaperSize)value;
- }
- }
- }
- public List<string> PageSizes { get; set; } = new List<string>();
- /// <summary>
- /// 数据模型
- /// </summary>
- public HtmlModel Model { get; set; } = new HtmlModel();
- public DelegateCommand OpenFileCommnad { get; set; }
- public DelegateCommand CreateCommand { get; set; }
- public DelegateCommand CancelCommand { get; set; }
- public CreateFromHtmlDialogViewModel()
- {
- OpenFileCommnad = new DelegateCommand(openFile);
- CreateCommand = new DelegateCommand(createFile,CanExcuteCreateFile).ObservesProperty(()=> FilePath);
- CancelCommand = new DelegateCommand(cancel);
- InitPageSize();
- }
- private void InitPageSize()
- {
- PageSizes.Add("10x14");
- PageSizes.Add("11x17");
- PageSizes.Add("Letter");
- PageSizes.Add("LetterSmall");
- PageSizes.Add("Legal");
- PageSizes.Add("Executive");
- PageSizes.Add("A3");
- PageSizes.Add("A4");
- PageSizes.Add("A4Small");
- PageSizes.Add("A5");
- PageSizes.Add("B4");
- PageSizes.Add("B5");
- PageSizes.Add("CSheet");
- PageSizes.Add("DSheet");
- PageSizes.Add("ESheet");
- PageSizes.Add("FanfoldLegalGerman");
- PageSizes.Add("FanfoldStdGerman");
- PageSizes.Add("FanfoldUS");
- PageSizes.Add("Folio");
- PageSizes.Add("Ledger");
- PageSizes.Add("Note");
- PageSizes.Add("Quarto");
- PageSizes.Add("Statement");
- PageSizes.Add("Tabloid");
- PageSizes.Add("Envelope9");
- PageSizes.Add("Envelope10");
- PageSizes.Add("Envelope11");
- PageSizes.Add("Envelope12");
- PageSizes.Add("EnvelopeB4");
- PageSizes.Add("EnvelopeB5");
- PageSizes.Add("EnvelopeB6");
- PageSizes.Add("EnvelopeC3");
- PageSizes.Add("EnvelopeC4");
- PageSizes.Add("EnvelopeC6");
- PageSizes.Add("EnvelopeC65");
- PageSizes.Add("EnvelopeDL");
- PageSizes.Add("EnvelopeItaly");
- PageSizes.Add("EnvelopeMonarch");
- PageSizes.Add("EnvelopePersonal");
- }
- private void createFile()
- {
- DialogParameters valuePairs = new DialogParameters();
- valuePairs.Add(ParameterNames.DataModel, Model);
- RequestClose.Invoke(new DialogResult(ButtonResult.OK,valuePairs));
- }
- /// <summary>
- /// 是否可以创建
- /// </summary>
- /// <returns></returns>
- private bool CanExcuteCreateFile()
- {
- return !string.IsNullOrEmpty(FilePath);
- }
- private void cancel()
- {
- RequestClose.Invoke(new DialogResult(ButtonResult.Cancel));
- }
- private void openFile()
- {
- OpenFileDialog dialog = new OpenFileDialog();
- dialog.Multiselect = false;
- dialog.Filter = "HTML(*.html)|*.html";
- if((bool)dialog.ShowDialog())
- {
- if(!string.IsNullOrEmpty(dialog.FileName))
- {
- FilePath = dialog.FileName;
- }
- }
- }
- #region 框架
- public bool CanCloseDialog()
- {
- return true;
- }
- public void OnDialogClosed()
- {
- }
- public void OnDialogOpened(IDialogParameters parameters)
- {
-
- }
- #endregion
- }
- }
|