HomePageBackgroundDialogViewModel.cs 29 KB

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