Esempio 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 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);
            });
        }
Esempio n. 3
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);
            });
        }