Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using MySql.Data.MySqlClient;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace Ubar4.Datos
- {
- public class datosUsuario
- {
- public static bool Verificacion(string nombreUsuario) {
- Conexion conn = new Conexion();
- string sql = "SELECT `idUsuario`,`nombreUsuario` FROM `ubar`.`usuarios` WHERE nombreUsuario='" + nombreUsuario + "'";
- MySqlCommand command = new MySqlCommand(sql, conn.Conectar());
- int filasAfectadas = command.ExecuteNonQuery();
- if (filasAfectadas == 1)
- {
- MessageBox.Show("El nombre de usaurio ya existe, favor de escoger otro");
- conn.Desconectar();
- return false;
- }
- else { return true; }
- }
- public static bool RegistrarUsuario(string nombreUsuario) {
- try {
- Conexion conn= new Conexion();
- string sql = "INSERT INTO `ubar`.`usuarios`(`nombreUsuario`)VALUES('"+nombreUsuario+"')";
- MySqlCommand command = new MySqlCommand(sql,conn.Conectar());
- int filasAdfectadas = command.ExecuteNonQuery();
- if (filasAdfectadas == 1)
- {
- MessageBox.Show("Usaurio Agregado correctamente ");
- conn.Desconectar();
- return true;
- }
- else
- {
- MessageBox.Show("fallo en el registro de usaurio, intentelo nuevamente ");
- conn.Desconectar();
- return false;
- }
- }
- catch (Exception ex) {
- MessageBox.Show("Error de conexion a la base de datos:"+ex.Message);
- return false;
- }
- }
- public static string RetraerUsuario(int idUser) {
- try {
- Conexion conn = new Conexion();
- string sql = "SELECT `nombreUsuario` FROM `ubar`.`usuarios` WHERE idUsuario='"+idUser+"'";
- MySqlCommand command = new MySqlCommand(sql, conn.Conectar());
- var reader =command.ExecuteReader();
- while (reader.Read()) {
- var username=reader.GetString(0);
- return username;
- }
- return null;
- } catch (Exception ex) {
- MessageBox.Show("Error en base de datos" + ex);
- return null;
- }
- }
- public static bool ComprobarUsuario(string nombre) {
- Conexion conn = new Conexion();
- string sql = "SELECT `idUsuario`,`nombreUsuario` FROM `ubar`.`usuarios` WHERE nombreUsuario='" + nombre + "'";
- MySqlCommand command = new MySqlCommand(sql, conn.Conectar());
- int rowsAffected = command.ExecuteNonQuery();
- if (rowsAffected == 1)
- {
- MessageBox.Show("El nombre de usuario no existe, favor de registrarse");
- return false;
- }
- else {
- var reader = command.ExecuteReader();
- while (reader.Read())
- {
- int id = reader.GetInt32(0);
- string username = reader.GetString(1);
- Viajes viaje = new Viajes(id, username);
- viaje.ShowDialog();
- return true;
- }
- return false;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment