Added DatePicker component
This commit is contained in:
parent
9834f67584
commit
71fa6549fb
51
AbazovApp/AbazovAppView/FormTest.Designer.cs
generated
51
AbazovApp/AbazovAppView/FormTest.Designer.cs
generated
@ -32,6 +32,10 @@
|
||||
this.buttonAdd = new System.Windows.Forms.Button();
|
||||
this.buttonClear = new System.Windows.Forms.Button();
|
||||
this.buttonSelected = new System.Windows.Forms.Button();
|
||||
this.abazovDatePicker = new AbazovViewComponents.Components.AbazovDatePicker();
|
||||
this.buttonBoundries = new System.Windows.Forms.Button();
|
||||
this.buttonSetDate = new System.Windows.Forms.Button();
|
||||
this.buttonGetDate = new System.Windows.Forms.Button();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// abazovCheckedListBox
|
||||
@ -73,11 +77,54 @@
|
||||
this.buttonSelected.UseVisualStyleBackColor = true;
|
||||
this.buttonSelected.Click += new System.EventHandler(this.buttonSelected_Click);
|
||||
//
|
||||
// abazovDatePicker
|
||||
//
|
||||
this.abazovDatePicker.Location = new System.Drawing.Point(188, 12);
|
||||
this.abazovDatePicker.Name = "abazovDatePicker";
|
||||
this.abazovDatePicker.Size = new System.Drawing.Size(321, 48);
|
||||
this.abazovDatePicker.TabIndex = 4;
|
||||
this.abazovDatePicker.DateChange += new System.Action<System.DateTime>(this.abazovDatePicker_DateChange);
|
||||
this.abazovDatePicker.AutoSizeChanged += new System.EventHandler(this.abazovDatePicker_DateChange);
|
||||
//
|
||||
// buttonBoundries
|
||||
//
|
||||
this.buttonBoundries.Location = new System.Drawing.Point(188, 143);
|
||||
this.buttonBoundries.Name = "buttonBoundries";
|
||||
this.buttonBoundries.Size = new System.Drawing.Size(254, 29);
|
||||
this.buttonBoundries.TabIndex = 5;
|
||||
this.buttonBoundries.Text = "Установить границы";
|
||||
this.buttonBoundries.UseVisualStyleBackColor = true;
|
||||
this.buttonBoundries.Click += new System.EventHandler(this.buttonBoundries_Click);
|
||||
//
|
||||
// buttonSetDate
|
||||
//
|
||||
this.buttonSetDate.Location = new System.Drawing.Point(188, 178);
|
||||
this.buttonSetDate.Name = "buttonSetDate";
|
||||
this.buttonSetDate.Size = new System.Drawing.Size(254, 29);
|
||||
this.buttonSetDate.TabIndex = 6;
|
||||
this.buttonSetDate.Text = "Установить значение";
|
||||
this.buttonSetDate.UseVisualStyleBackColor = true;
|
||||
this.buttonSetDate.Click += new System.EventHandler(this.buttonSetDate_Click);
|
||||
//
|
||||
// buttonGetDate
|
||||
//
|
||||
this.buttonGetDate.Location = new System.Drawing.Point(188, 213);
|
||||
this.buttonGetDate.Name = "buttonGetDate";
|
||||
this.buttonGetDate.Size = new System.Drawing.Size(254, 29);
|
||||
this.buttonGetDate.TabIndex = 7;
|
||||
this.buttonGetDate.Text = "Получить значение";
|
||||
this.buttonGetDate.UseVisualStyleBackColor = true;
|
||||
this.buttonGetDate.Click += new System.EventHandler(this.buttonGetDate_Click);
|
||||
//
|
||||
// FormTest
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(800, 450);
|
||||
this.Controls.Add(this.buttonGetDate);
|
||||
this.Controls.Add(this.buttonSetDate);
|
||||
this.Controls.Add(this.buttonBoundries);
|
||||
this.Controls.Add(this.abazovDatePicker);
|
||||
this.Controls.Add(this.buttonSelected);
|
||||
this.Controls.Add(this.buttonClear);
|
||||
this.Controls.Add(this.buttonAdd);
|
||||
@ -94,5 +141,9 @@
|
||||
private Button buttonAdd;
|
||||
private Button buttonClear;
|
||||
private Button buttonSelected;
|
||||
private AbazovViewComponents.Components.AbazovDatePicker abazovDatePicker;
|
||||
private Button buttonBoundries;
|
||||
private Button buttonSetDate;
|
||||
private Button buttonGetDate;
|
||||
}
|
||||
}
|
@ -1,4 +1,5 @@
|
||||
using AbazovViewComponents.Components;
|
||||
using AbazovViewComponents.Exceptions;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
@ -44,5 +45,51 @@ namespace AbazovAppView
|
||||
{
|
||||
MessageBox.Show(abazovCheckedListBox.selectedItem ?? "null", "By getter");
|
||||
}
|
||||
|
||||
private void buttonBoundries_Click(object sender, EventArgs e)
|
||||
{
|
||||
abazovDatePicker.dateFrom = new DateTime(1970, 01, 01);
|
||||
abazovDatePicker.dateTo = new DateTime(2010, 01, 01);
|
||||
}
|
||||
|
||||
private void buttonSetDate_Click(object sender, EventArgs e)
|
||||
{
|
||||
var result = MessageBox.Show("Установить значение в границах?", "Выбор", MessageBoxButtons.YesNo);
|
||||
if (result == DialogResult.Yes)
|
||||
{
|
||||
abazovDatePicker.Value = new DateTime(2000, 01, 01);
|
||||
}
|
||||
else
|
||||
{
|
||||
abazovDatePicker.Value = new DateTime(1900, 01, 01);
|
||||
}
|
||||
}
|
||||
|
||||
private void abazovDatePicker_DateChange(object sender, EventArgs e)
|
||||
{
|
||||
MessageBox.Show("ok");
|
||||
}
|
||||
|
||||
private void abazovDatePicker_DateChange(DateTime obj)
|
||||
{
|
||||
MessageBox.Show(obj.ToShortDateString(), "Date change event");
|
||||
}
|
||||
|
||||
private void buttonGetDate_Click(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
DateTime date = abazovDatePicker.Value;
|
||||
MessageBox.Show(date.ToString(), "Через свойство");
|
||||
}
|
||||
catch (DateBoundsNotSetException ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message);
|
||||
}
|
||||
catch (DateOutOfBoundsException ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
57
AbazovApp/AbazovViewComponents/Components/AbazovDatePicker.Designer.cs
generated
Normal file
57
AbazovApp/AbazovViewComponents/Components/AbazovDatePicker.Designer.cs
generated
Normal file
@ -0,0 +1,57 @@
|
||||
namespace AbazovViewComponents.Components
|
||||
{
|
||||
partial class AbazovDatePicker
|
||||
{
|
||||
/// <summary>
|
||||
/// Обязательная переменная конструктора.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Освободить все используемые ресурсы.
|
||||
/// </summary>
|
||||
/// <param name="disposing">истинно, если управляемый ресурс должен быть удален; иначе ложно.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Код, автоматически созданный конструктором компонентов
|
||||
|
||||
/// <summary>
|
||||
/// Требуемый метод для поддержки конструктора — не изменяйте
|
||||
/// содержимое этого метода с помощью редактора кода.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.dateTimePicker = new System.Windows.Forms.DateTimePicker();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// dateTimePicker
|
||||
//
|
||||
this.dateTimePicker.Location = new System.Drawing.Point(3, 3);
|
||||
this.dateTimePicker.Name = "dateTimePicker";
|
||||
this.dateTimePicker.Size = new System.Drawing.Size(250, 27);
|
||||
this.dateTimePicker.TabIndex = 0;
|
||||
this.dateTimePicker.ValueChanged += new System.EventHandler(this.dateTimePicker_ValueChanged);
|
||||
//
|
||||
// AbazovDatePicker
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.Controls.Add(this.dateTimePicker);
|
||||
this.Name = "AbazovDatePicker";
|
||||
this.Size = new System.Drawing.Size(257, 38);
|
||||
this.ResumeLayout(false);
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private DateTimePicker dateTimePicker;
|
||||
}
|
||||
}
|
@ -0,0 +1,73 @@
|
||||
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 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);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,60 @@
|
||||
<root>
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
@ -0,0 +1,19 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AbazovViewComponents.Exceptions
|
||||
{
|
||||
[Serializable]
|
||||
public class DateBoundsNotSetException: ApplicationException
|
||||
{
|
||||
public DateBoundsNotSetException() : base() { }
|
||||
public DateBoundsNotSetException(string message) : base(message) { }
|
||||
public DateBoundsNotSetException(string message, Exception exception) : base(message, exception){ }
|
||||
protected DateBoundsNotSetException(SerializationInfo info, StreamingContext contex) : base(info, contex) { }
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AbazovViewComponents.Exceptions
|
||||
{
|
||||
public class DateOutOfBoundsException : ApplicationException
|
||||
{
|
||||
public DateOutOfBoundsException() : base() { }
|
||||
public DateOutOfBoundsException(string message) : base(message) { }
|
||||
public DateOutOfBoundsException(string message, Exception exception) : base(message, exception) { }
|
||||
protected DateOutOfBoundsException(SerializationInfo info, StreamingContext contex) : base(info, contex) { }
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user