怎么在显示一个登陆form,验证通过后再进入主界面form

解决方案 »

  1.   

    private void OKbtn_Click(object sender, System.EventArgs e)
    {
    try
    {
    if(this.txt1.Text=="admin")
     
    {
    SqlConnection Myconn = new SqlConnection("Data Source=(local);Integrated Security=SSPI;"+"Initial Catalog=sellmanager");
    Myconn.Open();

    if(this.txt2.Text=="admin")
    {
    this.Visible=false;
    Myconn.Close();

    FrAdminMain Form=new FrAdminMain();
    Form.ShowDialog();
    //Form2 fr=new Form2();
    //fr.ShowDialog();

    }


    else
    {
    MessageBox.Show("用户名或密码有错!","错误信息",MessageBoxButtons.OK,MessageBoxIcon.Information);

    }


    }
    else
    {
    SqlConnection Myconn = new SqlConnection("Data Source=(local);Integrated Security=SSPI;"+"Initial Catalog=sellmanager");
    Myconn.Open();
    SqlCommand  Mycomm=Myconn.CreateCommand();
    Mycomm.CommandText="select sellID,psd from sellerinfo where sellID='"+this.txt1.Text+"'and psd='"+DataProdected.Encrypt(this.txt2.Text,"licesoft")+"'";
    SqlDataReader MyReader=Mycomm.ExecuteReader();
    if(MyReader.Read())
    {
    Myconn.Close();
    MyReader.Close();
    this.Visible=false;
    FrUserMain Form=new FrUserMain(this.txt1.Text);
    Form.ShowDialog();

    }
    else
    {
    MessageBox.Show("用户名或密码有错!","错误信息",MessageBoxButtons.OK,MessageBoxIcon.Information);

    }
    MyReader.Close();


    }
    }
    catch(Exception err)
    {
    MessageBox.Show(err.ToString());
    }

    }