Compare commits

..

5 Commits
main ... lab1

25 changed files with 1369 additions and 0 deletions

View File

@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWindowsForms>true</UseWindowsForms>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
</Project>

View File

@ -0,0 +1,7 @@
namespace Components.Exceptions
{
public class NodeIsNotLeafException : UserControlTreeViewException
{
public NodeIsNotLeafException() : base("Selected node is not a leaf") { }
}
}

View File

@ -0,0 +1,7 @@
namespace Components.Exceptions
{
public class NotSelectedNodeException : UserControlTreeViewException
{
public NotSelectedNodeException() : base("Node is not selected") { }
}
}

View File

@ -0,0 +1,7 @@
namespace Components.Exceptions
{
public class PropertyNotDeclaratedException : UserControlTreeViewException
{
public PropertyNotDeclaratedException(string propName) : base($"Property \"{propName}\" not declared") { }
}
}

View File

@ -0,0 +1,7 @@
namespace Components.Exceptions
{
public class PropertyNullException : UserControlTreeViewException
{
public PropertyNullException(string propName) : base($"Property \"{propName}\" is null") { }
}
}

View File

@ -0,0 +1,8 @@
namespace Components.Exceptions
{
public class RangeNotSetException : Exception
{
public RangeNotSetException() { }
public RangeNotSetException(string message) : base(message) { }
}
}

View File

@ -0,0 +1,7 @@
namespace Components.Exceptions
{
public class TreeHierarchyNotSetException : UserControlTreeViewException
{
public TreeHierarchyNotSetException() : base("Tree hierarchy not set") { }
}
}

View File

@ -0,0 +1,8 @@
namespace Components.Exceptions
{
public class UserControlTreeViewException : Exception
{
public UserControlTreeViewException() { }
public UserControlTreeViewException(string message) : base(message) { }
}
}

View File

@ -0,0 +1,8 @@
namespace Components.Exceptions
{
public class ValueOutOfRangeException : Exception
{
public ValueOutOfRangeException() { }
public ValueOutOfRangeException(string message) : base(message) { }
}
}

View File

@ -0,0 +1,60 @@
namespace Components
{
partial class UserControlCheckedList
{
/// <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()
{
checkedListBox = new CheckedListBox();
SuspendLayout();
//
// checkedListBox
//
checkedListBox.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
checkedListBox.CheckOnClick = true;
checkedListBox.FormattingEnabled = true;
checkedListBox.Location = new Point(20, 15);
checkedListBox.Name = "checkedListBox";
checkedListBox.Size = new Size(276, 148);
checkedListBox.TabIndex = 0;
checkedListBox.ItemCheck += checkedListBox_ItemCheck;
//
// UserControlCheckedList
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
BackColor = Color.Firebrick;
Controls.Add(checkedListBox);
Name = "UserControlCheckedList";
Size = new Size(318, 183);
ResumeLayout(false);
}
#endregion
private CheckedListBox checkedListBox;
}
}

View File

@ -0,0 +1,59 @@
namespace Components
{
public partial class UserControlCheckedList : UserControl
{
private EventHandler _onCheckedItemChangedEvent;
public event EventHandler CheckedItemChanged
{
add
{
_onCheckedItemChangedEvent += value;
}
remove
{
_onCheckedItemChangedEvent -= value;
}
}
public string CheckedItem
{
get
{
return checkedListBox.CheckedItems[0] as string ?? string.Empty;
}
set
{
if (checkedListBox.Items.Contains(value))
{
checkedListBox.SetItemCheckState(checkedListBox.Items.IndexOf(value), CheckState.Checked);
}
}
}
public UserControlCheckedList()
{
InitializeComponent();
}
public void SetCheckedListBoxValues(List<string> values)
{
ClearCheckedListBoxValues();
foreach (var item in values)
{
checkedListBox.Items.Add(item);
}
}
public void ClearCheckedListBoxValues()
{
checkedListBox.Items.Clear();
}
private void checkedListBox_ItemCheck(object sender, ItemCheckEventArgs e)
{
for (int i = 0; i < checkedListBox.Items.Count; i++)
{
if (i != e.Index)
{
checkedListBox.SetItemChecked(i, false);
}
}
_onCheckedItemChangedEvent?.Invoke(sender, e);
}
}
}

