HomePageBatesDialogViewModel.cs 25 KB

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