Esempio n. 1
0
        public DishAndOrder GetDishAndOrder(int orderId)
        {
            DishAndOrder dishAndOrder = new DishAndOrder();

            try
            {
                SqlCommand query = PrepareCommand("SELECT * " +
                                                  "FROM DishOrders " +
                                                  "WHERE OrderID = '" + orderId + "'");

                //dishAndOrder = Converter.ConvertTo(query);
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
            finally
            {
                connection?.Close();
            }

            return(dishAndOrder);
        }
Esempio n. 2
0
        public ObservableCollection <DishAndOrder> GetAllDishAndOrders(int orderID)
        {
            ObservableCollection <DishAndOrder> dishAndOrders = new ObservableCollection <DishAndOrder>();

            try
            {
                SqlCommand query = PrepareCommand(
                    "SELECT Catering.CateringName, Dish.DishName, Dish.Price, DishOrders.Amount, Dish.CateringID FROM DishOrders " +
                    $"INNER JOIN Dish ON DishOrders.DishID = Dish.DishID INNER JOIN Catering ON Catering.CateringID = Dish.CateringID WHERE DishOrders.OrderID = '{orderID}'");

                var reader = query.ExecuteReader();
                while (reader.Read())
                {
                    DishAndOrder dishAndOrder = new DishAndOrder()
                    {
                        CateringName = reader.GetString(0),
                        DishName     = reader.GetString(1),
                        DishPrice    = reader.GetDouble(2),
                        DishAmount   = reader.GetInt32(3),
                        CateringID   = reader.GetInt32(4)
                    };
                    dishAndOrders.Add(dishAndOrder);
                }
                reader.Close();
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
            finally
            {
                connection?.Close();
            }

            return(dishAndOrders);
        }