示例#1
0
        protected void registrationController(object sender, EventArgs e)
        {
            registrationErrorHandler regHandler = new registrationErrorHandler();

            if (regUserName.Text == "")
            {
                regHandler.emptyUserName();
            }
            if (regPassword.Text == "")
            {
                regHandler.emptyPassword();
            }
            if (regRealName.Text == "")
            {
                regHandler.emptyRealName();
            }

            if (regEmail.Text == "")
            {
                regHandler.emptyEmail();
            }
            else if (!regEmail.Text.Contains("@"))
            {
                regHandler.invalidEmail();
            }

            if (regPhone.Text == "")
            {
                regHandler.emptyPhoneNumber();
            }
            if (!regPhone.Text.All(char.IsDigit))
            {
                regHandler.invalidPhoneNumber();
            }
            if (regDescription.Text == "")
            {
                regHandler.emptyDescription();
            }

            // Check username exists
            SqlConnection con    = new SqlConnection(ConfigurationManager.ConnectionStrings["vetoTours"].ToString());
            SqlCommand    cmd    = null;
            SqlDataReader reader = null;

            con.Open();
            string query = "SELECT * FROM users WHERE userID='" + regUserName.Text + "';";

            cmd    = new SqlCommand(query, con);
            reader = cmd.ExecuteReader();
            if (reader.Read())
            {
                if (reader.GetString(0) == regUserName.Text)
                {
                    regHandler.userNameExists();
                }
            }
            con.Close();

            if (regHandler.error == "")
            {
                user newUser = new user(regUserName.Text, regPassword.Text, regRealName.Text, regEmail.Text, int.Parse(regPhone.Text), regDescription.Text, 0);
                newUser.createAccount();
                Session["regSuccess"] = "true";

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

            else
            {
                generalDialog.InnerHtml = regHandler.error;
                generalDialog.Visible   = true;
            }
        }