登录后,在下一个表单中显示用户信息

时间:2016-08-11 09:38:58

标签: c# mysql forms

我需要帮助,我的问题是我想在下一个表单中显示用户信息,例如当我在起始表单中登录时:

开始表格

Login Form

这是我登录的代码:

 private void btnOK_Click(object sender, EventArgs e)
    {
        Boolean exist = false;
        MainForm mf = new MainForm();
        if (txtUser.Text == "" || txtPass.Text == "")
        {
            MessageBox.Show("Please Input Logon ID and Password", "ERROR", MessageBoxButtons.RetryCancel);

        }

        else
        {
            conn = koneksyon.getConnect();
            conn.Open();
            cmd = new SqlCommand("select Username,Password from Staff where Username = '" + txtUser.Text + "' AND Password = '" + txtPass.Text + "'", conn);
            dr = cmd.ExecuteReader();
            while (dr.Read())
            {
                exist = true;

                txtUser.Text = dr[0].ToString();
                txtPass.Text = dr[1].ToString();

            }
            if (exist == true)
            {
                mf.Show();
                this.Hide();

            }
            else
            {
                MessageBox.Show("INCORRECT Logon ID or password", "INVALID", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtUser.Clear();
                txtPass.Clear();
                txtUser.Focus();
            }
            conn.Close();
            dr.Dispose();
            cmd.Dispose();
        }
    }

现在我的问题是我想在输入

时显示这个

用户名= admin,密码= 123456它将转到下一个表单并显示此

[![窗体2] [2] [2]

这是我登录时的信息,我该怎么办?我没有任何代码,显示,需要帮助!感谢

1 个答案:

答案 0 :(得分:0)

在MainForm构造函数中,必须在Personhesis之间放置一些变量。 即在MainForm中使用此:

public MainForm(string _staffID, string _firstName, string _lastName)
{
     InitializeComponent();

     txtStaffID.Text = _staffID;
     txtFisrtName.Text = _firstName;
     txtLastName.Text = _lastName;
}

现在,当您想要从其他表单显示MainForm时,请使用以下代码:

string StaffID = "Fill Yourself as you want";
string FisrtName = "Fill Yourself as you want";
string LastName = "Fill Yourself as you want";
MainForm mf = new MainForm(StaffID, FisrtName, LastName);
mf.Show();

我希望这有用。

相关问题