Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void button1_Click(object sender, EventArgs e)
- {
- if (textBox_login.Text == "")
- MessageBox.Show("Por favor, insira um login");
- else if (textBox_password.Text == "")
- MessageBox.Show("Por favor, insira uma senha");
- else if (comboBox_type.Text == "Administrador")
- {
- 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");
- SqlCommand cmd = new SqlCommand("select id, nome from admin where login=@login and senha=@senha", con);
- cmd.Parameters.Add("@login", SqlDbType.VarChar).Value = textBox_login.Text;
- cmd.Parameters.Add("@senha", SqlDbType.VarChar).Value = textBox_password.Text;
- try
- {
- con.Open();
- SqlDataReader dr = cmd.ExecuteReader();
- if (dr.HasRows == false)
- {
- throw new Exception("Usuario Nao encontrado");
- }
- dr.Read();
- string nome;
- nome = Convert.ToString(dr["nome"]);
- MessageBox.Show("Bem vindo, "+ nome);
- tabadmin_create form3 = new tabadmin_create();
- this.Hide();
- form3.Show();
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message);
- }
- finally
- {
- con.Close();
- }
- }
- else if (comboBox_type.Text == "Aluno")
- {
- 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");
- SqlCommand cmd = new SqlCommand("select id, nome from participante where login=@login and senha=@senha", con);
- cmd.Parameters.Add("@login", SqlDbType.VarChar).Value = textBox_login.Text;
- cmd.Parameters.Add("@senha", SqlDbType.VarChar).Value = textBox_password.Text;
- try
- {
- con.Open();
- SqlDataReader dr = cmd.ExecuteReader();
- if (dr.HasRows == false)
- {
- throw new Exception("Usuario ou senha não encontrado.");
- }
- dr.Read();
- int id;
- string nome;
- nome = Convert.ToString(dr["nome"]);
- id = Convert.ToInt32(dr["id"]);
- MessageBox.Show("Bem vindo, " + nome);
- this.Hide();
- Aluno form = new Aluno();
- form.id = id;
- form.Show();
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message);
- }
- finally
- {
- con.Close();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement