예제 #1
0
        public List <IngredientQuantity> GetAllIngredients()
        {
            List <IngredientQuantity> allIngredients = new List <IngredientQuantity> {
            };
            MySqlConnection conn = DB.Connection();

            conn.Open();
            MySqlCommand cmd = new MySqlCommand("SELECT ingredients.*, i_s.quantity FROM ingredients_shipments i_s JOIN ingredients ON (ingredients.id = i_s.ingredient_id) WHERE i_s.shipment_id=@shipment_id ORDER BY ingredients.name", conn);

            cmd.Parameters.Add(new MySqlParameter("@shipment_id", Id));
            MySqlDataReader rdr = cmd.ExecuteReader();

            while (rdr.Read())
            {
                int                id                 = rdr.GetInt32(0);
                string             name               = rdr.GetString(1);
                int                quantity           = rdr.GetInt32(2);
                int                shipmentQuantity   = rdr.GetInt32(3);
                Ingredient         newIngredient      = new Ingredient(name, quantity - shipmentQuantity, id);
                IngredientQuantity ingredientQuantity = new IngredientQuantity(newIngredient, shipmentQuantity);
                allIngredients.Add(ingredientQuantity);
            }
            conn.Close();
            if (conn != null)
            {
                conn.Dispose();
            }
            return(allIngredients);
        }
예제 #2
0
        public List <IngredientQuantity> GetAllIngredients()
        {
            List <IngredientQuantity> allIngredients = new List <IngredientQuantity> {
            };
            MySqlConnection conn = DB.Connection();

            conn.Open();
            MySqlCommand cmd = new MySqlCommand("SELECT ingredients.*, in_d.ingredient_quantity FROM ingredients JOIN ingredients_dishes in_d ON (ingredients.id = in_d.ingredient_id) WHERE in_d.dish_id=@id ORDER BY ingredients.name", conn);

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

            while (rdr.Read())
            {
                ingredientId      = rdr.GetInt32(0);
                name              = rdr.GetString(1);
                inventoryQuantity = rdr.GetInt32(2);
                dishQuantity      = rdr.GetInt32(3);
                Ingredient         ingredient         = new Ingredient(name, inventoryQuantity, ingredientId);
                IngredientQuantity ingredientQuantity = new IngredientQuantity(ingredient, dishQuantity);
                allIngredients.Add(ingredientQuantity);
            }
            conn.Close();
            if (conn != null)
            {
                conn.Dispose();
            }
            return(allIngredients);
        }
 public override bool Equals(System.Object otherIngredientQuantity)
 {
     if (!(otherIngredientQuantity is  IngredientQuantity))
     {
         return(false);
     }
     else
     {
         IngredientQuantity newIngredientQuantity = (IngredientQuantity)otherIngredientQuantity;
         bool IngredientEquality = this.GetIngredient().Equals(newIngredientQuantity.GetIngredient());
         bool quantityEquality   = this.GetQuantity().Equals(newIngredientQuantity.GetQuantity());
         return(IngredientEquality && quantityEquality);
     }
 }