FreetextAnnotPropertyViewModel.cs 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659
  1. using ComPDFKitViewer;
  2. using ComPDFKitViewer.AnnotEvent;
  3. using PDF_Office.CustomControl.CompositeControl;
  4. using PDF_Office.Model;
  5. using PDF_Office.Model.PropertyPanel.AnnotPanel;
  6. using PDF_Office.ViewModels.Tools;
  7. using PDFSettings;
  8. using Prism.Commands;
  9. using Prism.Mvvm;
  10. using Prism.Regions;
  11. using System;
  12. using System.Collections.Generic;
  13. using System.Linq;
  14. using System.Text;
  15. using System.Threading.Tasks;
  16. using System.Windows;
  17. using System.Windows.Controls;
  18. using System.Windows.Media;
  19. namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
  20. {
  21. public class FreetextAnnotPropertyViewModel : BindableBase, INavigationAware
  22. {
  23. private FontBoardVm _fontVm = new FontBoardVm(true);
  24. public FontBoardVm FontVm
  25. {
  26. get { return _fontVm; }
  27. set { SetProperty(ref _fontVm, value); }
  28. }
  29. private AnnotBasePropertyVM _basicVm = new AnnotBasePropertyVM();
  30. public AnnotBasePropertyVM BasicVm
  31. {
  32. get { return _basicVm; }
  33. set => SetProperty(ref _basicVm, value);
  34. }
  35. private bool _isFillFreeText = false;
  36. public bool IsFillFreeTextAnnot
  37. {
  38. get { return _isFillFreeText; }
  39. set => SetProperty(ref _isFillFreeText, value);
  40. }
  41. private bool _isCheckedTime = false;
  42. public bool IsCheckedTime
  43. {
  44. get { return _isCheckedTime; }
  45. set => SetProperty(ref _isCheckedTime, value);
  46. }
  47. private ComboDataItem _currrentDateFormat = new ComboDataItem("M/d", "format");
  48. public ComboDataItem CurrrentDateFormat
  49. {
  50. get { return _currrentDateFormat; }
  51. set => SetProperty(ref _currrentDateFormat, value);
  52. }
  53. public List<ComboDataItem> DateFormatItems { get; private set; }
  54. public AnnotAttribEvent AnnotEvent { get; set; }
  55. private FreeTextAnnotArgs Annot;
  56. private AnnotPropertyPanel PropertyPanel;
  57. public DelegateCommand SelectedPresetFontCommand { get; set; }
  58. public DelegateCommand FontFamilyChangedCommand { get; set; }
  59. public DelegateCommand FontStyleWeightChangedCommand { get; set; }
  60. public DelegateCommand<object> SelectedFillOpacityCommand { get; set; }
  61. public DelegateCommand<object> SelectedColorCommand { get; set; }
  62. public DelegateCommand<object> SelectedFillColorCommand { get; set; }
  63. public DelegateCommand FontSizeChangedCommand { get; set; }
  64. public DelegateCommand<object> TextAlignCheckedCommand { get; set; }
  65. public DelegateCommand<object> LineModeCheckedCommand { get; set; }
  66. public DelegateCommand<object> SelectedOpacityValueCommand { get; set; }
  67. public DelegateCommand CustomFontStyleCommand { get; set; }
  68. public DelegateCommand ReDefineFontStyleCommand { get; set; }
  69. public DelegateCommand RestoreDefaultStyleCommand { get; set; }
  70. public DelegateCommand DateFormatChangedCommand { get; set; }
  71. public DelegateCommand ShowTimeCheckedChnagedCommand { get; set; }
  72. public event EventHandler<object> LoadPropertyHandler;
  73. public FreetextAnnotPropertyViewModel()
  74. {
  75. //文本设置
  76. //预设文本样式
  77. SelectedPresetFontCommand = new DelegateCommand(SelectedPresetFont);
  78. //文本字重、字体
  79. FontStyleWeightChangedCommand = new DelegateCommand(FontStyleWeightChanged);
  80. //字体
  81. FontFamilyChangedCommand = new DelegateCommand(FontFamilyChanged);
  82. //自定义
  83. CustomFontStyleCommand = new DelegateCommand(CustomFontStyle);
  84. //重新定义
  85. ReDefineFontStyleCommand = new DelegateCommand(ReDefineFontStyle);
  86. //恢复默认
  87. RestoreDefaultStyleCommand = new DelegateCommand(RestoreDefaultStyle);
  88. //颜色
  89. SelectedColorCommand = new DelegateCommand<object>(SelectedColor_Command);
  90. //填充颜色
  91. SelectedFillColorCommand = new DelegateCommand<object>(SelectedFillColorChange);
  92. //填充颜色不透明度
  93. SelectedFillOpacityCommand = new DelegateCommand<object>(SelectedFillOpacity);
  94. //大小
  95. FontSizeChangedCommand = new DelegateCommand(FontSizeChanged);
  96. //内容对齐
  97. TextAlignCheckedCommand = new DelegateCommand<object>(TextAlignChecked);
  98. //填写与签名:日期
  99. DateFormatChangedCommand = new DelegateCommand(DateFormatChanged);
  100. ShowTimeCheckedChnagedCommand = new DelegateCommand(ShowTimeCheckedChnaged);
  101. //MVP不上
  102. LineModeCheckedCommand = new DelegateCommand<object>(LineMode_Checked);
  103. SelectedOpacityValueCommand = new DelegateCommand<object>(SelectedOpacityValue);
  104. InitVariable();
  105. }
  106. private void InitVariable()
  107. {
  108. DateFormatItems = new List<ComboDataItem>();
  109. DateFormatItems = TextFont.GetDateFormats();
  110. UpdateDateFormatLists();
  111. }
  112. private void UpdateDateFormatLists()
  113. {
  114. string strTime = " HH:mm:ss";
  115. foreach (var item in DateFormatItems)
  116. {
  117. if (IsCheckedTime)
  118. strTime = item.ValueStr + " HH:mm:ss";
  119. else
  120. strTime = item.ValueStr;
  121. string stadate = System.DateTime.Now.ToString(strTime);
  122. item.SetContent(stadate);
  123. if (CurrrentDateFormat != null && item.ValueStr == CurrrentDateFormat.ValueStr)
  124. CurrrentDateFormat.SetContent(stadate);
  125. }
  126. CurrrentDateFormat = new ComboDataItem(CurrrentDateFormat.ValueStr, CurrrentDateFormat.Content);
  127. }
  128. private void TextAlignChecked(object obj)
  129. {
  130. if ((string)obj != null)
  131. {
  132. switch ((string)obj)
  133. {
  134. case "AlignLeft":
  135. PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.TextAlign, TextAlignment.Left);
  136. break;
  137. case "AlignCenter":
  138. PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.TextAlign, TextAlignment.Center);
  139. break;
  140. case "AlignRight":
  141. PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.TextAlign, TextAlignment.Right);
  142. break;
  143. case "Justify":
  144. PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.TextAlign, TextAlignment.Justify);
  145. break;
  146. }
  147. }
  148. }
  149. private void LineMode_Checked(object obj)
  150. {
  151. if(obj != null)
  152. {
  153. var tag = ((string)obj);
  154. switch (tag)
  155. {
  156. case "Dashed":
  157. AnnotEvent?.UpdateAttrib(AnnotAttrib.LineStyle, DashStyles.Dash);
  158. break;
  159. case "Solid":
  160. AnnotEvent?.UpdateAttrib(AnnotAttrib.LineStyle, DashStyles.Solid);
  161. break;
  162. }
  163. AnnotEvent?.UpdateAnnot();
  164. }
  165. }
  166. //从预设样式设置文本
  167. private void SelectedPresetFont()
  168. {
  169. if (FontVm.CurrentPresetFont != null)
  170. {
  171. var itemComboxItem = FontVm.CurrentPresetFont;
  172. var item = FontVm.PresetFontList.FirstOrDefault(temp => temp.mTag == itemComboxItem.ValueStr);
  173. if (item != null)
  174. {
  175. FontVm.GetCurrentFontSize(item.mFontSize);
  176. FontVm.GetCurrentFontFamily(item.mFontFamily.ToString(), item.mFontFamily.ToString());
  177. FontVm.GetFontWeights_Style(item.mFontStyle, item.mFontWeight);
  178. Dictionary<AnnotAttrib, object> AnnotAttribDir = new Dictionary<AnnotAttrib, object>();
  179. AnnotAttribDir.Add(AnnotAttrib.FontSize, item.mFontSize);
  180. AnnotAttribDir.Add(AnnotAttrib.FontFamily, item.mFontFamily);
  181. AnnotAttribDir.Add(AnnotAttrib.FontStyle, item.mFontStyle);
  182. AnnotAttribDir.Add(AnnotAttrib.FontWeight, item.mFontWeight);
  183. PropertyPanel.UpdateAnnotAllAttribs(AnnotAttribDir);
  184. }
  185. }
  186. }
  187. //设置文本字重、样式
  188. private void FontStyleWeightChanged()
  189. {
  190. if(FontVm.CurrrentFontWeightStyle != null)
  191. {
  192. FontVm.UpdateFontWeight_Style();
  193. Dictionary<AnnotAttrib, object> AnnotAttribDir = new Dictionary<AnnotAttrib, object>();
  194. AnnotAttribDir.Add(AnnotAttrib.FontStyle, FontVm.FontStyleItem);
  195. AnnotAttribDir.Add(AnnotAttrib.FontWeight, FontVm.FontWeightItem);
  196. PropertyPanel.UpdateAnnotAllAttribs(AnnotAttribDir);
  197. }
  198. }
  199. private void SelectedFillOpacity(object obj)
  200. {
  201. if (obj != null)
  202. {
  203. BasicVm.FillOpacity = (double)obj;
  204. BasicVm.FillColor.Opacity = BasicVm.FillOpacity;
  205. PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.Transparency, BasicVm.FillOpacity);
  206. }
  207. }
  208. private void SelectedOpacityValue(object obj)
  209. {
  210. if (obj != null && obj is double)
  211. {
  212. BasicVm.FillOpacity = (double)obj;
  213. BasicVm.FillColor.Opacity = BasicVm.FillOpacity;
  214. PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.Transparency, BasicVm.FillOpacity);
  215. }
  216. }
  217. //设置字体大小
  218. private void FontSizeChanged()
  219. {
  220. if (FontVm.CurrentFontSize != null)
  221. {
  222. PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.FontSize, FontVm.CurrentFontSize.Value);
  223. }
  224. }
  225. //设置字体样式
  226. private void FontFamilyChanged()
  227. {
  228. if (string.IsNullOrEmpty(FontVm.CurrentFontFamily.ValueStr) == false)
  229. {
  230. PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.FontFamily, new FontFamily(FontVm.CurrentFontFamily.ValueStr));
  231. }
  232. }
  233. private void SelectedFillColorChange(object obj)
  234. {
  235. if (obj != null)
  236. {
  237. var colorValue = (Color)obj;
  238. if (colorValue != null)
  239. {
  240. BasicVm.FillColor = new SolidColorBrush(colorValue);
  241. PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.FillColor, colorValue);
  242. // BasicVm.FillColor.Opacity = BasicVmFillOpacity;
  243. }
  244. }
  245. }
  246. private void SelectedColor_Command(object obj)
  247. {
  248. if (obj != null)
  249. {
  250. var colorValue = (Color)obj;
  251. if (colorValue != null)
  252. {
  253. FontVm.FontColor = new SolidColorBrush(colorValue);
  254. PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.FontColor, colorValue);
  255. }
  256. }
  257. }
  258. private void CustomFontStyle()
  259. {
  260. if (FontVm.CurrentPresetFont != null)
  261. {
  262. ContextMenu menu;
  263. if (FontVm.CurrentPresetFont.ValueStr == "custom")
  264. {
  265. menu = SelectAnnotContextMenu(false);
  266. }
  267. else
  268. {
  269. menu = SelectAnnotContextMenu(true);
  270. }
  271. if (menu != null)
  272. {
  273. menu.IsOpen = true;
  274. }
  275. }
  276. }
  277. private ContextMenu SelectAnnotContextMenu(bool isEnable)
  278. {
  279. var popMenu = App.Current.FindResource("CustomFontStyleFlyoutMenu") as ContextMenu;
  280. if (popMenu != null && popMenu.Items.Count == 2)
  281. {
  282. //用所选部分重新定义
  283. MenuItem menuItem = popMenu.Items[0] as MenuItem;
  284. menuItem.IsEnabled = isEnable;
  285. menuItem.Command = ReDefineFontStyleCommand;
  286. //恢复默认预设样式
  287. menuItem = popMenu.Items[1] as MenuItem;
  288. menuItem.IsEnabled = isEnable;
  289. menuItem.Command = RestoreDefaultStyleCommand;
  290. }
  291. return popMenu;
  292. }
  293. public List<PresetFontItem> FontStyleList = new List<PresetFontItem>();
  294. private void ReDefineFontStyle()
  295. {
  296. var item = FontVm.PresetFontList.FirstOrDefault(temp => temp.mTag == FontVm.CurrentPresetFont.ValueStr);
  297. if (item == null) return;
  298. item.mFontFamily = new FontFamily(FontVm.CurrentFontFamily.ValueStr);
  299. if (FontVm.CurrrentFontWeightStyle.ValueStr == "Bold")
  300. {
  301. item.mFontStyle = FontStyles.Normal;
  302. item.mFontWeight = FontWeights.Bold;
  303. }
  304. else if (FontVm.CurrrentFontWeightStyle.ValueStr == "Regular")
  305. {
  306. item.mFontStyle = FontStyles.Normal;
  307. item.mFontWeight = FontWeights.Normal;
  308. }
  309. else
  310. {
  311. item.mFontStyle = FontStyles.Italic;
  312. item.mFontWeight = FontWeights.Bold;
  313. }
  314. item.mFontSize = (int)FontVm.CurrentFontSize.Value;
  315. }
  316. private void RestoreDefaultStyle()
  317. {
  318. var defaultlists = TextFont.GetPresetFontStyle();
  319. if(FontVm.CurrentPresetFont.ValueStr != "custom")
  320. {
  321. var defaulItem = defaultlists.FirstOrDefault(temp => temp.mTag == FontVm.CurrentPresetFont.ValueStr);
  322. if (defaulItem != null)
  323. {
  324. var currentItem = FontVm.PresetFontList.FirstOrDefault(temp => temp.mTag == FontVm.CurrentPresetFont.ValueStr);
  325. if (currentItem != null)
  326. {
  327. currentItem.mTagContent = defaulItem.mTagContent;
  328. currentItem.mFontStyle = defaulItem.mFontStyle;
  329. currentItem.mFontWeight = defaulItem.mFontWeight;
  330. currentItem.mFontFamily = defaulItem.mFontFamily;
  331. currentItem.mFontSize = defaulItem.mFontSize;
  332. FontVm.GetCurrentFontFamily(currentItem.mFontFamily.ToString(), currentItem.mFontFamily.ToString());
  333. FontVm.GetCurrentFontSize(currentItem.mFontSize);
  334. FontVm.GetFontWeights_Style(currentItem.mFontStyle, currentItem.mFontWeight);
  335. }
  336. }
  337. }
  338. }
  339. private void DateFormatChanged()
  340. {
  341. if(CurrrentDateFormat != null)
  342. {
  343. if (IsCheckedTime)
  344. UpdateDateFormatLists();
  345. PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.NoteText, CurrrentDateFormat.Content);
  346. }
  347. }
  348. private void ShowTimeCheckedChnaged()
  349. {
  350. if (CurrrentDateFormat != null)
  351. {
  352. UpdateDateFormatLists();
  353. PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.NoteText, CurrrentDateFormat.Content);
  354. }
  355. }
  356. public bool IsNavigationTarget(NavigationContext navigationContext)
  357. {
  358. return true;
  359. }
  360. public void OnNavigatedFrom(NavigationContext navigationContext)
  361. {
  362. BasicVm.IsMultiSelected = false;
  363. // IsCheckedTime = false;
  364. }
  365. public void OnNavigatedTo(NavigationContext navigationContext)
  366. {
  367. navigationContext.Parameters.TryGetValue<AnnotPropertyPanel>(ParameterNames.PropertyPanelContentViewModel, out PropertyPanel);
  368. if (PropertyPanel != null)
  369. {
  370. AnnotEvent = PropertyPanel.AnnotEvent;
  371. Annot = PropertyPanel.annot as FreeTextAnnotArgs;
  372. LoadPropertyHandler?.Invoke(this, Annot);
  373. BasicVm.AnnotTypeTitle = "文字";
  374. BasicVm.IsMultiSelected = PropertyPanel.IsMultiSelected;
  375. IsFillFreeTextAnnot = PropertyPanel.IsTextFill;
  376. if (BasicVm.IsMultiSelected)
  377. {
  378. IsAttributeEquals();
  379. BasicVm.SetStrDashStyle("None");
  380. }
  381. else
  382. {
  383. GetAnnotProperty();
  384. }
  385. IsFillFreeTextAnnot = PropertyPanel.IsTextFill;
  386. }
  387. }
  388. private List<FreeTextAnnotArgs> ConvertLists()
  389. {
  390. List<FreeTextAnnotArgs> FreeTextLists = new List<FreeTextAnnotArgs>();
  391. foreach (var item in PropertyPanel.annotlists)
  392. {
  393. var itemFreeText = item as FreeTextAnnotArgs;
  394. if (itemFreeText != null)
  395. {
  396. FreeTextLists.Add(itemFreeText);
  397. }
  398. }
  399. if (FreeTextLists.Count != PropertyPanel.annotlists.Count)
  400. return null;
  401. else
  402. return FreeTextLists;
  403. }
  404. private void IsAttributeEquals()
  405. {
  406. var list = ConvertLists();
  407. if (list != null)
  408. {
  409. var temp = list[0];
  410. Dictionary<string, bool> isNoEqualsDir = new Dictionary<string, bool>();
  411. isNoEqualsDir.Add("FontFamily", false);
  412. isNoEqualsDir.Add("FontSize", false);
  413. isNoEqualsDir.Add("FontStyleFontWeight", false);
  414. isNoEqualsDir.Add("FontColor", false);
  415. isNoEqualsDir.Add("FillColor", false);
  416. foreach (var item in list)
  417. {
  418. if (item == list[0])
  419. continue;
  420. if (temp.FontFamily != item.FontFamily)
  421. {
  422. isNoEqualsDir["FontFamily"] = true;
  423. FontVm.CurrentFontFamily = null;
  424. }
  425. if (temp.FontSize != item.FontSize)
  426. {
  427. isNoEqualsDir["FontSize"] = true;
  428. FontVm.CurrentFontSize = null;
  429. }
  430. if (temp.FontStyle != item.FontStyle || temp.FontWeight != item.FontWeight)
  431. {
  432. isNoEqualsDir["FontStyleFontWeight"] = true;
  433. FontVm.CurrrentFontWeightStyle = null;
  434. }
  435. if (isNoEqualsDir["FontFamily"] == true || isNoEqualsDir["FontSize"] == true || isNoEqualsDir["FontStyleFontWeight"] == true)
  436. {
  437. FontVm.CurrentPresetFont = null;
  438. }
  439. if (isNoEqualsDir["FontColor"] == false)
  440. {
  441. if (temp.FontColor.A != item.FontColor.A || temp.FontColor.R != item.FontColor.R || temp.FontColor.G != item.FontColor.G || temp.FontColor.B != item.FontColor.B)
  442. {
  443. FontVm.FontColor = new SolidColorBrush(Colors.Transparent);
  444. isNoEqualsDir["FontColor"] = true;
  445. }
  446. }
  447. if (isNoEqualsDir["FillColor"] == false)
  448. {
  449. if (temp.BgColor.A != item.BgColor.A || temp.BgColor.R != item.BgColor.R || temp.BgColor.G != item.BgColor.G || temp.BgColor.B != item.BgColor.B)
  450. {
  451. BasicVm.FillColor = new SolidColorBrush(Colors.Transparent);
  452. isNoEqualsDir["FillColor"] = true;
  453. }
  454. }
  455. }
  456. ////以下是多选注释的属性相等时
  457. if (isNoEqualsDir["FontFamily"] == false)
  458. {
  459. FontVm.GetCurrentFontFamily(temp.FontFamily.ToString(), temp.FontFamily.ToString());
  460. }
  461. if (isNoEqualsDir["FontSize"] == false)
  462. {
  463. FontVm.GetCurrentFontSize((int)temp.FontSize);
  464. }
  465. if (isNoEqualsDir["FontStyleFontWeight"] == false)
  466. {
  467. FontVm.GetFontWeights_Style(temp.FontStyle, temp.FontWeight);
  468. }
  469. if (isNoEqualsDir["FontColor"] == false)
  470. {
  471. FontVm.FontColor = new SolidColorBrush(temp.FontColor);
  472. }
  473. if (isNoEqualsDir["FillColor"] == false)
  474. {
  475. FontVm.FontColor = new SolidColorBrush(temp.BgColor);
  476. }
  477. }
  478. }
  479. private void GetAnnotProperty()
  480. {
  481. BasicVm.FillColor = new SolidColorBrush(Annot.BgColor);
  482. BasicVm.FillOpacity = Annot.Transparency;
  483. FontVm.FontColor = new SolidColorBrush(Annot.FontColor);
  484. FontVm.GetCurrentFontSize((int)Annot.FontSize);
  485. FontVm.GetCurrentFontFamily(Annot.FontFamily.ToString(), Annot.FontFamily.ToString());
  486. FontVm.GetFontWeights_Style(Annot.FontStyle, Annot.FontWeight);
  487. GetTimeFormat();
  488. string str = "";
  489. if (Annot.Align == TextAlignment.Left)
  490. str = "AlignLeft";
  491. else if (Annot.Align == TextAlignment.Center)
  492. str = "AlignCenter";
  493. else if (Annot.Align == TextAlignment.Right)
  494. str = "AlignRight";
  495. else if(Annot.Align == TextAlignment.Justify)
  496. str = "AlignJustify";
  497. else
  498. str = "None";
  499. BasicVm.SetStrDashStyle(str);
  500. }
  501. private void GetTimeFormat()
  502. {
  503. if (IsFillFreeTextAnnot == false)
  504. return;
  505. if(string.IsNullOrEmpty(Annot.TextContent))
  506. {
  507. if (CurrrentDateFormat != null)
  508. {
  509. if (IsCheckedTime)
  510. UpdateDateFormatLists();
  511. PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.NoteText, CurrrentDateFormat.Content);
  512. }
  513. return;
  514. }
  515. DateTime dtDate;
  516. bool isTime = false;
  517. foreach (var item in DateFormatItems)
  518. {
  519. var strFormat = "";
  520. var strArr = Annot.TextContent.Split(' ');
  521. if (strArr != null && strArr.Count() == 2)
  522. {
  523. strFormat = item.ValueStr + " HH:mm:ss";
  524. }
  525. else
  526. {
  527. strFormat = item.ValueStr;
  528. }
  529. if (DateTime.TryParseExact(Annot.TextContent, strFormat, System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.AdjustToUniversal, out dtDate))
  530. {
  531. if (strArr != null && strArr.Count() == 2)
  532. {
  533. isTime = true;
  534. }
  535. foreach (var item2 in DateFormatItems)
  536. {
  537. string stadate = System.DateTime.Now.ToString(strFormat);
  538. item.SetContent(stadate);
  539. }
  540. CurrrentDateFormat = new ComboDataItem(item.ValueStr, item.Content);
  541. break;
  542. }
  543. }
  544. IsCheckedTime = isTime;
  545. }
  546. }
  547. }