private void Spisok_LB_SelectedValueChanged(object sender, EventArgs e) { if (Spisok_LB.SelectedItem != null) { Schoolboy SchoolboyDB = Spisok_LB.SelectedItem as Schoolboy; if (SchoolboyDB != null) { Averagerating_TB.Text = SchoolboyDB.Averagerating.ToString(); Age_TB.Text = SchoolboyDB.Age.ToString(); Name_TB.Text = SchoolboyDB.Name; Surname_TB.Text = SchoolboyDB.Surname; Middlename_TB.Text = SchoolboyDB.Middlename; Class_TB.Text = SchoolboyDB.Class.ToString(); Ranked_TB.Text = SchoolboyDB.Ranked.ToString(); } StateButton(true); } else { Averagerating_TB.Clear(); Age_TB.Clear(); Name_TB.Clear(); Surname_TB.Clear(); Middlename_TB.Clear(); Class_TB.Clear(); Ranked_TB.Clear(); StateButton(false); } }
private void Modification_FormClosing(object sender, FormClosingEventArgs e) { if (DialogResult == DialogResult.OK) { try { if (Averagerating_TB.Text.Trim() == "") { Averagerating_TB.Focus(); throw new Exception("Средняя оценка должна содержать значение"); } if (Age_TB.Text.Trim() == "") { Age_TB.Focus(); throw new Exception("Введите возраст"); } String Name = Name_TB.Text.Trim(); if (String.IsNullOrWhiteSpace(Name)) { throw new Exception("Введите имя"); } String Surname = Surname_TB.Text.Trim(); if (String.IsNullOrWhiteSpace(Surname)) { throw new Exception("Введите фамилию"); } String Middlename = Middlename_TB.Text.Trim(); if (String.IsNullOrWhiteSpace(Middlename)) { throw new Exception("Введите отчество"); } if (Class_TB.Text.Trim() == "") { Class_TB.Focus(); throw new Exception("Введите класс"); } int c = Convert.ToInt32(Class_TB.Text); if (c < 1 || c > 11) { Class_TB.Focus(); throw new Exception("Номер класса должнен находиться в диапазоне от 1 до 11"); } if (Ranked_TB.Text.Trim() == "") { Ranked_TB.Focus(); throw new Exception("Введите занятое место"); } int r = Convert.ToInt32(Ranked_TB.Text); if (r < 1 || r > 3) { Ranked_TB.Focus(); throw new Exception("Занятое место находиться в диапазоне от 1 до 3"); } } catch (FormatException Fex) { e.Cancel = true; MessageBox.Show(Fex.Message, "Внимание", MessageBoxButtons.OK, MessageBoxIcon.Warning); } catch (Exception ex) { e.Cancel = true; MessageBox.Show(ex.Message, "Внимание", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } }