123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718 |
- using ComPDFKit.PDFDocument;
- using PDF_Office.CustomControl;
- using PDF_Office.Model.Dialog.HomePageToolsDialogs.HomePageBatchProcessing;
- using PDF_Office.Model;
- using Prism.Commands;
- using Prism.Mvvm;
- using Prism.Regions;
- using System;
- using System.Collections.Generic;
- using System.Diagnostics;
- using System.IO;
- using System.Linq;
- using System.Windows.Forms;
- using PDF_Office.Helper;
- using System.Windows;
- using System.Data;
- using ComPDFKitViewer.PdfViewer;
- using Prism.Events;
- using PDF_Office.EventAggregators;
- using PDFSettings;
- using PDF_Office.Model.EditTools.Watermark;
- using ComPDFKit.PDFWatermark;
- using Prism.Services.Dialogs;
- namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs.HomePageBatchProcessing.HomePageWatermark
- {
- public class HomePageWatermarkDialogViewModel : BindableBase, INavigationAware
- {
- #region 参数和属性
- private List<string> fileNames;
- private CPDFDocument tempDocument;
- public string PageNumber = "";
- public IEventAggregator eventAggregator;
- public IRegionManager watermarkRegion;
- public IDialogService dialogs;
- private CPDFViewer PDFViewer;
- private CPDFWatermark watermark;
- public WatermarkInfo WatermarkInfo;
- private CPDFViewer CurrentPDFViewer;
- private ViewContentViewModel viewContentViewModel;
- public string TemplateListName = "HomePageWatermarkTemplateListBaseContent";
- public string CreateBaseName = "HomePageWatermarkCreateBaseContent";
- public string CreateModTextName = "HomePageWatermarkCreateTextContent";
- public string CreateModFileName = "HomePageWatermarkCreateFileContent";
- public string TemplateListModTextName = "HomePageWatermarkTemplateListTextContent";
- public string TemplateListModFileName = "HomePageWatermarkTemplateListFileContent";
- private string _watermarkSettingsRegionName;
- public string WatermarkSettingsRegionName
- {
- get { return _watermarkSettingsRegionName; }
- set { _watermarkSettingsRegionName = value; }
- }
- private Visibility _watermarkSettingsVisible = Visibility.Collapsed;
- public Visibility WatermarkSettingsVisible
- {
- get { return _watermarkSettingsVisible; }
- set { _watermarkSettingsVisible = value; }
- }
- private EnumTextOrFile _currentCreateMod;
- public EnumTextOrFile CurrentCreateMod
- {
- get { return _currentCreateMod; }
- set { _currentCreateMod = value; }
- }
- private EnumTextOrFile _currentTemplateListMod;
- public EnumTextOrFile CurrentTemplateListMod
- {
- get { return _currentTemplateListMod; }
- set { _currentTemplateListMod = value; }
- }
- public List<int> fileNamesView = new List<int>();
- private int fileNamesIndex = 0;
- private int FileNameNumber = 0;
- private string watermarkGridIsEnabled = "True";
- public string WatermarkGridIsEnabled
- {
- get
- {
- return watermarkGridIsEnabled;
- }
- set
- {
- SetProperty(ref watermarkGridIsEnabled, value);
- }
- }
- private string setWatermarkGridIsEnabled = "True";
- public string SetWatermarkGridIsEnabled
- {
- get
- {
- return setWatermarkGridIsEnabled;
- }
- set
- {
- SetProperty(ref setWatermarkGridIsEnabled, value);
- }
- }
- private DataTable pdfDataTable = new DataTable();
- public DataTable PDFDataTable
- {
- get { return pdfDataTable; }
- set
- {
- SetProperty(ref pdfDataTable, value);
- }
- }
- private DataTable pdfCurrentDataTable = new DataTable();
- public DataTable PDFCurrentDataTable
- {
- get { return pdfCurrentDataTable; }
- set
- {
- SetProperty(ref pdfCurrentDataTable, value);
- }
- }
- private string removeIsEnable = "False";
- public string RemoveIsEnable
- {
- get { return removeIsEnable; }
- set
- {
- SetProperty(ref removeIsEnable, value);
- }
- }
- private string selectFileName = "False";
- public string SelectFileName
- {
- get { return selectFileName; }
- set
- {
- SetProperty(ref selectFileName, value);
- }
- }
- private string watermarkRegionName;
- public string WatermarkRegionName
- {
- get
- {
- return watermarkRegionName;
- }
- set
- {
- SetProperty(ref watermarkRegionName, value);
- }
- }
- private Visibility watermarkVisible = Visibility.Collapsed;
- public Visibility WatermarkVisible
- {
- get { return watermarkVisible; }
- set { SetProperty(ref watermarkVisible, value); }
- }
- private Visibility addFileVisibility = Visibility.Hidden;
- public Visibility AddFileVisibility
- {
- get { return addFileVisibility; }
- set
- {
- SetProperty(ref addFileVisibility, value);
- RaisePropertyChanged();
- }
- }
- private string createGridSpan = "1";
- public string CreateGridSpan
- {
- get { return createGridSpan; }
- set
- {
- SetProperty(ref createGridSpan, value);
- RaisePropertyChanged();
- }
- }
- private Visibility createGridSpanVisibility = Visibility.Visible;
- public Visibility CreateGridSpanVisibility
- {
- get { return createGridSpanVisibility; }
- set
- {
- SetProperty(ref createGridSpanVisibility, value);
- RaisePropertyChanged();
- }
- }
- #endregion
- #region 委托声明
- public DelegateCommand ADDPDFCommand { get; set; }
- public DelegateCommand RemovePDFFileCommand { get; set; }
- public DelegateCommand CreateCommand { get; set; }
- public DelegateCommand ADDPDFFilesCommand { get; set; }
- #endregion
- public string Unicode = null;
- public HomePageWatermarkDialogViewModel(IRegionManager watermarkRegion, IEventAggregator eventAggregator, IDialogService dialogs)
- {
- this.eventAggregator = eventAggregator;
- this.watermarkRegion = watermarkRegion;
- this.dialogs = dialogs;
- Unicode = App.mainWindowViewModel.SelectedItem.Unicode;
- WatermarkSettingsVisible = Visibility.Visible;
- PDFCurrentDataTable.Columns.Add("FilePageRangeText");
- PDFCurrentDataTable.Columns.Add("FilePageRangeSelectIndex");
- PDFCurrentDataTable.Columns.Add("IsEvenPageIsEnabled");
- PDFCurrentDataTable.Columns.Add("FileState");
- PDFDataTable.Columns.Add("FileName");
- PDFDataTable.Columns.Add("FilePageRangeText");
- PDFDataTable.Columns.Add("FilePageRangeSelectIndex");
- PDFDataTable.Columns.Add("IsEvenPageIsEnabled");
- PDFDataTable.Columns.Add("FileSize");
- PDFDataTable.Columns.Add("FileState");
- ADDPDFCommand = new DelegateCommand(addpicture);
- ADDPDFFilesCommand = new DelegateCommand(addpicturefiles);
- RemovePDFFileCommand = new DelegateCommand(removepdffile);
- CreateCommand = new DelegateCommand(create);
- WatermarkSettingsRegionName = Guid.NewGuid().ToString();
- eventAggregator.GetEvent<EnterTemplateListOrCreateEvent>().Subscribe(EnterTemplateListOrCreate, e => e.Unicode == Unicode);
- eventAggregator.GetEvent<SetCurrentCreateModEvent>().Subscribe(SetCurrentCreateMod, e => e.Unicode == Unicode);
- eventAggregator.GetEvent<SetCurrentTemplateListModEvent>().Subscribe(SetCurrentTemplateListMod, e => e.Unicode == Unicode);
- eventAggregator.GetEvent<CurrentWatermarkPDFViewerEvent>().Subscribe(CurrentWatermarkPDFViewer, e => e.Unicode == Unicode);
- eventAggregator.GetEvent<EditWatermarkTemplateItemEvent>().Subscribe(EditWatermarkTemplateItem, e => e.Unicode == Unicode);
- }
- #region 逻辑函数
- public void EnterTemplateListOrCreate(EnumTemplateListOrCreateUnicode enumTemplateListOrCreateunicode)
- {
- EnumTemplateListOrCreate enumTemplateListOrCreate = enumTemplateListOrCreateunicode.Status;
- if (enumTemplateListOrCreate == EnumTemplateListOrCreate.StatusTemplate)
- {
- CreateGridSpan = "1";
- CreateGridSpanVisibility = Visibility.Visible;
- EnterSelectedContent(TemplateListName);
- }
- else
- {
- CreateGridSpan = "2";
- CreateGridSpanVisibility = Visibility.Collapsed;
- EnterSelectedContent(CreateBaseName);
- }
- }
- public void EnterSelectedContent(string SelectedContentName)
- {
- NavigationParameters param = new NavigationParameters();
- param.Add(ParameterNames.PDFViewer, PDFViewer);
- param.Add("ViewModel", this);
- if (SelectedContentName == TemplateListName)
- {
- param.Add("CurrentCreateModName", CurrentCreateMod);
- }
- else if (SelectedContentName == CreateBaseName)
- {
- param.Add("CurrentTemplateListModName", CurrentTemplateListMod);
- }
- watermarkRegion.RequestNavigate(WatermarkSettingsRegionName, SelectedContentName, param);
- WatermarkSettingsVisible = Visibility.Visible;
- }
- public void SetCurrentCreateMod(stringUnicode currentCreateModNameunicode)
- {
- string currentCreateModName = currentCreateModNameunicode.Status;
- if (currentCreateModName == CreateModTextName)
- {
- CurrentCreateMod = EnumTextOrFile.StatusText;
- }
- else if (currentCreateModName == CreateModFileName)
- {
- CurrentCreateMod = EnumTextOrFile.StatusFile;
- }
- }
- public void SetCurrentTemplateListMod(stringUnicode currentTemplateListModNameunicode)
- {
- string currentTemplateListModName = currentTemplateListModNameunicode.Status;
- if (currentTemplateListModName == TemplateListModTextName)
- {
- CurrentTemplateListMod = EnumTextOrFile.StatusText;
- }
- else if (currentTemplateListModName == TemplateListModFileName)
- {
- CurrentTemplateListMod = EnumTextOrFile.StatusFile;
- }
- }
- public void CurrentWatermarkPDFViewer(CPDFViewerUnicode cPDFViewerunicod)
- {
- CurrentPDFViewer = cPDFViewerunicod.Status;
- }
- public void EditWatermarkTemplateItem(WatermarkItemUnicode watermarkItemunicode)
- {
- WatermarkItem watermarkItem = watermarkItemunicode.Status;
- NavigationParameters param = new NavigationParameters();
- param.Add(ParameterNames.PDFViewer, PDFViewer);
- param.Add("CurrentTemplateListModName", CurrentTemplateListMod);
- param.Add("WatermarkItem", watermarkItem);
- watermarkRegion.RequestNavigate(WatermarkSettingsRegionName, CreateBaseName, param);
- WatermarkSettingsVisible = Visibility.Visible;
- CreateGridSpan = "2";
- CreateGridSpanVisibility = Visibility.Collapsed;
- }
- private void create()
- {
- updateListview("待确定");
- fileNamesIndex = 0;
- WatermarkGridIsEnabled = "False";
- foreach (var filename in fileNames)
- {
- FileInfo fileinfo = new FileInfo(filename);
- string OutputPath = fileinfo.DirectoryName;
- char[] enumerationSeparator = new char[] { ',' };
- char[] rangeSeparator = new char[] { '-' };
- List<int> PageIndexLists = new List<int>();
- CPDFDocument document = CPDFDocument.InitWithFilePath(filename);
- if (document == null )
- {
- PDFDataTable.Rows[fileNamesIndex]["FileState"] = "文件出错";
- PDFCurrentDataTable.Rows[fileNamesIndex]["FileState"] = "文件出错";
- fileNamesIndex++;
- continue;
- }
- if (document.IsLocked)
- {
- DialogParameters value = new DialogParameters();
- value.Add(ParameterNames.PDFDocument, document);
- dialogs.ShowDialog(DialogNames.VerifyPassWordDialog, value, e =>
- {
- if (e.Result == ButtonResult.OK)
- {
- if (e.Parameters.ContainsKey(ParameterNames.PassWord) && e.Parameters.GetValue<string>(ParameterNames.PassWord) != null)
- {
- document.UnlockWithPassword(e.Parameters.GetValue<string>(ParameterNames.PassWord).ToString());
- }
- }
- });
- if (document.IsLocked)
- {
- //未成功解密文档时,释放Document对象,返回
- PDFDataTable.Rows[fileNamesIndex]["FileState"] = "文件出错";
- PDFCurrentDataTable.Rows[fileNamesIndex]["FileState"] = "文件出错";
- fileNamesIndex++;
- continue;
- }
- }
- CreateWatermark(document);
- document.WriteToFilePath(CommonHelper.CreateFilePath(filename + "_Watermark.pdf"));
- //if (!CommonHelper.GetPagesInRange(ref PageIndexLists, "1-" + document.PageCount.ToString(), document.PageCount, enumerationSeparator, rangeSeparator))
- //{ //TODO
- // Trace.WriteLine("输入不对");
- // MessageBoxEx.Show("输入不对");
- // return;
- //}
- document.Release();
- PDFDataTable.Rows[fileNamesIndex]["FileState"] = "完成";
- PDFCurrentDataTable.Rows[fileNamesIndex]["FileState"] = "完成";
- fileNamesIndex++;
- }
- WatermarkGridIsEnabled = "True";
- }
- public void CreateWatermark(CPDFDocument document)
- {
- if (WatermarkInfo != null)
- {
- document.DeleteWatermarks();
- if (WatermarkInfo.WatermarkType == C_Watermark_Type.WATERMARK_TYPE_TEXT)
- {
- watermark = document.InitWatermark(C_Watermark_Type.WATERMARK_TYPE_TEXT);
- watermark.SetText(WatermarkInfo.Text);
- watermark.SetFontName(WatermarkInfo.FontName);
- watermark.SetFontSize(WatermarkInfo.TextSize);
- watermark.SetTextRGBColor(WatermarkInfo.TextColor);
- }
- else
- {
- watermark = document.InitWatermark(C_Watermark_Type.WATERMARK_TYPE_IMG);
- if (WatermarkInfo.ImageArray != null)
- {
- watermark.SetImage(WatermarkInfo.ImageArray, WatermarkInfo.ImageWidth, WatermarkInfo.ImageHeight);
- }
- watermark.SetScale(WatermarkInfo.ImageSize / 100);
- }
- watermark.SetRotation((float)((WatermarkInfo.Rotation / 180) * Math.PI));
- watermark.SetOpacity((byte)(((float)WatermarkInfo.Opacity / 100) * 255));
- watermark.SetFront(WatermarkInfo.IsFront);
- watermark.SetVertalign(WatermarkInfo.WatermarkVertalign);
- watermark.SetHorizalign(WatermarkInfo.WatermarkHorizalign);
- watermark.SetFullScreen(WatermarkInfo.Isfull);
- watermark.SetVertOffset(WatermarkInfo.VertOffset);
- watermark.SetHorizOffset(WatermarkInfo.HorizOffset);
- watermark.SetHorizontalSpacing(WatermarkInfo.HorizontalSpacing);
- watermark.SetVerticalSpacing(WatermarkInfo.VerticalSpacing);
- watermark.SetPages(getFilePageRange(document, PDFCurrentDataTable.Rows[fileNamesIndex]["FilePageRangeText"].ToString(), PDFCurrentDataTable.Rows[fileNamesIndex]["FilePageRangeSelectIndex"].ToString()));
- Trace.WriteLine("IsCreateWatermark: " + watermark.CreateWatermark());
- Trace.WriteLine("IsUpdateWatermark: " + watermark.UpdateWatermark());
- }
- }
- #endregion
- #region 批量处理逻辑函数
- /// <summary>
- /// 添加PDF文件
- /// </summary>
- private void addpicture()
- {
- FileNameNumber = fileNames.Count;
- System.Windows.Forms.OpenFileDialog dlg = new System.Windows.Forms.OpenFileDialog();
- dlg.Multiselect = true;
- dlg.Filter = "PDF|*.pdf;*.PDF;";
- if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
- {
- fileNames.AddRange(dlg.FileNames.ToList());
- RemoveExcess(ref fileNames);
- SetWatermarkGridIsEnabled = "True";
- AddFileVisibility = Visibility.Collapsed;
- updateListview("待确定");
- }
- }
- public void addPDFFiles(string filename)
- {
- FileNameNumber = fileNames.Count;
- fileNames.Add(filename);
- RemoveExcess(ref fileNames);
- SetWatermarkGridIsEnabled = "True";
- AddFileVisibility = Visibility.Collapsed;
- updateListview("待确定");
- }
- /// <summary>
- /// 删除重复的文件
- /// </summary>
- public void RemoveExcess(ref List<string> Filenames)
- {
- List<string> filenames = new List<string>();
- foreach (var fileName in Filenames)
- {
- if (!filenames.Contains(fileName))
- {
- filenames.Add(fileName);
- }
- }
- Filenames.Clear();
- Filenames = filenames;
- }
- /// <summary>
- /// 添加PDF文件夹
- /// </summary>
- private void addpicturefiles()
- {
- FileNameNumber = fileNames.Count;
- FolderBrowserDialog dialog = new FolderBrowserDialog();
- dialog.Description = "请选择文件路径";
- if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
- {
- string foldPath = dialog.SelectedPath;
- var apps = System.IO.Directory.GetFiles(foldPath);
- foreach (string app in apps)
- {
- var fi = new FileInfo(app);
- if (fi.Extension == ".pdf" || fi.Extension == ".PDF")
- {
- fileNames.Add(app);
- }
- }
- RemoveExcess(ref fileNames);
- updateListview("待确定");
- SetWatermarkGridIsEnabled = "True";
- AddFileVisibility = Visibility.Collapsed;
- }
- }
- /// <summary>
- /// 更新listview显示
- /// state 状态显示字符串
- /// </summary>
- public void updateListview(string state)
- {
- updateCurrentListview();
- DataTable pdfdatatable = new DataTable();
- pdfdatatable.Columns.Add("FileName");
- pdfdatatable.Columns.Add("FilePageRangeText");
- pdfdatatable.Columns.Add("FilePageRangeSelectIndex");
- pdfdatatable.Columns.Add("IsEvenPageIsEnabled");
- pdfdatatable.Columns.Add("FileSize");
- pdfdatatable.Columns.Add("FileState");
- int datatableindex = 0;
- List<int> PageIndexLists = new List<int>();
- foreach (var fileName in fileNames)
- {
- string file_all = fileName;
- FileInfo f = new FileInfo(file_all);
- string file_size = (((float)f.Length) / 1024).ToString() + " K";
- if (!isEvenPage(fileName) && PDFCurrentDataTable.Rows[datatableindex]["FilePageRangeSelectIndex"].ToString() == "2")
- {
- PDFCurrentDataTable.Rows[datatableindex]["FilePageRangeSelectIndex"] = "0";
- }
- if (PDFCurrentDataTable.Rows[datatableindex]["FilePageRangeSelectIndex"].ToString() == "3" && !CommonHelper.GetPagesInRange(ref PageIndexLists, PDFCurrentDataTable.Rows[datatableindex]["FilePageRangeText"].ToString(), CPDFDocument.InitWithFilePath(fileName).PageCount, new char[] { ',' }, new char[] { '-' }, true))
- {
- PDFCurrentDataTable.Rows[datatableindex]["FilePageRangeSelectIndex"] = "0";
- }
- pdfdatatable.Rows.Add(f.Name, PDFCurrentDataTable.Rows[datatableindex]["FilePageRangeText"], PDFCurrentDataTable.Rows[datatableindex]["FilePageRangeSelectIndex"], isEvenPage(fileName), file_size, PDFCurrentDataTable.Rows[datatableindex]["FileState"]);
- datatableindex++;
- }
- PDFDataTable = pdfdatatable;
- HomePageBatchProcessingDialogModel.FilePaths = fileNames;
- }
- /// <summary>
- /// 更新Currentlistview显示
- /// pagerangetext 自定义页面范围字符串 pagerangeselectindex combobox下拉索引(0全部页面 1奇数页 2偶数页 3自定义页面)isevenpageisenabled 偶数页状态 state 状态显示字符串
- /// </summary>
- public void updateCurrentListview(string pagerangetext = "1", string pagerangeselectindex = "0", bool isevenpageisenabled = true, string state = "待完成")
- {
- if (fileNames.Count >= FileNameNumber)
- {
- for (int i = 0; fileNames.Count - FileNameNumber > i; i++)
- {
- PDFCurrentDataTable.Rows.Add(pagerangetext, pagerangeselectindex, isevenpageisenabled, state);
- }
- }
- else
- {
- Reverseorder(ref fileNamesView);
- foreach (int filenamesview in fileNamesView)
- {
- PDFCurrentDataTable.Rows.RemoveAt(filenamesview);
- }
- }
- }
- /// <summary>
- /// 更新Currentlistview显示
- /// pagerangetext 自定义页面范围字符串 pagerangeselectindex combobox下拉索引(0全部页面 1奇数页 2偶数页 3自定义页面)
- /// </summary>
- public void updateFilesPageRange(string pagerangetext = "1", string pagerangeselectindex = "0")
- {
- for (int i = 0; fileNames.Count > i; i++)
- {
- PDFDataTable.Rows[i]["FilePageRangeText"] = pagerangetext;
- PDFDataTable.Rows[i]["FilePageRangeSelectIndex"] = pagerangeselectindex;
- PDFCurrentDataTable.Rows[i]["FilePageRangeText"] = pagerangetext;
- PDFCurrentDataTable.Rows[i]["FilePageRangeSelectIndex"] = pagerangeselectindex;
- }
- }
- /// <summary>
- /// 获取文件列表单个文件对应的页码范围
- /// document 文档对象 pagerangetext 自定义页面范围字符串 pagerangeselectindex combobox下拉索引(0全部页面 1奇数页 2偶数页 3自定义页面)
- /// </summary>
- public string getFilePageRange(CPDFDocument document, string pagerangetext = "1", string pagerangeselectindex = "0")
- {
- string filePageRange = "1";
- EditToolsHelper.GetPageRange(int.Parse(pagerangeselectindex), document, ref filePageRange, pagerangetext);
- return filePageRange;
- }
- /// <summary>
- /// 判断是否关闭偶数页
- /// document 文档对象 )
- /// </summary>
- public bool isEvenPage(string filename)
- {
- CPDFDocument document = CPDFDocument.InitWithFilePath(filename);
- bool isevenpage = false;
- if (document.PageCount > 1)
- {
- isevenpage = true;
- }
- document.Release();
- return isevenpage;
- }
- /// <summary>
- /// 逆序int类型集合
- /// </summary>
- public void Reverseorder(ref List<int> Numbers)
- {
- Numbers = Numbers.OrderBy(a => a).ToList();
- Numbers.Reverse();
- }
- /// <summary>
- /// 打开文件PDF
- /// </summary>
- public void openfiledialog()
- {
- foreach (int filenamesview in fileNamesView)
- {
- System.Diagnostics.Process.Start(fileNames[filenamesview]);
- }
- }
- /// <summary>
- /// 删除文件PDF
- /// </summary>
- public void removepdffile()
- {
- FileNameNumber = fileNames.Count;
- Reverseorder(ref fileNamesView);
- foreach (int filenamesview in fileNamesView)
- {
- //Trace.WriteLine(filenamesview);
- fileNames.Remove(fileNames[filenamesview]);
- }
- if (fileNames.Count < 1)
- {
- SetWatermarkGridIsEnabled = "False";
- AddFileVisibility = Visibility.Visible;
- }
- updateListview("待确定");
- }
- public void removepdffile(int index)
- {
- PDFCurrentDataTable.Rows.RemoveAt(index);
- fileNames.Remove(fileNames[index]);
- if (fileNames.Count < 1)
- {
- SetWatermarkGridIsEnabled = "False";
- AddFileVisibility = Visibility.Visible;
- }
- updateListview("待确定");
- }
- public void PDFFileCount()
- {
- if (fileNames.Count == 0)
- {
- SetWatermarkGridIsEnabled = "False";
- AddFileVisibility = Visibility.Visible;
- }
- else
- {
- SetWatermarkGridIsEnabled = "True";
- AddFileVisibility = Visibility.Collapsed;
- }
- }
- #endregion
- #region 构架行为
- public void OnNavigatedTo(NavigationContext navigationContext)
- {
- List<string> filepath = new List<string>();
- navigationContext.Parameters.TryGetValue<ViewContentViewModel>(ParameterNames.ViewContentViewModel, out viewContentViewModel);
- navigationContext.Parameters.TryGetValue<CPDFViewer>(ParameterNames.PDFViewer, out PDFViewer);
-
- navigationContext.Parameters.TryGetValue<List<string>>(ParameterNames.FilePath, out filepath);
- if (filepath != null)
- {
- CreateGridSpan = "1";
- CreateGridSpanVisibility = Visibility.Visible;
- EnterSelectedContent(TemplateListName);
- fileNames = filepath;
- PDFFileCount();
- updateListview("待确定");
- }
- }
- public bool IsNavigationTarget(NavigationContext navigationContext)
- {
- return true;
- }
- public void OnNavigatedFrom(NavigationContext navigationContext)
- {
- }
- #endregion
- }
- }
|