Exemplo n.º 1
0
    private void SetPaperContent(List<Int32> list1, List<Int32> list2, List<Int32> list3, List<Int32> list4, List<Int32> list5)
    {
        tbSingleDAL singleDAL = new tbSingleDAL();
        tbCheckDAL checkDAL = new tbCheckDAL();
        tbJudgeDAL judgeDAL = new tbJudgeDAL();
        tbBlankDAL blankDAL = new tbBlankDAL();
        tbAnswerDAL answerDAl = new tbAnswerDAL();

        //单选题
        for (int i = 0; i < list1.Count; i++)
        {
            tbSingle single = singleDAL.GetModelTran(list1[i], SqlTransaction);
            //single.selectcount = single.selectcount + 1;
            //singleDAL.UpdateTran(single, SqlTransaction);
            paperContent.SRContent.Add(single);
        }

        //多选题
        for (int i = 0; i < list2.Count; i++)
        {
            tbCheck check = checkDAL.GetModelTran(list2[i], SqlTransaction);
            //check.selectcount = check.selectcount + 1;
            //checkDAL.UpdateTran(check, SqlTransaction);
            paperContent.CBContent.Add(check);
        }

        //判断题
        for (int i = 0; i < list3.Count; i++)
        {
            tbJudge judge = judgeDAL.GetModelTran(list3[i], SqlTransaction);
            //judge.selectcount = judge.selectcount + 1;
            //judgeDAL.UpdateTran(judge, SqlTransaction);
            paperContent.JDContent.Add(judge);
        }

        //填空题
        for (int i = 0; i < list4.Count; i++)
        {
            tbBlank blank = blankDAL.GetModelTran(list4[i], SqlTransaction);
            //blank.selectcount = blank.selectcount + 1;
            //blankDAL.UpdateTran(blank, SqlTransaction);
            paperContent.BFContent.Add(blank);
        }

        //简答题
        for (int i = 0; i < list5.Count; i++)
        {
            tbAnswer answer = answerDAl.GetModelTran(list5[i], SqlTransaction);
            //answer.selectcount = answer.selectcount + 1;
            //answerDAl.UpdateTran(answer, SqlTransaction);
            paperContent.SAContent.Add(answer);
        }
    }
Exemplo n.º 2
0
    /// <summary>
    /// 获取正确答案,计算分数,更新题库selectcount和rightcount
    /// </summary>
    /// <param name="studentAnswer"></param>
    /// <returns></returns>
    private PaperContent GetStandardAnswer(PaperContent studentAnswer)
    {
        PaperContent standardAnswer = new PaperContent();

        tbSingleDAL singleDAL = new tbSingleDAL();
        tbCheckDAL checkDAL = new tbCheckDAL();
        tbJudgeDAL judgeDAL = new tbJudgeDAL();
        tbBlankDAL blankDAL = new tbBlankDAL();
        tbAnswerDAL answerDAl = new tbAnswerDAL();
        tbAnswerOfPaperDAL answerOfPaperDAL = new tbAnswerOfPaperDAL();

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

        try
        {
            //单选
            foreach (tbSingle item in studentAnswer.SRContent)
            {
                tbSingle single = singleDAL.GetModelTran(item.id, SqlTransaction);
                single.selectcount = single.selectcount + 1;
                if (single.ans == item.ans)
                {
                    //正确
                    sum += paper.sa_scoreofeach;
                    single.rightcount = single.rightcount + 1;
                }
                standardAnswer.SRContent.Add(single);
                singleDAL.UpdateTran(single, SqlTransaction);
            }
            //多选
            foreach (tbCheck item in studentAnswer.CBContent)
            {
                tbCheck check = new tbCheckDAL().GetModelTran(item.id, SqlTransaction);
                check.selectcount = check.selectcount + 1;
                if (check.ans == item.ans)
                {
                    //正确
                    sum += paper.cb_scoreofeach;
                    check.rightcount = check.rightcount + 1;
                }
                standardAnswer.CBContent.Add(check);
                checkDAL.UpdateTran(check, SqlTransaction);
            }
            //判断
            foreach (tbJudge item in studentAnswer.JDContent)
            {
                tbJudge judge = new tbJudgeDAL().GetModelTran(item.id, SqlTransaction);
                judge.selectcount = judge.selectcount + 1;
                if (judge.ans == item.ans)
                {
                    //正确
                    sum += paper.jd_scoreofeach;
                    judge.rightcount = judge.rightcount + 1;
                }
                standardAnswer.JDContent.Add(judge);
                judgeDAL.UpdateTran(judge, SqlTransaction);
            }
            //填空
            foreach (tbBlank item in studentAnswer.BFContent)
            {
                tbBlank blank = new tbBlankDAL().GetModelTran(item.id, SqlTransaction);
                blank.selectcount = blank.selectcount + 1;
                if (blank.ans == item.ans)
                {
                    //正确
                    sum += paper.bf_scoreofeach;
                    blank.rightcount = blank.rightcount + 1;
                }
                standardAnswer.BFContent.Add(blank);
                blankDAL.UpdateTran(blank, SqlTransaction);
            }
            //简答题 不比较答案,但返回正确答案 并记录学生答案
            foreach (tbAnswer item in studentAnswer.SAContent)
            {
                tbAnswer answer = new tbAnswerDAL().GetModelTran(item.id, SqlTransaction);
                standardAnswer.SAContent.Add(answer);
                if (arrange.arrangetype == 2)
                {
                    //插入学生答案
                    tbAnswerOfPaper answerOfPaper = new tbAnswerOfPaper();
                    answerOfPaper.answerid = answer.id;
                    answerOfPaper.arrangeid = arrange.id;
                    answerOfPaper.useranswer = item.ans;
                    answerOfPaper.userid = score.userid;
                    answerOfPaper.allscore = paper.sa_scoreofeach;
                    answerOfPaper.getscore = -1;//还没批改
                    
                    //删除已存在的
                    String deleteSql = "delete from tbAnswerOfPaper where answerid=" + answerOfPaper.answerid + " and arrangeid=" + answerOfPaper.arrangeid + " and userid=" + answerOfPaper.userid;
                    SqlHelper.ExecuteNonQuery(SqlTransaction, CommandType.Text, deleteSql);

                    answerOfPaperDAL.AddTran(answerOfPaper, SqlTransaction);
                }
            }
            SqlTransaction.Commit();
        }
        catch (Exception)
        {
            try
            {
                SqlTransaction.Rollback();
            }
            catch (Exception)
            {
                //事务回滚出错
            }
        }
        finally
        {
            //关闭各种资源
            SqlTransaction.Dispose();
            conn.Close();
        }
        return standardAnswer;
    }