/// <summary> /// Загрузить список блюд /// </summary> private void LoadData() { try { var list = dishLogic.Read(null); if (list != null) { dataGridView.DataSource = list; dataGridView.Columns[0].Visible = false; dataGridView.Columns[1].Width = 200; dataGridView.Columns[2].Width = 80; dataGridView.Columns[3].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; dataGridView.Columns[4].Visible = false; } } catch (Exception ex) { MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public void CreateOrder(CreateOrderBindingModel model) { try { Random rnd = new Random(); var dishes = dishLogic.Read(null); var firstDishes = dishes.Where(x => x.DishType == DishType.Первое).ToList(); var secondDishes = dishes.Where(x => x.DishType == DishType.Второе).ToList(); var desserts = dishes.Where(x => x.DishType == DishType.Десерт).ToList(); var drinks = dishes.Where(x => x.DishType == DishType.Напиток).ToList(); if (firstDishes.Count() == 0 || secondDishes.Count() == 0 || desserts.Count() == 0 || drinks.Count() == 0) { throw new Exception("Отсутствуют 4 разных вида блюд"); } int indexFD = rnd.Next(0, firstDishes.Count()); int indexSD = rnd.Next(0, secondDishes.Count()); int indexDessert = rnd.Next(0, desserts.Count()); int indexDrink = rnd.Next(0, drinks.Count()); orderLogic.CreateOrUpdate(new OrderBindingModel { ClientId = model.ClientId, OrderDishes = new Dictionary <int, (string, decimal)> { { firstDishes[indexFD].Id.Value, (firstDishes[indexFD].DishName, firstDishes[indexFD].Price) }, { secondDishes[indexSD].Id.Value, (secondDishes[indexSD].DishName, secondDishes[indexSD].Price) },
/// <summary> /// Получение списка заявок и заказов с расшифровкой по продуктам /// </summary> /// <returns></returns> public List <ReportRequestAndOrderProductsViewModel> GetRequestOrderProducts(ReportPeriodBindingModel model) { var reportList = new List <ReportRequestAndOrderProductsViewModel>(); var requests = requestLogic.Read(new RequestBindingModel { DateFrom = model.DateFrom, DateTo = model.DateTo }); var orders = orderLogic.Read(new OrderBindingModel { DateFrom = model.DateFrom, DateTo = model.DateTo }); int ri = 0; int oi = 0; while (ri < requests.Count && oi < orders.Count) { if (requests[ri].DateRequest < orders[oi].DateCreate) { foreach (var product in requests[ri].RequestProducts) { reportList.Add(new ReportRequestAndOrderProductsViewModel { Id = requests[ri].Id.Value, DateCreate = requests[ri].DateRequest, DishName = string.Empty, ProductName = product.Value.Item1, Count = product.Value.Item2 }); } ri++; } else { foreach (var dish in orders[oi].OrderDishes) { var currentDish = dishLogic.Read(new DishBindingModel { Id = dish.Key })[0]; foreach (var product in currentDish.DishProducts) { reportList.Add(new ReportRequestAndOrderProductsViewModel { Id = null, DateCreate = orders[oi].DateCreate, DishName = currentDish.DishName, ProductName = product.Value.Item1, Count = product.Value.Item2 }); } } oi++; } } while (ri < requests.Count) { foreach (var product in requests[ri].RequestProducts) { reportList.Add(new ReportRequestAndOrderProductsViewModel { Id = requests[ri].Id.Value, DateCreate = requests[ri].DateRequest, DishName = string.Empty, ProductName = product.Value.Item1, Count = product.Value.Item2 }); } ri++; } while (oi < orders.Count) { foreach (var dish in orders[oi].OrderDishes) { var currentDish = dishLogic.Read(new DishBindingModel { Id = dish.Key })[0]; foreach (var product in currentDish.DishProducts) { reportList.Add(new ReportRequestAndOrderProductsViewModel { Id = null, DateCreate = orders[oi].DateCreate, DishName = currentDish.DishName, ProductName = product.Value.Item1, Count = product.Value.Item2 }); } } oi++; } return(reportList); }