private async Task <CartDetail> handleAddExistedItem(
            CartDetail cartDetail,
            ProductTier productTier)
        {
            var existingCartDetail = await _context.CartDetails
                                     .SingleOrDefaultAsync(c =>
                                                           c.ProductTierId == cartDetail.ProductTierId &&
                                                           c.CartId == cartDetail.CartId);

            if (existingCartDetail != null)
            {
                int newQuantity = cartDetail.Quantity + existingCartDetail.Quantity;

                if (newQuantity > productTier.Quantity)
                {
                    return(null);
                }

                existingCartDetail.Quantity = newQuantity;
                var result = await UpdateAsync(existingCartDetail);

                if (result.IsSuccess)
                {
                    return(existingCartDetail);
                }

                return(null);
            }

            return(null);
        }
Пример #2
0
        private void CheckValidSourceProductTier(
            ProductTier productTier1,
            double transferQuantity
            )
        {
            if (productTier1 == null || productTier1.IsDeleted == true)
            {
                throw new Exception(
                          $"Sản phẩm với id = {productTier1.Id} không tồn tại"
                          );
            }

            /** Only allow to transfer from tier 1 to tier 2 */
            if (productTier1.Tier.TierOption != TierEnum.tier1)
            {
                throw new Exception(
                          "Chỉ cho phép chuyển số lượng từ sản phẩm loại 1"
                          );
            }

            /** Check valid quantity */
            if (transferQuantity > productTier1.Quantity)
            {
                throw new Exception(
                          $"Số lượng yêu cầu chuyển ({transferQuantity}) lớn hơn số lượng hiện có của sản phẩm ({productTier1.Quantity})"
                          );
            }
        }
Пример #3
0
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            ProductTier theTier    = new ProductTier();
            Product     theProduct = new Product();

            theProduct.prodID    = (int)Session["ProductID"];
            theProduct.prodName  = txtProdName.Text;
            theProduct.prodDesc  = txtProdDesc.Text;
            theProduct.price     = Double.Parse(txtPrice.Text);
            theProduct.inventory = int.Parse(txtInventory.Text);
            if (newImg.HasFile)
            {
                Stream       fs = newImg.PostedFile.InputStream;
                BinaryReader br = new BinaryReader(fs);

                Byte[] theImage = br.ReadBytes((Int32)fs.Length);
                theProduct.prodImg = theImage;
            }
            else
            {
                theProduct.prodImg = (Byte[])Session["theImage"];
            }

            if (theTier.modifyProduct(theProduct))
            {
                Response.Redirect("/SuccessfulSubmission.aspx");
            }
            else
            {
                Response.Redirect("/FailedSubmission.aspx");
            }
        }
Пример #4
0
        public async Task <UpdateProductTierResult> UpdateAsync(ProductTier productTier)
        {
            var currentPricePerKg = await _context.ProductTiers
                                    .FirstOrDefaultAsync(pt => pt.Id == productTier.Id && pt.PricePerKg == productTier.PricePerKg);

            var currentKgSale = await _context.ProductTiers
                                .FirstOrDefaultAsync(pt => pt.Id == productTier.Id && pt.KgSale == productTier.KgSale);

            var currentDiscountPercentage = await _context.ProductTiers
                                            .FirstOrDefaultAsync(pt => pt.Id == productTier.Id &&
                                                                 pt.DiscountPercentage == productTier.DiscountPercentage);

            if (currentPricePerKg == null || currentKgSale == null || currentDiscountPercentage == null)
            {
                productTier.SalePrice          = Math.Floor(productTier.PricePerKg * productTier.KgSale);
                productTier.AfterDiscountPrice = CalculateAfterDiscountPrice(
                    productTier.SalePrice,
                    productTier.DiscountPercentage
                    );
            }

            _context.ProductTiers.Update(productTier);
            var updated = await _context.SaveChangesAsync();

            return(new UpdateProductTierResult
            {
                IsSuccess = true,
            });
        }
Пример #5
0
        protected void editClick(object sender, EventArgs e)
        {
            Button      theButton = (Button)sender;
            ProductTier theTier   = new ProductTier();

            Session["ProductID"] = int.Parse(theButton.ID.Remove(theButton.ID.IndexOf("a"), 1));

            Response.Redirect("/Admin/ModifyProduct.aspx");
        }
