Esempio n. 1
0
    protected void Page_Load(object sender, EventArgs e)
    {
        // make sure user is logged in
        if (Request.Cookies["userName"] == null)
        {
            Response.Redirect("login.aspx?ret=order.aspx");
        }

        if (!IsPostBack)
        {
            // get the cart
            CartsComponent cComp = new CartsComponent();
            Cart c = cComp.GetCartByUserName(Request.Cookies["userName"].Value);

            // get the item's info
            CatalogComponent catalog = new CatalogComponent();
            Item it = catalog.GetItemById(c.CatalogId);

            // display the catalog item
            imgThumbPhoto.ImageUrl = it.ThumbPhoto;
            lblDescription.Text = it.Description;
            lblItemPrice.Text = "$" + Convert.ToString(it.Price);
            txtDetails.Text = c.Details;
            // since our cart only can contain 1 item, just use the item's price for total price
            lblTotalPrice.Text = lblItemPrice.Text;
        }
    }
Esempio n. 2
0
    protected void btnEmptyCart_Click(object sender, EventArgs e)
    {
        // delete this user's cart
        CartsComponent cComp = new CartsComponent();
        cComp.DeleteCart(Request.Cookies["userName"].Value);
        String str = txtDetails.Text;

        Response.Redirect("cart.aspx");
    }
Esempio n. 3
0
    protected void btnOrder_Click(object sender, EventArgs e)
    {
        // validate payment info
        if (ValidatePayment())
        {
            // get the cart
            CartsComponent cComp = new CartsComponent();
            Cart c = cComp.GetCartByUserName(Request.Cookies["userName"].Value);

            // get the user
            UsersComponent users = new UsersComponent();
            BLL.User u = users.GetUserByName(Request.Cookies["userName"].Value);

            // get the catalog
            CatalogComponent catalog = new CatalogComponent();
            Item it = catalog.GetItemById(c.CatalogId);

            // create a payment
            PaymentsComponent pmts = new PaymentsComponent();
            Payment pmt = new Payment();
            pmt.CardholderName = txtName.Text;
            pmt.CardNumber = txtNumber.Text;
            pmt.CardType = ddlType.SelectedValue;
            // make expiration date
            int month = Convert.ToInt32(ddlMonth.SelectedValue);
            int year = Convert.ToInt32(ddlYear.SelectedValue);
            int day = DateTime.DaysInMonth(year, month);
            DateTime dt = Convert.ToDateTime(month + "-" + day + "-" + year);
            pmt.CardExpiration = dt;
            // save the payment
            int pmtId = pmts.InsertPayment(pmt);

            // create the order
            OrdersComponent orders = new OrdersComponent();
            Order o = new Order();
            o.CatalogId = c.CatalogId;
            o.ClientId = u.ClientId;
            o.Details = c.Details;
            o.PaymentId = pmtId;
            o.Price = it.Price;
            o.OrderDate = DateTime.Now;
            // save the order
            int orderId = orders.InsertOrder(o);

            // delete the cart
            cComp.DeleteCart(c);

            // display results to user
            lblOrderNum.Text = Convert.ToString(orderId);
            pnlCC.Visible = false;
            pnlSuccess.Visible = true;
            pnlTopLabels.Visible = false;
        }
    }
Esempio n. 4
0
    protected void Page_Load(object sender, EventArgs e)
    {
        // make sure user is logged in
        if (Request.Cookies["userName"] == null)
        {
            String extra = "";
            if (Request.QueryString["item"] != null)
            {
                extra = "&item=" + Request.QueryString["item"];
            }
            Response.Redirect("login.aspx?ret=cart.aspx" + extra);
        }

        if (!IsPostBack) // don't reload controls/data if not necessary
        {
            CartsComponent cComp = new CartsComponent();
            Cart c = cComp.GetCartByUserName(Request.Cookies["userName"].Value);

            // is user creating a new cart?
            if (Request.Params["item"] != null)
            {
                //CartsComponent cComp = new CartsComponent();
                //Cart c = cComp.GetCartByUserName(Request.Cookies["userName"].Value);

                // if a cart is already in database, then delete it
                if (c != null)
                {
                    cComp.DeleteCart(c);
                }

                // now, add item to cart
                c = new Cart();
                c.UserName = Request.Cookies["userName"].Value;
                c.CatalogId = Convert.ToInt32(Request.Params["item"]);
                cComp.InsertCart(c);
            }

            // show user's cart, if any
            if (c != null)
            {
                // get the item's info
                CatalogComponent catalog = new CatalogComponent();
                Item it = catalog.GetItemById(c.CatalogId);
                // display the catalog item
                imgThumbPhoto.ImageUrl = it.ThumbPhoto;
                lblDescription.Text = it.Description;
                lblItemPrice.Text = "$" + Convert.ToString(it.Price);
                txtDetails.Text = c.Details;
                // since our cart only can contain 1 item, just use the item's price for total price
                lblTotalPrice.Text = lblItemPrice.Text;

                // show cart contents
                SetVisibility(true);
            }
            else
            {
                // show 'cart empty'
                SetVisibility(false);
            }
        }
    }
Esempio n. 5
0
 private void SaveCart()
 {
     CartsComponent cComp = new CartsComponent();
     Cart c = cComp.GetCartByUserName(Request.Cookies["userName"].Value);
     c.Details = txtDetails.Text;
     cComp.UpdateCart(c);
 }