예제 #1
0
    protected void addtoCart_Click(object sender, EventArgs e)
    {
        //add certain number of selected product to cart
        List <Product> p         = (List <Product>)Session["Products"];
        Customer       aCustomer = (Customer)Session["Customer"];

        int qty    = Convert.ToInt16(txtQuantity.Text);
        int prodId = Convert.ToInt16(Request.QueryString["id"]);

        aCustomer = CartFunctions.addItemtoCart(p, aCustomer, prodId, qty);

        lblQty.Text         = txtQuantity.Text + " ";
        lblProduct.Text     = "x " + lblProdTitle.Text + " added to your cart";
        Session["Customer"] = aCustomer;

        //displays products bought with
        ClientScript.RegisterStartupScript(GetType(), "hwa", "confirmOrder();", true);

        Label lblCost = (Label)this.Master.FindControl("lblCost");

        lblCost.Text = CartFunctions.getSubTotal(aCustomer).ToString("C");

        Label lblItem = (Label)this.Master.FindControl("lblItems");

        lblItem.Text = CartFunctions.getNumItem(aCustomer).ToString() + " items";
    }
예제 #2
0
    protected void Page_Load(object sender, EventArgs e)
    {
        int    noItems   = 0;
        double dbCostost = 0.00;



        Customer aCustomer = (Customer)Session["Customer"];

        //check if there are orderlines to begin with
        if (aCustomer.Orders[0].OrderLines.Count <= 0)
        {
            //set to default values
            lblItems.Text = noItems.ToString();
            lblCost.Text  = dbCostost.ToString("C");
        }
        else
        {
            //get number of items and total and set labels to them
            noItems   = CartFunctions.getNumItem(aCustomer);
            dbCostost = CartFunctions.getSubTotal(aCustomer);
        }//end if else
        lblCost.Text  = dbCostost.ToString("C");
        lblItems.Text = noItems.ToString() + " items";
    }//end event
예제 #3
0
    //if row is deleted remove orderline
    protected void GridView1_RowDeleting(Object sender, GridViewDeleteEventArgs e)
    {
        Customer aCustomer = (Customer)Session["Customer"];
        int      index     = e.RowIndex;

        aCustomer = CartFunctions.removeItem(aCustomer, index);

        if (aCustomer.Orders[0].OrderLines.Count == 0)
        {
            HyperLink continueShop = new HyperLink();
            continueShop.NavigateUrl = "Shop.aspx";
            continueShop.Text        = "Back to the Shop";
            cartcontainer.InnerHtml  = "You have nothing in your cart" + " ";
            cartcontainer.Controls.Add(continueShop);
        }

        var query = from goods in aCustomer.Orders[0].OrderLines
                    select new
        {
            Name        = goods.Product.ProdName,
            Description = goods.Product.ProdDescription,
            Price       = goods.Product.ProdPrice,
            Qty         = goods.Quantity,
            Total       = "£" + Convert.ToString(goods.Quantity * goods.Product.ProdPrice),
            ProdImage   = goods.Product.ProdImage
        };

        subTotal     = CartFunctions.getSubTotal(aCustomer);
        cellSub.Text = "£" + Convert.ToString(subTotal);

        GridView1.DataSource = query;
        GridView1.DataBind();
        Session["Customer"] = aCustomer;

        Label lblCost = (Label)this.Master.FindControl("lblCost");

        lblCost.Text = CartFunctions.getSubTotal(aCustomer).ToString("C");

        Label lblItem = (Label)this.Master.FindControl("lblItems");

        lblItem.Text = CartFunctions.getNumItem(aCustomer).ToString() + " items";
    }
예제 #4
0
    //check to see if customer has increased  order numher
    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "AddItem")
        {
            // Retrieve the row index stored in the
            // CommandArgument property.
            int index = Convert.ToInt32(e.CommandArgument);

            // Retrieve the row that contains the button
            // from the Rows collection.
            GridViewRow row = GridView1.Rows[index];

            // Add code here to add the item to the shopping cart
            Customer aCustomer = (Customer)Session["Customer"];
            aCustomer.Orders[0].OrderLines[index].Quantity += 1;
            //display orderlines
            var query = from goods in aCustomer.Orders[0].OrderLines
                        select new
            {
                Name        = goods.Product.ProdName,
                Description = goods.Product.ProdDescription,
                Price       = goods.Product.ProdPrice,
                Qty         = goods.Quantity,
                Total       = "£" + Convert.ToString(goods.Quantity * goods.Product.ProdPrice),
                ProdImage   = goods.Product.ProdImage
            };

            subTotal       = CartFunctions.getSubTotal(aCustomer);
            cellSub.Text   = "£" + Convert.ToString(subTotal);
            total          = subTotal + shipping;
            cellTotal.Text = "£" + total;

            GridView1.DataSource = query;
            GridView1.DataBind();
            Session["Customer"] = aCustomer;

            Label lblCost = (Label)this.Master.FindControl("lblCost");
            lblCost.Text = CartFunctions.getSubTotal(aCustomer).ToString("C");

            Label lblItem = (Label)this.Master.FindControl("lblItems");
            lblItem.Text = CartFunctions.getNumItem(aCustomer).ToString() + " items";
        }

        //check to see if customer has decreased order numher
        if (e.CommandName == "RemoveItem")
        {
            // Retrieve the row index stored in the
            // CommandArgument property.
            int index = Convert.ToInt32(e.CommandArgument);

            // Retrieve the row that contains the button
            // from the Rows collection.
            GridViewRow row       = GridView1.Rows[index];
            Customer    aCustomer = (Customer)Session["Customer"];
            aCustomer.Orders[0].OrderLines[index].Quantity -= 1;
            //display orderlines
            if (aCustomer.Orders[0].OrderLines[index].Quantity == 0)
            {
                aCustomer = CartFunctions.removeItem(aCustomer, index);
                if (aCustomer.Orders[0].OrderLines.Count == 0)
                {
                    HyperLink continueShop = new HyperLink();
                    continueShop.NavigateUrl = "Shop.aspx";
                    continueShop.Text        = "Back to the Shop";
                    cartcontainer.InnerHtml  = "You have nothing in your cart" + " ";
                    cartcontainer.Controls.Add(continueShop);
                }
            }

            //display orderlines
            var query = from goods in aCustomer.Orders[0].OrderLines
                        select new
            {
                Name        = goods.Product.ProdName,
                Description = goods.Product.ProdDescription,
                Price       = "£" + goods.Product.ProdPrice,
                Qty         = goods.Quantity,
                Total       = "£" + Convert.ToString(goods.Quantity * goods.Product.ProdPrice),
                ProdImage   = goods.Product.ProdImage
            };

            subTotal       = CartFunctions.getSubTotal(aCustomer);
            cellSub.Text   = "£" + Convert.ToString(subTotal);
            total          = subTotal + shipping;
            cellTotal.Text = "£" + total;

            GridView1.DataSource = query;
            GridView1.DataBind();
            Session["Customer"] = aCustomer;

            Label lblCost = (Label)this.Master.FindControl("lblCost");
            lblCost.Text = CartFunctions.getSubTotal(aCustomer).ToString("C");

            Label lblItem = (Label)this.Master.FindControl("lblItems");
            lblItem.Text = CartFunctions.getNumItem(aCustomer).ToString() + " items";
        }
    }