Пример #6
0
        private async Task <bool> CreateProductTiersWhenCreateNewProduct(
            ProductTier productTier1,
            int productId
            )
        {
            /** Get tiers */
            var tier1AndTier2 = await _context.Tiers
                                .Where(t => t.TierOption == TierEnum.tier1 ||
                                       t.TierOption == TierEnum.tier2)
                                .ToListAsync();

            var tier1 = tier1AndTier2.SingleOrDefault(t => t.TierOption == TierEnum.tier1);
            var tier2 = tier1AndTier2.SingleOrDefault(t => t.TierOption == TierEnum.tier2);

            /** Prepare product tier info */
            // prepare tier 1 info
            productTier1.IsDeleted          = false;
            productTier1.CreatedAt          = DateTime.UtcNow;
            productTier1.UpdatedAt          = DateTime.UtcNow;
            productTier1.TierId             = tier1.Id;
            productTier1.ProductId          = productId;
            productTier1.SalePrice          = Math.Floor(productTier1.PricePerKg * productTier1.KgSale);
            productTier1.AfterDiscountPrice = CalculateAfterDiscountPrice(
                productTier1.SalePrice,
                productTier1.DiscountPercentage
                );

            // Create product tier 2 too
            // but the new product tier 2 will has quantity 0
            ProductTier productTier2 = new ProductTier
            {
                ProductId          = productId,
                TierId             = tier2.Id,
                Quantity           = 0,
                PricePerKg         = productTier1.PricePerKg,
                SalePrice          = productTier1.SalePrice,
                KgSale             = productTier1.KgSale,
                DiscountPercentage = productTier1.DiscountPercentage,
                AfterDiscountPrice = productTier1.AfterDiscountPrice,
                PriceCurrency      = productTier1.PriceCurrency,
                CreatedAt          = DateTime.UtcNow,
                UpdatedAt          = DateTime.UtcNow,
                IsDeleted          = false
            };

            await _context.AddRangeAsync(
                new List <ProductTier>()
            {
                productTier1,
                productTier2
            }
                );

            var created = await _context.SaveChangesAsync();

            return(created > 0);
        }
Пример #7
0
        protected void deleteClick(object sender, EventArgs e)
        {
            Button      theButton = (Button)sender;
            ProductTier theTier   = new ProductTier();
            int         prodID    = int.Parse(theButton.ID);

            theTier.deleteProduct(prodID);

            Response.Redirect("/Admin/ProductInfo.aspx");
        }
Пример #8
0
        public void ProcessRequest(HttpContext context)
        {
            Byte[]      theImage;
            ProductTier theTier = new ProductTier();
            Int32       imageID = Int32.Parse(context.Request.QueryString["ID"]);

            theImage = theTier.getImage(imageID);

            context.Response.BinaryWrite(theImage);
        }
        protected void btnOkay_Click(object sender, EventArgs e)
        {
            if (Session["theProduct"] != null)
            {
                ProductTier theTier    = new ProductTier();
                Product     theProduct = (Product)Session["theProduct"];

                if (theTier.insertProduct(theProduct))
                {
                    Session["theProduct"] = null;
                    Response.Redirect("/SuccessfulSubmission.aspx");
                }
                else
                {
                    Response.Redirect("/FailedSubmission.aspx");
                }
            }
        }
Пример #10
0
        private void CheckValidDestinationProductTier(
            ProductTier productTier2
            )
        {
            if (productTier2 == null || productTier2.IsDeleted == true)
            {
                throw new Exception(
                          $"Sản phẩm với id = {productTier2.Id} không tồn tại"
                          );
            }

            /** Only allow to transfer from tier 1 to tier 2 */
            if (productTier2.Tier.TierOption != TierEnum.tier2)
            {
                throw new Exception(
                          "Chỉ cho phép chuyển số lượng từ sản phẩm loại 1 sang loại 2"
                          );
            }
        }