View 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>

View File

@ -0,0 +1,59 @@
namespace Components
{
partial class UserControlDatePicker
{
/// <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()
{
dateTimePicker = new DateTimePicker();
SuspendLayout();
//
// dateTimePicker
//
dateTimePicker.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
dateTimePicker.Format = DateTimePickerFormat.Short;
dateTimePicker.Location = new Point(15, 12);
dateTimePicker.Name = "dateTimePicker";
dateTimePicker.Size = new Size(92, 23);
dateTimePicker.TabIndex = 0;
dateTimePicker.ValueChanged += dateTimePicker_ValueChanged;
//
// UserControlDatePicker
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
BackColor = Color.Orange;
Controls.Add(dateTimePicker);
Name = "UserControlDatePicker";
Size = new Size(121, 50);
ResumeLayout(false);
}
#endregion
private DateTimePicker dateTimePicker;
}
}

View File

@ -0,0 +1,55 @@
using Components.Exceptions;
namespace Components
{
public partial class UserControlDatePicker : UserControl
{
public DateTime? MinDate;
public DateTime? MaxDate;
public DateTime Date
{
get
{
if (MinDate == null || MaxDate == null)
{
throw new RangeNotSetException("Диапазон дат не задан");
}
if (dateTimePicker.Value < MinDate || dateTimePicker.Value > MaxDate)
{
throw new ValueOutOfRangeException("Значение даты вне диапазона");
}
return dateTimePicker.Value;
}
set
{
if (MinDate != null && MaxDate != null)
{
if (value >= MinDate && value <= MaxDate)
{
dateTimePicker.Value = value;
}
}
}
}
private EventHandler _onValueChangedEvent;
public event EventHandler ValueChanged
{
add
{
_onValueChangedEvent += value;
}
remove
{
_onValueChangedEvent -= value;
}
}
public UserControlDatePicker()
{
InitializeComponent();
}
private void dateTimePicker_ValueChanged(object sender, EventArgs e)
{
_onValueChangedEvent?.Invoke(sender, e);
}
}
}

View 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>

View File

@ -0,0 +1,56 @@
namespace Components
{
partial class UserControlTreeView
{
/// <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()
{
treeView = new TreeView();
SuspendLayout();
//
// treeView
//
treeView.Location = new Point(22, 17);
treeView.Name = "treeView";
treeView.Size = new Size(188, 285);
treeView.TabIndex = 0;
//
// UserControlTreeView
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
BackColor = SystemColors.ActiveCaption;
Controls.Add(treeView);
Name = "UserControlTreeView";
Size = new Size(232, 335);
ResumeLayout(false);
}
#endregion
private TreeView treeView;
}
}

View File

@ -0,0 +1,142 @@
using Components.Exceptions;
using System.Reflection;
namespace Components
{
public partial class UserControlTreeView : UserControl
{
public int SelectedIndex
{
get
{
return treeView.SelectedNode?.Index ?? -1;
}
set
{
if (value > -1 && value < treeView.Nodes.Count)
{
treeView.SelectedNode = treeView.Nodes[value];
}
}
}
private List<(string PropertyName, bool AlwaysCreateBranch)> Hierarchy;
public UserControlTreeView()
{
InitializeComponent();
Hierarchy = [];
}
public T GetObjectSelectedNode<T>()
where T : class, new()
{
var node = treeView.SelectedNode;
if (node == null)
{
throw new NotSelectedNodeException();
}
if ((Hierarchy?.Count ?? 0) == 0)
{
throw new TreeHierarchyNotSetException();
}
if (node.Nodes.Count > 0)
{
throw new NodeIsNotLeafException();
}
T obj = new T();
int propIndex = GetNodeDepth(node);
while (node != null)
{
string propValue = node.Text;
string propName = Hierarchy[propIndex].PropertyName;
var prop = obj.GetType().GetProperty(propName);
if (prop == null)
{
throw new PropertyNotDeclaratedException(propName);
}
prop.SetValue(obj, propValue);
node = node.Parent;
propIndex--;
}
return obj;
}
private int GetNodeDepth(TreeNode node)
{
int depth = 0;
while (node.Parent != null)
{
depth++;
node = node.Parent;
}
return depth;
}
public void SetTreeObjects<T>(List<T> objects)
{
if (objects.Count == 0)
{
return;
}
if ((Hierarchy?.Count ?? 0) == 0)
{
throw new TreeHierarchyNotSetException();
}
PropertyInfo[]? properties = objects[0]!.GetType().GetProperties();
ClearTreeView();
foreach (T obj in objects)
{
var nodes = treeView.Nodes;
foreach (var hierarchyProperty in Hierarchy)
{
PropertyInfo? objectPropertyInfo = properties?.Single(prop => prop.Name == hierarchyProperty.PropertyName);
if (objectPropertyInfo == null)
{
throw new PropertyNotDeclaratedException(hierarchyProperty.PropertyName);
}
string? objectPropertyValue = objectPropertyInfo.GetValue(obj)?.ToString() ?? null;
if (objectPropertyValue == null)
{
throw new PropertyNullException(hierarchyProperty.PropertyName);
}
TreeNode? node = null;
if (!hierarchyProperty.AlwaysCreateBranch)
{
foreach (TreeNode childNode in nodes)
{
if (childNode.Text == objectPropertyValue)
{
node = childNode;
break;
}
}
}
if (node == null)
{
node = nodes.Add(objectPropertyValue);
}
nodes = node.Nodes;
}
}
}
public void SetHierarchy(List<(string PropertyName, bool AlwaysCreateBranch)> hierarchy)
{
Hierarchy = hierarchy;
}
public void ClearTreeView()
{
treeView.Nodes.Clear();
treeView.Update();
}
}
}

View 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>

View File

@ -0,0 +1,31 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.11.35222.181
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Components", "Components\Components.csproj", "{18A921F6-FEBD-44BE-B74B-693AD384FD65}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WinFormsApp", "WinFormsApp\WinFormsApp.csproj", "{B2B2491A-9FAF-4682-B859-CEA0D63E593E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{18A921F6-FEBD-44BE-B74B-693AD384FD65}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{18A921F6-FEBD-44BE-B74B-693AD384FD65}.Debug|Any CPU.Build.0 = Debug|Any CPU
{18A921F6-FEBD-44BE-B74B-693AD384FD65}.Release|Any CPU.ActiveCfg = Release|Any CPU
{18A921F6-FEBD-44BE-B74B-693AD384FD65}.Release|Any CPU.Build.0 = Release|Any CPU
{B2B2491A-9FAF-4682-B859-CEA0D63E593E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B2B2491A-9FAF-4682-B859-CEA0D63E593E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B2B2491A-9FAF-4682-B859-CEA0D63E593E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B2B2491A-9FAF-4682-B859-CEA0D63E593E}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {431FB736-164C-4849-B179-D048D3651094}
EndGlobalSection
EndGlobal

View File

@ -0,0 +1,22 @@
namespace WinFormsApp
{
public class Employee
{
public string Departament { get; set; }
public string Position { get; set; }
public string Name { get; set; }
public string Surname { get; set; }
public Employee() { }
public Employee(string departament, string position, string surname, string name)
{
Departament = departament;
Position = position;
Name = name;
Surname = surname;
}
public override string ToString()
{
return Departament + ", " + Position + ", " + Surname + " " + Name;
}
}
}

View File

@ -0,0 +1,213 @@
namespace WinFormsApp
{
partial class Form
{
/// <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()
{
userControlCheckedList = new Components.UserControlCheckedList();
buttonFillCheckedList = new Button();
buttonClearList = new Button();
userControlDatePicker = new Components.UserControlDatePicker();
dateTimePickerMinDate = new DateTimePicker();
dateTimePicker1 = new DateTimePicker();
label1 = new Label();
label2 = new Label();
userControlTreeView = new Components.UserControlTreeView();
buttonFillTreeView = new Button();
buttonClearTreeView = new Button();
buttonShowTreeViewNode = new Button();
textBoxTreeViewSelectedNodeIndex = new TextBox();
textBoxTreeViewSelectedObject = new TextBox();
SuspendLayout();
//
// userControlCheckedList
//
userControlCheckedList.BackColor = Color.Firebrick;
userControlCheckedList.Location = new Point(12, 12);
userControlCheckedList.Name = "userControlCheckedList";
userControlCheckedList.Size = new Size(168, 170);
userControlCheckedList.TabIndex = 0;
//
// buttonFillCheckedList
//
buttonFillCheckedList.Location = new Point(12, 202);
buttonFillCheckedList.Name = "buttonFillCheckedList";
buttonFillCheckedList.Size = new Size(75, 23);
buttonFillCheckedList.TabIndex = 1;
buttonFillCheckedList.Text = "Заполнить";
buttonFillCheckedList.UseVisualStyleBackColor = true;
buttonFillCheckedList.Click += buttonFillCheckedList_Click;
//
// buttonClearList
//
buttonClearList.Location = new Point(105, 202);
buttonClearList.Name = "buttonClearList";
buttonClearList.Size = new Size(75, 23);
buttonClearList.TabIndex = 2;
buttonClearList.Text = "Очистить";
buttonClearList.UseVisualStyleBackColor = true;
buttonClearList.Click += buttonClearList_Click;
//
// userControlDatePicker
//
userControlDatePicker.BackColor = Color.Orange;
userControlDatePicker.Location = new Point(273, 12);
userControlDatePicker.Name = "userControlDatePicker";
userControlDatePicker.Size = new Size(121, 50);
userControlDatePicker.TabIndex = 3;
//
// dateTimePickerMinDate
//
dateTimePickerMinDate.Format = DateTimePickerFormat.Short;
dateTimePickerMinDate.Location = new Point(246, 95);
dateTimePickerMinDate.Name = "dateTimePickerMinDate";
dateTimePickerMinDate.Size = new Size(91, 23);
dateTimePickerMinDate.TabIndex = 4;
//
// dateTimePicker1
//
dateTimePicker1.Format = DateTimePickerFormat.Short;
dateTimePicker1.Location = new Point(343, 95);
dateTimePicker1.Name = "dateTimePicker1";
dateTimePicker1.Size = new Size(95, 23);
dateTimePicker1.TabIndex = 5;
//
// label1
//
label1.AutoSize = true;
label1.Location = new Point(264, 77);
label1.Name = "label1";
label1.Size = new Size(52, 15);
label1.TabIndex = 6;
label1.Text = "MinDate";
//
// label2
//
label2.AutoSize = true;
label2.Location = new Point(361, 77);
label2.Name = "label2";
label2.Size = new Size(54, 15);
label2.TabIndex = 7;
label2.Text = "MaxDate";
//
// userControlTreeView
//
userControlTreeView.BackColor = SystemColors.ActiveCaption;
userControlTreeView.Location = new Point(498, 12);
userControlTreeView.Name = "userControlTreeView";
userControlTreeView.SelectedIndex = 0;
userControlTreeView.Size = new Size(232, 320);
userControlTreeView.TabIndex = 8;
//
// buttonFillTreeView
//
buttonFillTreeView.Location = new Point(498, 348);
buttonFillTreeView.Name = "buttonFillTreeView";
buttonFillTreeView.Size = new Size(75, 23);
buttonFillTreeView.TabIndex = 9;
buttonFillTreeView.Text = "Заполнить";
buttonFillTreeView.UseVisualStyleBackColor = true;
buttonFillTreeView.Click += buttonFillTreeView_Click;
//
// buttonClearTreeView
//
buttonClearTreeView.Location = new Point(574, 348);
buttonClearTreeView.Name = "buttonClearTreeView";
buttonClearTreeView.Size = new Size(75, 23);
buttonClearTreeView.TabIndex = 10;
buttonClearTreeView.Text = "Очистить";
buttonClearTreeView.UseVisualStyleBackColor = true;
buttonClearTreeView.Click += buttonClearTreeView_Click;
//
// buttonShowTreeViewNode
//
buttonShowTreeViewNode.Location = new Point(655, 348);
buttonShowTreeViewNode.Name = "buttonShowTreeViewNode";
buttonShowTreeViewNode.Size = new Size(75, 23);
buttonShowTreeViewNode.TabIndex = 11;
buttonShowTreeViewNode.Text = "Показать";
buttonShowTreeViewNode.UseVisualStyleBackColor = true;
buttonShowTreeViewNode.Click += buttonShowTreeViewNode_Click;
//
// textBoxTreeViewSelectedNodeIndex
//
textBoxTreeViewSelectedNodeIndex.Location = new Point(630, 397);
textBoxTreeViewSelectedNodeIndex.Name = "textBoxTreeViewSelectedNodeIndex";
textBoxTreeViewSelectedNodeIndex.Size = new Size(100, 23);
textBoxTreeViewSelectedNodeIndex.TabIndex = 12;
//
// textBoxTreeViewSelectedObject
//
textBoxTreeViewSelectedObject.Location = new Point(31, 397);
textBoxTreeViewSelectedObject.Name = "textBoxTreeViewSelectedObject";
textBoxTreeViewSelectedObject.ReadOnly = true;
textBoxTreeViewSelectedObject.Size = new Size(593, 23);
textBoxTreeViewSelectedObject.TabIndex = 13;
//
// Form
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(768, 470);
Controls.Add(textBoxTreeViewSelectedObject);
Controls.Add(textBoxTreeViewSelectedNodeIndex);
Controls.Add(buttonShowTreeViewNode);
Controls.Add(buttonClearTreeView);
Controls.Add(buttonFillTreeView);
Controls.Add(userControlTreeView);
Controls.Add(label2);
Controls.Add(label1);
Controls.Add(dateTimePicker1);
Controls.Add(dateTimePickerMinDate);
Controls.Add(userControlDatePicker);
Controls.Add(buttonClearList);
Controls.Add(buttonFillCheckedList);
Controls.Add(userControlCheckedList);
Name = "Form";
Text = "Form";
ResumeLayout(false);
PerformLayout();
}
#endregion
private Components.UserControlCheckedList userControlCheckedList;
private Button buttonFillCheckedList;
private Button buttonClearList;
private Components.UserControlDatePicker userControlDatePicker;
private DateTimePicker dateTimePickerMinDate;
private DateTimePicker dateTimePicker1;
private Label label1;
private Label label2;
private Components.UserControlTreeView userControlTreeView;
private Button buttonFillTreeView;
private Button buttonClearTreeView;
private Button buttonShowTreeViewNode;
private TextBox textBoxTreeViewSelectedNodeIndex;
private TextBox textBoxTreeViewSelectedObject;
}
}

View File

@ -0,0 +1,91 @@
using Components.Exceptions;
namespace WinFormsApp
{
public partial class Form : System.Windows.Forms.Form
{
public Form()
{
InitializeComponent();
}
private void buttonFillCheckedList_Click(object sender, EventArgs e)
{
List<string> list = new List<string>();
list.Add("Êàæäûé");
list.Add("Ïðîãðàììèñò");
list.Add("Æåëàåò");
list.Add("Çíàòü");
list.Add("C#");
userControlCheckedList.SetCheckedListBoxValues(list);
userControlCheckedList.CheckedItem = list[3];
}
private void buttonClearList_Click(object sender, EventArgs e)
{
userControlCheckedList.ClearCheckedListBoxValues();
}
private void buttonFillTreeView_Click(object sender, EventArgs e)
{
List<Employee> employees = new List<Employee>();
employees.Add(new Employee("Îòäåë ïðîäàæ", "Ìåíåäæåð", "Èâàíîâ", "Ñåìåí"));
employees.Add(new Employee("Îòäåë ìàðêåòèíãà", "Ìàðêåòîëîã", "Êàþìîâà", "Ñâåòëàíà"));
employees.Add(new Employee("Îòäåë ôèíàíñîâ", "Áóõãàëòåð", "Ðàõèìîâà", "Ýëüâèðà"));
employees.Add(new Employee("Îòäåë çàêóïîê", "Ìåíåäæåð", "Ñåìåíîâ", "Ïåòð"));
employees.Add(new Employee("Îòäåë ïðîäàæ", "Ìåíåäæåð", "Èâàíîâ", "Ïàâåë"));
employees.Add(new Employee("Îòäåë ìàðêåòèíãà", "Ìàðêåòîëîã", "Êàðàìûøåâà", "Òàòüÿíà"));
employees.Add(new Employee("Îòäåë ôèíàíñîâ", "Ôèíàíñèñò", "Àáàëîâ", "Àëüáåðò"));
employees.Add(new Employee("Îòäåë çàêóïîê", "Ãëàâíûé ìåíåäæåð", "Ìî÷àëîâ", "Àëåêñåé"));
employees.Add(new Employee("Îòäåë ïðîäàæ", "Ãëàâíûé ìåíåäæåð", "Êóçíåöîâà", "Ìàðèÿ"));
employees.Add(new Employee("Îòäåë ìàðêåòèíãà", "PR-ñïåöèàëèñò", "Êóòÿêîâ", "Ìèõàèë"));
employees.Add(new Employee("Îòäåë ôèíàíñîâ", "Àíàëèòèê", "Àñòàôüåâ", "Ïàâåë"));
employees.Add(new Employee("Îòäåë çàêóïîê", "Àíàëèòèê", "Ñìèðíîâà", "Àíàñòàñèÿ"));
List<(string PropertyName, bool AlwaysCreateBranch)> hierarchy =
[
("Departament", false),
("Position", false),
("Surname", false),
("Name", false),
];
userControlTreeView.SetHierarchy(hierarchy);
userControlTreeView.SetTreeObjects(employees);
}
private void buttonClearTreeView_Click(object sender, EventArgs e)
{
userControlTreeView.ClearTreeView();
}
private void buttonShowTreeViewNode_Click(object sender, EventArgs e)
{
Employee employee;
try
{
employee = userControlTreeView.GetObjectSelectedNode<Employee>();
textBoxTreeViewSelectedObject.Text = employee.ToString();
}
catch (PropertyNotDeclaratedException ex)
{
MessageBox.Show(ex.Message);
textBoxTreeViewSelectedObject.Text = string.Empty;
}
catch (PropertyNullException ex)
{
MessageBox.Show(ex.Message);
textBoxTreeViewSelectedObject.Text = string.Empty;
}
catch (NotSelectedNodeException ex)
{
MessageBox.Show(ex.Message);
textBoxTreeViewSelectedObject.Text = string.Empty;
}
}
}
}

View 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>

View File

@ -0,0 +1,17 @@
namespace WinFormsApp
{
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 Form());
}
}
}

View File

@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net8.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWindowsForms>true</UseWindowsForms>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Components\Components.csproj" />
</ItemGroup>
</Project>