Ejemplo n.º 1
0
        public IBaseProps Create(IBaseProps p) // possibly might need to change to props to match origional parameter.
        {
            int          rowsAffected = 0;
            ProductProps props        = (ProductProps)p;


            DBCommand command = new DBCommand();

            command.CommandText = "usp_ProductCreate";
            command.CommandType = CommandType.StoredProcedure;
            command.Parameters.Add("@ProductID", SqlDbType.Int);
            command.Parameters.Add("@ProductCode", SqlDbType.Char);
            command.Parameters.Add("@Description", SqlDbType.VarChar);// these match the parameters int he stored procedure. name adreess etc
            command.Parameters.Add("@UnitPrice", SqlDbType.Money);
            command.Parameters.Add("@OnHandQuantity", SqlDbType.Int);

            // there were three statements here before, it did not include customerID ask about if it needs to be
            //added
            // assuming it would be redundant if it wasnt there before....
            command.Parameters[0].Direction             = ParameterDirection.Output;
            command.Parameters["@ProductCode"].Value    = props.ProductCode;
            command.Parameters["@Description"].Value    = props.Description;
            command.Parameters["@UnitPrice"].Value      = props.UnitPrice;
            command.Parameters["@OnHandQuantity"].Value = props.OnHandQuantity;

            try
            {
                rowsAffected = RunNonQueryProcedure(command);
                if (rowsAffected == 1)
                {
                    props.ID            = (int)command.Parameters[0].Value;
                    props.ConcurrencyID = 1;
                    return(props);
                }
                else
                {
                    throw new Exception("Unable to insert record. " + props.ToString());
                }
            }
            catch (Exception e)
            {
                // log this error
                throw;
            }
            finally
            {
                if (mConnection.State == ConnectionState.Open)
                {
                    mConnection.Close();
                }
            }
        }
        } //end of Retrieve()

        #endregion

        #region IWriteDB Members
        /// <summary>
        /// </summary>
        public IBaseProps Create(IBaseProps p)
        {
            //return p;
            int          rowsAffected = 0;
            ProductProps props        = (ProductProps)p;

            DBCommand command = new DBCommand();

            command.CommandText = "usp_ProductCreate";
            command.CommandType = CommandType.StoredProcedure;
            command.Parameters.Add("@ProductID", SqlDbType.Int);
            command.Parameters.Add("@ProductCode", SqlDbType.Char);
            command.Parameters.Add("@Description", SqlDbType.VarChar);
            command.Parameters.Add("@UnitPrice", SqlDbType.Money);
            command.Parameters.Add("@OnHandQuantity", SqlDbType.Int);
            command.Parameters.Add("@ConcurrencyID", SqlDbType.Int);
            command.Parameters[0].Direction = ParameterDirection.Output;
            //Should not add value for productID because of autonumber, right?
            command.Parameters["@ProductCode"].Value    = props.code;
            command.Parameters["@Description"].Value    = props.description;
            command.Parameters["@UnitPrice"].Value      = props.unitPrice;
            command.Parameters["@OnHandQuantity"].Value = props.onHandQty;
            command.Parameters["@ConcurrencyID"].Value  = props.concurrencyID; //This is hardcoded in the stored procedure

            try
            {
                rowsAffected = RunNonQueryProcedure(command);
                if (rowsAffected == 1)
                {
                    props.id            = (int)command.Parameters[0].Value;
                    props.concurrencyID = 1;
                    return(props);
                }
                else
                {
                    throw new Exception("Unable to insert record. " + props.ToString());
                }
            }
            catch (Exception e)
            {
                // log this error
                throw;
            }
            finally
            {
                if (mConnection.State == ConnectionState.Open)
                {
                    mConnection.Close();
                }
            }
        }
Ejemplo n.º 3
0
        public IBaseProps Create(IBaseProps p)
        {
            int          rowsAffected = 0;
            ProductProps props        = (ProductProps)p;

            DBCommand command = new DBCommand();

            command.CommandText = "usp_ProductCreate";
            command.CommandType = CommandType.StoredProcedure;
            command.Parameters.Add("@ProductID", SqlDbType.Int);
            command.Parameters.Add("@ProductCode", SqlDbType.Char);
            command.Parameters.Add("@Description", SqlDbType.NVarChar);
            command.Parameters.Add("@OnHandQuantity", SqlDbType.Int);
            command.Parameters.Add("@UnitPrice", SqlDbType.Money);
            //Attenetion
            command.Parameters[0].Direction             = ParameterDirection.Output;
            command.Parameters["@ProductCode"].Value    = props.code;
            command.Parameters["@Description"].Value    = props.description;
            command.Parameters["@OnHandQuantity"].Value = props.quantity;
            command.Parameters["@UnitPrice"].Value      = props.price;

            try
            {
                rowsAffected = RunNonQueryProcedure(command);
                if (rowsAffected == 1)
                {
                    props.ID            = (int)command.Parameters[0].Value;
                    props.ConcurrencyID = 1;
                    return(props);
                }
                else
                {
                    throw new Exception("Unable to insert record. " + props.ToString());
                }
            }
            catch (Exception e)
            {
                // log this error
                throw;
            }
            finally
            {
                if (mConnection.State == ConnectionState.Open)
                {
                    mConnection.Close();
                }
            }
        }