123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276 |
- using ComPDFKit.PDFDocument;
- using PDF_Master.Model.Dialog.ToolsDialogs;
- using PDF_Master.Model;
- using Prism.Commands;
- using Prism.Mvvm;
- using Prism.Services.Dialogs;
- using System;
- using System.Diagnostics;
- using System.Windows.Forms;
- using System.Windows;
- using DialogResult = Prism.Services.Dialogs.DialogResult;
- using MessageBox = System.Windows.Forms.MessageBox;
- using PDF_Master.Helper;
- using ComPDFKitViewer.PdfViewer;
- using PDF_Master.Model.Dialog.HomePageToolsDialogs.HomePageBatchProcessing;
- using System.Linq;
- using System.Collections.Generic;
- using PDF_Master.Properties;
- namespace PDF_Master.ViewModels.Dialog.ToolsDialogs.CompressDialogs
- {
- public class CompressDialogViewModel : BindableBase, IDialogAware
- {
- #region 文案
- private string T_title;
- public string T_Title
- {
- get { return T_title; }
- set
- {
- SetProperty(ref T_title, value);
- }
- }
- private string T_high;
- public string T_High
- {
- get { return T_high; }
- set
- {
- SetProperty(ref T_high, value);
- }
- }
- private string T_standard;
- public string T_Standard
- {
- get { return T_standard; }
- set
- {
- SetProperty(ref T_standard, value);
- }
- }
- private string T_low;
- public string T_Low
- {
- get { return T_low; }
- set
- {
- SetProperty(ref T_low, value);
- }
- }
- private string T_minimum;
- public string T_Minimum
- {
- get { return T_minimum; }
- set
- {
- SetProperty(ref T_minimum, value);
- }
- }
- private string T_compress;
- public string T_Compress
- {
- get { return T_compress; }
- set
- {
- SetProperty(ref T_compress, value);
- }
- }
- private string T_cancel;
- public string T_Cancel
- {
- get { return T_cancel; }
- set
- {
- SetProperty(ref T_cancel, value);
- }
- }
- private void InitSting()
- {
- T_Title = App.MainPageLoader.GetString("Compress_Title");
- T_High = App.MainPageLoader.GetString("Compress_High");
- T_Standard = App.MainPageLoader.GetString("Compress_Standard");
- T_Low = App.MainPageLoader.GetString("Compress_Low");
- T_Minimum = App.MainPageLoader.GetString("Compress_Minimum");
- T_Compress = App.MainPageLoader.GetString("Compress_Compress");
- T_Cancel = App.MainPageLoader.GetString("Compress_Cancel");
- }
- #endregion
- #region 参数和属性
- private CompressDialogModel compressDialogModel;
- private IntPtr compressingIntpr = IntPtr.Zero;
- private CPDFDocument document;
- private CPDFViewer pdfviewer;
- public IDialogService dialogs;
-
- #endregion
- #region 委托声明
- public DelegateCommand LargeQualityCommand { get; set; }
- public DelegateCommand StandardQualityCommand { get; set; }
- public DelegateCommand LittleQualityCommand { get; set; }
- public DelegateCommand MicroQualityCommand { get; set; }
- public DelegateCommand CompressCommand { get; set; }
- public DelegateCommand ConfirmCompressCommand { get; set; }
- public DelegateCommand BatchCompressCommand { get; set; }
- #endregion
- public CompressDialogViewModel(IDialogService dialogService)
- {
- InitSting();
- LargeQualityCommand = new DelegateCommand(LargeQuality);
- StandardQualityCommand = new DelegateCommand(StandardQuality);
- LittleQualityCommand = new DelegateCommand(LittleQuality);
- MicroQualityCommand = new DelegateCommand(MicroQuality);
- CompressCommand = new DelegateCommand(Compress);
- ConfirmCompressCommand = new DelegateCommand(ConfirmCompress);
- BatchCompressCommand = new DelegateCommand(BatchCompress);
- dialogs = dialogService;
- }
- #region 逻辑函数
- private void LargeQuality()
- {
- compressDialogModel.CompressQuality = CompressDialogModel.EnumQualityLevel.StatusLarge;
-
- }
- private void StandardQuality()
- {
- compressDialogModel.CompressQuality = CompressDialogModel.EnumQualityLevel.StatusStandard;
-
- }
- private void LittleQuality()
- {
- compressDialogModel.CompressQuality = CompressDialogModel.EnumQualityLevel.StatusLittle;
-
- }
- private void MicroQuality()
- {
- compressDialogModel.CompressQuality = CompressDialogModel.EnumQualityLevel.StatusMicro;
-
- }
- private void ConfirmCompress()
- {
- RequestClose?.Invoke(new DialogResult(ButtonResult.OK));
- }
- private void BatchCompress() {
- DialogParameters compresspdf = new DialogParameters();
- compresspdf.Add(ParameterNames.BatchProcessing_Name, "1");
- HomePageBatchProcessingDialogModel.FilePaths =new List<string> { pdfviewer.Document.FilePath.ToString() } ;
- HomePageBatchProcessingDialogModel.BatchProcessingIndex = 1;
- compresspdf.Add(ParameterNames.FilePath, new string[] { pdfviewer.Document.FilePath.ToString() });
- dialogs.ShowDialog(DialogNames.HomePageBatchProcessingDialog, compresspdf, e => { });
- }
- private int GetIndex(int pageindex)
- {
- Trace.WriteLine(pageindex);
- return 0;
- }
- private void Compress()
- {
- System.Windows.Forms.SaveFileDialog sfd = new System.Windows.Forms.SaveFileDialog();
- /*
- *设置这个对话框的起始保存路径
- */
- sfd.InitialDirectory = pdfviewer.Document.FilePath;
- /*
- *设置保存的文件的类型,注意过滤器的语法 例子:“文件类型|*.后缀名;*.后缀名;”
- */
- sfd.Filter = "PDF|*.pdf;";
- /*
- *调用ShowDialog()方法显示该对话框,该方法的返回值代表用户是否点击了确定按钮
- */
- sfd.FileName = pdfviewer.Document.FileName + "_Compress.pdf";
- /*
- * 做一些工作
- */
- if (sfd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
- {
- string saveSelectedPath = sfd.FileName;
- /*
- * 做一些工作
- */
- Trace.WriteLine("compressDialogModel.CompressQuality: " + compressDialogModel.CompressQuality);
- var dialogresult = new DialogResult(ButtonResult.OK);
- dialogresult.Parameters.Add(ParameterNames.PDFDocument, document);
- dialogresult.Parameters.Add(ParameterNames.PassWord, pdfviewer.Tag);
- dialogresult.Parameters.Add(ParameterNames.FilePath, saveSelectedPath);
- dialogresult.Parameters.Add("compressDialogModel.CompressQuality", (int)compressDialogModel.CompressQuality);
- RequestClose.Invoke(dialogresult);
- //DialogParameters value = new DialogParameters();
- //value.Add(ParameterNames.PDFDocument, document);
- //value.Add(ParameterNames.PassWord, pdfviewer.Tag);
- //value.Add(ParameterNames.FilePath, saveSelectedPath);
- //value.Add("compressDialogModel.CompressQuality", (int)compressDialogModel.CompressQuality);
- //RequestClose?.Invoke(new DialogResult(ButtonResult.OK));
- //dialogs.ShowDialog(DialogNames.CompressProgressBarDialog, value, e =>
- //{
- //});
- }
- else { return; }
- }
-
-
- #endregion
- #region 框架行为
- public string Title => "";
- public event Action<IDialogResult> RequestClose;
- public bool CanCloseDialog()
- {
- return true;
- }
- public void OnDialogClosed()
- {
- }
- public void OnDialogOpened(IDialogParameters parameters)
- {
- parameters.TryGetValue<CPDFViewer>(ParameterNames.PDFViewer, out pdfviewer);
- if (pdfviewer != null)
- {
- CompressDialogModel compressdialogmodel = new CompressDialogModel();
- document = pdfviewer.Document;
- compressDialogModel = compressdialogmodel;
- compressDialogModel.CompressQuality = CompressDialogModel.EnumQualityLevel.StatusDefault;
- }
- }
- #endregion
- }
- }
|