123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- using System;
- using System.Globalization;
- namespace InABox.Core
- {
- public class DFLayoutDateFieldProperties : DFLayoutFieldProperties<DateTime, DateTime?>
- {
-
- [EditorSequence(-995)]
- [DateEditor]
- public override DateTime Default { get; set; }
-
- public DFLayoutDateFieldProperties()
- {
- Format = "dd MMM yy";
- }
- public string Format { get; set; }
- public override string FormatValue(DateTime? value)
- {
- return string.Format("{0" + (string.IsNullOrWhiteSpace(Format) ? "" : ":" + Format.Replace(":", "\\:")) + "}", value);
- }
- public override DateTime GetValue(DateTime? value)
- {
- return value ?? Default;
- }
- public override void SerializeValue(DFSaveStorageEntry entry, DateTime? value)
- {
- if(value != null)
- {
- entry.SetValue(value.Value.ToString("dd-MM-yyyy"));
- }
- }
- public override DateTime? DeserializeValue(DFLoadStorageEntry entry)
- {
- var value = entry.GetValue();
- if (value is DateTime date)
- return date;
- if (DateTime.TryParseExact(value as string, "dd-MM-yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out var result))
- return result;
- return null;
- }
- protected override void LoadProperties()
- {
- base.LoadProperties();
- Format = GetProperty("Format", Format);
- }
- protected override void SaveProperties()
- {
- base.SaveProperties();
- SetProperty("Format", Format);
- }
- }
- }
|