Exemplo n.º 1
0
        public DataTable Insert(OrderDetailsDE OrderDetails)
        {
            dataAccess.Open();
            dataAccess.BeginTran();
            DataTable table;

            try
            {
                QueryParameter[] list = new QueryParameter[5];
                list[0] = new QueryParameter("OrderDetailsId", OrderDetails.OrderDetailsId, DbType.Int32);
                list[1] = new QueryParameter("OrderId", OrderDetails.OrderId, DbType.Int32);
                list[2] = new QueryParameter("ProductId", OrderDetails.ProductId, DbType.Int32);
                list[3] = new QueryParameter("Quantity", OrderDetails.Quantity, DbType.Int32);
                list[4] = new QueryParameter("TotalPrice", OrderDetails.TotalPrice, DbType.Decimal);
                string sql = "insert into OrderDetails values(@OrderId,@ProductId,@Quantity,@TotalPrice)";
                dataAccess.ExecuteNonQuery(sql, list);
                dataAccess.CommitTran();
                string sql1 = "SELECT dbo.OrderDetails.OrderDetailId, dbo.OrderDetails.OrderId, dbo.Product.ProductName, dbo.OrderDetails.Quantity, dbo.OrderDetails.TotalPrice FROM dbo.OrderDetails INNER JOIN dbo.Product ON dbo.OrderDetails.ProductId = dbo.Product.ProductId and OrderId='" + OrderDetails.OrderId + "'";
                table = dataAccess.GetTable(sql1);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                dataAccess.Close();
            }
            return(table);
        }
Exemplo n.º 2
0
        public bool Update(OrderDetailsDE OrderDetails)
        {
            bool result = true;

            dataAccess.Open();
            try
            {
                QueryParameter[] list = new QueryParameter[5];
                list[0] = new QueryParameter("OrderDetailId", OrderDetails.OrderDetailsId, DbType.Int32);
                list[1] = new QueryParameter("OrderId", OrderDetails.OrderId, DbType.Int32);
                list[2] = new QueryParameter("ProductId", OrderDetails.ProductId, DbType.Int32);
                list[3] = new QueryParameter("Quantity", OrderDetails.Quantity, DbType.Int32);
                list[4] = new QueryParameter("TotalPrice", OrderDetails.TotalPrice, DbType.Decimal);
                string sql = "update OrderDetails set ProductId=@ProductId, Quantity=@Quantity, TotalPrice=@TotalPrice where OrderId=@OrderId and OrderDetailId=@OrderDetailId";
                int    i   = dataAccess.ExecuteNonQuery(sql, list);
                if (i == 0)
                {
                    result = false;
                }
                else
                {
                    result = true;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                dataAccess.Close();
            }
            return(result);
        }
Exemplo n.º 3
0
        public List <OrderDetailsDE> GetAllOrderDetails()
        {
            List <OrderDetailsDE> list = new List <OrderDetailsDE>();

            dataAccess.Open();
            try
            {
                string      sql    = "select * from OrderDetails";
                IDataReader reader = dataAccess.GetReader(sql);
                while (reader.Read())
                {
                    OrderDetailsDE OrderDetails = new OrderDetailsDE();
                    OrderDetails.OrderDetailsId = reader.GetInt32(0);
                    OrderDetails.OrderId        = reader.GetInt32(1);
                    //Product.ProductId = OrderDetails.ProductDE.ProductId;
                    //OrderDetails.ProductDE.ProductName = reader.GetString(2);
                    OrderDetails.Quantity   = reader.GetInt32(3);
                    OrderDetails.TotalPrice = reader.GetDecimal(4);
                    int productId = reader.GetInt32(2);
                    //OrderDetails.ProductDE.ProductId = reader.GetInt32(2);
                    //string sql1 = "select ProductName from Product where ProductId=" + productId;
                    //dataAccess.Open();
                    //SqlCommand cmd = new SqlCommand(sql1);
                    ProductDE product = GetById(productId);

                    //product.ProductName = cmd.ExecuteScalar().ToString();
                    //ProductDE Product = GetById(productId);
                    OrderDetails.ProductDE = product;
                    list.Add(OrderDetails);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                dataAccess.Close();
            }
            return(list);
        }