HeaderFooterCreateContentViewModel.cs 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797
  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. HeaderFooterInfo.margin[2] = float.Parse(MarginRightValue);
  396. eventAggregator.GetEvent<SetHeaderFooterEvent>().Publish(new HeaderFooterInfoUnicode
  397. {
  398. Unicode = Unicode,
  399. Status = HeaderFooterInfo
  400. });
  401. }
  402. }
  403. private string _textValue = "";
  404. public string TextValue
  405. {
  406. get { return _textValue; }
  407. set
  408. {
  409. SetProperty(ref _textValue, value);
  410. }
  411. }
  412. public int GetLocationIndex = 0;
  413. private Dictionary<string, string> _getTextValueFromNumber = new Dictionary<string, string>();
  414. public Dictionary<string, string> GetTextValueFromNumber
  415. {
  416. get { return _getTextValueFromNumber; }
  417. set
  418. {
  419. _getTextValueFromNumber = value;
  420. }
  421. }
  422. public IEventAggregator eventAggregator;
  423. public DelegateCommand<object> ChangeLocationCommand { get; set; }
  424. public DelegateCommand EnterTemplateListCommand { get; set; }
  425. public DelegateCommand SaveToTemplateListCommand { get; set; }
  426. public DelegateCommand SaveToCurrentTemplateListCommand { get; set; }
  427. public DelegateCommand<object> SelectedColorChangedCommand { get; set; }
  428. public DelegateCommand<object> TextValueChangedCommand { get; set; }
  429. public DelegateCommand ADDDateCommand { get; set; }
  430. public DelegateCommand ADDPagesCommand { get; set; }
  431. public string Unicode = null;
  432. public HeaderFooterCreateContentViewModel(IEventAggregator eventAggregator)
  433. {
  434. this.eventAggregator = eventAggregator;
  435. Unicode = App.mainWindowViewModel.SelectedItem.Unicode;
  436. for (int i = 0; i <= 5; i++)
  437. {
  438. HeaderFooterInfo.TextData[i].Color = EditToolsHelper.ConvertColor(Color.FromArgb(0xFF, 0xFF, 0x00, 0x00));
  439. }
  440. InitList();
  441. InitHeaderFooterInfo();
  442. ChangeLocationCommand = new DelegateCommand<object>(ChangeLocation);
  443. SelectedColorChangedCommand = new DelegateCommand<object>(ChangedColor);
  444. EnterTemplateListCommand = new DelegateCommand(EnterTemplateList);
  445. SaveToTemplateListCommand = new DelegateCommand(SaveToTemplateList);
  446. SaveToCurrentTemplateListCommand = new DelegateCommand(SaveToCurrentTemplateList);
  447. TextValueChangedCommand = new DelegateCommand<object>(TextValueChanged);
  448. ADDDateCommand = new DelegateCommand(ADDDate);
  449. ADDPagesCommand = new DelegateCommand(ADDPages);
  450. }
  451. private void InitList()
  452. {
  453. InitFontNameList();
  454. InitFontSizeList();
  455. InitDateTimeFormatList();
  456. InitPageNumberFormatList();
  457. InitLocationButtonMatrix();
  458. }
  459. private void InitLocationButtonMatrix()
  460. {
  461. GetTextValueFromNumber.Clear();
  462. for (var temp = 0; temp <= 5; temp++)
  463. {
  464. GetTextValueFromNumber.Add(temp.ToString(), "");
  465. }
  466. }
  467. private void InitHeaderFooterInfo()
  468. {
  469. for (int i = 0; i <= 5; i++)
  470. {
  471. HeaderFooterInfo.TextData[i].text = GetTextValueFromNumber[i.ToString()];
  472. }
  473. HeaderFooterInfo.margin[0] = float.Parse(MarginTopValue);
  474. HeaderFooterInfo.margin[1] = float.Parse(MarginRightValue);
  475. HeaderFooterInfo.margin[2] = float.Parse(MarginDownValue);
  476. HeaderFooterInfo.margin[3] = float.Parse(MarginLeftValue);
  477. SetFontName(FontNameSelectedIndex);
  478. SetFontSize(FontSizeSelectedIndex);
  479. SetDateTimeFormat(DateTimeFormatIndex);
  480. SetPageNumberFormat(PageNumberFormatIndex);
  481. SetStarPagetNumber(StarPagetNumberIndex);
  482. StringColor = Color.FromArgb(0xFF, 0xFF, 0x00, 0x00);
  483. }
  484. private void SetFontName(int Index)
  485. {
  486. for (int i = 0; i <= 5; i++) { HeaderFooterInfo.TextData[i].fontName = FontNameList[Index]; }
  487. }
  488. private void SetFontSize(int Index)
  489. {
  490. for (int i = 0; i <= 5; i++) { HeaderFooterInfo.TextData[i].fontSize = (Index + 7) * 1.33f; }
  491. }
  492. private void SetDateTimeFormat(int Index)
  493. {
  494. HeaderFooterInfo.DateTimeFormat = DateTimeFormatList[Index];
  495. }
  496. private void SetPageNumberFormat(int Index)
  497. {
  498. HeaderFooterInfo.PageNumberFormat = PageNumberFormatList[Index];
  499. }
  500. private void SetStarPagetNumber(int Index)
  501. {
  502. HeaderFooterInfo.StarPagetNumber = Index;
  503. }
  504. public void ChangeLocation(object e)
  505. {
  506. string args = e as string;
  507. if (args != null)
  508. {
  509. GetLocationIndex = int.Parse(args);
  510. TextValue = GetTextValueFromNumber[args];
  511. }
  512. }
  513. private void ChangedColor(object obj)
  514. {
  515. if (obj != null)
  516. {
  517. var colorValue = (Color)obj;
  518. if (colorValue != null)
  519. {
  520. StringColor = colorValue;
  521. }
  522. }
  523. }
  524. public void EnterTemplateList()
  525. {
  526. this.eventAggregator.GetEvent<EnterTemplateListOrCreateEvent>().Publish(new EnumTemplateListOrCreateUnicode { Unicode = Unicode, Status = EnumTemplateListOrCreate.StatusTemplate });
  527. }
  528. public void SaveToTemplateList()
  529. {
  530. SaveCurrentTemplate();
  531. this.eventAggregator.GetEvent<EnterTemplateListOrCreateEvent>().Publish(new EnumTemplateListOrCreateUnicode { Unicode = Unicode, Status = EnumTemplateListOrCreate.StatusTemplate });
  532. }
  533. public void SaveToCurrentTemplateList()
  534. {
  535. ConfirmEditBackgroundTemplateItem();
  536. this.eventAggregator.GetEvent<EnterTemplateListOrCreateEvent>().Publish(new EnumTemplateListOrCreateUnicode { Unicode = Unicode, Status = EnumTemplateListOrCreate.StatusTemplate });
  537. }
  538. private void TextValueChanged(object obj)
  539. {
  540. if (obj != null)
  541. {
  542. var textValue = obj as System.Windows.Controls.TextBox;
  543. if (textValue != null)
  544. {
  545. bool TextEQ = true;
  546. if (GetTextValueFromNumber[GetLocationIndex.ToString()] == textValue.Text)
  547. {
  548. TextEQ = false;
  549. }
  550. GetTextValueFromNumber[GetLocationIndex.ToString()] = textValue.Text;
  551. HeaderFooterInfo.TextData[GetLocationIndex].text = GetTextValueFromNumber[GetLocationIndex.ToString()];
  552. if (TextEQ)
  553. {
  554. eventAggregator.GetEvent<SetHeaderFooterEvent>().Publish(new HeaderFooterInfoUnicode
  555. {
  556. Unicode = Unicode,
  557. Status = HeaderFooterInfo
  558. });
  559. }
  560. }
  561. }
  562. }
  563. public void ADDDate()
  564. {
  565. GetTextValueFromNumber[GetLocationIndex.ToString()] = GetTextValueFromNumber[GetLocationIndex.ToString()] + "<<" + DateTimeFormatList[DateTimeFormatIndex] + ">>";
  566. TextValue = GetTextValueFromNumber[GetLocationIndex.ToString()];
  567. HeaderFooterInfo.TextData[GetLocationIndex].text = GetTextValueFromNumber[GetLocationIndex.ToString()];
  568. eventAggregator.GetEvent<SetHeaderFooterEvent>().Publish(new HeaderFooterInfoUnicode
  569. {
  570. Unicode = Unicode,
  571. Status = HeaderFooterInfo
  572. });
  573. }
  574. public void ADDPages()
  575. {
  576. GetTextValueFromNumber[GetLocationIndex.ToString()] = GetTextValueFromNumber[GetLocationIndex.ToString()] + "<<" + PageNumberFormatList[PageNumberFormatIndex].Replace("1", (StarPagetNumberIndex + 1).ToString()) + ">>";
  577. TextValue = GetTextValueFromNumber[GetLocationIndex.ToString()];
  578. HeaderFooterInfo.TextData[GetLocationIndex].text = GetTextValueFromNumber[GetLocationIndex.ToString()];
  579. eventAggregator.GetEvent<SetHeaderFooterEvent>().Publish(new HeaderFooterInfoUnicode
  580. {
  581. Unicode = Unicode,
  582. Status = HeaderFooterInfo
  583. });
  584. }
  585. public void ConvertInfoToItem(ref BatesHeaderFooterItem headerFooterItem, HeaderFooterInfo headerFooterInfo)
  586. {
  587. headerFooterItem.TextData = headerFooterInfo.TextData;
  588. headerFooterItem.ItemName = headerFooterInfo.ItemName;
  589. headerFooterItem.DateTimeFormat = headerFooterInfo.DateTimeFormat;
  590. headerFooterItem.StarPagetNumber = headerFooterInfo.StarPagetNumber;
  591. headerFooterItem.PageNumberFormat = headerFooterInfo.PageNumberFormat;
  592. headerFooterItem.margin = headerFooterInfo.margin;
  593. headerFooterItem.PageRange = PageRangeText;
  594. headerFooterItem.PageRangeIndex = headerFooterInfo.PageRangeIndex;
  595. }
  596. public void ConvertItemToInfo(BatesHeaderFooterItem headerFooterItem, ref HeaderFooterInfo headerFooterInfo)
  597. {
  598. headerFooterInfo.TextData = headerFooterItem.TextData;
  599. headerFooterInfo.ItemName = headerFooterItem.ItemName;
  600. headerFooterInfo.DateTimeFormat = headerFooterItem.DateTimeFormat;
  601. headerFooterInfo.StarPagetNumber = headerFooterItem.StarPagetNumber;
  602. headerFooterInfo.PageNumberFormat = headerFooterItem.PageNumberFormat;
  603. headerFooterInfo.margin = headerFooterItem.margin;
  604. headerFooterInfo.PageRangeIndex = headerFooterItem.PageRangeIndex;
  605. EditToolsHelper.GetPageRange(headerFooterInfo.PageRangeIndex, PDFViewer.Document, ref headerFooterInfo.PageRange, headerFooterItem.PageRange);
  606. }
  607. public void SaveCurrentTemplate()
  608. {
  609. var headerFooterItem = new BatesHeaderFooterItem();
  610. ConvertInfoToItem(ref headerFooterItem, HeaderFooterInfo);
  611. headerFooterItem.ItemName += Settings.Default.HeaderFooterTemplateList.Count().ToString();
  612. try
  613. {
  614. //创建缓存文件夹
  615. string folderPath = Path.Combine(App.CurrentPath, "HeaderFooter");
  616. //有可能因为其他原因存在同名文件,导致创建文件夹失败,需要先删除同名文件
  617. //保险措施(猜测)
  618. if (File.Exists(folderPath))
  619. {
  620. File.Delete(folderPath);
  621. }
  622. DirectoryInfo tempfolder = new DirectoryInfo(folderPath);
  623. if (!tempfolder.Exists)
  624. {
  625. tempfolder.Create();
  626. }
  627. //预览图缓存
  628. string saveName = Guid.NewGuid().ToString();
  629. string savePath = Path.Combine(folderPath, saveName);
  630. Settings.Default.HeaderFooterTemplateList.Add(headerFooterItem);
  631. Settings.Default.Save();
  632. }
  633. catch
  634. {
  635. }
  636. this.eventAggregator.GetEvent<EnterTemplateListOrCreateEvent>().Publish(new EnumTemplateListOrCreateUnicode
  637. {
  638. Unicode = Unicode,
  639. Status = EnumTemplateListOrCreate.StatusTemplate
  640. });
  641. }
  642. public void ConfirmEditBackgroundTemplateItem()
  643. {
  644. var headerFooterItem = new BatesHeaderFooterItem();
  645. ConvertInfoToItem(ref headerFooterItem, HeaderFooterInfo);
  646. try
  647. {
  648. //创建缓存文件夹
  649. string folderPath = Path.Combine(App.CurrentPath, "Background");
  650. //有可能因为其他原因存在同名文件,导致创建文件夹失败,需要先删除同名文件
  651. //保险措施(猜测)
  652. if (File.Exists(folderPath))
  653. {
  654. File.Delete(folderPath);
  655. }
  656. DirectoryInfo tempfolder = new DirectoryInfo(folderPath);
  657. if (!tempfolder.Exists)
  658. {
  659. tempfolder.Create();
  660. }
  661. Settings.Default.HeaderFooterTemplateList[TemplateHeaderFooterItem.listIndex] = headerFooterItem;
  662. Settings.Default.Save();
  663. }
  664. catch
  665. {
  666. }
  667. this.eventAggregator.GetEvent<EnterTemplateListOrCreateEvent>().Publish(new EnumTemplateListOrCreateUnicode
  668. {
  669. Unicode = Unicode,
  670. Status = EnumTemplateListOrCreate.StatusTemplate
  671. });
  672. }
  673. public void InitComponentBySelectedInfo()
  674. {
  675. ConvertItemToInfo(TemplateHeaderFooterItem, ref HeaderFooterInfo);
  676. for (int i = 0; i <= 5; i++)
  677. {
  678. GetTextValueFromNumber[i.ToString()] = HeaderFooterInfo.TextData[i].text;
  679. }
  680. MarginTopValue = HeaderFooterInfo.margin[0].ToString();
  681. MarginRightValue = HeaderFooterInfo.margin[1].ToString();
  682. MarginDownValue = HeaderFooterInfo.margin[2].ToString();
  683. MarginLeftValue = HeaderFooterInfo.margin[3].ToString();
  684. DateTimeFormatIndex = DateTimeFormatList.IndexOf(HeaderFooterInfo.DateTimeFormat);
  685. PageNumberFormatIndex = PageNumberFormatList.IndexOf(HeaderFooterInfo.PageNumberFormat);
  686. FontNameSelectedIndex = FontNameList.IndexOf(HeaderFooterInfo.TextData[0].fontName);
  687. FontSizeSelectedIndex = FontSizeList.IndexOf(HeaderFooterInfo.TextData[0].fontSize.ToString());
  688. StarPagetNumberIndex = StarPagetNumberList.IndexOf(HeaderFooterInfo.StarPagetNumber.ToString());
  689. StringColor = EditToolsHelper.ConvertColor(HeaderFooterInfo.TextData[0].Color);
  690. SolidColorBrush = new SolidColorBrush(StringColor);
  691. PageRangeSelectIndex = HeaderFooterInfo.PageRangeIndex;
  692. if (HeaderFooterInfo.PageRangeIndex == 3) { PageRangeSelectIndex = 0; }
  693. }
  694. public bool IsNavigationTarget(NavigationContext navigationContext)
  695. {
  696. return true;
  697. }
  698. public void OnNavigatedFrom(NavigationContext navigationContext)
  699. {
  700. }
  701. public void OnNavigatedTo(NavigationContext navigationContext)
  702. {
  703. navigationContext.Parameters.TryGetValue<CPDFViewer>(ParameterNames.PDFViewer, out PDFViewer);
  704. MaxPageRange = PDFViewer.Document.PageCount;
  705. InitStarPagetNumberList(MaxPageRange);
  706. EditToolsHelper.GetPageRange(PageRangeSelectIndex, PDFViewer.Document, ref HeaderFooterInfo.PageRange, PageRangeText);
  707. if (navigationContext.Parameters.TryGetValue<BatesHeaderFooterItem>("HeaderFooterItem", out TemplateHeaderFooterItem))
  708. {
  709. CreateOrEdit = EnumCreateOrEdit.StatusEdit;
  710. InitComponentBySelectedInfo();
  711. }
  712. else
  713. {
  714. CreateOrEdit = EnumCreateOrEdit.StatusCreate;
  715. }
  716. StarPagetNumberIndex = 0;
  717. }
  718. }
  719. }