考试系统 根据是否补考等条件验证

来源:互联网 发布:有关域名的知识 编辑:程序博客网 时间:2024/04/29 12:22
 

 protected void Button2_Click(object sender, EventArgs e)
    {
        string StuID = Session["ID"].ToString();//考生的编号
        string StuKC = ddlKm.SelectedItem.Text;//选择的考试科目
        Session["taoshu"] = StuKC;

        SqlConnection connaa = BaseClass.DBCon();
        connaa.Open();
        SqlCommand cmdaa = new SqlCommand("select count(*) from chengji where uid='" + StuID + "' and sid='" + StuKC + "'and jige='是'", connaa);
        int ia = Convert.ToInt32(cmdaa.ExecuteScalar());
        if (ia > 0)
        {
            MessageBox.Show("您已经及格了");
        }
        else
        {

            SqlConnection conn = BaseClass.DBCon();
            conn.Open();
            SqlCommand cmd = new SqlCommand("select count(*) from cishu where uid='" + StuID + "' and sid='" + StuKC + "'", conn);
            int i = Convert.ToInt32(cmd.ExecuteScalar());
            if (i > 0)
            {
                SqlConnection conna = BaseClass.DBCon();
                conna.Open();
                SqlCommand cmda = new SqlCommand("select * from cishu where uid='" + StuID + "' and sid='" + StuKC + "'", conna);
                SqlDataReader sdr = cmda.ExecuteReader();
                sdr.Read();
                if (sdr["cishu"].ToString() == "4")
                {
                    MessageBox.Show("您已经补考过三次了");
                }
                else
                {

                    int s = Convert.ToInt32(sdr["cishu"].ToString());
                    string a = Convert.ToString(s + 1);
                    string str = "update cishu set cishu='" + a + "' where uid='" + StuID + "' and sid='" + StuKC + "'";
                    BaseClass.OperateData(str);
                    Session["cishu"] = a;
                    this.Response.Redirect("kaoshi.aspx");
                }
            }
            else
            {
                SqlConnection conna = BaseClass.DBCon();
                conna.Open();
               
               
             
                string str = "insert into cishu(cishu,sid,uid) values(1,'" + StuKC + "','" + StuID + "')";
                BaseClass.OperateData(str);
                SqlCommand cmda = new SqlCommand("select * from cishu where uid='" + StuID + "' and sid='" + StuKC + "'", conna);
                SqlDataReader sdr = cmda.ExecuteReader();
                sdr.Read();
                int s = Convert.ToInt32(sdr["cishu"].ToString()); 
           
                Session["cishu"] =1;
                this.Response.Redirect("kaoshi.aspx");
            }
        }
    }

原创粉丝点击