我正在使用 Visual Studio 2010 和 C# 中的 Windows 窗体应用程序。该应用程序正常运行我可以完美登录,并将用户名登录到下一个表单,这是登录成功后打开的菜单表单。现在我的问题是我想检查登录的用户是经理还是管理员,这取决于存储在数据库中角色列中的值,所以我可以禁用管理员用户的某些功能。有什么想法或帮助将我引导到正确的地方吗?我希望我的问题很清楚
我有一个名为 tblUsers 的表,其中包含以下字段:
userId
Username
Password
FirstName
LastName
Mobile
Landline
Address
Email
Role
//clsLoginCollection:
public Boolean Login(clsLogin Login)
{
clsDataConduit logincheck = new clsDataConduit();
logincheck.AddParameter("Username", Login.username);
logincheck.AddParameter("Password", Login.password);
logincheck.Execute("sproc_tblUser_Login");
if (logincheck.Count > 0)
{
return true;
}
else
{
return false;
}
}
//存储过程:
ALTER PROCEDURE sproc_tblUser_Login
@Username varchar(10),
@Password varchar(10)
AS
select Username, Password from tblUsers where Username = @Username AND Password = @Password
//clsLoginform:
private void btnLogin_Click(object sender, EventArgs e)
{
Boolean b = false;
if ((String.IsNullOrEmpty(tbUsername.Text)) || (String.IsNullOrEmpty(tbPassword.Text)))
{
MessageBox.Show("Username or Password Cannot Be Blank.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
else
{
clsLoginCollection l = new clsLoginCollection();
clsEncryption encrypt = new clsEncryption();// this class have the encryption method
b = l.Login(new clsLogin(tbUsername.Text, encrypt.Encrypt(tbPassword.Text)));
if (b == true)
{
MainMenu m = new MainMenu(tbUsername.Text, tbPassword.Text);
m.Show();
this.Visible = false;
}
else
{
MessageBox.Show("Invalid Login Details", "Error Message", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button2);
}
}
}
//cls 完整登录
public class clsLogin
{
private Int32 UserID;
private string Username;
private string Password;
private string FirstName;
private string LastName;
private string Mobile;
private string Landline;
private string Address;
private string Email;
private string Role;
public clsLogin()
{ }
public clsLogin(string UserName, string Password)
{
this.username = UserName;
this.Password = Password;
}
public clsLogin(string UserName, string Password, string FirstName, string LastName, string Mobile, string Landline, string Address, string Email, string Role)
{
this.username = UserName;
this.Password = Password;
this.FirstName = FirstName;
this.LastName = LastName;
this.Mobile = Mobile;
this.Landline = Landline;
this.Address = Address;
this.Email = Email;
this.Role = Role;
}
public Int32 userID
{
get { return UserID; }
set { UserID = value; }
}
public string username
{
get {return Username;}
set {Username = value;}
}
public string password
{
get {return Password;}
set {Password = value;}
}
public string firstName
{
get { return FirstName; }
set { FirstName = value; }
}
public string lastName
{
get { return LastName; }
set { LastName = value; }
}
public string mobile
{
get { return Mobile; }
set { Mobile = value; }
}
public string landline
{
get { return Landline; }
set { Landline = value; }
}
public string address
{
get { return Address; }
set { Address = value; }
}
public string email
{
get { return Email; }
set { Email = value; }
}
public string role
{
get { return Role; }
set { Role = value; }
}
}