/// <summary> /// Update an entry in the ItemIngredient table /// </summary> public static bool Update(ItemIngredient itemIngredient) { bool result = false; SqlConnection cn = GetConnection(); result = Update(cn, itemIngredient); FinishedWithConnection(cn); return(result); }
/// <summary> /// Get an entry from the ItemIngredient table /// </summary> public static ItemIngredient Get(int id) { ItemIngredient result = null; SqlConnection cn = GetConnection(); result = Get(cn, id); FinishedWithConnection(cn); return(result); }
/// <summary> /// Gets the item's ingredient cost (for a single item) /// </summary> /// <returns></returns> public double GetCostOfIngredients() { double result = 0; foreach (ItemIngredient itemIngredient in ItemIngredient.GetAll(Id)) { Ingredient ingredient = Ingredient.Get(itemIngredient.IngredientId); double amountInInventoryUnits = UnitConversion.Convert(itemIngredient.Amount, itemIngredient.MeasurementUnit, ingredient.MeasurementUnit); result += (amountInInventoryUnits * ingredient.GetActualCostPerUnit()); } return(result); }
private static ItemIngredient Get(SqlConnection cn, int id) { ItemIngredient result = null; using (SqlCommand cmd = new SqlCommand("SELECT * FROM ItemIngredient WHERE ItemIngredientId=" + id, cn)) { using (SqlDataReader rdr = cmd.ExecuteReader()) { if (rdr.Read()) { result = BuildItemIngredient(rdr); } } } return(result); }
/// <summary> /// Delete an entry from the ItemIngredient table /// </summary> public static bool Delete(int id) { Int32 rowsAffected = 0; SqlConnection cn = GetConnection(); ItemIngredient itemIngredient = Get(cn, id); if (itemIngredient != null) { using (SqlCommand sqlCmd = cn.CreateCommand()) { sqlCmd.CommandText = "DELETE FROM ItemIngredient WHERE ItemIngredientId=" + id; rowsAffected = sqlCmd.ExecuteNonQuery(); } } FinishedWithConnection(cn); return(rowsAffected != 0); }
private static bool Update(SqlConnection cn, ItemIngredient itemIngredient) { Int32 rowsAffected = 0; using (SqlCommand sqlCmd = cn.CreateCommand()) { sqlCmd.CommandText = "UPDATE ItemIngredient SET ItemIngredientItemId=@ItemIngredientItemId,ItemIngredientIngredientId=@ItemIngredientIngredientId,ItemIngredientAmount=@ItemIngredientAmount,ItemIngredientMeasurementUnit=@ItemIngredientMeasurementUnit WHERE ItemIngredientId=@ItemIngredientId"; BuildSqlParameter(sqlCmd, "@ItemIngredientId", SqlDbType.Int, itemIngredient.Id); BuildSqlParameter(sqlCmd, "@ItemIngredientItemId", SqlDbType.Int, itemIngredient.ItemId); BuildSqlParameter(sqlCmd, "@ItemIngredientIngredientId", SqlDbType.Int, itemIngredient.IngredientId); BuildSqlParameter(sqlCmd, "@ItemIngredientAmount", SqlDbType.Float, itemIngredient.Amount); BuildSqlParameter(sqlCmd, "@ItemIngredientMeasurementUnit", SqlDbType.SmallInt, (int)itemIngredient.MeasurementUnit); rowsAffected = sqlCmd.ExecuteNonQuery(); } return(rowsAffected != 0); }
/// <summary> /// Checks to see if there is enough Ingredients to make this Item /// </summary> /// <param name="quantity">The quantity of this item to be made</param> /// <returns></returns> public bool HaveIngredientsToMake(int quantity) { if (quantity <= 0) { throw new ArgumentOutOfRangeException("Quantity must be a positive non-zero integer"); } foreach (ItemIngredient itemIngredient in ItemIngredient.GetAll(Id)) { Ingredient ingredient = Ingredient.Get(itemIngredient.IngredientId); double amountInInventoryUnits = UnitConversion.Convert(itemIngredient.Amount, itemIngredient.MeasurementUnit, ingredient.MeasurementUnit); if (ingredient.InventoryAmount < (amountInInventoryUnits * quantity)) { return(false); } } return(true); }
public static void AdjustInventory(TicketItem ticketItem, bool increase, int?difference = null) { int quantity = (difference != null ? difference.Value : (ticketItem.QuantityPending != null ? ticketItem.QuantityPending.Value : ticketItem.Quantity)); foreach (ItemIngredient itemIngredient in ItemIngredient.GetAll(ticketItem.ItemId)) { PosModelHelper.AdjustInventoryByIngredient(itemIngredient.IngredientId, increase, itemIngredient.Amount * quantity, itemIngredient.MeasurementUnit); } foreach (TicketItemOption ticketItemOption in TicketItemOption.GetAll(ticketItem.PrimaryKey)) { TicketItemOption.AdjustInventory(ticketItemOption, quantity, increase); } }
/// <summary> /// Add a new entry to the ItemIngredient table /// </summary> public static ItemIngredient Add(int itemId, int ingredientId, double amount, MeasurementUnit measurementUnit) { ItemIngredient result = null; SqlConnection cn = GetConnection(); using (SqlCommand sqlCmd = new SqlCommand("AddItemIngredient", cn)) { sqlCmd.CommandType = CommandType.StoredProcedure; BuildSqlParameter(sqlCmd, "@ItemIngredientItemId", SqlDbType.Int, itemId); BuildSqlParameter(sqlCmd, "@ItemIngredientIngredientId", SqlDbType.Int, ingredientId); BuildSqlParameter(sqlCmd, "@ItemIngredientAmount", SqlDbType.Float, amount); BuildSqlParameter(sqlCmd, "@ItemIngredientMeasurementUnit", SqlDbType.SmallInt, measurementUnit); BuildSqlParameter(sqlCmd, "@ItemIngredientId", SqlDbType.Int, ParameterDirection.ReturnValue); if (sqlCmd.ExecuteNonQuery() > 0) { result = new ItemIngredient(Convert.ToInt32(sqlCmd.Parameters["@ItemIngredientId"].Value), itemId, ingredientId, amount, measurementUnit); } } FinishedWithConnection(cn); return(result); }
public bool Update() { return(ItemIngredient.Update(this)); }