HomePageConverterDialogViewModel.cs 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656
  1. using ComPDFKit.PDFDocument;
  2. using ComPDFKit_Conversion.Converter;
  3. using Microsoft.Office.Interop.Excel;
  4. using Microsoft.Office.Interop.Word;
  5. using PDF_Office.CustomControl;
  6. using PDF_Office.Helper;
  7. using PDF_Office.Model;
  8. using PDF_Office.Model.Dialog.ConverterDialogs;
  9. using PDF_Office.Model.Dialog.HomePageToolsDialogs.HomePageBatchProcessing;
  10. using PDF_Office.Model.Dialog.HomePageToolsDialogs.HomePageBatchProcessing.HomePageConverter;
  11. using Prism.Commands;
  12. using Prism.Mvvm;
  13. using Prism.Regions;
  14. using Prism.Services.Dialogs;
  15. using System;
  16. using System.Collections.Generic;
  17. using System.Data;
  18. using System.Diagnostics;
  19. using System.IO;
  20. using System.Linq;
  21. using System.Reflection;
  22. using System.Windows;
  23. using System.Windows.Forms;
  24. using DataTable = System.Data.DataTable;
  25. namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs.HomePageBatchProcessing.HomePageConverter
  26. {
  27. public class HomePageConverterDialogViewModel : BindableBase, INavigationAware
  28. {
  29. #region 参数和属性
  30. private List<string> fileNames;
  31. public HomePageConverterCSVModel ConverterCSVModel = new HomePageConverterCSVModel();
  32. public HomePageConverterExcelModel ConverterExcelModel = new HomePageConverterExcelModel();
  33. public HomePageConverterHTMLModel ConverterHTMLModel = new HomePageConverterHTMLModel();
  34. public HomePageConverterImgModel ConverterImgModel = new HomePageConverterImgModel();
  35. public HomePageConverterPPTModel ConverterPPTModel = new HomePageConverterPPTModel();
  36. public HomePageConverterRTFModel ConverterRTFModel = new HomePageConverterRTFModel();
  37. public HomePageConverterTextModel ConverterTextModel = new HomePageConverterTextModel();
  38. public HomePageConverterWordModel ConverterWordModel = new HomePageConverterWordModel();
  39. private CPDFDocument tempDocument;
  40. public string PageNumber = "";
  41. public IRegionManager ConverterRegion;
  42. public IDialogService dialogs;
  43. public List<int> fileNamesView = new List<int>();
  44. private int fileNamesIndex = 0;
  45. private int FileNameNumber = 0;
  46. public List<string> ConverterTypeFamily { set; get; } = new List<string>();
  47. private void SetImageTypeOrigin()
  48. {
  49. this.ConverterTypeFamily.Add("Word");
  50. this.ConverterTypeFamily.Add("Excel");
  51. this.ConverterTypeFamily.Add("PPT");
  52. this.ConverterTypeFamily.Add("RTF");
  53. this.ConverterTypeFamily.Add("HTML");
  54. this.ConverterTypeFamily.Add("Text");
  55. this.ConverterTypeFamily.Add("CSV");
  56. this.ConverterTypeFamily.Add("Img");
  57. }
  58. private string converterGridIsEnabled = "True";
  59. public string ConverterGridIsEnabled
  60. {
  61. get
  62. {
  63. return converterGridIsEnabled;
  64. }
  65. set
  66. {
  67. SetProperty(ref converterGridIsEnabled, value);
  68. }
  69. }
  70. private string setConverterGridIsEnabled = "True";
  71. public string SetConverterGridIsEnabled
  72. {
  73. get
  74. {
  75. return setConverterGridIsEnabled;
  76. }
  77. set
  78. {
  79. SetProperty(ref setConverterGridIsEnabled, value);
  80. }
  81. }
  82. private DataTable pdfDataTable = new DataTable();
  83. public DataTable PDFDataTable
  84. {
  85. get { return pdfDataTable; }
  86. set
  87. {
  88. SetProperty(ref pdfDataTable, value);
  89. }
  90. }
  91. private DataTable pdfCurrentDataTable = new DataTable();
  92. public DataTable PDFCurrentDataTable
  93. {
  94. get { return pdfCurrentDataTable; }
  95. set
  96. {
  97. SetProperty(ref pdfCurrentDataTable, value);
  98. }
  99. }
  100. private string removeIsEnable = "False";
  101. public string RemoveIsEnable
  102. {
  103. get { return removeIsEnable; }
  104. set
  105. {
  106. SetProperty(ref removeIsEnable, value);
  107. }
  108. }
  109. private string selectFileName = "False";
  110. public string SelectFileName
  111. {
  112. get { return selectFileName; }
  113. set
  114. {
  115. SetProperty(ref selectFileName, value);
  116. }
  117. }
  118. private int converterTypeIndex = 0;
  119. public int ConverterTypeIndex
  120. {
  121. get { return converterTypeIndex; }
  122. set
  123. {
  124. SetProperty(ref converterTypeIndex, value);
  125. }
  126. }
  127. private string converterRegionName;
  128. public string ConverterRegionName
  129. {
  130. get
  131. {
  132. return converterRegionName;
  133. }
  134. set
  135. {
  136. SetProperty(ref converterRegionName, value);
  137. }
  138. }
  139. private Visibility converterVisible = Visibility.Collapsed;
  140. public Visibility ConverterVisible
  141. {
  142. get { return converterVisible; }
  143. set { SetProperty(ref converterVisible, value); }
  144. }
  145. private Visibility addFileVisibility = Visibility.Hidden;
  146. public Visibility AddFileVisibility
  147. {
  148. get { return addFileVisibility; }
  149. set
  150. {
  151. SetProperty(ref addFileVisibility, value);
  152. RaisePropertyChanged();
  153. }
  154. }
  155. #endregion
  156. #region 委托声明
  157. public DelegateCommand ADDPDFCommand { get; set; }
  158. public DelegateCommand RemovePDFFileCommand { get; set; }
  159. public DelegateCommand ConvertCommand { get; set; }
  160. public DelegateCommand ADDPDFFilesCommand { get; set; }
  161. #endregion
  162. public HomePageConverterDialogViewModel(IRegionManager converterRegion, IDialogService dialogs)
  163. {
  164. SetImageTypeOrigin();
  165. PDFCurrentDataTable.Columns.Add("FilePageRangeText");
  166. PDFCurrentDataTable.Columns.Add("FilePageRangeSelectIndex");
  167. PDFCurrentDataTable.Columns.Add("IsEvenPageIsEnabled");
  168. PDFCurrentDataTable.Columns.Add("FileState");
  169. PDFDataTable.Columns.Add("FileName");
  170. PDFDataTable.Columns.Add("FilePageRangeText");
  171. PDFDataTable.Columns.Add("FilePageRangeSelectIndex");
  172. PDFDataTable.Columns.Add("IsEvenPageIsEnabled");
  173. PDFDataTable.Columns.Add("MaxPageRange");
  174. PDFDataTable.Columns.Add("FileSize");
  175. PDFDataTable.Columns.Add("FileState");
  176. ADDPDFCommand = new DelegateCommand(addpicture);
  177. ADDPDFFilesCommand = new DelegateCommand(addpicturefiles);
  178. RemovePDFFileCommand = new DelegateCommand(removepdffile);
  179. ConvertCommand = new DelegateCommand(convert);
  180. ConverterRegion = converterRegion;
  181. this.dialogs = dialogs;
  182. ConverterRegionName=Guid.NewGuid().ToString();
  183. }
  184. #region 逻辑函数
  185. private void SetProgress(int pageIndex)
  186. {
  187. PDFDataTable.Rows[fileNamesIndex]["FileState"] = pageIndex.ToString();
  188. pageIndex.ToString();
  189. }
  190. private async void convert()
  191. {
  192. updateListview("wait");
  193. bool result = false;
  194. OnProgress GetProgress = null;
  195. GetProgress += SetProgress;
  196. fileNamesIndex = 0;
  197. ConverterGridIsEnabled = "False";
  198. foreach (var filename in fileNames)
  199. {
  200. FileInfo fileinfo = new FileInfo(filename);
  201. string OutputPath = fileinfo.DirectoryName;
  202. char[] enumerationSeparator = new char[] { ',' };
  203. char[] rangeSeparator = new char[] { '-' };
  204. List<int> PageIndexLists=new List<int>();
  205. CPDFDocument document = CPDFDocument.InitWithFilePath(filename);
  206. if (document == null )
  207. {
  208. PDFDataTable.Rows[fileNamesIndex]["FileState"] = "error";
  209. PDFCurrentDataTable.Rows[fileNamesIndex]["FileState"] = "error";
  210. fileNamesIndex++;
  211. continue;
  212. }
  213. string DocPassword = "";
  214. if (document.IsLocked)
  215. {
  216. DialogParameters value = new DialogParameters();
  217. value.Add(ParameterNames.PDFDocument, document);
  218. dialogs.ShowDialog(DialogNames.VerifyPassWordDialog, value, e =>
  219. {
  220. if (e.Result == ButtonResult.OK)
  221. {
  222. if (e.Parameters.ContainsKey(ParameterNames.PassWord) && e.Parameters.GetValue<string>(ParameterNames.PassWord) != null)
  223. {
  224. DocPassword = e.Parameters.GetValue<string>(ParameterNames.PassWord).ToString();
  225. document.UnlockWithPassword(DocPassword);
  226. }
  227. }
  228. });
  229. if (document.IsLocked)
  230. {
  231. //未成功解密文档时,释放Document对象,返回
  232. PDFDataTable.Rows[fileNamesIndex]["FileState"] = "error";
  233. PDFCurrentDataTable.Rows[fileNamesIndex]["FileState"] = "error";
  234. fileNamesIndex++;
  235. continue;
  236. }
  237. }
  238. string pageRange = getFilePageRange(document, PDFCurrentDataTable.Rows[fileNamesIndex]["FilePageRangeText"].ToString(), PDFCurrentDataTable.Rows[fileNamesIndex]["FilePageRangeSelectIndex"].ToString());
  239. if (!CommonHelper.GetPagesInRange(ref PageIndexLists, pageRange, document.PageCount, enumerationSeparator, rangeSeparator))
  240. { //TODO
  241. MessageBoxEx.Show("输入不对");
  242. PDFDataTable.Rows[fileNamesIndex]["FileState"] = "error";
  243. PDFCurrentDataTable.Rows[fileNamesIndex]["FileState"] = "error";
  244. fileNamesIndex++;
  245. continue;
  246. }
  247. for (int index=0; index< PageIndexLists.Count;index++) {
  248. PageIndexLists[index]++;
  249. }
  250. switch (ConverterTypeIndex)
  251. {
  252. case 0:
  253. if (ConverterWordModel != null)
  254. {
  255. PageNumber = ConverterWordModel.PageIndexLists.Count().ToString();
  256. result = await ConverterHelper.WordConvert(filename, OutputPath, GetProgress, PageIndexLists, DocPassword);
  257. }
  258. break;
  259. case 1:
  260. if (ConverterExcelModel != null)
  261. {
  262. PageNumber = ConverterExcelModel.PageIndexLists.Count().ToString();
  263. result = await ConverterHelper.ExcelConvert(filename, OutputPath, GetProgress, PageIndexLists, DocPassword, ConverterExcelModel.excelOption);
  264. }
  265. break;
  266. case 2:
  267. if (ConverterPPTModel != null)
  268. {
  269. PageNumber = ConverterPPTModel.PageIndexLists.Count().ToString();
  270. result = await ConverterHelper.PPTConvert(filename, OutputPath, GetProgress, PageIndexLists, DocPassword);
  271. }
  272. break;
  273. case 3:
  274. if (ConverterRTFModel != null)
  275. {
  276. PageNumber = ConverterRTFModel.PageIndexLists.Count().ToString();
  277. result = await ConverterHelper.RTFConvert(filename, OutputPath, GetProgress, PageIndexLists, DocPassword);
  278. }
  279. break;
  280. case 4:
  281. if (ConverterHTMLModel != null)
  282. {
  283. PageNumber = ConverterHTMLModel.PageIndexLists.Count().ToString();
  284. result = await ConverterHelper.HTMLConvert(filename, OutputPath, GetProgress, PageIndexLists, DocPassword, ConverterHTMLModel.HTMLOptions());
  285. }
  286. break;
  287. case 5:
  288. if (ConverterTextModel != null)
  289. {
  290. PageNumber = ConverterTextModel.PageIndexLists.Count().ToString();
  291. result = await ConverterHelper.TxtConvert(filename, OutputPath, GetProgress, PageIndexLists, DocPassword);
  292. }
  293. break;
  294. case 6:
  295. if (ConverterCSVModel != null)
  296. {
  297. PageNumber = ConverterCSVModel.PageIndexLists.Count().ToString();
  298. result = await ConverterHelper.CSVConvert(filename, OutputPath, GetProgress, PageIndexLists, DocPassword);
  299. }
  300. break;
  301. case 7:
  302. if (ConverterImgModel != null)
  303. {
  304. PageNumber = ConverterImgModel.PageIndexLists.Count().ToString();
  305. result = await ConverterHelper.ImgConvert(filename, OutputPath, GetProgress, PageIndexLists, DocPassword, ConverterImgModel.Type, ConverterImgModel.imageType);
  306. }
  307. break;
  308. default:
  309. break;
  310. }
  311. document.Release();
  312. if (!result) {
  313. PDFDataTable.Rows[fileNamesIndex]["FileState"] = "error";
  314. PDFCurrentDataTable.Rows[fileNamesIndex]["FileState"] = "error";
  315. fileNamesIndex++;
  316. continue;
  317. }
  318. PDFDataTable.Rows[fileNamesIndex]["FileState"] = "complete";
  319. PDFCurrentDataTable.Rows[fileNamesIndex]["FileState"] = "complete";
  320. fileNamesIndex++;
  321. }
  322. ConverterGridIsEnabled = "True";
  323. }
  324. #endregion
  325. #region 批量处理逻辑函数
  326. /// <summary>
  327. /// 添加PDF文件
  328. /// </summary>
  329. private void addpicture()
  330. {
  331. FileNameNumber = fileNames.Count;
  332. System.Windows.Forms.OpenFileDialog dlg = new System.Windows.Forms.OpenFileDialog();
  333. dlg.Multiselect = true;
  334. dlg.Filter = "PDF|*.pdf;*.PDF;";
  335. if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  336. {
  337. fileNames.AddRange(dlg.FileNames.ToList());
  338. RemoveExcess(ref fileNames);
  339. SetConverterGridIsEnabled = "True";
  340. AddFileVisibility = Visibility.Collapsed;
  341. updateListview("wait");
  342. }
  343. }
  344. public void addPDFFiles(string filename)
  345. {
  346. FileNameNumber = fileNames.Count;
  347. fileNames.Add(filename);
  348. RemoveExcess(ref fileNames);
  349. SetConverterGridIsEnabled = "True";
  350. AddFileVisibility = Visibility.Collapsed;
  351. updateListview("wait");
  352. }
  353. /// <summary>
  354. /// 删除重复的文件
  355. /// </summary>
  356. public void RemoveExcess(ref List<string> Filenames)
  357. {
  358. List<string> filenames = new List<string>();
  359. foreach (var fileName in Filenames)
  360. {
  361. if (!filenames.Contains(fileName))
  362. {
  363. filenames.Add(fileName);
  364. }
  365. }
  366. Filenames.Clear();
  367. Filenames = filenames;
  368. }
  369. /// <summary>
  370. /// 添加PDF文件夹
  371. /// </summary>
  372. private void addpicturefiles()
  373. {
  374. FileNameNumber = fileNames.Count;
  375. FolderBrowserDialog dialog = new FolderBrowserDialog();
  376. dialog.Description = "请选择文件路径";
  377. if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  378. {
  379. string foldPath = dialog.SelectedPath;
  380. var apps = System.IO.Directory.GetFiles(foldPath);
  381. foreach (string app in apps)
  382. {
  383. var fi = new FileInfo(app);
  384. if (fi.Extension == ".pdf" || fi.Extension == ".PDF")
  385. {
  386. fileNames.Add(app);
  387. }
  388. }
  389. RemoveExcess(ref fileNames);
  390. updateListview("wait");
  391. SetConverterGridIsEnabled = "True";
  392. AddFileVisibility = Visibility.Collapsed;
  393. }
  394. }
  395. /// <summary>
  396. /// 更新listview显示
  397. /// state 状态显示字符串
  398. /// </summary>
  399. public void updateListview(string state)
  400. {
  401. updateCurrentListview();
  402. DataTable pdfdatatable = new DataTable();
  403. pdfdatatable.Columns.Add("FileName");
  404. pdfdatatable.Columns.Add("FilePageRangeText");
  405. pdfdatatable.Columns.Add("FilePageRangeSelectIndex");
  406. pdfdatatable.Columns.Add("IsEvenPageIsEnabled");
  407. pdfdatatable.Columns.Add("MaxPageRange");
  408. pdfdatatable.Columns.Add("FileSize");
  409. pdfdatatable.Columns.Add("FileState");
  410. int datatableindex = 0;
  411. List<int> PageIndexLists = new List<int>();
  412. foreach (var fileName in fileNames)
  413. {
  414. string file_all = fileName;
  415. FileInfo f = new FileInfo(file_all);
  416. string file_size = (((float)f.Length) / 1024).ToString() + " K";
  417. if (!isEvenPage(fileName) && PDFCurrentDataTable.Rows[datatableindex]["FilePageRangeSelectIndex"].ToString() == "2")
  418. {
  419. PDFCurrentDataTable.Rows[datatableindex]["FilePageRangeSelectIndex"] = "0";
  420. }
  421. int pagecount = CPDFDocument.InitWithFilePath(fileName).PageCount;
  422. if (PDFCurrentDataTable.Rows[datatableindex]["FilePageRangeSelectIndex"].ToString() == "3" && !CommonHelper.GetPagesInRange(ref PageIndexLists, PDFCurrentDataTable.Rows[datatableindex]["FilePageRangeText"].ToString(), pagecount, new char[] { ',' }, new char[] { '-' }, true))
  423. {
  424. PDFCurrentDataTable.Rows[datatableindex]["FilePageRangeSelectIndex"] = "0";
  425. }
  426. pdfdatatable.Rows.Add(f.Name, PDFCurrentDataTable.Rows[datatableindex]["FilePageRangeText"], PDFCurrentDataTable.Rows[datatableindex]["FilePageRangeSelectIndex"], isEvenPage(fileName), pagecount, file_size, PDFCurrentDataTable.Rows[datatableindex]["FileState"]);
  427. datatableindex++;
  428. }
  429. PDFDataTable = pdfdatatable;
  430. HomePageBatchProcessingDialogModel.FilePaths = fileNames;
  431. }
  432. /// <summary>
  433. /// 更新Currentlistview显示
  434. /// pagerangetext 自定义页面范围字符串 pagerangeselectindex combobox下拉索引(0全部页面 1奇数页 2偶数页 3自定义页面)isevenpageisenabled 偶数页状态 state 状态显示字符串
  435. /// </summary>
  436. public void updateCurrentListview(string pagerangetext = "1", string pagerangeselectindex = "0", bool isevenpageisenabled = true, string state = "wait")
  437. {
  438. if (fileNames.Count >= FileNameNumber)
  439. {
  440. for (int i = 0; fileNames.Count - FileNameNumber > i; i++)
  441. {
  442. PDFCurrentDataTable.Rows.Add(pagerangetext, pagerangeselectindex, isevenpageisenabled, state);
  443. }
  444. }
  445. else
  446. {
  447. Reverseorder(ref fileNamesView);
  448. foreach (int filenamesview in fileNamesView)
  449. {
  450. PDFCurrentDataTable.Rows.RemoveAt(filenamesview);
  451. }
  452. }
  453. }
  454. /// <summary>
  455. /// 更新Currentlistview显示
  456. /// pagerangetext 自定义页面范围字符串 pagerangeselectindex combobox下拉索引(0全部页面 1奇数页 2偶数页 3自定义页面)
  457. /// </summary>
  458. public void updateFilesPageRange(string pagerangetext = "1", string pagerangeselectindex = "0")
  459. {
  460. for (int i = 0; fileNames.Count > i; i++)
  461. {
  462. PDFDataTable.Rows[i]["FilePageRangeText"] = pagerangetext;
  463. PDFDataTable.Rows[i]["FilePageRangeSelectIndex"] = pagerangeselectindex;
  464. PDFCurrentDataTable.Rows[i]["FilePageRangeText"] = pagerangetext;
  465. PDFCurrentDataTable.Rows[i]["FilePageRangeSelectIndex"] = pagerangeselectindex;
  466. }
  467. }
  468. /// <summary>
  469. /// 获取文件列表单个文件对应的页码范围
  470. /// document 文档对象 pagerangetext 自定义页面范围字符串 pagerangeselectindex combobox下拉索引(0全部页面 1奇数页 2偶数页 3自定义页面)
  471. /// </summary>
  472. public string getFilePageRange(CPDFDocument document, string pagerangetext = "1", string pagerangeselectindex = "0")
  473. {
  474. string filePageRange = "1";
  475. EditToolsHelper.GetPageRange(int.Parse(pagerangeselectindex), document, ref filePageRange, pagerangetext,true);
  476. return filePageRange;
  477. }
  478. /// <summary>
  479. /// 判断是否关闭偶数页
  480. /// document 文档对象 )
  481. /// </summary>
  482. public bool isEvenPage(string filename)
  483. {
  484. CPDFDocument document = CPDFDocument.InitWithFilePath(filename);
  485. bool isevenpage = false;
  486. if (document.PageCount > 1)
  487. {
  488. isevenpage = true;
  489. }
  490. document.Release();
  491. return isevenpage;
  492. }
  493. /// <summary>
  494. /// 逆序int类型集合
  495. /// </summary>
  496. public void Reverseorder(ref List<int> Numbers)
  497. {
  498. Numbers = Numbers.OrderBy(a => a).ToList();
  499. Numbers.Reverse();
  500. }
  501. /// <summary>
  502. /// 打开文件PDF
  503. /// </summary>
  504. public void openfiledialog()
  505. {
  506. foreach (int filenamesview in fileNamesView)
  507. {
  508. System.Diagnostics.Process.Start(fileNames[filenamesview]);
  509. }
  510. }
  511. /// <summary>
  512. /// 删除文件PDF
  513. /// </summary>
  514. public void removepdffile()
  515. {
  516. FileNameNumber = fileNames.Count;
  517. Reverseorder(ref fileNamesView);
  518. foreach (int filenamesview in fileNamesView)
  519. {
  520. //Trace.WriteLine(filenamesview);
  521. fileNames.Remove(fileNames[filenamesview]);
  522. }
  523. if (fileNames.Count < 1)
  524. {
  525. SetConverterGridIsEnabled = "False";
  526. AddFileVisibility = Visibility.Visible;
  527. }
  528. updateListview("wait");
  529. }
  530. public void removepdffile(int index)
  531. {
  532. PDFCurrentDataTable.Rows.RemoveAt(index);
  533. fileNames.Remove(fileNames[index]);
  534. if (fileNames.Count < 1)
  535. {
  536. SetConverterGridIsEnabled = "False";
  537. AddFileVisibility = Visibility.Visible;
  538. }
  539. updateListview("wait");
  540. }
  541. public void PDFFileCount()
  542. {
  543. if (fileNames.Count == 0)
  544. {
  545. SetConverterGridIsEnabled = "False";
  546. AddFileVisibility = Visibility.Visible;
  547. }
  548. else
  549. {
  550. SetConverterGridIsEnabled = "True";
  551. AddFileVisibility = Visibility.Collapsed;
  552. }
  553. }
  554. public void ChangeConverter(int index)
  555. {
  556. ConverterTypeIndex=index;
  557. NavigationParameters param = new NavigationParameters();
  558. param.Add(ParameterNames.ViewContentViewModel, this);
  559. if (index == 0 || index == 1 || index == 6 || index == 7)
  560. {
  561. ConverterVisible = Visibility.Collapsed;
  562. ConverterRegion.RequestNavigate(ConverterRegionName, HomePageConverterDialogModel.GetConverter[index], param);
  563. ConverterVisible = Visibility.Visible;
  564. }
  565. else { ConverterVisible = Visibility.Collapsed; }
  566. }
  567. #endregion
  568. #region 构架行为
  569. public void OnNavigatedTo(NavigationContext navigationContext)
  570. {
  571. List<string> filepath = new List<string>();
  572. int convertertypeindex=0;
  573. navigationContext.Parameters.TryGetValue<List<string>>(ParameterNames.FilePath, out filepath);
  574. navigationContext.Parameters.TryGetValue<int>("ConverterTypeIndex", out convertertypeindex);
  575. if (filepath != null)
  576. {
  577. fileNames = filepath;
  578. PDFFileCount();
  579. updateListview("wait");
  580. ChangeConverter(convertertypeindex);
  581. }
  582. }
  583. public bool IsNavigationTarget(NavigationContext navigationContext)
  584. {
  585. return true;
  586. }
  587. public void OnNavigatedFrom(NavigationContext navigationContext)
  588. {
  589. ConverterHelper.Clear();
  590. }
  591. #endregion
  592. }
  593. }