Esempio n. 1
0
        protected void btnAddCC_Click(object sender, EventArgs e)
        {
            if (txtCCNum.Text.Length != 16)
            {
                lblCCNumMsg.Text = "Credit Card Number must be 16 characters long ";
            }

            if (txtCCV.Text.Length != 3)
            {
                lblCCVMsg.Text = "CCV must be 3 characters long";
            }

            if (txtCCExpiry.Text.Length != 4)
            {
                lblCCNumMsg.Text = "Credit Card Expiry must be  4 characters long";
            }

            if (txtCCNum.Text.Length == 16 && txtCCV.Text.Length == 3 && txtCCExpiry.Text.Length == 4)
            {
                CreditCardBLL creditCardBLL = new CreditCardBLL();
                int           checkCCard    = creditCardBLL.DoCheckCreditCardExists(txtCCNum.Text);

                if (checkCCard > 0)
                {
                    alertFailure.Visible = true;
                    lblFailure.Text      = "Credit Card Number exists. Please use another credit card";
                }

                else
                {
                    UserAccount user        = (UserAccount)Session["UserAccountObj"];
                    CustomerBLL customerBLL = new CustomerBLL();
                    Customer    customer    = customerBLL.DoRetrieveCustomerByID(user.UserId);

                    int result = creditCardBLL.DoCreateCreditCard(customer.CId, txtCCNum.Text, txtCCV.Text, txtCCExpiry.Text);

                    if (result > 0)
                    {
                        alertSuccess.Visible = true;

                        if (lblNoCreditCard.Text.Length > 0)
                        {
                            lblNoCreditCard.Text = "";
                        }
                    }

                    else
                    {
                        alertFailure.Visible = true;
                        lblFailure.Text      = "Unable to create credit card record";
                    }

                    //Refresh page
                    DataTable dt = new DataTable();
                    dt = creditCardBLL.DoRetrieveAllCustomerCreditCard(customer.CId);
                    gv_creditCard.DataSource = dt;
                    gv_creditCard.DataBind();
                }
            }
        }