private void btnDangNhap_Click(object sender, EventArgs e) { SqlConnection sqlcn = new SqlConnection(@"Data Source =.; Initial Catalog = dbChamCong; Integrated Security = True;"); string query = "select * from tbChamCong_DangNhap where UserName = '******' and Password = '******'"; SqlDataAdapter sda = new SqlDataAdapter(query, sqlcn); DataTable dtbl = new DataTable(); sda.Fill(dtbl); if (dtbl.Rows.Count == 1) { FrmDashboard dashboard = new FrmDashboard(); this.Hide(); dashboard.ShowDialog(); this.Close(); } else { MessageBox.Show("user hoặc mặt khẩu không đúng!"); } }
private void btnDangNhap_Click(object sender, EventArgs e) { Dangnhap user = Dangnhap.getUser(); FrmDangNhap log = new FrmDangNhap(); if (txtUser.Text == "" & txtPassword.Text == "") { lblGhiChu.Text = "Bạn chưa nhập user"; lblGhiChu.Show(); lbGhiChu2.Text = "Bạn chưa nhập mật khẩu"; lbGhiChu2.Show(); } else if (txtUser.Text == "" || txtPassword.Text != "") { lblGhiChu.Text = "Bạn chưa nhập user"; lblGhiChu.Show(); lbGhiChu2.Text = ""; lbGhiChu2.Show(); } else if (txtUser.Text != "" || txtPassword.Text == "") { lbGhiChu2.Text = "Bạn chưa nhập mật khẩu"; lbGhiChu2.Show(); lblGhiChu.Text = ""; lblGhiChu.Show(); } else { if (user.Dangnhap1(txtUser.Text, txtPassword.Text) == true) { FrmDashboard bang = new FrmDashboard(); this.Hide(); bang.ShowDialog(); this.Close(); } else { MessageBox.Show("Tên đăng nhập hoặc mật khẩu không đúng!"); } } }