HomePageBatesCreateContentViewModel.cs 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743
  1. using ComPDFKitViewer.PdfViewer;
  2. using PDF_Master.EventAggregators;
  3. using PDF_Master.Helper;
  4. using PDF_Master.Model.EditTools.Bates;
  5. using PDF_Master.Model;
  6. using PDF_Master.Properties;
  7. using PDFSettings;
  8. using Prism.Commands;
  9. using Prism.Events;
  10. using Prism.Mvvm;
  11. using Prism.Regions;
  12. using System;
  13. using System.Collections.Generic;
  14. using System.IO;
  15. using System.Linq;
  16. using System.Windows.Media;
  17. using System.Windows;
  18. using ComPDFKit.PDFDocument;
  19. using ComPDFKitViewer;
  20. using Microsoft.Office.Interop.Word;
  21. using PDF_Master.Model.Dialog.HomePageToolsDialogs.HomePageBatchProcessing;
  22. using System.Diagnostics;
  23. namespace PDF_Master.ViewModels.Dialog.HomePageToolsDialogs.HomePageBatchProcessing.HomePageBates
  24. {
  25. public class HomePageBatesCreateContentViewModel : BindableBase, INavigationAware
  26. {
  27. private CPDFViewer PDFViewer;
  28. public BatesInfo BatesInfo = new BatesInfo();
  29. public BatesHeaderFooterItem TemplateBatesItem;
  30. public enum EnumCreateOrEdit
  31. {
  32. None,
  33. StatusCreate,
  34. StatusEdit
  35. }
  36. private List<string> _fontNameList = new List<string>();
  37. public List<string> FontNameList
  38. {
  39. get { return _fontNameList; }
  40. set
  41. {
  42. SetProperty(ref _fontNameList, value);
  43. }
  44. }
  45. private void InitFontNameList()
  46. {
  47. FontNameList.Clear();
  48. FontNameList.Add("Courier");
  49. FontNameList.Add("Courier-Bold");
  50. FontNameList.Add("Courier-Oblique");
  51. FontNameList.Add("Courier-BoldOblique");
  52. FontNameList.Add("Helvetica");
  53. FontNameList.Add("Helvetica-Bold");
  54. FontNameList.Add("Helvetica-Oblique");
  55. FontNameList.Add("Helvetica-BoldOblique");
  56. FontNameList.Add("Times-Roman");
  57. FontNameList.Add("Times-Bold");
  58. FontNameList.Add("Times-Italic");
  59. FontNameList.Add("Times-BoldItalic");
  60. }
  61. private int _fontNameSelectedIndex = 0;
  62. public int FontNameSelectedIndex
  63. {
  64. get { return _fontNameSelectedIndex; }
  65. set
  66. {
  67. SetProperty(ref _fontNameSelectedIndex, value);
  68. SetFontName(FontNameSelectedIndex);
  69. }
  70. }
  71. private List<string> _fontSizeList = new List<string>();
  72. public List<string> FontSizeList
  73. {
  74. get { return _fontSizeList; }
  75. set
  76. {
  77. SetProperty(ref _fontSizeList, value);
  78. }
  79. }
  80. private void InitFontSizeList()
  81. {
  82. FontSizeList.Clear();
  83. for (int temp = 10; temp <= 15; temp += 1)
  84. {
  85. FontSizeList.Add(temp.ToString() + "pt");
  86. }
  87. }
  88. private int _fontSizeSelectedIndex = 0;
  89. public int FontSizeSelectedIndex
  90. {
  91. get { return _fontSizeSelectedIndex; }
  92. set
  93. {
  94. SetProperty(ref _fontSizeSelectedIndex, value);
  95. SetFontSize(FontSizeSelectedIndex);
  96. }
  97. }
  98. private List<string> _starPagetNumberList = new List<string>();
  99. public List<string> StarPagetNumberList
  100. {
  101. get { return _starPagetNumberList; }
  102. set
  103. {
  104. SetProperty(ref _starPagetNumberList, value);
  105. }
  106. }
  107. private void InitStarPagetNumberList()
  108. {
  109. StarPagetNumberList.Clear();
  110. for (int temp = 1; temp <= 999; temp += 1)
  111. {
  112. StarPagetNumberList.Add(temp.ToString());
  113. }
  114. }
  115. private int _starPagetNumberIndex = 0;
  116. public int StarPagetNumberIndex
  117. {
  118. get { return _starPagetNumberIndex; }
  119. set
  120. {
  121. SetProperty(ref _starPagetNumberIndex, value);
  122. SetStarPagetNumber(StarPagetNumberIndex);
  123. }
  124. }
  125. public string _pageRangeText = "0";
  126. public string PageRangeText
  127. {
  128. get { return _pageRangeText; }
  129. set
  130. {
  131. _pageRangeText = value;
  132. BatesInfo.PageRange =PageRangeText;
  133. //CommonHelper.GetPagesInRange(ref PageIndexLists, PageRangeText, 99999, new char[] { ',' }, new char[] { '-' });
  134. //foreach (var a in PageIndexLists) {
  135. // Trace.WriteLine("页面范围:" + a);
  136. //}
  137. //CommonHelper.GetPagesInRange(ref PageIndexLists, BatesInfo.PageRange, , new char[] { ',' }, new char[] { '-' }, true))
  138. //EditToolsHelper.GetPageRange(PageRangeSelectIndex, PDFViewer.Document, ref BatesInfo.PageRange, PageRangeText);
  139. }
  140. }
  141. private int _pageRangeSelectIndex = 0;
  142. public int PageRangeSelectIndex
  143. {
  144. get { return _pageRangeSelectIndex; }
  145. set
  146. {
  147. SetProperty(ref _pageRangeSelectIndex, value);
  148. BatesInfo.PageRangeIndex = PageRangeSelectIndex;
  149. //EditToolsHelper.GetPageRange(PageRangeSelectIndex, PDFViewer.Document, ref BatesInfo.PageRange, PageRangeText);
  150. }
  151. }
  152. private SolidColorBrush _solidColorBrush = new SolidColorBrush(Color.FromArgb(0xFF, 0xFF, 0x00, 0x00));
  153. public SolidColorBrush SolidColorBrush
  154. {
  155. get
  156. {
  157. return _solidColorBrush;
  158. }
  159. set
  160. {
  161. SetProperty(ref _solidColorBrush, value);
  162. }
  163. }
  164. private Color _stringColor = Color.FromArgb(0xFF, 0xFF, 0x00, 0x00);
  165. public Color StringColor
  166. {
  167. get
  168. {
  169. return _stringColor;
  170. }
  171. set
  172. {
  173. SetProperty(ref _stringColor, value);
  174. SolidColorBrush = new SolidColorBrush(StringColor);
  175. for (int i = 0; i <= 5; i++)
  176. {
  177. BatesInfo.TextData[i].Color = EditToolsHelper.ConvertColor(value);
  178. }
  179. }
  180. }
  181. private EnumCreateOrEdit _createOrEdit;
  182. public EnumCreateOrEdit CreateOrEdit
  183. {
  184. get { return _createOrEdit; }
  185. set
  186. {
  187. _createOrEdit = value;
  188. if (value == EnumCreateOrEdit.StatusEdit)
  189. {
  190. EditBaseVisible = Visibility.Visible;
  191. CreateBaseVisible = Visibility.Collapsed;
  192. }
  193. else if (value == EnumCreateOrEdit.StatusCreate)
  194. {
  195. CreateBaseVisible = Visibility.Visible;
  196. EditBaseVisible = Visibility.Collapsed;
  197. }
  198. }
  199. }
  200. private Visibility _createBaseVisible;
  201. public Visibility CreateBaseVisible
  202. {
  203. get => _createBaseVisible;
  204. set => SetProperty(ref _createBaseVisible, value);
  205. }
  206. private Visibility _editBaseVisible;
  207. public Visibility EditBaseVisible
  208. {
  209. get => _editBaseVisible;
  210. set => SetProperty(ref _editBaseVisible, value);
  211. }
  212. private string _marginTopValue = "3";
  213. public string MarginTopValue
  214. {
  215. get { return _marginTopValue; }
  216. set
  217. {
  218. SetProperty(ref _marginTopValue, value);
  219. bool ValueEQ = true;
  220. if (BatesInfo.margin[1] == float.Parse(MarginTopValue))
  221. {
  222. ValueEQ = false;
  223. }
  224. BatesInfo.margin[1] = float.Parse(MarginTopValue);
  225. if (ValueEQ)
  226. {
  227. }
  228. }
  229. }
  230. private string _marginDownValue = "3";
  231. public string MarginDownValue
  232. {
  233. get { return _marginDownValue; }
  234. set
  235. {
  236. SetProperty(ref _marginDownValue, value);
  237. bool ValueEQ = true;
  238. if (BatesInfo.margin[3] == float.Parse(MarginTopValue))
  239. {
  240. ValueEQ = false;
  241. }
  242. BatesInfo.margin[3] = float.Parse(MarginDownValue);
  243. if (ValueEQ)
  244. {
  245. }
  246. }
  247. }
  248. private string _marginLeftValue = "3";
  249. public string MarginLeftValue
  250. {
  251. get { return _marginLeftValue; }
  252. set
  253. {
  254. SetProperty(ref _marginLeftValue, value);
  255. bool ValueEQ = true;
  256. if (BatesInfo.margin[0] == float.Parse(MarginTopValue))
  257. {
  258. ValueEQ = false;
  259. }
  260. BatesInfo.margin[0] = float.Parse(MarginLeftValue);
  261. if (ValueEQ)
  262. {
  263. }
  264. }
  265. }
  266. private string _marginRightValue = "3";
  267. public string MarginRightValue
  268. {
  269. get { return _marginRightValue; }
  270. set
  271. {
  272. SetProperty(ref _marginRightValue, value);
  273. bool ValueEQ = true;
  274. if (BatesInfo.margin[2] == float.Parse(MarginTopValue))
  275. {
  276. ValueEQ = false;
  277. }
  278. if (ValueEQ)
  279. {
  280. BatesInfo.margin[2] = float.Parse(MarginRightValue);
  281. }
  282. }
  283. }
  284. private string _digitNumberValue = "1";
  285. public string DigitNumberValue
  286. {
  287. get { return _digitNumberValue; }
  288. set
  289. {
  290. SetProperty(ref _digitNumberValue, value);
  291. BatesInfo.DigitNumber = int.Parse(DigitNumberValue);
  292. }
  293. }
  294. private string _textValue = "";
  295. public string TextValue
  296. {
  297. get { return _textValue; }
  298. set
  299. {
  300. SetProperty(ref _textValue, value);
  301. }
  302. }
  303. private string _prefixTextValue = "";
  304. public string PrefixTextValue
  305. {
  306. get { return _prefixTextValue; }
  307. set
  308. {
  309. _prefixTextValue = value;
  310. }
  311. }
  312. private string _surfixTextValue = "";
  313. public string SurfixTextValue
  314. {
  315. get { return _surfixTextValue; }
  316. set
  317. {
  318. _surfixTextValue = value;
  319. }
  320. }
  321. public int GetLocationIndex = 0;
  322. private Dictionary<string, string> _getTextValueFromNumber = new Dictionary<string, string>();
  323. public Dictionary<string, string> GetTextValueFromNumber
  324. {
  325. get { return _getTextValueFromNumber; }
  326. set
  327. {
  328. _getTextValueFromNumber = value;
  329. }
  330. }
  331. public IEventAggregator eventAggregator;
  332. public DelegateCommand<object> ChangeLocationCommand { get; set; }
  333. public DelegateCommand EnterTemplateListCommand { get; set; }
  334. public DelegateCommand SaveToTemplateListCommand { get; set; }
  335. public DelegateCommand SaveToCurrentTemplateListCommand { get; set; }
  336. public DelegateCommand<object> SelectedColorChangedCommand { get; set; }
  337. public DelegateCommand<object> TextValueChangedCommand { get; set; }
  338. public DelegateCommand ADDBatesCommand { get; set; }
  339. public string Unicode = null;
  340. public HomePageBatesCreateContentViewModel(IEventAggregator eventAggregator)
  341. {
  342. this.eventAggregator = eventAggregator;
  343. for (int i = 0; i <= 5; i++)
  344. {
  345. BatesInfo.TextData[i].Color = EditToolsHelper.ConvertColor(Color.FromArgb(0xFF, 0xFF, 0x00, 0x00));
  346. }
  347. InitList();
  348. InitBatesInfo();
  349. ChangeLocationCommand = new DelegateCommand<object>(ChangeLocation);
  350. SelectedColorChangedCommand = new DelegateCommand<object>(ChangedColor);
  351. EnterTemplateListCommand = new DelegateCommand(EnterTemplateList);
  352. SaveToTemplateListCommand = new DelegateCommand(SaveToTemplateList);
  353. SaveToCurrentTemplateListCommand = new DelegateCommand(SaveToCurrentTemplateList);
  354. TextValueChangedCommand = new DelegateCommand<object>(TextValueChanged);
  355. ADDBatesCommand = new DelegateCommand(ADDBates);
  356. }
  357. private void InitList()
  358. {
  359. InitFontNameList();
  360. InitFontSizeList();
  361. InitStarPagetNumberList();
  362. InitLocationButtonMatrix();
  363. }
  364. private void InitLocationButtonMatrix()
  365. {
  366. GetTextValueFromNumber.Clear();
  367. for (var temp = 0; temp <= 5; temp++)
  368. {
  369. GetTextValueFromNumber.Add(temp.ToString(), temp.ToString());
  370. }
  371. }
  372. private void InitBatesInfo()
  373. {
  374. for (int i = 0; i <= 5; i++)
  375. {
  376. BatesInfo.TextData[i].text = GetTextValueFromNumber[i.ToString()];
  377. }
  378. BatesInfo.margin[0] = float.Parse(MarginTopValue);
  379. BatesInfo.margin[1] = float.Parse(MarginRightValue);
  380. BatesInfo.margin[2] = float.Parse(MarginDownValue);
  381. BatesInfo.margin[3] = float.Parse(MarginLeftValue);
  382. BatesInfo.Prefix = PrefixTextValue;
  383. BatesInfo.Suffix = SurfixTextValue;
  384. BatesInfo.DigitNumber = int.Parse(DigitNumberValue);
  385. SetFontName(FontNameSelectedIndex);
  386. SetFontSize(FontSizeSelectedIndex);
  387. SetStarPagetNumber(StarPagetNumberIndex);
  388. StringColor = Color.FromArgb(0xFF, 0xFF, 0x00, 0x00);
  389. }
  390. private void SetFontName(int Index)
  391. {
  392. for (int i = 0; i <= 5; i++) { BatesInfo.TextData[i].fontName = FontNameList[Index]; }
  393. }
  394. private void SetFontSize(int Index)
  395. {
  396. for (int i = 0; i <= 5; i++) { BatesInfo.TextData[i].fontSize = (Index + 7) * 1.33f; }
  397. }
  398. private void SetStarPagetNumber(int Index)
  399. {
  400. BatesInfo.StarPagetNumber = Index;
  401. }
  402. public void ChangeLocation(object e)
  403. {
  404. string args = e as string;
  405. if (args != null)
  406. {
  407. GetLocationIndex = int.Parse(args);
  408. TextValue = GetTextValueFromNumber[args];
  409. }
  410. }
  411. private void ChangedColor(object obj)
  412. {
  413. if (obj != null)
  414. {
  415. var colorValue = (Color)obj;
  416. if (colorValue != null)
  417. {
  418. StringColor = colorValue;
  419. }
  420. }
  421. }
  422. public void EnterTemplateList()
  423. {
  424. this.eventAggregator.GetEvent<EnterTemplateListOrCreateEvent>().Publish(new EnumTemplateListOrCreateUnicode { Unicode = Unicode, Status = EnumTemplateListOrCreate.StatusTemplate });
  425. }
  426. public void SaveToTemplateList()
  427. {
  428. SaveCurrentTemplate();
  429. }
  430. public void SaveToCurrentTemplateList()
  431. {
  432. ConfirmEditBackgroundTemplateItem();
  433. }
  434. private void TextValueChanged(object obj)
  435. {
  436. if (obj != null)
  437. {
  438. var textValue = obj as System.Windows.Controls.TextBox;
  439. if (textValue != null)
  440. {
  441. bool TextEQ = true;
  442. switch (textValue.Name)
  443. {
  444. case "TextValueTextBox":
  445. if (GetTextValueFromNumber[GetLocationIndex.ToString()] == textValue.Text)
  446. {
  447. TextEQ = false;
  448. }
  449. GetTextValueFromNumber[GetLocationIndex.ToString()] = textValue.Text;
  450. BatesInfo.TextData[GetLocationIndex].text = GetTextValueFromNumber[GetLocationIndex.ToString()];
  451. break;
  452. case "PrefixTextValueTextBox":
  453. if (BatesInfo.Prefix == textValue.Text)
  454. {
  455. TextEQ = false;
  456. }
  457. BatesInfo.Prefix = textValue.Text;
  458. PrefixTextValue = textValue.Text;
  459. break;
  460. case "SuffixTextValueTextBox":
  461. if (BatesInfo.Suffix == textValue.Text)
  462. {
  463. TextEQ = false;
  464. }
  465. BatesInfo.Suffix = textValue.Text;
  466. SurfixTextValue = textValue.Text;
  467. break;
  468. default:
  469. break;
  470. }
  471. if (TextEQ)
  472. {
  473. }
  474. }
  475. }
  476. }
  477. public void ADDBates()
  478. {
  479. if (PrefixTextValue == "" || SurfixTextValue == "")
  480. {
  481. if (SurfixTextValue == "" && PrefixTextValue == "")
  482. {
  483. GetTextValueFromNumber[GetLocationIndex.ToString()] = GetTextValueFromNumber[GetLocationIndex.ToString()] + "<<" + "#" + DigitNumberValue + "#" + (StarPagetNumberIndex + 1).ToString() + ">>";
  484. }
  485. else if (SurfixTextValue == "")
  486. {
  487. GetTextValueFromNumber[GetLocationIndex.ToString()] = GetTextValueFromNumber[GetLocationIndex.ToString()] + "<<" + "#" + DigitNumberValue + "#" + (StarPagetNumberIndex + 1).ToString() + "#" + PrefixTextValue + ">>";
  488. }
  489. else
  490. {
  491. GetTextValueFromNumber[GetLocationIndex.ToString()] = GetTextValueFromNumber[GetLocationIndex.ToString()] + "<<" + "#" + DigitNumberValue + "#" + (StarPagetNumberIndex + 1).ToString() + "#" + "#" + SurfixTextValue + ">>";
  492. }
  493. }
  494. else
  495. {
  496. GetTextValueFromNumber[GetLocationIndex.ToString()] = GetTextValueFromNumber[GetLocationIndex.ToString()] + "<<" + "#" + DigitNumberValue + "#" + (StarPagetNumberIndex + 1).ToString() + "#" + PrefixTextValue + "#" + SurfixTextValue + ">>";
  497. }
  498. TextValue = GetTextValueFromNumber[GetLocationIndex.ToString()];
  499. BatesInfo.TextData[GetLocationIndex].text = GetTextValueFromNumber[GetLocationIndex.ToString()];
  500. }
  501. public void ConvertInfoToItem(ref BatesHeaderFooterItem batesItem, BatesInfo batesInfo)
  502. {
  503. batesItem.TextData = batesInfo.TextData;
  504. batesItem.DigitNumber = batesInfo.DigitNumber;
  505. batesItem.ItemName = batesInfo.ItemName;
  506. batesItem.Prefix = batesInfo.Prefix;
  507. batesItem.Suffix = batesInfo.Suffix;
  508. batesItem.StarPagetNumber = batesInfo.StarPagetNumber;
  509. batesItem.margin = batesInfo.margin;
  510. batesItem.PageRange = batesInfo.PageRange;
  511. List<int> PageIndexLists = new List<int>();
  512. if (PageRangeSelectIndex == 3 && !CommonHelper.GetPagesInRange(ref PageIndexLists, BatesInfo.PageRange, 9999, new char[] { ',' }, new char[] { '-' }))
  513. {
  514. batesInfo.PageRangeIndex = 0;
  515. }
  516. batesItem.PageRangeIndex = batesInfo.PageRangeIndex;
  517. }
  518. public void ConvertItemToInfo(BatesHeaderFooterItem batesItem, ref BatesInfo batesInfo)
  519. {
  520. batesInfo.TextData = batesItem.TextData;
  521. batesInfo.ItemName = batesItem.ItemName;
  522. batesInfo.DigitNumber = batesItem.DigitNumber;
  523. batesInfo.Prefix = batesItem.Prefix;
  524. batesInfo.Suffix = batesItem.Suffix;
  525. batesInfo.StarPagetNumber = batesItem.StarPagetNumber;
  526. batesInfo.margin = batesItem.margin;
  527. batesInfo.PageRangeIndex = batesItem.PageRangeIndex;
  528. batesInfo.PageRange=batesItem.PageRange;
  529. //EditToolsHelper.GetPageRange(batesInfo.PageRangeIndex, PDFViewer.Document, ref batesInfo.PageRange, batesItem.PageRange);
  530. }
  531. public void SaveCurrentTemplate()
  532. {
  533. var batesItem = new BatesHeaderFooterItem();
  534. ConvertInfoToItem(ref batesItem, BatesInfo);
  535. batesItem.ItemName += Settings.Default.BatesTemplateList.Count().ToString();
  536. try
  537. {
  538. //创建缓存文件夹
  539. string folderPath = Path.Combine(App.CurrentPath, "Bates");
  540. //有可能因为其他原因存在同名文件,导致创建文件夹失败,需要先删除同名文件
  541. //保险措施(猜测)
  542. if (File.Exists(folderPath))
  543. {
  544. File.Delete(folderPath);
  545. }
  546. DirectoryInfo tempfolder = new DirectoryInfo(folderPath);
  547. if (!tempfolder.Exists)
  548. {
  549. tempfolder.Create();
  550. }
  551. //预览图缓存
  552. string saveName = Guid.NewGuid().ToString();
  553. string savePath = Path.Combine(folderPath, saveName);
  554. Settings.Default.BatesTemplateList.Add(batesItem);
  555. Settings.Default.Save();
  556. }
  557. catch
  558. {
  559. }
  560. this.eventAggregator.GetEvent<EnterTemplateListOrCreateEvent>().Publish(new EnumTemplateListOrCreateUnicode
  561. {
  562. Unicode = Unicode,
  563. Status = EnumTemplateListOrCreate.StatusTemplate
  564. });
  565. }
  566. public void ConfirmEditBackgroundTemplateItem()
  567. {
  568. var batesItem = new BatesHeaderFooterItem();
  569. ConvertInfoToItem(ref batesItem, BatesInfo);
  570. try
  571. {
  572. //创建缓存文件夹
  573. string folderPath = Path.Combine(App.CurrentPath, "Background");
  574. //有可能因为其他原因存在同名文件,导致创建文件夹失败,需要先删除同名文件
  575. //保险措施(猜测)
  576. if (File.Exists(folderPath))
  577. {
  578. File.Delete(folderPath);
  579. }
  580. DirectoryInfo tempfolder = new DirectoryInfo(folderPath);
  581. if (!tempfolder.Exists)
  582. {
  583. tempfolder.Create();
  584. }
  585. Settings.Default.BatesTemplateList[TemplateBatesItem.listIndex] = batesItem;
  586. Settings.Default.Save();
  587. }
  588. catch
  589. {
  590. }
  591. this.eventAggregator.GetEvent<EnterTemplateListOrCreateEvent>().Publish(new EnumTemplateListOrCreateUnicode
  592. {
  593. Unicode = Unicode,
  594. Status = EnumTemplateListOrCreate.StatusTemplate
  595. });
  596. }
  597. public void InitComponentBySelectedInfo()
  598. {
  599. ConvertItemToInfo(TemplateBatesItem, ref BatesInfo);
  600. for (int i = 0; i <= 5; i++)
  601. {
  602. GetTextValueFromNumber[i.ToString()] = BatesInfo.TextData[i].text;
  603. }
  604. MarginTopValue = BatesInfo.margin[0].ToString();
  605. MarginRightValue = BatesInfo.margin[1].ToString();
  606. MarginDownValue = BatesInfo.margin[2].ToString();
  607. MarginLeftValue = BatesInfo.margin[3].ToString();
  608. PrefixTextValue = BatesInfo.Prefix;
  609. SurfixTextValue = BatesInfo.Suffix;
  610. DigitNumberValue = BatesInfo.DigitNumber.ToString();
  611. FontNameSelectedIndex = FontNameList.IndexOf(BatesInfo.TextData[0].fontName);
  612. FontSizeSelectedIndex = FontSizeList.IndexOf(BatesInfo.TextData[0].fontSize.ToString());
  613. StarPagetNumberIndex = StarPagetNumberList.IndexOf(BatesInfo.StarPagetNumber.ToString());
  614. StringColor = EditToolsHelper.ConvertColor(BatesInfo.TextData[0].Color);
  615. SolidColorBrush = new SolidColorBrush(StringColor);
  616. PageRangeSelectIndex = BatesInfo.PageRangeIndex;
  617. PageRangeText = BatesInfo.PageRange;
  618. }
  619. public bool IsNavigationTarget(NavigationContext navigationContext)
  620. {
  621. return true;
  622. }
  623. public void OnNavigatedFrom(NavigationContext navigationContext)
  624. {
  625. }
  626. public void OnNavigatedTo(NavigationContext navigationContext)
  627. {
  628. navigationContext.Parameters.TryGetValue<CPDFViewer>(ParameterNames.PDFViewer, out PDFViewer);
  629. //EditToolsHelper.GetPageRange(PageRangeSelectIndex, PDFViewer.Document, ref BatesInfo.PageRange, PageRangeText);
  630. navigationContext.Parameters.TryGetValue<string>("Unicode", out Unicode);
  631. if (navigationContext.Parameters.TryGetValue<BatesHeaderFooterItem>("BatesItem", out TemplateBatesItem))
  632. {
  633. CreateOrEdit = EnumCreateOrEdit.StatusEdit;
  634. InitComponentBySelectedInfo();
  635. }
  636. else
  637. {
  638. CreateOrEdit = EnumCreateOrEdit.StatusCreate;
  639. BatesInfo.PageRange = "";
  640. }
  641. }
  642. }
  643. }