lab1
This commit is contained in:
parent
42dbfbbe8b
commit
188d33f5d1
34
Library36/Library36.sln
Normal file
34
Library36/Library36.sln
Normal file
@ -0,0 +1,34 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.11.35327.3
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Library36", "Library36\Library36.csproj", "{C00E43CC-2774-49D4-A88B-68511E92C85D}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Test", "Test\Test.csproj", "{C53E2551-8E80-4180-A4A9-61AA4A080C74}"
|
||||
ProjectSection(ProjectDependencies) = postProject
|
||||
{C00E43CC-2774-49D4-A88B-68511E92C85D} = {C00E43CC-2774-49D4-A88B-68511E92C85D}
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{C00E43CC-2774-49D4-A88B-68511E92C85D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{C00E43CC-2774-49D4-A88B-68511E92C85D}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{C00E43CC-2774-49D4-A88B-68511E92C85D}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{C00E43CC-2774-49D4-A88B-68511E92C85D}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{C53E2551-8E80-4180-A4A9-61AA4A080C74}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{C53E2551-8E80-4180-A4A9-61AA4A080C74}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{C53E2551-8E80-4180-A4A9-61AA4A080C74}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{C53E2551-8E80-4180-A4A9-61AA4A080C74}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {950FED72-BF84-4C12-94A7-ADBC5A288FDA}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
11
Library36/Library36/ColumnsConfiguratoin.cs
Normal file
11
Library36/Library36/ColumnsConfiguratoin.cs
Normal file
@ -0,0 +1,11 @@
|
||||
namespace Library36
|
||||
{
|
||||
public class ColumnsConfiguratoin
|
||||
{
|
||||
public int ColumnsCount { get; set; }
|
||||
public string[] NameColumn { get; set; } = Array.Empty<string>();
|
||||
public int[] Width { get; set; } = { 0, 0 };
|
||||
public bool[] Visible { get; set; } = Array.Empty<bool>();
|
||||
public string[]? PropertiesObject { get; set; }
|
||||
}
|
||||
}
|
67
Library36/Library36/CustomDataGridView.Designer.cs
generated
Normal file
67
Library36/Library36/CustomDataGridView.Designer.cs
generated
Normal file
@ -0,0 +1,67 @@
|
||||
namespace Library36
|
||||
{
|
||||
partial class CustomDataGridView
|
||||
{
|
||||
/// <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()
|
||||
{
|
||||
dataGridViewItems = new DataGridView();
|
||||
((System.ComponentModel.ISupportInitialize)dataGridViewItems).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
// dataGridViewItems
|
||||
//
|
||||
dataGridViewItems.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
|
||||
dataGridViewItems.BackgroundColor = SystemColors.ButtonHighlight;
|
||||
dataGridViewItems.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||
dataGridViewItems.Location = new Point(0, 0);
|
||||
dataGridViewItems.Margin = new Padding(4);
|
||||
dataGridViewItems.MultiSelect = false; // <--- Добавлено для выбора только одной строки
|
||||
dataGridViewItems.Name = "dataGridViewItems";
|
||||
dataGridViewItems.RowHeadersVisible = false;
|
||||
dataGridViewItems.RowHeadersWidth = 51;
|
||||
dataGridViewItems.RowTemplate.Height = 29;
|
||||
dataGridViewItems.Size = new Size(729, 441);
|
||||
dataGridViewItems.TabIndex = 0;
|
||||
dataGridViewItems.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect;
|
||||
//
|
||||
// CustomDataGridView
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(10F, 25F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
Controls.Add(dataGridViewItems);
|
||||
Margin = new Padding(4, 5, 4, 5);
|
||||
Name = "CustomDataGridView";
|
||||
Size = new Size(729, 441);
|
||||
((System.ComponentModel.ISupportInitialize)dataGridViewItems).EndInit();
|
||||
ResumeLayout(false);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private DataGridView dataGridViewItems;
|
||||
}
|
||||
}
|
123
Library36/Library36/CustomDataGridView.cs
Normal file
123
Library36/Library36/CustomDataGridView.cs
Normal file
@ -0,0 +1,123 @@
|
||||
namespace Library36
|
||||
{
|
||||
public partial class CustomDataGridView : UserControl
|
||||
{
|
||||
private DataGridView dataGridView;
|
||||
|
||||
public CustomDataGridView()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
public DataGridViewRowCollection Rows
|
||||
{
|
||||
get { return dataGridViewItems.Rows; }
|
||||
}
|
||||
public int SelectedRow
|
||||
{
|
||||
get { return dataGridViewItems.SelectedRows[0].Index; }
|
||||
set
|
||||
{
|
||||
if (dataGridViewItems.SelectedRows.Count <= value || value < 0)
|
||||
throw new ArgumentException(string.Format("{0} is an invalid row index.", value));
|
||||
else
|
||||
{
|
||||
dataGridViewItems.ClearSelection();
|
||||
dataGridViewItems.Rows[value].Selected = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
public void ClearDataGrid()
|
||||
{
|
||||
dataGridViewItems.DataSource = null;
|
||||
dataGridViewItems.Rows.Clear();
|
||||
}
|
||||
public void ConfigColumn(ColumnsConfiguratoin columnsData)
|
||||
{
|
||||
dataGridViewItems.ColumnCount = columnsData.ColumnsCount;
|
||||
for (int i = 0; i < columnsData.ColumnsCount; i++)
|
||||
{
|
||||
dataGridViewItems.Columns[i].Name = columnsData.NameColumn[i];
|
||||
dataGridViewItems.Columns[i].Width = columnsData.Width[i];
|
||||
dataGridViewItems.Columns[i].Visible = columnsData.Visible[i];
|
||||
dataGridViewItems.Columns[i].DataPropertyName = columnsData.PropertiesObject[i];
|
||||
}
|
||||
}
|
||||
public T GetSelectedObjectInRow<T>() where T : class, new()
|
||||
{
|
||||
T val = new();
|
||||
|
||||
var propertiesObj = typeof(T).GetProperties();
|
||||
foreach (var properties in propertiesObj)
|
||||
{
|
||||
bool propIsExist = false;
|
||||
int columnIndex = 0;
|
||||
for (; columnIndex < dataGridViewItems.Columns.Count; columnIndex++)
|
||||
{
|
||||
if (dataGridViewItems.Columns[columnIndex].DataPropertyName == properties.Name)
|
||||
{
|
||||
propIsExist = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (propIsExist)
|
||||
{
|
||||
object value = dataGridViewItems.SelectedRows[0].Cells[columnIndex].Value;
|
||||
if (value == null || value == DBNull.Value)
|
||||
{
|
||||
if (properties.PropertyType == typeof(int?))
|
||||
{
|
||||
properties.SetValue(val, null);
|
||||
}
|
||||
else if (properties.PropertyType.IsValueType)
|
||||
{
|
||||
properties.SetValue(val, Activator.CreateInstance(properties.PropertyType));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
if (properties.PropertyType == typeof(int?))
|
||||
{
|
||||
if (int.TryParse(value.ToString(), out int intValue))
|
||||
{
|
||||
properties.SetValue(val, intValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
properties.SetValue(val, null);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
properties.SetValue(val, Convert.ChangeType(value, properties.PropertyType));
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"Ошибка преобразования для свойства {properties.Name}: {ex.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
public void AddItem<T>(T item, int RowIndex, int ColumnIndex)
|
||||
{
|
||||
if (item == null)
|
||||
return;
|
||||
|
||||
string propertyName = dataGridViewItems.Columns[ColumnIndex].DataPropertyName.ToString();
|
||||
string? value = item.GetType().GetProperty(propertyName)?.GetValue(item)?.ToString();
|
||||
|
||||
if (RowIndex >= dataGridViewItems.Rows.Count)
|
||||
{
|
||||
dataGridViewItems.RowCount = RowIndex + 1;
|
||||
}
|
||||
|
||||
dataGridViewItems.Rows[RowIndex].Cells[ColumnIndex].Value = value;
|
||||
}
|
||||
}
|
||||
}
|
120
Library36/Library36/CustomDataGridView.resx
Normal file
120
Library36/Library36/CustomDataGridView.resx
Normal file
@ -0,0 +1,120 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<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>
|
61
Library36/Library36/CustomListBox.Designer.cs
generated
Normal file
61
Library36/Library36/CustomListBox.Designer.cs
generated
Normal file
@ -0,0 +1,61 @@
|
||||
namespace Library36
|
||||
{
|
||||
partial class CustomListBox
|
||||
{
|
||||
/// <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()
|
||||
{
|
||||
listBoxCustom = new ListBox();
|
||||
SuspendLayout();
|
||||
//
|
||||
// listBoxCustom
|
||||
//
|
||||
listBoxCustom.Dock = DockStyle.Fill;
|
||||
listBoxCustom.FormattingEnabled = true;
|
||||
listBoxCustom.ItemHeight = 25;
|
||||
listBoxCustom.Location = new Point(0, 0);
|
||||
listBoxCustom.Margin = new Padding(4);
|
||||
listBoxCustom.Name = "listBoxCustom";
|
||||
listBoxCustom.Size = new Size(306, 315);
|
||||
listBoxCustom.TabIndex = 0;
|
||||
listBoxCustom.SelectedIndexChanged += ListBox_SelectedIndexChanged;
|
||||
//
|
||||
// CustomListBox
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(10F, 25F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
Controls.Add(listBoxCustom);
|
||||
Margin = new Padding(4, 5, 4, 5);
|
||||
Name = "CustomListBox";
|
||||
Size = new Size(306, 315);
|
||||
ResumeLayout(false);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private ListBox listBoxCustom;
|
||||
}
|
||||
}
|
41
Library36/Library36/CustomListBox.cs
Normal file
41
Library36/Library36/CustomListBox.cs
Normal file
@ -0,0 +1,41 @@
|
||||
namespace Library36
|
||||
{
|
||||
public partial class CustomListBox : UserControl
|
||||
{
|
||||
private ListBox listBox;
|
||||
public event EventHandler ValueChanged;
|
||||
public CustomListBox()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
private void ListBox_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
ValueChanged?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
public string SelectedValue
|
||||
{
|
||||
get => listBoxCustom.SelectedItem?.ToString() ?? string.Empty;
|
||||
set
|
||||
{
|
||||
if (listBoxCustom.Items.Contains(value))
|
||||
listBoxCustom.SelectedItem = value;
|
||||
}
|
||||
}
|
||||
public ListBox.ObjectCollection ItemCollection
|
||||
{
|
||||
get => listBoxCustom.Items;
|
||||
}
|
||||
public void ClearList()
|
||||
{
|
||||
listBoxCustom.Items.Clear();
|
||||
}
|
||||
public void PopulateList(List<string> items)
|
||||
{
|
||||
listBoxCustom.Items.Clear();
|
||||
foreach (var item in items)
|
||||
{
|
||||
listBoxCustom.Items.Add(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
120
Library36/Library36/CustomListBox.resx
Normal file
120
Library36/Library36/CustomListBox.resx
Normal file
@ -0,0 +1,120 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<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>
|
73
Library36/Library36/DateBoxWithNull.Designer.cs
generated
Normal file
73
Library36/Library36/DateBoxWithNull.Designer.cs
generated
Normal file
@ -0,0 +1,73 @@
|
||||
namespace Library36
|
||||
{
|
||||
partial class DateBoxWithNull
|
||||
{
|
||||
/// <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()
|
||||
{
|
||||
checkBoxNull = new CheckBox();
|
||||
textBoxDate = new TextBox();
|
||||
SuspendLayout();
|
||||
//
|
||||
// checkBoxNull
|
||||
//
|
||||
checkBoxNull.AutoSize = true;
|
||||
checkBoxNull.Location = new Point(5, 10);
|
||||
checkBoxNull.Margin = new Padding(4, 4, 4, 4);
|
||||
checkBoxNull.Name = "checkBoxNull";
|
||||
checkBoxNull.Size = new Size(22, 21);
|
||||
checkBoxNull.TabIndex = 0;
|
||||
checkBoxNull.UseVisualStyleBackColor = true;
|
||||
checkBoxNull.CheckedChanged += CheckBoxNull_CheckedChanged;
|
||||
//
|
||||
// textBoxDate
|
||||
//
|
||||
textBoxDate.Location = new Point(35, 2);
|
||||
textBoxDate.Margin = new Padding(4, 4, 4, 4);
|
||||
textBoxDate.Name = "textBoxDate";
|
||||
textBoxDate.Size = new Size(283, 31);
|
||||
textBoxDate.TabIndex = 1;
|
||||
textBoxDate.TextChanged += TextBoxDate_TextChanged;
|
||||
//
|
||||
// DateBoxWithNull
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(10F, 25F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
Controls.Add(textBoxDate);
|
||||
Controls.Add(checkBoxNull);
|
||||
Margin = new Padding(4, 4, 4, 4);
|
||||
Name = "DateBoxWithNull";
|
||||
Size = new Size(334, 45);
|
||||
ResumeLayout(false);
|
||||
PerformLayout();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private CheckBox checkBoxNull;
|
||||
private TextBox textBoxDate;
|
||||
}
|
||||
}
|
50
Library36/Library36/DateBoxWithNull.cs
Normal file
50
Library36/Library36/DateBoxWithNull.cs
Normal file
@ -0,0 +1,50 @@
|
||||
using System.Globalization;
|
||||
namespace Library36
|
||||
{
|
||||
public partial class DateBoxWithNull : UserControl
|
||||
{
|
||||
public event EventHandler? CombinedEvent;
|
||||
public Exception? Error;
|
||||
public DateBoxWithNull()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
public DateTime? Value
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!checkBoxNull.Checked)
|
||||
{
|
||||
if (string.IsNullOrEmpty(textBoxDate.Text))
|
||||
{
|
||||
throw new NotFilledException("Text box can't be empty, click checkbox if value must be empty!");
|
||||
}
|
||||
if (DateTime.TryParseExact(textBoxDate.Text, "dd.MM.yyyy", null, DateTimeStyles.None, out DateTime parsedDate))
|
||||
{
|
||||
return parsedDate;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new ParseException($"Wrong format <{textBoxDate.Text}>!");
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
set
|
||||
{
|
||||
bool isNull = value is null;
|
||||
checkBoxNull.Checked = isNull;
|
||||
textBoxDate.Text = isNull ? string.Empty : value?.ToString("dd.MM.yyyy");
|
||||
}
|
||||
}
|
||||
private void TextBoxDate_TextChanged(object sender, EventArgs e)
|
||||
{
|
||||
CombinedEvent?.Invoke(sender, e);
|
||||
}
|
||||
private void CheckBoxNull_CheckedChanged(object sender, EventArgs e)
|
||||
{
|
||||
textBoxDate.Enabled = !checkBoxNull.Checked;
|
||||
CombinedEvent?.Invoke(sender, e);
|
||||
}
|
||||
}
|
||||
}
|
120
Library36/Library36/DateBoxWithNull.resx
Normal file
120
Library36/Library36/DateBoxWithNull.resx
Normal file
@ -0,0 +1,120 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<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>
|
10
Library36/Library36/Library36.csproj
Normal file
10
Library36/Library36/Library36.csproj
Normal file
@ -0,0 +1,10 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0-windows</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<UseWindowsForms>true</UseWindowsForms>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
9
Library36/Library36/NotFilledException.cs
Normal file
9
Library36/Library36/NotFilledException.cs
Normal file
@ -0,0 +1,9 @@
|
||||
namespace Library36
|
||||
{
|
||||
public class NotFilledException : Exception
|
||||
{
|
||||
public NotFilledException() { }
|
||||
public NotFilledException(string message) : base(message) { }
|
||||
public NotFilledException(string message, Exception inner) : base(message, inner) { }
|
||||
}
|
||||
}
|
9
Library36/Library36/ParseException.cs
Normal file
9
Library36/Library36/ParseException.cs
Normal file
@ -0,0 +1,9 @@
|
||||
namespace Library36
|
||||
{
|
||||
public class ParseException : Exception
|
||||
{
|
||||
public ParseException() { }
|
||||
public ParseException(string message) : base(message) { }
|
||||
public ParseException(string message, Exception innerException) : base(message, innerException) { }
|
||||
}
|
||||
}
|
222
Library36/Test/FormTest.Designer.cs
generated
Normal file
222
Library36/Test/FormTest.Designer.cs
generated
Normal file
@ -0,0 +1,222 @@
|
||||
using static System.Net.Mime.MediaTypeNames;
|
||||
using System.Windows.Forms;
|
||||
using System.Xml.Linq;
|
||||
using Library36;
|
||||
|
||||
namespace Test
|
||||
{
|
||||
partial class FormTest
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
customDataGridView1 = new CustomDataGridView();
|
||||
customListBox1 = new CustomListBox();
|
||||
dateBoxWithNull1 = new DateBoxWithNull();
|
||||
buttonClear = new Button();
|
||||
buttonLoad = new Button();
|
||||
buttonClearTable = new Button();
|
||||
buttonTableAdd = new Button();
|
||||
buttonGetValue = new Button();
|
||||
buttonGetValueCheckBox = new Button();
|
||||
buttonSetValueCheckBox = new Button();
|
||||
buttonGetList = new Button();
|
||||
buttonAddOneRow = new Button();
|
||||
textBoxDate = new TextBox();
|
||||
SuspendLayout();
|
||||
//
|
||||
// customDataGridView1
|
||||
//
|
||||
customDataGridView1.Location = new Point(329, 16);
|
||||
customDataGridView1.Margin = new Padding(4, 5, 4, 5);
|
||||
customDataGridView1.Name = "customDataGridView1";
|
||||
customDataGridView1.Size = new Size(419, 289);
|
||||
customDataGridView1.TabIndex = 0;
|
||||
//
|
||||
// customListBox1
|
||||
//
|
||||
customListBox1.Location = new Point(15, 16);
|
||||
customListBox1.Margin = new Padding(4, 5, 4, 5);
|
||||
customListBox1.Name = "customListBox1";
|
||||
customListBox1.SelectedValue = "";
|
||||
customListBox1.Size = new Size(306, 232);
|
||||
customListBox1.TabIndex = 1;
|
||||
customListBox1.ValueChanged += CustomListBox1_ValueChanged;
|
||||
//
|
||||
// dateBoxWithNull1
|
||||
//
|
||||
dateBoxWithNull1.Location = new Point(15, 314);
|
||||
dateBoxWithNull1.Margin = new Padding(5);
|
||||
dateBoxWithNull1.Name = "dateBoxWithNull1";
|
||||
dateBoxWithNull1.Size = new Size(306, 42);
|
||||
dateBoxWithNull1.TabIndex = 2;
|
||||
//
|
||||
// buttonClear
|
||||
//
|
||||
buttonClear.Location = new Point(203, 257);
|
||||
buttonClear.Margin = new Padding(4);
|
||||
buttonClear.Name = "buttonClear";
|
||||
buttonClear.Size = new Size(118, 36);
|
||||
buttonClear.TabIndex = 3;
|
||||
buttonClear.Text = "Clear List";
|
||||
buttonClear.UseVisualStyleBackColor = true;
|
||||
buttonClear.Click += buttonClear_Click;
|
||||
//
|
||||
// buttonLoad
|
||||
//
|
||||
buttonLoad.Location = new Point(15, 258);
|
||||
buttonLoad.Margin = new Padding(4);
|
||||
buttonLoad.Name = "buttonLoad";
|
||||
buttonLoad.Size = new Size(100, 36);
|
||||
buttonLoad.TabIndex = 4;
|
||||
buttonLoad.Text = "Load List";
|
||||
buttonLoad.UseVisualStyleBackColor = true;
|
||||
buttonLoad.Click += buttonLoad_Click;
|
||||
//
|
||||
// buttonClearTable
|
||||
//
|
||||
buttonClearTable.Location = new Point(329, 314);
|
||||
buttonClearTable.Margin = new Padding(4);
|
||||
buttonClearTable.Name = "buttonClearTable";
|
||||
buttonClearTable.Size = new Size(103, 36);
|
||||
buttonClearTable.TabIndex = 5;
|
||||
buttonClearTable.Text = "Table clear";
|
||||
buttonClearTable.UseVisualStyleBackColor = true;
|
||||
buttonClearTable.Click += buttonClearTable_Click;
|
||||
//
|
||||
// buttonTableAdd
|
||||
//
|
||||
buttonTableAdd.Location = new Point(440, 314);
|
||||
buttonTableAdd.Margin = new Padding(4);
|
||||
buttonTableAdd.Name = "buttonTableAdd";
|
||||
buttonTableAdd.Size = new Size(105, 36);
|
||||
buttonTableAdd.TabIndex = 6;
|
||||
buttonTableAdd.Text = "Add Table";
|
||||
buttonTableAdd.UseVisualStyleBackColor = true;
|
||||
buttonTableAdd.Click += buttonTableAdd_Click;
|
||||
//
|
||||
// buttonGetValue
|
||||
//
|
||||
buttonGetValue.Location = new Point(553, 315);
|
||||
buttonGetValue.Margin = new Padding(4);
|
||||
buttonGetValue.Name = "buttonGetValue";
|
||||
buttonGetValue.Size = new Size(94, 36);
|
||||
buttonGetValue.TabIndex = 7;
|
||||
buttonGetValue.Text = "Get Value";
|
||||
buttonGetValue.UseVisualStyleBackColor = true;
|
||||
buttonGetValue.Click += buttonGetValue_Click;
|
||||
//
|
||||
// buttonGetValueCheckBox
|
||||
//
|
||||
buttonGetValueCheckBox.Location = new Point(12, 358);
|
||||
buttonGetValueCheckBox.Margin = new Padding(4);
|
||||
buttonGetValueCheckBox.Name = "buttonGetValueCheckBox";
|
||||
buttonGetValueCheckBox.Size = new Size(103, 31);
|
||||
buttonGetValueCheckBox.TabIndex = 8;
|
||||
buttonGetValueCheckBox.Text = "Get value";
|
||||
buttonGetValueCheckBox.UseVisualStyleBackColor = true;
|
||||
buttonGetValueCheckBox.Click += buttonGetValueCheckBox_Click;
|
||||
//
|
||||
// buttonSetValueCheckBox
|
||||
//
|
||||
buttonSetValueCheckBox.Location = new Point(271, 358);
|
||||
buttonSetValueCheckBox.Margin = new Padding(4);
|
||||
buttonSetValueCheckBox.Name = "buttonSetValueCheckBox";
|
||||
buttonSetValueCheckBox.Size = new Size(50, 31);
|
||||
buttonSetValueCheckBox.TabIndex = 9;
|
||||
buttonSetValueCheckBox.Text = "Set";
|
||||
buttonSetValueCheckBox.UseVisualStyleBackColor = true;
|
||||
buttonSetValueCheckBox.Click += buttonSetDate_Click;
|
||||
//
|
||||
// buttonGetList
|
||||
//
|
||||
buttonGetList.Location = new Point(122, 257);
|
||||
buttonGetList.Name = "buttonGetList";
|
||||
buttonGetList.Size = new Size(74, 36);
|
||||
buttonGetList.TabIndex = 11;
|
||||
buttonGetList.Text = "Get";
|
||||
buttonGetList.UseVisualStyleBackColor = true;
|
||||
buttonGetList.Click += buttonGetList_Click;
|
||||
//
|
||||
// buttonAddOneRow
|
||||
//
|
||||
buttonAddOneRow.Location = new Point(654, 316);
|
||||
buttonAddOneRow.Name = "buttonAddOneRow";
|
||||
buttonAddOneRow.Size = new Size(94, 34);
|
||||
buttonAddOneRow.TabIndex = 12;
|
||||
buttonAddOneRow.Text = "Add Row";
|
||||
buttonAddOneRow.UseVisualStyleBackColor = true;
|
||||
buttonAddOneRow.Click += buttonAddOneRow_Click;
|
||||
//
|
||||
// textBoxDate
|
||||
//
|
||||
textBoxDate.Location = new Point(122, 358);
|
||||
textBoxDate.Name = "textBoxDate";
|
||||
textBoxDate.Size = new Size(142, 31);
|
||||
textBoxDate.TabIndex = 13;
|
||||
//
|
||||
// FormTest
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(10F, 25F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(763, 398);
|
||||
Controls.Add(textBoxDate);
|
||||
Controls.Add(buttonAddOneRow);
|
||||
Controls.Add(buttonGetList);
|
||||
Controls.Add(buttonSetValueCheckBox);
|
||||
Controls.Add(buttonGetValueCheckBox);
|
||||
Controls.Add(buttonGetValue);
|
||||
Controls.Add(buttonTableAdd);
|
||||
Controls.Add(buttonClearTable);
|
||||
Controls.Add(buttonLoad);
|
||||
Controls.Add(buttonClear);
|
||||
Controls.Add(dateBoxWithNull1);
|
||||
Controls.Add(customListBox1);
|
||||
Controls.Add(customDataGridView1);
|
||||
Margin = new Padding(4);
|
||||
Name = "FormTest";
|
||||
Text = "FormTest";
|
||||
ResumeLayout(false);
|
||||
PerformLayout();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private Library36.CustomDataGridView customDataGridView1;
|
||||
private Library36.CustomListBox customListBox1;
|
||||
private Library36.DateBoxWithNull dateBoxWithNull1;
|
||||
private Button buttonClear;
|
||||
private Button buttonLoad;
|
||||
private Button buttonClearTable;
|
||||
private Button buttonTableAdd;
|
||||
private Button buttonGetValue;
|
||||
private Button buttonGetValueCheckBox;
|
||||
private Button buttonSetValueCheckBox;
|
||||
private Button buttonGetList;
|
||||
private Button buttonAddOneRow;
|
||||
private TextBox textBoxDate;
|
||||
}
|
||||
}
|
120
Library36/Test/FormTest.cs
Normal file
120
Library36/Test/FormTest.cs
Normal file
@ -0,0 +1,120 @@
|
||||
namespace Test
|
||||
{
|
||||
public partial class FormTest : Form
|
||||
{
|
||||
private bool EmptyFill = false;
|
||||
readonly List<Student> students = new()
|
||||
{
|
||||
new Student { Id = 0, Surname = "Elatomtsev", Height = 195, Iq = 155 },
|
||||
new Student { Id = 1, Surname = "Bakshaeva", Height = 150, Iq = 170 },
|
||||
new Student { Id = 2, Surname = "Firsov", Height = 180, Iq = 100 },
|
||||
new Student { Id = 3, Surname = "Razin", Height = 185, Iq = 140 },
|
||||
|
||||
};
|
||||
readonly List<string> items = new()
|
||||
{
|
||||
new string("item1"),
|
||||
new string("item2"),
|
||||
new string("item3"),
|
||||
new string("item4"),
|
||||
new string("item5"),
|
||||
new string("item6"),
|
||||
new string("item7"),
|
||||
|
||||
};
|
||||
public FormTest()
|
||||
{
|
||||
InitializeComponent();
|
||||
CreateList();
|
||||
}
|
||||
private void CustomListBox1_ValueChanged(object sender, EventArgs e)
|
||||
{
|
||||
MessageBox.Show($"Selected item: {customListBox1.SelectedValue}");
|
||||
}
|
||||
private void CreateList()
|
||||
{
|
||||
customListBox1.PopulateList(items);
|
||||
}
|
||||
private void buttonClear_Click(object sender, EventArgs e)
|
||||
{
|
||||
customListBox1.ClearList();
|
||||
}
|
||||
private void buttonLoad_Click(object sender, EventArgs e)
|
||||
{
|
||||
CreateList();
|
||||
customListBox1.Refresh();
|
||||
}
|
||||
private void buttonGetList_Click(object sender, EventArgs e)
|
||||
{
|
||||
string selectedValue = customListBox1.SelectedValue;
|
||||
MessageBox.Show($"Selected Value: {selectedValue}");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private void CreateTable()
|
||||
{
|
||||
customDataGridView1.ConfigColumn(new()
|
||||
{
|
||||
ColumnsCount = 4,
|
||||
NameColumn = new string[] { "Id", "Surname", "Height", "Iq" },
|
||||
Width = new int[] { 10, 150, 250, 200 },
|
||||
Visible = new bool[] { false, true, true, true },
|
||||
PropertiesObject = new string[] { "Id", "Surname", "Height", "Iq" },
|
||||
});
|
||||
|
||||
foreach (Student student in students)
|
||||
{
|
||||
int rowIndex = customDataGridView1.Rows.Add();
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
customDataGridView1.AddItem(student, rowIndex, i);
|
||||
}
|
||||
}
|
||||
}
|
||||
private void buttonClearTable_Click(object sender, EventArgs e)
|
||||
{
|
||||
customDataGridView1.ClearDataGrid();
|
||||
}
|
||||
private void buttonTableAdd_Click(object sender, EventArgs e)
|
||||
{
|
||||
CreateTable();
|
||||
}
|
||||
private void buttonGetValue_Click(object sender, EventArgs e)
|
||||
{
|
||||
Student selectedStudent = customDataGridView1.GetSelectedObjectInRow<Student>();
|
||||
MessageBox.Show($"Selected Row Index: {customDataGridView1.SelectedRow}");
|
||||
MessageBox.Show($"Selected Student: {selectedStudent}");
|
||||
}
|
||||
private void buttonAddOneRow_Click(object sender, EventArgs e)
|
||||
{
|
||||
Student newStudent = new Student { Id = 4, Surname = "New Student", Height = 185, Iq = 125 };
|
||||
int rowIndex = customDataGridView1.Rows.Add();
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
customDataGridView1.AddItem(newStudent, rowIndex, i);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
private void buttonGetValueCheckBox_Click(object sender, EventArgs e)
|
||||
{
|
||||
MessageBox.Show($"Value is {dateBoxWithNull1.Value}");
|
||||
}
|
||||
private void buttonSetDate_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(textBoxDate.Text))
|
||||
{
|
||||
dateBoxWithNull1.Value = null; // Óñòàíàâëèâàåì çíà÷åíèå null, åñëè textBox ïóñò
|
||||
}
|
||||
else if (DateTime.TryParse(textBoxDate.Text, out DateTime date))
|
||||
{
|
||||
dateBoxWithNull1.Value = date;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
120
Library36/Test/FormTest.resx
Normal file
120
Library36/Test/FormTest.resx
Normal file
@ -0,0 +1,120 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<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>
|
17
Library36/Test/Program.cs
Normal file
17
Library36/Test/Program.cs
Normal file
@ -0,0 +1,17 @@
|
||||
namespace Test
|
||||
{
|
||||
internal static class Program
|
||||
{
|
||||
/// <summary>
|
||||
/// The main entry point for the application.
|
||||
/// </summary>
|
||||
[STAThread]
|
||||
static void Main()
|
||||
{
|
||||
// To customize application configuration such as set high DPI settings or default font,
|
||||
// see https://aka.ms/applicationconfiguration.
|
||||
ApplicationConfiguration.Initialize();
|
||||
Application.Run(new FormTest());
|
||||
}
|
||||
}
|
||||
}
|
26
Library36/Test/Student.cs
Normal file
26
Library36/Test/Student.cs
Normal file
@ -0,0 +1,26 @@
|
||||
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace Test
|
||||
{
|
||||
public class Student
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Surname { get; set; } = string.Empty;
|
||||
public int? Height { get; set; }
|
||||
public int? Iq { get; set; }
|
||||
public Student(int id, string surname, int? height, int? iq)
|
||||
{
|
||||
Id = id;
|
||||
this.Surname = surname;
|
||||
this.Height = height;
|
||||
this.Iq = iq;
|
||||
}
|
||||
public Student() { }
|
||||
public override string ToString()
|
||||
{
|
||||
return $"Surname: {Surname}, Iq: {Iq}";
|
||||
}
|
||||
|
||||
}
|
||||
}
|
15
Library36/Test/Test.csproj
Normal file
15
Library36/Test/Test.csproj
Normal file
@ -0,0 +1,15 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<TargetFramework>net6.0-windows</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<UseWindowsForms>true</UseWindowsForms>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Library36\Library36.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
Loading…
x
Reference in New Issue
Block a user