コード例 #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=" + 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);
        }
    }
コード例 #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;
        }
    }