HomePageHeaderFooterCreateContentViewModel.cs 27 KB

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