Advertisement
Guest User

Untitled

a guest
Dec 22nd, 2014
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.45 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using System.Data.SqlClient;
  11.  
  12. namespace PesadaoFinal
  13. {
  14. public partial class frmLogin : Form
  15. {
  16.  
  17. SqlConnection conn = null;
  18. private string conexao = @"Data Source=(LocalDB)v11.0;AttachDbFilename=C:UsersBrenoDocumentsVisual Studio 2013ProjectsPesadaoFinalPesadaoFinalbdpesadao_db.mdf;Integrated Security=True;Connect Timeout=30";
  19. private string consulta = string.Empty;
  20.  
  21. public frmLogin()
  22. {
  23. InitializeComponent();
  24. }
  25. public void logar(){
  26.  
  27.  
  28. conn= new SqlConnection(conexao);
  29.  
  30. try{
  31. string usuario, senha, cargo;
  32.  
  33. usuario = txtUsu.Text;
  34. senha=txtSenha.Text;
  35. SqlDataReader verCargo = null;
  36.  
  37.  
  38. if(usuario==string.Empty && senha==string.Empty){
  39.  
  40. MessageBox.Show("Usuário e senha devem ser digitados!");
  41. }
  42. else if (usuario != null && senha != null)
  43. {
  44. consulta = @"SELECT COUNT(cpf) FROM funcionarios WHERE login = @usuario AND senha = @senha";
  45. SqlCommand novoLogin = new SqlCommand(consulta, conn);
  46. novoLogin.Parameters.Add(@usuario, SqlDbType.VarChar).Value = usuario;
  47. novoLogin.Parameters.Add(@senha, SqlDbType.VarChar).Value = senha;
  48.  
  49. conn.Open();
  50.  
  51.  
  52. int rs = (int)novoLogin.ExecuteScalar();
  53. if (rs > 0)
  54. {
  55. verCargo = novoLogin.ExecuteReader();
  56. cargo = verCargo[7].ToString();
  57. if (cargo == "funcionario")
  58. {
  59. formFunc novoForm = new formFunc();
  60. this.Dispose();
  61.  
  62. } if (cargo == "diretor")
  63. {
  64. frmDiretor novoForm = new frmDiretor();
  65. this.Dispose();
  66.  
  67. } if (cargo == "TI")
  68. {
  69. formTI novoForm = new formTI();
  70. this.Dispose();
  71.  
  72.  
  73. }
  74. else
  75. {
  76. MessageBox.Show("Usuário ou Senha inválidos!");
  77. }
  78. }
  79.  
  80. }
  81.  
  82.  
  83. }catch(SqlException erroBD){
  84. MessageBox.Show(erroBD +"Erro no banco");
  85.  
  86. }
  87.  
  88.  
  89. }
  90. private void frmLogin_Load(object sender, EventArgs e)
  91. {
  92.  
  93.  
  94. }
  95.  
  96. private void btnLogar_Click(object sender, EventArgs e)
  97. {
  98. logar();
  99. }
  100. }
  101. }
  102.  
  103. novoLogin.Parameters.Add(@usuario, SqlDbType.VarChar).Value = usuario;
  104. novoLogin.Parameters.Add(@senha, SqlDbType.VarChar).Value = senha;
  105.  
  106. novoLogin.Parameters.Add("@usuario", SqlDbType.VarChar).Value = usuario;
  107. novoLogin.Parameters.Add("@senha", SqlDbType.VarChar).Value = senha;
  108.  
  109. int rs = (int)novoLogin.ExecuteScalar();
  110. if (rs > 0)
  111. {
  112. verCargo = novoLogin.ExecuteReader();
  113. cargo = verCargo[7].ToString(); \ <<--------- aqui
  114.  
  115. frmDiretor novoForm = new frmDiretor();
  116. novoForm.Show(); // ou dependendo de como você fizer novoForm.ShowDialog();
  117. this.Dispose();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement