HomePageHeaderFooterDialogViewModel.cs 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647
  1. using ComPDFKit.PDFDocument;
  2. using PDF_Office.CustomControl;
  3. using PDF_Office.Helper;
  4. using PDF_Office.Model.Dialog.HomePageToolsDialogs.HomePageBatchProcessing;
  5. using PDF_Office.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_Office.EventAggregators;
  20. using PDFSettings;
  21. using PDF_Office.Model.EditTools.HeaderFooter;
  22. using Prism.Services.Dialogs;
  23. namespace PDF_Office.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. #endregion
  171. #region 委托声明
  172. public DelegateCommand ADDPDFCommand { get; set; }
  173. public DelegateCommand RemovePDFFileCommand { get; set; }
  174. public DelegateCommand CreateCommand { get; set; }
  175. public DelegateCommand ADDPDFFilesCommand { get; set; }
  176. #endregion
  177. public string Unicode = null;
  178. public HomePageHeaderFooterDialogViewModel(IRegionManager regionManager, IEventAggregator eventAggregator, IDialogService dialogs)
  179. {
  180. this.eventAggregator = eventAggregator;
  181. this.headerFooterRegion = regionManager;
  182. this.dialogs = dialogs;
  183. HeaderFooterSettingsRegionName = Guid.NewGuid().ToString();
  184. Unicode = Guid.NewGuid().ToString();
  185. PDFCurrentDataTable.Columns.Add("FilePageRangeText");
  186. PDFCurrentDataTable.Columns.Add("FilePageRangeSelectIndex");
  187. PDFCurrentDataTable.Columns.Add("IsEvenPageIsEnabled");
  188. PDFCurrentDataTable.Columns.Add("FileState");
  189. PDFDataTable.Columns.Add("FileName");
  190. PDFDataTable.Columns.Add("FilePageRangeText");
  191. PDFDataTable.Columns.Add("FilePageRangeSelectIndex");
  192. PDFDataTable.Columns.Add("IsEvenPageIsEnabled");
  193. PDFDataTable.Columns.Add("MaxPageRange");
  194. PDFDataTable.Columns.Add("FileSize");
  195. PDFDataTable.Columns.Add("FileState");
  196. ADDPDFCommand = new DelegateCommand(addpicture);
  197. ADDPDFFilesCommand = new DelegateCommand(addpicturefiles);
  198. RemovePDFFileCommand = new DelegateCommand(removepdffile);
  199. CreateCommand = new DelegateCommand(create);
  200. eventAggregator.GetEvent<EditBatesHeaderFooterTemplateItemEvent>().Subscribe(EditHeaderFooterTemplateItem, e => e.Unicode == Unicode && e.Type == HeaderFooterType);
  201. eventAggregator.GetEvent<EnterTemplateListOrCreateEvent>().Subscribe(EnterTemplateListOrCreate, e => e.Unicode == Unicode);
  202. }
  203. #region 逻辑函数
  204. public void EditHeaderFooterTemplateItem(BatesHeaderFooterItemUnicode headerfooterItemunicode)
  205. {
  206. BatesHeaderFooterItem headerfooterItem = headerfooterItemunicode.Status;
  207. NavigationParameters param = new NavigationParameters();
  208. param.Add("Unicode", Unicode);
  209. param.Add(ParameterNames.PDFViewer, PDFViewer);
  210. param.Add("HeaderFooterItem", headerfooterItem);
  211. headerFooterRegion.RequestNavigate(HeaderFooterSettingsRegionName, CreateName, param);
  212. HeaderFooterSettingsVisible = Visibility.Visible;
  213. CreateGridSpan = "2";
  214. CreateGridSpanVisibility = Visibility.Collapsed;
  215. }
  216. public void EnterTemplateListOrCreate(EnumTemplateListOrCreateUnicode enumTemplateListOrCreateunicode)
  217. {
  218. EnumTemplateListOrCreate enumTemplateListOrCreate = enumTemplateListOrCreateunicode.Status;
  219. if (enumTemplateListOrCreate == EnumTemplateListOrCreate.StatusTemplate)
  220. {
  221. CreateGridSpan = "1";
  222. CreateGridSpanVisibility = Visibility.Visible;
  223. EnterSelectedContent(TemplateListName);
  224. }
  225. else
  226. {
  227. CreateGridSpan = "2";
  228. CreateGridSpanVisibility = Visibility.Collapsed;
  229. EnterSelectedContent(CreateName);
  230. }
  231. }
  232. public void EnterSelectedContent(string SelectedContentName)
  233. {
  234. NavigationParameters param = new NavigationParameters();
  235. param.Add("Unicode", Unicode);
  236. param.Add(ParameterNames.PDFViewer, PDFViewer);
  237. param.Add("ViewModel", this);
  238. headerFooterRegion.RequestNavigate(HeaderFooterSettingsRegionName, SelectedContentName, param);
  239. HeaderFooterSettingsVisible = Visibility.Visible;
  240. }
  241. private void create()
  242. {
  243. updateListview("wait");
  244. fileNamesIndex = 0;
  245. HeaderFooterGridIsEnabled = "False";
  246. foreach (var filename in fileNames)
  247. {
  248. FileInfo fileinfo = new FileInfo(filename);
  249. string OutputPath = fileinfo.DirectoryName;
  250. char[] enumerationSeparator = new char[] { ',' };
  251. char[] rangeSeparator = new char[] { '-' };
  252. List<int> PageIndexLists = new List<int>();
  253. CPDFDocument document = CPDFDocument.InitWithFilePath(filename);
  254. if (document == null)
  255. {
  256. PDFDataTable.Rows[fileNamesIndex]["FileState"] = "error";
  257. PDFCurrentDataTable.Rows[fileNamesIndex]["FileState"] = "error";
  258. fileNamesIndex++;
  259. continue;
  260. }
  261. if (document.IsLocked)
  262. {
  263. DialogParameters value = new DialogParameters();
  264. value.Add(ParameterNames.PDFDocument, document);
  265. dialogs.ShowDialog(DialogNames.VerifyPassWordDialog, value, e =>
  266. {
  267. if (e.Result == ButtonResult.OK)
  268. {
  269. if (e.Parameters.ContainsKey(ParameterNames.PassWord) && e.Parameters.GetValue<string>(ParameterNames.PassWord) != null)
  270. {
  271. document.UnlockWithPassword(e.Parameters.GetValue<string>(ParameterNames.PassWord).ToString());
  272. }
  273. }
  274. });
  275. if (document.IsLocked)
  276. {
  277. //未成功解密文档时,释放Document对象,返回
  278. PDFDataTable.Rows[fileNamesIndex]["FileState"] = "error";
  279. PDFCurrentDataTable.Rows[fileNamesIndex]["FileState"] = "error";
  280. fileNamesIndex++;
  281. continue;
  282. }
  283. }
  284. CreateHeaderFooter(document);
  285. document.WriteToFilePath(CommonHelper.CreateFilePath(filename + "_HeaderFooter.pdf"));
  286. //if (!CommonHelper.GetPagesInRange(ref PageIndexLists, "1-" + document.PageCount.ToString(), document.PageCount, enumerationSeparator, rangeSeparator))
  287. //{ //TODO
  288. // Trace.WriteLine("输入不对");
  289. // MessageBoxEx.Show("输入不对");
  290. // return;
  291. //}
  292. document.Release();
  293. PDFDataTable.Rows[fileNamesIndex]["FileState"] = "complete";
  294. PDFCurrentDataTable.Rows[fileNamesIndex]["FileState"] = "complete";
  295. fileNamesIndex++;
  296. }
  297. HeaderFooterGridIsEnabled = "True";
  298. }
  299. public void CreateHeaderFooter(CPDFDocument document)
  300. {
  301. if (HeaderFooterInfo != null)
  302. {
  303. //document.(HeaderFooterInfo.TextData, HeaderFooterInfo.margin, HeaderFooterInfo.PageRange, HeaderFooterInfo.StarPagetNumber + 1);
  304. headerFooter = document.GetHeaderFooter();
  305. for (int i = 0; i < 6; i++)
  306. {
  307. headerFooter.SetText(i, HomePageEditHelper.ReverseDate(HeaderFooterInfo.TextData[i].text, document));
  308. headerFooter.SetFontName(i, HeaderFooterInfo.TextData[i].fontName);
  309. headerFooter.SetFontSize(i, HeaderFooterInfo.TextData[i].fontSize);
  310. headerFooter.SetTextColor(i, HeaderFooterInfo.TextData[i].Color);
  311. }
  312. headerFooter.SetPages(getFilePageRange(document, PDFCurrentDataTable.Rows[fileNamesIndex]["FilePageRangeText"].ToString(), PDFCurrentDataTable.Rows[fileNamesIndex]["FilePageRangeSelectIndex"].ToString()));
  313. headerFooter.SetPageOffset(HeaderFooterInfo.StarPagetNumber + 1);
  314. headerFooter.SetMargin(HeaderFooterInfo.margin);
  315. headerFooter.Update();
  316. }
  317. }
  318. #endregion
  319. #region 批量处理逻辑函数
  320. /// <summary>
  321. /// 添加PDF文件
  322. /// </summary>
  323. private void addpicture()
  324. {
  325. FileNameNumber = fileNames.Count;
  326. System.Windows.Forms.OpenFileDialog dlg = new System.Windows.Forms.OpenFileDialog();
  327. dlg.Multiselect = true;
  328. dlg.Filter = "PDF|*.pdf;*.PDF;";
  329. if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  330. {
  331. fileNames.AddRange(dlg.FileNames.ToList());
  332. RemoveExcess(ref fileNames);
  333. SetHeaderFooterGridIsEnabled = "True";
  334. AddFileVisibility = Visibility.Collapsed;
  335. updateListview("wait");
  336. }
  337. }
  338. public void addPDFFiles(string filename)
  339. {
  340. FileNameNumber = fileNames.Count;
  341. fileNames.Add(filename);
  342. RemoveExcess(ref fileNames);
  343. SetHeaderFooterGridIsEnabled = "True";
  344. AddFileVisibility = Visibility.Collapsed;
  345. updateListview("wait");
  346. }
  347. /// <summary>
  348. /// 删除重复的文件
  349. /// </summary>
  350. public void RemoveExcess(ref List<string> Filenames)
  351. {
  352. List<string> filenames = new List<string>();
  353. foreach (var fileName in Filenames)
  354. {
  355. if (!filenames.Contains(fileName))
  356. {
  357. filenames.Add(fileName);
  358. }
  359. }
  360. Filenames.Clear();
  361. Filenames = filenames;
  362. }
  363. /// <summary>
  364. /// 添加PDF文件夹
  365. /// </summary>
  366. private void addpicturefiles()
  367. {
  368. FileNameNumber = fileNames.Count;
  369. FolderBrowserDialog dialog = new FolderBrowserDialog();
  370. dialog.Description = "请选择文件路径";
  371. if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  372. {
  373. string foldPath = dialog.SelectedPath;
  374. var apps = System.IO.Directory.GetFiles(foldPath);
  375. foreach (string app in apps)
  376. {
  377. var fi = new FileInfo(app);
  378. if (fi.Extension == ".pdf" || fi.Extension == ".PDF")
  379. {
  380. fileNames.Add(app);
  381. }
  382. }
  383. RemoveExcess(ref fileNames);
  384. updateListview("wait");
  385. SetHeaderFooterGridIsEnabled = "True";
  386. AddFileVisibility = Visibility.Collapsed;
  387. }
  388. }
  389. /// <summary>
  390. /// 更新listview显示
  391. /// state 状态显示字符串
  392. /// </summary>
  393. public void updateListview(string state)
  394. {
  395. updateCurrentListview();
  396. DataTable pdfdatatable = new DataTable();
  397. pdfdatatable.Columns.Add("FileName");
  398. pdfdatatable.Columns.Add("FilePageRangeText");
  399. pdfdatatable.Columns.Add("FilePageRangeSelectIndex");
  400. pdfdatatable.Columns.Add("IsEvenPageIsEnabled");
  401. pdfdatatable.Columns.Add("MaxPageRange");
  402. pdfdatatable.Columns.Add("FileSize");
  403. pdfdatatable.Columns.Add("FileState");
  404. int datatableindex = 0;
  405. List<int> PageIndexLists = new List<int>();
  406. foreach (var fileName in fileNames)
  407. {
  408. string file_all = fileName;
  409. FileInfo f = new FileInfo(file_all);
  410. string file_size = (((float)f.Length) / 1024).ToString() + " K";
  411. if (!isEvenPage(fileName) && PDFCurrentDataTable.Rows[datatableindex]["FilePageRangeSelectIndex"].ToString() == "2")
  412. {
  413. PDFCurrentDataTable.Rows[datatableindex]["FilePageRangeSelectIndex"] = "0";
  414. }
  415. int pagecount = CPDFDocument.InitWithFilePath(fileName).PageCount;
  416. if (PDFCurrentDataTable.Rows[datatableindex]["FilePageRangeSelectIndex"].ToString() == "3" && !CommonHelper.GetPagesInRange(ref PageIndexLists, PDFCurrentDataTable.Rows[datatableindex]["FilePageRangeText"].ToString(), pagecount, new char[] { ',' }, new char[] { '-' }, true))
  417. {
  418. PDFCurrentDataTable.Rows[datatableindex]["FilePageRangeSelectIndex"] = "0";
  419. }
  420. pdfdatatable.Rows.Add(f.Name, PDFCurrentDataTable.Rows[datatableindex]["FilePageRangeText"], PDFCurrentDataTable.Rows[datatableindex]["FilePageRangeSelectIndex"], isEvenPage(fileName), pagecount, file_size, PDFCurrentDataTable.Rows[datatableindex]["FileState"]);
  421. datatableindex++;
  422. }
  423. PDFDataTable = pdfdatatable;
  424. HomePageBatchProcessingDialogModel.FilePaths = fileNames;
  425. }
  426. /// <summary>
  427. /// 更新Currentlistview显示
  428. /// pagerangetext 自定义页面范围字符串 pagerangeselectindex combobox下拉索引(0全部页面 1奇数页 2偶数页 3自定义页面)isevenpageisenabled 偶数页状态 state 状态显示字符串
  429. /// </summary>
  430. public void updateCurrentListview(string pagerangetext = "1", string pagerangeselectindex = "0", bool isevenpageisenabled = true, string state = "wait")
  431. {
  432. if (fileNames.Count >= FileNameNumber)
  433. {
  434. for (int i = 0; fileNames.Count - FileNameNumber > i; i++)
  435. {
  436. PDFCurrentDataTable.Rows.Add(pagerangetext, pagerangeselectindex, isevenpageisenabled, state);
  437. }
  438. }
  439. else
  440. {
  441. Reverseorder(ref fileNamesView);
  442. foreach (int filenamesview in fileNamesView)
  443. {
  444. PDFCurrentDataTable.Rows.RemoveAt(filenamesview);
  445. }
  446. }
  447. }
  448. /// <summary>
  449. /// 更新Currentlistview显示
  450. /// pagerangetext 自定义页面范围字符串 pagerangeselectindex combobox下拉索引(0全部页面 1奇数页 2偶数页 3自定义页面)
  451. /// </summary>
  452. public void updateFilesPageRange(string pagerangetext = "1", string pagerangeselectindex = "0")
  453. {
  454. for (int i = 0; fileNames.Count > i; i++)
  455. {
  456. PDFDataTable.Rows[i]["FilePageRangeText"] = pagerangetext;
  457. PDFDataTable.Rows[i]["FilePageRangeSelectIndex"] = pagerangeselectindex;
  458. PDFCurrentDataTable.Rows[i]["FilePageRangeText"] = pagerangetext;
  459. PDFCurrentDataTable.Rows[i]["FilePageRangeSelectIndex"] = pagerangeselectindex;
  460. }
  461. }
  462. /// <summary>
  463. /// 获取文件列表单个文件对应的页码范围
  464. /// document 文档对象 pagerangetext 自定义页面范围字符串 pagerangeselectindex combobox下拉索引(0全部页面 1奇数页 2偶数页 3自定义页面)
  465. /// </summary>
  466. public string getFilePageRange(CPDFDocument document, string pagerangetext = "1", string pagerangeselectindex = "0")
  467. {
  468. string filePageRange = "1";
  469. EditToolsHelper.GetPageRange(int.Parse(pagerangeselectindex), document, ref filePageRange, pagerangetext);
  470. return filePageRange;
  471. }
  472. /// <summary>
  473. /// 判断是否关闭偶数页
  474. /// document 文档对象 )
  475. /// </summary>
  476. public bool isEvenPage(string filename)
  477. {
  478. CPDFDocument document = CPDFDocument.InitWithFilePath(filename);
  479. bool isevenpage = false;
  480. if (document.PageCount > 1)
  481. {
  482. isevenpage = true;
  483. }
  484. document.Release();
  485. return isevenpage;
  486. }
  487. /// <summary>
  488. /// 逆序int类型集合
  489. /// </summary>
  490. public void Reverseorder(ref List<int> Numbers)
  491. {
  492. Numbers = Numbers.OrderBy(a => a).ToList();
  493. Numbers.Reverse();
  494. }
  495. /// <summary>
  496. /// 打开文件PDF
  497. /// </summary>
  498. public void openfiledialog()
  499. {
  500. foreach (int filenamesview in fileNamesView)
  501. {
  502. System.Diagnostics.Process.Start(fileNames[filenamesview]);
  503. }
  504. }
  505. /// <summary>
  506. /// 删除文件PDF
  507. /// </summary>
  508. public void removepdffile()
  509. {
  510. FileNameNumber = fileNames.Count;
  511. Reverseorder(ref fileNamesView);
  512. foreach (int filenamesview in fileNamesView)
  513. {
  514. //Trace.WriteLine(filenamesview);
  515. fileNames.Remove(fileNames[filenamesview]);
  516. }
  517. if (fileNames.Count < 1)
  518. {
  519. SetHeaderFooterGridIsEnabled = "False";
  520. AddFileVisibility = Visibility.Visible;
  521. }
  522. updateListview("wait");
  523. }
  524. public void removepdffile(int index)
  525. {
  526. PDFCurrentDataTable.Rows.RemoveAt(index);
  527. fileNames.Remove(fileNames[index]);
  528. if (fileNames.Count < 1)
  529. {
  530. SetHeaderFooterGridIsEnabled = "False";
  531. AddFileVisibility = Visibility.Visible;
  532. }
  533. updateListview("wait");
  534. }
  535. public void PDFFileCount()
  536. {
  537. if (fileNames.Count == 0)
  538. {
  539. SetHeaderFooterGridIsEnabled = "False";
  540. AddFileVisibility = Visibility.Visible;
  541. }
  542. else
  543. {
  544. SetHeaderFooterGridIsEnabled = "True";
  545. AddFileVisibility = Visibility.Collapsed;
  546. }
  547. }
  548. #endregion
  549. #region 构架行为
  550. public void OnNavigatedTo(NavigationContext navigationContext)
  551. {
  552. List<string> filepath = new List<string>();
  553. navigationContext.Parameters.TryGetValue<ViewContentViewModel>(ParameterNames.ViewContentViewModel, out viewContentViewModel);
  554. navigationContext.Parameters.TryGetValue<CPDFViewer>(ParameterNames.PDFViewer, out PDFViewer);
  555. navigationContext.Parameters.TryGetValue<List<string>>(ParameterNames.FilePath, out filepath);
  556. if (filepath != null)
  557. {
  558. fileNames = filepath;
  559. PDFFileCount();
  560. CreateGridSpan = "1";
  561. CreateGridSpanVisibility = Visibility.Visible;
  562. updateListview("wait");
  563. EnterSelectedContent(TemplateListName);
  564. }
  565. }
  566. public bool IsNavigationTarget(NavigationContext navigationContext)
  567. {
  568. return true;
  569. }
  570. public void OnNavigatedFrom(NavigationContext navigationContext)
  571. {
  572. }
  573. #endregion
  574. }
  575. }