private void button1_Click(object sender, EventArgs e) { /* * MainFormGiaoVien mainFormGiaoVien = new MainFormGiaoVien("GV001"); * mainFormGiaoVien.Show(); */ mainFrmSinhVien mainFrmSinhVien = new mainFrmSinhVien("SV001"); mainFrmSinhVien.Show(); }
private void btnDangNhap_Click(object sender, EventArgs e) { myDB mydb = new myDB(); if (rdoSinhVien.Checked) { SqlCommand command = new SqlCommand("select * from sinhvien where tentaikhoansv = @tk and matkhausv = @mk", mydb.getConnection); command.Parameters.Add("@tk", SqlDbType.VarChar).Value = TextBox_Username.Text; command.Parameters.Add("@mk", SqlDbType.VarChar).Value = TextBox_Password.Text; SqlDataAdapter adapter = new SqlDataAdapter(command); DataTable dt = new DataTable(); adapter.Fill(dt); if (dt.Rows.Count > 0) { mainFrmSinhVien mainSV = new mainFrmSinhVien(dt.Rows[0][0].ToString()); Visible = false; mainSV.ShowDialog(); } else { MessageBox.Show("Sai Tài khoản hoặc Mật khẩu", "Login Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else if (rdoGiaoVien.Checked) { SqlCommand command = new SqlCommand("select * from giaovien where tentaikhoangv = @tk and matkhaugv = @mk", mydb.getConnection); command.Parameters.Add("@tk", SqlDbType.VarChar).Value = TextBox_Username.Text; command.Parameters.Add("@mk", SqlDbType.VarChar).Value = TextBox_Password.Text; SqlDataAdapter adapter = new SqlDataAdapter(command); DataTable dt = new DataTable(); adapter.Fill(dt); if (dt.Rows.Count > 0) { MainFormGiaoVien mainGV = new MainFormGiaoVien(dt.Rows[0][0].ToString()); Visible = false; mainGV.ShowDialog(); } else { MessageBox.Show("Sai Tài khoản hoặc Mật khẩu", "Login Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { SqlCommand command = new SqlCommand("select * from admin where tentaikhoanad = @tk and matkhauad = @mk", mydb.getConnection); command.Parameters.Add("@tk", SqlDbType.VarChar).Value = TextBox_Username.Text; command.Parameters.Add("@mk", SqlDbType.VarChar).Value = TextBox_Password.Text; SqlDataAdapter adapter = new SqlDataAdapter(command); DataTable dt = new DataTable(); adapter.Fill(dt); if (dt.Rows.Count > 0) { mainFormAdmin mainAD = new mainFormAdmin(dt.Rows[0][0].ToString()); Visible = false; mainAD.ShowDialog(); } else { MessageBox.Show("Sai Tài khoản hoặc Mật khẩu", "Login Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }