Exemple #1
0
        public List <DishQuantity> GetAllDishes()
        {
            List <DishQuantity> order = new List <DishQuantity> {
            };
            MySqlConnection conn      = DB.Connection();

            conn.Open();
            //MySqlCommand cmd = new MySqlCommand("SELECT dishes.* FROM orders JOIN dishes ON (orders.dish_id=dishes.id) WHERE orders.table_order_id=@id", conn);
            MySqlCommand cmd = new MySqlCommand("SELECT dishes.*, orders.dish_quantity FROM orders JOIN dishes ON (orders.dish_id=dishes.id) WHERE orders.table_order_id=@id ORDER BY dishes.name", conn);

            cmd.Parameters.Add(new MySqlParameter("@id", Id));
            MySqlDataReader rdr      = cmd.ExecuteReader();
            string          name     = "";
            int             dishId   = 0;
            int             quantity = 0;

            while (rdr.Read())
            {
                dishId   = rdr.GetInt32(0);
                name     = rdr.GetString(1);
                quantity = rdr.GetInt32(2);
                Dish         newDish         = new Dish(name, dishId);
                DishQuantity newDishQuantity = new DishQuantity(newDish, quantity);
                order.Add(newDishQuantity);
            }
            conn.Close();
            if (conn != null)
            {
                conn.Dispose();
            }

            return(order);
        }
 public override bool Equals(System.Object otherDishQuantity)
 {
     if (!(otherDishQuantity is DishQuantity))
     {
         return(false);
     }
     else
     {
         DishQuantity newDishQuantity  = (DishQuantity)otherDishQuantity;
         bool         dishEquality     = this.GetDish().Equals(newDishQuantity.GetDish());
         bool         quantityEquality = this.GetQuantity().Equals(newDishQuantity.GetQuantity());
         return(dishEquality && quantityEquality);
     }
 }