当前我的窗口是这样的edit and delete button disabled
。为了enable the buttons, user have to login with the administrator type
。现在,我已经使用成员类型的管理员类型登录。在我用管理员类型登录后,disabled buttons
应该是enabled
,但事实并非如此。启用窗体打开后的按钮c#
有没有什么办法给enable
这个按钮,用按钮打开表格后disabled
?
以下是图像:
正如你可以下面的图片上看到,有一个与编辑admin登录按钮和删除按钮禁用。(主系统表):
管理员登录(Privelege表)
这里是我使用的代码:
public class SystemManager
{
public static void AdminLogin(string _value1, string _value2, Form _windowsForm, TextBox _windowsTextBox)
{
using (OleDbConnection connection = new OleDbConnection(connectionString))
{
string query = "SELECT * FROM [Member] WHERE [Username] = @Username";
connection.Open();
using (OleDbCommand command = new OleDbCommand(query, connection))
{
command.Parameters.Add("@Username", OleDbType.VarChar);
command.Parameters["@Username"].Value = _value1;
using (OleDbDataReader reader = command.ExecuteReader())
{
if (reader.Read())
{
string password = (string)reader["Password"];
string userType = (string)reader["UserType"];
_isValidPassword = BCrypt.ValidateHash(_value2, password);
if (userType == "Administrator")
{
_isAdministrator = true;
}
else if (userType != "Administrator")
{
_isAdministrator = false;
}
if (_isValidPassword && _isAdministrator)
{
Authenticate _authenticate = new Authenticate();
_authenticate.ShowDialog();
ShowMessageBox("Authenticated.", "Success", 2);
UserInformation.isAdministrator = true;
_windowsForm.Hide();
_windowsForm.Close();
}
}
if (!_isValidPassword || !_isAdministrator)
{
Authenticate _authenticate = new Authenticate();
_authenticate.ShowDialog();
ShowMessageBox("Either username or password incorrect or you are not administrator. Please try again.", "Error", 1);
ClearTextBoxes(_windowsForm.Controls);
_windowsTextBox.Focus();
}
reader.Close();
}
}
connection.Close();
}
}
}
public partial class MainSystem: Form
{
void MainSystem_Load(object sender, EventArgs e)
{
UserPrivelege();
}
void UserPrivelege()
{
if (UserInformation.CurrentLoggedInUserType == "Member")
{
this.button3.Enabled = false; // Edit Button
this.button4.Enabled = false; // Delete Button
this.button7.Enabled = false;
this.button9.Enabled = true; // Admin Login Button
}
else if (UserInformation.CurrentLoggedInUserType == "Administrator" || UserInformation.isAdministrator)
{
this.button3.Enabled = true; // Edit Button
this.button4.Enabled = true; // Delete Button
this.button7.Enabled = true;
this.button9.Enabled = false; // Admin Login Button
}
}
}
public partial class Privelege : Form
{
void button1_Click(object sender, EventArgs e) // OK Button
{
Check();
}
void Check()
{
if (this.textBox1.Text == string.Empty || string.IsNullOrWhiteSpace(this.textBox1.Text))
{
SystemManager.ShowMessageBox("Username field required.", "Information", 2);
}
else if (this.textBox2.Text == string.Empty || string.IsNullOrWhiteSpace(this.textBox2.Text))
{
SystemManager.ShowMessageBox("Password field required.", "Information", 2);
}
else
{
SystemManager.AdminLogin(this.textBox1.Text, this.textBox2.Text, this, this.textBox1);
}
}
谢谢您。
我真的很感谢你的回答。
尼斯阅读和结构+1。先生,非常感谢Lathejockey81 – 2014-11-02 11:20:55