PIbd-31_PotapovNS_COP_20/WinFormSolution/Components/UserControlDatePicker.cs

56 lines
1.6 KiB
C#

using Components.Exceptions;
namespace Components
{
public partial class UserControlDatePicker : UserControl
{
public DateTime? MinDate;
public DateTime? MaxDate;
public DateTime Date
{
get
{
if (MinDate == null || MaxDate == null)
{
throw new RangeNotSetException("Диапазон дат не задан");
}
if (dateTimePicker.Value < MinDate || dateTimePicker.Value > MaxDate)
{
throw new ValueOutOfRangeException("Значение даты вне диапазона");
}
return dateTimePicker.Value;
}
set
{
if (MinDate != null && MaxDate != null)
{
if (value >= MinDate && value <= MaxDate)
{
dateTimePicker.Value = value;
}
}
}
}
private EventHandler _onValueChangedEvent;
public event EventHandler ValueChanged
{
add
{
_onValueChangedEvent += value;
}
remove
{
_onValueChangedEvent -= value;
}
}
public UserControlDatePicker()
{
InitializeComponent();
}
private void dateTimePicker_ValueChanged(object sender, EventArgs e)
{
_onValueChangedEvent?.Invoke(sender, e);
}
}
}