Metziop

Untitled

Jul 27th, 2022
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.85 KB | None | 0 0
  1. using MySql.Data.MySqlClient;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using System.Windows.Forms;
  8.  
  9. namespace Ubar4.Datos
  10. {
  11. public class datosUsuario
  12. {
  13.  
  14.  
  15. public static bool Verificacion(string nombreUsuario) {
  16. Conexion conn = new Conexion();
  17. string sql = "SELECT `idUsuario`,`nombreUsuario` FROM `ubar`.`usuarios` WHERE nombreUsuario='" + nombreUsuario + "'";
  18. MySqlCommand command = new MySqlCommand(sql, conn.Conectar());
  19. int filasAfectadas = command.ExecuteNonQuery();
  20. if (filasAfectadas == 1)
  21. {
  22. MessageBox.Show("El nombre de usaurio ya existe, favor de escoger otro");
  23. conn.Desconectar();
  24. return false;
  25.  
  26. }
  27. else { return true; }
  28. }
  29. public static bool RegistrarUsuario(string nombreUsuario) {
  30. try {
  31. Conexion conn= new Conexion();
  32. string sql = "INSERT INTO `ubar`.`usuarios`(`nombreUsuario`)VALUES('"+nombreUsuario+"')";
  33.  
  34. MySqlCommand command = new MySqlCommand(sql,conn.Conectar());
  35.  
  36. int filasAdfectadas = command.ExecuteNonQuery();
  37.  
  38. if (filasAdfectadas == 1)
  39. {
  40. MessageBox.Show("Usaurio Agregado correctamente ");
  41. conn.Desconectar();
  42. return true;
  43. }
  44. else
  45. {
  46. MessageBox.Show("fallo en el registro de usaurio, intentelo nuevamente ");
  47. conn.Desconectar();
  48. return false;
  49. }
  50.  
  51.  
  52. }
  53. catch (Exception ex) {
  54. MessageBox.Show("Error de conexion a la base de datos:"+ex.Message);
  55. return false;
  56. }
  57. }
  58.  
  59. public static string RetraerUsuario(int idUser) {
  60. try {
  61. Conexion conn = new Conexion();
  62. string sql = "SELECT `nombreUsuario` FROM `ubar`.`usuarios` WHERE idUsuario='"+idUser+"'";
  63. MySqlCommand command = new MySqlCommand(sql, conn.Conectar());
  64. var reader =command.ExecuteReader();
  65. while (reader.Read()) {
  66.  
  67. var username=reader.GetString(0);
  68. return username;
  69. }
  70. return null;
  71.  
  72.  
  73. } catch (Exception ex) {
  74. MessageBox.Show("Error en base de datos" + ex);
  75. return null;
  76.  
  77. }
  78. }
  79. public static bool ComprobarUsuario(string nombre) {
  80. Conexion conn = new Conexion();
  81. string sql = "SELECT `idUsuario`,`nombreUsuario` FROM `ubar`.`usuarios` WHERE nombreUsuario='" + nombre + "'";
  82. MySqlCommand command = new MySqlCommand(sql, conn.Conectar());
  83. int rowsAffected = command.ExecuteNonQuery();
  84.  
  85. if (rowsAffected == 1)
  86. {
  87. MessageBox.Show("El nombre de usuario no existe, favor de registrarse");
  88. return false;
  89. }
  90. else {
  91. var reader = command.ExecuteReader();
  92. while (reader.Read())
  93. {
  94. int id = reader.GetInt32(0);
  95. string username = reader.GetString(1);
  96.  
  97.  
  98. Viajes viaje = new Viajes(id, username);
  99. viaje.ShowDialog();
  100. return true;
  101.  
  102. }
  103. return false;
  104.  
  105. }
  106.  
  107. }
  108.  
  109. }
  110. }
Advertisement
Add Comment
Please, Sign In to add comment