Merge pull request 'lab1 to main' (#1) from lab1 into main
Reviewed-on: #1
This commit is contained in:
commit
bbaf9cd3fb
14
Components/Components.csproj
Normal file
14
Components/Components.csproj
Normal file
@ -0,0 +1,14 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net7.0-windows</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<UseWindowsForms>true</UseWindowsForms>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="PdfSharp.MigraDoc.Standard" Version="1.51.15" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
14
Components/Exceptions/UncheckedNullException.cs
Normal file
14
Components/Exceptions/UncheckedNullException.cs
Normal file
@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Components.Exceptions
|
||||
{
|
||||
public class UncheckedNullException : Exception
|
||||
{
|
||||
public UncheckedNullException() { }
|
||||
public UncheckedNullException(string message) : base(message) { }
|
||||
}
|
||||
}
|
14
Components/Exceptions/UnexpectedTypeException.cs
Normal file
14
Components/Exceptions/UnexpectedTypeException.cs
Normal file
@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Components.Exceptions
|
||||
{
|
||||
public class UnexpectedTypeException : Exception
|
||||
{
|
||||
public UnexpectedTypeException() { }
|
||||
public UnexpectedTypeException(string message) : base(message) { }
|
||||
}
|
||||
}
|
17
Components/Visual/ColumnInfo.cs
Normal file
17
Components/Visual/ColumnInfo.cs
Normal file
@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Components.Visual
|
||||
{
|
||||
public class ColumnInfo
|
||||
{
|
||||
public string HeaderText { get; set; } = string.Empty;
|
||||
public int Width { get; set; }
|
||||
public bool Visible { get; set; }
|
||||
public string Name { get; set; } = string.Empty;
|
||||
public string DataPropertyName { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
71
Components/Visual/UserControlIntegerInput.Designer.cs
generated
Normal file
71
Components/Visual/UserControlIntegerInput.Designer.cs
generated
Normal file
@ -0,0 +1,71 @@
|
||||
namespace Components
|
||||
{
|
||||
partial class UserControlIntegerInput
|
||||
{
|
||||
/// <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()
|
||||
{
|
||||
textBoxInteger = new TextBox();
|
||||
checkBoxNullable = new CheckBox();
|
||||
SuspendLayout();
|
||||
//
|
||||
// textBoxInteger
|
||||
//
|
||||
textBoxInteger.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
|
||||
textBoxInteger.Location = new Point(24, 1);
|
||||
textBoxInteger.Name = "textBoxInteger";
|
||||
textBoxInteger.Size = new Size(144, 23);
|
||||
textBoxInteger.TabIndex = 0;
|
||||
textBoxInteger.TextChanged += textBoxInteger_TextChanged;
|
||||
//
|
||||
// checkBoxNullable
|
||||
//
|
||||
checkBoxNullable.AutoSize = true;
|
||||
checkBoxNullable.Location = new Point(3, 5);
|
||||
checkBoxNullable.Name = "checkBoxNullable";
|
||||
checkBoxNullable.Size = new Size(15, 14);
|
||||
checkBoxNullable.TabIndex = 1;
|
||||
checkBoxNullable.UseVisualStyleBackColor = true;
|
||||
checkBoxNullable.CheckedChanged += checkBoxNullable_CheckedChanged;
|
||||
//
|
||||
// UserControlIntegerInput
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
Controls.Add(checkBoxNullable);
|
||||
Controls.Add(textBoxInteger);
|
||||
Name = "UserControlIntegerInput";
|
||||
Size = new Size(171, 30);
|
||||
ResumeLayout(false);
|
||||
PerformLayout();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private TextBox textBoxInteger;
|
||||
private CheckBox checkBoxNullable;
|
||||
}
|
||||
}
|
71
Components/Visual/UserControlIntegerInput.cs
Normal file
71
Components/Visual/UserControlIntegerInput.cs
Normal file
@ -0,0 +1,71 @@
|
||||
using Components.Exceptions;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace Components
|
||||
{
|
||||
public partial class UserControlIntegerInput : UserControl
|
||||
{
|
||||
private event EventHandler? _elementChanged;
|
||||
private event Action? _errorOccured;
|
||||
public string Error { get; private set; }
|
||||
public int? InputtedInteger
|
||||
{
|
||||
get
|
||||
{
|
||||
if (checkBoxNullable.Checked)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
if (textBoxInteger.Text.Equals(string.Empty) || textBoxInteger.Text == null)
|
||||
{
|
||||
throw new UncheckedNullException("Input was null, but checkbox wasnt checked");
|
||||
}
|
||||
if (Int32.TryParse(textBoxInteger.Text, out var number))
|
||||
{
|
||||
return number;
|
||||
}
|
||||
throw new UnexpectedTypeException("Input was non integer");
|
||||
}
|
||||
set
|
||||
{
|
||||
textBoxInteger.Text = value.ToString();
|
||||
checkBoxNullable.Checked = value == null;
|
||||
}
|
||||
}
|
||||
public event EventHandler ElementChanged
|
||||
{
|
||||
add { _elementChanged += value; }
|
||||
remove { _elementChanged -= value; }
|
||||
}
|
||||
public event Action AnErrorOccurred
|
||||
{
|
||||
add { _errorOccured += value; }
|
||||
remove { _errorOccured -= value; }
|
||||
}
|
||||
public UserControlIntegerInput()
|
||||
{
|
||||
InitializeComponent();
|
||||
Error = string.Empty;
|
||||
}
|
||||
|
||||
private void textBoxInteger_TextChanged(object sender, EventArgs e)
|
||||
{
|
||||
_elementChanged?.Invoke(this, e);
|
||||
}
|
||||
|
||||
private void checkBoxNullable_CheckedChanged(object sender, EventArgs e)
|
||||
{
|
||||
textBoxInteger.Enabled = !checkBoxNullable.Checked;
|
||||
textBoxInteger.Text = null;
|
||||
_elementChanged?.Invoke(this, e);
|
||||
}
|
||||
}
|
||||
}
|
120
Components/Visual/UserControlIntegerInput.resx
Normal file
120
Components/Visual/UserControlIntegerInput.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>
|
58
Components/Visual/UserControlStringsListBox.Designer.cs
generated
Normal file
58
Components/Visual/UserControlStringsListBox.Designer.cs
generated
Normal file
@ -0,0 +1,58 @@
|
||||
namespace Components
|
||||
{
|
||||
partial class UserControlStringsListBox
|
||||
{
|
||||
/// <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()
|
||||
{
|
||||
listBoxStrings = new ListBox();
|
||||
SuspendLayout();
|
||||
//
|
||||
// listBoxStrings
|
||||
//
|
||||
listBoxStrings.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
|
||||
listBoxStrings.FormattingEnabled = true;
|
||||
listBoxStrings.ItemHeight = 15;
|
||||
listBoxStrings.Location = new Point(3, 3);
|
||||
listBoxStrings.Name = "listBoxStrings";
|
||||
listBoxStrings.Size = new Size(144, 139);
|
||||
listBoxStrings.TabIndex = 0;
|
||||
listBoxStrings.SelectedValueChanged += listBoxStrings_SelectedValueChanged;
|
||||
//
|
||||
// UserControlStringsListBox
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
Controls.Add(listBoxStrings);
|
||||
Name = "UserControlStringsListBox";
|
||||
ResumeLayout(false);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private ListBox listBoxStrings;
|
||||
}
|
||||
}
|
70
Components/Visual/UserControlStringsListBox.cs
Normal file
70
Components/Visual/UserControlStringsListBox.cs
Normal file
@ -0,0 +1,70 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace Components
|
||||
{
|
||||
public partial class UserControlStringsListBox : UserControl
|
||||
{
|
||||
private event EventHandler? _listChanged;
|
||||
private event Action? _errorOccured;
|
||||
public string Error { get; private set; }
|
||||
public string ListElement
|
||||
{
|
||||
get
|
||||
{
|
||||
return listBoxStrings.SelectedItem?.ToString();
|
||||
}
|
||||
set
|
||||
{
|
||||
if (listBoxStrings.Items.Contains(value))
|
||||
{
|
||||
listBoxStrings.SelectedItem = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
public event EventHandler ListChanged
|
||||
{
|
||||
add { _listChanged += value; }
|
||||
remove { _listChanged -= value; }
|
||||
}
|
||||
public event Action AnErrorOccurred
|
||||
{
|
||||
add { _errorOccured += value; }
|
||||
remove { _errorOccured -= value; }
|
||||
}
|
||||
public UserControlStringsListBox()
|
||||
{
|
||||
InitializeComponent();
|
||||
Error = string.Empty;
|
||||
}
|
||||
|
||||
public void AddList(List<string> l)
|
||||
{
|
||||
try
|
||||
{
|
||||
listBoxStrings.Items.AddRange(l.ToArray());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Error = ex.Message;
|
||||
_errorOccured?.Invoke();
|
||||
}
|
||||
}
|
||||
public void ClearList()
|
||||
{
|
||||
listBoxStrings.Items.Clear();
|
||||
}
|
||||
|
||||
private void listBoxStrings_SelectedValueChanged(object sender, EventArgs e)
|
||||
{
|
||||
_listChanged?.Invoke(sender, e);
|
||||
}
|
||||
}
|
||||
}
|
120
Components/Visual/UserControlStringsListBox.resx
Normal file
120
Components/Visual/UserControlStringsListBox.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>
|
62
Components/Visual/UserControlTable.Designer.cs
generated
Normal file
62
Components/Visual/UserControlTable.Designer.cs
generated
Normal file
@ -0,0 +1,62 @@
|
||||
namespace Components
|
||||
{
|
||||
partial class UserControlTable
|
||||
{
|
||||
/// <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()
|
||||
{
|
||||
dataGridViewTable = new DataGridView();
|
||||
((System.ComponentModel.ISupportInitialize)dataGridViewTable).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
// dataGridViewTable
|
||||
//
|
||||
dataGridViewTable.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
|
||||
dataGridViewTable.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||
dataGridViewTable.Location = new Point(3, 3);
|
||||
dataGridViewTable.Name = "dataGridViewTable";
|
||||
dataGridViewTable.RowHeadersVisible = false;
|
||||
dataGridViewTable.RowTemplate.Height = 25;
|
||||
dataGridViewTable.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
|
||||
dataGridViewTable.Size = new Size(325, 150);
|
||||
dataGridViewTable.TabIndex = 0;
|
||||
//
|
||||
// UserControlTable
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
Controls.Add(dataGridViewTable);
|
||||
Name = "UserControlTable";
|
||||
Size = new Size(331, 157);
|
||||
((System.ComponentModel.ISupportInitialize)dataGridViewTable).EndInit();
|
||||
ResumeLayout(false);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private DataGridView dataGridViewTable;
|
||||
}
|
||||
}
|
97
Components/Visual/UserControlTable.cs
Normal file
97
Components/Visual/UserControlTable.cs
Normal file
@ -0,0 +1,97 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using Components.Visual;
|
||||
|
||||
namespace Components
|
||||
{
|
||||
public partial class UserControlTable : UserControl
|
||||
{
|
||||
public int index
|
||||
{
|
||||
get => dataGridViewTable.SelectedRows.Count > 0 ? dataGridViewTable.SelectedRows[0].Index : -1;
|
||||
set
|
||||
{
|
||||
if (value >= 0 && value < dataGridViewTable.Rows.Count)
|
||||
{
|
||||
dataGridViewTable.ClearSelection();
|
||||
dataGridViewTable.Rows[value].Selected = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
public UserControlTable()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public void ConfigureColumns(List<ColumnInfo> columnInfo)
|
||||
{
|
||||
dataGridViewTable.Columns.Clear();
|
||||
for (int i = 0; i < columnInfo.Count; i++)
|
||||
{
|
||||
DataGridViewTextBoxColumn column = new DataGridViewTextBoxColumn
|
||||
{
|
||||
Name = columnInfo[i].Name,
|
||||
HeaderText = columnInfo[i].HeaderText,
|
||||
Width = columnInfo[i].Width,
|
||||
Visible = columnInfo[i].Visible,
|
||||
DataPropertyName = columnInfo[i].DataPropertyName,
|
||||
};
|
||||
dataGridViewTable.Columns.Add(column);
|
||||
}
|
||||
}
|
||||
|
||||
public void ClearRows()
|
||||
{
|
||||
dataGridViewTable.Rows.Clear();
|
||||
}
|
||||
|
||||
public void AddList<T>(List<T> values)
|
||||
{
|
||||
ClearRows();
|
||||
var props = typeof(T).GetProperties();
|
||||
|
||||
foreach (T value in values)
|
||||
{
|
||||
int newRowInd = dataGridViewTable.Rows.Add();
|
||||
foreach (DataGridViewColumn col in dataGridViewTable.Columns)
|
||||
{
|
||||
var prop = props.FirstOrDefault(x => x.Name == col.DataPropertyName)
|
||||
?? throw new InvalidOperationException($"No property {col.DataPropertyName} found in type {typeof(T).Name}");
|
||||
var val = prop.GetValue(value);
|
||||
dataGridViewTable.Rows[newRowInd].Cells[col.Index].Value = val;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public T GetObjectFromRow<T>()
|
||||
where T : new()
|
||||
{
|
||||
if (dataGridViewTable.SelectedRows.Count == 0)
|
||||
{
|
||||
throw new InvalidOperationException("At least one row must be selected");
|
||||
}
|
||||
|
||||
T returnObject = new();
|
||||
|
||||
var selectedRow = dataGridViewTable.SelectedRows[0];
|
||||
var props = typeof(T).GetProperties();
|
||||
var cells = dataGridViewTable.Rows[selectedRow.Index].Cells;
|
||||
|
||||
for (int i = 0; i < dataGridViewTable.ColumnCount; i++)
|
||||
{
|
||||
var curCell = cells[i];
|
||||
var prop = props.FirstOrDefault(x => x.Name == dataGridViewTable.Columns[i].DataPropertyName);
|
||||
prop?.SetValue(returnObject, curCell.Value);
|
||||
}
|
||||
return returnObject;
|
||||
}
|
||||
}
|
||||
}
|
120
Components/Visual/UserControlTable.resx
Normal file
120
Components/Visual/UserControlTable.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>
|
25
ComponentsProgramming.sln
Normal file
25
ComponentsProgramming.sln
Normal file
@ -0,0 +1,25 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.9.34728.123
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Components", "Components\Components.csproj", "{260D3E8C-3599-49F1-BF42-64A92DD0FB62}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{260D3E8C-3599-49F1-BF42-64A92DD0FB62}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{260D3E8C-3599-49F1-BF42-64A92DD0FB62}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{260D3E8C-3599-49F1-BF42-64A92DD0FB62}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{260D3E8C-3599-49F1-BF42-64A92DD0FB62}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {1208CC7E-AF27-4982-8E30-0DC89F09BBA6}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
Loading…
Reference in New Issue
Block a user