private void btnLogin_Click(object sender, EventArgs e) { string userName = txtUsername.Text, passWord = txtPassword.Text; if (Login(userName, passWord)) { frmAdmin admin = new frmAdmin(); this.Hide(); admin.ShowDialog(); this.Show(); } else { MessageBox.Show("Sai tên đăng nhập hoặc mật khẩu"); } }
private void Logining() { string userName = txtUserName.Text.Trim(); string passWord = txtPassWord.Text.Trim(); var conn = new SqlConnection(connectionString); conn.Open(); var cmd = new SqlCommand("GetUser", conn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@UserName", userName); cmd.Parameters.AddWithValue("@PassWord", passWord); var tb = new DataTable(); var adpt = new SqlDataAdapter(cmd); adpt.Fill(tb); conn.Close(); if (tb == null || tb.Rows.Count == 0) { MessageBox.Show(null, "Tên đăng nhập / mật khẩu không đúng!", "Thông báo"); } else { int type = int.Parse(tb.Rows[0]["Type"].ToString()); switch (type) { case 1: //admin { var frm = new frmAdmin(); frm.Show(); break; } case 2: //teacher { var frm = new frmTeacher(); frm.Show(); break; } case 3: //student { int idUser = int.Parse(tb.Rows[0]["ID"].ToString()); cmd.CommandText = "SELECT ID FROM Student WHERE UserID=" + idUser; cmd.CommandType = CommandType.Text; var tbTemp = new DataTable(); var adapter = new SqlDataAdapter(cmd); adapter.Fill(tbTemp); int idStudent = int.Parse(tbTemp.Rows[0]["ID"].ToString()); var frm = new frmStudent(idStudent); frm.Show(); break; } default: break; } this.Hide(); } }