| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- using System;
- using System.Globalization;
- using System.Text.RegularExpressions;
- using InABox.Core;
- using InABox.Mobile;
- using Xamarin.Forms;
- namespace PRS.Mobile
- {
- public class DigitalFormDateEntry : MobileDateButton, IDigitalFormField<DFLayoutDateField, DFLayoutDateFieldProperties, DateTime>
- {
- private DFLayoutDateField _definition;
- public DFLayoutDateField Definition
- {
- get => _definition;
- set
- {
- _definition = value;
- Initialize(value ?? new DFLayoutDateField());
- }
- }
-
- public DateTime Value
- {
- get => Date;
- set => Date = value;
- }
- public bool IsEmpty => Value.IsEmpty();
-
- public void Deserialize(string serialized)
- {
- if (DateTime.TryParseExact(serialized, "dd-MM-yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None,
- out DateTime d))
- Value = d;
- }
- public string Serialize() =>
- Value.ToString("dd-MM-yyyy");
- 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;
- var colors = DigitalFormUtils.GetColors(!IsEnabled, Definition.Properties.Required, true);
- BackgroundColor = colors.Background;
- BorderColor = colors.Border;
- TextColor = colors.Foreground;
- }
-
- }
- }
|