Пример #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            Table mainTable = new Table();

            mainTable.Attributes.Add("HorizontalAlign", "Center");
            ProductInfoTier productTier = new ProductInfoTier();
            TableRow        mainTr;
            TableCell       mainTd;
            int             counter     = 0;
            List <Product>  productList = productTier.getAllProducts();

            mainTr = new TableRow();
            foreach (Product item in productList)
            {
                if (counter % 3 == 0)
                {
                    mainTable.Rows.Add(mainTr);
                    mainTr = new TableRow();
                }
                //create a new table cell
                mainTd = new TableCell();
                //get a product table from my method definded bellow.
                Table theProductTable = productTable(item);
                //Add the product table to the table cell
                mainTd.Controls.Add(theProductTable);
                //add the table cell to the table row.
                mainTr.Cells.Add(mainTd);

                counter++;
            }
            //Add the main table to the panel on the ASPX Page
            pnlProduct.Controls.Add(mainTable);
        }
Пример #2
0
        protected void addToCartClick(object sender, EventArgs e)
        {
            //sender is a button, make it a button
            Button theButton = (Button)sender;

            ProductInfoTier productTier = new ProductInfoTier();

            //using the ID from the button, get a product from the Data Tier
            Product theProduct = productTier.getProductByID(int.Parse(theButton.ID));

            //The following is basic shopping cart code minus the shoppiong cart class.
            List <Product> theCart;

            if (Session["Cart"] != null)
            {
                theCart = (List <Product>)Session["Cart"];
                theCart.Add(theProduct);
            }
            else
            {
                theCart = new List <Product>();
                theCart.Add(theProduct);
            }

            Session["Cart"] = theCart;
        }
Пример #3
0
        protected void ShowProducts()
        {
            DataSet         ds = new DataSet();
            ProductInfoTier pt = new ProductInfoTier();

            try
            {
                ds = pt.getProductDataSet();
            }
            catch (Exception ex)
            {
                throw new Exception("Error Getting DataSet " + ex.Message);
            }
            gvProduct.DataSource = ds;
            gvProduct.DataMember = "ProductInfo";
            gvProduct.DataBind();
        }
Пример #4
0
        protected void Page_Load(object sender, EventArgs e)
        {
            ProductInfoTier productTier = new ProductInfoTier();
            TableRow        mainTr;
            TableCell       mainTd;
            int             counter     = 0;
            List <Product>  productList = new List <Product>();

            if (Session["Cart"] != null)
            {
                productList = (List <Product>)Session["Cart"];
            }
            else
            {
                Response.Redirect("Products.aspx");
            }
            mainTr = new TableRow();
            foreach (Product item in productList)
            {
                tblCart.Rows.Add(mainTr);
                mainTr = new TableRow();
                //create a new table cell
                mainTd = new TableCell();
                Label theLabel = new Label();
                theLabel.Text = item.ProductName;
                mainTd.Controls.Add(theLabel);
                mainTr.Cells.Add(mainTd);
                mainTd = new TableCell();
                Label Price = new Label();
                Price.Text = item.ProductPrice.ToString();
                totalPrice = totalPrice + int.Parse(Price.Text);
                mainTd.Controls.Add(Price);
                mainTr.Cells.Add(mainTd);
                counter++;
            }
            tblCart.Rows.Add(mainTr);
            lblPrice.Text    = totalPrice.ToString();
            lblQuantity.Text = counter.ToString();
        }