HeaderFooterCreateContentViewModel.cs 29 KB

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