public static Product GetProduct(int productId) { // get a configured DbCommand object DbCommand comm = GenericDataAccess.CreateCommand(); // set the stored procedure name comm.CommandText = "SELECT Product.productName,Product.productShortDesc,Product.productPrice,Product.productImagePath,Product.productQty,Country.countryName,Country.countryId,Vendor.vendorName,Vendor.vendorId,Product.productId,Product.productRating FROM dbo.Product INNER JOIN dbo.Country ON Product.productCountryId=Country.countryId INNER JOIN dbo.Vendor ON Product.vendorId=Vendor.vendorId where dbo.Product.productId='" + productId + "';"; comm.CommandType = CommandType.Text; // execute the stored procedure and return the results DataTable table=GenericDataAccess.ExecuteSelectCommand(comm); DbDataReader reader = table.CreateDataReader(); Product product = new Product(); while (reader.Read()) { product.setProductId(reader.GetInt32(9)); product.setproductName(reader.GetString(0)); product.setProductShortDesc(reader.GetString(1)); product.setProductPrice(reader.GetDouble(2)); product.setProductImagePath(reader.GetString(3)); product.setProductQuantity(reader.GetInt32(4)); product.setProductCountryId(reader.GetInt32(6)); product.setproductVendorName(reader.GetString(7)); product.setProductVendorId(reader.GetInt32(8)); product.setProductRating(reader.GetInt32(10)); } return product; }
public static Product[] GetCart(int customerId) { // get a configured DbCommand object DbCommand comm = GenericDataAccess.CreateCommand(); // set the stored procedure name comm.CommandText = "SELECT ShoppingCart.customerId,ShoppingCart.productId,ShoppingCart.quantity,Product.productName,Product.productPrice,Product.productImagePath,Product.productCountryId,Product.categoryId,Product.vendorId,Product.productRating,Product.productShortDesc,Product.productLongDesc,Vendor.vendorName FROM dbo.ShoppingCart INNER JOIN dbo.Product ON ShoppingCart.productId=Product.productId INNER JOIN dbo.Vendor ON ShoppingCart.vendorId=Vendor.vendorId WHERE ShoppingCart.customerId="+customerId+";"; comm.CommandType = CommandType.Text; // execute the stored procedure and return the results comm.Connection.Open(); DbDataReader reader = comm.ExecuteReader(); Product[] product = new Product[20]; int i = 0; while (reader.Read()) { Product product1 = new Product(); product1.setProductId(reader.GetInt32(1)); product1.setproductName(reader.GetString(3)); product1.setProductShortDesc(reader.GetString(10)); product1.setProductPrice(reader.GetDouble(4)); product1.setProductImagePath(reader.GetString(5)); product1.setProductQuantity(reader.GetInt32(2)); product1.setProductCountryId(reader.GetInt32(6)); product1.setProductCategoryId(reader.GetInt32(7)); product1.setProductLongDesc(reader.GetString(11)); product1.setproductVendorName(reader.GetString(12)); product1.setProductVendorId(reader.GetInt32(8)); product1.setProductRating(reader.GetInt32(9)); product1.addProduct(product1, product); } return product; }
protected void Page_Load(object sender, EventArgs e) { if (Session["user"] == null) { Session["prevpage"] = "ShoppingCart.aspx"; Response.Redirect("loginpage.aspx"); } DbCommand comm = GenericDataAccess.CreateCommand(); // set the stored procedure name int customerId = (int)Session["userid"]; comm.CommandText = "SELECT ShoppingCart.customerId,ShoppingCart.productId,ShoppingCart.quantity,Product.productName,Product.productPrice,Product.productImagePath,Product.productCountryId,Product.categoryId,Product.vendorId,Product.productRating,Product.productShortDesc,Product.productLongDesc,Vendor.vendorName FROM dbo.ShoppingCart INNER JOIN dbo.Product ON ShoppingCart.productId=Product.productId INNER JOIN dbo.Vendor ON ShoppingCart.vendorId=Vendor.vendorId WHERE ShoppingCart.customerId="+customerId+";"; comm.CommandType = CommandType.Text; DataTable table = GenericDataAccess.ExecuteSelectCommand(comm); DbDataReader reader = table.CreateDataReader(); string rows = null; int i = 0; Product[] productCart = new Product[20]; while (reader.Read()) { Product product = new Product(); product.setProductId(reader.GetInt32(1)); int custid = reader.GetInt32(0); product.setProductQuantity(reader.GetInt32(2)); product.setproductName(reader.GetString(3)); product.setProductPrice(reader.GetDouble(4)); product.setProductImagePath(reader.GetString(5)); product.setProductCountryId(reader.GetInt32(6)); product.setProductCategoryId(reader.GetInt32(7)); product.setProductVendorId(reader.GetInt32(8)); product.setProductRating(reader.GetInt32(9)); product.setProductShortDesc(reader.GetString(10)); product.setProductLongDesc(reader.GetString(11)); product.setproductVendorName(reader.GetString(12)); product.addProduct(product, productCart); rows += "<div class='prodtable'><input type=radio id=cart runat=server name=selproduct value=" + product.getProductId() + " /><img src=" + product.getProductImagePath() + " height=100 width=100 /><br /><b>Name: </b>" + product.getProductName() + " <br /><b>Vendor: </b>" + product.getProductVendorName() + " <br /><b>Quantity: </b>" + product.getProductQuantity() + "<br /><b>Price: </b>" + product.getProductPrice() + "<br /><br /></div>"; } if (productCart[0] != null) { rows += "<p style='margin-top:50px;font-size:60px;'>Total Price= " + productCart[0].calcTotalPrice(productCart); } /* <table width="80%" style="border: thin solid #000000; top:20%;"> <% Product[] productCart=(Product[])Session["productCart"]; %>> <% for (int i = 0; i < productCart.Length; i++) { if (productCart[i] != null) { %> <tr> <td> <img= id="img1" height="412" width="473" src="<%=productCart[i].getProductImagePath()%>"> </td> <td class="style1"> <ul> <li>Product Name: <%=productCart[i].getProductName()%></li> <li>Quantity:<%=productCart[i].getProductQuantity()%></li> <li>Rating:<%=productCart[i].getProductRating()%> </li> <li> </li> </ul> </td> </tr> <%} } %> TotalPrice= <%=productCart[0].calcTotalPrice(productCart) %> </table> */ if (Session["productCart"] == null) { Session["productCart"] = productCart; } tableproducts.InnerHtml = rows; }