using ComPDFKitViewer.PdfViewer; using PDF_Office.CustomControl; using PDF_Office.Helper; using PDF_Office.Model; using PDF_Office.Model.Dialog.ConverterDialogs; using Prism.Commands; using Prism.Mvvm; using Prism.Services.Dialogs; using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Windows.Forms; using DialogResult = Prism.Services.Dialogs.DialogResult; namespace PDF_Office.ViewModels.Dialog.ConverterDialogs { public class ConverterHTMLDialogViewModel : BindableBase, IDialogAware { public ConverterHTMLDialogModel ConverterHTMLModel = new ConverterHTMLDialogModel(); public CPDFViewer currentViewer; public IDialogService dialogs; public string PageRangeText { set; get; } = "0"; public string PageRangeSelectIndex { set; get; } = "0"; public DelegateCommand CancelCommand { get; set; } public DelegateCommand ConverterCommnad { get; set; } public ConverterHTMLDialogViewModel(IDialogService dialogService) { CancelCommand = new DelegateCommand(cancel); ConverterCommnad = new DelegateCommand(converter); dialogs = dialogService; } private void cancel() { RequestClose.Invoke(new DialogResult(ButtonResult.Cancel)); } private void converter() { FolderBrowserDialog dlg = new FolderBrowserDialog(); if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK) { ConverterHTMLModel.OutputPath = dlg.SelectedPath.Trim(); } HomePageEditHelper.GetPagerange(PageRangeSelectIndex, currentViewer, ref ConverterHTMLModel.PageRange, PageRangeText, true); char[] enumerationSeparator = new char[] { ',' }; char[] rangeSeparator = new char[] { '-' }; if (!CommonHelper.GetPagesInRange(ref ConverterHTMLModel.PageIndexLists, ConverterHTMLModel.PageRange, currentViewer.Document.PageCount, enumerationSeparator, rangeSeparator)) { //TODO Trace.WriteLine("输入不对"); MessageBoxEx.Show("输入不对"); return; } //result = await ConverterHelper.TxtConvert(ConverterTextModel.InputPath, ConverterTextModel.OutputPath, ConverterTextModel.GetProgress, ConverterTextModel.PageIndexLists, ConverterTextModel.Pawssword); DialogParameters value = new DialogParameters(); value.Add(ParameterNames.ConverterType, "HTML"); value.Add(ParameterNames.ConverterTypeModel, ConverterHTMLModel); RequestClose?.Invoke(new DialogResult(ButtonResult.OK)); dialogs.ShowDialog(DialogNames.ConverterProgressBarDialog, value, e => { }); } private void SetProgress(int pageIndex) { } public string Title => ""; public event Action RequestClose; public bool CanCloseDialog() { return true; } public void OnDialogClosed() { } public void OnDialogOpened(IDialogParameters parameters) { CPDFViewer pdfViewer = null; parameters.TryGetValue(ParameterNames.PDFViewer, out pdfViewer); if (pdfViewer != null) { currentViewer = pdfViewer; ConverterHTMLModel.InputPath = pdfViewer.Document.FilePath; FileInfo fileinfo = new FileInfo(ConverterHTMLModel.InputPath); ConverterHTMLModel.OutputPath = fileinfo.DirectoryName; } } } }