protected void ObjectDataSource1_Selecting(object sender, ObjectDataSourceSelectingEventArgs e)
 {
     // get the clientId to fill the grid w/ orders
     UsersComponent users = new UsersComponent();
     BLL.User u = users.GetUserByName(Request.Cookies["userName"].Value);
     e.InputParameters["id"] = u.ClientId;
 }
    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;
        }
    }
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        // hide error messages
        lblNotValid.Visible = false;
        lblEmptyTextBox.Visible = false;

        // verify username & password textboxes are not empty
        if ((txtUserName.Text == "") || (txtPassword.Text == ""))
        {
            // either username or password textbox was empty
            lblEmptyTextBox.Visible = true;
        }
        else
        {
            // validate username/password
            UsersComponent users = new UsersComponent();
            BLL.User user = users.ValidateLogin(txtUserName.Text, txtPassword.Text);

            if (user != null) // a null user means the username/password combination was not in the DB
            {
                // set the cookie to remember user for 2 hours
                Response.Cookies["userName"].Value = user.Name;
                Response.Cookies["userName"].Expires = DateTime.Now.AddHours(2);
                // send browser back to previous page
                if (Request.Params["ret"] != null)
                {
                    String qStr = Request.QueryString["ret"];
                    // we must re-assemble the query string
                    if (Request.QueryString.Count > 1)
                        qStr += "?";
                    for (int i = 1; i < Request.QueryString.Count; i++)
                    {
                        qStr += Request.QueryString.GetKey(i) + "=" + Request.QueryString.Get(i) + "&";
                    }
                    qStr = qStr.TrimEnd('&');
                    Response.Redirect(qStr);
                }
                else
                {
                    Response.Redirect("default.aspx");
                }
            }
            else
            {
                // credentials are not valid
                lblNotValid.Visible = true;
            }
        }
    }
 protected void btnChangePassword_Click(object sender, EventArgs e)
 {
     // make sure password textboxes are not empty
     if ((txtCurrentPassword.Text == "") || (txtNewPassword1.Text == "") || (txtNewPassword2.Text == ""))
     {
         lblPasswordMessage.Text = "Passwords cannot be blank. Please try again.";
         lblPasswordMessage.ForeColor = System.Drawing.Color.Red;
         lblPasswordMessage.Visible = true;
     }
     // make sure new passwords match
     else if (!String.Equals(txtNewPassword1.Text, txtNewPassword2.Text))
     {
         lblPasswordMessage.Text = "New passwords must match. Please try again.";
         lblPasswordMessage.ForeColor = System.Drawing.Color.Red;
         lblPasswordMessage.Visible = true;
     }
     // good to go
     else
     {
         UsersComponent users = new UsersComponent();
         BLL.User u = users.GetUserByName(Request.Cookies["userName"].Value);
         // verify current password
         if (!String.Equals(u.Password, txtCurrentPassword.Text))
         {
             lblPasswordMessage.Text = "Current Password is incorrect. Please try again.";
             lblPasswordMessage.ForeColor = System.Drawing.Color.Red;
             lblPasswordMessage.Visible = true;
         }
         // good to go; change password
         else
         {
             u.Password = txtNewPassword1.Text;
             int success = users.UpdateUser(u);
             if (success > 0)
             {
                 lblPasswordMessage.Text = "Password successfully changed.";
                 lblPasswordMessage.Visible = true;
             }
         }
     }
 }