using ComPDFKit.PDFDocument; using ComPDFKit_Conversion.Converter; using ComPDFKit_Conversion.Options; 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.Linq; using System.Net.Mime; using System.Windows.Media; using static Dropbox.Api.Sharing.ListFileMembersIndividualResult; namespace PDF_Office.ViewModels.Dialog.ConverterDialogs { public class ConverterProgressBarDialogViewModel : BindableBase,IDialogAware { public string Title => ""; public event Action RequestClose; #region 参数和属性 private string _pageIndex = "0"; /// /// 当前页 /// public string PageIndex { get { return _pageIndex; } set { SetProperty(ref _pageIndex, value); } } private string _pageNumber = ""; /// /// 总页数 /// public string PageNumber { get { return _pageNumber; } set { SetProperty(ref _pageNumber, value); } } #endregion public ConverterProgressBarDialogViewModel() { } #region 逻辑函数 private void SetProgress(int pageIndex) { PageIndex=pageIndex.ToString(); } #endregion #region 构架行为 public bool CanCloseDialog() { return true; } public void OnDialogClosed() { ConverterHelper.Clear(); } public async void OnDialogOpened(IDialogParameters parameters) { bool result=false; string convertType=""; OnProgress GetProgress = null; GetProgress += SetProgress; parameters.TryGetValue(ParameterNames.ConverterType, out convertType); switch (convertType) { case "CSV": ConverterCSVDialogModel ConverterCSVModel; parameters.TryGetValue(ParameterNames.ConverterTypeModel, out ConverterCSVModel); if (ConverterCSVModel != null) { PageNumber = ConverterCSVModel.PageIndexLists.Count().ToString(); for (int i = 0; ConverterCSVModel.PageIndexLists.Count > i; i++) { ConverterCSVModel.PageIndexLists[i] = ConverterCSVModel.PageIndexLists[i] + 1; } result = await ConverterHelper.CSVConvert(ConverterCSVModel.InputPath, ConverterCSVModel.OutputPath, GetProgress, ConverterCSVModel.PageIndexLists, ConverterCSVModel.Pawssword); } break; case "Excel": ConverterExcelDialogModel ConverterExcelModel; parameters.TryGetValue(ParameterNames.ConverterTypeModel, out ConverterExcelModel); if (ConverterExcelModel != null) { PageNumber = ConverterExcelModel.PageIndexLists.Count().ToString(); for (int i = 0; ConverterExcelModel.PageIndexLists.Count > i; i++) { ConverterExcelModel.PageIndexLists[i] = ConverterExcelModel.PageIndexLists[i] + 1; } result = await ConverterHelper.ExcelConvert(ConverterExcelModel.InputPath, ConverterExcelModel.OutputPath, GetProgress, ConverterExcelModel.PageIndexLists, ConverterExcelModel.Pawssword, ConverterExcelModel.excelOption); } break; case "HTML": ConverterHTMLDialogModel ConverterHTMLModel; parameters.TryGetValue(ParameterNames.ConverterTypeModel, out ConverterHTMLModel); if (ConverterHTMLModel != null) { PageNumber = ConverterHTMLModel.PageIndexLists.Count().ToString(); for (int i = 0; ConverterHTMLModel.PageIndexLists.Count > i; i++) { ConverterHTMLModel.PageIndexLists[i] = ConverterHTMLModel.PageIndexLists[i] + 1; } result = await ConverterHelper.HTMLConvert(ConverterHTMLModel.InputPath, ConverterHTMLModel.OutputPath, GetProgress, ConverterHTMLModel.PageIndexLists, ConverterHTMLModel.Pawssword, ConverterHTMLModel.htmlOption); } break; case "Img": ConverterImgDialogModel ConverterImgModel; parameters.TryGetValue(ParameterNames.ConverterTypeModel, out ConverterImgModel); if (ConverterImgModel != null) { PageNumber = ConverterImgModel.PageIndexLists.Count().ToString(); for (int i=0; ConverterImgModel.PageIndexLists.Count>i;i++) { ConverterImgModel.PageIndexLists[i] = ConverterImgModel.PageIndexLists[i] + 1; } result = await ConverterHelper.ImgConvert(ConverterImgModel.InputPath, ConverterImgModel.OutputPath, GetProgress, ConverterImgModel.PageIndexLists, ConverterImgModel.Pawssword, ConverterImgModel.Type,ConverterImgModel.imageType); } break; case "PPT": ConverterPPTDialogModel ConverterPPTModel; parameters.TryGetValue(ParameterNames.ConverterTypeModel, out ConverterPPTModel); if (ConverterPPTModel != null) { PageNumber = ConverterPPTModel.PageIndexLists.Count().ToString(); for (int i = 0; ConverterPPTModel.PageIndexLists.Count > i; i++) { ConverterPPTModel.PageIndexLists[i] = ConverterPPTModel.PageIndexLists[i] + 1; } result = await ConverterHelper.PPTConvert(ConverterPPTModel.InputPath, ConverterPPTModel.OutputPath, GetProgress, ConverterPPTModel.PageIndexLists, ConverterPPTModel.Pawssword); } break; case "RTF": ConverterRTFDialogModel ConverterRTFModel; parameters.TryGetValue(ParameterNames.ConverterTypeModel, out ConverterRTFModel); if (ConverterRTFModel != null) { PageNumber = ConverterRTFModel.PageIndexLists.Count().ToString(); for (int i = 0; ConverterRTFModel.PageIndexLists.Count > i; i++) { ConverterRTFModel.PageIndexLists[i] = ConverterRTFModel.PageIndexLists[i] + 1; } result = await ConverterHelper.RTFConvert(ConverterRTFModel.InputPath, ConverterRTFModel.OutputPath, GetProgress, ConverterRTFModel.PageIndexLists, ConverterRTFModel.Pawssword); } break; case "Text": ConverterTextDialogModel ConverterTextModel; parameters.TryGetValue(ParameterNames.ConverterTypeModel, out ConverterTextModel); if (ConverterTextModel != null) { PageNumber = ConverterTextModel.PageIndexLists.Count().ToString(); for (int i = 0; ConverterTextModel.PageIndexLists.Count > i; i++) { ConverterTextModel.PageIndexLists[i] = ConverterTextModel.PageIndexLists[i] + 1; } result = await ConverterHelper.TxtConvert(ConverterTextModel.InputPath, ConverterTextModel.OutputPath, GetProgress, ConverterTextModel.PageIndexLists, ConverterTextModel.Pawssword); } break; case "Word": ConverterWordDialogModel ConverterWordModel; parameters.TryGetValue(ParameterNames.ConverterTypeModel, out ConverterWordModel); if (ConverterWordModel != null) { PageNumber = ConverterWordModel.PageIndexLists.Count().ToString(); for (int i = 0; ConverterWordModel.PageIndexLists.Count > i; i++) { ConverterWordModel.PageIndexLists[i] = ConverterWordModel.PageIndexLists[i] + 1; } result = await ConverterHelper.WordConvert(ConverterWordModel.InputPath, ConverterWordModel.OutputPath, GetProgress, ConverterWordModel.PageIndexLists, ConverterWordModel.Pawssword); } break; default: break; } RequestClose?.Invoke(new DialogResult(ButtonResult.OK)); } #endregion } }