private decimal getMoistureContent(RawMixRecipe r) { string strIngredientName = r.Ingredient; ingredient i = ctx.ingredients.Where(ing => ing.ingredient1 == strIngredientName).First(); return i.moisture.Value; }
private decimal getWhey(RawMixRecipe r) { RawMixRecipe cream = null; RawMixRecipe skimPowder = null; foreach (RawMixRecipe re in lstRecipes) { switch (re.Ingredient) { case "Cream": cream = re; break; case "Skim Powder": skimPowder = re; break; } } decimal dcmlCreamKg = Decimal.Divide(dcmlTotalKG, 100); dcmlCreamKg = Decimal.Multiply(dcmlCreamKg, cream.Value.Value); //get that same amount in kg of cream respectivley to the butter fat content in the cream dcmlCreamKg = Decimal.Divide(dcmlCreamKg, this.txtButterFat.Value); dcmlCreamKg = Decimal.Multiply(dcmlCreamKg, 100); //get SNF from cream. This formula is predetermined: Total Cream in kilograms * inputted SNF value / 100 decimal dcmlSNFinCream = Decimal.Multiply(dcmlCreamKg, this.txtSNF.Value); dcmlSNFinCream = Decimal.Divide(dcmlSNFinCream, 100); //this represent X percent by weight from total KG of whey in recipe decimal dcmlTotalWhey = Decimal.Divide(dcmlTotalKG, 100); dcmlTotalWhey = Decimal.Multiply(dcmlTotalWhey, r.Value.Value); //some recipes need to account for skim powder and whey (25% and 75%) respectively. decimal dcmlTotalSkimPowder = 0m; if (skimPowder != null) { //do stuff to accomodate for skim powder dcmlTotalSkimPowder = dcmlTotalWhey - dcmlSNFinCream; dcmlTotalSkimPowder = Decimal.Multiply(dcmlTotalSkimPowder, Convert.ToDecimal(0.25)); } else { dcmlTotalWhey = dcmlTotalWhey - dcmlSNFinCream - dcmlTotalSkimPowder;//accomodate for some whey that comes from cream } //accomodate for moisture. This is preset 3% for whey decimal dcmlMoistureInWhey = Decimal.Divide(dcmlTotalWhey, 100); decimal dcmlMoistureContent = this.getMoistureContent(r); dcmlMoistureInWhey = Decimal.Multiply(dcmlMoistureInWhey, dcmlMoistureContent); dcmlTotalWhey = Decimal.Add(dcmlTotalWhey, dcmlMoistureInWhey); //round to two decimal places return dcmlTotalWhey; }
private decimal getIngredientAmount(RawMixRecipe r) { decimal dcmlValue = Decimal.Divide(dcmlTotalKG, 100); dcmlValue = Decimal.Multiply(dcmlValue, r.Value.Value); //account for moisture decimal dcmlMoisture = this.getMoistureContent(r); decimal dcmlAmountOfMoisture = Decimal.Divide(dcmlValue, 100); dcmlAmountOfMoisture = Decimal.Multiply(dcmlAmountOfMoisture, dcmlMoisture); dcmlValue = decimal.Add(dcmlValue, dcmlAmountOfMoisture); //round to two decimal places return dcmlValue; }
private decimal getEggYellow(RawMixRecipe r) { decimal dcmlValue = Decimal.Divide(dcmlTotalKG, 100); dcmlValue = Decimal.Multiply(dcmlValue, 0.019m); dcmlValue = Decimal.Multiply(dcmlValue, 0.1m); dcmlValue = Decimal.Divide(dcmlValue, 2); return dcmlValue; }
private decimal getCream(RawMixRecipe r) { //get weight of Butter Fat decimal dcmlValue = Decimal.Divide(dcmlTotalKG, 100); dcmlValue = Decimal.Multiply(dcmlValue, r.Value.Value); //get that same amount in kg of cream respectivley to the butter fat content in the cream dcmlValue = Decimal.Divide(dcmlValue, this.txtButterFat.Value); dcmlValue = Decimal.Multiply(dcmlValue, 100); //divide by a coefficinet that is constan to get liters of cream dcmlValue = Decimal.Divide(dcmlValue, COEFFICIENT_TO_GET_LITERS_OF_CREAM); //round to 2 decimal places return dcmlValue; }
//,int position) private void checkAvailableStock(RawMixRecipe r, decimal dcmlValue) { //db operations go here to retrieve lot codes for ingredients to use Dry_Ingredient_Use_Temp ingredientToSave = new Dry_Ingredient_Use_Temp(); List<remaining_inventory> list = null; decimal totalWeightForLotCode = dcmlValue; decimal dcmlBagsUsedForRecipe = 0m; decimal dcmlUnitSize = 0m; decimal dcmlnumberOfBags = 0m; //decimal dcmlRunninTotal = 0m; bool firstRun = true; // int intLotCodeCounter = 1; int roundingDigits = 1; try { list = ctx.remaining_inventory.Where(o => o.ingredient == r.Ingredient).ToList(); } catch (Exception ex) { MessageBox.Show("something went wrong \nwhile retrieving available inventory", "Error", MessageBoxButtons.OK); Console.WriteLine(ex); } if(list.Count == 0) { //this means that the invonetory does not have this ingredient... //allow the user to use the ingredient only if it's cream... } foreach (remaining_inventory ri in list) { if (ri.ingredient.Equals("Egg Yellow")) { roundingDigits = 3; } dcmlUnitSize = Convert.ToDecimal(ri.unit_size); dcmlBagsUsedForRecipe = decimal.Divide(totalWeightForLotCode, dcmlUnitSize); dcmlnumberOfBags = decimal.Divide(dcmlValue, dcmlUnitSize); //there is enough stock fron one lot code if ((ri.remaining_bags >= dcmlnumberOfBags) & firstRun) { //this.addLabelToForm(locationOnTheForm++ // , ri.ingredient // , Math.Round(dcmlValue, roundingDigits).ToString() // , Math.Round(dcmlnumberOfBags, 2).ToString() // , ri.lot_code); this.addIngredientToTempDB(ri, dcmlnumberOfBags, 1,dcmlValue,dcmlValue, dcmlBagsUsedForRecipe); //int ingredientLength = 40 - ri.ingredient.Length; //int valueLength = 40 - Math.Round(dcmlValue, roundingDigits).ToString().Length; //int numberOfBagLength = 40 - Math.Round(dcmlnumberOfBags, 2).ToString().Length; //int lotCodeLength = 40 - ri.lot_code.Length; //StringBuilder sb = new StringBuilder(); //sb.Append(ri.ingredient.PadRight(ingredientLength)); //sb.Append(Math.Round(dcmlValue, roundingDigits).ToString().PadRight(valueLength)); //sb.Append(Math.Round(dcmlnumberOfBags, 2).ToString().PadRight(numberOfBagLength)); //sb.Append(ri.lot_code); //listToPrint.Add(sb.ToString()); break; } //need to use more than one lot code for an ingredient if (ri.remaining_bags < dcmlnumberOfBags || ((ri.remaining_bags >= dcmlnumberOfBags) & !firstRun)) { if (firstRun) { //this.addLabelToForm(locationOnTheForm++ // , ri.ingredient // , Math.Round(dcmlValue, roundingDigits).ToString() // , Math.Round(dcmlnumberOfBags, 2).ToString() // , ri.lot_code); firstRun = false; if (ri.remaining_bags >= dcmlnumberOfBags) { this.addIngredientToTempDB(ri, dcmlnumberOfBags, 1,dcmlValue,totalWeightForLotCode, dcmlBagsUsedForRecipe); } if (ri.remaining_bags < dcmlnumberOfBags) { decimal dcmlUsed = decimal.Multiply(Convert.ToDecimal(ri.remaining_bags), dcmlUnitSize); dcmlValue = decimal.Subtract(dcmlValue, dcmlUsed); this.addIngredientToTempDB(ri, Convert.ToDecimal(ri.remaining_bags), 1,dcmlUsed, totalWeightForLotCode, dcmlBagsUsedForRecipe); } //int ingredientLength = 40 - ri.ingredient.Length; //int valueLength = 40 - Math.Round(dcmlValue, roundingDigits).ToString().Length; //int numberOfBagLength = 40 - Math.Round(dcmlnumberOfBags, 2).ToString().Length; //int lotCodeLength = 40 - ri.lot_code.Length; //StringBuilder sb = new StringBuilder(); //sb.Append(ri.ingredient.PadRight(ingredientLength)); //sb.Append(Math.Round(dcmlValue, roundingDigits).ToString().PadRight(valueLength)); //sb.Append(Math.Round(dcmlnumberOfBags, 2).ToString().PadRight(numberOfBagLength)); //sb.Append(ri.lot_code); //listToPrint.Add(sb.ToString()); } else { //this.addLabelToForm(locationOnTheForm++ // , null//ri.ingredient // , null//Math.Round(dcmlValue, 2).ToString() // , null//Math.Round(dcmlnumberOfBags, 2).ToString() // , ri.lot_code); if (ri.remaining_bags >= dcmlnumberOfBags) { decimal dcmlUsed = decimal.Multiply(Convert.ToDecimal(dcmlnumberOfBags), dcmlUnitSize); this.addIngredientToTempDB(ri, dcmlnumberOfBags, 2, dcmlUsed, totalWeightForLotCode, dcmlBagsUsedForRecipe); break; } if (ri.remaining_bags < dcmlnumberOfBags) { decimal dcmlUsed = decimal.Multiply(Convert.ToDecimal(ri.remaining_bags), dcmlUnitSize); dcmlValue = decimal.Subtract(dcmlValue, dcmlUsed); this.addIngredientToTempDB(ri, Convert.ToDecimal(ri.remaining_bags), 2,dcmlValue, totalWeightForLotCode, dcmlBagsUsedForRecipe); } //StringBuilder sb = new StringBuilder(); //sb.Append(ri.lot_code.PadLeft(120)); //listToPrint.Add(sb.ToString()); } } } }
private List<KeyValuePair<string, decimal>> getWhey(RawMixRecipe r,decimal dcmlTotalKG,List<RawMixRecipe> lstRecipes) { RawMixRecipe cream = null; RawMixRecipe skimPowder = null; RawMixRecipe whey = null; foreach (RawMixRecipe re in lstRecipes) { switch (re.Ingredient) { case "Cream": cream = re; break; case "Skim Powder": skimPowder = re; break; case "Whey": whey = re; break; } } decimal dcmlCreamKg = Decimal.Multiply(dcmlTotalKG, cream.Value.Value); //get that same amount in kg of cream respectivley to the butter fat content in the cream dcmlCreamKg = Decimal.Divide(dcmlCreamKg, this.txtButterFat.Value); //get SNF from cream. This formula is predetermined: Total Cream in kilograms * inputted SNF value / 100 decimal dcmlSNFinCream = Decimal.Multiply(dcmlCreamKg, this.txtSNF.Value); dcmlSNFinCream = Decimal.Divide(dcmlSNFinCream, 100); //this represent X percent by weight from total KG of whey in recipe decimal dcmlTotalWhey = Decimal.Divide(dcmlTotalKG, 100); decimal dcmlTotalSkimPowder = Decimal.Divide(dcmlTotalKG, 100);//get percent representation of the weight dcmlTotalWhey = Decimal.Multiply(dcmlTotalWhey, whey.Value.Value); //some recipes need to account for skim powder and whey (25% and 75%) respectively. if (skimPowder == null) { dcmlTotalWhey = dcmlTotalWhey - dcmlSNFinCream;//accomodate for some whey that comes from cream } else { dcmlTotalSkimPowder = Decimal.Multiply(dcmlTotalSkimPowder, r.Value.Value);//get weight for the recipe dcmlTotalSkimPowder = Decimal.Subtract(dcmlTotalSkimPowder, dcmlTotalWhey);//accomodate for whey dcmlTotalSkimPowder = Decimal.Subtract(dcmlTotalSkimPowder, dcmlSNFinCream);//accomodate for snf in cream } //accomodate for moisture. This is preset 3% for whey decimal dcmlMoistureInWhey = Decimal.Divide(dcmlTotalWhey, 100); decimal dcmlMoistureContent = this.getMoistureContent(r); dcmlMoistureInWhey = Decimal.Multiply(dcmlMoistureInWhey, dcmlMoistureContent); decimal dcmlMoistureInSkim = Decimal.Divide(dcmlTotalWhey, 100); decimal dcmlMoistureContentInSkim = this.getMoistureContent(r); dcmlMoistureInSkim = Decimal.Multiply(dcmlMoistureInSkim, dcmlMoistureContent); dcmlTotalWhey = Decimal.Add(dcmlTotalWhey, dcmlMoistureInWhey); //round to two decimal places KeyValuePair<string, decimal> kvpWhey = new KeyValuePair<string, decimal>("whey",dcmlTotalWhey); KeyValuePair<string, decimal> kvpSkim = new KeyValuePair<string, decimal>("skim", dcmlTotalSkimPowder); List<KeyValuePair<string, decimal>> listToreturn = new List<KeyValuePair<string, decimal>>(); listToreturn.Add(kvpSkim); listToreturn.Add(kvpWhey); return listToreturn; }