public vanphongchibo checklogin(string taikhoan, string matkhau) { vanphongchibo curuser = null; db_connection(); cmd = new SqlCommand(); cmd.CommandText = "Select taikhoan,matkhau,hoten,capdo from users where taikhoan=@taikhoan and matkhau=@matkhau"; cmd.Parameters.AddWithValue("@taikhoan", taikhoan); cmd.Parameters.AddWithValue("@matkhau", matkhau); cmd.Connection = connect; SqlDataReader login = cmd.ExecuteReader(); if (login.Read()) { string tk = login.GetString(0); string mk = login.GetString(1); string ht = login.GetString(2); int cd = login.GetInt32(3); if (cd == 1) { curuser = new vanphongchibo(tk, mk, ht, cd); } else { curuser = new vanphongdanguy(tk, mk, ht, cd); } // connect.Close(); } return(curuser); }
private void button1_Click(object sender, EventArgs e) { vanphongchibo curuser = db.checklogin(textBoxtaikhoan.Text, textBoxmatkhau.Text); if (textBoxtaikhoan.Text == "") { labelthongbaotaikhoan.Visible = true; } else if (textBoxmatkhau.Text == "") { labelthongbaomatkhau.Visible = true; } else if (curuser != null) { this.Hide(); formhethongquanly htql = new formhethongquanly(); htql.Show(); } else { labelthongbao.Visible = true; } }