using ComPDFKit_Conversion.Converter;
using ComPDFKitViewer.PdfViewer;
using DryIoc;
using Microsoft.Office.Interop.Word;
using PDF_Master.Helper;
using PDF_Master.Model;
using PDF_Master.Model.Dialog.ConverterDialogs;
using PDF_Master.Properties;
using PDFReader_WPF.Helper;
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;
using System.Windows.Controls;
namespace PDF_Master.ViewModels.Tools
{
public class ConverterBarContentViewModel : BindableBase, INavigationAware
{
private CPDFViewer PDFViewer;
public IDialogService dialogs;
private ViewContentViewModel viewContentViewModel;
/////
///// 当前页
/////
//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);
// }
//}
///
/// 防止自动保存异步导致弹窗出现两次
///
private bool _isPopupInProgress;
public bool IsPopupInProgress
{
get { return _isPopupInProgress; }
set { SetProperty(ref _isPopupInProgress, value); }
}
public DelegateCommand ToConverterCommand { get; set; }
public ConverterBarContentViewModel(IDialogService dialogService)
{
dialogs = dialogService;
ToConverterCommand = new DelegateCommand(toconverter);
}
private async void toconverter(object sender)
{
if (IsPopupInProgress)
{
return;
}
IsPopupInProgress = true;
DataTrackingHelper.SetSendInformation(DataTrackingHelper.EventType.Purchase_Converter, DataTrackingHelper.EntryPathKeyType.SubTbr_Converter);
var args = sender as Button;
if (args != null)
{
toConverterDataTracking(args.Name);
//转档前 如果需要 自动保存
if (!await viewContentViewModel.SaveBeforeOption())
{
IsPopupInProgress = false;
return;
}
IsPopupInProgress = false;
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;
}
}
IsPopupInProgress = false;
}
///
/// 埋点
///
///
private async void toConverterDataTracking(string sender)
{
switch (sender)
{
case "ConverterWordBtn":
DataTrackingHelper.AddFirstAndSecondaryPath(DataTrackingHelper.FirstPath.Reading, DataTrackingHelper.SecondaryPath.toWord);
DataTrackingHelper.SendEvent(DataTrackingHelper.EventType.SubTbr_Converter, "SubTbr_Btn", "Btn_SubTbr_toWord");
break;
case "ConverterExcelBtn":
DataTrackingHelper.AddFirstAndSecondaryPath(DataTrackingHelper.FirstPath.Reading, DataTrackingHelper.SecondaryPath.toExcel);
DataTrackingHelper.SendEvent(DataTrackingHelper.EventType.SubTbr_Converter, "SubTbr_Btn", "Btn_SubTbr_toExcel");
break;
case "ConverterPPTBtn":
DataTrackingHelper.AddFirstAndSecondaryPath(DataTrackingHelper.FirstPath.Reading, DataTrackingHelper.SecondaryPath.toPPT);
DataTrackingHelper.SendEvent(DataTrackingHelper.EventType.SubTbr_Converter, "SubTbr_Btn", "Btn_SubTbr_toPPT");
break;
case "ConverterRTFBtn":
DataTrackingHelper.AddFirstAndSecondaryPath(DataTrackingHelper.FirstPath.Reading, DataTrackingHelper.SecondaryPath.toRTF);
DataTrackingHelper.SendEvent(DataTrackingHelper.EventType.SubTbr_Converter, "SubTbr_Btn", "Btn_SubTbr_toRTF");
break;
case "ConverterCSVBtn":
DataTrackingHelper.AddFirstAndSecondaryPath(DataTrackingHelper.FirstPath.Reading, DataTrackingHelper.SecondaryPath.toCSV);
DataTrackingHelper.SendEvent(DataTrackingHelper.EventType.SubTbr_Converter, "SubTbr_Btn", "Btn_SubTbr_toCSV");
break;
case "ConverterHTMLBtn":
DataTrackingHelper.AddFirstAndSecondaryPath(DataTrackingHelper.FirstPath.Reading, DataTrackingHelper.SecondaryPath.toHTML);
DataTrackingHelper.SendEvent(DataTrackingHelper.EventType.SubTbr_Converter, "SubTbr_Btn", "Btn_SubTbr_toHTML");
break;
case "ConverterTextBtn":
DataTrackingHelper.AddFirstAndSecondaryPath(DataTrackingHelper.FirstPath.Reading, DataTrackingHelper.SecondaryPath.toText);
DataTrackingHelper.SendEvent(DataTrackingHelper.EventType.SubTbr_Converter, "SubTbr_Btn", "Btn_SubTbr_toText");
break;
case "ConverterImgBtn":
DataTrackingHelper.AddFirstAndSecondaryPath(DataTrackingHelper.FirstPath.Reading, DataTrackingHelper.SecondaryPath.toImage);
DataTrackingHelper.SendEvent(DataTrackingHelper.EventType.SubTbr_Converter, "SubTbr_Btn", "Btn_SubTbr_toImage");
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)
{
viewContentViewModel.IsPropertyOpen = false;
PDFViewer.SetMouseMode(MouseModes.PanTool);
}
}
}
}