using System; using InABox.Core; using InABox.Mobile; namespace PRS.Mobile { public class DigitalFormDateEntry : MobileDateButton, IDigitalFormField { private DateTime _value = DateTime.MinValue; private DFLayoutDateField? _definition; public DFLayoutDateField? Definition { get => _definition; set { _definition = value; Initialize(value ?? new DFLayoutDateField()); } } public DateTime Value { get => _value; set { _value = value; UpdateUI(); } } private void UpdateUI() { Date = _value; } protected override void DoChanged() { _value = Date; base.DoChanged(); } public bool IsEmpty => Value.IsEmpty(); public void Deserialize(DFLoadStorageEntry entry) => Value = Definition?.Properties.DeserializeValue(entry) ?? DateTime.MinValue; public void Serialize(DFSaveStorageEntry entry) => entry.SetValue(Value); private bool _readOnly; public bool ReadOnly { get => _readOnly; set { _readOnly = value; UpdateStatus(); } } public event DigitalFormViewChangedHandler? ValueChanged; public DigitalFormDateEntry() { HeightRequest = 40; Changed += (sender, args) => { ValueChanged?.Invoke(this,new DigitalFormViewChangedArgs(Definition,Value)); }; } private void Initialize(DFLayoutDateField definition) { UpdateStatus(); } private void UpdateStatus() { IsEnabled = !_readOnly && Definition?.Properties.Secure == false; var colors = DigitalFormUtils.GetColors(!IsEnabled, Definition?.Properties.Required ?? false, true); BackgroundColor = colors.Background; BorderColor = colors.Border; TextColor = colors.Foreground; } } }