PIbd-31_Putincev.D.M._COP_29/COP/PutincevLibrary/DateTimePickerControl.cs

84 lines
2.0 KiB
C#
Raw Permalink Normal View History

2024-10-11 02:06:27 +04:00
using PutincevLibrary.Exceptions;
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;
namespace PutincevLibrary
{
public partial class DateTimePickerControl : UserControl
{
public DateTimePickerControl()
{
InitializeComponent();
}
private DateTime? minValue;
private DateTime? maxValue;
public event EventHandler? _valueChanged;
public DateTime? MinValue
{
get { return minValue; }
set { minValue = value; }
}
public DateTime? MaxValue
{
get { return maxValue; }
set { maxValue = value; }
}
public DateTime? SelectedValue
{
get
{
if (!minValue.HasValue || !maxValue.HasValue)
{
throw new RangeNullException("Диапозон не был задан");
}
else if (dateTimePicker.Value < minValue ||
dateTimePicker.Value > maxValue)
{
throw new WrongRangeException("Значение не попадает в диапазон");
}
return dateTimePicker.Value;
}
set
{
if (!minValue.HasValue || !maxValue.HasValue)
{
return;
}
if (value < minValue || value > maxValue)
{
return;
}
dateTimePicker.Value = value.Value;
}
}
public event EventHandler ValueChanged
{
add { _valueChanged += value; }
remove { _valueChanged -= value; }
}
private void DateTimePicker_ValueChanged(object sender, EventArgs e)
{
_valueChanged?.Invoke(this, e);
}
}
}