Пример #11
0
    /// <summary>
    /// Submit Button Click event
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        ProductAdmin productTierAdmin = new ProductAdmin();
        ProductTier _productTier = new ProductTier();

        if (productTierID > 0)
        {
            _productTier = productTierAdmin.GetByProductTierId(productTierID);
        }

        if (ddlProfiles.SelectedValue == "0")
        {
            _productTier.ProfileID = null;
        }
        else { _productTier.ProfileID = int.Parse(ddlProfiles.SelectedValue); }

        _productTier.TierStart = int.Parse(txtTierStart.Text.Trim());
        _productTier.TierEnd = int.Parse(txtTierEnd.Text.Trim());
        _productTier.Price = decimal.Parse(txtPrice.Text.Trim());
        _productTier.ProductID = ItemID; //Set ProductId field

        bool status = false;

        //if Edit mode, then update fields
        if (productTierID > 0)
        {
           status = productTierAdmin.UpdateProductTier(_productTier);
        }
        else
        {
            status = productTierAdmin.AddProductTier(_productTier);
        }

        if (status)
        {
            Response.Redirect(viewLink + ItemID + "&mode=tieredPricing");
        }
        else
        {
            lblError.Text = "Could not update the product Tiered pricing. Please try again.";
        }
    }
Пример #12
0
        protected void Page_Load(object sender, EventArgs e)
        {
            Table mainTable = new Table();

            mainTable.CssClass = "table-striped";
            mainTable.Style.Add("margin", "10px auto 10px auto");
            mainTable.Style.Add("width", "auto");
            ProductTier productTier = new ProductTier();
            TableRow    mainTr;
            TableCell   mainTd;

            int counter = 0;

            List <Product> productList = productTier.getAllProducts();

            mainTr = new TableRow();

            foreach (Product item in productList)
            {
                if (counter % 4 == 0)
                {
                    mainTable.Rows.Add(mainTr);
                    mainTr = new TableRow();
                }
                mainTd = new TableCell();
                Table theProductTable = productTable(item);
                mainTd.Controls.Add(theProductTable);
                mainTd.Style.Add("padding", "0px 20px 0px 20px");
                mainTr.Cells.Add(mainTd);


                counter++;
            }

            if (counter % 1 == 0 || counter % 2 == 0 || counter % 3 == 0)
            {
                mainTable.Rows.Add(mainTr);
            }

            pnlProducts.Controls.Add(mainTable);
        }
Пример #13
0
        protected void addToCartClick(object sender, EventArgs e)
        {
            Button      theButton   = (Button)sender;
            ProductTier productTier = new ProductTier();
            Product     theProduct  = productTier.getProductById(int.Parse(theButton.ID));

            Cart theCart;

            if (Session["theCart"] != null)
            {
                theCart = (Cart)Session["theCart"];
                theCart.addProduct(theProduct, 1);
            }
            else
            {
                theCart = new Cart();
                theCart.addProduct(theProduct, 1);
            }

            Session["theCart"] = theCart;
        }
Пример #14
0
        private async Task <bool> UpdateSourceAndDestinationProductTiersQuantity(
            ProductTier productTier1,
            ProductTier productTier2,
            double transferQuantity
            )
        {
            /** calculate new quantity */
            productTier1.Quantity = productTier1.Quantity - transferQuantity;
            productTier2.Quantity = productTier2.Quantity + transferQuantity;

            /** Update to Database */
            _context.ProductTiers.UpdateRange(
                new List <ProductTier>()
            {
                productTier1,
                productTier2
            }
                );
            var updated = await _context.SaveChangesAsync();

            return(updated > 0);
        }
Пример #15
0
        private void AreSourceAndDestinationProductTierValid(
            ProductTier productTier1,
            ProductTier productTier2,
            double transferQuantity
            )
        {
            try
            {
                /** validate source and destination has to be the same product */
                if (productTier1.ProductId != productTier2.ProductId)
                {
                    throw new Exception(
                              @"Sản phẩm cần chuyển và sản phẩm nhận không cùng chung một loại sản phẩm"
                              );
                }

                CheckValidSourceProductTier(productTier1, transferQuantity);
                CheckValidDestinationProductTier(productTier2);
            }
            catch (Exception)
            {
                throw;
            }
        }
Пример #16
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["ProductID"] != null)
            {
                int         id         = (int)Session["ProductID"];
                ProductTier theTier    = new ProductTier();
                Product     theProduct = theTier.getProductById(id);
                Session["theImage"] = theProduct.prodImg;

                if (!IsPostBack)
                {
                    idLabel.InnerText = "Product ID: " + theProduct.prodID.ToString();
                    txtProdName.Text  = theProduct.prodName;
                    txtProdDesc.Text  = theProduct.prodDesc;
                    txtPrice.Text     = Math.Round(theProduct.price, 2).ToString();
                    txtInventory.Text = theProduct.inventory.ToString();
                    prodImg.ImageUrl  = "/Handlers/imgHandler.ashx?ID=" + theProduct.prodID;
                }
            }
            else
            {
                Response.Redirect("/Admin/ProductInfo.aspx");
            }
        }
