HomePageBackgroundDialogViewModel.cs 28 KB

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