private void FormCarDetail_Load(object sender, EventArgs e) { try { var list = logicP.Read(null); if (list != null) { comboBoxDetail.DisplayMember = "DetailName"; comboBoxDetail.ValueMember = "Id"; comboBoxDetail.DataSource = list; comboBoxDetail.SelectedItem = null; } } catch (Exception ex) { MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public FormDetailRequest(IDetailLogic logic) { InitializeComponent(); List <DetailViewModel> list = logic.Read(null); if (list != null) { comboBoxDetail.DisplayMember = "DetailName"; comboBoxDetail.ValueMember = "Id"; comboBoxDetail.DataSource = list; comboBoxDetail.SelectedItem = null; } }
private void LoadData() { try { var list = logic.Read(null); if (list != null) { dataGridView.DataSource = list; dataGridView.Columns[0].Visible = false; dataGridView.Columns[1].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; } } catch (Exception ex) { MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void FormDetail_Load(object sender, EventArgs e) { if (id.HasValue) { try { var view = logic.Read(new DetailBindingModel { Id = id })?[0]; if (view != null) { textBoxName.Text = view.DetailName; textBoxPrice.Text = view.Price.ToString(); textBoxCount.Text = view.TotalAmount.ToString(); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
public ActionResult CreateOrder(CreateOrderModel model) { if (!ModelState.IsValid) { ViewBag.OrderCars = _carLogic.Read(null); return(View(model)); } if (model.OrderCars == null) { ViewBag.OrderCars = _carLogic.Read(null); ModelState.AddModelError("", "Выберите автомобиль"); return(View(model)); } var orderCars = new List <OrderCarBindingModel>(); int flag = 0; foreach (var car in model.OrderCars) { if (car.Value > 0) { var cart = _carLogic.Read(new CarBindingModel { Id = car.Key }).FirstOrDefault(); foreach (var det in cart.CarDetails) { var detcount = _detailLogic.Read(new DetailBindingModel { Id = det.Key }).FirstOrDefault(); if ((det.Value.Item2 * car.Value) > detcount.TotalAmount) { //вывести пользователю ModelState.AddModelError("", "МАЛО ДЕТАЛЕЙ"); flag = 1; int raznica = (det.Value.Item2 * car.Value) - detcount.TotalAmount; } else { _detailLogic.CreateOrUpdate(new DetailBindingModel { Id = detcount.Id, DetailName = detcount.DetailName, Price = detcount.Price, TotalAmount = detcount.TotalAmount - (det.Value.Item2 * car.Value) }); } } orderCars.Add(new OrderCarBindingModel { CarId = car.Key, Count = car.Value }); } } if (flag == 1) { _orderLogic.CreateOrUpdate(new OrderBindingModel { ClientId = Program.Client.Id, DateCreate = DateTime.Now, Status = OrderStatus.Ожидает_поставки_деталей, Price = CalculateSum(orderCars), OrderCars = orderCars }); } else { _orderLogic.CreateOrUpdate(new OrderBindingModel { ClientId = Program.Client.Id, DateCreate = DateTime.Now, Status = OrderStatus.Принят, Price = CalculateSum(orderCars), OrderCars = orderCars }); } return(RedirectToAction("Order")); }