| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- using System;
- using InABox.Core;
- using InABox.Mobile;
- namespace PRS.Mobile
- {
- public class DigitalFormDateEntry : MobileDateButton, IDigitalFormField<DFLayoutDateField, DFLayoutDateFieldProperties, DateTime, DateTime?>
- {
-
- 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;
- }
-
- }
- }
|