Beispiel #1
0
        public static bool Update(ItemGroup itemGroup)
        {
            Int32         rowsAffected = 0;
            SqlConnection cn           = GetConnection();

            using (SqlCommand sqlCmd = cn.CreateCommand())
            {
                sqlCmd.CommandText = "UPDATE ItemGroup SET ItemGroupSourceItemId=@ItemGroupSourceItemId,ItemGroupTargetItemId=@ItemGroupTargetItemId,ItemGroupTargetItemQuantity=@ItemGroupTargetItemQuantity WHERE ItemGroupId=@ItemGroupId";

                BuildSqlParameter(sqlCmd, "@ItemGroupId", SqlDbType.Int, itemGroup.Id);
                BuildSqlParameter(sqlCmd, "@ItemGroupSourceItemId", SqlDbType.Int, itemGroup.SourceItemId);
                BuildSqlParameter(sqlCmd, "@ItemGroupTargetItemId", SqlDbType.Int, itemGroup.TargetItemId);
                BuildSqlParameter(sqlCmd, "@ItemGroupTargetItemQuantity", SqlDbType.Int, itemGroup.TargetItemQuantity);

                rowsAffected = sqlCmd.ExecuteNonQuery();
            }
            FinishedWithConnection(cn);
            return(rowsAffected != 0);
        }
Beispiel #2
0
        public static ItemGroup Get(int itemGroupId)
        {
            ItemGroup result = null;

            SqlConnection cn = GetConnection();

            using (SqlCommand cmd = new SqlCommand("SELECT * FROM ItemGroup WHERE ItemGroupId=" + itemGroupId, cn))
            {
                using (SqlDataReader rdr = cmd.ExecuteReader())
                {
                    if (rdr.Read())
                    {
                        result = BuildItemGroup(rdr);
                    }
                }
            }
            FinishedWithConnection(cn);
            return(result);
        }
Beispiel #3
0
        public static ItemGroup Add(int sourceItemId, int targetItemId, int targetItemQuantity)
        {
            ItemGroup     result = null;
            SqlConnection cn     = GetConnection();

            using (SqlCommand sqlCmd = new SqlCommand("AddItemGroup", cn))
            {
                sqlCmd.CommandType = CommandType.StoredProcedure;
                BuildSqlParameter(sqlCmd, "@ItemGroupSourceItemId", SqlDbType.Int, sourceItemId);
                BuildSqlParameter(sqlCmd, "@ItemGroupTargetItemId", SqlDbType.Int, targetItemId);
                BuildSqlParameter(sqlCmd, "@ItemGroupTargetItemQuantity", SqlDbType.Int, targetItemQuantity);
                BuildSqlParameter(sqlCmd, "@ItemGroupId", SqlDbType.Int, ParameterDirection.ReturnValue);
                if (sqlCmd.ExecuteNonQuery() > 0)
                {
                    result = new ItemGroup(Convert.ToInt32(sqlCmd.Parameters["@ItemGroupId"].Value),
                                           sourceItemId, targetItemId, targetItemQuantity);
                }
            }
            FinishedWithConnection(cn);
            return(result);
        }