HomePageHeaderFooterCreateContentViewModel.cs 27 KB

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