HomePageBackgroundDialogViewModel.cs 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751
  1. using Prism.Commands;
  2. using Prism.Mvvm;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Data;
  7. using System.Windows;
  8. using PDF_Master.Helper;
  9. using Prism.Regions;
  10. using ComPDFKit.PDFDocument;
  11. using PDF_Master.CustomControl;
  12. using PDF_Master.Model.Dialog.HomePageToolsDialogs.HomePageBatchProcessing;
  13. using PDF_Master.Model;
  14. using System.Diagnostics;
  15. using System.IO;
  16. using System.Windows.Forms;
  17. using Prism.Events;
  18. using ComPDFKitViewer.PdfViewer;
  19. using PDF_Master.EventAggregators;
  20. using PDFSettings;
  21. using PDF_Master.Model.EditTools.Bates;
  22. using PDF_Master.Model.EditTools.Background;
  23. using static System.Windows.Forms.VisualStyles.VisualStyleElement.TrayNotify;
  24. using Prism.Services.Dialogs;
  25. namespace PDF_Master.ViewModels.Dialog.HomePageToolsDialogs.HomePageBatchProcessing.HomePageBackground
  26. {
  27. public class HomePageBackgroundDialogViewModel : BindableBase, INavigationAware
  28. {
  29. #region 参数和属性
  30. private List<string> fileNames;
  31. public BackgroundInfo BackgroundInfo;
  32. public string PageNumber = "";
  33. private CPDFBackground background;
  34. public IRegionManager backgroundRegion;
  35. public IEventAggregator eventAggregator;
  36. public IDialogService dialogs;
  37. private CPDFViewer PDFViewer;
  38. private ViewContentViewModel viewContentViewModel;
  39. public string TemplateListBaseName = "HomePageBackgroundTemplateListBaseContent";
  40. public string CreateBaseName = "HomePageBackgroundCreateBaseContent";
  41. public string CreateModColorName = "HomePageBackgroundCreateColorContent";
  42. public string CreateModFileName = "HomePageBackgroundCreateFileContent";
  43. public string TemplateListModColorName = "HomePageBackgroundTemplateListColorContent";
  44. public string TemplateListModFileName = "HomePageBackgroundTemplateListFileContent";
  45. private string _backgroundSettingsRegionName;
  46. /// <summary>
  47. /// 属性设置Region
  48. /// </summary>
  49. public string BackgroundSettingsRegionName
  50. {
  51. get { return _backgroundSettingsRegionName; }
  52. set { _backgroundSettingsRegionName = value; }
  53. }
  54. private Visibility _backgroundSettingsVisible = Visibility.Collapsed;
  55. /// <summary>
  56. /// 属性设置Region可见
  57. /// </summary>
  58. public Visibility BackgroundSettingsVisible
  59. {
  60. get { return _backgroundSettingsVisible; }
  61. set { _backgroundSettingsVisible = value; }
  62. }
  63. private EnumColorOrFile _currentCreateMod;
  64. public EnumColorOrFile CurrentCreateMod
  65. {
  66. get { return _currentCreateMod; }
  67. set { _currentCreateMod = value; }
  68. }
  69. private EnumColorOrFile _currentTemplateListMod;
  70. public EnumColorOrFile CurrentTemplateListMod
  71. {
  72. get { return _currentTemplateListMod; }
  73. set { _currentTemplateListMod = value; }
  74. }
  75. public List<int> fileNamesView = new List<int>();
  76. private int fileNamesIndex = 0;
  77. private int FileNameNumber = 0;
  78. private string backgroundGridIsEnabled = "True";
  79. public string BackgroundGridIsEnabled
  80. {
  81. get
  82. {
  83. return backgroundGridIsEnabled;
  84. }
  85. set
  86. {
  87. SetProperty(ref backgroundGridIsEnabled, value);
  88. }
  89. }
  90. private string setBackgroundGridIsEnabled = "True";
  91. public string SetBackgroundGridIsEnabled
  92. {
  93. get
  94. {
  95. return setBackgroundGridIsEnabled;
  96. }
  97. set
  98. {
  99. SetProperty(ref setBackgroundGridIsEnabled, value);
  100. }
  101. }
  102. private DataTable pdfDataTable = new DataTable();
  103. public DataTable PDFDataTable
  104. {
  105. get { return pdfDataTable; }
  106. set
  107. {
  108. SetProperty(ref pdfDataTable, value);
  109. }
  110. }
  111. private DataTable pdfCurrentDataTable = new DataTable();
  112. public DataTable PDFCurrentDataTable
  113. {
  114. get { return pdfCurrentDataTable; }
  115. set
  116. {
  117. SetProperty(ref pdfCurrentDataTable, value);
  118. }
  119. }
  120. private string removeIsEnable = "False";
  121. public string RemoveIsEnable
  122. {
  123. get { return removeIsEnable; }
  124. set
  125. {
  126. SetProperty(ref removeIsEnable, value);
  127. }
  128. }
  129. private string selectFileName = "False";
  130. public string SelectFileName
  131. {
  132. get { return selectFileName; }
  133. set
  134. {
  135. SetProperty(ref selectFileName, value);
  136. }
  137. }
  138. private string backgroundRegionName;
  139. public string BackgroundRegionName
  140. {
  141. get
  142. {
  143. return backgroundRegionName;
  144. }
  145. set
  146. {
  147. SetProperty(ref backgroundRegionName, value);
  148. }
  149. }
  150. private Visibility backgroundVisible = Visibility.Collapsed;
  151. public Visibility BackgroundVisible
  152. {
  153. get { return backgroundVisible; }
  154. set { SetProperty(ref backgroundVisible, value); }
  155. }
  156. private Visibility addFileVisibility = Visibility.Hidden;
  157. public Visibility AddFileVisibility
  158. {
  159. get { return addFileVisibility; }
  160. set
  161. {
  162. SetProperty(ref addFileVisibility, value);
  163. RaisePropertyChanged();
  164. }
  165. }
  166. private string createGridSpan = "1";
  167. public string CreateGridSpan
  168. {
  169. get { return createGridSpan; }
  170. set
  171. {
  172. SetProperty(ref createGridSpan, value);
  173. RaisePropertyChanged();
  174. }
  175. }
  176. private Visibility createGridSpanVisibility = Visibility.Visible;
  177. public Visibility CreateGridSpanVisibility
  178. {
  179. get { return createGridSpanVisibility; }
  180. set
  181. {
  182. SetProperty(ref createGridSpanVisibility, value);
  183. RaisePropertyChanged();
  184. }
  185. }
  186. private bool _createBtnIsEnabled = false;
  187. public bool CreateBtnIsEnabled
  188. {
  189. get { return _createBtnIsEnabled; }
  190. set { SetProperty(ref _createBtnIsEnabled, value); }
  191. }
  192. #endregion
  193. #region 委托声明
  194. public DelegateCommand ADDPDFCommand { get; set; }
  195. public DelegateCommand ADDOpenedPDFCommand { get; set; }
  196. public DelegateCommand RemovePDFFileCommand { get; set; }
  197. public DelegateCommand CreateCommand { get; set; }
  198. public DelegateCommand ADDPDFFilesCommand { get; set; }
  199. #endregion
  200. public string Unicode = null;
  201. public HomePageBackgroundDialogViewModel(IRegionManager backgroundRegion, IEventAggregator eventAggregator, IDialogService dialogs)
  202. {
  203. this.eventAggregator = eventAggregator;
  204. this.backgroundRegion = backgroundRegion;
  205. this.dialogs = dialogs;
  206. PDFCurrentDataTable.Columns.Add("FilePageRangeText");
  207. PDFCurrentDataTable.Columns.Add("FilePageRangeSelectIndex");
  208. PDFCurrentDataTable.Columns.Add("IsEvenPageIsEnabled");
  209. PDFCurrentDataTable.Columns.Add("FileState");
  210. PDFDataTable.Columns.Add("FileName");
  211. PDFDataTable.Columns.Add("FilePageRangeText");
  212. PDFDataTable.Columns.Add("FilePageRangeSelectIndex");
  213. PDFDataTable.Columns.Add("IsEvenPageIsEnabled");
  214. PDFDataTable.Columns.Add("MaxPageRange");
  215. PDFDataTable.Columns.Add("FileSize");
  216. PDFDataTable.Columns.Add("FileState");
  217. Unicode = Guid.NewGuid().ToString();
  218. BackgroundSettingsVisible = Visibility.Visible;
  219. ADDPDFCommand = new DelegateCommand(addpicture);
  220. ADDOpenedPDFCommand = new DelegateCommand(addOpenedPDFFiles);
  221. ADDPDFFilesCommand = new DelegateCommand(addpicturefiles);
  222. RemovePDFFileCommand = new DelegateCommand(removepdffile);
  223. CreateCommand = new DelegateCommand(create);
  224. BackgroundSettingsRegionName = Guid.NewGuid().ToString();
  225. eventAggregator.GetEvent<EnterTemplateListOrCreateEvent>().Subscribe(EnterTemplateListOrCreate, e => e.Unicode == Unicode);
  226. eventAggregator.GetEvent<SetCurrentCreateModEvent>().Subscribe(SetCurrentCreateMod, e => e.Unicode == Unicode);
  227. eventAggregator.GetEvent<SetCurrentTemplateListModEvent>().Subscribe(SetCurrentTemplateListMod, e => e.Unicode == Unicode);
  228. eventAggregator.GetEvent<EditBackgroundTemplateItemEvent>().Subscribe(EditBackgroundTemplateItem, e => e.Unicode == Unicode);
  229. }
  230. #region 逻辑函数
  231. public void EnterTemplateListOrCreate(EnumTemplateListOrCreateUnicode enumTemplateListOrCreateunicode)
  232. {
  233. EnumTemplateListOrCreate enumTemplateListOrCreate = enumTemplateListOrCreateunicode.Status;
  234. if (enumTemplateListOrCreate == EnumTemplateListOrCreate.StatusTemplate)
  235. {
  236. CreateGridSpan = "1";
  237. CreateGridSpanVisibility = Visibility.Visible;
  238. EnterSelectedContent(TemplateListBaseName);
  239. }
  240. else
  241. {
  242. CreateGridSpan = "2";
  243. CreateGridSpanVisibility = Visibility.Collapsed;
  244. EnterSelectedContent(CreateBaseName);
  245. }
  246. }
  247. public void EnterSelectedContent(string SelectedContentName)
  248. {
  249. NavigationParameters param = new NavigationParameters();
  250. param.Add(ParameterNames.PDFViewer, PDFViewer);
  251. param.Add("Unicode", Unicode);
  252. param.Add("ViewModel", this);
  253. if (SelectedContentName == TemplateListBaseName)
  254. {
  255. param.Add("CurrentCreateModName", CurrentCreateMod);
  256. }
  257. else if (SelectedContentName == CreateBaseName)
  258. {
  259. param.Add("CurrentTemplateListModName", CurrentTemplateListMod);
  260. }
  261. backgroundRegion.RequestNavigate(BackgroundSettingsRegionName, SelectedContentName, param);
  262. BackgroundSettingsVisible = Visibility.Visible;
  263. }
  264. public void SetCurrentCreateMod(stringUnicode currentCreateModNameunicode)
  265. {
  266. string currentCreateModName = currentCreateModNameunicode.Status;
  267. if (currentCreateModName == CreateModColorName)
  268. {
  269. CurrentCreateMod = EnumColorOrFile.StatusColor;
  270. }
  271. else if (currentCreateModName == CreateModFileName)
  272. {
  273. CurrentCreateMod = EnumColorOrFile.StatusFile;
  274. }
  275. }
  276. public void SetCurrentTemplateListMod(stringUnicode currentTemplateListModNameunicode)
  277. {
  278. string currentTemplateListModName = currentTemplateListModNameunicode.Status;
  279. if (currentTemplateListModName == TemplateListModColorName)
  280. {
  281. CurrentTemplateListMod = EnumColorOrFile.StatusColor;
  282. }
  283. else if (currentTemplateListModName == TemplateListModFileName)
  284. {
  285. CurrentTemplateListMod = EnumColorOrFile.StatusFile;
  286. }
  287. }
  288. public void EditBackgroundTemplateItem(BackgroundItemUnicode backgroundItemunicode)
  289. {
  290. BackgroundItem backgroundItem = backgroundItemunicode.Status;
  291. NavigationParameters param = new NavigationParameters();
  292. param.Add(ParameterNames.PDFViewer, PDFViewer);
  293. param.Add("CurrentTemplateListModName", CurrentTemplateListMod);
  294. param.Add("Unicode", Unicode);
  295. param.Add("BackgroundItem", backgroundItem);
  296. backgroundRegion.RequestNavigate(BackgroundSettingsRegionName, CreateBaseName, param);
  297. BackgroundSettingsVisible = Visibility.Visible;
  298. CreateGridSpan = "2";
  299. CreateGridSpanVisibility = Visibility.Collapsed;
  300. }
  301. private void create()
  302. {
  303. FolderBrowserDialog dlg = new FolderBrowserDialog();
  304. string saveSelectedPath = "";
  305. if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  306. {
  307. saveSelectedPath = dlg.SelectedPath.Trim();
  308. saveSelectedPath = saveSelectedPath + "\\";
  309. }
  310. else { return; }
  311. HomePageBatchProcessingDialogModel.closeDialog = true;
  312. updateListview("wait");
  313. fileNamesIndex = 0;
  314. BackgroundGridIsEnabled = "False";
  315. foreach (var filename in fileNames)
  316. {
  317. FileInfo fileinfo = new FileInfo(filename);
  318. string OutputPath = fileinfo.DirectoryName;
  319. char[] enumerationSeparator = new char[] { ',' };
  320. char[] rangeSeparator = new char[] { '-' };
  321. List<int> PageIndexLists = new List<int>();
  322. CPDFDocument document = CPDFDocument.InitWithFilePath(filename);
  323. if (document == null)
  324. {
  325. PDFDataTable.Rows[fileNamesIndex]["FileState"] = "error";
  326. PDFCurrentDataTable.Rows[fileNamesIndex]["FileState"] = "error";
  327. fileNamesIndex++;
  328. continue;
  329. }
  330. if (document.IsLocked)
  331. {
  332. DialogParameters value = new DialogParameters();
  333. value.Add(ParameterNames.PDFDocument, document);
  334. dialogs.ShowDialog(DialogNames.VerifyPassWordDialog, value, e =>
  335. {
  336. if (e.Result == ButtonResult.OK)
  337. {
  338. if (e.Parameters.ContainsKey(ParameterNames.PassWord) && e.Parameters.GetValue<string>(ParameterNames.PassWord) != null)
  339. {
  340. document.UnlockWithPassword(e.Parameters.GetValue<string>(ParameterNames.PassWord).ToString());
  341. }
  342. }
  343. });
  344. if (document.IsLocked)
  345. {
  346. //未成功解密文档时,释放Document对象,返回
  347. PDFDataTable.Rows[fileNamesIndex]["FileState"] = "error";
  348. PDFCurrentDataTable.Rows[fileNamesIndex]["FileState"] = "error";
  349. fileNamesIndex++;
  350. continue;
  351. }
  352. }
  353. CreateBackground(document);
  354. document.WriteToFilePath(CommonHelper.CreateFilePath(saveSelectedPath + document.FileName + "_Background.pdf"));
  355. // if (!CommonHelper.GetPagesInRange(ref PageIndexLists, "1-" + document.PageCount.ToString(), document.PageCount, enumerationSeparator, rangeSeparator))
  356. // { //TODO
  357. // Trace.WriteLine("输入不对");
  358. // MessageBoxEx.Show("输入不对");
  359. // return;
  360. // }
  361. document.Release();
  362. PDFDataTable.Rows[fileNamesIndex]["FileState"] = "complete";
  363. PDFCurrentDataTable.Rows[fileNamesIndex]["FileState"] = "complete";
  364. fileNamesIndex++;
  365. }
  366. BackgroundGridIsEnabled = "True";
  367. HomePageBatchProcessingDialogModel.closeDialog = false;
  368. }
  369. public void CreateBackground(CPDFDocument document)
  370. {
  371. if (BackgroundInfo != null)
  372. {
  373. background = document.GetBackground();
  374. if (BackgroundInfo.BackgroundType == C_Background_Type.BG_TYPE_COLOR)
  375. {
  376. background.SetBackgroundType(C_Background_Type.BG_TYPE_COLOR);
  377. background.SetColor(BackgroundInfo.Color);
  378. }
  379. else
  380. {
  381. background.SetBackgroundType(C_Background_Type.BG_TYPE_IMAGE);
  382. background.SetImage(BackgroundInfo.ImageArray, BackgroundInfo.ImageWidth, BackgroundInfo.ImageHeight, ComPDFKit.Import.C_Scale_Type.fitCenter);
  383. }
  384. if (!BackgroundInfo.IsRelativeScale)
  385. {
  386. background.SetScale(1);
  387. }
  388. else
  389. {
  390. background.SetScale((float)(BackgroundInfo.Scale / 100));
  391. }
  392. background.SetRotation((float)((BackgroundInfo.Rotation / 180) * Math.PI));
  393. background.SetOpacity((byte)(((float)BackgroundInfo.Opacity / 100) * 255));
  394. background.SetVertalign(BackgroundInfo.Vertalign);
  395. background.SetHorizalign(BackgroundInfo.Horizalign);
  396. background.SetXOffset(BackgroundInfo.HorizOffset);
  397. background.SetYOffset(BackgroundInfo.VertOffset);
  398. background.SetAllowsPrint(true);
  399. background.SetAllowsView(true);
  400. background.SetPages(getFilePageRange(document, PDFCurrentDataTable.Rows[fileNamesIndex]["FilePageRangeText"].ToString(), PDFCurrentDataTable.Rows[fileNamesIndex]["FilePageRangeSelectIndex"].ToString()));
  401. background.Update();
  402. }
  403. }
  404. #endregion
  405. #region 批量处理逻辑函数
  406. /// <summary>
  407. /// 添加PDF文件
  408. /// </summary>
  409. private void addpicture()
  410. {
  411. FileNameNumber = fileNames.Count;
  412. System.Windows.Forms.OpenFileDialog dlg = new System.Windows.Forms.OpenFileDialog();
  413. dlg.Multiselect = true;
  414. dlg.Filter = "PDF|*.pdf;*.PDF;";
  415. if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  416. {
  417. fileNames.AddRange(dlg.FileNames.ToList());
  418. RemoveExcess(ref fileNames);
  419. SetBackgroundGridIsEnabled = "True";
  420. AddFileVisibility = Visibility.Collapsed;
  421. updateListview("wait");
  422. }
  423. }
  424. public void addPDFFiles(string filename)
  425. {
  426. FileNameNumber = fileNames.Count;
  427. fileNames.Add(filename);
  428. RemoveExcess(ref fileNames);
  429. SetBackgroundGridIsEnabled = "True";
  430. AddFileVisibility = Visibility.Collapsed;
  431. updateListview("wait");
  432. }
  433. /// <summary>
  434. /// 添加已打开PDF文件
  435. /// </summary>
  436. public void addOpenedPDFFiles()
  437. {
  438. FileNameNumber = fileNames.Count;
  439. foreach (var filename in App.OpenedFileList)
  440. {
  441. fileNames.Add(filename);
  442. }
  443. RemoveExcess(ref fileNames);
  444. SetBackgroundGridIsEnabled = "True";
  445. AddFileVisibility = Visibility.Collapsed;
  446. updateListview("wait");
  447. }
  448. /// <summary>
  449. /// 删除重复的文件
  450. /// </summary>
  451. public void RemoveExcess(ref List<string> Filenames)
  452. {
  453. List<string> filenames = new List<string>();
  454. foreach (var fileName in Filenames)
  455. {
  456. if (!filenames.Contains(fileName))
  457. {
  458. filenames.Add(fileName);
  459. }
  460. }
  461. Filenames.Clear();
  462. Filenames = filenames;
  463. }
  464. /// <summary>
  465. /// 添加PDF文件夹
  466. /// </summary>
  467. private void addpicturefiles()
  468. {
  469. FileNameNumber = fileNames.Count;
  470. FolderBrowserDialog dialog = new FolderBrowserDialog();
  471. dialog.Description = "请选择文件路径";
  472. if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  473. {
  474. string foldPath = dialog.SelectedPath;
  475. var apps = System.IO.Directory.GetFiles(foldPath);
  476. foreach (string app in apps)
  477. {
  478. var fi = new FileInfo(app);
  479. if (fi.Extension == ".pdf" || fi.Extension == ".PDF")
  480. {
  481. fileNames.Add(app);
  482. }
  483. }
  484. RemoveExcess(ref fileNames);
  485. updateListview("wait");
  486. SetBackgroundGridIsEnabled = "True";
  487. AddFileVisibility = Visibility.Collapsed;
  488. }
  489. }
  490. /// <summary>
  491. /// 更新listview显示
  492. /// state 状态显示字符串
  493. /// </summary>
  494. public void updateListview(string state)
  495. {
  496. updateCurrentListview();
  497. DataTable pdfdatatable = new DataTable();
  498. pdfdatatable.Columns.Add("FileName");
  499. pdfdatatable.Columns.Add("FilePageRangeText");
  500. pdfdatatable.Columns.Add("FilePageRangeSelectIndex");
  501. pdfdatatable.Columns.Add("IsEvenPageIsEnabled");
  502. pdfdatatable.Columns.Add("MaxPageRange");
  503. pdfdatatable.Columns.Add("FileSize");
  504. pdfdatatable.Columns.Add("FileState");
  505. int datatableindex = 0;
  506. List<int> PageIndexLists = new List<int>();
  507. foreach (var fileName in fileNames)
  508. {
  509. string file_all = fileName;
  510. FileInfo f = new FileInfo(file_all);
  511. string file_size = (((float)f.Length) / 1024).ToString() + " K";
  512. if (!isEvenPage(fileName) && PDFCurrentDataTable.Rows[datatableindex]["FilePageRangeSelectIndex"].ToString() == "2")
  513. {
  514. PDFCurrentDataTable.Rows[datatableindex]["FilePageRangeSelectIndex"] = "0";
  515. }
  516. int pagecount = CPDFDocument.InitWithFilePath(fileName).PageCount;
  517. if (PDFCurrentDataTable.Rows[datatableindex]["FilePageRangeSelectIndex"].ToString() == "3" && !CommonHelper.GetPagesInRange(ref PageIndexLists, PDFCurrentDataTable.Rows[datatableindex]["FilePageRangeText"].ToString(), pagecount, new char[] { ',' }, new char[] { '-' }, true))
  518. {
  519. PDFCurrentDataTable.Rows[datatableindex]["FilePageRangeSelectIndex"] = "0";
  520. }
  521. pdfdatatable.Rows.Add(f.Name, PDFCurrentDataTable.Rows[datatableindex]["FilePageRangeText"], PDFCurrentDataTable.Rows[datatableindex]["FilePageRangeSelectIndex"], isEvenPage(fileName), pagecount, file_size, PDFCurrentDataTable.Rows[datatableindex]["FileState"]);
  522. datatableindex++;
  523. }
  524. PDFDataTable = pdfdatatable;
  525. HomePageBatchProcessingDialogModel.FilePaths = fileNames;
  526. }
  527. /// <summary>
  528. /// 更新Currentlistview显示
  529. /// pagerangetext 自定义页面范围字符串 pagerangeselectindex combobox下拉索引(0全部页面 1奇数页 2偶数页 3自定义页面)isevenpageisenabled 偶数页状态 state 状态显示字符串
  530. /// </summary>
  531. public void updateCurrentListview(string pagerangetext = "1", string pagerangeselectindex = "0", bool isevenpageisenabled = true, string state = "wait")
  532. {
  533. if (fileNames.Count >= FileNameNumber)
  534. {
  535. for (int i = 0; fileNames.Count - FileNameNumber > i; i++)
  536. {
  537. PDFCurrentDataTable.Rows.Add(pagerangetext, pagerangeselectindex, isevenpageisenabled, state);
  538. }
  539. }
  540. else
  541. {
  542. Reverseorder(ref fileNamesView);
  543. foreach (int filenamesview in fileNamesView)
  544. {
  545. PDFCurrentDataTable.Rows.RemoveAt(filenamesview);
  546. }
  547. }
  548. }
  549. /// <summary>
  550. /// 更新Currentlistview显示
  551. /// pagerangetext 自定义页面范围字符串 pagerangeselectindex combobox下拉索引(0全部页面 1奇数页 2偶数页 3自定义页面)
  552. /// </summary>
  553. public void updateFilesPageRange(string pagerangetext = "1", string pagerangeselectindex = "0")
  554. {
  555. for (int i = 0; fileNames.Count > i; i++)
  556. {
  557. PDFDataTable.Rows[i]["FilePageRangeText"] = pagerangetext;
  558. PDFDataTable.Rows[i]["FilePageRangeSelectIndex"] = pagerangeselectindex;
  559. PDFCurrentDataTable.Rows[i]["FilePageRangeText"] = pagerangetext;
  560. PDFCurrentDataTable.Rows[i]["FilePageRangeSelectIndex"] = pagerangeselectindex;
  561. }
  562. }
  563. /// <summary>
  564. /// 获取文件列表单个文件对应的页码范围
  565. /// document 文档对象 pagerangetext 自定义页面范围字符串 pagerangeselectindex combobox下拉索引(0全部页面 1奇数页 2偶数页 3自定义页面)
  566. /// </summary>
  567. public string getFilePageRange(CPDFDocument document, string pagerangetext = "1", string pagerangeselectindex = "0")
  568. {
  569. string filePageRange = "1";
  570. EditToolsHelper.GetPageRange(int.Parse(pagerangeselectindex), document, ref filePageRange, pagerangetext);
  571. return filePageRange;
  572. }
  573. /// <summary>
  574. /// 判断是否关闭偶数页
  575. /// document 文档对象 )
  576. /// </summary>
  577. public bool isEvenPage(string filename)
  578. {
  579. CPDFDocument document = CPDFDocument.InitWithFilePath(filename);
  580. bool isevenpage = false;
  581. if (document.PageCount > 1)
  582. {
  583. isevenpage = true;
  584. }
  585. document.Release();
  586. return isevenpage;
  587. }
  588. /// <summary>
  589. /// 逆序int类型集合
  590. /// </summary>
  591. public void Reverseorder(ref List<int> Numbers)
  592. {
  593. Numbers = Numbers.OrderBy(a => a).ToList();
  594. Numbers.Reverse();
  595. }
  596. /// <summary>
  597. /// 打开文件PDF
  598. /// </summary>
  599. public void openfiledialog()
  600. {
  601. foreach (int filenamesview in fileNamesView)
  602. {
  603. System.Diagnostics.Process.Start("Explorer", "/select," + fileNames[filenamesview]);
  604. }
  605. }
  606. /// <summary>
  607. /// 删除文件PDF
  608. /// </summary>
  609. public void removepdffile()
  610. {
  611. FileNameNumber = fileNames.Count;
  612. Reverseorder(ref fileNamesView);
  613. foreach (int filenamesview in fileNamesView)
  614. {
  615. //Trace.WriteLine(filenamesview);
  616. fileNames.Remove(fileNames[filenamesview]);
  617. }
  618. if (fileNames.Count < 1)
  619. {
  620. SetBackgroundGridIsEnabled = "False";
  621. AddFileVisibility = Visibility.Visible;
  622. }
  623. updateListview("wait");
  624. }
  625. public void removepdffile(int index)
  626. {
  627. PDFCurrentDataTable.Rows.RemoveAt(index);
  628. fileNames.Remove(fileNames[index]);
  629. if (fileNames.Count < 1)
  630. {
  631. SetBackgroundGridIsEnabled = "False";
  632. AddFileVisibility = Visibility.Visible;
  633. }
  634. updateListview("wait");
  635. }
  636. public void PDFFileCount()
  637. {
  638. if (fileNames.Count == 0)
  639. {
  640. SetBackgroundGridIsEnabled = "False";
  641. AddFileVisibility = Visibility.Visible;
  642. }
  643. else
  644. {
  645. SetBackgroundGridIsEnabled = "True";
  646. AddFileVisibility = Visibility.Collapsed;
  647. }
  648. }
  649. #endregion
  650. #region 构架行为
  651. public void OnNavigatedTo(NavigationContext navigationContext)
  652. {
  653. List<string> filepath = new List<string>();
  654. navigationContext.Parameters.TryGetValue<ViewContentViewModel>(ParameterNames.ViewContentViewModel, out viewContentViewModel);
  655. navigationContext.Parameters.TryGetValue<CPDFViewer>(ParameterNames.PDFViewer, out PDFViewer);
  656. navigationContext.Parameters.TryGetValue<List<string>>(ParameterNames.FilePath, out filepath);
  657. if (filepath != null)
  658. {
  659. fileNames = filepath;
  660. PDFFileCount();
  661. updateListview("wait");
  662. CreateGridSpan = "1";
  663. CreateGridSpanVisibility = Visibility.Visible;
  664. EnterSelectedContent(TemplateListBaseName);
  665. }
  666. }
  667. public bool IsNavigationTarget(NavigationContext navigationContext)
  668. {
  669. return true;
  670. }
  671. public void OnNavigatedFrom(NavigationContext navigationContext)
  672. {
  673. }
  674. #endregion
  675. }
  676. }