private void LoadProduct(int productId) { product = BLProduct.RetrieveFromDB(connectionString, productId); if (product == null) { throw new HttpException(404, $"Product.aspx?productId={productId} doesn't exist."); } productImage.Src = $"ImgHandler.ashx?productId={productId}"; productTitle.InnerText = product.Name; if (product.Discount > 0) { originalProductPrice.InnerText = "£" + product.Price; originalProductPrice.Visible = true; double newPrice = product.Price * (1 - product.Discount / 100); productPrice.Visible = false; discountProductPrice.Visible = true; discountProductPrice.InnerText = "£" + newPrice; } else { productPrice.InnerText = "£" + product.Price; } productDescription.InnerText = product.Description; if (product.TrailerUrl != null) { linkViewTrailer.Visible = true; linkViewTrailer.HRef = product.TrailerUrl; } }
private void ShowOrderProducts() { double vatTotal = 0; double sumTotal = 0; foreach (var cartProduct in order.CartProducts) { BLProduct product = BLProduct.RetrieveFromDB(connectionString, cartProduct.Id); TableCell titleCell = new TableCell { Text = product.Name }; TableCell priceCell = new TableCell { Text = "£" + product.Price * (1 - product.Discount / 100) }; TableCell amountCell = new TableCell { Text = cartProduct.Quantity.ToString() }; double sum = cartProduct.Quantity * product.Price * (1 - product.Discount / 100); sumTotal += sum; double vat = (product.VAT * sum / (100 + product.VAT)); vatTotal += vat; TableCell vatCell = new TableCell { Text = "£" + vat }; TableCell sumCell = new TableCell { Text = "£" + sum }; TableRow row = new TableRow(); row.Controls.Add(titleCell); row.Controls.Add(priceCell); row.Controls.Add(amountCell); row.Controls.Add(vatCell); row.Controls.Add(sumCell); productTable.Controls.Add(row); } TableCell titleFoot = new TableCell(); TableCell priceFoot = new TableCell(); TableCell amountFoot = new TableCell(); TableCell vatFoot = new TableCell { Text = "£" + vatTotal }; TableCell sumFoot = new TableCell { Text = "£" + sumTotal }; TableRow footRow = new TableRow(); footRow.Controls.Add(titleFoot); footRow.Controls.Add(priceFoot); footRow.Controls.Add(amountFoot); footRow.Controls.Add(vatFoot); footRow.Controls.Add(sumFoot); productTable.Controls.Add(footRow); }
private void FillTableCellsFromCartList() { totalCartPrice = 0; checkout_product_table.Controls.Clear(); TableHeaderRow headerRow = new TableHeaderRow(); TableCell headerImageCell = new TableCell(); TableCell headerTitleCell = new TableCell { Text = " Title " }; TableCell headerPriceCell = new TableCell { Text = " Price " }; TableCell headerQuantityCell = new TableCell { Text = " Quantity " }; TableCell headerStockStatusCell = new TableCell { Text = " Stock status " }; TableCell headerVATCell = new TableCell { Text = " VAT " }; TableCell headerTotalCell = new TableCell { Text = " Sum " }; headerRow.Controls.Add(headerImageCell); headerRow.Controls.Add(headerTitleCell); headerRow.Controls.Add(headerPriceCell); headerRow.Controls.Add(headerQuantityCell); headerRow.Controls.Add(headerStockStatusCell); headerRow.Controls.Add(headerVATCell); headerRow.Controls.Add(headerTotalCell); checkout_product_table.Controls.Add(headerRow); foreach (var cartProduct in cartList) { BLProduct product = BLProduct.RetrieveFromDB(connectionString, cartProduct.Id); HyperLink linkProduct = new HyperLink { NavigateUrl = $"Product.aspx?productId={product.Id}" }; Image productImage = new Image { ImageUrl = $"ImgHandler.ashx?productIdThumb={product.Id}", AlternateText = product.Name, CssClass = "productImage" }; linkProduct.Controls.Add(productImage); TableCell cellImage = new TableCell() { CssClass = "imageCell" }; cellImage.Controls.Add(linkProduct); Label nameLabel = new Label { Text = product.Name }; TableCell cellName = new TableCell(); cellName.Controls.Add(nameLabel); Label priceLabel = new Label { Text = "£" + (product.Price * (1 - product.Discount / 100)) }; TableCell cellPrice = new TableCell(); cellPrice.Controls.Add(priceLabel); Panel quantityPanel = new Panel(); Label quantityLabel = new Label { Enabled = false, Text = cartProduct.Quantity.ToString(), CssClass = "quantityNumbelLabel" }; Button increaseEditCartButton = new Button() { Text = "+", CausesValidation = false, ID = $"increaseEditCartButton_{product.Id}" }; increaseEditCartButton.Click += IncreaseEditCartButton_Click; if (cartProduct.Quantity >= product.StockQuantity) { increaseEditCartButton.Enabled = false; } Button decreaseEditCartButton = new Button() { Text = "-", CausesValidation = false, ID = $"decreaseEditCartButton_{product.Id}" }; decreaseEditCartButton.Click += DecreaseEditCartButton_Click; if (cartProduct.Quantity <= 1) { decreaseEditCartButton.Enabled = false; } TableCell cellQuantity = new TableCell { CssClass = "QuantityTextbox td" }; quantityPanel.Controls.Add(decreaseEditCartButton); quantityPanel.Controls.Add(quantityLabel); quantityPanel.Controls.Add(increaseEditCartButton); cellQuantity.Controls.Add(quantityPanel); Label stockLabel = new Label { Text = product.StockQuantity.ToString() }; TableCell cellStock = new TableCell(); cellStock.Controls.Add(stockLabel); double totalPriceSum = cartProduct.Quantity * product.Price * (1 - product.Discount / 100); Label vatLabel = new Label { Text = "£" + (product.VAT * totalPriceSum / (100 + product.VAT)) }; TableCell cellVAT = new TableCell(); cellVAT.Controls.Add(vatLabel); totalCartPrice += totalPriceSum; Label totalPriceLabel = new Label { Text = "£" + totalPriceSum }; TableCell celltotalPrice = new TableCell(); celltotalPrice.Controls.Add(totalPriceLabel); ImageButton removeProductButton = new ImageButton() { ImageUrl = "/Images/removeProduct.png", CssClass = "removeProductButton", CausesValidation = false, ID = $"removeButton_{product.Id}" }; removeProductButton.Click += RemoveButton_Click; TableCell cellRemoveProductButton = new TableCell(); cellRemoveProductButton.Controls.Add(removeProductButton); TableRow row = new TableRow(); row.Controls.Add(cellImage); row.Controls.Add(cellName); row.Controls.Add(cellPrice); row.Controls.Add(cellQuantity); row.Controls.Add(cellStock); row.Controls.Add(cellVAT); row.Controls.Add(celltotalPrice); row.Controls.Add(cellRemoveProductButton); checkout_product_table.Controls.Add(row); } double shippingCost; ShippingDrowdown(out shippingCost); tableShippingPrice.InnerText = "£" + shippingCost; totalCartPrice += shippingCost; tableTotalPrice.InnerText = "£" + totalCartPrice; }
private void GenerateCartContent() { try { foreach (var cartProduct in cartList) { BLProduct product = BLProduct.RetrieveFromDB(connectionString, cartProduct.Id); HyperLink productLink = new HyperLink { NavigateUrl = $"Product.aspx?productId={product.Id}" }; Image productImage = new Image { ImageUrl = $"ImgHandler.ashx?productIdThumb={product.Id}", AlternateText = product.Name, CssClass = "productImage" }; productLink.Controls.Add(productImage); TableCell cellImage = new TableCell { CssClass = "td" }; cellImage.Controls.Add(productLink); Label nameLabel = new Label { Text = product.Name }; TableCell cellName = new TableCell { CssClass = "td" }; cellName.Controls.Add(nameLabel); Label priceLabel = new Label { Text = "£" + (product.Price * (1 - product.Discount / 100)) }; TableCell cellPrice = new TableCell { CssClass = "td" }; cellPrice.Controls.Add(priceLabel); Label quantityLabel = new Label { Text = cartProduct.Quantity.ToString(), ID = $"quantity{product.Id}", Enabled = false }; TableCell cellQuantity = new TableCell { CssClass = "td" }; cellQuantity.Controls.Add(quantityLabel); double totalPriceSum = cartProduct.Quantity * product.Price * (1 - product.Discount / 100); Label totalPriceLabel = new Label { Text = "£" + totalPriceSum }; TableCell celltotalPrice = new TableCell { CssClass = "td" }; celltotalPrice.Controls.Add(totalPriceLabel); TableRow row = new TableRow(); row.Controls.Add(cellImage); row.Controls.Add(cellName); row.Controls.Add(cellPrice); row.Controls.Add(cellQuantity); row.Controls.Add(celltotalPrice); CartListTable.Controls.Add(row); } } catch (Exception) { Session["cartList"] = null; Session["cartCount"] = null; throw; //Error retrieving product from Products } }