HomePageHeaderFooterDialogViewModel.cs 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683
  1. using ComPDFKit.PDFDocument;
  2. using PDF_Master.CustomControl;
  3. using PDF_Master.Helper;
  4. using PDF_Master.Model.Dialog.HomePageToolsDialogs.HomePageBatchProcessing;
  5. using PDF_Master.Model;
  6. using Prism.Commands;
  7. using Prism.Mvvm;
  8. using Prism.Regions;
  9. using System;
  10. using System.Collections.Generic;
  11. using System.Data;
  12. using System.Diagnostics;
  13. using System.IO;
  14. using System.Linq;
  15. using System.Windows;
  16. using System.Windows.Forms;
  17. using Prism.Events;
  18. using ComPDFKitViewer.PdfViewer;
  19. using PDF_Master.EventAggregators;
  20. using PDFSettings;
  21. using PDF_Master.Model.EditTools.HeaderFooter;
  22. using Prism.Services.Dialogs;
  23. namespace PDF_Master.ViewModels.Dialog.HomePageToolsDialogs.HomePageBatchProcessing.HomePageHeaderFooter
  24. {
  25. public class HomePageHeaderFooterDialogViewModel : BindableBase, INavigationAware
  26. {
  27. #region 参数和属性
  28. private List<string> fileNames;
  29. private CPDFDocument tempDocument;
  30. public string PageNumber = "";
  31. private CPDFHeaderFooter headerFooter;
  32. public IRegionManager headerFooterRegion;
  33. public IEventAggregator eventAggregator;
  34. public IDialogService dialogs;
  35. private CPDFViewer PDFViewer;
  36. public HeaderFooterInfo HeaderFooterInfo;
  37. private ViewContentViewModel viewContentViewModel;
  38. public string TemplateListName = "HomePageHeaderFooterTemplateListContent";
  39. public string CreateName = "HomePageHeaderFooterCreateContent";
  40. public string HeaderFooterType = "HomePageHeaderFooterType";
  41. private string _headerFooterSettingsRegionName;
  42. /// <summary>
  43. /// 属性设置Region
  44. /// </summary>
  45. public string HeaderFooterSettingsRegionName
  46. {
  47. get { return _headerFooterSettingsRegionName; }
  48. set { _headerFooterSettingsRegionName = value; }
  49. }
  50. private Visibility _headerFooterSettingsVisible = Visibility.Visible;
  51. /// <summary>
  52. /// 属性设置Region可见
  53. /// </summary>
  54. public Visibility HeaderFooterSettingsVisible
  55. {
  56. get { return _headerFooterSettingsVisible; }
  57. set { _headerFooterSettingsVisible = value; }
  58. }
  59. public List<int> fileNamesView = new List<int>();
  60. private int fileNamesIndex = 0;
  61. private int FileNameNumber = 0;
  62. private string headerFooterGridIsEnabled = "True";
  63. public string HeaderFooterGridIsEnabled
  64. {
  65. get
  66. {
  67. return headerFooterGridIsEnabled;
  68. }
  69. set
  70. {
  71. SetProperty(ref headerFooterGridIsEnabled, value);
  72. }
  73. }
  74. private string setHeaderFooterGridIsEnabled = "True";
  75. public string SetHeaderFooterGridIsEnabled
  76. {
  77. get
  78. {
  79. return setHeaderFooterGridIsEnabled;
  80. }
  81. set
  82. {
  83. SetProperty(ref setHeaderFooterGridIsEnabled, value);
  84. }
  85. }
  86. private DataTable pdfDataTable = new DataTable();
  87. public DataTable PDFDataTable
  88. {
  89. get { return pdfDataTable; }
  90. set
  91. {
  92. SetProperty(ref pdfDataTable, value);
  93. }
  94. }
  95. private DataTable pdfCurrentDataTable = new DataTable();
  96. public DataTable PDFCurrentDataTable
  97. {
  98. get { return pdfCurrentDataTable; }
  99. set
  100. {
  101. SetProperty(ref pdfCurrentDataTable, value);
  102. }
  103. }
  104. private string removeIsEnable = "False";
  105. public string RemoveIsEnable
  106. {
  107. get { return removeIsEnable; }
  108. set
  109. {
  110. SetProperty(ref removeIsEnable, value);
  111. }
  112. }
  113. private string selectFileName = "False";
  114. public string SelectFileName
  115. {
  116. get { return selectFileName; }
  117. set
  118. {
  119. SetProperty(ref selectFileName, value);
  120. }
  121. }
  122. private string headerFooterRegionName;
  123. public string HeaderFooterRegionName
  124. {
  125. get
  126. {
  127. return headerFooterRegionName;
  128. }
  129. set
  130. {
  131. SetProperty(ref headerFooterRegionName, value);
  132. }
  133. }
  134. private Visibility headerFooterVisible = Visibility.Collapsed;
  135. public Visibility HeaderFooterVisible
  136. {
  137. get { return headerFooterVisible; }
  138. set { SetProperty(ref headerFooterVisible, value); }
  139. }
  140. private Visibility addFileVisibility = Visibility.Hidden;
  141. public Visibility AddFileVisibility
  142. {
  143. get { return addFileVisibility; }
  144. set
  145. {
  146. SetProperty(ref addFileVisibility, value);
  147. RaisePropertyChanged();
  148. }
  149. }
  150. private string createGridSpan = "1";
  151. public string CreateGridSpan
  152. {
  153. get { return createGridSpan; }
  154. set
  155. {
  156. SetProperty(ref createGridSpan, value);
  157. RaisePropertyChanged();
  158. }
  159. }
  160. private Visibility createGridSpanVisibility = Visibility.Visible;
  161. public Visibility CreateGridSpanVisibility
  162. {
  163. get { return createGridSpanVisibility; }
  164. set
  165. {
  166. SetProperty(ref createGridSpanVisibility, value);
  167. RaisePropertyChanged();
  168. }
  169. }
  170. private bool _createBtnIsEnabled = false;
  171. public bool CreateBtnIsEnabled
  172. {
  173. get { return _createBtnIsEnabled; }
  174. set { SetProperty(ref _createBtnIsEnabled, value); }
  175. }
  176. #endregion
  177. #region 委托声明
  178. public DelegateCommand ADDPDFCommand { get; set; }
  179. public DelegateCommand ADDOpenedPDFCommand { get; set; }
  180. public DelegateCommand RemovePDFFileCommand { get; set; }
  181. public DelegateCommand CreateCommand { get; set; }
  182. public DelegateCommand ADDPDFFilesCommand { get; set; }
  183. #endregion
  184. public string Unicode = null;
  185. public HomePageHeaderFooterDialogViewModel(IRegionManager regionManager, IEventAggregator eventAggregator, IDialogService dialogs)
  186. {
  187. this.eventAggregator = eventAggregator;
  188. this.headerFooterRegion = regionManager;
  189. this.dialogs = dialogs;
  190. HeaderFooterSettingsRegionName = Guid.NewGuid().ToString();
  191. Unicode = Guid.NewGuid().ToString();
  192. PDFCurrentDataTable.Columns.Add("FilePageRangeText");
  193. PDFCurrentDataTable.Columns.Add("FilePageRangeSelectIndex");
  194. PDFCurrentDataTable.Columns.Add("IsEvenPageIsEnabled");
  195. PDFCurrentDataTable.Columns.Add("FileState");
  196. PDFDataTable.Columns.Add("FileName");
  197. PDFDataTable.Columns.Add("FilePageRangeText");
  198. PDFDataTable.Columns.Add("FilePageRangeSelectIndex");
  199. PDFDataTable.Columns.Add("IsEvenPageIsEnabled");
  200. PDFDataTable.Columns.Add("MaxPageRange");
  201. PDFDataTable.Columns.Add("FileSize");
  202. PDFDataTable.Columns.Add("FileState");
  203. ADDPDFCommand = new DelegateCommand(addpicture);
  204. ADDOpenedPDFCommand = new DelegateCommand(addOpenedPDFFiles);
  205. ADDPDFFilesCommand = new DelegateCommand(addpicturefiles);
  206. RemovePDFFileCommand = new DelegateCommand(removepdffile);
  207. CreateCommand = new DelegateCommand(create);
  208. eventAggregator.GetEvent<EditBatesHeaderFooterTemplateItemEvent>().Subscribe(EditHeaderFooterTemplateItem, e => e.Unicode == Unicode && e.Type == HeaderFooterType);
  209. eventAggregator.GetEvent<EnterTemplateListOrCreateEvent>().Subscribe(EnterTemplateListOrCreate, e => e.Unicode == Unicode);
  210. }
  211. #region 逻辑函数
  212. public void EditHeaderFooterTemplateItem(BatesHeaderFooterItemUnicode headerfooterItemunicode)
  213. {
  214. BatesHeaderFooterItem headerfooterItem = headerfooterItemunicode.Status;
  215. NavigationParameters param = new NavigationParameters();
  216. param.Add("Unicode", Unicode);
  217. param.Add(ParameterNames.PDFViewer, PDFViewer);
  218. param.Add("HeaderFooterItem", headerfooterItem);
  219. headerFooterRegion.RequestNavigate(HeaderFooterSettingsRegionName, CreateName, param);
  220. HeaderFooterSettingsVisible = Visibility.Visible;
  221. CreateGridSpan = "2";
  222. CreateGridSpanVisibility = Visibility.Collapsed;
  223. }
  224. public void EnterTemplateListOrCreate(EnumTemplateListOrCreateUnicode enumTemplateListOrCreateunicode)
  225. {
  226. EnumTemplateListOrCreate enumTemplateListOrCreate = enumTemplateListOrCreateunicode.Status;
  227. if (enumTemplateListOrCreate == EnumTemplateListOrCreate.StatusTemplate)
  228. {
  229. CreateGridSpan = "1";
  230. CreateGridSpanVisibility = Visibility.Visible;
  231. EnterSelectedContent(TemplateListName);
  232. }
  233. else
  234. {
  235. CreateGridSpan = "2";
  236. CreateGridSpanVisibility = Visibility.Collapsed;
  237. EnterSelectedContent(CreateName);
  238. }
  239. }
  240. public void EnterSelectedContent(string SelectedContentName)
  241. {
  242. NavigationParameters param = new NavigationParameters();
  243. param.Add("Unicode", Unicode);
  244. param.Add(ParameterNames.PDFViewer, PDFViewer);
  245. param.Add("ViewModel", this);
  246. headerFooterRegion.RequestNavigate(HeaderFooterSettingsRegionName, SelectedContentName, param);
  247. HeaderFooterSettingsVisible = Visibility.Visible;
  248. }
  249. private void create()
  250. {
  251. FolderBrowserDialog dlg = new FolderBrowserDialog();
  252. string saveSelectedPath = "";
  253. if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  254. {
  255. saveSelectedPath = dlg.SelectedPath.Trim();
  256. saveSelectedPath = saveSelectedPath + "\\";
  257. }
  258. else { return; }
  259. HomePageBatchProcessingDialogModel.closeDialog = true;
  260. updateListview("wait");
  261. fileNamesIndex = 0;
  262. HeaderFooterGridIsEnabled = "False";
  263. foreach (var filename in fileNames)
  264. {
  265. FileInfo fileinfo = new FileInfo(filename);
  266. string OutputPath = fileinfo.DirectoryName;
  267. char[] enumerationSeparator = new char[] { ',' };
  268. char[] rangeSeparator = new char[] { '-' };
  269. List<int> PageIndexLists = new List<int>();
  270. CPDFDocument document = CPDFDocument.InitWithFilePath(filename);
  271. if (document == null)
  272. {
  273. PDFDataTable.Rows[fileNamesIndex]["FileState"] = "error";
  274. PDFCurrentDataTable.Rows[fileNamesIndex]["FileState"] = "error";
  275. fileNamesIndex++;
  276. continue;
  277. }
  278. if (document.IsLocked)
  279. {
  280. DialogParameters value = new DialogParameters();
  281. value.Add(ParameterNames.PDFDocument, document);
  282. dialogs.ShowDialog(DialogNames.VerifyPassWordDialog, value, e =>
  283. {
  284. if (e.Result == ButtonResult.OK)
  285. {
  286. if (e.Parameters.ContainsKey(ParameterNames.PassWord) && e.Parameters.GetValue<string>(ParameterNames.PassWord) != null)
  287. {
  288. document.UnlockWithPassword(e.Parameters.GetValue<string>(ParameterNames.PassWord).ToString());
  289. }
  290. }
  291. });
  292. if (document.IsLocked)
  293. {
  294. //未成功解密文档时,释放Document对象,返回
  295. PDFDataTable.Rows[fileNamesIndex]["FileState"] = "error";
  296. PDFCurrentDataTable.Rows[fileNamesIndex]["FileState"] = "error";
  297. fileNamesIndex++;
  298. continue;
  299. }
  300. }
  301. CreateHeaderFooter(document);
  302. document.WriteToFilePath(CommonHelper.CreateFilePath(saveSelectedPath + document.FileName + "_HeaderFooter.pdf"));
  303. //if (!CommonHelper.GetPagesInRange(ref PageIndexLists, "1-" + document.PageCount.ToString(), document.PageCount, enumerationSeparator, rangeSeparator))
  304. //{ //TODO
  305. // Trace.WriteLine("输入不对");
  306. // MessageBoxEx.Show("输入不对");
  307. // return;
  308. //}
  309. document.Release();
  310. PDFDataTable.Rows[fileNamesIndex]["FileState"] = "complete";
  311. PDFCurrentDataTable.Rows[fileNamesIndex]["FileState"] = "complete";
  312. fileNamesIndex++;
  313. }
  314. HeaderFooterGridIsEnabled = "True";
  315. HomePageBatchProcessingDialogModel.closeDialog = false;
  316. }
  317. public void CreateHeaderFooter(CPDFDocument document)
  318. {
  319. if (HeaderFooterInfo != null)
  320. {
  321. //document.(HeaderFooterInfo.TextData, HeaderFooterInfo.margin, HeaderFooterInfo.PageRange, HeaderFooterInfo.StarPagetNumber + 1);
  322. headerFooter = document.GetHeaderFooter();
  323. for (int i = 0; i < 6; i++)
  324. {
  325. headerFooter.SetText(i, HomePageEditHelper.ReverseDate(HeaderFooterInfo.TextData[i].text, document));
  326. headerFooter.SetFontName(i, HeaderFooterInfo.TextData[i].fontName);
  327. headerFooter.SetFontSize(i, HeaderFooterInfo.TextData[i].fontSize);
  328. headerFooter.SetTextColor(i, HeaderFooterInfo.TextData[i].Color);
  329. }
  330. headerFooter.SetPages(getFilePageRange(document, PDFCurrentDataTable.Rows[fileNamesIndex]["FilePageRangeText"].ToString(), PDFCurrentDataTable.Rows[fileNamesIndex]["FilePageRangeSelectIndex"].ToString()));
  331. headerFooter.SetPageOffset(HeaderFooterInfo.StarPagetNumber + 1);
  332. headerFooter.SetMargin(HeaderFooterInfo.margin);
  333. headerFooter.Update();
  334. }
  335. }
  336. #endregion
  337. #region 批量处理逻辑函数
  338. /// <summary>
  339. /// 添加PDF文件
  340. /// </summary>
  341. private void addpicture()
  342. {
  343. FileNameNumber = fileNames.Count;
  344. System.Windows.Forms.OpenFileDialog dlg = new System.Windows.Forms.OpenFileDialog();
  345. dlg.Multiselect = true;
  346. dlg.Filter = "PDF|*.pdf;*.PDF;";
  347. if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  348. {
  349. fileNames.AddRange(dlg.FileNames.ToList());
  350. RemoveExcess(ref fileNames);
  351. SetHeaderFooterGridIsEnabled = "True";
  352. AddFileVisibility = Visibility.Collapsed;
  353. updateListview("wait");
  354. }
  355. }
  356. public void addPDFFiles(string filename)
  357. {
  358. FileNameNumber = fileNames.Count;
  359. fileNames.Add(filename);
  360. RemoveExcess(ref fileNames);
  361. SetHeaderFooterGridIsEnabled = "True";
  362. AddFileVisibility = Visibility.Collapsed;
  363. updateListview("wait");
  364. }
  365. /// <summary>
  366. /// 添加已打开PDF文件
  367. /// </summary>
  368. public void addOpenedPDFFiles()
  369. {
  370. FileNameNumber = fileNames.Count;
  371. foreach (var filename in App.OpenedFileList)
  372. {
  373. fileNames.Add(filename);
  374. }
  375. RemoveExcess(ref fileNames);
  376. SetHeaderFooterGridIsEnabled = "True";
  377. AddFileVisibility = Visibility.Collapsed;
  378. updateListview("wait");
  379. }
  380. /// <summary>
  381. /// 删除重复的文件
  382. /// </summary>
  383. public void RemoveExcess(ref List<string> Filenames)
  384. {
  385. List<string> filenames = new List<string>();
  386. foreach (var fileName in Filenames)
  387. {
  388. if (!filenames.Contains(fileName))
  389. {
  390. filenames.Add(fileName);
  391. }
  392. }
  393. Filenames.Clear();
  394. Filenames = filenames;
  395. }
  396. /// <summary>
  397. /// 添加PDF文件夹
  398. /// </summary>
  399. private void addpicturefiles()
  400. {
  401. FileNameNumber = fileNames.Count;
  402. FolderBrowserDialog dialog = new FolderBrowserDialog();
  403. dialog.Description = "请选择文件路径";
  404. if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  405. {
  406. string foldPath = dialog.SelectedPath;
  407. var apps = System.IO.Directory.GetFiles(foldPath);
  408. foreach (string app in apps)
  409. {
  410. var fi = new FileInfo(app);
  411. if (fi.Extension == ".pdf" || fi.Extension == ".PDF")
  412. {
  413. fileNames.Add(app);
  414. }
  415. }
  416. RemoveExcess(ref fileNames);
  417. updateListview("wait");
  418. SetHeaderFooterGridIsEnabled = "True";
  419. AddFileVisibility = Visibility.Collapsed;
  420. }
  421. }
  422. /// <summary>
  423. /// 更新listview显示
  424. /// state 状态显示字符串
  425. /// </summary>
  426. public void updateListview(string state)
  427. {
  428. updateCurrentListview();
  429. DataTable pdfdatatable = new DataTable();
  430. pdfdatatable.Columns.Add("FileName");
  431. pdfdatatable.Columns.Add("FilePageRangeText");
  432. pdfdatatable.Columns.Add("FilePageRangeSelectIndex");
  433. pdfdatatable.Columns.Add("IsEvenPageIsEnabled");
  434. pdfdatatable.Columns.Add("MaxPageRange");
  435. pdfdatatable.Columns.Add("FileSize");
  436. pdfdatatable.Columns.Add("FileState");
  437. int datatableindex = 0;
  438. List<int> PageIndexLists = new List<int>();
  439. foreach (var fileName in fileNames)
  440. {
  441. string file_all = fileName;
  442. FileInfo f = new FileInfo(file_all);
  443. string file_size = (((float)f.Length) / 1024).ToString() + " K";
  444. if (!isEvenPage(fileName) && PDFCurrentDataTable.Rows[datatableindex]["FilePageRangeSelectIndex"].ToString() == "2")
  445. {
  446. PDFCurrentDataTable.Rows[datatableindex]["FilePageRangeSelectIndex"] = "0";
  447. }
  448. int pagecount = CPDFDocument.InitWithFilePath(fileName).PageCount;
  449. if (PDFCurrentDataTable.Rows[datatableindex]["FilePageRangeSelectIndex"].ToString() == "3" && !CommonHelper.GetPagesInRange(ref PageIndexLists, PDFCurrentDataTable.Rows[datatableindex]["FilePageRangeText"].ToString(), pagecount, new char[] { ',' }, new char[] { '-' }, true))
  450. {
  451. PDFCurrentDataTable.Rows[datatableindex]["FilePageRangeSelectIndex"] = "0";
  452. }
  453. pdfdatatable.Rows.Add(f.Name, PDFCurrentDataTable.Rows[datatableindex]["FilePageRangeText"], PDFCurrentDataTable.Rows[datatableindex]["FilePageRangeSelectIndex"], isEvenPage(fileName), pagecount, file_size, PDFCurrentDataTable.Rows[datatableindex]["FileState"]);
  454. datatableindex++;
  455. }
  456. PDFDataTable = pdfdatatable;
  457. HomePageBatchProcessingDialogModel.FilePaths = fileNames;
  458. }
  459. /// <summary>
  460. /// 更新Currentlistview显示
  461. /// pagerangetext 自定义页面范围字符串 pagerangeselectindex combobox下拉索引(0全部页面 1奇数页 2偶数页 3自定义页面)isevenpageisenabled 偶数页状态 state 状态显示字符串
  462. /// </summary>
  463. public void updateCurrentListview(string pagerangetext = "1", string pagerangeselectindex = "0", bool isevenpageisenabled = true, string state = "wait")
  464. {
  465. if (fileNames.Count >= FileNameNumber)
  466. {
  467. for (int i = 0; fileNames.Count - FileNameNumber > i; i++)
  468. {
  469. PDFCurrentDataTable.Rows.Add(pagerangetext, pagerangeselectindex, isevenpageisenabled, state);
  470. }
  471. }
  472. else
  473. {
  474. Reverseorder(ref fileNamesView);
  475. foreach (int filenamesview in fileNamesView)
  476. {
  477. PDFCurrentDataTable.Rows.RemoveAt(filenamesview);
  478. }
  479. }
  480. }
  481. /// <summary>
  482. /// 更新Currentlistview显示
  483. /// pagerangetext 自定义页面范围字符串 pagerangeselectindex combobox下拉索引(0全部页面 1奇数页 2偶数页 3自定义页面)
  484. /// </summary>
  485. public void updateFilesPageRange(string pagerangetext = "1", string pagerangeselectindex = "0")
  486. {
  487. for (int i = 0; fileNames.Count > i; i++)
  488. {
  489. PDFDataTable.Rows[i]["FilePageRangeText"] = pagerangetext;
  490. PDFDataTable.Rows[i]["FilePageRangeSelectIndex"] = pagerangeselectindex;
  491. PDFCurrentDataTable.Rows[i]["FilePageRangeText"] = pagerangetext;
  492. PDFCurrentDataTable.Rows[i]["FilePageRangeSelectIndex"] = pagerangeselectindex;
  493. }
  494. }
  495. /// <summary>
  496. /// 获取文件列表单个文件对应的页码范围
  497. /// document 文档对象 pagerangetext 自定义页面范围字符串 pagerangeselectindex combobox下拉索引(0全部页面 1奇数页 2偶数页 3自定义页面)
  498. /// </summary>
  499. public string getFilePageRange(CPDFDocument document, string pagerangetext = "1", string pagerangeselectindex = "0")
  500. {
  501. string filePageRange = "1";
  502. EditToolsHelper.GetPageRange(int.Parse(pagerangeselectindex), document, ref filePageRange, pagerangetext);
  503. return filePageRange;
  504. }
  505. /// <summary>
  506. /// 判断是否关闭偶数页
  507. /// document 文档对象 )
  508. /// </summary>
  509. public bool isEvenPage(string filename)
  510. {
  511. CPDFDocument document = CPDFDocument.InitWithFilePath(filename);
  512. bool isevenpage = false;
  513. if (document.PageCount > 1)
  514. {
  515. isevenpage = true;
  516. }
  517. document.Release();
  518. return isevenpage;
  519. }
  520. /// <summary>
  521. /// 逆序int类型集合
  522. /// </summary>
  523. public void Reverseorder(ref List<int> Numbers)
  524. {
  525. Numbers = Numbers.OrderBy(a => a).ToList();
  526. Numbers.Reverse();
  527. }
  528. /// <summary>
  529. /// 打开文件PDF
  530. /// </summary>
  531. public void openfiledialog()
  532. {
  533. foreach (int filenamesview in fileNamesView)
  534. {
  535. System.Diagnostics.Process.Start("Explorer", "/select," + fileNames[filenamesview]);
  536. }
  537. }
  538. /// <summary>
  539. /// 删除文件PDF
  540. /// </summary>
  541. public void removepdffile()
  542. {
  543. FileNameNumber = fileNames.Count;
  544. Reverseorder(ref fileNamesView);
  545. foreach (int filenamesview in fileNamesView)
  546. {
  547. //Trace.WriteLine(filenamesview);
  548. fileNames.Remove(fileNames[filenamesview]);
  549. }
  550. if (fileNames.Count < 1)
  551. {
  552. SetHeaderFooterGridIsEnabled = "False";
  553. AddFileVisibility = Visibility.Visible;
  554. }
  555. updateListview("wait");
  556. }
  557. public void removepdffile(int index)
  558. {
  559. PDFCurrentDataTable.Rows.RemoveAt(index);
  560. fileNames.Remove(fileNames[index]);
  561. if (fileNames.Count < 1)
  562. {
  563. SetHeaderFooterGridIsEnabled = "False";
  564. AddFileVisibility = Visibility.Visible;
  565. }
  566. updateListview("wait");
  567. }
  568. public void PDFFileCount()
  569. {
  570. if (fileNames.Count == 0)
  571. {
  572. SetHeaderFooterGridIsEnabled = "False";
  573. AddFileVisibility = Visibility.Visible;
  574. }
  575. else
  576. {
  577. SetHeaderFooterGridIsEnabled = "True";
  578. AddFileVisibility = Visibility.Collapsed;
  579. }
  580. }
  581. #endregion
  582. #region 构架行为
  583. public void OnNavigatedTo(NavigationContext navigationContext)
  584. {
  585. List<string> filepath = new List<string>();
  586. navigationContext.Parameters.TryGetValue<ViewContentViewModel>(ParameterNames.ViewContentViewModel, out viewContentViewModel);
  587. navigationContext.Parameters.TryGetValue<CPDFViewer>(ParameterNames.PDFViewer, out PDFViewer);
  588. navigationContext.Parameters.TryGetValue<List<string>>(ParameterNames.FilePath, out filepath);
  589. if (filepath != null)
  590. {
  591. fileNames = filepath;
  592. PDFFileCount();
  593. CreateGridSpan = "1";
  594. CreateGridSpanVisibility = Visibility.Visible;
  595. updateListview("wait");
  596. EnterSelectedContent(TemplateListName);
  597. }
  598. }
  599. public bool IsNavigationTarget(NavigationContext navigationContext)
  600. {
  601. return true;
  602. }
  603. public void OnNavigatedFrom(NavigationContext navigationContext)
  604. {
  605. }
  606. #endregion
  607. }
  608. }