HomePageBackgroundDialogViewModel.cs 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717
  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_Office.Helper;
  9. using Prism.Regions;
  10. using ComPDFKit.PDFDocument;
  11. using PDF_Office.CustomControl;
  12. using PDF_Office.Model.Dialog.HomePageToolsDialogs.HomePageBatchProcessing;
  13. using PDF_Office.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_Office.EventAggregators;
  20. using PDFSettings;
  21. using PDF_Office.Model.EditTools.Bates;
  22. using PDF_Office.Model.EditTools.Background;
  23. using static System.Windows.Forms.VisualStyles.VisualStyleElement.TrayNotify;
  24. using Prism.Services.Dialogs;
  25. namespace PDF_Office.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. #endregion
  188. #region 委托声明
  189. public DelegateCommand ADDPDFCommand { get; set; }
  190. public DelegateCommand RemovePDFFileCommand { get; set; }
  191. public DelegateCommand CreateCommand { get; set; }
  192. public DelegateCommand ADDPDFFilesCommand { get; set; }
  193. #endregion
  194. public string Unicode = null;
  195. public HomePageBackgroundDialogViewModel(IRegionManager backgroundRegion, IEventAggregator eventAggregator, IDialogService dialogs)
  196. {
  197. this.eventAggregator = eventAggregator;
  198. this.backgroundRegion = backgroundRegion;
  199. this.dialogs = dialogs;
  200. PDFCurrentDataTable.Columns.Add("FilePageRangeText");
  201. PDFCurrentDataTable.Columns.Add("FilePageRangeSelectIndex");
  202. PDFCurrentDataTable.Columns.Add("IsEvenPageIsEnabled");
  203. PDFCurrentDataTable.Columns.Add("FileState");
  204. PDFDataTable.Columns.Add("FileName");
  205. PDFDataTable.Columns.Add("FilePageRangeText");
  206. PDFDataTable.Columns.Add("FilePageRangeSelectIndex");
  207. PDFDataTable.Columns.Add("IsEvenPageIsEnabled");
  208. PDFDataTable.Columns.Add("MaxPageRange");
  209. PDFDataTable.Columns.Add("FileSize");
  210. PDFDataTable.Columns.Add("FileState");
  211. Unicode = Guid.NewGuid().ToString() ;
  212. BackgroundSettingsVisible = Visibility.Visible;
  213. ADDPDFCommand = new DelegateCommand(addpicture);
  214. ADDPDFFilesCommand = new DelegateCommand(addpicturefiles);
  215. RemovePDFFileCommand = new DelegateCommand(removepdffile);
  216. CreateCommand = new DelegateCommand(create);
  217. BackgroundSettingsRegionName = Guid.NewGuid().ToString();
  218. eventAggregator.GetEvent<EnterTemplateListOrCreateEvent>().Subscribe(EnterTemplateListOrCreate, e => e.Unicode == Unicode);
  219. eventAggregator.GetEvent<SetCurrentCreateModEvent>().Subscribe(SetCurrentCreateMod, e => e.Unicode == Unicode);
  220. eventAggregator.GetEvent<SetCurrentTemplateListModEvent>().Subscribe(SetCurrentTemplateListMod, e => e.Unicode == Unicode);
  221. eventAggregator.GetEvent<EditBackgroundTemplateItemEvent>().Subscribe(EditBackgroundTemplateItem, e => e.Unicode == Unicode);
  222. }
  223. #region 逻辑函数
  224. public void EnterTemplateListOrCreate(EnumTemplateListOrCreateUnicode enumTemplateListOrCreateunicode)
  225. {
  226. EnumTemplateListOrCreate enumTemplateListOrCreate = enumTemplateListOrCreateunicode.Status;
  227. if (enumTemplateListOrCreate == EnumTemplateListOrCreate.StatusTemplate)
  228. {
  229. CreateGridSpan = "1";
  230. CreateGridSpanVisibility = Visibility.Visible;
  231. EnterSelectedContent(TemplateListBaseName);
  232. }
  233. else
  234. {
  235. CreateGridSpan = "2";
  236. CreateGridSpanVisibility = Visibility.Collapsed;
  237. EnterSelectedContent(CreateBaseName);
  238. }
  239. }
  240. public void EnterSelectedContent(string SelectedContentName)
  241. {
  242. NavigationParameters param = new NavigationParameters();
  243. param.Add(ParameterNames.PDFViewer, PDFViewer);
  244. param.Add("Unicode", Unicode);
  245. param.Add("ViewModel", this);
  246. if (SelectedContentName == TemplateListBaseName)
  247. {
  248. param.Add("CurrentCreateModName", CurrentCreateMod);
  249. }
  250. else if (SelectedContentName == CreateBaseName)
  251. {
  252. param.Add("CurrentTemplateListModName", CurrentTemplateListMod);
  253. }
  254. backgroundRegion.RequestNavigate(BackgroundSettingsRegionName, SelectedContentName, param);
  255. BackgroundSettingsVisible = Visibility.Visible;
  256. }
  257. public void SetCurrentCreateMod(stringUnicode currentCreateModNameunicode)
  258. {
  259. string currentCreateModName = currentCreateModNameunicode.Status;
  260. if (currentCreateModName == CreateModColorName)
  261. {
  262. CurrentCreateMod = EnumColorOrFile.StatusColor;
  263. }
  264. else if (currentCreateModName == CreateModFileName)
  265. {
  266. CurrentCreateMod = EnumColorOrFile.StatusFile;
  267. }
  268. }
  269. public void SetCurrentTemplateListMod(stringUnicode currentTemplateListModNameunicode)
  270. {
  271. string currentTemplateListModName = currentTemplateListModNameunicode.Status;
  272. if (currentTemplateListModName == TemplateListModColorName)
  273. {
  274. CurrentTemplateListMod = EnumColorOrFile.StatusColor;
  275. }
  276. else if (currentTemplateListModName == TemplateListModFileName)
  277. {
  278. CurrentTemplateListMod = EnumColorOrFile.StatusFile;
  279. }
  280. }
  281. public void EditBackgroundTemplateItem(BackgroundItemUnicode backgroundItemunicode)
  282. {
  283. BackgroundItem backgroundItem = backgroundItemunicode.Status;
  284. NavigationParameters param = new NavigationParameters();
  285. param.Add(ParameterNames.PDFViewer, PDFViewer);
  286. param.Add("CurrentTemplateListModName", CurrentTemplateListMod);
  287. param.Add("Unicode", Unicode);
  288. param.Add("BackgroundItem", backgroundItem);
  289. backgroundRegion.RequestNavigate(BackgroundSettingsRegionName, CreateBaseName, param);
  290. BackgroundSettingsVisible = Visibility.Visible;
  291. CreateGridSpan = "2";
  292. CreateGridSpanVisibility = Visibility.Collapsed;
  293. }
  294. private void create()
  295. {
  296. updateListview("wait");
  297. fileNamesIndex = 0;
  298. BackgroundGridIsEnabled = "False";
  299. foreach (var filename in fileNames)
  300. {
  301. FileInfo fileinfo = new FileInfo(filename);
  302. string OutputPath = fileinfo.DirectoryName;
  303. char[] enumerationSeparator = new char[] { ',' };
  304. char[] rangeSeparator = new char[] { '-' };
  305. List<int> PageIndexLists = new List<int>();
  306. CPDFDocument document = CPDFDocument.InitWithFilePath(filename);
  307. if (document == null)
  308. {
  309. PDFDataTable.Rows[fileNamesIndex]["FileState"] = "error";
  310. PDFCurrentDataTable.Rows[fileNamesIndex]["FileState"] = "error";
  311. fileNamesIndex++;
  312. continue;
  313. }
  314. if (document.IsLocked)
  315. {
  316. DialogParameters value = new DialogParameters();
  317. value.Add(ParameterNames.PDFDocument, document);
  318. dialogs.ShowDialog(DialogNames.VerifyPassWordDialog, value, e =>
  319. {
  320. if (e.Result == ButtonResult.OK)
  321. {
  322. if (e.Parameters.ContainsKey(ParameterNames.PassWord) && e.Parameters.GetValue<string>(ParameterNames.PassWord) != null)
  323. {
  324. document.UnlockWithPassword(e.Parameters.GetValue<string>(ParameterNames.PassWord).ToString());
  325. }
  326. }
  327. });
  328. if (document.IsLocked)
  329. {
  330. //未成功解密文档时,释放Document对象,返回
  331. PDFDataTable.Rows[fileNamesIndex]["FileState"] = "error";
  332. PDFCurrentDataTable.Rows[fileNamesIndex]["FileState"] = "error";
  333. fileNamesIndex++;
  334. continue;
  335. }
  336. }
  337. CreateBackground(document);
  338. document.WriteToFilePath(CommonHelper.CreateFilePath(filename + "_Background.pdf"));
  339. // if (!CommonHelper.GetPagesInRange(ref PageIndexLists, "1-" + document.PageCount.ToString(), document.PageCount, enumerationSeparator, rangeSeparator))
  340. // { //TODO
  341. // Trace.WriteLine("输入不对");
  342. // MessageBoxEx.Show("输入不对");
  343. // return;
  344. // }
  345. document.Release();
  346. PDFDataTable.Rows[fileNamesIndex]["FileState"] = "complete";
  347. PDFCurrentDataTable.Rows[fileNamesIndex]["FileState"] = "complete";
  348. fileNamesIndex++;
  349. }
  350. BackgroundGridIsEnabled = "True";
  351. }
  352. public void CreateBackground(CPDFDocument document)
  353. {
  354. if (BackgroundInfo != null)
  355. {
  356. background = document.GetBackground();
  357. if (BackgroundInfo.BackgroundType == C_Background_Type.BG_TYPE_COLOR)
  358. {
  359. background.SetBackgroundType(C_Background_Type.BG_TYPE_COLOR);
  360. background.SetColor(BackgroundInfo.Color);
  361. }
  362. else
  363. {
  364. background.SetBackgroundType(C_Background_Type.BG_TYPE_IMAGE);
  365. background.SetImage(BackgroundInfo.ImageArray, BackgroundInfo.ImageWidth, BackgroundInfo.ImageHeight, ComPDFKit.Import.C_Scale_Type.fitCenter);
  366. }
  367. if (!BackgroundInfo.IsRelativeScale)
  368. {
  369. background.SetScale(1);
  370. }
  371. else
  372. {
  373. background.SetScale((float)(BackgroundInfo.Scale / 100));
  374. }
  375. background.SetRotation((float)((BackgroundInfo.Rotation / 180) * Math.PI));
  376. background.SetOpacity((byte)(((float)BackgroundInfo.Opacity / 100) * 255));
  377. background.SetVertalign(BackgroundInfo.Vertalign);
  378. background.SetHorizalign(BackgroundInfo.Horizalign);
  379. background.SetXOffset(BackgroundInfo.HorizOffset);
  380. background.SetYOffset(BackgroundInfo.VertOffset);
  381. background.SetAllowsPrint(true);
  382. background.SetAllowsView(true);
  383. background.SetPages(getFilePageRange(document, PDFCurrentDataTable.Rows[fileNamesIndex]["FilePageRangeText"].ToString(), PDFCurrentDataTable.Rows[fileNamesIndex]["FilePageRangeSelectIndex"].ToString()));
  384. background.Update();
  385. }
  386. }
  387. #endregion
  388. #region 批量处理逻辑函数
  389. /// <summary>
  390. /// 添加PDF文件
  391. /// </summary>
  392. private void addpicture()
  393. {
  394. FileNameNumber = fileNames.Count;
  395. System.Windows.Forms.OpenFileDialog dlg = new System.Windows.Forms.OpenFileDialog();
  396. dlg.Multiselect = true;
  397. dlg.Filter = "PDF|*.pdf;*.PDF;";
  398. if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  399. {
  400. fileNames.AddRange(dlg.FileNames.ToList());
  401. RemoveExcess(ref fileNames);
  402. SetBackgroundGridIsEnabled = "True";
  403. AddFileVisibility = Visibility.Collapsed;
  404. updateListview("wait");
  405. }
  406. }
  407. public void addPDFFiles(string filename)
  408. {
  409. FileNameNumber = fileNames.Count;
  410. fileNames.Add(filename);
  411. RemoveExcess(ref fileNames);
  412. SetBackgroundGridIsEnabled = "True";
  413. AddFileVisibility = Visibility.Collapsed;
  414. updateListview("wait");
  415. }
  416. /// <summary>
  417. /// 删除重复的文件
  418. /// </summary>
  419. public void RemoveExcess(ref List<string> Filenames)
  420. {
  421. List<string> filenames = new List<string>();
  422. foreach (var fileName in Filenames)
  423. {
  424. if (!filenames.Contains(fileName))
  425. {
  426. filenames.Add(fileName);
  427. }
  428. }
  429. Filenames.Clear();
  430. Filenames = filenames;
  431. }
  432. /// <summary>
  433. /// 添加PDF文件夹
  434. /// </summary>
  435. private void addpicturefiles()
  436. {
  437. FileNameNumber = fileNames.Count;
  438. FolderBrowserDialog dialog = new FolderBrowserDialog();
  439. dialog.Description = "请选择文件路径";
  440. if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  441. {
  442. string foldPath = dialog.SelectedPath;
  443. var apps = System.IO.Directory.GetFiles(foldPath);
  444. foreach (string app in apps)
  445. {
  446. var fi = new FileInfo(app);
  447. if (fi.Extension == ".pdf" || fi.Extension == ".PDF")
  448. {
  449. fileNames.Add(app);
  450. }
  451. }
  452. RemoveExcess(ref fileNames);
  453. updateListview("wait");
  454. SetBackgroundGridIsEnabled = "True";
  455. AddFileVisibility = Visibility.Collapsed;
  456. }
  457. }
  458. /// <summary>
  459. /// 更新listview显示
  460. /// state 状态显示字符串
  461. /// </summary>
  462. public void updateListview(string state)
  463. {
  464. updateCurrentListview();
  465. DataTable pdfdatatable = new DataTable();
  466. pdfdatatable.Columns.Add("FileName");
  467. pdfdatatable.Columns.Add("FilePageRangeText");
  468. pdfdatatable.Columns.Add("FilePageRangeSelectIndex");
  469. pdfdatatable.Columns.Add("IsEvenPageIsEnabled");
  470. pdfdatatable.Columns.Add("MaxPageRange");
  471. pdfdatatable.Columns.Add("FileSize");
  472. pdfdatatable.Columns.Add("FileState");
  473. int datatableindex = 0;
  474. List<int> PageIndexLists = new List<int>();
  475. foreach (var fileName in fileNames)
  476. {
  477. string file_all = fileName;
  478. FileInfo f = new FileInfo(file_all);
  479. string file_size = (((float)f.Length) / 1024).ToString() + " K";
  480. if (!isEvenPage(fileName) && PDFCurrentDataTable.Rows[datatableindex]["FilePageRangeSelectIndex"].ToString() == "2")
  481. {
  482. PDFCurrentDataTable.Rows[datatableindex]["FilePageRangeSelectIndex"] = "0";
  483. }
  484. int pagecount = CPDFDocument.InitWithFilePath(fileName).PageCount;
  485. if (PDFCurrentDataTable.Rows[datatableindex]["FilePageRangeSelectIndex"].ToString() == "3" && !CommonHelper.GetPagesInRange(ref PageIndexLists, PDFCurrentDataTable.Rows[datatableindex]["FilePageRangeText"].ToString(), pagecount, new char[] { ',' }, new char[] { '-' }, true))
  486. {
  487. PDFCurrentDataTable.Rows[datatableindex]["FilePageRangeSelectIndex"] = "0";
  488. }
  489. pdfdatatable.Rows.Add(f.Name, PDFCurrentDataTable.Rows[datatableindex]["FilePageRangeText"], PDFCurrentDataTable.Rows[datatableindex]["FilePageRangeSelectIndex"], isEvenPage(fileName), pagecount, file_size, PDFCurrentDataTable.Rows[datatableindex]["FileState"]);
  490. datatableindex++;
  491. }
  492. PDFDataTable = pdfdatatable;
  493. HomePageBatchProcessingDialogModel.FilePaths = fileNames;
  494. }
  495. /// <summary>
  496. /// 更新Currentlistview显示
  497. /// pagerangetext 自定义页面范围字符串 pagerangeselectindex combobox下拉索引(0全部页面 1奇数页 2偶数页 3自定义页面)isevenpageisenabled 偶数页状态 state 状态显示字符串
  498. /// </summary>
  499. public void updateCurrentListview(string pagerangetext = "1", string pagerangeselectindex = "0",bool isevenpageisenabled=true,string state = "wait")
  500. {
  501. if (fileNames.Count >= FileNameNumber)
  502. {
  503. for (int i = 0; fileNames.Count - FileNameNumber > i; i++)
  504. {
  505. PDFCurrentDataTable.Rows.Add(pagerangetext, pagerangeselectindex, isevenpageisenabled, state);
  506. }
  507. }
  508. else
  509. {
  510. Reverseorder(ref fileNamesView);
  511. foreach (int filenamesview in fileNamesView)
  512. {
  513. PDFCurrentDataTable.Rows.RemoveAt(filenamesview);
  514. }
  515. }
  516. }
  517. /// <summary>
  518. /// 更新Currentlistview显示
  519. /// pagerangetext 自定义页面范围字符串 pagerangeselectindex combobox下拉索引(0全部页面 1奇数页 2偶数页 3自定义页面)
  520. /// </summary>
  521. public void updateFilesPageRange(string pagerangetext = "1", string pagerangeselectindex = "0")
  522. {
  523. for (int i = 0; fileNames.Count > i; i++)
  524. {
  525. PDFDataTable.Rows[i]["FilePageRangeText"] = pagerangetext;
  526. PDFDataTable.Rows[i]["FilePageRangeSelectIndex"] = pagerangeselectindex;
  527. PDFCurrentDataTable.Rows[i]["FilePageRangeText"] = pagerangetext;
  528. PDFCurrentDataTable.Rows[i]["FilePageRangeSelectIndex"] = pagerangeselectindex;
  529. }
  530. }
  531. /// <summary>
  532. /// 获取文件列表单个文件对应的页码范围
  533. /// document 文档对象 pagerangetext 自定义页面范围字符串 pagerangeselectindex combobox下拉索引(0全部页面 1奇数页 2偶数页 3自定义页面)
  534. /// </summary>
  535. public string getFilePageRange(CPDFDocument document, string pagerangetext = "1", string pagerangeselectindex = "0")
  536. {
  537. string filePageRange = "1";
  538. EditToolsHelper.GetPageRange(int.Parse(pagerangeselectindex), document, ref filePageRange, pagerangetext);
  539. return filePageRange;
  540. }
  541. /// <summary>
  542. /// 判断是否关闭偶数页
  543. /// document 文档对象 )
  544. /// </summary>
  545. public bool isEvenPage(string filename)
  546. {
  547. CPDFDocument document= CPDFDocument.InitWithFilePath(filename);
  548. bool isevenpage = false;
  549. if (document.PageCount > 1)
  550. {
  551. isevenpage = true;
  552. }
  553. document.Release();
  554. return isevenpage;
  555. }
  556. /// <summary>
  557. /// 逆序int类型集合
  558. /// </summary>
  559. public void Reverseorder(ref List<int> Numbers)
  560. {
  561. Numbers = Numbers.OrderBy(a => a).ToList();
  562. Numbers.Reverse();
  563. }
  564. /// <summary>
  565. /// 打开文件PDF
  566. /// </summary>
  567. public void openfiledialog()
  568. {
  569. foreach (int filenamesview in fileNamesView)
  570. {
  571. System.Diagnostics.Process.Start(fileNames[filenamesview]);
  572. }
  573. }
  574. /// <summary>
  575. /// 删除文件PDF
  576. /// </summary>
  577. public void removepdffile()
  578. {
  579. FileNameNumber = fileNames.Count;
  580. Reverseorder(ref fileNamesView);
  581. foreach (int filenamesview in fileNamesView)
  582. {
  583. //Trace.WriteLine(filenamesview);
  584. fileNames.Remove(fileNames[filenamesview]);
  585. }
  586. if (fileNames.Count < 1)
  587. {
  588. SetBackgroundGridIsEnabled = "False";
  589. AddFileVisibility = Visibility.Visible;
  590. }
  591. updateListview("wait");
  592. }
  593. public void removepdffile(int index)
  594. {
  595. PDFCurrentDataTable.Rows.RemoveAt(index);
  596. fileNames.Remove(fileNames[index]);
  597. if (fileNames.Count < 1)
  598. {
  599. SetBackgroundGridIsEnabled = "False";
  600. AddFileVisibility = Visibility.Visible;
  601. }
  602. updateListview("wait");
  603. }
  604. public void PDFFileCount()
  605. {
  606. if (fileNames.Count == 0)
  607. {
  608. SetBackgroundGridIsEnabled = "False";
  609. AddFileVisibility = Visibility.Visible;
  610. }
  611. else
  612. {
  613. SetBackgroundGridIsEnabled = "True";
  614. AddFileVisibility = Visibility.Collapsed;
  615. }
  616. }
  617. #endregion
  618. #region 构架行为
  619. public void OnNavigatedTo(NavigationContext navigationContext)
  620. {
  621. List<string> filepath = new List<string>();
  622. navigationContext.Parameters.TryGetValue<ViewContentViewModel>(ParameterNames.ViewContentViewModel, out viewContentViewModel);
  623. navigationContext.Parameters.TryGetValue<CPDFViewer>(ParameterNames.PDFViewer, out PDFViewer);
  624. navigationContext.Parameters.TryGetValue<List<string>>(ParameterNames.FilePath, out filepath);
  625. if (filepath != null)
  626. {
  627. fileNames = filepath;
  628. PDFFileCount();
  629. updateListview("wait");
  630. CreateGridSpan = "1";
  631. CreateGridSpanVisibility = Visibility.Visible;
  632. EnterSelectedContent(TemplateListBaseName);
  633. }
  634. }
  635. public bool IsNavigationTarget(NavigationContext navigationContext)
  636. {
  637. return true;
  638. }
  639. public void OnNavigatedFrom(NavigationContext navigationContext)
  640. {
  641. }
  642. #endregion
  643. }
  644. }