HomePageBatesCreateContentViewModel.cs 26 KB

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