HomePageBatesDialogViewModel.cs 25 KB

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