//根据设置自动生成试卷
    protected void GVbind()
    {
        int course = int.Parse(ddlCourse.SelectedValue);

        DataBase db = new DataBase();//创建DataBase类对象
        string GridView1Str = "select * from SingleProblem where courseId=" + course + " ";//根据参数设置查询单选题Sql语句
        DataSet ds1 = db.GetDataSetSql(GridView1Str);//调用DataBase类方法GetDataSetSql方法查询数据
        GridView11.DataSource = ds1.Tables[0].DefaultView;//为单选题GridView控件指名数据源
        GridView11.DataBind();//绑定数据
        string GridView2Str = "select * from MultiProblem where courseId=" + course + "";//根据参数设置查询多选题Sql语句
        DataSet ds2 = db.GetDataSetSql(GridView2Str);//调用DataBase类方法GetDataSetSql方法查询数据
        GridView2.DataSource = ds2.Tables[0].DefaultView;//为多选题GridView控件指名数据源
        GridView2.DataBind();//绑定数据
        string GridView3Str = "select * from JudgeProblem where courseId=" + course + "";//根据参数设置查询判断题Sql语句
        DataSet ds3 = db.GetDataSetSql(GridView3Str);//调用DataBase类方法GetDataSetSql方法查询数据
        GridView3.DataSource = ds3.Tables[0].DefaultView;//为判断题GridView控件指名数据源
        GridView3.DataBind();//绑定数据
        string GridView4Str = "select * from FillBlankProblem where courseId=" + course + "";//根据参数设置查询填空题Sql语句
        DataSet ds4 = db.GetDataSetSql(GridView4Str);//调用DataBase类方法GetDataSetSql方法查询数据
        GridView4.DataSource = ds4.Tables[0].DefaultView;//为填空题GridView控件指名数据源
        GridView4.DataBind();//绑定数据
        string GridView5Str = "select * from QuestionProblem where courseId=" + course + "";//根据参数设置查询问答题Sql语句
        DataSet ds5 = db.GetDataSetSql(GridView5Str);//调用DataBase类方法GetDataSetSql方法查询数据
        GridView5.DataSource = ds5.Tables[0].DefaultView;//为问答题GridView控件指名数据源
        GridView5.DataBind();//绑定数据
    }
    //根据设置自动生成试卷
    protected void imgBtnConfirm_Click(object sender, ImageClickEventArgs e)
    {
        int res = 0;
        if (txtSingleFen != null && txtSingleFen.Text != "" && txtSingleNum != null && txtSingleFen.Text != "")
        {
            res = res + int.Parse(txtSingleNum.Text) * int.Parse(txtSingleFen.Text);
        }
        if (txtMultiNum != null && txtMultiFen.Text != "" && txtMultiNum != null && txtMultiFen.Text != "")
        {
            res = res + int.Parse(txtMultiNum.Text) * int.Parse(txtMultiFen.Text);
        }
        if (txtJudgeFen != null && txtJudgeFen.Text != "" && txtJudgeNum != null && txtJudgeFen.Text != "")
        {
            res = res + int.Parse(txtJudgeNum.Text) * int.Parse(txtJudgeFen.Text);
        }
        if (txtFillFen != null && txtFillFen.Text != "" && txtFillNum != null && txtFillFen.Text != "")
        {
            res = res + int.Parse(txtFillNum.Text) * int.Parse(txtFillFen.Text);
        }
        if (txtQuestionFen != null && txtQuestionFen.Text != "" && txtSingleNum != null && txtQuestionFen.Text != "")
        {
            res = res + int.Parse(txtQuestionNum.Text) * int.Parse(txtQuestionFen.Text);
        }

        lblres.Text = "总分为:" + res.ToString() + "分";

        Panel1.Visible = true;
        int course = int.Parse(ddlCourse.SelectedValue);//选择科目
        int diff = int.Parse(ddlDiff.SelectedValue); //选择的难度

        DataBase db = new DataBase();//创建DataBase类对象
        string GridView1Str = "select top " + int.Parse(txtSingleNum.Text.Trim()) + " * from SingleProblem where courseId=" + course + " and diffid >= " + (diff-2) + " and diffid <= " + (diff+2) + " order by newid()";//根据参数设置查询单选题Sql语句
        DataSet ds1 = db.GetDataSetSql(GridView1Str);//调用DataBase类方法GetDataSetSql方法查询数据
        GridView11.DataSource = ds1.Tables[0].DefaultView;//为单选题GridView控件指名数据源
        GridView11.DataBind();//绑定数据
        string GridView2Str = "select top " + int.Parse(txtMultiNum.Text.Trim()) + " * from MultiProblem where courseId=" + course + " and diffid >= " + (diff - 2) + " and diffid <= " + (diff + 2) + " order by newid()";//根据参数设置查询多选题Sql语句
        DataSet ds2 = db.GetDataSetSql(GridView2Str);//调用DataBase类方法GetDataSetSql方法查询数据
        GridView2.DataSource = ds2.Tables[0].DefaultView;//为多选题GridView控件指名数据源
        GridView2.DataBind();//绑定数据
        string GridView3Str = "select top " + int.Parse(txtJudgeNum.Text.Trim()) + " * from JudgeProblem where courseId=" + course + " and diffid >= " + (diff - 2) + " and diffid <= " + (diff + 2) + " order by newid()";//根据参数设置查询判断题Sql语句
        DataSet ds3 = db.GetDataSetSql(GridView3Str);//调用DataBase类方法GetDataSetSql方法查询数据
        GridView3.DataSource = ds3.Tables[0].DefaultView;//为判断题GridView控件指名数据源
        GridView3.DataBind();//绑定数据
        string GridView4Str = "select top " + int.Parse(txtFillNum.Text.Trim()) + " * from FillBlankProblem where courseId=" + course + " and diffid >= " + (diff - 2) + " and diffid <= " + (diff + 2) + " order by newid()";//根据参数设置查询填空题Sql语句
        DataSet ds4 = db.GetDataSetSql(GridView4Str);//调用DataBase类方法GetDataSetSql方法查询数据
        GridView4.DataSource = ds4.Tables[0].DefaultView;//为填空题GridView控件指名数据源
        GridView4.DataBind();//绑定数据
        string GridView5Str = "select top " + int.Parse(txtQuestionNum.Text.Trim()) + " * from QuestionProblem where courseId=" + course + " and diffid >= " + (diff - 2) + " and diffid <= " + (diff + 2) + " order by newid()";//根据参数设置查询填空题Sql语句
        DataSet ds5 = db.GetDataSetSql(GridView5Str);//调用DataBase类方法GetDataSetSql方法查询数据
        GridView5.DataSource = ds5.Tables[0].DefaultView;//为填空题GridView控件指名数据源
        GridView5.DataBind();//绑定数据
    }
 public void Bind()
 {
     DataBase DB = new DataBase();
     DataSet ds = DB.GetDataSetSql("SELECT [PaperID], [PaperName] FROM [Paper] WHERE ([NeedTime] = 0)");
     DataList1.DataSource = ds;
     DataList1.DataKeyField = "PaperID";
     DataList1.DataBind();
 }
