HomePageSetPasswordDialogViewModel.cs 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809
  1. using ComPDFKit.PDFDocument;
  2. using PDF_Office.CustomControl;
  3. using PDF_Office.Model;
  4. using PDF_Office.Model.Dialog.HomePageToolsDialogs.HomePageBatchProcessing;
  5. using Prism.Commands;
  6. using Prism.Mvvm;
  7. using Prism.Regions;
  8. using Prism.Services.Dialogs;
  9. using System.Collections.Generic;
  10. using System.Data;
  11. using System.IO;
  12. using System.Linq;
  13. using System.Windows;
  14. using System.Windows.Forms;
  15. using CheckBox = System.Windows.Controls.CheckBox;
  16. using DialogResult = Prism.Services.Dialogs.DialogResult;
  17. using static PDF_Office.Model.Dialog.HomePageToolsDialogs.HomePageBatchProcessing.HomePageSetPasswordDialogModel;
  18. using PDF_Office.Model.Dialog.ToolsDialogs.SaftyDialogs;
  19. using PDF_Office.Helper;
  20. namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs.HomePageBatchProcessing
  21. {
  22. public class HomePageSetPasswordDialogViewModel : BindableBase, INavigationAware
  23. {
  24. #region 参数和属性
  25. private List<string> fileNames;
  26. public IDialogService dialogs;
  27. private int fileNamesIndex = 0;
  28. private int FileNameNumber = 0;
  29. private HomePageSetPasswordDialogModel setPasswordDialogModel = new HomePageSetPasswordDialogModel();
  30. public List<int> fileNamesView = new List<int>();
  31. private bool _canOpen;
  32. public bool CanOpen
  33. {
  34. get { return _canOpen; }
  35. set
  36. {
  37. _canOpen = value;
  38. RaisePropertyChanged("isChecked");
  39. }
  40. }
  41. private bool _canEdit;
  42. public bool CanEdit
  43. {
  44. get { return _canEdit; }
  45. set
  46. {
  47. _canEdit = value;
  48. RaisePropertyChanged("isChecked");
  49. }
  50. }
  51. private EnumPermissionsMod enumPermissionsMod = EnumPermissionsMod.StatusUnknown | EnumPermissionsMod.StatusRestrictPrinting | EnumPermissionsMod.StatusRestrictCopying;
  52. private string _changeMod = "0";
  53. ///<value>
  54. ///"0"为ChangeMod.None;
  55. ///"1"为ChangeMod.ChangePage;
  56. ///"2"为ChangeMod.FormAndSignature;
  57. ///"3"为ChangeMod.AnnotAndFormAndSignature;
  58. ///"4"为ChangeMod.ExceptAbstrat;
  59. ///</value>
  60. public string ChangeMod
  61. {
  62. get { return _changeMod; }
  63. set
  64. {
  65. _changeMod = value;
  66. }
  67. }
  68. private string _printMod = "0";
  69. ///<value>
  70. ///"0"为PrintMod.None;
  71. ///"1"为PrintMod.LowDpi;
  72. ///"2"为PrintMod.HighDpi;
  73. ///</value>
  74. public string PrintMod
  75. {
  76. get { return _printMod; }
  77. set
  78. {
  79. _printMod = value;
  80. }
  81. }
  82. private string _isEnableConfirm = "False";
  83. public string IsEnabledConfirm
  84. {
  85. get { return _isEnableConfirm; }
  86. set
  87. {
  88. SetProperty(ref _isEnableConfirm, value);
  89. }
  90. }
  91. private bool _enableConfirm = false;
  92. public bool EnableConfirm
  93. {
  94. get { return _enableConfirm; }
  95. set { SetProperty(ref _enableConfirm, value); }
  96. }
  97. private string _openPassword = "";
  98. public string OpenPassword
  99. {
  100. get { return _openPassword; }
  101. set
  102. {
  103. SetProperty(ref _openPassword, value);
  104. CheckEnableConfirmEncrypt();
  105. }
  106. }
  107. private string _permissionsPassword = "";
  108. public string PermissionsPassword
  109. {
  110. get { return _permissionsPassword; }
  111. set
  112. {
  113. SetProperty(ref _permissionsPassword, value);
  114. CheckEnableConfirmEncrypt();
  115. }
  116. }
  117. private string _openPasswordMsg = "Open Password";
  118. public string OpenPasswordMsg
  119. {
  120. get { return _openPasswordMsg; }
  121. set
  122. {
  123. SetProperty(ref _openPasswordMsg, value);
  124. }
  125. }
  126. private string _permissionsPasswordMsg = "Permission Password";
  127. public string PermissionsPasswordMsg
  128. {
  129. get { return _permissionsPasswordMsg; }
  130. set
  131. {
  132. SetProperty(ref _permissionsPasswordMsg, value);
  133. }
  134. }
  135. private string safetyGridIsEnabled = "True";
  136. public string SafetyGridIsEnabled
  137. {
  138. get
  139. {
  140. return safetyGridIsEnabled;
  141. }
  142. set
  143. {
  144. SetProperty(ref safetyGridIsEnabled, value);
  145. }
  146. }
  147. private string setSafetyGridIsEnabled = "True";
  148. public string SetSafetyGridIsEnabled
  149. {
  150. get
  151. {
  152. return setSafetyGridIsEnabled;
  153. }
  154. set
  155. {
  156. SetProperty(ref setSafetyGridIsEnabled, value);
  157. }
  158. }
  159. private Visibility _openTextVisibility = Visibility.Collapsed;
  160. public Visibility OpenTextVisibility
  161. {
  162. get { return _openTextVisibility; }
  163. set
  164. {
  165. SetProperty(ref _openTextVisibility, value);
  166. }
  167. }
  168. private Visibility _openPasswordVisibility = Visibility.Visible;
  169. public Visibility OpenPasswordVisibility
  170. {
  171. get { return _openPasswordVisibility; }
  172. set
  173. {
  174. if (value == Visibility.Visible)
  175. {
  176. OpenTextVisibility = Visibility.Collapsed;
  177. }
  178. else
  179. {
  180. OpenTextVisibility = Visibility.Visible;
  181. }
  182. SetProperty(ref _openPasswordVisibility, value);
  183. }
  184. }
  185. private Visibility _permissionsPasswordVisibility = Visibility.Visible;
  186. public Visibility PermissionsPasswordVisibility
  187. {
  188. get { return _permissionsPasswordVisibility; }
  189. set
  190. {
  191. if (value == Visibility.Visible)
  192. {
  193. PermissionsTextVisibility = Visibility.Collapsed;
  194. }
  195. else
  196. {
  197. PermissionsTextVisibility = Visibility.Visible;
  198. }
  199. SetProperty(ref _permissionsPasswordVisibility, value);
  200. }
  201. }
  202. private Visibility _permissionsTextVisibility = Visibility.Collapsed;
  203. public Visibility PermissionsTextVisibility
  204. {
  205. get { return _permissionsTextVisibility; }
  206. set { SetProperty(ref _permissionsTextVisibility, value); }
  207. }
  208. private bool? _isRestrictPrinting;
  209. public bool? IsRestrictPrinting
  210. {
  211. get { return _isRestrictPrinting; }
  212. set { SetProperty(ref _isRestrictPrinting, value); }
  213. }
  214. private bool? _isRestrictCopying;
  215. public bool? IsRestrictCopying
  216. {
  217. get { return _isRestrictCopying; }
  218. set { SetProperty(ref _isRestrictCopying, value); }
  219. }
  220. private bool _needOpenPassword;
  221. public bool NeedOpenPassword
  222. {
  223. get { return _needOpenPassword; }
  224. set { SetProperty(ref _needOpenPassword, value); }
  225. }
  226. private bool _needPermissionsPassword;
  227. public bool NeedPermissionsPassword
  228. {
  229. get { return _needPermissionsPassword; }
  230. set { SetProperty(ref _needPermissionsPassword, value); }
  231. }
  232. private bool _isOpenPasswordDisplayed;
  233. public bool IsOpenPasswordDisplayed
  234. {
  235. get { return _isOpenPasswordDisplayed; }
  236. set { SetProperty(ref _isOpenPasswordDisplayed, value); }
  237. }
  238. private bool _isPermissionsPasswordDisplayed;
  239. public bool IsPermissionsPasswordDisplayed
  240. {
  241. get { return _isPermissionsPasswordDisplayed; }
  242. set { SetProperty(ref _isPermissionsPasswordDisplayed, value); }
  243. }
  244. private DataTable pdfDataTable = new DataTable();
  245. public DataTable PDFDataTable
  246. {
  247. get { return pdfDataTable; }
  248. set
  249. {
  250. SetProperty(ref pdfDataTable, value);
  251. }
  252. }
  253. private DataTable pdfCurrentDataTable = new DataTable();
  254. public DataTable PDFCurrentDataTable
  255. {
  256. get { return pdfCurrentDataTable; }
  257. set
  258. {
  259. SetProperty(ref pdfCurrentDataTable, value);
  260. }
  261. }
  262. private string removeIsEnable = "False";
  263. public string RemoveIsEnable
  264. {
  265. get { return removeIsEnable; }
  266. set
  267. {
  268. SetProperty(ref removeIsEnable, value);
  269. }
  270. }
  271. private string selectFileName = "False";
  272. public string SelectFileName
  273. {
  274. get { return selectFileName; }
  275. set
  276. {
  277. SetProperty(ref selectFileName, value);
  278. }
  279. }
  280. private Visibility addFileVisibility = Visibility.Hidden;
  281. public Visibility AddFileVisibility
  282. {
  283. get { return addFileVisibility; }
  284. set
  285. {
  286. SetProperty(ref addFileVisibility, value);
  287. RaisePropertyChanged();
  288. }
  289. }
  290. #endregion
  291. #region 委托声明
  292. public DelegateCommand<object> DisplayPasswordCommand { get; set; }
  293. public DelegateCommand<object> SetOpenPasswordCommand { get; set; }
  294. public DelegateCommand<object> SetPermissionsPasswordCommand { get; set; }
  295. public DelegateCommand<object> SetRestrictCommand { get; set; }
  296. public DelegateCommand EncryptCommand { get; set; }
  297. public DelegateCommand DelegateSetOpenCommand { get; set; }
  298. public DelegateCommand DelegateSetEditCommand { get; set; }
  299. public DelegateCommand DelegateCanOpenTextChangedCommand { get; set; }
  300. public DelegateCommand DelegateCanEditTextChangedCommand { get; set; }
  301. public DelegateCommand DelegateConfirmEncryptCommand { get; set; }
  302. public DelegateCommand CancelEncryptCommand { get; set; }
  303. public DelegateCommand DelegateCancelEncryptCommand { get; set; }
  304. public DelegateCommand ADDPDFCommand { get; set; }
  305. public DelegateCommand ADDOpenedPDFCommand { get; set; }
  306. public DelegateCommand RemovePDFFileCommand { get; set; }
  307. public DelegateCommand ADDPDFFilesCommand { get; set; }
  308. #endregion
  309. public HomePageSetPasswordDialogViewModel(IDialogService dialogs)
  310. {
  311. PDFCurrentDataTable.Columns.Add("FileState");
  312. PDFDataTable.Columns.Add("FileName");
  313. PDFDataTable.Columns.Add("FileSize");
  314. PDFDataTable.Columns.Add("FileState");
  315. HomePageSetPasswordDialogModel.PasswordForOpen = "";
  316. HomePageSetPasswordDialogModel.PasswordForEdit = "";
  317. DisplayPasswordCommand = new DelegateCommand<object>(DisplayPassword);
  318. SetOpenPasswordCommand = new DelegateCommand<object>(SetOpenPassword);
  319. SetPermissionsPasswordCommand = new DelegateCommand<object>(SetPermissionsPassword);
  320. SetRestrictCommand = new DelegateCommand<object>(SetRestrict);
  321. EncryptCommand = new DelegateCommand(ConfirmEncrypt);
  322. DelegateConfirmEncryptCommand = new DelegateCommand(ConfirmEncrypt);
  323. ADDPDFCommand = new DelegateCommand(addpdf);
  324. ADDOpenedPDFCommand = new DelegateCommand(addOpenedPDFFiles);
  325. ADDPDFFilesCommand = new DelegateCommand(addpdffiles);
  326. RemovePDFFileCommand = new DelegateCommand(removepdffile);
  327. this.dialogs = dialogs;
  328. }
  329. #region 检查和初始化
  330. private void CheckEnableConfirmEncrypt()
  331. {
  332. EnableConfirm = true;
  333. if (!(NeedOpenPassword || NeedPermissionsPassword))
  334. {
  335. EnableConfirm = false;
  336. }
  337. if (NeedOpenPassword && string.IsNullOrEmpty(OpenPassword))
  338. {
  339. EnableConfirm = false;
  340. }
  341. if (NeedPermissionsPassword && string.IsNullOrEmpty(PermissionsPassword))
  342. {
  343. EnableConfirm = false;
  344. }
  345. if (NeedPermissionsPassword && (!((bool)IsRestrictCopying || (bool)IsRestrictPrinting)))
  346. {
  347. EnableConfirm = false;
  348. }
  349. }
  350. #endregion
  351. #region 逻辑函数
  352. public void DisplayPassword(object e)
  353. {
  354. var chk = e as CheckBox;
  355. if (chk != null)
  356. {
  357. if (chk.Name == "DisplayOpenPasswordChk")
  358. {
  359. if (chk.IsChecked == true)
  360. {
  361. OpenPasswordVisibility = Visibility.Collapsed;
  362. }
  363. else
  364. {
  365. OpenPasswordVisibility = Visibility.Visible;
  366. }
  367. }
  368. else
  369. {
  370. if (chk.IsChecked == true)
  371. {
  372. PermissionsPasswordVisibility = Visibility.Collapsed;
  373. }
  374. else
  375. {
  376. PermissionsPasswordVisibility = Visibility.Visible;
  377. }
  378. }
  379. }
  380. }
  381. public void SetOpenPassword(object e)
  382. {
  383. var chk = e as CheckBox;
  384. if (chk != null)
  385. {
  386. IsOpenPasswordDisplayed = false;
  387. OpenPasswordVisibility = Visibility.Visible;
  388. }
  389. CheckEnableConfirmEncrypt();
  390. }
  391. public void SetPermissionsPassword(object e)
  392. {
  393. var chk = e as CheckBox;
  394. if (chk != null)
  395. {
  396. IsPermissionsPasswordDisplayed = false;
  397. PermissionsPasswordVisibility = Visibility.Visible;
  398. if (chk.IsChecked == true)
  399. {
  400. IsRestrictPrinting = true;
  401. IsRestrictCopying = true;
  402. }
  403. else
  404. {
  405. IsRestrictPrinting = false;
  406. IsRestrictCopying = false;
  407. }
  408. }
  409. CheckEnableConfirmEncrypt();
  410. }
  411. public void SetRestrict(object e)
  412. {
  413. var chk = e as CheckBox;
  414. if (chk != null)
  415. {
  416. if ((bool)chk.IsChecked)
  417. {
  418. if (chk.Tag.ToString() == "Printing")
  419. {
  420. enumPermissionsMod |= EnumPermissionsMod.StatusRestrictPrinting;
  421. }
  422. else if (chk.Tag.ToString() == "Copying")
  423. {
  424. enumPermissionsMod |= EnumPermissionsMod.StatusRestrictCopying;
  425. }
  426. }
  427. else
  428. {
  429. if (chk.Tag.ToString() == "Printing")
  430. {
  431. enumPermissionsMod -= EnumPermissionsMod.StatusRestrictPrinting;
  432. }
  433. else if (chk.Tag.ToString() == "Copying")
  434. {
  435. enumPermissionsMod -= EnumPermissionsMod.StatusRestrictCopying;
  436. }
  437. }
  438. }
  439. CheckEnableConfirmEncrypt();
  440. }
  441. public void ConfirmEncrypt()
  442. {
  443. HomePageBatchProcessingDialogModel.closeDialog = true;
  444. SafetyGridIsEnabled = "False";
  445. string openPassword = "";
  446. string permissionsPassword = "";
  447. CPDFPermissionsInfo permissionsInfo = new CPDFPermissionsInfo();
  448. if (NeedOpenPassword)
  449. {
  450. if (!string.IsNullOrEmpty(OpenPassword))
  451. {
  452. openPassword = OpenPassword;
  453. }
  454. }
  455. if (NeedPermissionsPassword)
  456. {
  457. if (!string.IsNullOrEmpty(PermissionsPassword))
  458. {
  459. permissionsPassword = PermissionsPassword;
  460. permissionsInfo = CreatePermissionsInfo(enumPermissionsMod);
  461. }
  462. }
  463. fileNamesIndex = 0;
  464. foreach (var filename in fileNames)
  465. {
  466. PDFDataTable.Rows[fileNamesIndex]["FileState"] = "wait";
  467. CPDFDocument document = CPDFDocument.InitWithFilePath(filename);
  468. if(document == null)
  469. {
  470. PDFDataTable.Rows[fileNamesIndex]["FileState"] = "error";
  471. PDFCurrentDataTable.Rows[fileNamesIndex]["FileState"] = "error";
  472. fileNamesIndex++;
  473. continue;
  474. }
  475. if (document.IsLocked)
  476. {
  477. DialogParameters value = new DialogParameters();
  478. value.Add(ParameterNames.PDFDocument, document);
  479. dialogs.ShowDialog(DialogNames.VerifyPassWordDialog, value, e =>
  480. {
  481. if (e.Result == ButtonResult.OK)
  482. {
  483. if (e.Parameters.ContainsKey(ParameterNames.PassWord) && e.Parameters.GetValue<string>(ParameterNames.PassWord) != null)
  484. {
  485. document.UnlockWithPassword(e.Parameters.GetValue<string>(ParameterNames.PassWord).ToString());
  486. }
  487. }
  488. });
  489. if (document.IsLocked)
  490. {
  491. //未成功解密文档时,释放Document对象,返回
  492. PDFDataTable.Rows[fileNamesIndex]["FileState"] = "error";
  493. PDFCurrentDataTable.Rows[fileNamesIndex]["FileState"] = "error";
  494. fileNamesIndex++;
  495. continue;
  496. }
  497. }
  498. //FileInfo fileinfo = new FileInfo(filename);
  499. //string file_size = (((float)fileinfo.Length) / 1024).ToString() + " K";
  500. document.Encrypt(openPassword, permissionsPassword, permissionsInfo);
  501. document.WriteToFilePath(CommonHelper.CreateFilePath(filename + "SetPassword"));
  502. PDFDataTable.Rows[fileNamesIndex]["FileState"] = "complete";
  503. PDFCurrentDataTable.Rows[fileNamesIndex]["FileState"] = "complete";
  504. fileNamesIndex++;
  505. document.Release();
  506. }
  507. SafetyGridIsEnabled = "True";
  508. HomePageBatchProcessingDialogModel.closeDialog = false;
  509. }
  510. #endregion
  511. #region 批量处理逻辑函数
  512. /// <summary>
  513. /// 添加PDF文件
  514. /// </summary>
  515. private void addpdf()
  516. {
  517. FileNameNumber = fileNames.Count;
  518. System.Windows.Forms.OpenFileDialog dlg = new System.Windows.Forms.OpenFileDialog();
  519. dlg.Multiselect = true;
  520. dlg.Filter = "PDF|*.pdf;*.PDF;";
  521. if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  522. {
  523. fileNames.AddRange(dlg.FileNames.ToList());
  524. RemoveExcess(ref fileNames);
  525. SetSafetyGridIsEnabled = "True";
  526. AddFileVisibility = Visibility.Collapsed;
  527. updateListview("wait");
  528. }
  529. }
  530. public void addPDFFiles(string filename)
  531. {
  532. FileNameNumber = fileNames.Count;
  533. fileNames.Add(filename);
  534. RemoveExcess(ref fileNames);
  535. SetSafetyGridIsEnabled = "True";
  536. AddFileVisibility = Visibility.Collapsed;
  537. updateListview("wait");
  538. }
  539. /// <summary>
  540. /// 添加已打开PDF文件
  541. /// </summary>
  542. public void addOpenedPDFFiles()
  543. {
  544. FileNameNumber = fileNames.Count;
  545. foreach (var filename in App.OpenedFileList)
  546. {
  547. fileNames.Add(filename);
  548. }
  549. RemoveExcess(ref fileNames);
  550. SetSafetyGridIsEnabled = "True";
  551. AddFileVisibility = Visibility.Collapsed;
  552. updateListview("wait");
  553. }
  554. /// <summary>
  555. /// 删除重复的文件
  556. /// </summary>
  557. public void RemoveExcess(ref List<string> Filenames)
  558. {
  559. List<string> filenames = new List<string>();
  560. foreach (var fileName in Filenames)
  561. {
  562. if (!filenames.Contains(fileName))
  563. {
  564. filenames.Add(fileName);
  565. }
  566. }
  567. Filenames.Clear();
  568. Filenames = filenames;
  569. }
  570. /// <summary>
  571. /// 添加PDF文件夹
  572. /// </summary>
  573. private void addpdffiles()
  574. {
  575. FileNameNumber = fileNames.Count;
  576. FolderBrowserDialog dialog = new FolderBrowserDialog();
  577. dialog.Description = "请选择文件路径";
  578. if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  579. {
  580. string foldPath = dialog.SelectedPath;
  581. var apps = System.IO.Directory.GetFiles(foldPath);
  582. foreach (string app in apps)
  583. {
  584. var fi = new FileInfo(app);
  585. if (fi.Extension == ".pdf" || fi.Extension == ".PDF")
  586. {
  587. fileNames.Add(app);
  588. }
  589. }
  590. RemoveExcess(ref fileNames);
  591. updateListview("wait");
  592. SetSafetyGridIsEnabled = "True";
  593. AddFileVisibility = Visibility.Collapsed;
  594. }
  595. }
  596. /// <summary>
  597. /// 更新listview显示
  598. /// state 状态显示字符串
  599. /// </summary>
  600. public void updateListview(string state)
  601. {
  602. updateCurrentListview();
  603. DataTable pdfdatatable = new DataTable();
  604. pdfdatatable.Columns.Add("FileName");
  605. pdfdatatable.Columns.Add("FileSize");
  606. pdfdatatable.Columns.Add("FileState");
  607. int datatableindex = 0;
  608. foreach (var fileName in fileNames)
  609. {
  610. string file_all = fileName;
  611. FileInfo f = new FileInfo(file_all);
  612. string file_size = (((float)f.Length) / 1024).ToString() + " K";
  613. pdfdatatable.Rows.Add(f.Name, file_size, PDFCurrentDataTable.Rows[datatableindex]["FileState"]);
  614. datatableindex++;
  615. }
  616. PDFDataTable = pdfdatatable;
  617. HomePageBatchProcessingDialogModel.FilePaths = fileNames;
  618. }
  619. /// <summary>
  620. /// 更新Currentlistview显示
  621. /// state 状态显示字符串
  622. /// </summary>
  623. public void updateCurrentListview( string state = "wait")
  624. {
  625. if (fileNames.Count >= FileNameNumber)
  626. {
  627. for (int i = 0; fileNames.Count - FileNameNumber > i; i++)
  628. {
  629. PDFCurrentDataTable.Rows.Add(state);
  630. }
  631. }
  632. else
  633. {
  634. Reverseorder(ref fileNamesView);
  635. foreach (int filenamesview in fileNamesView)
  636. {
  637. PDFCurrentDataTable.Rows.RemoveAt(filenamesview);
  638. }
  639. }
  640. }
  641. /// <summary>
  642. /// 逆序int类型集合
  643. /// </summary>
  644. public void Reverseorder(ref List<int> Numbers)
  645. {
  646. Numbers = Numbers.OrderBy(a => a).ToList();
  647. Numbers.Reverse();
  648. }
  649. /// <summary>
  650. /// 打开文件PDF
  651. /// </summary>
  652. public void openfiledialog()
  653. {
  654. foreach (int filenamesview in fileNamesView)
  655. {
  656. System.Diagnostics.Process.Start(fileNames[filenamesview]);
  657. }
  658. }
  659. /// <summary>
  660. /// 删除文件PDF
  661. /// </summary>
  662. public void removepdffile()
  663. {
  664. FileNameNumber = fileNames.Count;
  665. Reverseorder(ref fileNamesView);
  666. foreach (int filenamesview in fileNamesView)
  667. {
  668. //Trace.WriteLine(filenamesview);
  669. fileNames.Remove(fileNames[filenamesview]);
  670. }
  671. if (fileNames.Count < 1)
  672. {
  673. SetSafetyGridIsEnabled = "False";
  674. AddFileVisibility = Visibility.Visible;
  675. }
  676. updateListview("wait");
  677. }
  678. public void removepdffile(int index)
  679. {
  680. PDFCurrentDataTable.Rows.RemoveAt(index);
  681. fileNames.Remove(fileNames[index]);
  682. if (fileNames.Count < 1)
  683. {
  684. SetSafetyGridIsEnabled = "False";
  685. AddFileVisibility = Visibility.Visible;
  686. }
  687. updateListview("wait");
  688. }
  689. public void PDFFileCount()
  690. {
  691. if (fileNames.Count == 0)
  692. {
  693. SetSafetyGridIsEnabled = "False";
  694. AddFileVisibility = Visibility.Visible;
  695. }
  696. else
  697. {
  698. SetSafetyGridIsEnabled = "True";
  699. AddFileVisibility = Visibility.Collapsed;
  700. }
  701. }
  702. #endregion
  703. public void OnNavigatedTo(NavigationContext navigationContext)
  704. {
  705. List<string> filepath = new List<string>();
  706. navigationContext.Parameters.TryGetValue<List<string>>(ParameterNames.FilePath, out filepath);
  707. if (filepath != null)
  708. {
  709. fileNames = filepath;
  710. PDFFileCount();
  711. updateListview("wait");
  712. }
  713. }
  714. public bool IsNavigationTarget(NavigationContext navigationContext)
  715. {
  716. return true;
  717. }
  718. public void OnNavigatedFrom(NavigationContext navigationContext)
  719. {
  720. }
  721. }
  722. }