Exemplo n.º 1
0
    /*
     * Index.aspx needs to be renamed to Webshop.aspx
     * TODO
     * create Index.aspx  (a real index page,  not this crap)
     *
     * */

    private void FillPage()
    {
        try
        {
            ProductsModel  productModel = new ProductsModel();
            List <Product> products     = productModel.GetAllProducts();

            if (products != null)
            {
                foreach (Product product in products)
                {
                    Panel       productPanel = new Panel();
                    ImageButton imageButton  = new ImageButton();
                    Label       lblName      = new Label();
                    Label       lblPrice     = new Label();

                    imageButton.ImageUrl    = "~/Images/Products/" + product.Image;
                    imageButton.CssClass    = "productImage";
                    imageButton.PostBackUrl = "~/Pages/Product.aspx?id=" + product.Id;

                    lblName.Text     = product.Name;
                    lblName.CssClass = "productName";

                    lblPrice.Text     = "R " + product.Price;
                    lblPrice.CssClass = "productPrice";

                    productPanel.Controls.Add(imageButton);
                    productPanel.Controls.Add(new Literal {
                        Text = "<br />"
                    });
                    productPanel.Controls.Add(lblName);
                    productPanel.Controls.Add(new Literal {
                        Text = "<br />"
                    });
                    productPanel.Controls.Add(lblPrice);

                    if (!(bool)product.isVisible)
                    {
                        productPanel.Visible = false;
                    }

                    pnlProducts.Controls.Add(productPanel);
                }
            }
            else
            {
                pnlProducts.Controls.Add(new Literal {
                    Text = "No products found!"
                });
            }
        }
        catch (Exception e)
        {
            String temp = e.ToString();
            System.Console.WriteLine("Hello world " + temp);
            Response.Redirect("~/Pages/Errors/InternalServerErrorPage.aspx");
        }
    }
Exemplo n.º 2
0
    private void FillPage(String [] args)
    {
        try
        {
            ProductsModel  productModel = new ProductsModel();
            List <Product> products     = productModel.GetAllProducts(args);

            if (products != null)
            {
                foreach (Product product in products)
                {
                    Panel       productPanel = new Panel();
                    ImageButton imageButton  = new ImageButton();
                    Label       lblName      = new Label();
                    Label       lblPrice     = new Label();

                    imageButton.ImageUrl    = "~/Images/Products/" + product.Image;
                    imageButton.CssClass    = "productImage";
                    imageButton.PostBackUrl = "~/Pages/Product.aspx?id=" + product.Id;

                    lblName.Text     = product.Name;
                    lblName.CssClass = "productName";

                    lblPrice.Text     = "R " + product.Price;
                    lblPrice.CssClass = "productPrice";

                    productPanel.Controls.Add(imageButton);
                    productPanel.Controls.Add(new Literal {
                        Text = "<br />"
                    });
                    productPanel.Controls.Add(lblName);
                    productPanel.Controls.Add(new Literal {
                        Text = "<br />"
                    });
                    productPanel.Controls.Add(lblPrice);

                    pnlProducts.Controls.Add(productPanel);
                }
            }
            else
            {
                pnlProducts.Controls.Add(new Literal {
                    Text = "No products found!"
                });
            }
        }
        catch (Exception e)
        {
            String temp = e.ToString();
            System.Console.WriteLine("Hello world \n Exception: " + temp +
                                     "\nHere's the arg : " + args +
                                     "\nThrowing exception...");
            throw new Exception(e.StackTrace);
            // Response.Redirect("~/Pages/Errors/InternalServerErrorPage.aspx");
        }
    }
Exemplo n.º 3
0
    protected void Page_Load(object sender, EventArgs e)
    {
        ProductsModel   model    = new ProductsModel();
        List <Products> products = model.GetAllProducts();

        if (products != null)
        {
            foreach (Products product in products)
            {
                Panel       productPanel = new Panel();
                ImageButton imageButton  = new ImageButton
                {
                    ImageUrl    = "~/Images/Products/" + product.Image,
                    CssClass    = "productImage",
                    PostBackUrl = string.Format("~/Pages/Product.aspx?id={0}", product.ID)
                };
                Label lblName = new Label
                {
                    Text     = product.Name,
                    CssClass = "productName"
                };
                Label lblPrice = new Label
                {
                    Text     = "€" + product.Price,
                    CssClass = "productPrice"
                };

                productPanel.Controls.Add(imageButton);
                productPanel.Controls.Add(new Literal {
                    Text = "<br/>"
                });
                productPanel.Controls.Add(lblName);
                productPanel.Controls.Add(new Literal {
                    Text = "<br/>"
                });
                productPanel.Controls.Add(lblPrice);

                //Add dynamic controls to static control
                pnlProducts.Controls.Add(productPanel);
            }
        }
        else
        {
            pnlProducts.Controls.Add(new Literal {
                Text = "No products found!"
            });
        }
    }