BatesCreateContentViewModel.cs 25 KB

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