I got a login where depending of the type of user it will open a different menu but I dont know how to make it recognize the type without specifying it, this is the code I got:
private void btnaceptar_Click(object sender, EventArgs e) { if (txtusuario.Text == "" || txtcontraseña.Text == "") { MessageBox.Show("TODOS LOS CAMPOS DEBEN ESTAR LLENOS.", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); txtusuario.Clear(); txtusuario.Focus(); }
n = n - 1;
if (n <= 3 && n >= 0)
{
if (n == 1)
{
MessageBox.Show("Solo le quedan 1 intento, porfavor asegurese de poner los datos correctos!", "AVISO!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
MessageBox.Show("Usuario y/o contraseña incorrectos, verifique porfavor", "Error al ingresar datos.", MessageBoxButtons.OK, MessageBoxIcon.Error);
this.txtusuario.Clear();
this.txtcontraseña.Clear();
this.txtusuario.Focus();
}
else
{
SqlConnection miconexion = new SqlConnection(@"Data Source=USER-PC;Initial Catalog=dbpuntodeventa;Integrated Security=True");
miconexion.Open();
SqlCommand comando1 = new SqlCommand("select * from usuarios where usuario='" + txtusuario.Text + "'and contraseña='" + txtcontraseña.Text + "'", miconexion);
SqlDataReader Ejecuta = comando1.ExecuteReader();
if (Ejecuta.Read() == true)
{
MessageBox.Show("Bienvenido Administrador , Ingreso de datos correctos", "Ingreso exitoso!", MessageBoxButtons.OK, MessageBoxIcon.Information);
this.Hide();
frmmenuadmin frmprincipal = new frmmenuadmin();
frmprincipal.Show();
frmprincipal.lblid.Text = txtusuario.Text;
}
else
{
SqlConnection miconexion2 = new SqlConnection(@"Data Source=USER-PC;Initial Catalog=dbpuntodeventa;Integrated Security=True");
miconexion2.Open();
SqlCommand comando = new SqlCommand("select * from usuarios where usuario='" + txtusuario.Text + "'and contraseña='" + txtcontraseña.Text + "'", miconexion2);
SqlDataReader ejecutar1 = comando.ExecuteReader();
if (ejecutar1.Read() == true)
{
MessageBox.Show("Bienvenido Empleado , Ingreso de datos correctos", "Ingreso exitoso!", MessageBoxButtons.OK, MessageBoxIcon.Information);
this.Hide();
frmmenu frm2 = new frmmenu();
frm2.Show();
frm2.lblnombre.Text = txtusuario.Text;
}
else
{
if (n == 0)
{
MessageBox.Show("Error,se han agotado los intentos", "AVISO!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
Application.Exit();
}
MessageBox.Show("Usuario y/o contraseña incorrectos, verifique porfavor", "Error al ingresar datos.", MessageBoxButtons.OK, MessageBoxIcon.Error);
this.txtusuario.Clear();
this.txtcontraseña.Clear();
this.txtusuario.Focus();
}
}
}
}
}
}
}
for those who dont speack spanish, usuario means user and contraseña means password now I need to implement tipo which means type