Beispiel #1
0
    private void AddStudentRecord(int arrangeid, int userid, int subjectid, int hasShortAnswer)
    {
        //查询所有要进行该考试的学生
        String    strSql = "select id from tbUser where classid in (select classid from tbGrant where userid=" + userid + " and subjectid=" + subjectid + ")";
        DataTable table  = DbHelperSQL.Query(strSql).Tables[0];

        //取得数据库连接
        SqlConnection conn = SQLHelper.GetConnection();

        //打开数据库连接
        conn.Open();
        //创建事务
        SqlTransaction SqlTransaction = conn.BeginTransaction();

        try
        {
            for (int i = 0; i < table.Rows.Count; i++)
            {
                tbScore score = new tbScore();
                score.arrangeid      = arrangeid;
                score.userid         = Convert.ToInt32(table.Rows[i][0]);
                score.createtime     = DateTime.Now;
                score.starttime      = DateTime.Now;
                score.endtime        = DateTime.Now;
                score.hasshortanswer = hasShortAnswer;
                score.hascorrect     = 0; //没有批改
                score.scorestatus    = 1; //还没考试
                scoreDAL.AddTran(score, SqlTransaction);
            }
            SqlTransaction.Commit();
        }
        catch (Exception)
        {
            try
            {
                SqlTransaction.Rollback();
            }
            catch (Exception)
            {
                //事务回滚出错
            }
            throw;
        }
        finally
        {
            //关闭各种资源
            SqlTransaction.Dispose();
            conn.Close();
        }
    }
Beispiel #2
0
    /// <summary>
    /// 交卷
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        //比较时间大小
        int scoreid = Convert.ToInt32(ViewState[Constant.ScoreID]);

        score = scoreBLL.GetModel(scoreid);

        PaperContent studentAnswer  = CollectData();
        PaperContent standardAnswer = GetStandardAnswer(studentAnswer);

        if (arrange.arrangetype == 1)
        {
            //===============练习
            ShowCorrectAnswer(studentAnswer, standardAnswer);
            MyUtil.ExecuteJS(this, "clearInterval(timer);document.getElementById('timer').style.display='none';");
        }
        if (arrange.arrangetype == 2)
        {
            //===============考试
            score.endtime = DateTime.Now;
            if (DateTime.Compare(DateTime.Now, score.starttime.AddMinutes(paper.durationtime + 5)) > 0)
            {
                //超时
                MyUtil.ExecuteJS(this, "alert('交卷失败,超过指定时间!');top.closeExam();");
                score.scorestatus = 4;
                scoreBLL.Update(score);
                return;
            }
            score.score = Convert.ToDecimal(sum);
            if (paper.sa_count > 0)
            {
                //有简答题,等待批改
                score.scorestatus = 5;
            }
            else
            {
                //记录成绩
                score.scorestatus = 3;
            }
            scoreBLL.Update(score);
            //MyUtil.ExecuteJS(this, "alert('交卷成功!');top.closeExam();");
            Response.Write("<script type='text/javascript'>alert('交卷成功!');top.closeExam();</script>");
        }
        lbtnSubmit.Visible = false;
        lbtnBack.Visible   = true;
    }
    protected void lbtnAdd_Click(object sender, EventArgs e)
    {
        int answerofpaperid = Convert.ToInt32(ViewState["answerofpaperid"].ToString());
        int userid          = Convert.ToInt32(ViewState["userid"].ToString());

        tbAnswerOfPaper model = answerOfPaperDAL.GetModel(answerofpaperid);

        model.getscore = Convert.ToDecimal(ddlGetScore.SelectedValue);
        answerOfPaperDAL.Update(model);
        //判断这个学生的简答题是否全部改完
        if (!DbHelperSQL.Exists("select * from tbAnswerOfPaper where arrangeid=" + arrangeid + " and userid=" + userid + " and getscore=-1"))
        {
            //批改完毕
            double  sum     = (double)DbHelperSQL.GetSingle("select sum(getscore) from tbAnswerOfPaper where arrangeid=" + arrangeid + " and userid=" + userid);
            int     scoreid = (int)DbHelperSQL.GetSingle("select id from tbScore where arrangeid=" + arrangeid + " and userid=" + userid);
            tbScore score   = scoreDAL.GetModel(scoreid);
            score.hascorrect  = 1;
            score.scorestatus = 3;
            score.score      += Convert.ToDecimal(sum);
            scoreDAL.Update(score);
        }
        BindData();
    }
Beispiel #4
0
    protected void Page_Load(object sender, EventArgs e)
    {
        arrangeid = Convert.ToInt32(Request.QueryString["id"]);
        arrange   = arrangeBLL.GetModel(arrangeid);
        paper     = paperBLL.GetModel(arrange.paperid);
        subject   = subjectBLL.GetModel(arrange.subjectid);

        if (!IsPostBack)
        {
            //取得数据库连接
            SqlConnection conn = SQLHelper.GetConnection();
            //打开数据库连接
            conn.Open();
            //创建事务
            SqlTransaction SqlTransaction = conn.BeginTransaction();

            try
            {
                PaperGenerateDAL pgd = new PaperGenerateDAL(paper, SqlTransaction);
                pc = pgd.GetPaperContent();
                SqlTransaction.Commit();
            }
            catch (Exception)
            {
                try
                {
                    SqlTransaction.Rollback();
                }
                catch (Exception)
                {
                    //事务回滚出错
                }
            }
            finally
            {
                //关闭各种资源
                SqlTransaction.Dispose();
                conn.Close();
            }
            if (arrange.arrangetype == 2)
            {
                //考试,记录考试时间,成绩状态
                tbUser  user  = (tbUser)Session[Constant.User];
                tbScore score = this.GetScore(arrangeid, user.id);
                score.starttime   = DateTime.Now;
                score.scorestatus = 2;//正在考试
                scoreBLL.Update(score);

                //把scoreid存放在ViewState
                ViewState[Constant.ScoreID] = score.id;
            }
            if (pc.SRContent.Count != 0)
            {
                rptSR.DataSource = pc.SRContent;
                rptSR.DataBind();
            }

            if (pc.CBContent.Count != 0)
            {
                rptCB.DataSource = pc.CBContent;
                rptCB.DataBind();
            }

            if (pc.JDContent.Count != 0)
            {
                rptJD.DataSource = pc.JDContent;
                rptJD.DataBind();
            }

            if (pc.BFContent.Count != 0)
            {
                rptBF.DataSource = pc.BFContent;
                rptBF.DataBind();
            }

            if (pc.SAContent.Count != 0)
            {
                rptSA.DataSource = pc.SAContent;
                rptSA.DataBind();
            }
        }
    }