HeaderFooterCreateContentViewModel.cs 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802
  1. using ComPDFKit.PDFWatermark;
  2. using ComPDFKitViewer.PdfViewer;
  3. using Microsoft.Office.Interop.Word;
  4. using PDF_Master.EventAggregators;
  5. using PDF_Master.Helper;
  6. using PDF_Master.Model;
  7. using PDF_Master.Model.EditTools.Background;
  8. using PDF_Master.Model.EditTools.Bates;
  9. using PDF_Master.Model.EditTools.HeaderFooter;
  10. using PDF_Master.Model.EditTools.Watermark;
  11. using PDF_Master.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_Master.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(int pageCount)
  120. {
  121. StarPagetNumberList.Clear();
  122. for (int temp = 1; temp <= pageCount; 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. 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. eventAggregator.GetEvent<SetHeaderFooterEvent>().Publish(new HeaderFooterInfoUnicode
  248. {
  249. Unicode = Unicode,
  250. Status = HeaderFooterInfo
  251. });
  252. }
  253. }
  254. private SolidColorBrush _solidColorBrush = new SolidColorBrush(Color.FromArgb(0xFF, 0xFF, 0x00, 0x00));
  255. public SolidColorBrush SolidColorBrush
  256. {
  257. get
  258. {
  259. return _solidColorBrush;
  260. }
  261. set
  262. {
  263. SetProperty(ref _solidColorBrush, value);
  264. }
  265. }
  266. private Color _stringColor = Color.FromArgb(0xFF, 0xFF, 0x00, 0x00);
  267. public Color StringColor
  268. {
  269. get
  270. {
  271. return _stringColor;
  272. }
  273. set
  274. {
  275. SetProperty(ref _stringColor, value);
  276. SolidColorBrush = new SolidColorBrush(StringColor);
  277. for (int i = 0; i <= 5; i++)
  278. {
  279. HeaderFooterInfo.TextData[i].Color = EditToolsHelper.ConvertColor(value);
  280. }
  281. eventAggregator.GetEvent<SetHeaderFooterEvent>().Publish(new HeaderFooterInfoUnicode
  282. {
  283. Unicode = Unicode,
  284. Status = HeaderFooterInfo
  285. });
  286. }
  287. }
  288. private EnumCreateOrEdit _createOrEdit;
  289. public EnumCreateOrEdit CreateOrEdit
  290. {
  291. get { return _createOrEdit; }
  292. set
  293. {
  294. _createOrEdit = value;
  295. if (value == EnumCreateOrEdit.StatusEdit)
  296. {
  297. EditBaseVisible = Visibility.Visible;
  298. CreateBaseVisible = Visibility.Collapsed;
  299. }
  300. else if (value == EnumCreateOrEdit.StatusCreate)
  301. {
  302. CreateBaseVisible = Visibility.Visible;
  303. EditBaseVisible = Visibility.Collapsed;
  304. }
  305. }
  306. }
  307. private Visibility _createBaseVisible;
  308. public Visibility CreateBaseVisible
  309. {
  310. get => _createBaseVisible;
  311. set => SetProperty(ref _createBaseVisible, value);
  312. }
  313. private Visibility _editBaseVisible;
  314. public Visibility EditBaseVisible
  315. {
  316. get => _editBaseVisible;
  317. set => SetProperty(ref _editBaseVisible, value);
  318. }
  319. private string _marginTopValue = "3";
  320. public string MarginTopValue
  321. {
  322. get { return _marginTopValue; }
  323. set
  324. {
  325. SetProperty(ref _marginTopValue, value);
  326. bool ValueEQ = true;
  327. if (HeaderFooterInfo.margin[1] == float.Parse(MarginTopValue))
  328. {
  329. ValueEQ = false;
  330. }
  331. HeaderFooterInfo.margin[1] = float.Parse(MarginTopValue);
  332. if (ValueEQ)
  333. {
  334. eventAggregator.GetEvent<SetHeaderFooterEvent>().Publish(new HeaderFooterInfoUnicode
  335. {
  336. Unicode = Unicode,
  337. Status = HeaderFooterInfo
  338. });
  339. }
  340. }
  341. }
  342. private string _marginDownValue = "3";
  343. public string MarginDownValue
  344. {
  345. get { return _marginDownValue; }
  346. set
  347. {
  348. SetProperty(ref _marginDownValue, value);
  349. bool ValueEQ = true;
  350. if (HeaderFooterInfo.margin[3] == float.Parse(MarginTopValue))
  351. {
  352. ValueEQ = false;
  353. }
  354. HeaderFooterInfo.margin[3] = float.Parse(MarginDownValue);
  355. if (ValueEQ)
  356. {
  357. eventAggregator.GetEvent<SetHeaderFooterEvent>().Publish(new HeaderFooterInfoUnicode
  358. {
  359. Unicode = Unicode,
  360. Status = HeaderFooterInfo
  361. });
  362. }
  363. }
  364. }
  365. private string _marginLeftValue = "3";
  366. public string MarginLeftValue
  367. {
  368. get { return _marginLeftValue; }
  369. set
  370. {
  371. SetProperty(ref _marginLeftValue, value);
  372. bool ValueEQ = true;
  373. if (HeaderFooterInfo.margin[0] == float.Parse(MarginTopValue))
  374. {
  375. ValueEQ = false;
  376. }
  377. HeaderFooterInfo.margin[0] = float.Parse(MarginLeftValue);
  378. if (ValueEQ)
  379. {
  380. eventAggregator.GetEvent<SetHeaderFooterEvent>().Publish(new HeaderFooterInfoUnicode
  381. {
  382. Unicode = Unicode,
  383. Status = HeaderFooterInfo
  384. });
  385. }
  386. }
  387. }
  388. private string _marginRightValue = "3";
  389. public string MarginRightValue
  390. {
  391. get { return _marginRightValue; }
  392. set
  393. {
  394. SetProperty(ref _marginRightValue, value);
  395. bool ValueEQ = true;
  396. if (HeaderFooterInfo.margin[2] == float.Parse(MarginTopValue))
  397. {
  398. ValueEQ = false;
  399. }
  400. HeaderFooterInfo.margin[2] = float.Parse(MarginRightValue);
  401. eventAggregator.GetEvent<SetHeaderFooterEvent>().Publish(new HeaderFooterInfoUnicode
  402. {
  403. Unicode = Unicode,
  404. Status = HeaderFooterInfo
  405. });
  406. }
  407. }
  408. private string _textValue = "";
  409. public string TextValue
  410. {
  411. get { return _textValue; }
  412. set
  413. {
  414. SetProperty(ref _textValue, value);
  415. }
  416. }
  417. public int GetLocationIndex = 0;
  418. private Dictionary<string, string> _getTextValueFromNumber = new Dictionary<string, string>();
  419. public Dictionary<string, string> GetTextValueFromNumber
  420. {
  421. get { return _getTextValueFromNumber; }
  422. set
  423. {
  424. _getTextValueFromNumber = value;
  425. }
  426. }
  427. public IEventAggregator eventAggregator;
  428. public DelegateCommand<object> ChangeLocationCommand { get; set; }
  429. public DelegateCommand EnterTemplateListCommand { get; set; }
  430. public DelegateCommand SaveToTemplateListCommand { get; set; }
  431. public DelegateCommand SaveToCurrentTemplateListCommand { get; set; }
  432. public DelegateCommand<object> SelectedColorChangedCommand { get; set; }
  433. public DelegateCommand<object> TextValueChangedCommand { get; set; }
  434. public DelegateCommand ADDDateCommand { get; set; }
  435. public DelegateCommand ADDPagesCommand { get; set; }
  436. public string Unicode = null;
  437. public HeaderFooterCreateContentViewModel(IEventAggregator eventAggregator)
  438. {
  439. this.eventAggregator = eventAggregator;
  440. Unicode = App.mainWindowViewModel.SelectedItem.Unicode;
  441. for (int i = 0; i <= 5; i++)
  442. {
  443. HeaderFooterInfo.TextData[i].Color = EditToolsHelper.ConvertColor(Color.FromArgb(0xFF, 0xFF, 0x00, 0x00));
  444. }
  445. InitList();
  446. InitHeaderFooterInfo();
  447. ChangeLocationCommand = new DelegateCommand<object>(ChangeLocation);
  448. SelectedColorChangedCommand = new DelegateCommand<object>(ChangedColor);
  449. EnterTemplateListCommand = new DelegateCommand(EnterTemplateList);
  450. SaveToTemplateListCommand = new DelegateCommand(SaveToTemplateList);
  451. SaveToCurrentTemplateListCommand = new DelegateCommand(SaveToCurrentTemplateList);
  452. TextValueChangedCommand = new DelegateCommand<object>(TextValueChanged);
  453. ADDDateCommand = new DelegateCommand(ADDDate);
  454. ADDPagesCommand = new DelegateCommand(ADDPages);
  455. }
  456. private void InitList()
  457. {
  458. InitFontNameList();
  459. InitFontSizeList();
  460. InitDateTimeFormatList();
  461. InitPageNumberFormatList();
  462. InitLocationButtonMatrix();
  463. }
  464. private void InitLocationButtonMatrix()
  465. {
  466. GetTextValueFromNumber.Clear();
  467. for (var temp = 0; temp <= 5; temp++)
  468. {
  469. GetTextValueFromNumber.Add(temp.ToString(), "");
  470. }
  471. }
  472. private void InitHeaderFooterInfo()
  473. {
  474. for (int i = 0; i <= 5; i++)
  475. {
  476. HeaderFooterInfo.TextData[i].text = GetTextValueFromNumber[i.ToString()];
  477. }
  478. HeaderFooterInfo.margin[0] = float.Parse(MarginTopValue);
  479. HeaderFooterInfo.margin[1] = float.Parse(MarginRightValue);
  480. HeaderFooterInfo.margin[2] = float.Parse(MarginDownValue);
  481. HeaderFooterInfo.margin[3] = float.Parse(MarginLeftValue);
  482. SetFontName(FontNameSelectedIndex);
  483. SetFontSize(FontSizeSelectedIndex);
  484. SetDateTimeFormat(DateTimeFormatIndex);
  485. SetPageNumberFormat(PageNumberFormatIndex);
  486. SetStarPagetNumber(StarPagetNumberIndex);
  487. StringColor = Color.FromArgb(0xFF, 0xFF, 0x00, 0x00);
  488. }
  489. private void SetFontName(int Index)
  490. {
  491. for (int i = 0; i <= 5; i++) { HeaderFooterInfo.TextData[i].fontName = FontNameList[Index]; }
  492. }
  493. private void SetFontSize(int Index)
  494. {
  495. for (int i = 0; i <= 5; i++) { HeaderFooterInfo.TextData[i].fontSize = (Index + 7) * 1.33f; }
  496. }
  497. private void SetDateTimeFormat(int Index)
  498. {
  499. HeaderFooterInfo.DateTimeFormat = DateTimeFormatList[Index];
  500. }
  501. private void SetPageNumberFormat(int Index)
  502. {
  503. HeaderFooterInfo.PageNumberFormat = PageNumberFormatList[Index];
  504. }
  505. private void SetStarPagetNumber(int Index)
  506. {
  507. HeaderFooterInfo.StarPagetNumber = Index;
  508. }
  509. public void ChangeLocation(object e)
  510. {
  511. string args = e as string;
  512. if (args != null)
  513. {
  514. GetLocationIndex = int.Parse(args);
  515. TextValue = GetTextValueFromNumber[args];
  516. }
  517. }
  518. private void ChangedColor(object obj)
  519. {
  520. if (obj != null)
  521. {
  522. var colorValue = (Color)obj;
  523. if (colorValue != null)
  524. {
  525. StringColor = colorValue;
  526. }
  527. }
  528. }
  529. public void EnterTemplateList()
  530. {
  531. this.eventAggregator.GetEvent<EnterTemplateListOrCreateEvent>().Publish(new EnumTemplateListOrCreateUnicode { Unicode = Unicode, Status = EnumTemplateListOrCreate.StatusTemplate });
  532. }
  533. public void SaveToTemplateList()
  534. {
  535. SaveCurrentTemplate();
  536. this.eventAggregator.GetEvent<EnterTemplateListOrCreateEvent>().Publish(new EnumTemplateListOrCreateUnicode { Unicode = Unicode, Status = EnumTemplateListOrCreate.StatusTemplate });
  537. }
  538. public void SaveToCurrentTemplateList()
  539. {
  540. ConfirmEditBackgroundTemplateItem();
  541. this.eventAggregator.GetEvent<EnterTemplateListOrCreateEvent>().Publish(new EnumTemplateListOrCreateUnicode { Unicode = Unicode, Status = EnumTemplateListOrCreate.StatusTemplate });
  542. }
  543. private void TextValueChanged(object obj)
  544. {
  545. if (obj != null)
  546. {
  547. var textValue = obj as System.Windows.Controls.TextBox;
  548. if (textValue != null)
  549. {
  550. bool TextEQ = true;
  551. if (GetTextValueFromNumber[GetLocationIndex.ToString()] == textValue.Text)
  552. {
  553. TextEQ = false;
  554. }
  555. GetTextValueFromNumber[GetLocationIndex.ToString()] = textValue.Text;
  556. HeaderFooterInfo.TextData[GetLocationIndex].text = GetTextValueFromNumber[GetLocationIndex.ToString()];
  557. if (TextEQ)
  558. {
  559. eventAggregator.GetEvent<SetHeaderFooterEvent>().Publish(new HeaderFooterInfoUnicode
  560. {
  561. Unicode = Unicode,
  562. Status = HeaderFooterInfo
  563. });
  564. }
  565. }
  566. }
  567. }
  568. public void ADDDate()
  569. {
  570. GetTextValueFromNumber[GetLocationIndex.ToString()] = GetTextValueFromNumber[GetLocationIndex.ToString()] + "<<" + DateTimeFormatList[DateTimeFormatIndex] + ">>";
  571. TextValue = GetTextValueFromNumber[GetLocationIndex.ToString()];
  572. HeaderFooterInfo.TextData[GetLocationIndex].text = GetTextValueFromNumber[GetLocationIndex.ToString()];
  573. eventAggregator.GetEvent<SetHeaderFooterEvent>().Publish(new HeaderFooterInfoUnicode
  574. {
  575. Unicode = Unicode,
  576. Status = HeaderFooterInfo
  577. });
  578. }
  579. public void ADDPages()
  580. {
  581. GetTextValueFromNumber[GetLocationIndex.ToString()] = GetTextValueFromNumber[GetLocationIndex.ToString()] + "<<" + PageNumberFormatList[PageNumberFormatIndex].Replace("1", (StarPagetNumberIndex + 1).ToString()) + ">>";
  582. TextValue = GetTextValueFromNumber[GetLocationIndex.ToString()];
  583. HeaderFooterInfo.TextData[GetLocationIndex].text = GetTextValueFromNumber[GetLocationIndex.ToString()];
  584. eventAggregator.GetEvent<SetHeaderFooterEvent>().Publish(new HeaderFooterInfoUnicode
  585. {
  586. Unicode = Unicode,
  587. Status = HeaderFooterInfo
  588. });
  589. }
  590. public void ConvertInfoToItem(ref BatesHeaderFooterItem headerFooterItem, HeaderFooterInfo headerFooterInfo)
  591. {
  592. headerFooterItem.TextData = headerFooterInfo.TextData;
  593. headerFooterItem.ItemName = headerFooterInfo.ItemName;
  594. headerFooterItem.DateTimeFormat = headerFooterInfo.DateTimeFormat;
  595. headerFooterItem.StarPagetNumber = headerFooterInfo.StarPagetNumber;
  596. headerFooterItem.PageNumberFormat = headerFooterInfo.PageNumberFormat;
  597. headerFooterItem.margin = headerFooterInfo.margin;
  598. headerFooterItem.PageRange = PageRangeText;
  599. headerFooterItem.PageRangeIndex = headerFooterInfo.PageRangeIndex;
  600. }
  601. public void ConvertItemToInfo(BatesHeaderFooterItem headerFooterItem, ref HeaderFooterInfo headerFooterInfo)
  602. {
  603. headerFooterInfo.TextData = headerFooterItem.TextData;
  604. headerFooterInfo.ItemName = headerFooterItem.ItemName;
  605. headerFooterInfo.DateTimeFormat = headerFooterItem.DateTimeFormat;
  606. headerFooterInfo.StarPagetNumber = headerFooterItem.StarPagetNumber;
  607. headerFooterInfo.PageNumberFormat = headerFooterItem.PageNumberFormat;
  608. headerFooterInfo.margin = headerFooterItem.margin;
  609. headerFooterInfo.PageRangeIndex = headerFooterItem.PageRangeIndex;
  610. EditToolsHelper.GetPageRange(headerFooterInfo.PageRangeIndex, PDFViewer.Document, ref headerFooterInfo.PageRange, headerFooterItem.PageRange);
  611. }
  612. public void SaveCurrentTemplate()
  613. {
  614. var headerFooterItem = new BatesHeaderFooterItem();
  615. ConvertInfoToItem(ref headerFooterItem, HeaderFooterInfo);
  616. headerFooterItem.ItemName += Settings.Default.HeaderFooterTemplateList.Count().ToString();
  617. try
  618. {
  619. //创建缓存文件夹
  620. string folderPath = Path.Combine(App.CurrentPath, "HeaderFooter");
  621. //有可能因为其他原因存在同名文件,导致创建文件夹失败,需要先删除同名文件
  622. //保险措施(猜测)
  623. if (File.Exists(folderPath))
  624. {
  625. File.Delete(folderPath);
  626. }
  627. DirectoryInfo tempfolder = new DirectoryInfo(folderPath);
  628. if (!tempfolder.Exists)
  629. {
  630. tempfolder.Create();
  631. }
  632. //预览图缓存
  633. string saveName = Guid.NewGuid().ToString();
  634. string savePath = Path.Combine(folderPath, saveName);
  635. Settings.Default.HeaderFooterTemplateList.Add(headerFooterItem);
  636. Settings.Default.Save();
  637. }
  638. catch
  639. {
  640. }
  641. this.eventAggregator.GetEvent<EnterTemplateListOrCreateEvent>().Publish(new EnumTemplateListOrCreateUnicode
  642. {
  643. Unicode = Unicode,
  644. Status = EnumTemplateListOrCreate.StatusTemplate
  645. });
  646. }
  647. public void ConfirmEditBackgroundTemplateItem()
  648. {
  649. var headerFooterItem = new BatesHeaderFooterItem();
  650. ConvertInfoToItem(ref headerFooterItem, HeaderFooterInfo);
  651. try
  652. {
  653. //创建缓存文件夹
  654. string folderPath = Path.Combine(App.CurrentPath, "Background");
  655. //有可能因为其他原因存在同名文件,导致创建文件夹失败,需要先删除同名文件
  656. //保险措施(猜测)
  657. if (File.Exists(folderPath))
  658. {
  659. File.Delete(folderPath);
  660. }
  661. DirectoryInfo tempfolder = new DirectoryInfo(folderPath);
  662. if (!tempfolder.Exists)
  663. {
  664. tempfolder.Create();
  665. }
  666. Settings.Default.HeaderFooterTemplateList[TemplateHeaderFooterItem.listIndex] = headerFooterItem;
  667. Settings.Default.Save();
  668. }
  669. catch
  670. {
  671. }
  672. this.eventAggregator.GetEvent<EnterTemplateListOrCreateEvent>().Publish(new EnumTemplateListOrCreateUnicode
  673. {
  674. Unicode = Unicode,
  675. Status = EnumTemplateListOrCreate.StatusTemplate
  676. });
  677. }
  678. public void InitComponentBySelectedInfo()
  679. {
  680. ConvertItemToInfo(TemplateHeaderFooterItem, ref HeaderFooterInfo);
  681. for (int i = 0; i <= 5; i++)
  682. {
  683. GetTextValueFromNumber[i.ToString()] = HeaderFooterInfo.TextData[i].text;
  684. }
  685. MarginTopValue = HeaderFooterInfo.margin[0].ToString();
  686. MarginRightValue = HeaderFooterInfo.margin[1].ToString();
  687. MarginDownValue = HeaderFooterInfo.margin[2].ToString();
  688. MarginLeftValue = HeaderFooterInfo.margin[3].ToString();
  689. DateTimeFormatIndex = DateTimeFormatList.IndexOf(HeaderFooterInfo.DateTimeFormat);
  690. PageNumberFormatIndex = PageNumberFormatList.IndexOf(HeaderFooterInfo.PageNumberFormat);
  691. FontNameSelectedIndex = FontNameList.IndexOf(HeaderFooterInfo.TextData[0].fontName);
  692. FontSizeSelectedIndex = FontSizeList.IndexOf(HeaderFooterInfo.TextData[0].fontSize.ToString());
  693. StarPagetNumberIndex = StarPagetNumberList.IndexOf(HeaderFooterInfo.StarPagetNumber.ToString());
  694. StringColor = EditToolsHelper.ConvertColor(HeaderFooterInfo.TextData[0].Color);
  695. SolidColorBrush = new SolidColorBrush(StringColor);
  696. PageRangeSelectIndex = HeaderFooterInfo.PageRangeIndex;
  697. if (HeaderFooterInfo.PageRangeIndex == 3) { PageRangeSelectIndex = 0; }
  698. }
  699. public bool IsNavigationTarget(NavigationContext navigationContext)
  700. {
  701. return true;
  702. }
  703. public void OnNavigatedFrom(NavigationContext navigationContext)
  704. {
  705. }
  706. public void OnNavigatedTo(NavigationContext navigationContext)
  707. {
  708. navigationContext.Parameters.TryGetValue<CPDFViewer>(ParameterNames.PDFViewer, out PDFViewer);
  709. MaxPageRange = PDFViewer.Document.PageCount;
  710. InitStarPagetNumberList(MaxPageRange);
  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. StarPagetNumberIndex = 0;
  722. }
  723. }
  724. }