private void buttonSave_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(textBoxDate.Text)) { MessageBox.Show("Не указана дата", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (details == null || details.Count == 0) { MessageBox.Show("Заполните детали", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } try { List <DetailRequestBindingModel> requestDetailsBinding = new List <DetailRequestBindingModel>(); for (int i = 0; i < details.Count; ++i) { requestDetailsBinding.Add(new DetailRequestBindingModel { Id = details[i].Id, DetailId = details[i].DetailId, Amount = details[i].Amount, }); } request.AddElement(new RequestBindingModel { DateCreate = DateTime.Now, DetailRequests = requestDetailsBinding }); MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); DialogResult = DialogResult.OK; Close(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void buttonAddRequest_Click(object sender, EventArgs e) { if (requestProducts == null || requestProducts.Count == 0) { MessageBox.Show("Выберите продукты для заявки", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } try { List <RequestProductBindingModel> requestProductBM = new List <RequestProductBindingModel>(); for (int i = 0; i < requestProducts.Count; ++i) { requestProductBM.Add(new RequestProductBindingModel { Id = requestProducts[i].Id, RequestId = requestProducts[i].RequestId, ProductId = requestProducts[i].ProductId, Count = requestProducts[i].Count } ); } service.AddElement(new RequestBindingModel { Price = Convert.ToInt32(textBoxTotalSum.Text), Date = DateTime.Now, RequestProducts = requestProductBM } ); MessageBox.Show("Добавлена новое заявка", "Информация", MessageBoxButtons.OK, MessageBoxIcon.Information); DialogResult = DialogResult.OK; Close(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } }