Esempio n. 1
0
 protected void Page_Load(object sender, EventArgs e)
 {
     /// retrive cart object from session state on every postback
     cart = CartItemList.GetCart();
     //on initial page load, add cart items to list control
     if (!IsPostBack)
     {
         this.DisplayCart();
     }
 }
Esempio n. 2
0
        protected void btnCheckOut_Click(object sender, EventArgs e)
        {
            Session["cart"] = cart;



            Random rnd             = new Random();
            int    extensionNumber = rnd.Next(1, 2000000);

            Session["extensionNumber"] = extensionNumber;



            using (SqlConnection connection = new SqlConnection("Data Source = SQLEXPRESS; Initial Catalog = steveale_db; Integrated Security = True"))
            {
                using (SqlCommand command = new SqlCommand())
                {
                    command.Connection  = connection;
                    command.CommandType = CommandType.Text;
                    command.CommandText = "INSERT into LineItems(extension, ProductID, UnitPrice, Quantity)" +
                                          "VALUES (@extension, @ProductID, @UnitPrice, @Quantity)";
                    connection.Open();
                    for (int i = 0; i < CartItemList.GetCart().Count; i++)
                    {
                        command.Parameters.Clear();

                        command.Parameters.AddWithValue("@extension", extensionNumber);

                        command.Parameters.AddWithValue("@ProductID", cart[i].Product.ProductNumber.ToString());
                        command.Parameters.AddWithValue("@UnitPrice", Convert.ToDecimal(cart[i].Product.ProductPrice));
                        command.Parameters.AddWithValue("@Quantity", Convert.ToInt32(cart[i].Quantity));
                        command.ExecuteNonQuery();
                    }



                    connection.Close();
                }
            }


            Response.Redirect("PaymentMethod.aspx");
        }
Esempio n. 3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            cart = CartItemList.GetCart();


            lblSFName.Visible          = false;
            lblSLName.Visible          = false;
            lblShippingaddress.Visible = false;
            lblSAddress.Visible        = false;
            lblSCity.Visible           = false;
            lblSState.Visible          = false;
            lblSZip.Visible            = false;

            txtSAddress.Visible = false;
            txtSCity.Visible    = false;
            txtSFName.Visible   = false;
            txtSLName.Visible   = false;
            txtSZip.Visible     = false;
            ddlSStates.Visible  = false;
        }
Esempio n. 4
0
        protected void btnAddToCart_Click(object sender, EventArgs e)
        {
            string sessionAccount;

            try
            {
                sessionAccount = Session["sessionAccount"].ToString();
            }
            catch (NullReferenceException)
            {
                sessionAccount = "";
            }
            if (sessionAccount != "")
            {
                sessionAccount = Session["sessionAccount"].ToString();
            }

            if (sessionAccount == "")
            {
                Response.Redirect("LoginPage.aspx");
            }



            if (IsValid)
            {
                CartItemList cart     = CartItemList.GetCart();
                CartItem     cartItem = cart[selectedProduct.ProductNumber];

                if (cartItem == null)
                {
                    cart.AddItem(selectedProduct, Convert.ToInt32(ddlQuantityOrdered.SelectedItem.Text));
                }
                else
                {
                    cartItem.AddQuantity(Convert.ToInt32(ddlQuantityOrdered.SelectedItem.Text));
                }
            }
            Response.Redirect("~/Cart.aspx");
        }
Esempio n. 5
0
        protected void btnProceedOrderConfirm_Click(object sender, EventArgs e)
        {
            int extensionNumber = Convert.ToInt32(Session["extensionNumber"]);

            sessionAccount = Session["sessionAccount"].ToString();
            decimal Subtotal        = 0m;
            decimal ShippingCost    = 7.99m;
            decimal SalesTax        = 1.065m;
            decimal Total           = 0.0m;
            string  CreditCardType  = "";
            double  CardNumber      = 0;
            string  ExpirationMonth = "";
            string  ExpirationYear  = "";
            string  CvcCode         = "";


            CreditCardType  = ddlCreditCardType.Text.ToString();
            CardNumber      = Convert.ToDouble(txtCreditCardNumber.Text);
            ExpirationMonth = ddlExpMonth.Text.ToString();
            ExpirationYear  = ddlexpYear.Text.ToString();
            CvcCode         = txtcreditCardCVCcode.Text.ToString();

            int     tempquanity = 0;
            decimal tempPrice   = 0.0m;

            for (int i = 0; i < CartItemList.GetCart().Count; i++)
            {
                tempquanity = cart[i].Product.ProductQuantity;
                tempPrice   = cart[i].Product.ProductPrice;

                Subtotal += tempPrice * tempquanity;
            }
            Total = (Subtotal + ShippingCost) * SalesTax;

            Session["subtotalSession"] = Subtotal;
            Session["totalSession"]    = Total;
            Session["shippingSession"] = ShippingCost;
            Session["taxSession"]      = "6.5%";


            string query = "INSERT INTO Invoices(extension, OrderDate, Subtotal, CustEmail, ShippingCost, SalesTax, Total, CreditCardType, CardNumber, ExpirationMonth, ExpirationYear, CvcCode)" +
                           "Values('" + Subtotal + "', '" + sessionAccount + "', '" + ShippingCost + "', '" + SalesTax + "', '" + Total + "', '" + CreditCardType + "', '" + CardNumber + "', '" + ExpirationMonth + "', '" + ExpirationYear + "', '" + CvcCode + "')";

            using (SqlConnection connection = new SqlConnection("Data Source = SQLEXPRESS; Initial Catalog = steveale_db; Integrated Security = True"))
            {
                using (SqlCommand command = new SqlCommand())
                {
                    connection.Open();
                    command.Connection  = connection;
                    command.CommandType = CommandType.Text;
                    command.CommandText = "INSERT into Invoices (extension, OrderDate, Subtotal, CustEmail, ShippingCost, SalesTax, Total, CreditCardType, CardNumber, ExpirationMonth, ExpirationYear, CvcCode)" +
                                          "VALUES (@extension, @OrderDate, @Subtotal, @CustEmail, @ShippingCost, @SalesTax, @Total, @CreditCardType, @CardNumber, @ExpirationMonth, @ExpirationYear, @CvcCode)";
                    command.Parameters.AddWithValue("@extension", extensionNumber);

                    command.Parameters.AddWithValue("@OrderDate", DateTime.Now);
                    command.Parameters.AddWithValue("@Subtotal", Subtotal);
                    command.Parameters.AddWithValue("@CustEmail", sessionAccount);
                    command.Parameters.AddWithValue("@ShippingCost", ShippingCost);
                    command.Parameters.AddWithValue("@SalesTax", SalesTax);
                    command.Parameters.AddWithValue("@Total", Total);
                    command.Parameters.AddWithValue("@CreditCardType", CreditCardType);
                    command.Parameters.AddWithValue("@CardNumber", CardNumber);
                    command.Parameters.AddWithValue("@ExpirationMonth", ExpirationMonth);
                    command.Parameters.AddWithValue("@ExpirationYear", ExpirationYear);
                    command.Parameters.AddWithValue("@CvcCode", CvcCode);
                    command.ExecuteNonQuery();

                    connection.Close();
                }
            }
            Response.Redirect("OrderConfirmation.aspx");
        }