Advertisement
Guest User

Untitled

a guest
Nov 17th, 2017
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.46 KB | None | 0 0
  1. private void button1_Click(object sender, EventArgs e)
  2.         {
  3.             if (textBox_login.Text == "")
  4.                 MessageBox.Show("Por favor, insira um login");
  5.             else if (textBox_password.Text == "")
  6.                 MessageBox.Show("Por favor, insira uma senha");
  7.  
  8.             else if (comboBox_type.Text == "Administrador")
  9.             {
  10.                 SqlConnection con = new SqlConnection("Integrated Security=SSPI;Persist Security Info=False;User ID=DESKTOP-PI7D0K7\\SQLEXPRESS;Initial Catalog=trabalho_tp1_kaio_bruno;Data Source=DESKTOP-PI7D0K7\\SQLEXPRESS");
  11.                 SqlCommand cmd = new SqlCommand("select id, nome from admin where login=@login and senha=@senha", con);
  12.                 cmd.Parameters.Add("@login", SqlDbType.VarChar).Value = textBox_login.Text;
  13.                 cmd.Parameters.Add("@senha", SqlDbType.VarChar).Value = textBox_password.Text;
  14.  
  15.                 try
  16.                 {
  17.                     con.Open();
  18.                     SqlDataReader dr = cmd.ExecuteReader();
  19.                     if (dr.HasRows == false)
  20.                     {
  21.                         throw new Exception("Usuario Nao encontrado");
  22.                     }
  23.              
  24.                         dr.Read();
  25.  
  26.                         string nome;
  27.                         nome = Convert.ToString(dr["nome"]);
  28.  
  29.                         MessageBox.Show("Bem vindo, "+ nome);
  30.  
  31.                         tabadmin_create form3 = new tabadmin_create();
  32.                         this.Hide();
  33.                         form3.Show();
  34.                    
  35.                    
  36.                 }
  37.                 catch (Exception ex)
  38.                 {
  39.                     MessageBox.Show(ex.Message);
  40.                 }
  41.                 finally
  42.                 {
  43.                     con.Close();
  44.  
  45.                 }
  46.  
  47.  
  48.             }
  49.  
  50.             else if (comboBox_type.Text == "Aluno")
  51.             {
  52.                 SqlConnection con = new SqlConnection("Integrated Security=SSPI;Persist Security Info=False;User ID=DESKTOP-PI7D0K7\\SQLEXPRESS;Initial Catalog=trabalho_tp1_kaio_bruno;Data Source=DESKTOP-PI7D0K7\\SQLEXPRESS");
  53.                 SqlCommand cmd = new SqlCommand("select id, nome from participante where login=@login and senha=@senha", con);
  54.                 cmd.Parameters.Add("@login", SqlDbType.VarChar).Value = textBox_login.Text;
  55.                 cmd.Parameters.Add("@senha", SqlDbType.VarChar).Value = textBox_password.Text;
  56.  
  57.                 try
  58.                 {
  59.                     con.Open();
  60.                     SqlDataReader dr = cmd.ExecuteReader();
  61.  
  62.                     if (dr.HasRows == false)
  63.                     {
  64.                         throw new Exception("Usuario ou senha não encontrado.");
  65.                     }
  66.  
  67.                         dr.Read();
  68.  
  69.                         int id;
  70.                         string nome;
  71.  
  72.                         nome = Convert.ToString(dr["nome"]);
  73.                         id = Convert.ToInt32(dr["id"]);
  74.                         MessageBox.Show("Bem vindo, " + nome);
  75.  
  76.                         this.Hide();
  77.                         Aluno form = new Aluno();
  78.                         form.id = id;
  79.                         form.Show();
  80.                 }
  81.  
  82.                 catch (Exception ex)
  83.                 {
  84.                     MessageBox.Show(ex.Message);
  85.                 }
  86.                 finally
  87.                 {
  88.                     con.Close();
  89.  
  90.                 }
  91.  
  92.             }
  93.  
  94.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement