private void btnLogin_Click(object sender, EventArgs e) { string username = txtUser.Text; string password = txtPass.Text; EC_User user = new EC_User(); C_User active = new C_User(); try { user.UserName = username; user.Password = password; if (active.CheckUser(username, password)) { MessageBox.Show("Đăng Nhập Thành Công", "Chúc Mừng", MessageBoxButtons.OK, MessageBoxIcon.Information); user.PhanQuyen = active.LoadPhanQuyen(user.PhanQuyen, username); user.MaNV = active.LoadMaNVUser(user.MaNV, user.UserName); fmain.Access = user.PhanQuyen; fmain.User = user; this.Hide(); fmain.Show(); } else { MessageBox.Show("Tài khoản đăng nhập chưa đúng. Vui lòng kiểm tra lại.", "Chú Ý", MessageBoxButtons.OK, MessageBoxIcon.Error); txtUser.Text = ""; txtPass.Text = ""; txtUser.Focus(); return; } } catch (Exception ex) { MessageBox.Show(ex.Message, "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public void UpdateTK(EC_User _user) { string sqlquery = (@"UPDATE tb_User SET Password =N'{0}', phanquyen =N'{1}', manv =N'{2}' where Username =N'{3}'"); sqlquery = string.Format(sqlquery, _user.Password, _user.PhanQuyen, _user.MaNV, _user.UserName); Connect.ExcuteNonQuery(sqlquery); }
public void AddTK(EC_User _user) { string sqlquery = @"INSERT INTO tb_User (Username, Password, phanquyen, manv) VALUES (N'{0}',N'{1}',N'{2}',N'{3}')"; sqlquery = string.Format(sqlquery, _user.UserName, _user.Password, _user.PhanQuyen, _user.MaNV); Connect.ExcuteNonQuery(sqlquery); }
public void AddUser(EC_User _user) { if (!sql.CheckUserName(_user.UserName)) { sql.AddTK(_user); } else { MessageBox.Show("User này đã tồn tại!", "Chú Ý", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }
public void DeleteUser(EC_User _user) { sql.DeleteTK(_user); }
public void UpdateUser(EC_User _user) { sql.UpdateTK(_user); }
public void DeleteTK(EC_User _user) { Connect.ExcuteNonQuery("DELETE FROM [tb_User] WHERE Username=N'" + _user.UserName + "'"); }
public bool CheckUser(EC_User _user) { string sqlquery = "select count(*) from tb_User where Username ='******' and Password = '******'"; return(Connect.CheckUsername(sqlquery)); }