コード例 #1
0
        public void insertIngredientIntoAllTables(Ingredient i, Recipe r)
        {
            var dbRecipes     = new DatabaseAccessRecipe();
            var dbIngredients = new DatabaseAccessIngredient();
            var dbConsumptionOuncesConsumed = new DatabaseAccessConsumptionOuncesConsumed();
            var dbConsumption          = new DatabaseAccessConsumption();
            var dbDensities            = new DatabaseAccessDensities();
            var dbDensitiesInformation = new DatabaseAccessDensityInformation();
            var dbCosts   = new DatabaseAccessCosts();
            var myRecipes = dbRecipes.queryRecipes();
            //var myIngredientBox = dbIngredients.queryAllIngredientsFromIngredientTable();
            var myIngredients = queryAllRelevantTablesSQLByIngredientName(i);
            var myRecipe      = dbRecipes.queryRecipeFromRecipesTableByName(r);

            if (string.IsNullOrEmpty(myRecipe.name))
            {
                dbRecipes.InsertRecipe(r);
            }
            dbIngredients.insertIngredient(i, r);
            var myIng = queryAllRelevantTablesSQLByIngredientName(i);

            dbDensitiesInformation.insertIngredientIntoDensityInfoDatabase(i);
            dbDensities.insertIngredientDensityData(i);
            dbConsumption.insertIngredientConsumtionData(i);
            var myIngUpdated = queryAllRelevantTablesSQLByIngredientName(i);

            dbCosts.insertIngredientCostDataCostTable(i);
            var myConsumptionIngredient = dbConsumption.queryConsumptionTableRowByName(i);

            dbIngredients.UpdateIngredient(i);
            var myUpdatedIngredient = queryAllRelevantTablesSQLByIngredientName(i);
        }
コード例 #2
0
        public void updateAllTables(Ingredient i, Recipe r)
        {
            var dbRecipes     = new DatabaseAccessRecipe();
            var dbIngredients = new DatabaseAccessIngredient();
            var dbConsumptionOuncesConsumed = new DatabaseAccessConsumptionOuncesConsumed();
            var dbConsumption        = new DatabaseAccessConsumption();
            var dbDensities          = new DatabaseAccessDensities();
            var dbDensityInformation = new DatabaseAccessDensityInformation();
            var dbCosts     = new DatabaseAccessCosts();
            var myCostTable = dbCosts.queryCostTable();

            foreach (var ingredient in myCostTable)
            {
                if (ingredient.ingredientId == i.ingredientId)
                {
                    if (ingredient.sellingPrice == 0m && i.sellingPrice != 0m)
                    {
                        dbCosts.updateCostDataTable(i);
                        break;
                    }
                }
            }
            dbRecipes.UpdateRecipe(r);
            dbIngredients.UpdateIngredient(i);
            var updatedIngredient = queryAllRelevantTablesSQLByIngredientName(i);

            dbDensityInformation.updateDensityInfoTable(i);
            dbDensities.updateDensityTable(i);
            dbCosts.updateCostDataTable(i);
        }
コード例 #3
0
        public List <string> getListOfDistinctSellingWeights()
        {
            var dbD = new DatabaseAccessDensities();
            var myDensiitiesTable      = dbD.queryDensitiesTableAllRows();
            var myUniqueSellingWeights = new List <string>();

            foreach (var ingredient in myDensiitiesTable)
            {
                if (!myUniqueSellingWeights.Contains(ingredient.sellingWeight))
                {
                    myUniqueSellingWeights.Add(ingredient.sellingWeight);
                }
            }
            myUniqueSellingWeights.Sort();
            return(myUniqueSellingWeights);
        }
コード例 #4
0
        public void insertIngredientCostDataCostTable(Ingredient i)
        {
            var db      = new DatabaseAccess();
            var dbD     = new DatabaseAccessDensities();
            var convert = new ConvertWeight();
            var myIngredientDensityInformation = dbD.queryIngredientFromDensityTableByName(i);

            if (i.classification.ToLower().Contains("egg"))
            {
                i.sellingWeightInOunces = convert.NumberOfEggsFromSellingQuantity(i.sellingWeight);
                i.pricePerOunce         = i.sellingPrice / i.sellingWeightInOunces;
            }
            var commandText = @"Insert into costs (name, selling_weight, selling_price, price_per_ounce, item_id) values (@name, @selling_weight, @selling_price, @price_per_ounce, @item_id);";

            db.executeVoidQuery(commandText, cmd => {
                cmd.Parameters.AddWithValue("@ing_id", i.ingredientId);
                cmd.Parameters.AddWithValue("@name", i.name);
                cmd.Parameters.AddWithValue("@selling_weight", i.sellingWeight);
                cmd.Parameters.AddWithValue("@selling_price", i.sellingPrice);
                cmd.Parameters.AddWithValue("@price_per_ounce", i.pricePerOunce);
                cmd.Parameters.AddWithValue("@item_id", i.itemId);
                return(cmd);
            });
        }
コード例 #5
0
        public void updateConsumptionTable(Ingredient i)
        {
            var db  = new DatabaseAccess();
            var dbI = new DatabaseAccessIngredient();
            var dbConsumptionOuncesConsumed = new DatabaseAccessConsumptionOuncesConsumed();
            var convert      = new ConvertWeight();
            var dbD          = new DatabaseAccessDensities();
            var myIngredient = dbI.queryIngredientFromIngredientsTableByName(i);
            var myConsumptionTableIngredient = queryConsumptionTableRowByName(i);
            var myDensityTableIngredient     = dbD.queryIngredientFromDensityTableByName(i);
            //var myDensityTableIngredient = dbD.queryIngredientFromDensityTableByName(i);
            var temp = new Ingredient();

            //this handles egg classifications, calculates ounces consumed and ounces remaining
            if (myIngredient.classification.ToLower().Contains("egg"))
            {
                var currentOuncesConsumed = convert.EggsConsumedFromIngredientMeasurement(i.measurement);
                if (myConsumptionTableIngredient.ouncesConsumed != currentOuncesConsumed)
                {
                    i.ouncesConsumed = convert.EggsConsumedFromIngredientMeasurement(i.measurement);
                }
                if (myConsumptionTableIngredient.ouncesRemaining == 0m)
                {
                    i.ouncesRemaining = i.sellingWeightInOunces - i.ouncesConsumed;
                }
                else
                {
                    i.ouncesRemaining = myConsumptionTableIngredient.ouncesRemaining - i.ouncesConsumed;
                }
            }
            //this handles other ingredients; eggs have to be calculated by usage of egg, not by an actual measurement
            else
            {
                //if (i.ouncesConsumed == 0m)
                myConsumptionTableIngredient.ouncesConsumed = dbConsumptionOuncesConsumed.CalculateOuncesConsumedFromMeasurement(i);
                i.ouncesConsumed = myConsumptionTableIngredient.ouncesConsumed;
                if (myConsumptionTableIngredient.ouncesRemaining == 0m)
                {
                    myConsumptionTableIngredient.ouncesRemaining = myDensityTableIngredient.sellingWeightInOunces - myConsumptionTableIngredient.ouncesConsumed;
                }
                else
                {
                    myConsumptionTableIngredient.ouncesRemaining = myConsumptionTableIngredient.ouncesRemaining - myConsumptionTableIngredient.ouncesConsumed;
                }
                i.ouncesRemaining = myConsumptionTableIngredient.ouncesRemaining;
            }
            //if (string.IsNullOrEmpty(temp.name) && !(i.classification.ToLower().Contains("egg")))
            if (i.classification.ToLower().Contains("egg"))
            {
                temp.name = "Egg";
            }
            if (string.IsNullOrEmpty(temp.name))
            {
                temp.name = i.name;
            }
            //temp.name = i.name;
            //subtractOuncesRemainingIfExpirationDateIsPast(i);
            // this needs to be fixed, maybe for hte moment having a condition for ig it is eggs or dairy... flour and sugar, etc. should be totally fine
            var commandText = "update consumption set ounces_consumed=@ounces_consumed, ounces_remaining=@ounces_remaining, refill=@refill where name=@name;";

            db.executeVoidQuery(commandText, cmd => {
                cmd.Parameters.AddWithValue("@name", temp.name);
                cmd.Parameters.AddWithValue("@ounces_consumed", i.ouncesConsumed);
                cmd.Parameters.AddWithValue("@ounces_remaining", i.ouncesRemaining);
                cmd.Parameters.AddWithValue("@refill", i.restock);
                return(cmd);
            });
            doesIngredientNeedRestocking(i);
            //this is after the consumption insertion and update... so it should work fine...
            var myUpdatedIngredient = queryConsumptionTableRowByName(i);

            dbConsumptionOuncesConsumed.insertIngredientIntoConsumptionOuncesConsumed(i);
            //still not getting the ouncesRemaining... need to change this
            var consumptionOuncesConsumed = dbConsumptionOuncesConsumed.queryConsumptionOuncesConsumed();
            var myUpdatedIngredient2      = queryConsumptionTableRowByName(i);
            //why am i not inserting this into the database?
            var myUpdatedConsumptionOuncesConsumedTable = dbConsumptionOuncesConsumed.queryConsumptionOuncesConsumed();
        }