Пример #17
0
        public async Task <CreateProductTierResult> CreateAsync(ProductTier productTier)
        {
            productTier.IsDeleted = false;
            productTier.CreatedAt = DateTime.UtcNow;
            productTier.UpdatedAt = DateTime.UtcNow;

            await _context.ProductTiers.AddAsync(productTier);

            var created = await _context.SaveChangesAsync();

            if (!(created > 0))
            {
                return(new CreateProductTierResult
                {
                    IsSuccess = false,
                    Errors = new[] { "Có lỗi khi tạo sản phẩm mới, vui lòng thử lại" }
                });
            }

            return(new CreateProductTierResult
            {
                IsSuccess = true
            });
        }
Пример #18
0
        protected void Page_Load(object sender, EventArgs e)
        {
            ProductTier    theTier  = new ProductTier();
            List <Product> theList  = theTier.getAllProducts();
            Table          theTable = new Table();

            theTable.CssClass = "table-striped";
            theTable.Style.Add("margin", "10px auto 10px auto");
            theTable.Style.Add("width", "auto");
            TableRow  tr = new TableRow();
            TableCell td;
            Button    delete;
            Button    edit;

            TableHeaderCell th       = new TableHeaderCell();
            Label           theLabel = new Label();

            theLabel.Text = "Product ID";
            th.Controls.Add(theLabel);
            tr.Cells.Add(th);

            th            = new TableHeaderCell();
            theLabel      = new Label();
            theLabel.Text = "Name";
            th.Controls.Add(theLabel);
            tr.Cells.Add(th);

            th            = new TableHeaderCell();
            theLabel      = new Label();
            theLabel.Text = "Description";
            th.Controls.Add(theLabel);
            tr.Cells.Add(th);

            th            = new TableHeaderCell();
            theLabel      = new Label();
            theLabel.Text = "Image";
            th.Controls.Add(theLabel);
            tr.Cells.Add(th);

            th            = new TableHeaderCell();
            theLabel      = new Label();
            theLabel.Text = "Price";
            th.Controls.Add(theLabel);
            tr.Cells.Add(th);

            th            = new TableHeaderCell();
            theLabel      = new Label();
            theLabel.Text = "Inventory";
            th.Controls.Add(theLabel);
            tr.Cells.Add(th);

            theTable.Rows.Add(tr);
            if (theList != null)
            {
                foreach (Product prod in theList)
                {
                    Session["theImage"] = prod.prodImg;
                    tr = new TableRow();

                    td            = new TableCell();
                    theLabel      = new Label();
                    theLabel.Text = prod.prodID.ToString();
                    td.Controls.Add(theLabel);
                    tr.Cells.Add(td);

                    td            = new TableCell();
                    theLabel      = new Label();
                    theLabel.Text = prod.prodName.ToString();
                    td.Controls.Add(theLabel);
                    tr.Cells.Add(td);

                    td            = new TableCell();
                    theLabel      = new Label();
                    theLabel.Text = prod.prodDesc.ToString();
                    td.Controls.Add(theLabel);
                    tr.Cells.Add(td);

                    td = new TableCell();
                    Image theImage = new Image();
                    theImage.ImageUrl = "/Handlers/imgHandler.ashx?ID=" + prod.prodID;
                    theImage.CssClass = "img-thumbnail prodImg";
                    td.Controls.Add(theImage);
                    tr.Cells.Add(td);

                    td            = new TableCell();
                    theLabel      = new Label();
                    theLabel.Text = "$" + Math.Round(prod.price, 2).ToString("N2");
                    td.Controls.Add(theLabel);
                    tr.Cells.Add(td);

                    td            = new TableCell();
                    theLabel      = new Label();
                    theLabel.Text = prod.inventory.ToString();
                    td.Controls.Add(theLabel);
                    tr.Cells.Add(td);

                    td            = new TableCell();
                    delete        = new Button();
                    delete.Text   = "Delete";
                    delete.ID     = prod.prodID.ToString();
                    delete.Click += deleteClick;
                    td.Controls.Add(delete);
                    edit        = new Button();
                    edit.Text   = "Edit";
                    edit.ID     = prod.prodID.ToString() + "a";
                    edit.Click += editClick;
                    td.Controls.Add(edit);

                    tr.Cells.Add(td);

                    theTable.Rows.Add(tr);
                }
            }

            pnlOut.Controls.Add(theTable);
        }
