Morozov_Pibd-32_KOP/VisEl/VisableComponents/MyTextBoxDate.cs
2023-10-13 17:33:04 +03:00

85 lines
2.4 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System;
using System.Collections.Generic;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace VisableComponents
{
public partial class MyTextBoxDate : UserControl
{
private EventHandler onValueChanged;
public event EventHandler ValueChanged
{
add
{
onValueChanged += value;
}
remove
{
onValueChanged -= value;
}
}
public string TextEr;
public string Err { get { return TextEr; } private set { TextEr = value; } }
public DateTime? DateMin = null;
public DateTime? DateMax = null;
public MyTextBoxDate()
{
InitializeComponent();
}
public DateTime? DateMaximum {
get { return DateMax ; }
set {
DateMax = value;
}
}
public DateTime? DateMinimum
{
get { return DateMin; }
set
{
DateMin = value;
}
}
public DateTime? Value
{
get
{
if(DateMin is null || DateMax is null) {
Err = "Ошибка: НЕТ диапазона";
return null;
}
if (dateTimePicker.Value > DateMax || dateTimePicker.Value < DateMin)
{
Err = "Ошибка: Выход за допустимые пределы!!!";
return null;
}
return dateTimePicker.Value;
}
set
{
if (value == null) return;
if (value > DateMax || value < DateMin) return;
dateTimePicker.Value = (DateTime)value;
}
}
private void dateTimePicker_ValueChanged(object sender, EventArgs e)
{
if (dateTimePicker.Value >= DateMinimum && dateTimePicker.Value <= DateMaximum) panel.BackColor = Color.LightBlue;
else panel.BackColor = Color.Red;
onValueChanged?.Invoke(this,e);
}
}
}