我想制作一个登录表单,为每个用户打开单独的窗口 类型。在此程序数据库中有 3 列。(用户名、密码、用户类型)此程序中有 3 种用户类型(管理员、经理、用户),每种用户类型都有单独的窗口。
- admin = Form2
- 经理 = Form3
- 用户 = Form4
这是我的登录按钮代码。请帮我把这个单独打开 每个用户类型的窗口。
SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=c:\users\sasindu\documents\visual studio 2010\Projects\Employee Database\Employee Database\Database.mdf;Integrated Security=True;User Instance=True");
SqlCommand cmd = new SqlCommand("select * from login where username=@username and password =@password", con);
cmd.Parameters.AddWithValue("@username", textBox1.Text);
cmd.Parameters.AddWithValue("@password", textBox2.Text);
SqlDataAdapter sda = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
sda.Fill(dt);
con.Open();
int i = cmd.ExecuteNonQuery();
con.Close();
if (dt.Rows.Count > 0)
{
Form3 Form = new Form3();
Form.Show();
this.Hide();
}
else
{
MessageBox.Show("Please enter Correct Username and Password");
}
最佳答案
我认为您已经在登录表用户类型中添加了一列。 用户类型列有派生admin、user、manager等。 然后你会很容易验证
if(dt.rows[0]["user_type"].tostring()=="Admin")
{
// which form you show
}
if(dt.rows[0]["user_type"].tostring()=="User")
{
// which form you show
}
if(dt.rows[0]["user_type"].tostring()=="Manager")
{
// which form you show
}
我希望这段代码对您有所帮助。如果有任何疑问,请发表评论。
关于c# - 如何为每个用户打开单独的窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39302711/