HomePageHeaderFooterDialogViewModel.cs 26 KB

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