У меня есть форма WinForms.
Все данные сохраняются в БД на SQL
, и форматы данных разный.Как обработать исключения(для каждого типа),что-бы было коротко для всех контролов(минимум 20-25 контролов) этой формы при нажатия на Save Button
.
private void button1_Click(object sender, EventArgs e)
{
try
{
BandivanKatDataContext db = new BandivanKatDataContext();
Animals newAnimal = new Animals();
newAnimal.number = int.Parse(textBox1.Text);
newAnimal.name = textBox2.Text;
newAnimal.gender = textBox3.Text;
newAnimal.age_Group = textBox4.Text;
newAnimal.birthday = DateTime.Parse(textBox5.Text);
newAnimal.breed = textBox7.Text;
newAnimal.milk_volume = textBox6.Text;
newAnimal.genetic = textBox17.Text;
newAnimal.weghit = int.Parse(textBox18.Text);
newAnimal.count_of_child = int.Parse(textBox19.Text);
//
db.Animals.InsertOnSubmit(newAnimal);
db.SubmitChanges();
//
MotherAnimal newMotherAnimal = new MotherAnimal();
newMotherAnimal.motherNumber = int.Parse(textBox8.Text);
newMotherAnimal.name = textBox9.Text;
newMotherAnimal.birthday = DateTime.Parse(textBox10.Text);
newMotherAnimal.genetic = textBox16.Text;
newMotherAnimal.number = int.Parse(textBox1.Text);
//
db.MotherAnimal.InsertOnSubmit(newMotherAnimal);
db.SubmitChanges();
//
FatherAnimal newFatherAnimal = new FatherAnimal();
newFatherAnimal.fatherNumber = int.Parse(textBox11.Text);
newFatherAnimal.name = textBox12.Text;
newFatherAnimal.birthday = DateTime.Parse(textBox13.Text);
newFatherAnimal.genetic = textBox14.Text;
newFatherAnimal.weghit = int.Parse(textBox15.Text);
newFatherAnimal.number = int.Parse(textBox1.Text);
db.FatherAnimal.InsertOnSubmit(newFatherAnimal);
db.SubmitChanges();
//
}
catch(Exception)
{
MessageBox.Show("Մուտքագրեք ճիշտ տվյալ");
}
}
Linq To Sql
не думаю что разница будет большой,база не так и уж большая