public static int DangNhap(NguoiSuDungDTO nsd) { SqlConnection conn = null; try { conn = KetNoi(); SqlCommand cmd = new SqlCommand("DangNhap", conn); cmd.CommandType = System.Data.CommandType.StoredProcedure; cmd.Parameters.Add("@MaNguoiSuDung", System.Data.SqlDbType.NChar, 10); cmd.Parameters.Add("@MatKhau", System.Data.SqlDbType.NChar, 10); cmd.Parameters["@MaNguoiSuDung"].Value = nsd.MaNguoiSuDung; cmd.Parameters["@MatKhau"].Value = nsd.MatKhau; SqlParameter returnValue = new SqlParameter(); returnValue.Direction = System.Data.ParameterDirection.ReturnValue; cmd.Parameters.Add(returnValue); cmd.ExecuteNonQuery(); return((int)returnValue.Value); } catch (Exception ex) { } finally { if (conn != null && conn.State == System.Data.ConnectionState.Open) { conn.Close(); } } return(-999); }
private void btnDangNhap_Click(object sender, EventArgs e) { NguoiSuDungDTO nsd = new NguoiSuDungDTO(); if (kiemTraDuLieuHopLe()) { nsd.MaNguoiSuDung = txtTenDangNhap.Text; nsd.MatKhau = txtMatKhau.Text; int kq = NguoiSuDungDAO.DangNhap(nsd); switch (kq) { case -1: MessageBox.Show("Tên đăng nhập không tồn tại.\n Vui lòng kiểm tra lại.", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); break; case 0: MessageBox.Show("Mật khẩu không đúng.\n Vui lòng kiểm tra lại.", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); break; case 1: this.DialogResult = DialogResult.OK; Program.setNguoiSuDung(nsd); this.Close(); break; } } else { MessageBox.Show("Dữ liệu nhập vào không hợp lệ.\n Vui lòng kiểm tra lại.", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public static void setNguoiSuDung(NguoiSuDungDTO nsd) { nguoiSuDung = nsd; }