From 1128ffdc1a29fd5984498c078d786ee08fea3111 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=98=D0=B2=D0=B0=D0=BD=20=D0=90=D0=BB=D0=B5=D0=BA=D1=81?= =?UTF-8?q?=D0=B5=D0=B5=D0=B2?= Date: Sat, 21 Sep 2024 17:41:05 +0400 Subject: [PATCH] =?UTF-8?q?=D1=81=D0=B4=D0=B0=D0=BD=D0=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- FormLibrary/CustomListBox.Designer.cs | 58 ++++++ FormLibrary/CustomListBox.cs | 48 +++++ FormLibrary/CustomListBox.resx | 120 ++++++++++++ FormLibrary/Exceptions/EmptyValueException.cs | 13 ++ .../Exceptions/InvalidValueTypeException.cs | 13 ++ FormLibrary/FormLibrary.csproj | 10 + FormLibrary/HelperClasses/ColumnConfig.cs | 16 ++ FormLibrary/HelperClasses/Student.cs | 15 ++ FormLibrary/IntegerInputControl.Designer.cs | 68 +++++++ FormLibrary/IntegerInputControl.cs | 82 ++++++++ FormLibrary/IntegerInputControl.resx | 120 ++++++++++++ FormLibrary/ValueTableControl.Designer.cs | 58 ++++++ FormLibrary/ValueTableControl.cs | 103 ++++++++++ FormLibrary/ValueTableControl.resx | 120 ++++++++++++ Forms/Forms.csproj | 15 ++ Forms/MainForm.Designer.cs | 180 ++++++++++++++++++ Forms/MainForm.cs | 130 +++++++++++++ Forms/MainForm.resx | 120 ++++++++++++ Forms/Program.cs | 17 ++ KopLab1.sln | 31 +++ 20 files changed, 1337 insertions(+) create mode 100644 FormLibrary/CustomListBox.Designer.cs create mode 100644 FormLibrary/CustomListBox.cs create mode 100644 FormLibrary/CustomListBox.resx create mode 100644 FormLibrary/Exceptions/EmptyValueException.cs create mode 100644 FormLibrary/Exceptions/InvalidValueTypeException.cs create mode 100644 FormLibrary/FormLibrary.csproj create mode 100644 FormLibrary/HelperClasses/ColumnConfig.cs create mode 100644 FormLibrary/HelperClasses/Student.cs create mode 100644 FormLibrary/IntegerInputControl.Designer.cs create mode 100644 FormLibrary/IntegerInputControl.cs create mode 100644 FormLibrary/IntegerInputControl.resx create mode 100644 FormLibrary/ValueTableControl.Designer.cs create mode 100644 FormLibrary/ValueTableControl.cs create mode 100644 FormLibrary/ValueTableControl.resx create mode 100644 Forms/Forms.csproj create mode 100644 Forms/MainForm.Designer.cs create mode 100644 Forms/MainForm.cs create mode 100644 Forms/MainForm.resx create mode 100644 Forms/Program.cs create mode 100644 KopLab1.sln diff --git a/FormLibrary/CustomListBox.Designer.cs b/FormLibrary/CustomListBox.Designer.cs new file mode 100644 index 0000000..fc24a8e --- /dev/null +++ b/FormLibrary/CustomListBox.Designer.cs @@ -0,0 +1,58 @@ +namespace FormLibrary +{ + partial class CustomListBox + { + /// + /// Обязательная переменная конструктора. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Освободить все используемые ресурсы. + /// + /// истинно, если управляемый ресурс должен быть удален; иначе ложно. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Код, автоматически созданный конструктором компонентов + + /// + /// Требуемый метод для поддержки конструктора — не изменяйте + /// содержимое этого метода с помощью редактора кода. + /// + private void InitializeComponent() + { + listBox1 = new ListBox(); + SuspendLayout(); + // + // listBox1 + // + listBox1.FormattingEnabled = true; + listBox1.ItemHeight = 15; + listBox1.Location = new Point(3, 3); + listBox1.Name = "listBox1"; + listBox1.Size = new Size(231, 169); + listBox1.TabIndex = 0; + listBox1.SelectedIndexChanged += ListBox1_SelectedIndexChanged; + // + // CustomListBox + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + Controls.Add(listBox1); + Name = "CustomListBox"; + Size = new Size(237, 179); + ResumeLayout(false); + } + + #endregion + + private ListBox listBox1; + } +} diff --git a/FormLibrary/CustomListBox.cs b/FormLibrary/CustomListBox.cs new file mode 100644 index 0000000..27fb348 --- /dev/null +++ b/FormLibrary/CustomListBox.cs @@ -0,0 +1,48 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using static System.Windows.Forms.VisualStyles.VisualStyleElement.Header; + +namespace FormLibrary +{ + public partial class CustomListBox : UserControl + { + + public event EventHandler? SelectedItemChanged; + public CustomListBox() + { + InitializeComponent(); + } + + public string SelectedItem + { + get => listBox1.SelectedItem?.ToString() ?? string.Empty; + set => listBox1.SelectedIndex = listBox1.Items.IndexOf(value); + } + + private void ListBox1_SelectedIndexChanged(object? sender, EventArgs e) + { + SelectedItemChanged?.Invoke(this, EventArgs.Empty); + } + public void PopulateListBox(List items) + { + listBox1.Items.Clear(); + + foreach (var item in items) + { + listBox1.Items.Add(item); + } + } + + public void ClearListBox() + { + listBox1.Items.Clear(); + } + } +} diff --git a/FormLibrary/CustomListBox.resx b/FormLibrary/CustomListBox.resx new file mode 100644 index 0000000..8b2ff64 --- /dev/null +++ b/FormLibrary/CustomListBox.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/FormLibrary/Exceptions/EmptyValueException.cs b/FormLibrary/Exceptions/EmptyValueException.cs new file mode 100644 index 0000000..9ac3854 --- /dev/null +++ b/FormLibrary/Exceptions/EmptyValueException.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FormLibrary.Exceptions +{ + public class EmptyValueException : Exception + { + public EmptyValueException() : base("Значение не заполнено.") { } + } +} diff --git a/FormLibrary/Exceptions/InvalidValueTypeException.cs b/FormLibrary/Exceptions/InvalidValueTypeException.cs new file mode 100644 index 0000000..09cc6df --- /dev/null +++ b/FormLibrary/Exceptions/InvalidValueTypeException.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FormLibrary.Exceptions +{ + public class InvalidValueTypeException : Exception + { + public InvalidValueTypeException() : base("Значение не соответствует требуемому типу.") { } + } +} diff --git a/FormLibrary/FormLibrary.csproj b/FormLibrary/FormLibrary.csproj new file mode 100644 index 0000000..3e210aa --- /dev/null +++ b/FormLibrary/FormLibrary.csproj @@ -0,0 +1,10 @@ + + + + net8.0-windows + enable + true + enable + + + diff --git a/FormLibrary/HelperClasses/ColumnConfig.cs b/FormLibrary/HelperClasses/ColumnConfig.cs new file mode 100644 index 0000000..bcf1056 --- /dev/null +++ b/FormLibrary/HelperClasses/ColumnConfig.cs @@ -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; } + } +} diff --git a/FormLibrary/HelperClasses/Student.cs b/FormLibrary/HelperClasses/Student.cs new file mode 100644 index 0000000..b83d979 --- /dev/null +++ b/FormLibrary/HelperClasses/Student.cs @@ -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; } + } +} diff --git a/FormLibrary/IntegerInputControl.Designer.cs b/FormLibrary/IntegerInputControl.Designer.cs new file mode 100644 index 0000000..91a5670 --- /dev/null +++ b/FormLibrary/IntegerInputControl.Designer.cs @@ -0,0 +1,68 @@ +namespace FormLibrary +{ + partial class IntegerInputControl + { + /// + /// Обязательная переменная конструктора. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Освободить все используемые ресурсы. + /// + /// истинно, если управляемый ресурс должен быть удален; иначе ложно. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Код, автоматически созданный конструктором компонентов + + /// + /// Требуемый метод для поддержки конструктора — не изменяйте + /// содержимое этого метода с помощью редактора кода. + /// + private void InitializeComponent() + { + checkBoxNull = new CheckBox(); + textBoxInput = new TextBox(); + SuspendLayout(); + // + // checkBoxNull + // + checkBoxNull.AutoSize = true; + checkBoxNull.Location = new Point(13, 17); + checkBoxNull.Name = "checkBoxNull"; + checkBoxNull.Size = new Size(15, 14); + checkBoxNull.TabIndex = 0; + checkBoxNull.UseVisualStyleBackColor = true; + // + // textBoxInput + // + textBoxInput.Location = new Point(34, 13); + textBoxInput.Name = "textBoxInput"; + textBoxInput.Size = new Size(100, 23); + textBoxInput.TabIndex = 1; + // + // IntegerInputControl + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + Controls.Add(textBoxInput); + Controls.Add(checkBoxNull); + Name = "IntegerInputControl"; + Size = new Size(146, 49); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private CheckBox checkBoxNull; + private TextBox textBoxInput; + } +} diff --git a/FormLibrary/IntegerInputControl.cs b/FormLibrary/IntegerInputControl.cs new file mode 100644 index 0000000..269c259 --- /dev/null +++ b/FormLibrary/IntegerInputControl.cs @@ -0,0 +1,82 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +using System; +using System.Windows.Forms; +using FormLibrary.Exceptions; + +namespace FormLibrary +{ + public partial class IntegerInputControl : UserControl + { + public event EventHandler? ValueChanged; + + public event EventHandler? CheckBoxChanged; + + public IntegerInputControl() + { + InitializeComponent(); + + checkBoxNull.CheckedChanged += CheckBoxNull_CheckedChanged; + textBoxInput.TextChanged += TextBoxInput_TextChanged; + } + + public int? Value + { + get + { + if (checkBoxNull.Checked) + { + return null; + } + else + { + if (string.IsNullOrWhiteSpace(textBoxInput.Text)) + { + throw new EmptyValueException(); + } + + if (int.TryParse(textBoxInput.Text, out int result)) + { + return result; + } + else + { + throw new InvalidValueTypeException(); + } + } + } + set + { + if(value is not null) + { + textBoxInput.Text = value.ToString(); + } + checkBoxNull.Checked = value is null; + } + } + + private void CheckBoxNull_CheckedChanged(object sender, EventArgs e) + { + textBoxInput.Enabled = !checkBoxNull.Checked; + if (checkBoxNull.Checked) + { + textBoxInput.Text = string.Empty; + } + CheckBoxChanged?.Invoke(this, EventArgs.Empty); + } + + private void TextBoxInput_TextChanged(object sender, EventArgs e) + { + ValueChanged?.Invoke(this, EventArgs.Empty); + } + } +} + diff --git a/FormLibrary/IntegerInputControl.resx b/FormLibrary/IntegerInputControl.resx new file mode 100644 index 0000000..8b2ff64 --- /dev/null +++ b/FormLibrary/IntegerInputControl.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/FormLibrary/ValueTableControl.Designer.cs b/FormLibrary/ValueTableControl.Designer.cs new file mode 100644 index 0000000..7ae2ab2 --- /dev/null +++ b/FormLibrary/ValueTableControl.Designer.cs @@ -0,0 +1,58 @@ +namespace FormLibrary +{ + partial class ValueTableControl + { + /// + /// Обязательная переменная конструктора. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Освободить все используемые ресурсы. + /// + /// истинно, если управляемый ресурс должен быть удален; иначе ложно. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Код, автоматически созданный конструктором компонентов + + /// + /// Требуемый метод для поддержки конструктора — не изменяйте + /// содержимое этого метода с помощью редактора кода. + /// + 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; + } +} diff --git a/FormLibrary/ValueTableControl.cs b/FormLibrary/ValueTableControl.cs new file mode 100644 index 0000000..d781aad --- /dev/null +++ b/FormLibrary/ValueTableControl.cs @@ -0,0 +1,103 @@ +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[0].Index; + set + { + if (value >= 0 && value < dataGridView1.Rows.Count) + { + dataGridView1.ClearSelection(); + dataGridView1.Rows[value].Selected = true; + } + } + } + + public T GetSelectedObject() 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) + { + var value = selectedRow.Cells[column.Index].Value; + prop.SetValue(obj, Convert.ChangeType(value, prop.PropertyType)); + } + } + + return obj; + } + + public void FillData(List objects) + { + dataGridView1.Rows.Clear(); + + if (objects == null || !objects.Any()) + { + return; + } + + var properties = typeof(T).GetProperties(); + + foreach (var obj in objects) + { + var values = properties.Select(p => p.GetValue(obj, null)).ToArray(); + dataGridView1.Rows.Add(values); + } + } + } +} diff --git a/FormLibrary/ValueTableControl.resx b/FormLibrary/ValueTableControl.resx new file mode 100644 index 0000000..8b2ff64 --- /dev/null +++ b/FormLibrary/ValueTableControl.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Forms/Forms.csproj b/Forms/Forms.csproj new file mode 100644 index 0000000..07a9ca3 --- /dev/null +++ b/Forms/Forms.csproj @@ -0,0 +1,15 @@ + + + + WinExe + net8.0-windows + enable + true + enable + + + + + + + \ No newline at end of file diff --git a/Forms/MainForm.Designer.cs b/Forms/MainForm.Designer.cs new file mode 100644 index 0000000..e572193 --- /dev/null +++ b/Forms/MainForm.Designer.cs @@ -0,0 +1,180 @@ +namespace Forms +{ + partial class MainForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + customListBox1 = new FormLibrary.CustomListBox(); + button1 = new Button(); + button2 = new Button(); + integerInputControl1 = new FormLibrary.IntegerInputControl(); + button3 = new Button(); + button4 = new Button(); + textBox1 = new TextBox(); + valueTableControl1 = new FormLibrary.ValueTableControl(); + button5 = new Button(); + button6 = new Button(); + button7 = new Button(); + SuspendLayout(); + // + // customListBox1 + // + customListBox1.Location = new Point(12, 12); + customListBox1.Name = "customListBox1"; + customListBox1.SelectedItem = ""; + customListBox1.Size = new Size(237, 176); + customListBox1.TabIndex = 0; + // + // button1 + // + button1.Location = new Point(12, 194); + button1.Name = "button1"; + button1.Size = new Size(237, 34); + button1.TabIndex = 1; + button1.Text = "Заполнить список"; + button1.UseVisualStyleBackColor = true; + button1.Click += ButtonLoad_Click; + // + // button2 + // + button2.Location = new Point(12, 234); + button2.Name = "button2"; + button2.Size = new Size(237, 34); + button2.TabIndex = 2; + button2.Text = "Очистить список"; + button2.UseVisualStyleBackColor = true; + button2.Click += ButtonClear_Click; + // + // integerInputControl1 + // + integerInputControl1.Location = new Point(329, 12); + integerInputControl1.Name = "integerInputControl1"; + integerInputControl1.Size = new Size(146, 56); + integerInputControl1.TabIndex = 3; + // + // button3 + // + button3.Location = new Point(361, 74); + button3.Name = "button3"; + button3.Size = new Size(103, 23); + button3.TabIndex = 4; + button3.Text = "Set"; + button3.UseVisualStyleBackColor = true; + button3.Click += buttonInput_Click; + // + // button4 + // + button4.Location = new Point(361, 103); + button4.Name = "button4"; + button4.Size = new Size(103, 23); + button4.TabIndex = 5; + button4.Text = "Get"; + button4.UseVisualStyleBackColor = true; + button4.Click += buttonOutput_Click; + // + // textBox1 + // + textBox1.Location = new Point(329, 132); + textBox1.Name = "textBox1"; + 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(949, 450); + Controls.Add(button7); + Controls.Add(button6); + Controls.Add(button5); + Controls.Add(valueTableControl1); + Controls.Add(textBox1); + Controls.Add(button4); + Controls.Add(button3); + Controls.Add(integerInputControl1); + Controls.Add(button2); + Controls.Add(button1); + Controls.Add(customListBox1); + Name = "MainForm"; + Text = "MainForm"; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private FormLibrary.CustomListBox customListBox1; + private Button button1; + private Button button2; + private FormLibrary.IntegerInputControl integerInputControl1; + private Button button3; + private Button button4; + private TextBox textBox1; + private FormLibrary.ValueTableControl valueTableControl1; + private Button button5; + private Button button6; + private Button button7; + } +} \ No newline at end of file diff --git a/Forms/MainForm.cs b/Forms/MainForm.cs new file mode 100644 index 0000000..e17ccb8 --- /dev/null +++ b/Forms/MainForm.cs @@ -0,0 +1,130 @@ +using FormLibrary; +using FormLibrary.Exceptions; +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; +using System.Windows.Forms.VisualStyles; +using static System.Windows.Forms.VisualStyles.VisualStyleElement.Header; + +namespace Forms +{ + public partial class MainForm : Form + { + private int? savedValue; + public MainForm() + { + InitializeComponent(); + customListBox1.SelectedItemChanged += CustomListBox1_SelectedItemChanged; + integerInputControl1.ValueChanged += IntegerInputControl1_ValueChanged; + integerInputControl1.CheckBoxChanged += IntegerInputControl_CheckBoxChanged; + } + + private void CustomListBox1_SelectedItemChanged(object? sender, EventArgs e) + { + if (sender is CustomListBox customListBox) + { + string selectedItem = customListBox.SelectedItem; + MessageBox.Show($"Выбранный элемент: {selectedItem}", "Выбор элемента", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + } + private void ButtonLoad_Click(object? sender, EventArgs e) + { + List items = new List(); + for (int i = 0; i <= 5; i++) + { + items.Add("Item " + i.ToString()); + } + + customListBox1.PopulateListBox(items); + } + + private void ButtonClear_Click(object? sender, EventArgs e) + { + customListBox1.ClearListBox(); + } + private void buttonInput_Click(object sender, EventArgs e) + { + try + { + savedValue = integerInputControl1.Value; + MessageBox.Show("Значение успешно сохранено.", "Информация", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + catch (EmptyValueException ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + catch (InvalidValueTypeException ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void buttonOutput_Click(object sender, EventArgs e) + { + if (savedValue.HasValue) + { + MessageBox.Show($"Сохраненное значение: {savedValue}", "Информация", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + else + { + MessageBox.Show("Сохраненное значение: null", "Информация", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + } + private void IntegerInputControl1_ValueChanged(object? sender, EventArgs e) + { + textBox1.Text = "Textbox changed"; + } + + private void IntegerInputControl_CheckBoxChanged(object? sender, EventArgs e) + { + 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 + { + new Student { Group = "Пибд-31", FullName = "Иванов Иван Иванович", Course = 3 }, + new Student { Group = "Пибд-31", FullName = "Петров Петр Петрович", Course = 2 }, + new Student { Group = "Пибд-31", 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(); + MessageBox.Show($"Группа: {selectedStudent.Group}, ФИО: {selectedStudent.FullName}, Курс: {selectedStudent.Course}", + "Выбранный студент", + MessageBoxButtons.OK, + MessageBoxIcon.Information); + } + catch (InvalidOperationException ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } +} diff --git a/Forms/MainForm.resx b/Forms/MainForm.resx new file mode 100644 index 0000000..8b2ff64 --- /dev/null +++ b/Forms/MainForm.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Forms/Program.cs b/Forms/Program.cs new file mode 100644 index 0000000..ff6d1a9 --- /dev/null +++ b/Forms/Program.cs @@ -0,0 +1,17 @@ +namespace Forms +{ + internal static class Program + { + /// + /// The main entry point for the application. + /// + [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 MainForm()); + } + } +} \ No newline at end of file diff --git a/KopLab1.sln b/KopLab1.sln new file mode 100644 index 0000000..5506f5f --- /dev/null +++ b/KopLab1.sln @@ -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("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FormLibrary", "FormLibrary\FormLibrary.csproj", "{E840E4D9-B195-449A-AB24-ECAAE2655D58}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Forms", "Forms\Forms.csproj", "{83F3C50D-D872-48B6-8932-1D5B7E0A40F0}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {E840E4D9-B195-449A-AB24-ECAAE2655D58}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E840E4D9-B195-449A-AB24-ECAAE2655D58}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E840E4D9-B195-449A-AB24-ECAAE2655D58}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E840E4D9-B195-449A-AB24-ECAAE2655D58}.Release|Any CPU.Build.0 = Release|Any CPU + {83F3C50D-D872-48B6-8932-1D5B7E0A40F0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {83F3C50D-D872-48B6-8932-1D5B7E0A40F0}.Debug|Any CPU.Build.0 = Debug|Any CPU + {83F3C50D-D872-48B6-8932-1D5B7E0A40F0}.Release|Any CPU.ActiveCfg = Release|Any CPU + {83F3C50D-D872-48B6-8932-1D5B7E0A40F0}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {C6DEED66-161D-4CE7-B327-9DB0A6D32439} + EndGlobalSection +EndGlobal