我使用Visual Studio 2010中的角色列值和Windows窗体在C#应用程序。 该应用程序正常工作我可以完美登录,并获取用户名登录到下一个表单,这是登录成功后打开的菜单表单。 现在我的问题是我要检查登录的用户是否是经理还是取决于存储在数据库中的角色列中的值管理,这样的话我可以禁用Admin用户的某些功能。 任何想法或帮助指引我到正确的地方吗? 我希望我的问题是清楚的从数据库中检索登录后
我有一个表叫向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);
}
}
}
// clsLogin完全
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; }
}
}
我已经得到了SQL查询,我可以登录通过检查用户名和密码,但现在我想要做的是当我登录检索存储在角色列中的值检查用户是管理员还是管理员,如果是管理员,则重定向到管理员表单,如果是管理员,则是管理员表单 荫使用C#在Visual Studio 2010中,这是一个Windows窗体应用程序 – user2267472 2013-04-10 23:03:23
哎呀sowi didnt阅读乌尔查询正确RIKKI乙 sowi IAM要去尝试,在一个位 – user2267472 2013-04-10 23:04:51
@ user2267472是查询检查用户和通过。您需要另一个查询来查找该用户的角色。希望这一个适合你。您的帮助 我仍然没有管理 – 2013-04-10 23:12:07