using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using AbazovViewComponents.Exceptions; namespace AbazovViewComponents.Components { public partial class AbazovDatePicker : UserControl { public AbazovDatePicker() { InitializeComponent(); } public event Action DateChange; private bool lowBoundrySet = false; private bool highBoundrySet = false; public DateTime? dateFrom { get { return lowBoundrySet ? dateTimePicker.MinDate : null; } set { if (value.HasValue) { dateTimePicker.MinDate = value.Value; lowBoundrySet = true; } } } public DateTime? dateTo { get { return highBoundrySet ? dateTimePicker.MaxDate : null; } set { if (value.HasValue) { dateTimePicker.MaxDate = value.Value; highBoundrySet = true; } } } public DateTime Value { get { if (dateFrom is null && dateTo is null) throw new DateBoundsNotSetException("Не заданы диапазоны компонента!"); if (this.dateTimePicker.Value < dateFrom || this.dateTimePicker.Value > dateTo) throw new DateOutOfBoundsException("Дата вне диапазона!"); return this.dateTimePicker.Value; } set { if (dateFrom is not null && dateTo is not null && value >= dateFrom && value <= dateTo) this.dateTimePicker.Value = value; } } private void dateTimePicker_ValueChanged(object sender, EventArgs e) { DateChange.Invoke(dateTimePicker.Value); } } }