Esempio n. 1
0
        public void Update()
        {
            int test = 0;
            List <ProductsProps> temp = (List <ProductsProps>)db.RetrieveAll(test.GetType());
            int           i           = 0;
            ProductsProps p;
            bool          found = false;

            for (; i < temp.Count(); i++)
            {
                if (temp[i].code == "TEST")
                {
                    found = true;
                    break;
                }
            }
            if (found)
            {
                p      = (ProductsProps)db.Retrieve(temp[i].ID);
                p.code = "NOTTEST";

                db.Update(p);

                ProductsProps x = (ProductsProps)db.Retrieve(temp[i].ID);
            }
            else
            {
                Assert.Fail();
            }
            //   Assert.True(x.code == p.code);
            //   x.code = "TEST";
            //   db.Update(x);
        }
Esempio n. 2
0
        public void TestClone()
        {
            ProductsProps newP = (ProductsProps)p.Clone();

            Assert.AreEqual(newP.ID, p.ID);
            Assert.AreEqual(newP.description, p.description);
            Assert.AreEqual(newP.unitPrice, p.unitPrice);
            Assert.AreEqual(newP.quantity, p.quantity);
            Assert.AreEqual(newP.code, p.code);
        }
Esempio n. 3
0
        public void TestSetState()
        {
            ProductsProps newP = new ProductsProps();
            string        xml  = p.GetState();

            newP.SetState(xml);
            Assert.AreEqual(newP.ID, p.ID);
            Assert.AreEqual(newP.description, p.description);
            Assert.AreEqual(newP.unitPrice, p.unitPrice);
            Assert.AreEqual(newP.quantity, p.quantity);
            Assert.AreEqual(newP.code, p.code);
        }
Esempio n. 4
0
        public void Create()
        {
            ProductsProps p = new ProductsProps();

            p.code        = "TEST";
            p.description = "Test Product";
            p.quantity    = 1;
            p.unitPrice   = 10.50m;

            db.Create(p);
            ProductsProps x = (ProductsProps)db.Retrieve(p.ID);

            Assert.AreEqual(x.description, p.description);
        }
Esempio n. 5
0
        public IBaseProps Create(IBaseProps p)
        {
            int           rowsAffected = 0;
            ProductsProps props        = (ProductsProps)p;

            DBCommand command = new DBCommand();

            command.CommandText = "usp_ProductsCreate";
            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[0].Direction             = ParameterDirection.Output;
            command.Parameters["@ProductCode"].Value    = props.code;
            command.Parameters["@Description"].Value    = props.description;
            command.Parameters["@UnitPrice"].Value      = props.unitPrice;
            command.Parameters["@OnHandQuantity"].Value = props.quantity;
            //props.ID = (int) command.Parameters["@ProductID"].Value;

            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();
                }
            }
        }
Esempio n. 6
0
        public bool Update(IBaseProps p)
        {
            int           rowsAffected = 0;
            ProductsProps props        = (ProductsProps)p;

            DBCommand command = new DBCommand();

            command.CommandText = "usp_ProductsUpdate";
            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("@UnitPrice", SqlDbType.Money);
            command.Parameters.Add("@OnHandQuanity", SqlDbType.Int);
            command.Parameters.Add("@ConcurrencyID", SqlDbType.Int);
            command.Parameters["@ProductID"].Value     = props.ID;
            command.Parameters["@ProductCode"].Value   = props.code;
            command.Parameters["@UnitPrice"].Value     = props.unitPrice;
            command.Parameters["@OnHandQuanity"].Value = props.quantity;
            command.Parameters["@Description"].Value   = props.description;
            command.Parameters["@ConcurrencyID"].Value = props.ConcurrencyID;

            try
            {
                rowsAffected = RunNonQueryProcedure(command);
                if (rowsAffected == 1)
                {
                    props.ConcurrencyID++;
                    return(true);
                }
                else
                {
                    string message = "Record cannot be updated. It has been edited by another user.";
                    throw new Exception(message);
                }
            }
            catch (Exception e)
            {
                // log this exception
                throw;
            }
            finally
            {
                if (mConnection.State == ConnectionState.Open)
                {
                    mConnection.Close();
                }
            }
        }
