PIbd-33_Abazov_A.A._KOP_29/AbazovApp/AbazovViewComponents/Components/AbazovDatePicker.cs
2023-09-25 20:52:43 +04:00

75 lines
2.0 KiB
C#

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<DateTime> DateChange;
private bool lowBoundrySet = false;
private bool highBoundrySet = false;
public bool BoundriesSet { get { return lowBoundrySet && highBoundrySet; } }
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 (!lowBoundrySet || !highBoundrySet || dateTimePicker.Value < dateFrom || dateTimePicker.Value > dateTo) return null;
return dateTimePicker.Value;
}
set
{
if (lowBoundrySet && highBoundrySet && value.HasValue && value.Value >= dateFrom && value.Value <= dateTo) dateTimePicker.Value = value.Value;
}
}
private void dateTimePicker_ValueChanged(object sender, EventArgs e)
{
DateChange?.Invoke(dateTimePicker.Value);
}
}
}