public Frm_Main() { mainFrm = this; InitializeComponent(); }
/* * private void checkLogin() * { * if (rbtn_1.Checked) * { * role = "管理员"; * } * else if (rbtn_2.Checked) * { * role = "学生"; * } * else * { * role = "教师"; * } * //登录验证 * if (txt_Name.Text.Trim().Equals("")) * { * MessageBox.Show("账号不能为空!"); * txt_Name.Focus(); * } * else if (txt_Pwd.Text.Trim().Equals("")) * { * MessageBox.Show("密码不能为空!"); * txt_Pwd.Focus(); * } * * else * { * OleDbConnection con = new OleDbConnection(Message.conStr); * try * { * con.Open(); * } * catch (Exception ex) * { * MessageBox.Show(ex.ToString()); * } * //String cmdStr = "select * from logInfo where num='" + txt_Name.Text.Trim() + "' and pwd='" + txt_Pwd.Text.Trim() + "' and role='" + role + "'"; * cmdStr = "select * from logInfo where num='" + txt_Name.Text.Trim() + "'"; * cmd = new OleDbCommand(cmdStr, con); * read = cmd.ExecuteReader(); * if (read.HasRows) * { * cmdStr = "select * from logInfo where num='" + txt_Name.Text.Trim() + "' and pwd='" + txt_Pwd.Text.Trim() + "'"; * cmd = new OleDbCommand(cmdStr, con); * read = cmd.ExecuteReader(); * if (read.HasRows) * { * cmdStr = "select * from logInfo where num='" + txt_Name.Text.Trim() + "' and pwd='" + txt_Pwd.Text.Trim() + "' and role='" + role + "'"; * cmd = new OleDbCommand(cmdStr, con); * read = cmd.ExecuteReader(); * if (read.HasRows) * { * * name = txt_Name.Text.Trim(); * pwd = txt_Pwd.Text.Trim(); * if (login) * { * Frm_Main.mainFrm.Reload();//重新加载main窗体 * this.Hide(); * login = false; * } * else * { * Frm_Main frm = new Frm_Main(); * frm.Show();//打开一个main窗体 * this.Hide(); * } * * } * else * { * MessageBox.Show("用户身份错误,请重新选择!"); * } * } * else * { * MessageBox.Show("密码错误,请重新输入!"); * txt_Pwd.Text = ""; * * txt_Pwd.Focus(); * initIdc(); * count++; * if (count > 3) { * btn_Login.Enabled = false; * count = 0; * } * con.Close(); * } * } * else * { * MessageBox.Show("用户不存在,请重新输入!"); * txt_Name.Text = ""; * txt_Pwd.Text = ""; * txt_Idc.Text = ""; * txt_Name.Focus(); * initIdc(); * con.Close(); * } * con.Close(); * } * } */ private void btn_Login_Click(object sender, EventArgs e) { // checkLogin(); role = "管理员"; //登录验证 if (txt_Name.Text.Trim().Equals("")) { MessageBox.Show("账号不能为空!"); txt_Name.Focus(); } else if (txt_Pwd.Text.Trim().Equals("")) { MessageBox.Show("密码不能为空!"); txt_Pwd.Focus(); } else { OleDbConnection con = new OleDbConnection(Message.conStr); try { con.Open(); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } //String cmdStr = "select * from logInfo where num='" + txt_Name.Text.Trim() + "' and pwd='" + txt_Pwd.Text.Trim() + "' and role='" + role + "'"; cmdStr = "select * from logInfo where num='" + txt_Name.Text.Trim() + "'"; cmd = new OleDbCommand(cmdStr, con); read = cmd.ExecuteReader(); if (read.HasRows) { cmdStr = "select * from logInfo where num='" + txt_Name.Text.Trim() + "' and pwd='" + txt_Pwd.Text.Trim() + "'"; cmd = new OleDbCommand(cmdStr, con); read = cmd.ExecuteReader(); if (read.HasRows) { cmdStr = "select * from logInfo where num='" + txt_Name.Text.Trim() + "' and pwd='" + txt_Pwd.Text.Trim() + "' and role='" + role + "'"; cmd = new OleDbCommand(cmdStr, con); read = cmd.ExecuteReader(); if (read.HasRows) { name = txt_Name.Text.Trim(); pwd = txt_Pwd.Text.Trim(); if (login) { Frm_Main.mainFrm.Reload(); //重新加载main窗体 this.Hide(); login = false; } else { Frm_Main frm = new Frm_Main(); frm.Show(); //打开一个main窗体 this.Hide(); } } else { MessageBox.Show("用户身份错误,请重新选择!"); } } else { MessageBox.Show("密码错误,请重新输入!"); txt_Pwd.Text = ""; txt_Pwd.Focus(); initIdc(); count++; if (count > 3) { btn_Login.Enabled = false; count = 0; } con.Close(); } } else { MessageBox.Show("用户不存在,请重新输入!"); txt_Name.Text = ""; txt_Pwd.Text = ""; txt_Name.Focus(); initIdc(); con.Close(); } con.Close(); } }