Esempio n. 7
0
        protected override void SetUp()
        {
            mProps    = new ProductsProps();
            mOldProps = new ProductsProps();

            if (this.mConnectionString == "")
            {
                mdbReadable  = new ProductsDB();
                mdbWriteable = new ProductsDB();
            }

            else
            {
                mdbReadable  = new ProductsDB(this.mConnectionString);
                mdbWriteable = new ProductsDB(this.mConnectionString);
            }
        }
Esempio n. 8
0
        public IBaseProps Retrieve(object key)
        {
            DBDataReader  data    = null;
            ProductsProps props   = new ProductsProps();
            DBCommand     command = new DBCommand();

            command.CommandText = "usp_ProductsSelect";
            command.CommandType = CommandType.StoredProcedure;
            command.Parameters.Add("@ProductID", SqlDbType.Int);
            command.Parameters["@ProductID"].Value = (Int32)key;

            try
            {
                data = RunProcedure(command);
                if (!data.IsClosed)
                {
                    if (data.Read())
                    {
                        props.SetState(data);
                    }
                    else
                    {
                        throw new Exception("Record does not exist in the database.");
                    }
                }
                return(props);
            }
            catch (Exception e)
            {
                // log this exception
                throw;
            }
            finally
            {
                if (data != null)
                {
                    if (!data.IsClosed)
                    {
                        data.Close();
                    }
                }
            }
        }
Esempio n. 9
0
        public object RetrieveAll(Type type)
        {
            List <ProductsProps> results = new List <ProductsProps>();
            DBDataReader         data    = null;
            ProductsProps        props   = new ProductsProps();
            DBCommand            command = new DBCommand();

            command.CommandText = "usp_ProductsSelectAll";
            command.CommandType = CommandType.StoredProcedure;


            try
            {
                data = RunProcedure(command);
                if (!data.IsClosed)
                {
                    while (data.Read())
                    {
                        props = new ProductsProps();
                        props.SetState(data);
                        results.Add(props);
                    }
                }
                return(results);
            }
            catch (Exception e)
            {
                // log this exception
                throw;
            }
            finally
            {
                if (data != null)
                {
                    if (!data.IsClosed)
                    {
                        data.Close();
                    }
                }
            }
        }
Esempio n. 10
0
        public bool Delete(IBaseProps props)
        {
            ProductsProps x    = (ProductsProps)props;
            ProductsProps temp = (ProductsProps)Retrieve(x.ID);

            int           rowsAffected = 0;
            ProductsProps p            = (ProductsProps)props;
            DBCommand     command      = new DBCommand();

            command.CommandText = "usp_ProductsDelete";
            command.CommandType = CommandType.StoredProcedure;
            command.Parameters.Add("@ProductID", SqlDbType.Int);
            command.Parameters["@ProductID"].Value = p.ID;
            command.Parameters.Add("@ConcurrencyID", SqlDbType.Int);
            command.Parameters["@ConcurrencyID"].Value = temp.ConcurrencyID;
            try
            {
                rowsAffected = RunNonQueryProcedure(command);
                if (rowsAffected != 1)
                {
                    string message = "Record was not deleted. Perhaps the key you specified does not exist.";
                    throw new Exception(message);
                }
                return(true);
            }
            catch (Exception e)
            {
                // log this error
                throw;
            }
            finally
            {
                if (mConnection.State == ConnectionState.Open)
                {
                    mConnection.Close();
                }
            }
            return(rowsAffected != 0);
        }
Esempio n. 11
0
        public void Retreive()
        {
            ProductsProps p = (ProductsProps)db.Retrieve(8);

            Assert.AreEqual("DB2R", p.code);
        }