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

        if (Request.Params["id"] != null)
        {
            // get the orderId
            int id = Convert.ToInt32(Request.Params["id"]);

            // load order info
            OrdersComponent orders = new OrdersComponent();
            Order o = orders.GetOrderById(id);

            // load catalog item info
            CatalogComponent cat = new CatalogComponent();
            BLL.Item it = cat.GetItemById(o.CatalogId);

            // fill the controls
            lblOrderNum.Text = Convert.ToString(o.ID);
            lblDate.Text = Convert.ToString(o.OrderDate);
            imgThumbPhoto.ImageUrl = it.ThumbPhoto;
            btnDescription.Text = it.Description;
            btnDescription.PostBackUrl = "itemdetails.aspx?item=" + o.CatalogId;
            lblItemPrice.Text = "$" + Convert.ToString(o.Price);
            lblTotalPrice.Text = lblItemPrice.Text;
            txtDetails.Text = o.Details;

            // update the page title
            Page.Title = "WSC :: Order Details for order #" + Convert.ToString(o.ID);
        }
    }
Exemplo n.º 2
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;
        }
    }
Exemplo n.º 3
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);
            }
        }
    }
Exemplo n.º 4
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;
        }
    }
 protected void btnSave_OnClick(object sender, EventArgs e)
 {
     var component = new CatalogComponent() {Name = txtComponentName.Text};
     component.Save();
 }