123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285 |
- 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";
- ///// <value>
- ///// 当前页
- ///// </value>
- //public string PageIndex
- //{
- // get { return _pageIndex; }
- // set
- // {
- // SetProperty(ref _pageIndex, value);
- // App.mainWindowViewModel.Value = int.Parse(PageIndex);
- // }
- //}
- //private string _pageNumber = "0";
- ///// <value>
- ///// 总页数
- ///// </value>
- //public string PageNumber
- //{
- // get { return _pageNumber; }
- // set
- // {
- // SetProperty(ref _pageNumber, value);
- // App.mainWindowViewModel.MaxValue = int.Parse(PageNumber);
- // }
- //}
- public DelegateCommand<object> ToConverterCommand { get; set; }
- public ConverterBarContentViewModel(IDialogService dialogService)
- {
- dialogs = dialogService;
- ToConverterCommand = new DelegateCommand<object>(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<string>(ParameterNames.ConverterType).ToString();
- // switch (convertType)
- // {
- // case "CSV":
- // ConverterCSVDialogModel ConverterCSVModel=e.Parameters.GetValue<ConverterCSVDialogModel>(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<ConverterExcelDialogModel>(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<ConverterHTMLDialogModel>(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<ConverterImgDialogModel>(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<ConverterPPTDialogModel>(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<ConverterRTFDialogModel>(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<ConverterTextDialogModel>(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<ConverterWordDialogModel>(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<ViewContentViewModel>(ParameterNames.ViewContentViewModel, out viewContentViewModel);
- navigationContext.Parameters.TryGetValue<CPDFViewer>(ParameterNames.PDFViewer, out PDFViewer);
- if (PDFViewer != null)
- {
- isFirstLoad = false;
- viewContentViewModel.IsPropertyOpen = false;
- PDFViewer.SetMouseMode(MouseModes.PanTool);
- }
- }
- }
- }
|