private void btnLogin_Click(object sender, EventArgs e) { userName = txtTaiKhoan.Text.ToString(); password = txtMatKhau.Text.ToString(); try { conn = @"Data Source=" + "(local)" + ";Database=" + "QuanLyLinhKienPC" + ";Integrated Security = true"; //StreamWriter writer = new StreamWriter("ConnectString.con"); //writer.WriteLine(conn); //writer.Close(); s = new DALayer(); if (s.Connection() == "y") { if (con.State == ConnectionState.Open) { con.Close(); } con.Open(); SqlCommand cmd = new SqlCommand("SELECT * FROM TaiKhoan WHERE TenTK ='" + userName + "' and Pass='******'", con); SqlDataReader reader = cmd.ExecuteReader(); if (reader.Read() == true) { if (userName == "admin") { quyen = true; } else { quyen = false; } this.Hide(); Form main = new frmMain(); main.ShowDialog(); this.Close(); } else { MessageBox.Show("Đăng nhập không thành công"); } } else { MessageBox.Show("Connect Failed !", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch (SqlException ex) { MessageBox.Show("Không truy cập Database !!!/n" + ex, "Thông báo ", MessageBoxButtons.OK, MessageBoxIcon.Error); } }