Ejemplo n.º 1
0
 public void RemoveIngredient(Recipe r)
 {
     foreach (Recipe rec in lstIngredients)
         if (rec == r)
             lstIngredients.Remove(rec);
 }
Ejemplo n.º 2
0
        public static void DeleteRecipeMaterial(Recipe recToDel)
        {
            try
            {
                string query = "delete from RecipeMaterials where Makes = ? and MadeOf = ?";
                OleDbCommand cmd = new OleDbCommand(query, conn);
                cmd.Parameters.Add("?", OleDbType.VarChar).Value = recToDel.Makes;
                cmd.Parameters.Add("?", OleDbType.VarChar).Value = recToDel.MadeOf;

                DataConnection.OpenConnection();

                cmd.ExecuteNonQuery();
            }
            catch (Exception ex)
            {

            }
            finally
            {
                DataConnection.CloseConnection();
            }
        }
Ejemplo n.º 3
0
 public void AddIngredient(Recipe r)
 {
     lstIngredients.Add(r);
 }
Ejemplo n.º 4
0
        public static string AddRecipeItem(Recipe r)
        {
            //insert a single recipe entry in the RecipeMaterials table
            //since adding a bulk of Recipe items (such as from a complex recipe) would be most easily done by a
            //compound insert which Access conveniently does not support, this just needs to be called multiple times for
            //each of the recipes in the Foodstuff's list to add.
            try
            {
                //refactoring to build in only those parameters we actually need.
                OleDbCommand cmd = new OleDbCommand();
                string query = "insert into RecipeMaterials(Makes, MadeOf";

                cmd.Parameters.Add("?", OleDbType.VarChar).Value = r.Makes;
                cmd.Parameters.Add("?", OleDbType.VarChar).Value = r.MadeOf;
                int intParameterCounter = 2;
                if (r.FractionAmount() != "")
                {
                    query += " , Quantity";
                    cmd.Parameters.Add("?", OleDbType.VarChar).Value = r.FractionAmount();
                    intParameterCounter++;
                }
                if (r.Unit != "")
                {
                    query += ", Unit";
                    cmd.Parameters.Add("?", OleDbType.VarChar).Value = r.Unit;
                    intParameterCounter++;
                }
                query += ") Values(?";

                for (int i = 1; i < intParameterCounter; i++) //counter is one-based
                {
                    query += ",?";
                }
                query += ")";
                cmd.CommandText = query;
                cmd.Connection = conn;

                DataConnection.OpenConnection();

                cmd.ExecuteNonQuery();

                return "Item added.";
            }
            catch (Exception ex)
            {
                return ex.ToString();
            }
            finally
            {
                DataConnection.CloseConnection();
            }
        }