/// <summary> /// Add a new entry to the ItemOptionSet table /// </summary> public static ItemOptionSet Add(string optionSetName, int min, int free, int max, double excessUnitCost, bool isPizzaStyle) { ItemOptionSet result = null; bool isDiscontinued = false; SqlConnection cn = GetConnection(); using (SqlCommand sqlCmd = new SqlCommand("AddItemOptionSet", cn)) { sqlCmd.CommandType = CommandType.StoredProcedure; BuildSqlParameter(sqlCmd, "@ItemOptionSetName", SqlDbType.Text, optionSetName); BuildSqlParameter(sqlCmd, "@ItemOptionSetNumMin", SqlDbType.TinyInt, min); BuildSqlParameter(sqlCmd, "@ItemOptionSetNumFree", SqlDbType.TinyInt, free); BuildSqlParameter(sqlCmd, "@ItemOptionSetNumMax", SqlDbType.TinyInt, max); BuildSqlParameter(sqlCmd, "@ItemOptionSetExcessUnitCost", SqlDbType.Float, excessUnitCost); BuildSqlParameter(sqlCmd, "@ItemOptionSetPizzaStyle", SqlDbType.Bit, isPizzaStyle); BuildSqlParameter(sqlCmd, "@ItemOptionSetIsDiscontinued", SqlDbType.Bit, isDiscontinued); BuildSqlParameter(sqlCmd, "@ItemOptionSetId", SqlDbType.Int, ParameterDirection.ReturnValue); if (sqlCmd.ExecuteNonQuery() > 0) { result = new ItemOptionSet(Convert.ToInt32(sqlCmd.Parameters["@ItemOptionSetId"].Value), optionSetName, min, free, max, excessUnitCost, isPizzaStyle, isDiscontinued); } } FinishedWithConnection(cn); return(result); }
/// <summary> /// Get an entry from the ItemOptionSet table, using the option set's name /// </summary> public static ItemOptionSet Get(string optionSetName) { ItemOptionSet result = null; SqlConnection cn = GetConnection(); result = Get(cn, optionSetName); FinishedWithConnection(cn); return(result); }
/// <summary> /// Get an entry from the ItemOptionSet table /// </summary> public static ItemOptionSet Get(int optionSetId) { ItemOptionSet result = null; SqlConnection cn = GetConnection(); result = Get(cn, optionSetId); FinishedWithConnection(cn); return(result); }
/// <summary> /// Update an entry in the ItemOptionSet table /// </summary> public static bool Update(ItemOptionSet itemOptionSet) { bool result = false; SqlConnection cn = GetConnection(); result = Update(cn, itemOptionSet); FinishedWithConnection(cn); return(result); }
private static ItemOptionSet Get(SqlConnection cn, int optionSetId) { ItemOptionSet result = null; using (SqlCommand cmd = new SqlCommand("SELECT * FROM ItemOptionSet WHERE ItemOptionSetId=" + optionSetId, cn)) { using (SqlDataReader rdr = cmd.ExecuteReader()) { while (rdr.Read()) { result = BuildItemOptionSet(rdr); break; } } } return(result); }
private static bool Update(SqlConnection cn, ItemOptionSet itemOptionSet) { Int32 rowsAffected = 0; using (SqlCommand sqlCmd = cn.CreateCommand()) { sqlCmd.CommandText = "UPDATE ItemOptionSet SET ItemOptionSetName=@ItemOptionSetName,ItemOptionSetNumMin=@ItemOptionSetNumMin,ItemOptionSetNumFree=@ItemOptionSetNumFree,ItemOptionSetNumMax=@ItemOptionSetNumMax,ItemOptionSetExcessUnitCost=@ItemOptionSetExcessUnitCost,ItemOptionSetPizzaStyle=@ItemOptionSetPizzaStyle,ItemOptionSetIsDiscontinued=@ItemOptionSetIsDiscontinued WHERE ItemOptionSetId=@ItemOptionSetId"; BuildSqlParameter(sqlCmd, "@ItemOptionSetId", SqlDbType.Int, itemOptionSet.Id); BuildSqlParameter(sqlCmd, "@ItemOptionSetName", SqlDbType.Text, itemOptionSet.Name); BuildSqlParameter(sqlCmd, "@ItemOptionSetNumMin", SqlDbType.TinyInt, itemOptionSet.SelectedMinimum); BuildSqlParameter(sqlCmd, "@ItemOptionSetNumFree", SqlDbType.TinyInt, itemOptionSet.SelectedFree); BuildSqlParameter(sqlCmd, "@ItemOptionSetNumMax", SqlDbType.TinyInt, itemOptionSet.SelectedMaximum); BuildSqlParameter(sqlCmd, "@ItemOptionSetExcessUnitCost", SqlDbType.Float, itemOptionSet.ExcessUnitCost); BuildSqlParameter(sqlCmd, "@ItemOptionSetPizzaStyle", SqlDbType.Bit, itemOptionSet.IsPizzaStyle); BuildSqlParameter(sqlCmd, "@ItemOptionSetIsDiscontinued", SqlDbType.Bit, itemOptionSet.IsDiscontinued); rowsAffected = sqlCmd.ExecuteNonQuery(); } return(rowsAffected != 0); }
private static ItemOptionSet Get(SqlConnection cn, string optionSetName) { ItemOptionSet result = null; using (SqlCommand cmd = new SqlCommand("SELECT * FROM ItemOptionSet WHERE ItemOptionSetIsDiscontinued=0", cn)) { using (SqlDataReader rdr = cmd.ExecuteReader()) { while (rdr.Read()) { //result = new Category(); string lineName = rdr[1].ToString(); if (optionSetName == lineName) { result = BuildItemOptionSet(rdr); break; } } } } return(result); }
public bool Update() { return(ItemOptionSet.Update(this)); }