private void FormCarSpare_Load(object sender, EventArgs e)
 {
     try
     {
         var list = logicP.Read(null);
         if (list != null)
         {
             comboBoxSpare.DisplayMember = "SpareName";
             comboBoxSpare.ValueMember   = "Id";
             comboBoxSpare.DataSource    = list;
             comboBoxSpare.SelectedItem  = null;
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
        public FormFlawRequest(ISpareLogic logic)
        {
            InitializeComponent();
            List <SpareViewModel> list = logic.Read(null);

            if (list != null)
            {
                comboBoxSpare.DisplayMember = "SpareName";
                comboBoxSpare.ValueMember   = "Id";
                comboBoxSpare.DataSource    = list;
                comboBoxSpare.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);
     }
 }
Example #4
0
 private void FormSpare_Load(object sender, EventArgs e)
 {
     if (id.HasValue)
     {
         try
         {
             var view = logic.Read(new SpareBindingModel {
                 Id = id
             })?[0];
             if (view != null)
             {
                 textBoxName.Text  = view.SpareName;
                 textBoxPrice.Text = view.Price.ToString();
                 textBoxCount.Text = view.TotalAmount.ToString();
             }
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
     }
 }
Example #5
0
        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.CarSpares)
                    {
                        var detcount = _SpareLogic.Read(new SpareBindingModel {
                            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
                        {
                            _SpareLogic.CreateOrUpdate(new SpareBindingModel
                            {
                                Id          = detcount.Id,
                                SpareName   = detcount.SpareName,
                                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"));
        }