BatesCreateContentViewModel.cs 27 KB

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