0
I am developing a service registration, the first screen is the login and I need to take the position of the user who logged in and indicate a form for it, my code ta thus:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace PesadaoFinal
{
public partial class frmLogin : Form
{
SqlConnection conn = null;
private string conexao = @"Data Source=(LocalDB)\v11.0;AttachDbFilename=C:\Users\Breno\Documents\Visual Studio 2013\Projects\PesadaoFinal\PesadaoFinal\bd\pesadao_db.mdf;Integrated Security=True;Connect Timeout=30";
private string consulta = string.Empty;
public frmLogin()
{
InitializeComponent();
}
public void logar(){
conn= new SqlConnection(conexao);
try{
string usuario, senha, cargo;
usuario = txtUsu.Text;
senha=txtSenha.Text;
SqlDataReader verCargo = null;
if(usuario==string.Empty && senha==string.Empty){
MessageBox.Show("Usuário e senha devem ser digitados!");
}
else if (usuario != null && senha != null)
{
consulta = @"SELECT COUNT(cpf) FROM funcionarios WHERE login = @usuario AND senha = @senha";
SqlCommand novoLogin = new SqlCommand(consulta, conn);
novoLogin.Parameters.Add(@usuario, SqlDbType.VarChar).Value = usuario;
novoLogin.Parameters.Add(@senha, SqlDbType.VarChar).Value = senha;
conn.Open();
int rs = (int)novoLogin.ExecuteScalar();
if (rs > 0)
{
verCargo = novoLogin.ExecuteReader();
cargo = verCargo[7].ToString();
if (cargo == "funcionario")
{
formFunc novoForm = new formFunc();
this.Dispose();
} if (cargo == "diretor")
{
frmDiretor novoForm = new frmDiretor();
this.Dispose();
} if (cargo == "TI")
{
formTI novoForm = new formTI();
this.Dispose();
}
else
{
MessageBox.Show("Usuário ou Senha inválidos!");
}
}
}
}catch(SqlException erroBD){
MessageBox.Show(erroBD +"Erro no banco");
}
}
private void frmLogin_Load(object sender, EventArgs e)
{
}
private void btnLogar_Click(object sender, EventArgs e)
{
logar();
}
}
}
and the error message you’re giving is this:
You can put in your question code examples of what you have so far?
– Leonel Sanches da Silva
will be only two types of form? I did not understand very well, you could describe how should be the result?
– Jovita
Gypsy, I erased all my code to start over, I was having a lot of problems. Jovita, would be basically 3 types of Forms, 1 that would allow the "director" register and delete users and do everything else, another that would be for the employee register the services and another pro "technical", inform the bank path, when there was some change.
– brenoguto
I rephrased my question and gave real examples.
– brenoguto