| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- using System;
- using System.Globalization;
- using InABox.Core;
- using InABox.Mobile;
- namespace PRS.Mobile
- {
- public class DigitalFormTimeEntry : MobileTimeButton, IDigitalFormField<DFLayoutTimeField, DFLayoutTimeFieldProperties, TimeSpan>
- {
-
- private DFLayoutTimeField _definition;
- public DFLayoutTimeField Definition
- {
- get => _definition;
- set
- {
- _definition = value;
- Initialize(value ?? new DFLayoutTimeField());
- }
- }
-
- public TimeSpan Value
- {
- get => Time;
- set => Time = value;
- }
- public bool IsEmpty => Value.Equals(TimeSpan.Zero);
- private bool _readOnly;
- public bool ReadOnly
- {
- get => _readOnly;
- set
- {
- _readOnly = value;
- UpdateStatus();
- }
- }
-
- public void Deserialize(string serialized)
- {
- if (TimeSpan.TryParseExact(serialized, "c", CultureInfo.InvariantCulture, TimeSpanStyles.None,
- out TimeSpan t))
- Value = t;
- }
- public string Serialize() => Value.ToString("c");
- public event DigitalFormViewChangedHandler ValueChanged;
- public DigitalFormTimeEntry()
- {
- HeightRequest = 40;
- Changed += (sender, args) =>
- {
- ValueChanged?.Invoke(this, new DigitalFormViewChangedArgs(Definition,Value));
- };
- }
- private void Initialize(DFLayoutTimeField 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;
- }
-
- }
- }
|