Пример #19
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["OrderID"] != null)
            {
                int                orderID        = (int)Session["OrderID"];
                OrderDetailTier    theDetailTier  = new OrderDetailTier();
                ProductTier        theProductTier = new ProductTier();
                Product            theProduct;
                List <OrderDetail> theDetailList = theDetailTier.getFullOrder(orderID);
                Table              theTable      = new Table();
                theTable.CssClass = "table-striped";
                theTable.Style.Add("margin", "10px auto 10px auto");
                theTable.Style.Add("width", "auto");
                TableRow       tr = new TableRow();
                TableCell      td = new TableCell();
                TableHeaderRow th = new TableHeaderRow();
                Image          theImage;
                Button         delete;

                Label theLabel = new Label();
                theLabel.Text = "Order ID: " + orderID.ToString();
                td.Controls.Add(theLabel);
                th.Cells.Add(td);
                theTable.Rows.Add(th);

                tr            = new TableRow();
                td            = new TableCell();
                theLabel      = new Label();
                theLabel.Text = "Product ID";
                td.Controls.Add(theLabel);
                tr.Cells.Add(td);

                theLabel      = new Label();
                td            = new TableCell();
                theLabel.Text = "Product Name";
                td.Controls.Add(theLabel);
                tr.Cells.Add(td);

                theLabel      = new Label();
                td            = new TableCell();
                theLabel.Text = "Product Description";
                td.Controls.Add(theLabel);
                tr.Cells.Add(td);

                theLabel      = new Label();
                td            = new TableCell();
                theLabel.Text = "Product Image";
                td.Controls.Add(theLabel);
                tr.Cells.Add(td);

                theLabel      = new Label();
                td            = new TableCell();
                theLabel.Text = "Qauntity";
                td.Controls.Add(theLabel);
                tr.Cells.Add(td);

                theLabel      = new Label();
                td            = new TableCell();
                theLabel.Text = "Price";
                td.Controls.Add(theLabel);
                tr.Cells.Add(td);

                theTable.Rows.Add(tr);

                if (theDetailList != null)
                {
                    foreach (OrderDetail item in theDetailList)
                    {
                        theProduct = new Product();
                        theProduct = theProductTier.getProductById(item.prodID);

                        tr = new TableRow();

                        theLabel      = new Label();
                        td            = new TableCell();
                        theLabel.Text = theProduct.prodID.ToString();
                        td.Controls.Add(theLabel);
                        tr.Cells.Add(td);

                        theLabel      = new Label();
                        td            = new TableCell();
                        theLabel.Text = theProduct.prodName.ToString();
                        td.Controls.Add(theLabel);
                        tr.Cells.Add(td);

                        theLabel      = new Label();
                        td            = new TableCell();
                        theLabel.Text = theProduct.prodDesc.ToString();
                        td.Controls.Add(theLabel);
                        tr.Cells.Add(td);

                        theImage          = new Image();
                        td                = new TableCell();
                        theImage.ImageUrl = "/Handlers/imgHandler.ashx?ID=" + theProduct.prodID;
                        theImage.CssClass = "img-thumbnail prodImg";
                        td.Controls.Add(theImage);
                        tr.Cells.Add(td);

                        theLabel      = new Label();
                        td            = new TableCell();
                        theLabel.Text = item.quantitySold.ToString();
                        td.Controls.Add(theLabel);
                        tr.Cells.Add(td);

                        theLabel      = new Label();
                        td            = new TableCell();
                        theLabel.Text = "$" + Math.Round(theProduct.price, 2).ToString("N2");
                        td.Controls.Add(theLabel);
                        tr.Cells.Add(td);

                        delete          = new Button();
                        td              = new TableCell();
                        delete.Text     = "Delete";
                        delete.CssClass = "btn btn-danger";
                        delete.ID       = item.orderID + " " + item.prodID;
                        delete.Click   += deleteClick;
                        td.Controls.Add(delete);
                        tr.Cells.Add(td);

                        theTable.Rows.Add(tr);
                    }
                    pnlDetails.Controls.Add(theTable);
                }
            }
            else
            {
                Response.Redirect("/Admin/OrderInfo.aspx");
            }
        }
