162 lines
5.2 KiB
C#
162 lines
5.2 KiB
C#
using Sarand.Net.Standard.Base.Core;
|
|
using Sarand.Net.Standard.Base.Utils;
|
|
using Sarand.Net.Mobile.Xamarin.Forms.Layouts;
|
|
using Sarand.Net.Mobile.Xamarin.Forms.Views;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Runtime.CompilerServices;
|
|
using System.Text;
|
|
using Xamarin.Forms;
|
|
|
|
namespace Sarand.Net.Mobile.Xamarin.Forms.Controls
|
|
{
|
|
//=======================================================================
|
|
public class SaxDateTimePicker : SaxContentView
|
|
{
|
|
//-------------------------------------------------------------------
|
|
// Definitions.
|
|
// Control layout.
|
|
private SaxStackLayout layoutControl = new SaxStackLayout() { Orientation = StackOrientation.Horizontal };
|
|
private SaxDatePicker pickerDate = new SaxDatePicker();
|
|
private SaxLabel labelTimePrefix = new SaxLabel();
|
|
private SaxTimePicker pickerTime = new SaxTimePicker();
|
|
|
|
//-------------------------------------------------------------------
|
|
// Data members.
|
|
|
|
//-------------------------------------------------------------------
|
|
// Construction.
|
|
public SaxDateTimePicker ()
|
|
{
|
|
DefaultFontSize = pickerDate.FontSize;
|
|
|
|
// Configure components.
|
|
Content = layoutControl;
|
|
layoutControl.Children.Add(pickerDate);
|
|
layoutControl.Children.Add(pickerTime);
|
|
|
|
// Control events.
|
|
pickerDate.DateSelected += PickerDate_DateSelected;
|
|
pickerTime.TimeChanged += PickerTime_TimeChanged;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Properties.
|
|
public string DateFormat
|
|
{
|
|
get { return pickerDate.Format; }
|
|
set
|
|
{
|
|
if (pickerDate.Format.Equals(value)) return;
|
|
pickerDate.Format = value;
|
|
}
|
|
}
|
|
public DateTime MinimumDate
|
|
{
|
|
get { return pickerDate.MinimumDate; }
|
|
set { pickerDate.MinimumDate = value; }
|
|
}
|
|
public DateTime MaximumDate
|
|
{
|
|
get { return pickerDate.MaximumDate; }
|
|
set { pickerDate.MaximumDate = value; }
|
|
}
|
|
public string TimeFormat
|
|
{
|
|
get { return pickerTime.Format; }
|
|
set
|
|
{
|
|
if (pickerTime.Format.Equals(value)) return;
|
|
pickerTime.Format = value;
|
|
}
|
|
}
|
|
// Control value.
|
|
public DateTime DateTime
|
|
{
|
|
get { return pickerDate.Date.Date + pickerTime.Time; }
|
|
set
|
|
{
|
|
if (DateTime.CompareTo(value) == 0) return;
|
|
pickerDate.Date = value.Date;
|
|
pickerTime.Time = value - value.Date;
|
|
}
|
|
}
|
|
public String DateTimeDelim { get; set; } = " ";
|
|
public String FormattedDateTime { get { return pickerDate.FormattedDate + DateTimeDelim + pickerTime.FormattedTime; } }
|
|
// Styling.
|
|
public double DefaultFontSize { get; }
|
|
public double FontSize
|
|
{
|
|
get { return pickerDate.FontSize; }
|
|
set { if (pickerDate.FontSize == value) return; pickerDate.FontSize = value; pickerTime.FontSize = value; labelTimePrefix.FontSize = value; }
|
|
}
|
|
/// <summary>Amount of space between date and time pickers.</summary>
|
|
public double ControlSpacing
|
|
{
|
|
get { return layoutControl.Spacing; }
|
|
set { if (layoutControl.Spacing == value) return; layoutControl.Spacing = value; }
|
|
}
|
|
public String TimePickerPrefixText
|
|
{
|
|
get { return labelTimePrefix.Text; }
|
|
set { value = StringUtil.TrimAll(value); if (labelTimePrefix.Text.Equals(value)) return; labelTimePrefix.Text = value; ConfigureComponents(); }
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// C o n f i g u r e C o m p o n e n t s
|
|
//-------------------------------------------------------------------
|
|
protected override void ConfigureComponents ()
|
|
{
|
|
base.ConfigureComponents();
|
|
|
|
// Time Picker prefix label text.
|
|
if (!StringUtil.IsEmpty(TimePickerPrefixText))
|
|
{
|
|
// Label has text - ensure label is in the layout.
|
|
if (!layoutControl.Children.Contains(labelTimePrefix))
|
|
{
|
|
// Label will be inserted before the time picker.
|
|
int insertIdx = layoutControl.Children.IndexOf(pickerTime);
|
|
layoutControl.Children.Insert(insertIdx, labelTimePrefix);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
// Blank label text - remove label from layout.
|
|
if (layoutControl.Children.Contains(labelTimePrefix))
|
|
layoutControl.Children.Remove(labelTimePrefix);
|
|
}
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// C o n t r o l A c t i v i t y
|
|
//-------------------------------------------------------------------
|
|
protected override void SetControlActivity ()
|
|
{
|
|
base.SetControlActivity();
|
|
}
|
|
protected override void SetControlsReadOnly ()
|
|
{
|
|
base.SetControlsReadOnly();
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// C o n t r o l E v e n t s
|
|
//-------------------------------------------------------------------
|
|
private void PickerDate_DateSelected (object sender, DateChangedEventArgs e)
|
|
{
|
|
if (DateSelected != null) DateSelected.Invoke(sender, e);
|
|
}
|
|
public event EventHandler<DateChangedEventArgs> DateSelected;
|
|
//-------------------------------------------------------------------
|
|
private void PickerTime_TimeChanged (object sender, SaxTimePicker.TimeChangedEventArgs e)
|
|
{
|
|
if (TimeChanged != null) TimeChanged.Invoke(sender, e);
|
|
}
|
|
public event EventHandler<SaxTimePicker.TimeChangedEventArgs> TimeChanged;
|
|
|
|
//-------------------------------------------------------------------
|
|
}
|
|
//=======================================================================
|
|
}
|