HomePageBatesCreateContentViewModel.cs 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740
  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. _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. Unicode = App.mainWindowViewModel.SelectedItem.Unicode;
  344. for (int i = 0; i <= 5; i++)
  345. {
  346. BatesInfo.TextData[i].Color = EditToolsHelper.ConvertColor(Color.FromArgb(0xFF, 0xFF, 0x00, 0x00));
  347. }
  348. InitList();
  349. InitBatesInfo();
  350. ChangeLocationCommand = new DelegateCommand<object>(ChangeLocation);
  351. SelectedColorChangedCommand = new DelegateCommand<object>(ChangedColor);
  352. EnterTemplateListCommand = new DelegateCommand(EnterTemplateList);
  353. SaveToTemplateListCommand = new DelegateCommand(SaveToTemplateList);
  354. SaveToCurrentTemplateListCommand = new DelegateCommand(SaveToCurrentTemplateList);
  355. TextValueChangedCommand = new DelegateCommand<object>(TextValueChanged);
  356. ADDBatesCommand = new DelegateCommand(ADDBates);
  357. }
  358. private void InitList()
  359. {
  360. InitFontNameList();
  361. InitFontSizeList();
  362. InitStarPagetNumberList();
  363. InitLocationButtonMatrix();
  364. }
  365. private void InitLocationButtonMatrix()
  366. {
  367. GetTextValueFromNumber.Clear();
  368. for (var temp = 0; temp <= 5; temp++)
  369. {
  370. GetTextValueFromNumber.Add(temp.ToString(), temp.ToString());
  371. }
  372. }
  373. private void InitBatesInfo()
  374. {
  375. for (int i = 0; i <= 5; i++)
  376. {
  377. BatesInfo.TextData[i].text = GetTextValueFromNumber[i.ToString()];
  378. }
  379. BatesInfo.margin[0] = float.Parse(MarginTopValue);
  380. BatesInfo.margin[1] = float.Parse(MarginRightValue);
  381. BatesInfo.margin[2] = float.Parse(MarginDownValue);
  382. BatesInfo.margin[3] = float.Parse(MarginLeftValue);
  383. BatesInfo.Prefix = PrefixTextValue;
  384. BatesInfo.Suffix = SurfixTextValue;
  385. BatesInfo.DigitNumber = int.Parse(DigitNumberValue);
  386. SetFontName(FontNameSelectedIndex);
  387. SetFontSize(FontSizeSelectedIndex);
  388. SetStarPagetNumber(StarPagetNumberIndex);
  389. StringColor = Color.FromArgb(0xFF, 0xFF, 0x00, 0x00);
  390. }
  391. private void SetFontName(int Index)
  392. {
  393. for (int i = 0; i <= 5; i++) { BatesInfo.TextData[i].fontName = FontNameList[Index]; }
  394. }
  395. private void SetFontSize(int Index)
  396. {
  397. for (int i = 0; i <= 5; i++) { BatesInfo.TextData[i].fontSize = (Index + 7) * 1.33f; }
  398. }
  399. private void SetStarPagetNumber(int Index)
  400. {
  401. BatesInfo.StarPagetNumber = Index;
  402. }
  403. public void ChangeLocation(object e)
  404. {
  405. string args = e as string;
  406. if (args != null)
  407. {
  408. GetLocationIndex = int.Parse(args);
  409. TextValue = GetTextValueFromNumber[args];
  410. }
  411. }
  412. private void ChangedColor(object obj)
  413. {
  414. if (obj != null)
  415. {
  416. var colorValue = (Color)obj;
  417. if (colorValue != null)
  418. {
  419. StringColor = colorValue;
  420. }
  421. }
  422. }
  423. public void EnterTemplateList()
  424. {
  425. this.eventAggregator.GetEvent<EnterTemplateListOrCreateEvent>().Publish(new EnumTemplateListOrCreateUnicode { Unicode = Unicode, Status = EnumTemplateListOrCreate.StatusTemplate });
  426. }
  427. public void SaveToTemplateList()
  428. {
  429. SaveCurrentTemplate();
  430. }
  431. public void SaveToCurrentTemplateList()
  432. {
  433. ConfirmEditBackgroundTemplateItem();
  434. }
  435. private void TextValueChanged(object obj)
  436. {
  437. if (obj != null)
  438. {
  439. var textValue = obj as System.Windows.Controls.TextBox;
  440. if (textValue != null)
  441. {
  442. bool TextEQ = true;
  443. switch (textValue.Name)
  444. {
  445. case "TextValueTextBox":
  446. if (GetTextValueFromNumber[GetLocationIndex.ToString()] == textValue.Text)
  447. {
  448. TextEQ = false;
  449. }
  450. GetTextValueFromNumber[GetLocationIndex.ToString()] = textValue.Text;
  451. BatesInfo.TextData[GetLocationIndex].text = GetTextValueFromNumber[GetLocationIndex.ToString()];
  452. break;
  453. case "PrefixTextValueTextBox":
  454. if (BatesInfo.Prefix == textValue.Text)
  455. {
  456. TextEQ = false;
  457. }
  458. BatesInfo.Prefix = textValue.Text;
  459. PrefixTextValue = textValue.Text;
  460. break;
  461. case "SuffixTextValueTextBox":
  462. if (BatesInfo.Suffix == textValue.Text)
  463. {
  464. TextEQ = false;
  465. }
  466. BatesInfo.Suffix = textValue.Text;
  467. SurfixTextValue = textValue.Text;
  468. break;
  469. default:
  470. break;
  471. }
  472. if (TextEQ)
  473. {
  474. }
  475. }
  476. }
  477. }
  478. public void ADDBates()
  479. {
  480. if (PrefixTextValue == "" || SurfixTextValue == "")
  481. {
  482. if (SurfixTextValue == "" && PrefixTextValue == "")
  483. {
  484. GetTextValueFromNumber[GetLocationIndex.ToString()] = GetTextValueFromNumber[GetLocationIndex.ToString()] + "<<" + "#" + DigitNumberValue + "#" + (StarPagetNumberIndex + 1).ToString() + ">>";
  485. }
  486. else if (SurfixTextValue == "")
  487. {
  488. GetTextValueFromNumber[GetLocationIndex.ToString()] = GetTextValueFromNumber[GetLocationIndex.ToString()] + "<<" + "#" + DigitNumberValue + "#" + (StarPagetNumberIndex + 1).ToString() + "#" + PrefixTextValue + ">>";
  489. }
  490. else
  491. {
  492. GetTextValueFromNumber[GetLocationIndex.ToString()] = GetTextValueFromNumber[GetLocationIndex.ToString()] + "<<" + "#" + DigitNumberValue + "#" + (StarPagetNumberIndex + 1).ToString() + "#" + "#" + SurfixTextValue + ">>";
  493. }
  494. }
  495. else
  496. {
  497. GetTextValueFromNumber[GetLocationIndex.ToString()] = GetTextValueFromNumber[GetLocationIndex.ToString()] + "<<" + "#" + DigitNumberValue + "#" + (StarPagetNumberIndex + 1).ToString() + "#" + PrefixTextValue + "#" + SurfixTextValue + ">>";
  498. }
  499. TextValue = GetTextValueFromNumber[GetLocationIndex.ToString()];
  500. BatesInfo.TextData[GetLocationIndex].text = GetTextValueFromNumber[GetLocationIndex.ToString()];
  501. }
  502. public void ConvertInfoToItem(ref BatesHeaderFooterItem batesItem, BatesInfo batesInfo)
  503. {
  504. batesItem.TextData = batesInfo.TextData;
  505. batesItem.DigitNumber = batesInfo.DigitNumber;
  506. batesItem.ItemName = batesInfo.ItemName;
  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. List<int> PageIndexLists = new List<int>();
  513. if (PageRangeSelectIndex == 3 && !CommonHelper.GetPagesInRange(ref PageIndexLists, BatesInfo.PageRange, 9999, new char[] { ',' }, new char[] { '-' }))
  514. {
  515. batesInfo.PageRangeIndex = 0;
  516. }
  517. batesItem.PageRangeIndex = batesInfo.PageRangeIndex;
  518. }
  519. public void ConvertItemToInfo(BatesHeaderFooterItem batesItem, ref BatesInfo batesInfo)
  520. {
  521. batesInfo.TextData = batesItem.TextData;
  522. batesInfo.ItemName = batesItem.ItemName;
  523. batesInfo.DigitNumber = batesItem.DigitNumber;
  524. batesInfo.Prefix = batesItem.Prefix;
  525. batesInfo.Suffix = batesItem.Suffix;
  526. batesInfo.StarPagetNumber = batesItem.StarPagetNumber;
  527. batesInfo.margin = batesItem.margin;
  528. batesInfo.PageRangeIndex = batesItem.PageRangeIndex;
  529. batesInfo.PageRange=batesItem.PageRange;
  530. //EditToolsHelper.GetPageRange(batesInfo.PageRangeIndex, PDFViewer.Document, ref batesInfo.PageRange, batesItem.PageRange);
  531. }
  532. public void SaveCurrentTemplate()
  533. {
  534. var batesItem = new BatesHeaderFooterItem();
  535. ConvertInfoToItem(ref batesItem, BatesInfo);
  536. batesItem.ItemName += Settings.Default.BatesTemplateList.Count().ToString();
  537. try
  538. {
  539. //创建缓存文件夹
  540. string folderPath = Path.Combine(App.CurrentPath, "Bates");
  541. //有可能因为其他原因存在同名文件,导致创建文件夹失败,需要先删除同名文件
  542. //保险措施(猜测)
  543. if (File.Exists(folderPath))
  544. {
  545. File.Delete(folderPath);
  546. }
  547. DirectoryInfo tempfolder = new DirectoryInfo(folderPath);
  548. if (!tempfolder.Exists)
  549. {
  550. tempfolder.Create();
  551. }
  552. //预览图缓存
  553. string saveName = Guid.NewGuid().ToString();
  554. string savePath = Path.Combine(folderPath, saveName);
  555. Settings.Default.BatesTemplateList.Add(batesItem);
  556. Settings.Default.Save();
  557. }
  558. catch
  559. {
  560. }
  561. this.eventAggregator.GetEvent<EnterTemplateListOrCreateEvent>().Publish(new EnumTemplateListOrCreateUnicode
  562. {
  563. Unicode = Unicode,
  564. Status = EnumTemplateListOrCreate.StatusTemplate
  565. });
  566. }
  567. public void ConfirmEditBackgroundTemplateItem()
  568. {
  569. var batesItem = new BatesHeaderFooterItem();
  570. ConvertInfoToItem(ref batesItem, BatesInfo);
  571. try
  572. {
  573. //创建缓存文件夹
  574. string folderPath = Path.Combine(App.CurrentPath, "Background");
  575. //有可能因为其他原因存在同名文件,导致创建文件夹失败,需要先删除同名文件
  576. //保险措施(猜测)
  577. if (File.Exists(folderPath))
  578. {
  579. File.Delete(folderPath);
  580. }
  581. DirectoryInfo tempfolder = new DirectoryInfo(folderPath);
  582. if (!tempfolder.Exists)
  583. {
  584. tempfolder.Create();
  585. }
  586. Settings.Default.BatesTemplateList[TemplateBatesItem.listIndex] = batesItem;
  587. Settings.Default.Save();
  588. }
  589. catch
  590. {
  591. }
  592. this.eventAggregator.GetEvent<EnterTemplateListOrCreateEvent>().Publish(new EnumTemplateListOrCreateUnicode
  593. {
  594. Unicode = Unicode,
  595. Status = EnumTemplateListOrCreate.StatusTemplate
  596. });
  597. }
  598. public void InitComponentBySelectedInfo()
  599. {
  600. ConvertItemToInfo(TemplateBatesItem, ref BatesInfo);
  601. for (int i = 0; i <= 5; i++)
  602. {
  603. GetTextValueFromNumber[i.ToString()] = BatesInfo.TextData[i].text;
  604. }
  605. MarginTopValue = BatesInfo.margin[0].ToString();
  606. MarginRightValue = BatesInfo.margin[1].ToString();
  607. MarginDownValue = BatesInfo.margin[2].ToString();
  608. MarginLeftValue = BatesInfo.margin[3].ToString();
  609. PrefixTextValue = BatesInfo.Prefix;
  610. SurfixTextValue = BatesInfo.Suffix;
  611. DigitNumberValue = BatesInfo.DigitNumber.ToString();
  612. FontNameSelectedIndex = FontNameList.IndexOf(BatesInfo.TextData[0].fontName);
  613. FontSizeSelectedIndex = FontSizeList.IndexOf(BatesInfo.TextData[0].fontSize.ToString());
  614. StarPagetNumberIndex = StarPagetNumberList.IndexOf(BatesInfo.StarPagetNumber.ToString());
  615. StringColor = EditToolsHelper.ConvertColor(BatesInfo.TextData[0].Color);
  616. SolidColorBrush = new SolidColorBrush(StringColor);
  617. PageRangeSelectIndex = BatesInfo.PageRangeIndex;
  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. if (navigationContext.Parameters.TryGetValue<BatesHeaderFooterItem>("BatesItem", out TemplateBatesItem))
  631. {
  632. CreateOrEdit = EnumCreateOrEdit.StatusEdit;
  633. InitComponentBySelectedInfo();
  634. }
  635. else
  636. {
  637. CreateOrEdit = EnumCreateOrEdit.StatusCreate;
  638. }
  639. }
  640. }
  641. }