Пример #20
0
        public async Task <CreateProductResult> CreateAsync(
            Product product,
            ProductTier productTier,
            int createdProductUserId,
            IEnumerable <IFormFile> images,
            string productImageDir,
            string appRootDir)
        {
            var prepareProductInfoResult = await PrepareNewProductInfo(
                product,
                createdProductUserId
                );

            if (prepareProductInfoResult.IsSuccess == false)
            {
                return(new CreateProductResult
                {
                    IsSuccess = false,
                    Errors = prepareProductInfoResult.Errors
                });
            }

            using (var transaction = _context.Database.BeginTransaction())
            {
                try
                {
                    /** Create product */
                    await _context.Products.AddAsync(product);

                    var created = await _context.SaveChangesAsync();

                    if (!(created > 0))
                    {
                        transaction.Dispose();
                        throw new Exception("Có lỗi khi tạo sản phẩm mới, vui lòng thử lại");
                    }

                    /** Create Images of product */
                    // only work if images are existed
                    bool isUploadImageSuccess = await UploadImagesWhenCreateProduct(
                        images,
                        appRootDir,
                        productImageDir,
                        product.Id
                        );

                    if (isUploadImageSuccess == false)
                    {
                        transaction.Dispose();
                        throw new Exception("Có lỗi khi tạo sản phẩm mới, vui lòng thử lại");
                    }

                    /** Create product tiers */
                    bool isCreatedProductTiersSuccess = await CreateProductTiersWhenCreateNewProduct(
                        productTier,
                        product.Id
                        );

                    if (!isCreatedProductTiersSuccess)
                    {
                        transaction.Dispose();
                        throw new Exception("Có lỗi khi tạo sản phẩm mới, vui lòng thử lại");
                    }

                    await transaction.CommitAsync();
                }
                catch (Exception e)
                {
                    return(new CreateProductResult
                    {
                        IsSuccess = false,
                        Errors = new[] { e.Message.ToString() }
                    });
                }
            }

            return(new CreateProductResult
            {
                IsSuccess = true
            });
        }
Пример #21
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["theCart"] != null)
            {
                Cart        theCart  = (Cart)Session["theCart"];
                ProductTier theTier  = new ProductTier();
                Table       theTable = new Table();
                theTable.CssClass = "table-striped";
                theTable.Style.Add("margin", "10px auto 10px auto");
                theTable.Style.Add("width", "auto");
                TableRow       tr;
                TableCell      td = new TableCell();
                TableHeaderRow th = new TableHeaderRow();
                Image          theImage;
                Button         delete;

                Label theLabel = new Label();
                td            = new TableCell();
                theLabel.Text = "Product Name";
                td.Controls.Add(theLabel);
                th.Cells.Add(td);

                theLabel      = new Label();
                td            = new TableCell();
                theLabel.Text = "Image";
                td.Controls.Add(theLabel);
                th.Cells.Add(td);

                theLabel      = new Label();
                td            = new TableCell();
                theLabel.Text = "Quantity";
                td.Controls.Add(theLabel);
                th.Cells.Add(td);

                theLabel      = new Label();
                td            = new TableCell();
                theLabel.Text = "Price";
                td.Controls.Add(theLabel);
                th.Cells.Add(td);

                theTable.Rows.Add(th);

                foreach (Product item in theCart.products)
                {
                    tr = new TableRow();

                    theLabel      = new Label();
                    td            = new TableCell();
                    theLabel.Text = item.prodName;
                    td.Controls.Add(theLabel);
                    tr.Cells.Add(td);

                    theLabel          = new Label();
                    td                = new TableCell();
                    theImage          = new Image();
                    theImage.ImageUrl = "/Handlers/imgHandler.ashx?ID=" + item.prodID;
                    theImage.CssClass = "img-thumbnail prodImg";
                    td.Controls.Add(theImage);
                    tr.Cells.Add(td);

                    theLabel      = new Label();
                    td            = new TableCell();
                    theLabel.Text = theCart.quantities[theCart.products.IndexOf(item)].ToString();
                    td.Controls.Add(theLabel);
                    tr.Cells.Add(td);


                    theLabel      = new Label();
                    td            = new TableCell();
                    theLabel.Text = "$" + Math.Round(item.price, 2).ToString("N2");
                    td.Controls.Add(theLabel);
                    tr.Cells.Add(td);

                    td     = new TableCell();
                    delete = new Button();

                    delete.Click   += deleteClick;
                    delete.Text     = "Delete";
                    delete.CssClass = item.prodID.ToString() + " btn btn-danger";
                    td.Controls.Add(delete);
                    tr.Cells.Add(td);

                    theTable.Rows.Add(tr);
                }

                Button submit = new Button();
                td              = new TableCell();
                tr              = new TableRow();
                submit.Text     = "Submit Order";
                submit.CssClass = "btn btn-success";
                submit.Click   += submitClick;
                td.Controls.Add(submit);
                tr.Cells.Add(td);

                theTable.Rows.Add(tr);

                pnlOut.Controls.Add(theTable);
            }
            else
            {
                Label theLabel = new Label();
                theLabel.Text = "There are no items in your cart!";
                pnlOut.Controls.Add(theLabel);
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["theCart"] != null)
            {
                Cart        theCart  = (Cart)Session["theCart"];
                ProductTier theTier  = new ProductTier();
                Table       theTable = new Table();
                theTable.CssClass = "table-striped";
                theTable.Style.Add("margin", "10px auto 10px auto");
                theTable.Style.Add("width", "auto");
                TableRow       tr;
                TableCell      td = new TableCell();
                TableHeaderRow th = new TableHeaderRow();
                Image          theImage;
                TextBox        txtCustID;
                TextBox        txtDiscount;


                Label theLabel = new Label();
                td            = new TableCell();
                theLabel.Text = "Product Name";
                td.Controls.Add(theLabel);
                th.Cells.Add(td);

                theLabel      = new Label();
                td            = new TableCell();
                theLabel.Text = "Image";
                td.Controls.Add(theLabel);
                th.Cells.Add(td);

                theLabel      = new Label();
                td            = new TableCell();
                theLabel.Text = "Quantity";
                td.Controls.Add(theLabel);
                th.Cells.Add(td);

                theLabel      = new Label();
                td            = new TableCell();
                theLabel.Text = "Price";
                td.Controls.Add(theLabel);
                th.Cells.Add(td);

                theTable.Rows.Add(th);

                foreach (Product item in theCart.products)
                {
                    tr = new TableRow();

                    theLabel      = new Label();
                    td            = new TableCell();
                    theLabel.Text = item.prodName;
                    td.Controls.Add(theLabel);
                    tr.Cells.Add(td);

                    theLabel          = new Label();
                    td                = new TableCell();
                    theImage          = new Image();
                    theImage.ImageUrl = "/Handlers/imgHandler.ashx?ID=" + item.prodID;
                    theImage.CssClass = "img-thumbnail prodImg";
                    td.Controls.Add(theImage);
                    tr.Cells.Add(td);

                    theLabel      = new Label();
                    td            = new TableCell();
                    theLabel.Text = theCart.quantities[theCart.products.IndexOf(item)].ToString();
                    td.Controls.Add(theLabel);
                    tr.Cells.Add(td);


                    theLabel      = new Label();
                    td            = new TableCell();
                    theLabel.Text = "$" + Math.Round(item.price, 2).ToString("N2");
                    td.Controls.Add(theLabel);
                    tr.Cells.Add(td);

                    theTable.Rows.Add(tr);
                }

                tr = new TableRow();
                td = new TableCell();
                tr.Cells.Add(td);
                td = new TableCell();
                tr.Cells.Add(td);
                td = new TableCell();
                tr.Cells.Add(td);
                td       = new TableCell();
                theLabel = new Label();
                double total = 0;
                int    quan  = 1;
                foreach (Product item in theCart.products)
                {
                    if (int.Parse(theCart.quantities[theCart.products.IndexOf(item)].ToString()) > 1)
                    {
                        quan = int.Parse(theCart.quantities[theCart.products.IndexOf(item)].ToString());
                    }
                    total += (item.price * quan);
                    quan   = 1;
                }
                Session["total"] = total;
                theLabel.Text    = "Total: $" + Math.Round(total, 2).ToString("N2");
                td.Controls.Add(theLabel);
                tr.Cells.Add(td);
                theTable.Rows.Add(tr);


                Button submit = new Button();
                td              = new TableCell();
                tr              = new TableRow();
                submit.Text     = "Confirm Order";
                submit.CssClass = "btn btn-success";
                submit.Click   += submitClick;
                td.Controls.Add(submit);
                tr.Cells.Add(td);

                theTable.Rows.Add(tr);

                pnlOut.Controls.Add(theTable);
            }
            else
            {
                Response.Redirect("ViewCart.aspx");
            }
        }