/// <summary> /// shows the leftovers from the whole bags in the previous batches /// </summary> private void calculateLastBatch() { List<IngredientForBatch> ingredientList = new List<IngredientForBatch>(); decimal intBatchAmount = 0; foreach (Dry_Ingredient_Use_Temp d in list) { IngredientForBatch ingred = new IngredientForBatch(); IngredientForBatch weight = new IngredientForBatch(); Raw_Mix_Batch rawMixBatch = new Raw_Mix_Batch(); rawMixBatch.ingredient = d.ingredient; if((d.ingredient != "Water" && d.ingredient != "Cream")) { if (d.totalBagsForRecipe > this.txtBatches.Value) { ingred.amount = Convert.ToString(d.totalBagsForRecipe % this.txtBatches.Value); weight.amount = Convert.ToString(d.totalWeightForRecipe % this.txtBatches.Value); //rawMixBatch.amount = d.totalBagsForRecipe % this.txtBatches.Value; rawMixBatch.batch_number = 100; ingred.ingredient = d.ingredient; ingred.batch = 100; ingredientList.Add(ingred); listForDB.Add(rawMixBatch); intBatchAmount += Convert.ToDecimal(weight.amount); } } } addControlsToForm(ingredientList, Convert.ToInt32(txtBatches.Value + 1)); }
private void presistToTable() { //get all dataGrdiViews in the form foreach (DataGridView d in this.flowPanel.Controls.OfType<DataGridView>()) { //get rows in the dgv foreach(DataGridViewRow dgvr in d.Rows) { Raw_Mix_Batch batch = new Raw_Mix_Batch(); if (dgvr.Cells[0].Value != null) { batch.ingredient = dgvr.Cells[0].Value.ToString(); } if(dgvr.Cells[1].Value != null) { //batch.amount = Convert.ToDecimal(dgvr.Cells[1].Value); } if(dgvr.Cells[2].Value != null) { batch.batch_number = Convert.ToInt32(dgvr.Cells[2].Value); } if(batch.ingredient != null && batch.amount != null && batch.batch_number != null) { ctx.Raw_Mix_Batch.Add(batch); } } } try { ctx.SaveChanges(); } catch(Exception ex) { ErrorLog log = new ErrorLog(); log.createLogFile(ex); } }
private void calculate() { this.clearDataGridView(); this.clearLabels(); this.clearListForDB(); //these are needed for point to put datagrdivews onto the form int i = 0;// This a batch counter. Also used to add/remove holdbackwater int intNumberOfBatches = Convert.ToInt32(this.txtBatches.Value);//this is needed for the batch that has leftovers while (i!=intNumberOfBatches) { List<IngredientForBatch> ingredientList = new List<IngredientForBatch>(); int intBatchAmount = 0; foreach (Dry_Ingredient_Use_Temp d in list) { IngredientForBatch ingred = new IngredientForBatch(); IngredientForBatch weight = new IngredientForBatch(); Raw_Mix_Batch rawMixBatch = new Raw_Mix_Batch(); rawMixBatch.ingredient = d.ingredient; switch(d.ingredient) { case "Water": if (i != this.txtBatches.Value) { ingred.amount = Convert.ToString(Convert.ToInt32((d.bags_used - this.txtHoldBackWater.Value) / this.txtBatches.Value)); //rawMixBatch.amount = (((d.totalBagsForRecipe - this.txtHoldBackWater.Value) / this.txtBatches.Value)); weight.amount = Convert.ToString(Convert.ToInt32((d.totalWeightForRecipe - this.txtHoldBackWater.Value) / this.txtBatches.Value)); } break; case "Egg Yellow": string strBullsEye = "hit"; if (i != this.txtBatches.Value) { if ((d.bags_used > this.txtBatches.Value) || (d.bags_used >= i)) { ingred.amount = d.bags_used.ToString();//Convert.ToString(Convert.ToInt32(d.totalBagsForRecipe / this.txtBatches.Value)); weight.amount = Math.Ceiling(Convert.ToDecimal(d.bags_used)).ToString();//Convert.ToString(Convert.ToInt32(d.totalWeightForRecipe / this.txtBatches.Value)); //rawMixBatch.amount = d.bags_used;// d.totalBagsForRecipe / this.txtBatches.Value; } } break; default: if (i != this.txtBatches.Value) { if ((d.bags_used > this.txtBatches.Value) || (d.bags_used >= i)) { ingred.amount = Convert.ToString(Convert.ToInt32(d.bags_used / this.txtBatches.Value)); weight.amount = Convert.ToString(Convert.ToInt32(d.bags_used / this.txtBatches.Value)); //rawMixBatch.amount = d.bags_used / this.txtBatches.Value; } } break; } rawMixBatch.batch_number = i; ingred.ingredient = d.ingredient; ingred.batch = i + 1; ingredientList.Add(ingred); listForDB.Add(rawMixBatch); intBatchAmount += Convert.ToInt32(weight.amount); } if (i + 1 == this.txtBatches.Value)//this is last batch. { //this is the last batch, it must show the holdback water string strDgvName = "dgv" + i.ToString(); IngredientForBatch ingred = new IngredientForBatch(); Raw_Mix_Batch rawMixBatch = new Raw_Mix_Batch(); IngredientForBatch weight = new IngredientForBatch(); rawMixBatch.ingredient = "Holdback Water"; ingred.amount = txtHoldBackWater.Value.ToString(); //rawMixBatch.amount = txtHoldBackWater.Value; weight.amount = Convert.ToString(txtHoldBackWater.Value); rawMixBatch.batch_number = i; ingred.ingredient = "Holdback Water"; ingred.batch = i + 1; ingredientList.Add(ingred); listForDB.Add(rawMixBatch); intBatchAmount += Convert.ToInt32(weight.amount); } //this is the total count that cannot exceed 4000litres IngredientForBatch totalVolumeForBatch = new IngredientForBatch(); totalVolumeForBatch.ingredient = "Total"; totalVolumeForBatch.amount = Convert.ToString(intBatchAmount); totalVolumeForBatch.batch = i + 1; ingredientList.Add(totalVolumeForBatch); addControlsToForm(ingredientList,i); i++; } //remove holdback water //foreach(Dry_Ingredient_Use_Temp d in list) //{ // if(d.ingredient == "Holdback Water") // { // list.Remove(d); // } //} this.calculateLastBatch(); }