protected void btnNuevaClave_Click(object sender, EventArgs e) { try { if (!string.IsNullOrEmpty(txtUsu.Text)) { SqlCommand sc1 = new SqlCommand("select username from usuario where username=@usu", cn.getConexion()); sc1.Parameters.AddWithValue("@usu", txtUsu.Text); cn.Conectar(); SqlDataAdapter sa1 = new SqlDataAdapter(sc1); DataTable dt = new DataTable(); sa1.Fill(dt); cn.Cerrar(); if (dt.Rows.Count > 0) { SqlCommand sc = new SqlCommand("select email, username, id from usuario where username=@usu", cn.getConexion()); sc.Parameters.AddWithValue("@usu", txtUsu.Text); cn.Conectar(); SqlDataReader sa = sc.ExecuteReader(); sa.Read(); email = sa["email"].ToString(); usu = sa["username"].ToString(); idUsuario = sa["id"].ToString(); cn.Cerrar(); ConfigSMTP smtp = new ConfigSMTP(); smtp.enviarClave(email, usu); if (!string.IsNullOrEmpty(mensaje)) { lblError.Text = mensaje; lblError.Visible = true; return; } SqlCommand sc2 = new SqlCommand("insert into solicitudClave values (@usuario, @fecha, 0)", cn.getConexion()); sc2.Parameters.AddWithValue("@usuario", idUsuario.ToString()); sc2.Parameters.AddWithValue("@fecha", DateTime.Today); cn.Conectar(); sc2.ExecuteNonQuery(); cn.Cerrar(); lblAviso.Text = "Su solicitud fue registrada. Verifique su correo."; lblAviso.Visible = true; } else { lblError.Text = "El usuario es erróneo o no está registrado"; lblError.Visible = true; return; } } else { lblError.Text = "Debe ingresar un usuario."; lblError.Visible = true; return; } } catch (Exception x) { lblError.Text = "Ha ocurrido un error inesperado."; lblError.Visible = true; ConfigSMTP smtp = new ConfigSMTP(); smtp.enviarError(x.Message.ToString(), Request.Url.ToString(), Session["username"].ToString(), "BTNNUEVACLAVE"); return; } }