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 CustomerBindingModel { Id = id.Value, CustomerFIO = textBoxFIO.Text }); } else { service.AddElement(new CustomerBindingModel { CustomerFIO = textBoxFIO.Text }); } MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); DialogResult = DialogResult.OK; Close(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void buttonAdd_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(textBoxFIO.Text)) { MessageBox.Show("Заполните поле ФИО", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (controlComboBox.SelectedText == "") { MessageBox.Show("Выберите статус", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } try { if (id.HasValue) { customerService.UpdElement(new CustomerBindingModel { Id = id.Value, CustomerFIO = textBoxFIO.Text, State = (CustomerStatus)Enum.Parse(typeof(CustomerStatus), controlComboBox.SelectedText, true), Sum = controlSumBox.Sum }); } else { customerService.AddElement(new CustomerBindingModel { CustomerFIO = textBoxFIO.Text, State = (CustomerStatus)Enum.Parse(typeof(CustomerStatus), controlComboBox.SelectedText, true), Sum = controlSumBox.Sum }); } if (CustomerStatus.Активен == (CustomerStatus)Enum.Parse(typeof(CustomerStatus), controlComboBox.SelectedText, true)) { var form = Container.Resolve <FormSelectWorker>(); if (form.ShowDialog() == DialogResult.OK) { MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); DialogResult = DialogResult.OK; Close(); } } else { MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); DialogResult = DialogResult.OK; Close(); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } }