Exemple #1
0
        private void LoadHistory()
        {
            using (var context = new DBEntities.OrderDBContext())
            {
                var ResultOrder = from all in context.Orders select all;
                orders.AddRange(ResultOrder.ToList <DBEntities.Order>());

                var ResultPizza = from all in context.Pizzas select all;
                pizzas.AddRange(ResultPizza.ToList <DBEntities.Pizza>());

                var ResultDish = from all in context.Dishes select all;
                dishes.AddRange(ResultDish.ToList <DBEntities.Dish>());

                var ResultSoup = from all in context.Soups select all;
                soups.AddRange(ResultSoup.ToList <DBEntities.Soup>());

                var ResultDrink = from all in context.Drinks select all;
                drinks.AddRange(ResultDrink.ToList <DBEntities.Drink>());

                var ResultPizzaAdd = from all in context.PizzaAdds select all;
                pizzaAdds.AddRange(ResultPizzaAdd.ToList <DBEntities.PizzaAdd>());

                var ResultDishAdd = from all in context.DishAdds select all;
                dishAdds.AddRange(ResultDishAdd.ToList <DBEntities.DishAdd>());

                cmbOrder.DataSource = orders;
            }
        }
Exemple #2
0
        private void SendToDatabase(out int?OrderId)
        {
            OrderId = null;
            try
            {
                using (var db = new DBEntities.OrderDBContext())
                {
                    var order = new DBEntities.Order();
                    order.TableNO     = (ETable)cmbSelectTable.SelectedValue;
                    order.TotalPrice  = double.Parse(txtTotalPrice.Text);
                    order.Description = txtDescription.Text;

                    order.Meals = new List <IMeal>();

                    foreach (DBEntities.Pizza pizza in pizzaList)
                    {
                        order.Meals.Add(pizza);
                        pizza.Order = order;
                        db.Pizzas.Add(pizza);
                    }

                    foreach (DBEntities.Dish dish in dishList)
                    {
                        order.Meals.Add(dish);
                        dish.Order = order;
                        db.Dishes.Add(dish);
                    }

                    foreach (DBEntities.Soup soup in soupList)
                    {
                        order.Meals.Add(soup);
                        soup.Order = order;
                        db.Soups.Add(soup);
                    }

                    foreach (DBEntities.Drink drink in drinkList)
                    {
                        order.Meals.Add(drink);
                        drink.Order = order;
                        db.Drinks.Add(drink);
                    }



                    db.Orders.Add(order);

                    db.SaveChanges();

                    OrderId = order.Id;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Błąd zapisu do bazy danych", "Zapis do bazy danych", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }