Ejemplo n.º 1
0
        public decimal getPricePerOunce(Ingredient i)
        {
            var convert = new ConvertWeight();
            var myCostTableIngredients = queryCostTable();
            var pricePerOunce          = 0m;

            foreach (var ingredient in myCostTableIngredients)
            {
                if (ingredient.name == i.name)
                {
                    i.sellingPrice = ingredient.sellingPrice;
                    if (i.classification.ToLower().Contains("egg"))
                    {
                        i.sellingWeightInOunces = convert.NumberOfEggsFromSellingQuantity(i.sellingWeight);
                    }
                    else
                    {
                        i.sellingWeightInOunces = convert.ConvertWeightToOunces(ingredient.sellingWeight);
                    }
                    i.pricePerOunce = Math.Round((i.sellingPrice / i.sellingWeightInOunces), 4);
                    pricePerOunce   = i.pricePerOunce;
                }
            }
            return(pricePerOunce);
        }
        public void refillIngredientInConsumptionDatabase(Ingredient i, string sellingWeightToRefill)
        {
            var db                            = new DatabaseAccess();
            var convert                       = new ConvertWeight();
            var myConsumptionTable            = queryConsumptionTable();
            var sellingWeightToRefillInOunces = convert.ConvertWeightToOunces(sellingWeightToRefill);

            foreach (var ingredient in myConsumptionTable)
            {
                if (ingredient.name.ToLower() == i.name.ToLower())
                {
                    if (i.ouncesRemaining < 0m)
                    {
                        i.ouncesRemaining = 0m;
                    }
                    i.ouncesRemaining = ingredient.ouncesRemaining + sellingWeightToRefillInOunces;
                    break;
                }
            }
            var commandText = "update consumption set ounces_remaining=@ounces_remaining where name=@name;";

            db.executeVoidQuery(commandText, cmd => {
                cmd.Parameters.AddWithValue("@name", i.name);
                cmd.Parameters.AddWithValue("@ounces_remaining", i.ouncesRemaining);
                return(cmd);
            });
        }
        public void insertIngredientDensityData(Ingredient i)
        {
            var convert = new ConvertWeight();
            var db      = new DatabaseAccess();
            var dbDensityInformation = new DatabaseAccessDensityInformation();

            if (i.sellingPrice == 0m)
            {
                myItemResponse = returnItemResponse(i);
            }
            i.density = dbDensityInformation.queryDensityTableRowDensityValueByName(i);
            if (i.sellingPrice == 0m)
            {
                i.sellingPrice = myItemResponse.salePrice;
            }
            if (i.classification.ToLower() == "egg" || i.classification.ToLower() == "eggs")
            {
                i.sellingWeightInOunces = convert.NumberOfEggsFromSellingQuantity(i.sellingWeight);
            }
            else
            {
                i.sellingWeightInOunces = convert.ConvertWeightToOunces(i.sellingWeight);
            }
            if (i.sellingWeightInOunces == 0m)
            {
                throw new Exception("Selling Weight In Ounces is 0; please check that your Selling Weight is an appopriate weight.");
            }
            i.pricePerOunce = Math.Round((i.sellingPrice / i.sellingWeightInOunces), 4);
            if (string.IsNullOrEmpty(i.classification))
            {
                i.classification = " ";
            }
            var commandText = @"Insert into densities (name, density, selling_weight, selling_weight_ounces, selling_price, price_per_ounce) 
                            values (@name, @density, @selling_weight, @selling_weight_ounces, @selling_price, @price_per_ounce);";

            db.executeVoidQuery(commandText, cmd => {
                cmd.Parameters.AddWithValue("@name", i.name);
                cmd.Parameters.AddWithValue("@density", i.density);
                cmd.Parameters.AddWithValue("@selling_weight", i.sellingWeight);
                cmd.Parameters.AddWithValue("@selling_price", i.sellingPrice);
                cmd.Parameters.AddWithValue("@selling_weight_ounces", i.sellingWeightInOunces);
                cmd.Parameters.AddWithValue("@price_per_ounce", i.pricePerOunce);
                return(cmd);
            });
        }
        public void refillIngredientInConsumptionDatabase(Ingredient i, string sellingWeightToRefill, string newExpirationDate)
        {
            var db                          = new DatabaseAccess();
            var dbIngredients               = new DatabaseAccessIngredient();
            var convert                     = new ConvertWeight();
            var myConsumptionTable          = queryConsumptionTable();
            var myIngredientTable           = dbIngredients.queryAllIngredientsFromIngredientTable();
            var sellingWeightToRefillOunces = convert.ConvertWeightToOunces(sellingWeightToRefill);

            foreach (var ingredient in myConsumptionTable)
            {
                if (ingredient.name.ToLower() == i.name.ToLower())
                {
                    if (i.ouncesRemaining < 0m)
                    {
                        i.ouncesRemaining = 0m;
                    }
                    i.ouncesRemaining = ingredient.ouncesRemaining + sellingWeightToRefillOunces;
                    var commandText = "update consumption set ounces_remaining=@ounces_remaining where name=@name;";
                    db.executeVoidQuery(commandText, cmd => {
                        cmd.Parameters.AddWithValue("@name", i.name);
                        cmd.Parameters.AddWithValue("@ounces_remaining", i.ouncesRemaining);
                        return(cmd);
                    });
                    break;
                }
            }
            foreach (var ingredient in myIngredientTable)
            {
                if (ingredient.ingredientId == i.ingredientId && ingredient.name.ToLower() == i.name.ToLower())
                {
                    ingredient.expirationDate = dbIngredients.convertStringMMDDYYYYToDateYYYYMMDD(newExpirationDate);
                    var commandText = "update ingredients set expiration_date=@expiration_date where ing_id=@ing_id";
                    db.executeVoidQuery(commandText, cmd => {
                        cmd.Parameters.AddWithValue("@expiration_date", dbIngredients.convertDateToStringMMDDYYYY(ingredient.expirationDate));
                        cmd.Parameters.AddWithValue("@ing_id", ingredient.ingredientId);
                        return(cmd);
                    });
                    break;
                }
            }
        }