限制用户删除和更新记录 [英] Limit User from Deleting and Updating records

查看:160
本文介绍了限制用户删除和更新记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我正在使用MS Access和VB.Net 2008,我需要帮助



1.我有购买和带有按钮的员工信息表(添加,保存,更新,删除和重新加载)。

2.主菜单表格

3.登录表格。

我想以这样的方式限制用户的某些权限:如果用户登录,则应禁用更新和删除按钮,以便用户无法删除和更新记录,除非管理员。



我已经在登录表单中编写了登录按钮,如下所示。但是,如果我以用户(用户名:系统密码:经理)登录并打开购买或员工信息表单,则首先禁用删除和更新按钮,然后在添加其他记录或单击重新加载按钮后,它们将变为活动状态(未禁用)。 br />


以下是编码:



Private Sub btnLogin_Click(ByVal sender As System.Object,ByVal e As System.EventArgs)处理btnLogin.Click



'管理员登录

Dim admin As String

Dim administrator As字符串



'用户登录

Dim system As String

Dim manager As String



如果txtadmin.Text =那么:MsgBox(请输入用户名,MsgBoxStyle.Exclamation):txtadmin.Focus():退出Sub:结束如果

如果txtadmin1.Text =那么:MsgBox(请输入密码,MsgBoxStyle.Exclamation):txtadmin1.Focus():退出子:结束如果



如果txtadmin.Text =admin和txtadmin1.Text = 管理员然后

Me.Hide()



ElseIf txtadmin.Text =system和txtadmin1.Text =manager然后

frmPurchases.btnDelete.Enabled = False

frmPurchases.btnUpdate.Enabled = False



frmEmployessDetails.btnDelete。 Enabled = False

frmEmployessDetails.btnUpdate.Enabled = False





Me.Hide()

Else

MsgBox(抱歉,您的登录详细信息无效&vbCrLf&vbCrLf&请联系系统管理员,MsgBoxStyle.Critical MsgBoxStyle.OkOnly,错误:用户名或密码无效)

txtadmin.Focus()



txtadmin.Clear()

txtadmin1.Clear( )



结束如果

结束Sub

Hi Guys,
I am using MS Access and VB.Net 2008 and I need help

1. I have Purchases and Employee Information forms with buttons (Add, Save, Update, Delete and Reload).
2. Main menu form
3. Login form.
I want to limit some privileges for the User in such a way that if the User logs in, Update and Delete buttons should be disabled so that the User is unable to Delete and Update records unless admin.

I have coded the login button in the login form as shown below. But if I logs in as User (Username: system. Password: manager) and open purchases or Employees information form, it first disable Delete and Update buttons and later they become active (not disabled) after adding another record or clicking reload button.

Below is the coding:

Private Sub btnLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLogin.Click

'Admin login
Dim admin As String
Dim administrator As String

'User login
Dim system As String
Dim manager As String

If txtadmin.Text = "" Then : MsgBox("Please input User Name", MsgBoxStyle.Exclamation) : txtadmin.Focus() : Exit Sub : End If
If txtadmin1.Text = "" Then : MsgBox("Please input Password", MsgBoxStyle.Exclamation) : txtadmin1.Focus() : Exit Sub : End If

If txtadmin.Text = "admin" And txtadmin1.Text = "administrator" Then
Me.Hide()

ElseIf txtadmin.Text = "system" And txtadmin1.Text = "manager" Then
frmPurchases.btnDelete.Enabled = False
frmPurchases.btnUpdate.Enabled = False

frmEmployessDetails.btnDelete.Enabled = False
frmEmployessDetails.btnUpdate.Enabled = False


Me.Hide()
Else
MsgBox("Sorry, Your Login Detail is invalid" & vbCrLf & vbCrLf & "Please contact the system administrator", MsgBoxStyle.Critical MsgBoxStyle.OkOnly, "Error: Username or Password Invalid")
txtadmin.Focus()

txtadmin.Clear()
txtadmin1.Clear()

End If
End Sub

推荐答案

class security
{
 public static string role;
}
Create a column in users table [Role]
now read that role at the time of login
store it in static variable (i think shared in vb.net)
initialize like this
security.role=usertable.Row[0]["Role"];

now on any form load check it like this
form_load(object obj,eventargs sender)
{
   if(security.role=="admin")
      btnsave.Enabled=false;
}


这篇关于限制用户删除和更新记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