Esempio n. 1
0
 public static Exam ex  = new Exam();  //声明静态全局变量 考试窗口实例
 private void LogButt_Click(object sender, EventArgs e)
 {
     //判断是否选择登陆身份
     if (useIdeTextBox.Text == "")
     {
         MessageBox.Show("请选择登陆身份!");
     }
     else
     {
         //判断是否输入用户名和密码
         if (accTextBox.Text == "" || pwdTxtBox.Text == "")
         {
             MessageBox.Show("请输入用户名和密码!");
         }
         else
         {
             //如果是考生
             if (useIdeTextBox.Text == "考生")
             {
                 //判断用户名密码是否符合
                 OleDbConnection con = DataClass.DBCon();
                 con.Open();
                 OleDbCommand com = new OleDbCommand(
                     "select * from UserInfo where userAcc='" + accTextBox.Text + "' and userPwd='" + pwdTxtBox.Text + "' and userIde=0", con);
                 OleDbDataReader red = com.ExecuteReader();
                 red.Read();
                 if (red.HasRows)
                 {
                     ComVal.userPwd = pwdTxtBox.Text;
                     ComVal.userAcc = accTextBox.Text;
                     Exam._Useracc  = ComVal.userAcc; //传递用户名
                     ex.Show();                       //显示考试窗口
                     this.Hide();
                 }
                 else
                 {
                     MessageBox.Show("用户名或密码错误!");
                 }
                 con.Close();
             }
             else
             {
                 //如果不是学生,则判断管理员的身份是否符合
                 OleDbConnection con = DataClass.DBCon();
                 con.Open();
                 OleDbCommand com = new OleDbCommand(
                     "select * from UserInfo where userIde=1 and userAcc='" + accTextBox.Text + "' and userPwd='" + pwdTxtBox.Text + "'", con);
                 OleDbDataReader red = com.ExecuteReader();
                 red.Read();
                 if (red.HasRows)
                 {
                     //上传用户名密码
                     ComVal.userPwd  = pwdTxtBox.Text;
                     ComVal.userAcc  = accTextBox.Text;
                     ComVal.userName = red[2].ToString();
                     ad.Show();//显示管理员窗口
                     this.Hide();
                 }
                 else
                 {
                     MessageBox.Show("用户名或密码错误!");
                 }
                 con.Close();
             }
         }
     }
 }