Ну надеюсь усё, на паре увидем...
This commit is contained in:
parent
c0b76475ef
commit
1c98fe8e19
@ -54,7 +54,6 @@ namespace FormLibrary
|
||||
listBox.Items.Add(item);
|
||||
}
|
||||
}
|
||||
// Метод для заполнения списка элементами
|
||||
public void PopulateListBox(List<string> items)
|
||||
{
|
||||
listBox1.Items.Clear();
|
||||
@ -64,8 +63,6 @@ namespace FormLibrary
|
||||
listBox1.Items.Add(item);
|
||||
}
|
||||
}
|
||||
|
||||
// Метод для очистки списка
|
||||
public void ClearListBox()
|
||||
{
|
||||
listBox1.Items.Clear();
|
||||
|
16
KopLab1/FormLibrary/HelperClasses/ColumnConfig.cs
Normal file
16
KopLab1/FormLibrary/HelperClasses/ColumnConfig.cs
Normal file
@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FormLibrary.HelperClasses
|
||||
{
|
||||
public class ColumnConfig
|
||||
{
|
||||
public string HeaderText { get; set; }
|
||||
public int Width { get; set; }
|
||||
public bool IsVisible { get; set; }
|
||||
public string PropertyName { get; set; }
|
||||
}
|
||||
}
|
15
KopLab1/FormLibrary/HelperClasses/Student.cs
Normal file
15
KopLab1/FormLibrary/HelperClasses/Student.cs
Normal file
@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FormLibrary.HelperClasses
|
||||
{
|
||||
public class Student
|
||||
{
|
||||
public string Group { get; set; }
|
||||
public string FullName { get; set; }
|
||||
public int Course { get; set; }
|
||||
}
|
||||
}
|
@ -30,7 +30,6 @@ namespace FormLibrary
|
||||
textBoxInput.TextChanged += TextBoxInput_TextChanged;
|
||||
}
|
||||
|
||||
// Публичное свойство для установки и получения введенного значения
|
||||
public int? Value
|
||||
{
|
||||
get
|
||||
@ -73,7 +72,6 @@ namespace FormLibrary
|
||||
}
|
||||
}
|
||||
|
||||
// Метод обработки изменения состояния CheckBox
|
||||
private void CheckBoxNull_CheckedChanged(object sender, EventArgs e)
|
||||
{
|
||||
textBoxInput.Enabled = !checkBoxNull.Checked;
|
||||
@ -81,15 +79,11 @@ namespace FormLibrary
|
||||
{
|
||||
textBoxInput.Text = string.Empty;
|
||||
}
|
||||
|
||||
// Вызываем событие при изменении состояния CheckBox
|
||||
CheckBoxChanged?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
|
||||
// Метод обработки изменения текста в текстовом поле
|
||||
private void TextBoxInput_TextChanged(object sender, EventArgs e)
|
||||
{
|
||||
// Вызываем событие при изменении текста
|
||||
ValueChanged?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
|
58
KopLab1/FormLibrary/ValueTableControl.Designer.cs
generated
Normal file
58
KopLab1/FormLibrary/ValueTableControl.Designer.cs
generated
Normal file
@ -0,0 +1,58 @@
|
||||
namespace FormLibrary
|
||||
{
|
||||
partial class ValueTableControl
|
||||
{
|
||||
/// <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()
|
||||
{
|
||||
dataGridView1 = new DataGridView();
|
||||
((System.ComponentModel.ISupportInitialize)dataGridView1).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
// dataGridView1
|
||||
//
|
||||
dataGridView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||
dataGridView1.Location = new Point(3, 3);
|
||||
dataGridView1.Name = "dataGridView1";
|
||||
dataGridView1.Size = new Size(445, 363);
|
||||
dataGridView1.TabIndex = 0;
|
||||
//
|
||||
// ValueTableControl
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
Controls.Add(dataGridView1);
|
||||
Name = "ValueTableControl";
|
||||
Size = new Size(451, 369);
|
||||
((System.ComponentModel.ISupportInitialize)dataGridView1).EndInit();
|
||||
ResumeLayout(false);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private DataGridView dataGridView1;
|
||||
}
|
||||
}
|
98
KopLab1/FormLibrary/ValueTableControl.cs
Normal file
98
KopLab1/FormLibrary/ValueTableControl.cs
Normal file
@ -0,0 +1,98 @@
|
||||
using FormLibrary.HelperClasses;
|
||||
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 FormLibrary
|
||||
{
|
||||
public partial class ValueTableControl : UserControl
|
||||
{
|
||||
public ValueTableControl()
|
||||
{
|
||||
InitializeComponent();
|
||||
ConfigureDataGridView();
|
||||
}
|
||||
|
||||
private void ConfigureDataGridView()
|
||||
{
|
||||
dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
|
||||
dataGridView1.MultiSelect = false;
|
||||
dataGridView1.RowHeadersVisible = false;
|
||||
dataGridView1.AllowUserToAddRows = false;
|
||||
|
||||
dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
|
||||
}
|
||||
|
||||
|
||||
public void ConfigureColumns(List<(string HeaderText, string DataPropertyName, float FillWeight)> columns)
|
||||
{
|
||||
dataGridView1.Columns.Clear();
|
||||
|
||||
foreach (var column in columns)
|
||||
{
|
||||
dataGridView1.Columns.Add(new DataGridViewTextBoxColumn
|
||||
{
|
||||
HeaderText = column.HeaderText,
|
||||
DataPropertyName = column.DataPropertyName,
|
||||
FillWeight = column.FillWeight
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public void ClearRows()
|
||||
{
|
||||
dataGridView1.Rows.Clear();
|
||||
}
|
||||
|
||||
public int SelectedRowIndex
|
||||
{
|
||||
get => dataGridView1.SelectedRows.Count > 0 ? dataGridView1.SelectedRows[0].Index : -1;
|
||||
set
|
||||
{
|
||||
if (value >= 0 && value < dataGridView1.Rows.Count)
|
||||
{
|
||||
dataGridView1.ClearSelection();
|
||||
dataGridView1.Rows[value].Selected = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public T GetSelectedObject<T>() where T : new()
|
||||
{
|
||||
if (dataGridView1.SelectedRows.Count == 0)
|
||||
throw new InvalidOperationException("Нет выбранной строки.");
|
||||
|
||||
var selectedRow = dataGridView1.SelectedRows[0];
|
||||
var obj = new T();
|
||||
|
||||
foreach (DataGridViewColumn column in dataGridView1.Columns)
|
||||
{
|
||||
var prop = typeof(T).GetProperty(column.DataPropertyName);
|
||||
if (prop != null && prop.CanWrite)
|
||||
{
|
||||
var value = selectedRow.Cells[column.Index].Value;
|
||||
prop.SetValue(obj, Convert.ChangeType(value, prop.PropertyType));
|
||||
}
|
||||
}
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
public void FillData(List<Student> students)
|
||||
{
|
||||
dataGridView1.DataSource = null;
|
||||
dataGridView1.Rows.Clear();
|
||||
|
||||
foreach (var student in students)
|
||||
{
|
||||
dataGridView1.Rows.Add(student.Group, student.FullName, student.Course);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
120
KopLab1/FormLibrary/ValueTableControl.resx
Normal file
120
KopLab1/FormLibrary/ValueTableControl.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>
|
52
KopLab1/Forms/MainForm.Designer.cs
generated
52
KopLab1/Forms/MainForm.Designer.cs
generated
@ -35,6 +35,10 @@
|
||||
button3 = new Button();
|
||||
button4 = new Button();
|
||||
textBox1 = new TextBox();
|
||||
valueTableControl1 = new FormLibrary.ValueTableControl();
|
||||
button5 = new Button();
|
||||
button6 = new Button();
|
||||
button7 = new Button();
|
||||
SuspendLayout();
|
||||
//
|
||||
// customListBox1
|
||||
@ -99,11 +103,53 @@
|
||||
textBox1.Size = new Size(135, 23);
|
||||
textBox1.TabIndex = 6;
|
||||
//
|
||||
// valueTableControl1
|
||||
//
|
||||
valueTableControl1.Location = new Point(487, 12);
|
||||
valueTableControl1.Name = "valueTableControl1";
|
||||
valueTableControl1.SelectedRowIndex = -1;
|
||||
valueTableControl1.Size = new Size(450, 369);
|
||||
valueTableControl1.TabIndex = 7;
|
||||
//
|
||||
// button5
|
||||
//
|
||||
button5.Location = new Point(487, 387);
|
||||
button5.Name = "button5";
|
||||
button5.Size = new Size(159, 51);
|
||||
button5.TabIndex = 8;
|
||||
button5.Text = "Заполнить таблицу";
|
||||
button5.UseVisualStyleBackColor = true;
|
||||
button5.Click += ButtonFillTable_Click;
|
||||
//
|
||||
// button6
|
||||
//
|
||||
button6.Location = new Point(652, 387);
|
||||
button6.Name = "button6";
|
||||
button6.Size = new Size(134, 51);
|
||||
button6.TabIndex = 9;
|
||||
button6.Text = "Очистить таблицу";
|
||||
button6.UseVisualStyleBackColor = true;
|
||||
button6.Click += ButtonClearTable_Click;
|
||||
//
|
||||
// button7
|
||||
//
|
||||
button7.Location = new Point(792, 387);
|
||||
button7.Name = "button7";
|
||||
button7.Size = new Size(148, 51);
|
||||
button7.TabIndex = 10;
|
||||
button7.Text = "Get";
|
||||
button7.UseVisualStyleBackColor = true;
|
||||
button7.Click += ButtonShowData_Click;
|
||||
//
|
||||
// MainForm
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(800, 450);
|
||||
ClientSize = new Size(949, 450);
|
||||
Controls.Add(button7);
|
||||
Controls.Add(button6);
|
||||
Controls.Add(button5);
|
||||
Controls.Add(valueTableControl1);
|
||||
Controls.Add(textBox1);
|
||||
Controls.Add(button4);
|
||||
Controls.Add(button3);
|
||||
@ -126,5 +172,9 @@
|
||||
private Button button3;
|
||||
private Button button4;
|
||||
private TextBox textBox1;
|
||||
private FormLibrary.ValueTableControl valueTableControl1;
|
||||
private Button button5;
|
||||
private Button button6;
|
||||
private Button button7;
|
||||
}
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
using FormLibrary;
|
||||
using FormLibrary.Exceptions;
|
||||
using FormLibrary.HelperClasses;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
@ -33,7 +34,6 @@ namespace Forms
|
||||
MessageBox.Show($"Выбранный элемент: {selectedItem}", "Выбор элемента", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
}
|
||||
}
|
||||
// Обработчик для кнопки загрузки элементов
|
||||
private void ButtonLoad_Click(object? sender, EventArgs e)
|
||||
{
|
||||
List<string> items = new List<string>();
|
||||
@ -45,7 +45,6 @@ namespace Forms
|
||||
customListBox1.PopulateListBox(items);
|
||||
}
|
||||
|
||||
// Обработчик для кнопки очистки списка
|
||||
private void ButtonClear_Click(object? sender, EventArgs e)
|
||||
{
|
||||
customListBox1.ClearListBox();
|
||||
@ -54,7 +53,6 @@ namespace Forms
|
||||
{
|
||||
try
|
||||
{
|
||||
// Проверка и сохранение значения в контроллере
|
||||
savedValue = integerInputControl1.Value;
|
||||
MessageBox.Show("Значение успешно сохранено.", "Информация", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
}
|
||||
@ -81,14 +79,52 @@ namespace Forms
|
||||
}
|
||||
private void IntegerInputControl1_ValueChanged(object? sender, EventArgs e)
|
||||
{
|
||||
// Обработка изменения значения в IntegerInputControl
|
||||
textBox1.Text = "Textbox changed";
|
||||
}
|
||||
|
||||
private void IntegerInputControl_CheckBoxChanged(object? sender, EventArgs e)
|
||||
{
|
||||
// Обработка изменения состояния CheckBox в IntegerInputControl
|
||||
textBox1.Text = "Checkbox changed";
|
||||
}
|
||||
private void ButtonFillTable_Click(object sender, EventArgs e)
|
||||
{
|
||||
var columns = new List<(string HeaderText, string DataPropertyName, float FillWeight)>
|
||||
{
|
||||
("Группа", "Group", 30),
|
||||
("ФИО", "FullName", 50),
|
||||
("Курс", "Course", 20)
|
||||
};
|
||||
valueTableControl1.ConfigureColumns(columns);
|
||||
|
||||
var students = new List<Student>
|
||||
{
|
||||
new Student { Group = "Пибд-33", FullName = "Иванов Иван Иванович", Course = 3 },
|
||||
new Student { Group = "Пибд-33", FullName = "Петров Петр Петрович", Course = 2 },
|
||||
new Student { Group = "Пибд-33", FullName = "Сидоров Сидор Сидорович", Course = 1 }
|
||||
};
|
||||
|
||||
valueTableControl1.FillData(students);
|
||||
}
|
||||
|
||||
private void ButtonClearTable_Click(object sender, EventArgs e)
|
||||
{
|
||||
valueTableControl1.ClearRows();
|
||||
}
|
||||
|
||||
private void ButtonShowData_Click(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
var selectedStudent = valueTableControl1.GetSelectedObject<Student>();
|
||||
MessageBox.Show($"Группа: {selectedStudent.Group}, ФИО: {selectedStudent.FullName}, Курс: {selectedStudent.Course}",
|
||||
"Выбранный студент",
|
||||
MessageBoxButtons.OK,
|
||||
MessageBoxIcon.Information);
|
||||
}
|
||||
catch (InvalidOperationException ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user