PIbd-31_Malafeev.L.S._COP_25/Cop_25/Forms/FormMain.cs

73 lines
2.5 KiB
C#

using Controls;
using Controls.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 Forms
{
public partial class FormMain : Form
{
public FormMain()
{
InitializeComponent();
customComboBox.ComboBoxItems.Add("aboba1");
customComboBox.ComboBoxItems.Add("aboba2");
customTextBoxNumber.NumPattern = @"^\+7\d{10}$";
customListBox.SetTemplateString("Имя: {FirstName}, Фамилия: {LastName}, Возраст: {Age}", "{", "}");
Person person1 = new Person { FirstName = "{Лена}", LastName = "{Пряникова}", Age = "{18}" };
Person person2 = new Person { FirstName = "{Ева}", LastName = "{Конфетковна}", Age = "{20}" };
customListBox.FillProperty(person1, 0, "FirstName");
customListBox.FillProperty(person1, 0, "LastName");
customListBox.FillProperty(person1, 0, "Age");
customListBox.FillProperty(person2, 1, "FirstName");
customListBox.FillProperty(person2, 1, "LastName");
customListBox.FillProperty(person2, 1, "Age");
}
private void buttonValidate_Click(object sender, EventArgs e)
{
try
{
string phoneNumber = customTextBoxNumber.TextBoxNumber;
MessageBox.Show($"Введенный номер: {phoneNumber}");
}
catch (CustomNumberException ex)
{
MessageBox.Show($"Ошибка: {ex.Message}");
}
}
private void buttonGetObject_Click(object sender, EventArgs e)
{
try
{
Person selectedPerson = customListBox.GetObjectFromStr<Person>();
MessageBox.Show($"Имя: {selectedPerson.FirstName}, Фамилия: {selectedPerson.LastName}, Возраст: {selectedPerson.Age}");
}
catch (Exception ex)
{
MessageBox.Show($"Ошибка: {ex.Message}");
}
}
private void buttonClear_Click(object sender, EventArgs e) {
customComboBox.ComboBoxClear();
}
private void buttonAdd_Click(object sender, EventArgs e)
{
customComboBox.ComboBoxItems.Add("abobaSECRET");
}
}
}