我有一個數據庫中有一列用戶名和UserRights的表。 UserRights是admin
或user
現在,如果用戶名登錄login form
只是一個用戶,我想要禁用其他形式的一些按鈕。我將如何做到這一點? 我有下面的代碼:如何禁用某些用戶的按鈕?
private void button1_Click_1(object sender, EventArgs e)
{
connection.Open();
OleDbDataReader reader = null;
OleDbCommand command = new OleDbCommand("select* from TableAcct", connection);
reader = command.ExecuteReader();
while (reader.Read())
{
uname.Add(reader["username"].ToString());
password.Add(reader["userpassword"].ToString());
rights.Add(reader["rights"].ToString());
}
connection.Close();
int totalItems = uname.Count;
int count = 0;
string isValidated = "";
while (count < totalItems)
{
if ((Username.Text == uname[count].ToString()) && (pword.Text == password[count].ToString()))
{
isValidated = "True";
rights2 = rights[count].ToString();
count = 100;
}
else
{
count++;
}
}
if (isValidated == "True")
{
Mainform mainform1 = new Mainform();
login.ActiveForm.Hide();
mainform1.linkLabel1.Text = Username.Text;
mainform1.ShowDialog();
Username.Clear();
pword.Clear();
}
else
{
MessageBox.Show("Invalid Log in. Please try again", "Error Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
檢查,如果是UserRights用戶集合button1.Enabled = FALSE; – 2013-03-20 07:50:00