using ComPDFKit_Conversion.Converter; using ComPDFKitViewer.PdfViewer; using Microsoft.Office.Interop.Word; using PDF_Office.Helper; using PDF_Office.Model; using PDF_Office.Model.Dialog.ConverterDialogs; using Prism.Commands; using Prism.Mvvm; using Prism.Regions; using Prism.Services.Dialogs; using System; using System.Collections.Generic; using System.Linq; using System.Windows.Controls; namespace PDF_Office.ViewModels.Tools { public class ConverterBarContentViewModel : BindableBase, INavigationAware { private bool isFirstLoad = true; private CPDFViewer PDFViewer; public IDialogService dialogs; private ViewContentViewModel viewContentViewModel; private string _pageIndex = "0"; ///// ///// 当前页 ///// //public string PageIndex //{ // get { return _pageIndex; } // set // { // SetProperty(ref _pageIndex, value); // App.mainWindowViewModel.Value = int.Parse(PageIndex); // } //} //private string _pageNumber = "0"; ///// ///// 总页数 ///// //public string PageNumber //{ // get { return _pageNumber; } // set // { // SetProperty(ref _pageNumber, value); // App.mainWindowViewModel.MaxValue = int.Parse(PageNumber); // } //} public DelegateCommand ToConverterCommand { get; set; } public ConverterBarContentViewModel(IDialogService dialogService) { dialogs = dialogService; ToConverterCommand = new DelegateCommand(toconverter); } private void toconverter(object sender) { //付费锁 if(!App.IsLogin) { dialogs.ShowDialog(DialogNames.IAPCompareDialog); return; } var args = sender as Button; if (args != null) { DialogParameters value = new DialogParameters(); value.Add(ParameterNames.PDFViewer, PDFViewer); switch (args.Name) { case "ConverterWordBtn": dialogs.ShowDialog(DialogNames.ConverterWordDialog, value, e => { ConverterDialogsModel converterDialogsModel = new ConverterDialogsModel(); converterDialogsModel. OnOpened((DialogResult)e); }); break; case "ConverterExcelBtn": dialogs.ShowDialog(DialogNames.ConverterExcelDialog, value, e => { ConverterDialogsModel converterDialogsModel = new ConverterDialogsModel(); converterDialogsModel.OnOpened((DialogResult)e); }); break; case "ConverterPPTBtn": dialogs.ShowDialog(DialogNames.ConverterPPTDialog, value, e => { ConverterDialogsModel converterDialogsModel = new ConverterDialogsModel(); converterDialogsModel.OnOpened((DialogResult)e); }); break; case "ConverterRTFBtn": dialogs.ShowDialog(DialogNames.ConverterRTFDialog, value, e => { ConverterDialogsModel converterDialogsModel = new ConverterDialogsModel(); converterDialogsModel.OnOpened((DialogResult)e); }); break; case "ConverterCSVBtn": dialogs.ShowDialog(DialogNames.ConverterCSVDialog, value, e => { ConverterDialogsModel converterDialogsModel = new ConverterDialogsModel(); converterDialogsModel.OnOpened((DialogResult)e); }); break; case "ConverterHTMLBtn": dialogs.ShowDialog(DialogNames.ConverterHTMLDialog, value, e => { ConverterDialogsModel converterDialogsModel = new ConverterDialogsModel(); converterDialogsModel.OnOpened((DialogResult)e); }); break; case "ConverterTextBtn": dialogs.ShowDialog(DialogNames.ConverterTextDialog, value, e => { ConverterDialogsModel converterDialogsModel = new ConverterDialogsModel(); converterDialogsModel.OnOpened((DialogResult)e); }); break; case "ConverterImgBtn": dialogs.ShowDialog(DialogNames.ConverterImgDialog, value, e => { ConverterDialogsModel converterDialogsModel = new ConverterDialogsModel(); converterDialogsModel.OnOpened((DialogResult)e); }); break; default: break; } } } //private void ConverterClear() { // ConverterHelper.Clear(); // App.mainWindowViewModel.IsProcessVisible = System.Windows.Visibility.Collapsed; //} //private void SetProgress(int pageIndex) //{ // PageIndex = pageIndex.ToString(); // App.mainWindowViewModel.IsProcessVisible=System.Windows.Visibility.Visible; // if (PageIndex == PageNumber) { App.mainWindowViewModel.IsProcessVisible = System.Windows.Visibility.Collapsed; } //} //public async void OnOpened(Prism.Services.Dialogs.DialogResult e) //{ // if (e.Result == Prism.Services.Dialogs.ButtonResult.Cancel) { return; } // bool result = false; // string convertType = ""; // OnProgress GetProgress = null; // GetProgress += SetProgress; // App.mainWindowViewModel.ProcessCloseAction= ConverterClear; // convertType = e.Parameters.GetValue(ParameterNames.ConverterType).ToString(); // switch (convertType) // { // case "CSV": // ConverterCSVDialogModel ConverterCSVModel=e.Parameters.GetValue(ParameterNames.ConverterTypeModel); // 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, ConverterCSVModel.csvOptions); // } // break; // case "Excel": // ConverterExcelDialogModel ConverterExcelModel = e.Parameters.GetValue(ParameterNames.ConverterTypeModel); // 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.excelOptions); // } // break; // case "HTML": // ConverterHTMLDialogModel ConverterHTMLModel = e.Parameters.GetValue(ParameterNames.ConverterTypeModel); // 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.htmlOptions); // } // break; // case "Img": // ConverterImgDialogModel ConverterImgModel = e.Parameters.GetValue(ParameterNames.ConverterTypeModel); // 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.imageType, ConverterImgModel.imgOptions); // } // break; // case "PPT": // ConverterPPTDialogModel ConverterPPTModel = e.Parameters.GetValue(ParameterNames.ConverterTypeModel); // 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, ConverterPPTModel.pPTOptions); // } // break; // case "RTF": // ConverterRTFDialogModel ConverterRTFModel = e.Parameters.GetValue(ParameterNames.ConverterTypeModel); // 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, ConverterRTFModel.rTFOptions); // } // break; // case "Text": // ConverterTextDialogModel ConverterTextModel = e.Parameters.GetValue(ParameterNames.ConverterTypeModel); // 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, ConverterTextModel.txtOptions); // } // break; // case "Word": // ConverterWordDialogModel ConverterWordModel = e.Parameters.GetValue(ParameterNames.ConverterTypeModel); // 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, ConverterWordModel.wordOptions); // } // break; // default: // break; // } //} public bool IsNavigationTarget(NavigationContext navigationContext) { return true; } public void OnNavigatedFrom(NavigationContext navigationContext) { } public void OnNavigatedTo(NavigationContext navigationContext) { navigationContext.Parameters.TryGetValue(ParameterNames.ViewContentViewModel, out viewContentViewModel); navigationContext.Parameters.TryGetValue(ParameterNames.PDFViewer, out PDFViewer); if (PDFViewer != null) { isFirstLoad = false; viewContentViewModel.IsPropertyOpen = false; PDFViewer.SetMouseMode(MouseModes.PanTool); } } } }