private void btnSubmit_Click(object sender, EventArgs e) { if(settingHold) { string strReasonForHold = this.txtReasonForHold.Text.ToString(); if (!string.IsNullOrEmpty(strReasonForHold)) { hold.reason_for_hold = this.txtReasonForHold.Text.ToString(); try { ingredient_hold_log record = new ingredient_hold_log(); record.reason_for_hold = strReasonForHold; record.lot_code = dryIngredient.lot_code; record.ingredient = dryIngredient.ingredient; record.on_hold = true; record.date_set_hold = DateTime.Now; this.ctx.ingredient_hold_log.Add(record); ctx.SaveChanges(); MessageBox.Show("The ingredient has been put on hold"); this.Close(); } catch (Exception ex) { } } else { MessageBox.Show("Please provide a reason for putting the ingredient on hold"); } } if (!settingHold) { string strReasonForUnHold = this.txtReasonUnHold.Text.ToString(); if(!String.IsNullOrEmpty(strReasonForUnHold)) { hold.date_unset_hold = DateTime.Now; hold.on_hold = false; hold.reason_for_remove_hold = strReasonForUnHold; } try { ctx.ingredient_hold_log.Attach(hold); ctx.Entry(hold).State = EntityState.Modified; ctx.SaveChanges(); MessageBox.Show("Removed Hold from this ingredient"); this.Close(); } catch (Exception ex) { Console.WriteLine(ex); } } }
private void addIngredient(Dry_Ingredient ingredient) { //this is an afterthought that all ingredients must be received ON HOLD ctx.Dry_Ingredient.Add(ingredient); if (ingredient.ingredient != "Cream") { ingredient_hold_log hold = new ingredient_hold_log(); hold.lot_code = ingredient.lot_code; hold.ingredient = ingredient.ingredient; hold.reason_for_hold = "Initial Receiving Of Ingredient"; hold.date_set_hold = DateTime.Now; hold.on_hold = true; ingredient.on_hold = true; ctx.ingredient_hold_log.Add(hold); } try { ctx.SaveChanges(); StringBuilder sb = new StringBuilder(); sb.Append(ingredient.number_of_bags.ToString()); if(ingredient.ingredient.ToString().Equals("Cream")) { sb.Append(" litres of "); } else { sb.Append(" Bags of "); } sb.Append(ingredient.ingredient.ToString()); sb.Append(" added to inventory"); MessageBox.Show(sb.ToString(),"Inventory Count Updated", MessageBoxButtons.OK, MessageBoxIcon.Information); this.clearSelections(); } catch (Exception ex) { MessageBox.Show("Could not save to the database. See log for details"); this.createLogFile(ex); } //dgvDryIngredient.DataSource = ctx.Dry_Ingredient.ToList(); //cmbLotCode.DataSource = ctx.Dry_Ingredient.Select(u => u.lot_code).ToList(); this.populateDryIngredientReceivingTable(); //this.loadLotCodesOnUsePage(); }
private void getHoldOnIngredient(Dry_Ingredient ingred) { List<ingredient_hold_log> list = null; List<ingredient_hold_log> listOfIngredientsOnHold = null; try { list = ctx.ingredient_hold_log.Where(o => o.lot_code == ingred.lot_code ).ToList(); } catch(Exception ex) { //somethingWentWrong } try { listOfIngredientsOnHold = ctx.ingredient_hold_log.Where(o => o.lot_code == ingred.lot_code && o.on_hold == true).ToList();// } catch (Exception ex) { //somethingWentWrong } if(listOfIngredientsOnHold.Count > 0) { //the ingredient is in this table. This means that it is being un-held if (listOfIngredientsOnHold.Count > 1) { //This should not happen. There should only be one reason at a time. } hold = listOfIngredientsOnHold.ElementAt(0); this.txtReasonForHold.Text = hold.reason_for_hold; this.txtReasonForHold.ReadOnly = true; settingHold = false; } else { hold = new ingredient_hold_log(); hold.lot_code = ingred.lot_code; hold.ingredient = ingred.ingredient; settingHold = true; } }