private void btnDangNhap_Click(object sender, EventArgs e) { var tb = new HideNotifications(); SqlConnection conn = dl.Connect(); string sql = "select MaND, TenDangNhap,ChucVu from NguoiDung where TenDangNhap = '" + txtTenDangNhap.Text + "' and MatKhau = '" + txtMatKhau.Text + "'"; DataTable dt = NguoiDung.GetDataTable(conn, sql); if (txtMatKhau.Text != "" && txtTenDangNhap.Text != "") { if (dt.Rows.Count > 0) { foreach (DataRow dr in dt.Rows) { PhanQuyenNguoiDung.TenDangNhap = dr["TenDangNhap"].ToString(); PhanQuyenNguoiDung.ChucVu = dr["ChucVu"].ToString(); frmMain f = new frmMain(); f.OnOff(this.ParentForm); this.Close(); } } else { txtMatKhau.Clear(); txtTenDangNhap.Clear(); //TaoChuChim(); txtTenDangNhap.Focus(); lblThongBao.Text = "Tên tài khoản hoặc mật khẩu không chính xác"; tb.stt(lblThongBao); } } else { txtMatKhau.Clear(); txtTenDangNhap.Clear(); //TaoChuChim(); txtTenDangNhap.Focus(); lblThongBao.Text = "Vui lòng nhập đầy đủ thông tin!"; tb.stt(lblThongBao); } }
public string Login(string name, string pass) { if (name != "" && pass != "") { SqlConnection conn = dl.Connect(); string sql = "select MaND, TenDangNhap,ChucVu from NguoiDung where TenDangNhap = '" + name + "' and MatKhau = '" + pass + "'"; DataTable dt = NguoiDung.GetDataTable(conn, sql); if (dt.Rows.Count > 0) { return("successed"); } else { return("failed"); } } else { return("failed"); } }