Exemple #4
0
 //查询用户
 //查询所用用户
 //不需要参数
 public DataSet QueryUsers()
 {
     DataBase DB = new DataBase();
     string sql = "SELECT [Users].[UserID],[Users].[UserName],[Role].[RoleName]FROM [Users],[Role] WHERE [Users].[RoleId]=[Role].[RoleId] and [Users].[UserID]!='admin'";
     return DB.GetDataSetSql(sql);//DB.GetDataSet("Proc_UsersList");
 }
    //初始化试卷,从数据库中将试题取出
    protected void PaperData()
    {
        string userid = Request.QueryString["UserID"].ToString();
        paperid = int.Parse(Request.QueryString["PaperID"].ToString());

        DataBase DB = new DataBase();

        DataSet ds = DB.GetDataSetSql("select * from [UserAnswertb] where UserID='" + userid + "'");
        DataRow[] row = ds.Tables[0].Select();
        foreach (DataRow rs in row)
        {
            lblExamtime.Text = rs["ExamTime"].ToString();
        }

        SqlParameter[] Params1 = new SqlParameter[3];
        Params1[0] = DB.MakeInParam("@PaperID", SqlDbType.Int, 4, paperid);
        Params1[1] = DB.MakeInParam("@Type", SqlDbType.VarChar, 10, "单选题");
        Params1[2] = DB.MakeInParam("@UserID", SqlDbType.VarChar, 50, userid);
        DataSet ds1 = DB.GetDataSet("Proc_UserAnswertb", Params1);
        if (ds1.Tables[0].Rows.Count > 0)
        {
            GridView11.DataSource = ds1;
            GridView11.DataBind();
            ((Label)GridView11.HeaderRow.FindControl("Label27")).Text = ((Label)GridView11.Rows[0].FindControl("Label4")).Text;
        }

        SqlParameter[] Params2 = new SqlParameter[3];
        Params2[0] = DB.MakeInParam("@PaperID", SqlDbType.Int, 4, paperid);
        Params2[1] = DB.MakeInParam("@Type", SqlDbType.VarChar, 10, "多选题");
        Params2[2] = DB.MakeInParam("@UserID", SqlDbType.VarChar, 50, userid);
        DataSet ds2 = DB.GetDataSet("Proc_UserAnswertb", Params2);
        if (ds2.Tables[0].Rows.Count > 0)
        {
            GridView2.DataSource = ds2;
            GridView2.DataBind();
            ((Label)GridView2.HeaderRow.FindControl("Label28")).Text = ((Label)GridView2.Rows[0].FindControl("Label8")).Text;
        }

        SqlParameter[] Params3 = new SqlParameter[3];
        Params3[0] = DB.MakeInParam("@PaperID", SqlDbType.Int, 4, paperid);
        Params3[1] = DB.MakeInParam("@Type", SqlDbType.VarChar, 10, "判断题");
        Params3[2] = DB.MakeInParam("@UserID", SqlDbType.VarChar, 50, userid);
        DataSet ds3 = DB.GetDataSet("Proc_UserAnswertb", Params3);
        if (ds3.Tables[0].Rows.Count > 0)
        {
            GridView3.DataSource = ds3;
            GridView3.DataBind();
            ((Label)GridView3.HeaderRow.FindControl("Label29")).Text = ((Label)GridView3.Rows[0].FindControl("Label12")).Text;
        }

        SqlParameter[] Params4 = new SqlParameter[3];
        Params4[0] = DB.MakeInParam("@PaperID", SqlDbType.Int, 4, paperid);
        Params4[1] = DB.MakeInParam("@Type", SqlDbType.VarChar, 10, "填空题");
        Params4[2] = DB.MakeInParam("@UserID", SqlDbType.VarChar, 50, userid);
        DataSet ds4 = DB.GetDataSet("Proc_UserAnswertb", Params4);
        if (ds4.Tables[0].Rows.Count > 0)
        {
            GridView4.DataSource = ds4;
            GridView4.DataBind();
            ((Label)GridView4.HeaderRow.FindControl("Label30")).Text = ((Label)GridView4.Rows[0].FindControl("Label17")).Text;
        }
        SqlParameter[] Params5 = new SqlParameter[3];
        Params5[0] = DB.MakeInParam("@PaperID", SqlDbType.Int, 4, paperid);
        Params5[1] = DB.MakeInParam("@Type", SqlDbType.VarChar, 10, "问答题");
        Params5[2] = DB.MakeInParam("@UserID", SqlDbType.VarChar, 50, userid);
        DataSet ds5 = DB.GetDataSet("Proc_UserAnswertb", Params5);
        if (ds5.Tables[0].Rows.Count > 0)
        {
            GridView5.DataSource = ds5;
            GridView5.DataBind();
            ((Label)GridView5.HeaderRow.FindControl("Label31")).Text = ((Label)GridView5.Rows[0].FindControl("Label21")).Text;
        }

        if (GridView11.Rows.Count > 0)
        {
            int score1 = 0;
            int singlemark = int.Parse(((Label)GridView11.Rows[0].FindControl("Label4")).Text);//取出单选题的每题分值
            foreach (GridViewRow dr in GridView11.Rows)
            {
                if (((Label)dr.FindControl("Label3")).Text.Trim() == "A")
                {
                    ((RadioButton)dr.FindControl("RadioButton1")).Checked = true;
                }
                else if (((Label)dr.FindControl("Label3")).Text.Trim() == "B")
                {
                    ((RadioButton)dr.FindControl("RadioButton2")).Checked = true;
                }
                else if (((Label)dr.FindControl("Label3")).Text.Trim() == "C")
                {
                    ((RadioButton)dr.FindControl("RadioButton3")).Checked = true;
                }
                else if (((Label)dr.FindControl("Label3")).Text.Trim() == "D")
                {
                    ((RadioButton)dr.FindControl("RadioButton4")).Checked = true;
                }
                if (((Label)dr.FindControl("Label3")).Text.Trim() == ((Label)dr.FindControl("Label23")).Text.Trim())
                {
                    score1 = score1 + singlemark;
                    sinScore.Text = Convert.ToString(score1);
                }
            }
        }

        if (GridView2.Rows.Count > 0)
        {
            int score2 = 0;
            int multimark = int.Parse(((Label)GridView2.Rows[0].FindControl("Label8")).Text);//取出多选题每题分值
            foreach (GridViewRow dr in GridView2.Rows)
            {
                if (((Label)dr.FindControl("Label7")).Text.Trim() == "A")
                {
                    ((CheckBox)dr.FindControl("CheckBox1")).Checked = true;
                }
                if (((Label)dr.FindControl("Label7")).Text.Trim() == "B")
                {
                    ((CheckBox)dr.FindControl("CheckBox2")).Checked = true;
                }
                if (((Label)dr.FindControl("Label7")).Text.Trim() == "C")
                {
                    ((CheckBox)dr.FindControl("CheckBox3")).Checked = true;
                }
                if (((Label)dr.FindControl("Label7")).Text.Trim() == "D")
                {
                    ((CheckBox)dr.FindControl("CheckBox4")).Checked = true;
                }
                if (((Label)dr.FindControl("Label7")).Text.Trim() == "AB")
                {
                    ((CheckBox)dr.FindControl("CheckBox1")).Checked = true;
                    ((CheckBox)dr.FindControl("CheckBox2")).Checked = true;
                }
                if (((Label)dr.FindControl("Label7")).Text.Trim() == "AC")
                {
                    ((CheckBox)dr.FindControl("CheckBox1")).Checked = true;
                    ((CheckBox)dr.FindControl("CheckBox3")).Checked = true;
                }
                if (((Label)dr.FindControl("Label7")).Text.Trim() == "AD")
                {
                    ((CheckBox)dr.FindControl("CheckBox1")).Checked = true;
                    ((CheckBox)dr.FindControl("CheckBox4")).Checked = true;
                }
                if (((Label)dr.FindControl("Label7")).Text.Trim() == "BC")
                {
                    ((CheckBox)dr.FindControl("CheckBox2")).Checked = true;
                    ((CheckBox)dr.FindControl("CheckBox3")).Checked = true;
                }
                if (((Label)dr.FindControl("Label7")).Text.Trim() == "BD")
                {
                    ((CheckBox)dr.FindControl("CheckBox2")).Checked = true;
                    ((CheckBox)dr.FindControl("CheckBox4")).Checked = true;
                }
                if (((Label)dr.FindControl("Label7")).Text.Trim() == "CD")
                {
                    ((CheckBox)dr.FindControl("CheckBox3")).Checked = true;
                    ((CheckBox)dr.FindControl("CheckBox4")).Checked = true;
                }
                if (((Label)dr.FindControl("Label7")).Text.Trim() == "ABC")
                {
                    ((CheckBox)dr.FindControl("CheckBox1")).Checked = true;
                    ((CheckBox)dr.FindControl("CheckBox2")).Checked = true;
                    ((CheckBox)dr.FindControl("CheckBox3")).Checked = true;
                }
                if (((Label)dr.FindControl("Label7")).Text.Trim() == "ABD")
                {
                    ((CheckBox)dr.FindControl("CheckBox1")).Checked = true;
                    ((CheckBox)dr.FindControl("CheckBox2")).Checked = true;
                    ((CheckBox)dr.FindControl("CheckBox4")).Checked = true;
                }
                if (((Label)dr.FindControl("Label7")).Text.Trim() == "ACD")
                {
                    ((CheckBox)dr.FindControl("CheckBox1")).Checked = true;
                    ((CheckBox)dr.FindControl("CheckBox3")).Checked = true;
                    ((CheckBox)dr.FindControl("CheckBox4")).Checked = true;
                }
                if (((Label)dr.FindControl("Label7")).Text.Trim() == "ABCD")
                {
                    ((CheckBox)dr.FindControl("CheckBox1")).Checked = true;
                    ((CheckBox)dr.FindControl("CheckBox2")).Checked = true;
                    ((CheckBox)dr.FindControl("CheckBox3")).Checked = true;
                    ((CheckBox)dr.FindControl("CheckBox4")).Checked = true;
                }
                if (((Label)dr.FindControl("Label7")).Text.Trim() == ((Label)dr.FindControl("Label27")).Text.Trim())
                {
                    score2 = score2 + multimark;
                    mulScore.Text = Convert.ToString(score2);
                }
            }
        }

        if (GridView3.Rows.Count > 0)
        {
            int score3 = 0;
            int judgemark = int.Parse(((Label)GridView3.Rows[0].FindControl("Label12")).Text);//取出判断题每题分值
            foreach (GridViewRow dr in GridView3.Rows)//对判断题每题进行判断用户选择答案
            {
                try
                {
                    if (bool.Parse(((Label)dr.FindControl("Label11")).Text.Trim()))
                    {
                        ((CheckBox)dr.FindControl("CheckBox5")).Checked = true;
                    }
                    else
                    {
                        ((CheckBox)dr.FindControl("CheckBox6")).Checked = true;
                    }
                }
                catch
                {
                    ((CheckBox)dr.FindControl("CheckBox5")).Checked = false;
                    ((CheckBox)dr.FindControl("CheckBox6")).Checked = false;
                }
                if (((Label)dr.FindControl("Label11")).Text.Trim() == ((Label)dr.FindControl("Label41")).Text.Trim())
                {
                    score3 = score3 + judgemark;
                    judScore.Text = Convert.ToString(score3);
                }
            }
        }
        //取出填空题每题分值
        if (GridView4.Rows.Count > 0)
        {
            int score4 = 0;
            int fillmark = int.Parse(((Label)GridView4.Rows[0].FindControl("Label17")).Text);
            foreach (GridViewRow dr in GridView4.Rows)//对填空题每题进行判断用户选择答案
            {
                string str = "";
                str = ((TextBox)dr.FindControl("TextBox1")).Text.Trim();
                if (str == ((Label)dr.FindControl("Label26")).Text.Trim())
                {
                    score4 = score4 + fillmark;
                    filScore.Text = Convert.ToString(score4);
                }
            }
        }
    }
    //初始化试卷,从数据库中将试题取出
    protected void PaperData()
    {
        string userid = Request.QueryString["UserID"].ToString();
        paperid = int.Parse(Request.QueryString["PaperID"].ToString());

        DataBase DB = new DataBase();

        DataSet ds = DB.GetDataSetSql("select PaperName,ExamTime from [UserAnswertb],[Paper] where[UserAnswertb].PaperID=[Paper].PaperID and UserID='" + userid + "' and [UserAnswertb].PaperID='" + paperid + "'");
        DataRow[] row = ds.Tables[0].Select();
        //获取试卷基本信息
        lblExamtime.Text = row[0]["ExamTime"].ToString();
        lblExamname.Text = row[0]["PaperName"].ToString();
        //获取总分
        ds = DB.GetDataSetSql("select Score from Scoretb where UserID='" + userid + "' and PaperID='" + paperid + "'");
        DataRow[] rowSum = ds.Tables[0].Select();
        sumScore.Text = rowSum[0]["Score"].ToString();

        SqlParameter[] Params1 = new SqlParameter[3];
        Params1[0] = DB.MakeInParam("@PaperID", SqlDbType.Int, 4, paperid);
        Params1[1] = DB.MakeInParam("@Type", SqlDbType.VarChar, 10, "单选题");
        Params1[2] = DB.MakeInParam("@UserID", SqlDbType.VarChar, 50, userid);
        DataSet ds1 = DB.GetDataSet("Proc_UserAnswertb", Params1);
        if (ds1.Tables[0].Rows.Count > 0)
        {
            GridView11.DataSource = ds1;
            GridView11.DataBind();
            ((Label)GridView11.HeaderRow.FindControl("Label27")).Text = ((Label)GridView11.Rows[0].FindControl("Label4")).Text;
        }

        SqlParameter[] Params2 = new SqlParameter[3];
        Params2[0] = DB.MakeInParam("@PaperID", SqlDbType.Int, 4, paperid);
        Params2[1] = DB.MakeInParam("@Type", SqlDbType.VarChar, 10, "多选题");
        Params2[2] = DB.MakeInParam("@UserID", SqlDbType.VarChar, 50, userid);
        DataSet ds2 = DB.GetDataSet("Proc_UserAnswertb", Params2);
        if (ds2.Tables[0].Rows.Count > 0)
        {
            GridView2.DataSource = ds2;
            GridView2.DataBind();
            ((Label)GridView2.HeaderRow.FindControl("Label28")).Text = ((Label)GridView2.Rows[0].FindControl("Label8")).Text;
        }

        SqlParameter[] Params3 = new SqlParameter[3];
        Params3[0] = DB.MakeInParam("@PaperID", SqlDbType.Int, 4, paperid);
        Params3[1] = DB.MakeInParam("@Type", SqlDbType.VarChar, 10, "判断题");
        Params3[2] = DB.MakeInParam("@UserID", SqlDbType.VarChar, 50, userid);
        DataSet ds3 = DB.GetDataSet("Proc_UserAnswertb", Params3);
        if (ds3.Tables[0].Rows.Count > 0)
        {
            GridView3.DataSource = ds3;
            GridView3.DataBind();
            ((Label)GridView3.HeaderRow.FindControl("Label29")).Text = ((Label)GridView3.Rows[0].FindControl("Label12")).Text;
        }
        SqlParameter[] Params4 = new SqlParameter[3];
        Params4[0] = DB.MakeInParam("@PaperID", SqlDbType.Int, 4, paperid);
        Params4[1] = DB.MakeInParam("@Type", SqlDbType.VarChar, 10, "填空题");
        Params4[2] = DB.MakeInParam("@UserID", SqlDbType.VarChar, 50, userid);
        DataSet ds4 = DB.GetDataSet("Proc_UserAnswertb", Params4);
        if (ds4.Tables[0].Rows.Count > 0)
        {
            GridView4.DataSource = ds4;
            GridView4.DataBind();
            ((Label)GridView4.HeaderRow.FindControl("Label30")).Text = ((Label)GridView4.Rows[0].FindControl("Label17")).Text;
        }

        SqlParameter[] Params5 = new SqlParameter[3];
        Params5[0] = DB.MakeInParam("@PaperID", SqlDbType.Int, 4, paperid);
        Params5[1] = DB.MakeInParam("@Type", SqlDbType.VarChar, 10, "问答题");
        Params5[2] = DB.MakeInParam("@UserID", SqlDbType.VarChar, 50, userid);
        DataSet ds5 = DB.GetDataSet("Proc_UserAnswertb", Params5);
        if (ds5.Tables[0].Rows.Count > 0)
        {
            GridView5.DataSource = ds5;
            GridView5.DataBind();
            ((Label)GridView5.HeaderRow.FindControl("Label31")).Text = ((Label)GridView5.Rows[0].FindControl("Label21")).Text;
        }

        if (GridView11.Rows.Count > 0)
        {
            int score1 = 0;
            int singlemark = int.Parse(((Label)GridView11.Rows[0].FindControl("Label4")).Text);//取出单选题的每题分值
            foreach (GridViewRow dr in GridView11.Rows)
            {
                if (((Label)dr.FindControl("Label3")).Text.Trim() == "A")
                {
                    ((RadioButton)dr.FindControl("RadioButton1")).Checked = true;
                }
                else if (((Label)dr.FindControl("Label3")).Text.Trim() == "B")
                {
                    ((RadioButton)dr.FindControl("RadioButton2")).Checked = true;
                }
                else if (((Label)dr.FindControl("Label3")).Text.Trim() == "C")
                {
                    ((RadioButton)dr.FindControl("RadioButton3")).Checked = true;
                }
                else if (((Label)dr.FindControl("Label3")).Text.Trim() == "D")
                {
                    ((RadioButton)dr.FindControl("RadioButton4")).Checked = true;
                }
                if (((Label)dr.FindControl("Label3")).Text.Trim() == ((Label)dr.FindControl("Label23")).Text.Trim())
                {
                    score1 = score1 + singlemark;
                    sinScore.Text = Convert.ToString(score1);
                    //dr.Visible = false;//单选题

                }
                else
                {
                    dr.BackColor = System.Drawing.Color.LightPink;//错题以红色背景显示
                }
            }
        }

        if (GridView2.Rows.Count > 0)
        {
            int score2 = 0;
            int multimark = int.Parse(((Label)GridView2.Rows[0].FindControl("Label8")).Text);//取出多选题每题分值
            foreach (GridViewRow dr in GridView2.Rows)
            {
                if (((Label)dr.FindControl("Label7")).Text.Trim() == "A")
                {
                    ((CheckBox)dr.FindControl("CheckBox1")).Checked = true;
                }
                if (((Label)dr.FindControl("Label7")).Text.Trim() == "B")
                {
                    ((CheckBox)dr.FindControl("CheckBox2")).Checked = true;
                }
                if (((Label)dr.FindControl("Label7")).Text.Trim() == "C")
                {
                    ((CheckBox)dr.FindControl("CheckBox3")).Checked = true;
                }
                if (((Label)dr.FindControl("Label7")).Text.Trim() == "D")
                {
                    ((CheckBox)dr.FindControl("CheckBox4")).Checked = true;
                }
                if (((Label)dr.FindControl("Label7")).Text.Trim() == "AB")
                {
                    ((CheckBox)dr.FindControl("CheckBox1")).Checked = true;
                    ((CheckBox)dr.FindControl("CheckBox2")).Checked = true;
                }
                if (((Label)dr.FindControl("Label7")).Text.Trim() == "AC")
                {
                    ((CheckBox)dr.FindControl("CheckBox1")).Checked = true;
                    ((CheckBox)dr.FindControl("CheckBox3")).Checked = true;
                }
                if (((Label)dr.FindControl("Label7")).Text.Trim() == "AD")
                {
                    ((CheckBox)dr.FindControl("CheckBox1")).Checked = true;
                    ((CheckBox)dr.FindControl("CheckBox4")).Checked = true;
                }
                if (((Label)dr.FindControl("Label7")).Text.Trim() == "BC")
                {
                    ((CheckBox)dr.FindControl("CheckBox2")).Checked = true;
                    ((CheckBox)dr.FindControl("CheckBox3")).Checked = true;
                }
                if (((Label)dr.FindControl("Label7")).Text.Trim() == "BD")
                {
                    ((CheckBox)dr.FindControl("CheckBox2")).Checked = true;
                    ((CheckBox)dr.FindControl("CheckBox4")).Checked = true;
                }
                if (((Label)dr.FindControl("Label7")).Text.Trim() == "CD")
                {
                    ((CheckBox)dr.FindControl("CheckBox3")).Checked = true;
                    ((CheckBox)dr.FindControl("CheckBox4")).Checked = true;
                }
                if (((Label)dr.FindControl("Label7")).Text.Trim() == "ABC")
                {
                    ((CheckBox)dr.FindControl("CheckBox1")).Checked = true;
                    ((CheckBox)dr.FindControl("CheckBox2")).Checked = true;
                    ((CheckBox)dr.FindControl("CheckBox3")).Checked = true;
                }
                if (((Label)dr.FindControl("Label7")).Text.Trim() == "ABD")
                {
                    ((CheckBox)dr.FindControl("CheckBox1")).Checked = true;
                    ((CheckBox)dr.FindControl("CheckBox2")).Checked = true;
                    ((CheckBox)dr.FindControl("CheckBox4")).Checked = true;
                }
                if (((Label)dr.FindControl("Label7")).Text.Trim() == "ACD")
                {
                    ((CheckBox)dr.FindControl("CheckBox1")).Checked = true;
                    ((CheckBox)dr.FindControl("CheckBox3")).Checked = true;
                    ((CheckBox)dr.FindControl("CheckBox4")).Checked = true;
                }
                if (((Label)dr.FindControl("Label7")).Text.Trim() == "ABCD")
                {
                    ((CheckBox)dr.FindControl("CheckBox1")).Checked = true;
                    ((CheckBox)dr.FindControl("CheckBox2")).Checked = true;
                    ((CheckBox)dr.FindControl("CheckBox3")).Checked = true;
                    ((CheckBox)dr.FindControl("CheckBox4")).Checked = true;
                }
                if (((Label)dr.FindControl("Label7")).Text.Trim() == ((Label)dr.FindControl("Label27")).Text.Trim())
                {
                    score2 = score2 + multimark;
                    mulScore.Text = Convert.ToString(score2);
                }
                else
                {
                    dr.BackColor = System.Drawing.Color.LightPink;//错题以红色背景显示

                }
            }
        }

        if (GridView3.Rows.Count > 0)
        {
            int score3 = 0;
            int judgemark = int.Parse(((Label)GridView3.Rows[0].FindControl("Label12")).Text);//取出判断题每题分值
            foreach (GridViewRow dr in GridView3.Rows)//对判断题每题进行判断用户选择答案
            {
                try
                {
                    if (bool.Parse(((Label)dr.FindControl("Label11")).Text.Trim()))
                    {
                        ((CheckBox)dr.FindControl("CheckBox5")).Checked = true;
                    }
                    else
                    {
                        ((CheckBox)dr.FindControl("CheckBox6")).Checked = true;
                    }
                }
                catch
                {
                    ((CheckBox)dr.FindControl("CheckBox5")).Checked = false;
                    ((CheckBox)dr.FindControl("CheckBox6")).Checked = false;
                }
                if (((Label)dr.FindControl("Label11")).Text.Trim() == ((Label)dr.FindControl("Label41")).Text.Trim())
                {
                    score3 = score3 + judgemark;
                    judScore.Text = Convert.ToString(score3);
                }
                else
                {
                    dr.BackColor = System.Drawing.Color.LightPink;//错题以红色背景显示

                }
            }
        }

        //计算总分
    }
    //初始化试卷,从数据库中将试题取出
    protected void InitData()
    {
        DataBase DB = new DataBase();
        string userid = Session["UserID"].ToString();
        paperid = int.Parse(Session["PaperID"].ToString());

        DataSet ds = DB.GetDataSetSql("select * from UserAnswertb where UserID='" + userid + "' and PaperID='" + paperid + "'");

        if (ds.Tables[0].Rows.Count>0)
        {
            sum = right =  error =  noDone = 0;//初始化变量

            SqlParameter[] Params1 = new SqlParameter[3];
            Params1[0] = DB.MakeInParam("@PaperID", SqlDbType.Int, 4, paperid);
            Params1[1] = DB.MakeInParam("@Type", SqlDbType.VarChar, 10, "单选题");
            Params1[2] = DB.MakeInParam("@UserID", SqlDbType.VarChar, 50, userid);
            DataSet ds1 = DB.GetDataSet("Proc_UserAnswertb", Params1);
            if (ds1.Tables[0].Rows.Count > 0)
            {
                GridView11.DataSource = ds1;
                GridView11.DataBind();
                ((Label)GridView11.HeaderRow.FindControl("Label27")).Text = ((Label)GridView11.Rows[0].FindControl("Label4")).Text;
            }

            SqlParameter[] Params2 = new SqlParameter[3];
            Params2[0] = DB.MakeInParam("@PaperID", SqlDbType.Int, 4, paperid);
            Params2[1] = DB.MakeInParam("@Type", SqlDbType.VarChar, 10, "多选题");
            Params2[2] = DB.MakeInParam("@UserID", SqlDbType.VarChar, 50, userid);
            DataSet ds2 = DB.GetDataSet("Proc_UserAnswertb", Params2);
            if (ds2.Tables[0].Rows.Count > 0)
            {
                GridView2.DataSource = ds2;
                GridView2.DataBind();
                ((Label)GridView2.HeaderRow.FindControl("Label28")).Text = ((Label)GridView2.Rows[0].FindControl("Label8")).Text;
            }

            SqlParameter[] Params3 = new SqlParameter[3];
            Params3[0] = DB.MakeInParam("@PaperID", SqlDbType.Int, 4, paperid);
            Params3[1] = DB.MakeInParam("@Type", SqlDbType.VarChar, 10, "判断题");
            Params3[2] = DB.MakeInParam("@UserID", SqlDbType.VarChar, 50, userid);
            DataSet ds3 = DB.GetDataSet("Proc_UserAnswertb", Params3);
            if (ds3.Tables[0].Rows.Count > 0)
            {
                GridView3.DataSource = ds3;
                GridView3.DataBind();
                ((Label)GridView3.HeaderRow.FindControl("Label29")).Text = ((Label)GridView3.Rows[0].FindControl("Label12")).Text;
            }
            SqlParameter[] Params4 = new SqlParameter[3];
            Params4[0] = DB.MakeInParam("@PaperID", SqlDbType.Int, 4, paperid);
            Params4[1] = DB.MakeInParam("@Type", SqlDbType.VarChar, 10, "填空题");
            Params4[2] = DB.MakeInParam("@UserID", SqlDbType.VarChar, 50, userid);
            DataSet ds4 = DB.GetDataSet("Proc_UserAnswertb", Params4);
            if (ds4.Tables[0].Rows.Count > 0)
            {
                GridView4.DataSource = ds4;
                GridView4.DataBind();
                ((Label)GridView4.HeaderRow.FindControl("Label30")).Text = ((Label)GridView4.Rows[0].FindControl("Label17")).Text;
            }

            SqlParameter[] Params5 = new SqlParameter[3];
            Params5[0] = DB.MakeInParam("@PaperID", SqlDbType.Int, 4, paperid);
            Params5[1] = DB.MakeInParam("@Type", SqlDbType.VarChar, 10, "问答题");
            Params5[2] = DB.MakeInParam("@UserID", SqlDbType.VarChar, 50, userid);
            DataSet ds5 = DB.GetDataSet("Proc_UserAnswertb", Params5);
            if (ds5.Tables[0].Rows.Count > 0)
            {
                GridView5.DataSource = ds5;
                GridView5.DataBind();
                ((Label)GridView5.HeaderRow.FindControl("Label31")).Text = ((Label)GridView5.Rows[0].FindControl("Label21")).Text;
            }

            //得到题目总数
            sum = GridView11.Rows.Count + GridView2.Rows.Count + GridView3.Rows.Count + GridView4.Rows.Count ;

            if (GridView11.Rows.Count > 0)
            {
                foreach (GridViewRow dr in GridView11.Rows)
                {
                    if (((Label)dr.FindControl("Label3")).Text.Trim() == "A")
                    {
                        ((RadioButton)dr.FindControl("RadioButton1")).Checked = true;
                    }
                    else if (((Label)dr.FindControl("Label3")).Text.Trim() == "B")
                    {
                        ((RadioButton)dr.FindControl("RadioButton2")).Checked = true;
                    }
                    else if (((Label)dr.FindControl("Label3")).Text.Trim() == "C")
                    {
                        ((RadioButton)dr.FindControl("RadioButton3")).Checked = true;
                    }
                    else if (((Label)dr.FindControl("Label3")).Text.Trim() == "D")
                    {
                        ((RadioButton)dr.FindControl("RadioButton4")).Checked = true;
                    }
                    if (((Label)dr.FindControl("Label3")).Text.Trim() == ((Label)dr.FindControl("lbSingleAnswer")).Text.Trim())
                    {

                        right++;

                    }
                    else
                    {
                        if(((Label)dr.FindControl("Label3")).Text.Trim()=="")
                        {
                            noDone++;
                        }
                        else
                        {
                            dr.BackColor = System.Drawing.Color.LightPink;//错题以红色背景显示
                            error++;
                        }

                    }
                }
            }

            if (GridView2.Rows.Count > 0)
            {
                foreach (GridViewRow dr in GridView2.Rows)
                {
                    if (((Label)dr.FindControl("Label7")).Text.Trim() == "A")
                    {
                        ((CheckBox)dr.FindControl("CheckBox1")).Checked = true;
                    }
                    if (((Label)dr.FindControl("Label7")).Text.Trim() == "B")
                    {
                        ((CheckBox)dr.FindControl("CheckBox2")).Checked = true;
                    }
                    if (((Label)dr.FindControl("Label7")).Text.Trim() == "C")
                    {
                        ((CheckBox)dr.FindControl("CheckBox3")).Checked = true;
                    }
                    if (((Label)dr.FindControl("Label7")).Text.Trim() == "D")
                    {
                        ((CheckBox)dr.FindControl("CheckBox4")).Checked = true;
                    }
                    if (((Label)dr.FindControl("Label7")).Text.Trim() == "AB")
                    {
                        ((CheckBox)dr.FindControl("CheckBox1")).Checked = true;
                        ((CheckBox)dr.FindControl("CheckBox2")).Checked = true;
                    }
                    if (((Label)dr.FindControl("Label7")).Text.Trim() == "AC")
                    {
                        ((CheckBox)dr.FindControl("CheckBox1")).Checked = true;
                        ((CheckBox)dr.FindControl("CheckBox3")).Checked = true;
                    }
                    if (((Label)dr.FindControl("Label7")).Text.Trim() == "AD")
                    {
                        ((CheckBox)dr.FindControl("CheckBox1")).Checked = true;
                        ((CheckBox)dr.FindControl("CheckBox4")).Checked = true;
                    }
                    if (((Label)dr.FindControl("Label7")).Text.Trim() == "BC")
                    {
                        ((CheckBox)dr.FindControl("CheckBox2")).Checked = true;
                        ((CheckBox)dr.FindControl("CheckBox3")).Checked = true;
                    }
                    if (((Label)dr.FindControl("Label7")).Text.Trim() == "BD")
                    {
                        ((CheckBox)dr.FindControl("CheckBox2")).Checked = true;
                        ((CheckBox)dr.FindControl("CheckBox4")).Checked = true;
                    }
                    if (((Label)dr.FindControl("Label7")).Text.Trim() == "CD")
                    {
                        ((CheckBox)dr.FindControl("CheckBox3")).Checked = true;
                        ((CheckBox)dr.FindControl("CheckBox4")).Checked = true;
                    }
                    if (((Label)dr.FindControl("Label7")).Text.Trim() == "ABC")
                    {
                        ((CheckBox)dr.FindControl("CheckBox1")).Checked = true;
                        ((CheckBox)dr.FindControl("CheckBox2")).Checked = true;
                        ((CheckBox)dr.FindControl("CheckBox3")).Checked = true;
                    }
                    if (((Label)dr.FindControl("Label7")).Text.Trim() == "ABD")
                    {
                        ((CheckBox)dr.FindControl("CheckBox1")).Checked = true;
                        ((CheckBox)dr.FindControl("CheckBox2")).Checked = true;
                        ((CheckBox)dr.FindControl("CheckBox4")).Checked = true;
                    }
                    if (((Label)dr.FindControl("Label7")).Text.Trim() == "ACD")
                    {
                        ((CheckBox)dr.FindControl("CheckBox1")).Checked = true;
                        ((CheckBox)dr.FindControl("CheckBox3")).Checked = true;
                        ((CheckBox)dr.FindControl("CheckBox4")).Checked = true;
                    }
                    if (((Label)dr.FindControl("Label7")).Text.Trim() == "ABCD")
                    {
                        ((CheckBox)dr.FindControl("CheckBox1")).Checked = true;
                        ((CheckBox)dr.FindControl("CheckBox2")).Checked = true;
                        ((CheckBox)dr.FindControl("CheckBox3")).Checked = true;
                        ((CheckBox)dr.FindControl("CheckBox4")).Checked = true;
                    }
                    if (((Label)dr.FindControl("Label7")).Text.Trim() == ((Label)dr.FindControl("lbMultiAnswer")).Text.Trim())
                    {
                        right++;
                    }
                    else
                    {
                        if(((Label)dr.FindControl("Label7")).Text.Trim()=="")
                        {
                            noDone++;
                        }
                        else
                        {
                            dr.BackColor = System.Drawing.Color.LightPink;//错题以红色背景显示
                            error++;
                        }
                    }
                }
            }

            if (GridView3.Rows.Count > 0)
            {
                foreach (GridViewRow dr in GridView3.Rows)//对判断题每题进行判断用户选择答案
                {
                    try
                    {
                        if (bool.Parse(((Label)dr.FindControl("Label11")).Text.Trim()))
                        {
                            ((CheckBox)dr.FindControl("RadioButton5")).Checked = true;
                        }
                        else
                        {
                            ((CheckBox)dr.FindControl("RadioButton6")).Checked = true;
                        }
                    }
                    catch
                    {
                        ((CheckBox)dr.FindControl("RadioButton5")).Checked = false;
                        ((CheckBox)dr.FindControl("RadioButton6")).Checked = false;
                    }
                    if (((Label)dr.FindControl("Label11")).Text.Trim() == ((Label)dr.FindControl("lbJudgeAnswer")).Text.Trim())
                    {
                        right++;
                    }
                    else
                    {
                        if(((Label)dr.FindControl("Label11")).Text.Trim()=="")
                        {
                            noDone++;
                        }
                        else
                        {
                            dr.BackColor = System.Drawing.Color.LightPink;//错题以红色背景显示
                            error++;
                        }
                    }
                }
            }
            //取出填空题每题分值
            if (GridView4.Rows.Count > 0)
            {
                int score4 = 0;
                int fillmark = int.Parse(((Label)GridView4.Rows[0].FindControl("Label17")).Text);
                foreach (GridViewRow dr in GridView4.Rows)//对填空题每题进行判断用户选择答案
                {
                    string str = "";
                    str = ((TextBox)dr.FindControl("TextBox1")).Text.Trim();
                    if (str == ((Label)dr.FindControl("Label26")).Text.Trim())
                    {
                        right++;
                    }
                    else
                    {
                        if (str == "")
                        {
                            noDone++;
                        }
                        else
                        {
                            dr.BackColor = System.Drawing.Color.LightPink;//错题以红色背景显示
                            error++;
                        }

                    }
                }
            }

            lbSumUp.Text = "除问答题外,共"+sum.ToString()+"道客观题,其中正确"+right.ToString()+"道题,错误"+error.ToString()+"道题,"+noDone.ToString()+"没做!";
        }
        else
        {
            int paperID = paperid;
            lbSumUp.Text = "没有记录!";
            SqlParameter[] Params1 = new SqlParameter[2];
            Params1[0] = DB.MakeInParam("@PaperID", SqlDbType.Int, 4, paperID);               //试卷编号
            Params1[1] = DB.MakeInParam("@Type", SqlDbType.VarChar, 10, "单选题");            //题目类型
            DataSet ds1 = DB.GetDataSet("Proc_PaperDetail", Params1);
            if (ds1.Tables[0].Rows.Count > 0)//判断下是否有单选题
            {
                GridView11.DataSource = ds1;
                GridView11.DataBind();
                ((Label)GridView11.HeaderRow.FindControl("Label27")).Text = ((Label)GridView11.Rows[0].FindControl("Label4")).Text;
            }

            SqlParameter[] Params2 = new SqlParameter[2];
            Params2[0] = DB.MakeInParam("@PaperID", SqlDbType.Int, 4, paperID);               //试卷编号
            Params2[1] = DB.MakeInParam("@Type", SqlDbType.VarChar, 10, "多选题");            //题目类型
            DataSet ds2 = DB.GetDataSet("Proc_PaperDetail", Params2);
            if (ds2.Tables[0].Rows.Count > 0)
            {
                GridView2.DataSource = ds2;
                GridView2.DataBind();
                ((Label)GridView2.HeaderRow.FindControl("Label28")).Text = ((Label)GridView2.Rows[0].FindControl("Label8")).Text;
            }

            SqlParameter[] Params3 = new SqlParameter[2];
            Params3[0] = DB.MakeInParam("@PaperID", SqlDbType.Int, 4, paperID);               //试卷编号
            Params3[1] = DB.MakeInParam("@Type", SqlDbType.VarChar, 10, "判断题");            //题目类型
            DataSet ds3 = DB.GetDataSet("Proc_PaperDetail", Params3);
            if (ds3.Tables[0].Rows.Count > 0)
            {
                GridView3.DataSource = ds3;
                GridView3.DataBind();
                ((Label)GridView3.HeaderRow.FindControl("Label29")).Text = ((Label)GridView3.Rows[0].FindControl("Label12")).Text;
            }
            SqlParameter[] Params4 = new SqlParameter[2];
            Params4[0] = DB.MakeInParam("@PaperID", SqlDbType.Int, 4, paperID);               //试卷编号
            Params4[1] = DB.MakeInParam("@Type", SqlDbType.VarChar, 10, "填空题");            //题目类型
            DataSet ds4 = DB.GetDataSet("Proc_PaperDetail", Params4);
            if (ds4.Tables[0].Rows.Count > 0)
            {
                GridView4.DataSource = ds4;
                GridView4.DataBind();
                ((Label)GridView4.HeaderRow.FindControl("Label30")).Text = ((Label)GridView4.Rows[0].FindControl("Label17")).Text;
            }
            SqlParameter[] Params5 = new SqlParameter[2];
            Params5[0] = DB.MakeInParam("@PaperID", SqlDbType.Int, 4, paperID);               //试卷编号
            Params5[1] = DB.MakeInParam("@Type", SqlDbType.VarChar, 10, "问答题");            //题目类型
            DataSet ds5 = DB.GetDataSet("Proc_PaperDetail", Params5);
            if (ds5.Tables[0].Rows.Count > 0)
            {
                GridView5.DataSource = ds5;
                GridView5.DataBind();
                ((Label)GridView5.HeaderRow.FindControl("Label31")).Text = ((Label)GridView5.Rows[0].FindControl("Label21")).Text;
            }

        }
    }
Exemple #8
0
 //从评审后的成绩数据库中读取成绩列表!
 public DataSet QueryUserPaperList2(string UID)
 {
     DataBase DB = new DataBase();
     //return DB.GetDataSet("Proc_UserPaperList");
     string SqlStr = string.Format("SELECT distinct [dbo].[Users].[UserID],[dbo].[Users].[UserName],[dbo].[UserAnswertb].[UserID],	[dbo].[UserAnswertb].[PaperID],[dbo].[UserAnswertb].[ExamTime],[dbo].[UserAnswertb].[state],[dbo].[Paper].[PaperName] FROM [dbo].[Users],[dbo].[UserAnswertb],[dbo].[Paper] where Users.UserID=UserAnswertb.UserID and UserAnswertb.PaperID=Paper.PaperID and Paper.NeedTime!=0 and UserAnswertb.UserID='{0}'", UID);
     return DB.GetDataSetSql(SqlStr);
 }
Exemple #9
0
 public DataSet QueryTestPaper()
 {
     DataBase DB = new DataBase();
     string SqlStr = string.Format("SELECT [Paper].[PaperID],[Paper].[PaperName] FROM [Paper] where PaperState=1 and NeedTime =0");// and PaperID not in(SELECT PaperID FROM UserAnswertb WHERE UserID='{0}')", userid);
     return DB.GetDataSetSql(SqlStr);
 }