PIbd-33_Abazov_A.A._KOP_29/AbazovApp/AbazovViewComponents/Components/AbazovDatePicker.cs

75 lines
2.0 KiB
C#
Raw Normal View History

2023-09-21 18:50:11 +04:00
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;
2023-09-25 20:52:43 +04:00
public bool BoundriesSet { get { return lowBoundrySet && highBoundrySet; } }
2023-09-21 18:50:11 +04:00
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;
}
}
}
2023-09-25 20:52:43 +04:00
public DateTime? Value
2023-09-21 18:50:11 +04:00
{
get
2023-09-25 20:52:43 +04:00
{
if (!lowBoundrySet || !highBoundrySet || dateTimePicker.Value < dateFrom || dateTimePicker.Value > dateTo) return null;
return dateTimePicker.Value;
2023-09-21 18:50:11 +04:00
}
set
{
2023-09-25 20:52:43 +04:00
if (lowBoundrySet && highBoundrySet && value.HasValue && value.Value >= dateFrom && value.Value <= dateTo) dateTimePicker.Value = value.Value;
2023-09-21 18:50:11 +04:00
}
}
private void dateTimePicker_ValueChanged(object sender, EventArgs e)
{
2023-09-25 20:52:43 +04:00
DateChange?.Invoke(dateTimePicker.Value);
2023-09-21 18:50:11 +04:00
}
}
}