如何为每个用户打开单独的窗口

1 .net c# sql login winforms

我想创建一个登录表单,为每个用户类型打开单独的窗口.在这个程序数据库中有3列.(用户名,密码,usertype)这个程序中有3个用户类型(admin,manager,user),每个用户类型都有单独的窗口.

  1. admin = Form2
  2. manager = Form3
  3. user = 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");
    }
Run Code Online (Sandbox Code Playgroud)

Man*_*ngh 5

我想你已经在登录表用户类型中添加了一列.用户类型列已派生管理员,用户,经理等.然后您将轻松验证

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

}
Run Code Online (Sandbox Code Playgroud)

我希望这段代码可以帮助你.如有任何疑问,请发表评论.