Example #1
0
        List <IngredientsQuantity> GetRecipeIngredientsFromDB(int RecipeId)
        {
            List <IngredientsQuantity> ingredientsList = new List <IngredientsQuantity>();
            SqlDataReader reader;

            query   = "SELECT * FROM RecipesIngredientsTable WHERE RecipeId = " + RecipeId.ToString();
            command = new SqlCommand(query, conn);
            try
            {
                conn.Open();

                reader = command.ExecuteReader();
                while (reader.Read())
                {
                    IngredientsQuantity ingredient = new IngredientsQuantity();
                    ingredient.ingredient = reader["Ingredient"].ToString();
                    ingredient.Quantity   = (int)reader["Quantity"];
                    ingredient.unit       = reader["Unit"].ToString();

                    ingredientsList.Add(ingredient);
                }
            }
            finally
            {
                conn.Close();
            }

            return(ingredientsList);
        }
Example #2
0
        Recipe GetRecipeFromForm()
        {
            string name          = txtRecipeName.Text;
            string sPeopleServed = txtPeopleServed.Text;
            string sCookingTime  = txtCookingTime.Text;

            Int16 peopleServed = 0;

            Int16.TryParse(sPeopleServed, out peopleServed);

            Int16 cookingTime = 0;

            Int16.TryParse(sCookingTime, out cookingTime);

            //ingredientsList
            List <IngredientsQuantity> ingredientsList = new List <IngredientsQuantity>();

            IngredientsQuantity ingredientQuantity = new IngredientsQuantity();

            if (!(comboBox1.Text == "" || comboBox1.Text == "none" || comboBox1.Text == "None" || txtQty1.Text == ""))
            {
                ingredientQuantity.ingredient = comboBox1.Text;
                ingredientQuantity.Quantity   = int.Parse(txtQty1.Text);
                ingredientQuantity.unit       = lblUnit1.Text;
                ingredientsList.Add(ingredientQuantity);
            }

            if (!(comboBox2.Text == "" || comboBox2.Text == "none" || comboBox2.Text == "None" || txtQty2.Text == ""))
            {
                ingredientQuantity            = new IngredientsQuantity();
                ingredientQuantity.ingredient = comboBox2.Text;
                ingredientQuantity.Quantity   = int.Parse(txtQty2.Text);
                ingredientQuantity.unit       = lblUnit2.Text;
                ingredientsList.Add(ingredientQuantity);
            }

            if (!(comboBox3.Text == "" || comboBox3.Text == "none" || comboBox3.Text == "None" || txtQty3.Text == ""))
            {
                ingredientQuantity            = new IngredientsQuantity();
                ingredientQuantity.ingredient = comboBox3.Text;
                ingredientQuantity.Quantity   = int.Parse(txtQty3.Text);
                ingredientQuantity.unit       = lblUnit3.Text;
                ingredientsList.Add(ingredientQuantity);
            }

            if (!(comboBox4.Text == "" || comboBox4.Text == "none" || comboBox4.Text == "None" || txtQty4.Text == ""))
            {
                ingredientQuantity            = new IngredientsQuantity();
                ingredientQuantity.ingredient = comboBox4.Text;
                ingredientQuantity.Quantity   = int.Parse(txtQty4.Text);
                ingredientQuantity.unit       = lblUnit4.Text;
                ingredientsList.Add(ingredientQuantity);
            }

            if (!(comboBox5.Text == "" || comboBox5.Text == "none" || comboBox5.Text == "None" || txtQty5.Text == ""))
            {
                ingredientQuantity            = new IngredientsQuantity();
                ingredientQuantity.ingredient = comboBox5.Text;
                ingredientQuantity.Quantity   = int.Parse(txtQty5.Text);
                ingredientQuantity.unit       = lblUnit5.Text;
                ingredientsList.Add(ingredientQuantity);
            }

            //int Id = GetNextRecipeId();

            Recipe recipe = new Recipe(ingredientsList, peopleServed, cookingTime, name);

            return(recipe);
        }