DFLayoutDateTimeFieldProperties.cs 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. using System;
  2. namespace InABox.Core
  3. {
  4. public class DFLayoutDateTimeFieldProperties : DFLayoutFieldProperties<DateTime>
  5. {
  6. public DFLayoutDateTimeFieldProperties()
  7. {
  8. Format = "mm HH dd MMM yy";
  9. }
  10. public string Format { get; set; }
  11. public override string FormatValue(object? value)
  12. {
  13. return string.Format("{0" + (string.IsNullOrWhiteSpace(Format) ? "" : ":" + Format.Replace(":", "\\:")) + "}", value);
  14. }
  15. public override object? ParseValue(object? value)
  16. {
  17. if (value is DateTime)
  18. return value;
  19. if (DateTime.TryParse(value as string, out var result))
  20. return result;
  21. return null;
  22. }
  23. protected override void LoadProperties()
  24. {
  25. base.LoadProperties();
  26. Format = GetProperty("Format", Format);
  27. }
  28. protected override void SaveProperties()
  29. {
  30. base.SaveProperties();
  31. SetProperty("Format", Format);
  32. }
  33. }
  34. }