private void buttonSave_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(textBoxFIO.Text)) { MessageBox.Show("Заполните ФИО", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } try { if (id.HasValue) { service.UpdElement(new ProviderBM { Id = id.Value, Name = textBoxFIO.Text, Frequency = chastotaDiapComponent1.number, Type = userControlList1.SelectedText }); } else { service.AddElement(new ProviderBM { Name = textBoxFIO.Text, Frequency = chastotaDiapComponent1.number, Type = userControlList1.SelectedText }); } MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); DialogResult = DialogResult.OK; Close(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } }