Exemplo n.º 1
0
    protected void Page_Load(object sender, EventArgs e)
    {
        Customer aCustomer = (Customer)Session["Customer"];

        //if its not a post back display orderlines
        if (!IsPostBack)
        {
            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
            };

            GridView1.DataSource = query;
            GridView1.DataBind();
        }
        //display totals
        subTotal       = CartFunctions.getSubTotal(aCustomer);
        shipping       = Convert.ToDouble(drpPostage.SelectedValue);
        cellSub.Text   = "£" + Convert.ToString(subTotal);
        total          = subTotal + shipping;
        cellTotal.Text = "£" + total;
    }
Exemplo n.º 2
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";
    }
Exemplo n.º 3
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
Exemplo n.º 4
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";
    }
Exemplo n.º 5
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";
        }
    }
Exemplo n.º 6
0
    protected void Page_Load(object sender, EventArgs e)
    {
        double subTotal = 0;
        double total    = 0;
        double shipping = 00;

        if (!IsPostBack)
        {
            NVPAPICaller payPalCaller = new NVPAPICaller();

            string retMsg   = "";
            string token    = "";
            string PayerID  = "";
            string foreName = "";
            string surName  = "";
            string email    = "";
            string address  = "";
            string postcode = "";
            string town     = "";

            NVPCodec decoder = new NVPCodec();
            token = Session["token"].ToString();

            bool ret = payPalCaller.GetCheckoutDetails(token, ref PayerID, ref decoder, ref retMsg);
            if (ret)
            {
                //get user information from papal
                Session["payerId"] = PayerID;

                foreName = decoder["FIRSTNAME"].ToString();
                surName  = decoder["LASTNAME"].ToString();
                address  = decoder["SHIPTOSTREET"].ToString();
                town     = decoder["SHIPTOCITY"].ToString();
                postcode = decoder["SHIPTOZIP"].ToString();
                email    = decoder["EMAIL"].ToString();

                //display user information
                lblFore.Text     = foreName;
                lblSur.Text      = surName;
                lblCity.Text     = town;
                lblEmail.Text    = email;
                lblPostCode.Text = postcode;
                lblAddress.Text  = address;


                //set customer object with information from paypal
                Customer aCustomer = (Customer)Session["Customer"];
                aCustomer.CityAddress   = town;
                aCustomer.Email         = email;
                aCustomer.FName         = foreName;
                aCustomer.SName         = surName;
                aCustomer.StreetAddress = address;
                aCustomer.PostCode      = postcode;


                // Verify total payment amount as set on CheckoutStart.aspx.
                try
                {
                    decimal paymentAmountOnCheckout = Convert.ToDecimal(Session["payment_amt"].ToString());
                    decimal paymentAmoutFromPayPal  = Convert.ToDecimal(decoder["AMT"].ToString());
                    shipping = Convert.ToDouble(decoder["SHIPPINGAMT"].ToString());
                    if (paymentAmountOnCheckout != paymentAmoutFromPayPal)
                    {
                        Response.Redirect("CheckoutError.aspx?" + "Desc=Amount%20total%20mismatch.");
                    }
                }
                catch (Exception)
                {
                    Response.Redirect("CheckoutError.aspx?" + "Desc=Amount%20total%20mismatch.");
                }

                // Display Order information.

                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
                };


                GridView1.DataSource = query;
                GridView1.DataBind();

                subTotal = CartFunctions.getSubTotal(aCustomer);

                cellSub.Text      = "£" + Convert.ToString(subTotal);
                total             = subTotal + shipping;
                cellTotal.Text    = "£" + total;
                cellShipping.Text = shipping.ToString();
            }
            else
            {
                Response.Redirect("CheckoutError.aspx?" + retMsg);
            }
        }
    }