PIbd-31_Alekseev.I.S._COP_3/Forms/MainForm.cs

131 lines
4.9 KiB
C#
Raw Normal View History

2024-09-21 17:41:05 +04:00
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<string> items = new List<string>();
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<Student>
{
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<Student>();
MessageBox.Show($"Группа: {selectedStudent.Group}, ФИО: {selectedStudent.FullName}, Курс: {selectedStudent.Course}",
"Выбранный студент",
MessageBoxButtons.OK,
MessageBoxIcon.Information);
}
catch (InvalidOperationException ex)
{
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}