protected void btnRegistrar_Click(object sender, EventArgs e) { try { if (Session["username"] == null) { Session["error"] = "Primero debe iniciar sesión"; Response.Redirect("login.aspx"); } cn.Conectar(); SqlCommand q = new SqlCommand("select username from usuario", cn.getConexion()); SqlDataReader dr = q.ExecuteReader(); dr.Read(); usu = dr["username"].ToString(); cn.Cerrar(); SqlCommand cmd = new SqlCommand("insert into usuario (fecRegistro, username, clave, nombre, email, idPerfil) values (getDate(), @usu, @clave, @nom, @email, @perfil)", cn.getConexion()); cmd.Parameters.AddWithValue("@usu", txtUsuario.Text); cmd.Parameters.AddWithValue("@clave", pwd2); cmd.Parameters.AddWithValue("@nom", txtNom.Text); cmd.Parameters.AddWithValue("@email", txtEmail.Text); cmd.Parameters.AddWithValue("@perfil", int.Parse(cboPerfil.SelectedValue.ToString())); if (!string.IsNullOrEmpty(txtUsuario.Text)) { cn.Conectar(); cmd.ExecuteNonQuery(); ConfigSMTP cs = new ConfigSMTP(); cs.enviar(txtEmail.Text, txtUsuario.Text, pwd1); cn.Cerrar(); lblError.Visible = false; lblCorrecto.Text = "Usuario registrado exitosamente."; lblCorrecto.Visible = true; txtEmail.Text = ""; txtNom.Text = ""; txtUsuario.Text = ""; } else { lblCorrecto.Visible = false; lblError.Text = "El usuario es requerido."; lblError.Visible = true; } }catch (Exception x) { lblError.Text = "Ha ocurrido un error inesperado. Comuniquese con Soporte Técnico."; lblError.Visible = true; if (Session["username"] != null) { ConfigSMTP smtp = new ConfigSMTP(); smtp.enviarError(x.Message.ToString(), Request.Url.ToString(), Session["username"].ToString(), "BTNREGISTRAR"); } return; } }