Пример #1
0
        public static ItemIngredientAdjustment Add(int employeeId, int itemId,
                                                   int ingredientId, double?oldAmount, double?newAmount,
                                                   MeasurementUnit measurementUnit, DateTime?when = null)
        {
            ItemIngredientAdjustment result = null;
            SqlConnection            cn     = GetConnection();

            if (when == null)
            {
                when = DateTime.Now;
            }

            string cmd = "AddItemIngredientAdjustment";

            using (SqlCommand sqlCmd = new SqlCommand(cmd, cn))
            {
                sqlCmd.CommandType = CommandType.StoredProcedure;
                BuildSqlParameter(sqlCmd, "@ItemIngredientAdjustmentItemId", SqlDbType.Int, itemId);
                BuildSqlParameter(sqlCmd, "@ItemIngredientAdjustmentIngredientId", SqlDbType.Int, ingredientId);
                BuildSqlParameter(sqlCmd, "@ItemIngredientAdjustmentEmployeeId", SqlDbType.Int, employeeId);
                BuildSqlParameter(sqlCmd, "@ItemIngredientAdjustmentOriginalValue", SqlDbType.Float, oldAmount);
                BuildSqlParameter(sqlCmd, "@ItemIngredientAdjustmentNewValue", SqlDbType.Float, newAmount);
                BuildSqlParameter(sqlCmd, "@ItemIngredientAdjustmentMeasurementUnit", SqlDbType.SmallInt, measurementUnit);
                BuildSqlParameter(sqlCmd, "@ItemIngredientAdjustmentWhen", SqlDbType.DateTime, when.Value);
                BuildSqlParameter(sqlCmd, "@ItemIngredientAdjustmentId", SqlDbType.Int, ParameterDirection.ReturnValue);

                if (sqlCmd.ExecuteNonQuery() > 0)
                {
                    result = new ItemIngredientAdjustment(Convert.ToInt32(sqlCmd.Parameters["@ItemIngredientAdjustmentId"].Value),
                                                          employeeId, itemId, ingredientId, oldAmount, newAmount, measurementUnit, when.Value);
                }
            }
            FinishedWithConnection(cn);
            return(result);
        }
Пример #2
0
        public static ItemIngredientAdjustment Get(int id)
        {
            ItemIngredientAdjustment result = null;
            SqlConnection            cn     = GetConnection();

            result = Get(cn, id);
            FinishedWithConnection(cn);
            return(result);
        }
Пример #3
0
        private static ItemIngredientAdjustment Get(SqlConnection cn, int id)
        {
            ItemIngredientAdjustment result = null;

            using (SqlCommand cmd = new SqlCommand("SELECT * FROM ItemIngredientAdjustment WHERE ItemIngredientAdjustmentId=" + id, cn))
            {
                using (SqlDataReader rdr = cmd.ExecuteReader())
                {
                    if (rdr.Read())
                    {
                        result = BuildItemIngredientAdjustment(rdr);
                    }
                }
            }
            return(result);
        }