Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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:UsersBrenoDocumentsVisual Studio 2013ProjectsPesadaoFinalPesadaoFinalbdpesadao_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();
- }
- }
- }
- novoLogin.Parameters.Add(@usuario, SqlDbType.VarChar).Value = usuario;
- novoLogin.Parameters.Add(@senha, SqlDbType.VarChar).Value = senha;
- novoLogin.Parameters.Add("@usuario", SqlDbType.VarChar).Value = usuario;
- novoLogin.Parameters.Add("@senha", SqlDbType.VarChar).Value = senha;
- int rs = (int)novoLogin.ExecuteScalar();
- if (rs > 0)
- {
- verCargo = novoLogin.ExecuteReader();
- cargo = verCargo[7].ToString(); \ <<--------- aqui
- frmDiretor novoForm = new frmDiretor();
- novoForm.Show(); // ou dependendo de como você fizer novoForm.ShowDialog();
- this.Dispose();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement