HomePageSetPasswordDialogViewModel.cs 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817
  1. using ComPDFKit.PDFDocument;
  2. using PDF_Master.CustomControl;
  3. using PDF_Master.Model;
  4. using PDF_Master.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_Master.Model.Dialog.HomePageToolsDialogs.HomePageBatchProcessing.HomePageSetPasswordDialogModel;
  18. using PDF_Master.Model.Dialog.ToolsDialogs.SaftyDialogs;
  19. using PDF_Master.Helper;
  20. namespace PDF_Master.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. FolderBrowserDialog dlg = new FolderBrowserDialog();
  444. string saveSelectedPath = "";
  445. if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  446. {
  447. saveSelectedPath = dlg.SelectedPath.Trim();
  448. saveSelectedPath = saveSelectedPath + "\\";
  449. }
  450. else { return; }
  451. HomePageBatchProcessingDialogModel.closeDialog = true;
  452. SafetyGridIsEnabled = "False";
  453. string openPassword = "";
  454. string permissionsPassword = "";
  455. CPDFPermissionsInfo permissionsInfo = new CPDFPermissionsInfo();
  456. if (NeedOpenPassword)
  457. {
  458. if (!string.IsNullOrEmpty(OpenPassword))
  459. {
  460. openPassword = OpenPassword;
  461. }
  462. }
  463. if (NeedPermissionsPassword)
  464. {
  465. if (!string.IsNullOrEmpty(PermissionsPassword))
  466. {
  467. permissionsPassword = PermissionsPassword;
  468. permissionsInfo = CreatePermissionsInfo(enumPermissionsMod);
  469. }
  470. }
  471. fileNamesIndex = 0;
  472. foreach (var filename in fileNames)
  473. {
  474. PDFDataTable.Rows[fileNamesIndex]["FileState"] = "wait";
  475. CPDFDocument document = CPDFDocument.InitWithFilePath(filename);
  476. if(document == null)
  477. {
  478. PDFDataTable.Rows[fileNamesIndex]["FileState"] = "error";
  479. PDFCurrentDataTable.Rows[fileNamesIndex]["FileState"] = "error";
  480. fileNamesIndex++;
  481. continue;
  482. }
  483. if (document.IsLocked)
  484. {
  485. DialogParameters value = new DialogParameters();
  486. value.Add(ParameterNames.PDFDocument, document);
  487. dialogs.ShowDialog(DialogNames.VerifyPassWordDialog, value, e =>
  488. {
  489. if (e.Result == ButtonResult.OK)
  490. {
  491. if (e.Parameters.ContainsKey(ParameterNames.PassWord) && e.Parameters.GetValue<string>(ParameterNames.PassWord) != null)
  492. {
  493. document.UnlockWithPassword(e.Parameters.GetValue<string>(ParameterNames.PassWord).ToString());
  494. }
  495. }
  496. });
  497. if (document.IsLocked)
  498. {
  499. //未成功解密文档时,释放Document对象,返回
  500. PDFDataTable.Rows[fileNamesIndex]["FileState"] = "error";
  501. PDFCurrentDataTable.Rows[fileNamesIndex]["FileState"] = "error";
  502. fileNamesIndex++;
  503. continue;
  504. }
  505. }
  506. //FileInfo fileinfo = new FileInfo(filename);
  507. //string file_size = (((float)fileinfo.Length) / 1024).ToString() + " K";
  508. document.Encrypt(openPassword, permissionsPassword, permissionsInfo);
  509. document.WriteToFilePath(CommonHelper.CreateFilePath(saveSelectedPath + document.FileName + "SetPassword"));
  510. PDFDataTable.Rows[fileNamesIndex]["FileState"] = "complete";
  511. PDFCurrentDataTable.Rows[fileNamesIndex]["FileState"] = "complete";
  512. fileNamesIndex++;
  513. document.Release();
  514. }
  515. SafetyGridIsEnabled = "True";
  516. HomePageBatchProcessingDialogModel.closeDialog = false;
  517. }
  518. #endregion
  519. #region 批量处理逻辑函数
  520. /// <summary>
  521. /// 添加PDF文件
  522. /// </summary>
  523. private void addpdf()
  524. {
  525. FileNameNumber = fileNames.Count;
  526. System.Windows.Forms.OpenFileDialog dlg = new System.Windows.Forms.OpenFileDialog();
  527. dlg.Multiselect = true;
  528. dlg.Filter = "PDF|*.pdf;*.PDF;";
  529. if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  530. {
  531. fileNames.AddRange(dlg.FileNames.ToList());
  532. RemoveExcess(ref fileNames);
  533. SetSafetyGridIsEnabled = "True";
  534. AddFileVisibility = Visibility.Collapsed;
  535. updateListview("wait");
  536. }
  537. }
  538. public void addPDFFiles(string filename)
  539. {
  540. FileNameNumber = fileNames.Count;
  541. fileNames.Add(filename);
  542. RemoveExcess(ref fileNames);
  543. SetSafetyGridIsEnabled = "True";
  544. AddFileVisibility = Visibility.Collapsed;
  545. updateListview("wait");
  546. }
  547. /// <summary>
  548. /// 添加已打开PDF文件
  549. /// </summary>
  550. public void addOpenedPDFFiles()
  551. {
  552. FileNameNumber = fileNames.Count;
  553. foreach (var filename in App.OpenedFileList)
  554. {
  555. fileNames.Add(filename);
  556. }
  557. RemoveExcess(ref fileNames);
  558. SetSafetyGridIsEnabled = "True";
  559. AddFileVisibility = Visibility.Collapsed;
  560. updateListview("wait");
  561. }
  562. /// <summary>
  563. /// 删除重复的文件
  564. /// </summary>
  565. public void RemoveExcess(ref List<string> Filenames)
  566. {
  567. List<string> filenames = new List<string>();
  568. foreach (var fileName in Filenames)
  569. {
  570. if (!filenames.Contains(fileName))
  571. {
  572. filenames.Add(fileName);
  573. }
  574. }
  575. Filenames.Clear();
  576. Filenames = filenames;
  577. }
  578. /// <summary>
  579. /// 添加PDF文件夹
  580. /// </summary>
  581. private void addpdffiles()
  582. {
  583. FileNameNumber = fileNames.Count;
  584. FolderBrowserDialog dialog = new FolderBrowserDialog();
  585. dialog.Description = "请选择文件路径";
  586. if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  587. {
  588. string foldPath = dialog.SelectedPath;
  589. var apps = System.IO.Directory.GetFiles(foldPath);
  590. foreach (string app in apps)
  591. {
  592. var fi = new FileInfo(app);
  593. if (fi.Extension == ".pdf" || fi.Extension == ".PDF")
  594. {
  595. fileNames.Add(app);
  596. }
  597. }
  598. RemoveExcess(ref fileNames);
  599. updateListview("wait");
  600. SetSafetyGridIsEnabled = "True";
  601. AddFileVisibility = Visibility.Collapsed;
  602. }
  603. }
  604. /// <summary>
  605. /// 更新listview显示
  606. /// state 状态显示字符串
  607. /// </summary>
  608. public void updateListview(string state)
  609. {
  610. updateCurrentListview();
  611. DataTable pdfdatatable = new DataTable();
  612. pdfdatatable.Columns.Add("FileName");
  613. pdfdatatable.Columns.Add("FileSize");
  614. pdfdatatable.Columns.Add("FileState");
  615. int datatableindex = 0;
  616. foreach (var fileName in fileNames)
  617. {
  618. string file_all = fileName;
  619. FileInfo f = new FileInfo(file_all);
  620. string file_size = (((float)f.Length) / 1024).ToString() + " K";
  621. pdfdatatable.Rows.Add(f.Name, file_size, PDFCurrentDataTable.Rows[datatableindex]["FileState"]);
  622. datatableindex++;
  623. }
  624. PDFDataTable = pdfdatatable;
  625. HomePageBatchProcessingDialogModel.FilePaths = fileNames;
  626. }
  627. /// <summary>
  628. /// 更新Currentlistview显示
  629. /// state 状态显示字符串
  630. /// </summary>
  631. public void updateCurrentListview( string state = "wait")
  632. {
  633. if (fileNames.Count >= FileNameNumber)
  634. {
  635. for (int i = 0; fileNames.Count - FileNameNumber > i; i++)
  636. {
  637. PDFCurrentDataTable.Rows.Add(state);
  638. }
  639. }
  640. else
  641. {
  642. Reverseorder(ref fileNamesView);
  643. foreach (int filenamesview in fileNamesView)
  644. {
  645. PDFCurrentDataTable.Rows.RemoveAt(filenamesview);
  646. }
  647. }
  648. }
  649. /// <summary>
  650. /// 逆序int类型集合
  651. /// </summary>
  652. public void Reverseorder(ref List<int> Numbers)
  653. {
  654. Numbers = Numbers.OrderBy(a => a).ToList();
  655. Numbers.Reverse();
  656. }
  657. /// <summary>
  658. /// 打开文件PDF
  659. /// </summary>
  660. public void openfiledialog()
  661. {
  662. foreach (int filenamesview in fileNamesView)
  663. {
  664. System.Diagnostics.Process.Start("Explorer", "/select," + fileNames[filenamesview]);
  665. }
  666. }
  667. /// <summary>
  668. /// 删除文件PDF
  669. /// </summary>
  670. public void removepdffile()
  671. {
  672. FileNameNumber = fileNames.Count;
  673. Reverseorder(ref fileNamesView);
  674. foreach (int filenamesview in fileNamesView)
  675. {
  676. //Trace.WriteLine(filenamesview);
  677. fileNames.Remove(fileNames[filenamesview]);
  678. }
  679. if (fileNames.Count < 1)
  680. {
  681. SetSafetyGridIsEnabled = "False";
  682. AddFileVisibility = Visibility.Visible;
  683. }
  684. updateListview("wait");
  685. }
  686. public void removepdffile(int index)
  687. {
  688. PDFCurrentDataTable.Rows.RemoveAt(index);
  689. fileNames.Remove(fileNames[index]);
  690. if (fileNames.Count < 1)
  691. {
  692. SetSafetyGridIsEnabled = "False";
  693. AddFileVisibility = Visibility.Visible;
  694. }
  695. updateListview("wait");
  696. }
  697. public void PDFFileCount()
  698. {
  699. if (fileNames.Count == 0)
  700. {
  701. SetSafetyGridIsEnabled = "False";
  702. AddFileVisibility = Visibility.Visible;
  703. }
  704. else
  705. {
  706. SetSafetyGridIsEnabled = "True";
  707. AddFileVisibility = Visibility.Collapsed;
  708. }
  709. }
  710. #endregion
  711. public void OnNavigatedTo(NavigationContext navigationContext)
  712. {
  713. List<string> filepath = new List<string>();
  714. navigationContext.Parameters.TryGetValue<List<string>>(ParameterNames.FilePath, out filepath);
  715. if (filepath != null)
  716. {
  717. fileNames = filepath;
  718. PDFFileCount();
  719. updateListview("wait");
  720. }
  721. }
  722. public bool IsNavigationTarget(NavigationContext navigationContext)
  723. {
  724. return true;
  725. }
  726. public void OnNavigatedFrom(NavigationContext navigationContext)
  727. {
  728. }
  729. }
  730. }