/// <summary> /// This method validates the dinner registration information entered by the user. /// If problems exist the user is prompted to fix them. /// If the information does not produce an error the information is saved as a session variable /// and user is directed to the checkout page. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> /// Aaron Copeland - 11/19/2012 /// Tested by Aaron Copeland - 11/28/2012 protected void btnCheckout_Click(object sender, EventArgs e) { // verifyDinnerRegistration BusinessTier bt = new BusinessTier(); Dictionary<String, String> dinnerRegInfo = new Dictionary<string, string>(); try { // variables for the party size calculation int numAdults; int numChildren; int numParty; // attempt to parse the number of adults and number of children Int32.TryParse(txtNumAdults.Text, out numAdults); Int32.TryParse(txtNumChildren.Text, out numChildren); // party size was properly calculated above numParty = numAdults + numChildren; // checks if the party size is zero or if the number of adults or children is a negative number if (numAdults <= 0 || numAdults < 0 || numChildren < 0) { lblError.Text = "Please enter a valid number for adults and children"; PresentationHelpers.FocusControlOnPageLoad(lblError.ClientID, this.Page); } else { // creates a dictionary with the registrants information as specified by the contract 11/28/2012 10:30am --AC dinnerRegInfo.Add("firstName", txtFirstName.Text); dinnerRegInfo.Add("lastName", txtLastName.Text); dinnerRegInfo.Add("suffix", txtSuffix.Text); dinnerRegInfo.Add("email", txtEmail.Text); dinnerRegInfo.Add("emailConfirm", txtConfirmEmail.Text); dinnerRegInfo.Add("phone", txtAreaCode.Text + txtPrefix.Text + txtLineNumber.Text); dinnerRegInfo.Add("numInParty", numParty.ToString()); dinnerRegInfo.Add("numChildren", numChildren.ToString()); dinnerRegInfo.Add("numAdults", numAdults.ToString()); dinnerRegInfo.Add("transactionID", Guid.NewGuid().ToString()); dinnerRegInfo.Add("cost", ((numChildren * Convert.ToDouble(lblChildPrice.Text)) + (numAdults * Convert.ToDouble(lblAdultPrice.Text))).ToString()); Session["email"] = txtEmail.Text; // sends the dictionary to the business tier to check the fields DataSet ds = bt.validateDinnerReg(dinnerRegInfo); // gets any errors returned if (ds.Tables[0].Rows.Count > 0) { String errorString = "Please fix the following items:</br>"; // Iterate through errors for (int i = 0; i < ds.Tables[0].Rows.Count; i++) errorString += ds.Tables[0].Rows[i][1] + "<br/>"; lblError.Text = errorString; PresentationHelpers.FocusControlOnPageLoad(lblError.ClientID, this.Page); } else { // no errors were returned Session["regInfo"] = dinnerRegInfo; // dictionary used as a session variable Session["eventID"] = Request["eventID"].ToString(); Response.Redirect("Checkout.aspx", false); } } } catch (Exception ex) { ErrorLog.logError(ex); Response.Redirect("Oops.aspx"); } }