Beispiel #1
0
        public void Next_Click(object sender, EventArgs e)
        {
            string password1               = txtPassword1.Text.Trim();
            string password2               = txtPassword2.Text.Trim();
            int    townCityID              = -1;
            int    occupationSectorID      = -1;
            int    employmentLevelID       = -1;
            int    annualHouseholdIncomeID = -1;
            string gender = null;

            DateTime dob;

            if (!_emailRegex.IsMatch(txtEmail.Text))
            {
                ValidationMessage.Text = "Please enter a valid e-mail address.";
                return;
            }
            else
            {
                ValidationMessage.Text = "";
            }

            if (password1 != password2)
            {
                ValidationMessage.Text = "Passwords do not match";
                return;
            }
            else
            {
                ValidationMessage.Text = "";
            }

            if (!rbGenderFemale.Checked && !rbGenderMale.Checked)
            {
                ValidationMessage.Text = "Please select your gender";
                return;
            }
            else
            {
                gender = rbGenderFemale.Checked ? "female" : "male";
                ValidationMessage.Text = "";
            }

            try
            {
                dob = new DateTime(int.Parse(dobYear.SelectedValue), int.Parse(dobMonth.SelectedValue), int.Parse(dobDay.SelectedValue));
                ValidationMessage.Text = "";
            }
            catch
            {
                ValidationMessage.Text = "Please enter a valid Date of Birth";
                return;
            }

            if (ddlCountry.SelectedValue == "-1")
            {
                ValidationMessage.Text = "Please select your country";
                return;
            }
            else
            {
                ValidationMessage.Text = "";
            }

            if (ddlState.Visible && ddlState.SelectedValue == "-1")
            {
                ValidationMessage.Text = "Please select your state";
                return;
            }
            else
            {
                ValidationMessage.Text = "";
            }

            if (!int.TryParse(ddlTownCities.SelectedValue, out townCityID) || ddlTownCities.SelectedValue == "-1")
            {
                ValidationMessage.Text = "Please select your town or city";
                return;
            }
            else
            {
                ValidationMessage.Text = "";
            }

            if (!int.TryParse(ddlSector.SelectedValue, out occupationSectorID) || ddlSector.SelectedValue == "-1")
            {
                ValidationMessage.Text = "Please select your occupation sector";
                return;
            }
            else
            {
                ValidationMessage.Text = "";
            }

            if (!int.TryParse(ddlLevel.SelectedValue, out employmentLevelID) || ddlLevel.SelectedValue == "-1")
            {
                ValidationMessage.Text = "Please select your employment level";
                return;
            }
            else
            {
                ValidationMessage.Text = "";
            }

            if (!int.TryParse(ddlIncome.SelectedValue, out annualHouseholdIncomeID) || ddlIncome.SelectedValue == "-1")
            {
                ValidationMessage.Text = "Please select your Annual Household Income";
                return;
            }
            else
            {
                ValidationMessage.Text = "";
            }

            // all inputs are ok

            bool     bEmailExists = false;
            BLClient client       = null;

            try
            {
                client = new BLClient();

                bEmailExists = client.EditUserDetails(((User)Session["User"]).UserID, txtEmail.Text, password1, txtFirstName.Text, txtLastName.Text,
                                                      gender, dob, townCityID, occupationSectorID, employmentLevelID, annualHouseholdIncomeID);
            }
            finally
            {
                if (client != null)
                {
                    client.Dispose();
                }
            }

            if (bEmailExists)
            {
                ValidationMessage.Text = "This e-mail address already exists on our system.";
                return;
            }
            else
            {
                ValidationMessage.Text = "";
            }

            Response.Redirect("Home.aspx");
        }