/// <summary>
 /// 获取数据集
 /// </summary>
 /// <param name="where"></param>
 /// <param name="orderBy"></param>
 /// <returns></returns>
 public List<Member_CourseContentTestAnswerResult> GetList(string where, string orderBy)
 {
     StringBuilder sql = new StringBuilder();
     sql.Append("select * from [dbo].[Member_CourseContentTestAnswerResult]");
     if (!string.IsNullOrEmpty(where))
         sql.Append(" where " + where);
     if (!string.IsNullOrEmpty(orderBy))
         sql.Append(" order by " + orderBy);
     List<Member_CourseContentTestAnswerResult> list = new List<Member_CourseContentTestAnswerResult>();
     using (IDataReader reader = MSEntLibSqlHelper.ExecuteDataReaderBySql(sql.ToString()))
     {
         while (reader.Read())
         {
             Member_CourseContentTestAnswerResult model = new Member_CourseContentTestAnswerResult();
             ConvertToModel(reader, model);
             list.Add(model);
         }
     }
     return list;
 }
 /// <summary>
 /// 新增一条记录
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public int Add(Member_CourseContentTestAnswerResult model)
 {
     StringBuilder sql = new StringBuilder();
     sql.Append("insert into [dbo].[Member_CourseContentTestAnswerResult] ([Verson],[UnitContent],[ClassId],[Score],[QuestionCnt],[RightAnswer],[WrongAnswer],[Result],[AccountId],[Delflag],[CreateDate])");
     sql.Append(" values (@Verson,@UnitContent,@ClassId,@Score,@QuestionCnt,@RightAnswer,@WrongAnswer,@Result,@AccountId,@Delflag,@CreateDate)");
     sql.Append(" set @Id=@@IDENTITY");
     SqlParameter[] cmdParams = new SqlParameter[]{
         new SqlParameter("@Id", SqlDbType.Int, 4) { Value = model.Id, Direction = ParameterDirection.Output },
         new SqlParameter("@Verson", SqlDbType.VarChar, 200) { Value = model.Verson },
         new SqlParameter("@UnitContent", SqlDbType.Int, 4) { Value = model.UnitContent },
         new SqlParameter("@ClassId", SqlDbType.Int, 4) { Value = model.ClassId },
         new SqlParameter("@Score", SqlDbType.Float, 8) { Value = model.Score },
         new SqlParameter("@QuestionCnt", SqlDbType.Int, 4) { Value = model.QuestionCnt },
         new SqlParameter("@RightAnswer", SqlDbType.Int, 4) { Value = model.RightAnswer },
         new SqlParameter("@WrongAnswer", SqlDbType.Int, 4) { Value = model.WrongAnswer },
         new SqlParameter("@Result", SqlDbType.Bit, 1) { Value = model.Result },
         new SqlParameter("@AccountId", SqlDbType.Int, 4) { Value = model.AccountId },
         new SqlParameter("@Delflag", SqlDbType.Bit, 1) { Value = model.Delflag },
         new SqlParameter("@CreateDate", SqlDbType.DateTime, 8) { Value = model.CreateDate }
     };
     int result = Convert.ToInt32(MSEntLibSqlHelper.ExecuteNonQueryBySql(sql.ToString(), cmdParams));
     model.Id = Convert.ToInt32(cmdParams[0].Value);
     return result;
 }
 /// <summary>
 /// 更新一条记录
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public bool Update(Member_CourseContentTestAnswerResult model)
 {
     return dal.Update(model) > 0;
 }
 /// <summary>
 /// 新增一条记录
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public int Add(Member_CourseContentTestAnswerResult model)
 {
     return dal.Add(model);
 }
Ejemplo n.º 5
0
        /// <summary>
        /// 获取[结业考试]结果
        /// </summary>
        /// <param name="listOther"></param>
        /// <returns></returns>
        private Member_CourseContentTestAnswerResult GetLearnOnLineExamResult(List<Member_CourseContentTestAnswerOther> listResultOther, out int TrainingId)
        {
            var strVerson = string.Empty;
            int iUnitContent = 0, iClassId = 0, iAccountId = 0, iQuestionCnt = 0, iRightAnswer = 0, iWrongAnswer = 0, iTrainingId = 0;
            double dblScore = 0, dblTestTotalScore = 0;
            var bolResult = false;

            var unitContentBll = new Course_UnitContentBLL();
            var Model_ExamResult = new Member_CourseContentTestAnswerResult();//保存总分
            var Model_ExamAnswer = new Member_CourseContentTestAnswer();

            if (listResultOther.Count > 0)
            {
                iTrainingId = listResultOther[0].TrainingId;
                iClassId = listResultOther[0].ClassId;
                iAccountId = Code.SiteCache.Instance.LoginInfo.UserId;
                iUnitContent = listResultOther[0].UnitContentId;//一批题目的UnitContentId相同
            }

            TrainingId = iTrainingId;

            var List_Course_UnitTest = this.GetExamCourseUnitTest(iTrainingId);
            iQuestionCnt = List_Course_UnitTest.Count;//总题数
            strVerson = List_Course_UnitTest[0].Verson;
            foreach (var item in listResultOther)
            {
                var modelUnitTest = List_Course_UnitTest.Find(x => x.Id == item.Id);
                if (modelUnitTest.QTtype == 4)//问答题
                {
                    iRightAnswer++;
                }
                else
                {
                    if (item.Answer.Trim() == modelUnitTest.Answer.Trim())//答案正确
                    {
                        iRightAnswer++;
                        dblScore += modelUnitTest.Credit.Value;//用户得分
                    }
                    else//答案错误
                    {
                        iWrongAnswer++;
                    }
                    dblTestTotalScore += modelUnitTest.Credit.Value;//所有题目的总分数
                }
            }

            //获取学员是否过关
            var Model_Content = unitContentBll.GetModel(iUnitContent, string.Empty);
            bolResult = iRightAnswer >= Model_Content.PassLine;

            Model_ExamResult.Verson = strVerson;
            Model_ExamResult.UnitContent = iUnitContent;
            Model_ExamResult.ClassId = iClassId;
            Model_ExamResult.Score = dblScore;
            Model_ExamResult.QuestionCnt = iQuestionCnt;
            Model_ExamResult.RightAnswer = iRightAnswer;
            Model_ExamResult.WrongAnswer = iWrongAnswer;

            Model_ExamResult.Result = bolResult;
            Model_ExamResult.AccountId = iAccountId;
            Model_ExamResult.Delflag = false;
            Model_ExamResult.CreateDate = DateTime.Now;

            return Model_ExamResult;
        }
 /// <summary>
 /// 获取分页数据集
 /// </summary>
 /// <param name="pageSize"></param>
 /// <param name="pageIndex"></param>
 /// <param name="where"></param>
 /// <param name="orderBy"></param>
 /// <param name="recordCount"></param>
 /// <returns></returns>
 public List<Member_CourseContentTestAnswerResult> GetList(int pageSize, int pageIndex, string where, string orderBy, out int recordCount)
 {
     if (string.IsNullOrEmpty(orderBy))
         throw new ArgumentNullException();
     StringBuilder sb = new StringBuilder();
     sb.Append("select count(1) from [dbo].[Member_CourseContentTestAnswerResult]");
     if (!string.IsNullOrEmpty(where))
         sb.Append(" where " + where);
     recordCount = Convert.ToInt32(MSEntLibSqlHelper.ExecuteScalarBySql(sb.ToString()));
     int start = (pageIndex - 1) * pageSize + 1;
     int end = pageIndex * pageSize;
     StringBuilder sql = new StringBuilder();
     sql.Append("select * from (select *,ROW_NUMBER() over (order by " + orderBy + ") as [RowNum] from [dbo].[Member_CourseContentTestAnswerResult]");
     if (!string.IsNullOrEmpty(where))
         sql.Append(" where " + where);
     sql.Append(") as T where [RowNum] between " + start + " and " + end);
     List<Member_CourseContentTestAnswerResult> list = new List<Member_CourseContentTestAnswerResult>();
     using (IDataReader reader = MSEntLibSqlHelper.ExecuteDataReaderBySql(sql.ToString()))
     {
         while (reader.Read())
         {
             Member_CourseContentTestAnswerResult model = new Member_CourseContentTestAnswerResult();
             ConvertToModel(reader, model);
             list.Add(model);
         }
     }
     return list;
 }
 private void ConvertToModel(IDataReader reader, Member_CourseContentTestAnswerResult model)
 {
     if (reader["Id"] != DBNull.Value)
         model.Id = Convert.ToInt32(reader["Id"]);
     if (reader["Verson"] != DBNull.Value)
         model.Verson = reader["Verson"].ToString();
     if (reader["UnitContent"] != DBNull.Value)
         model.UnitContent = Convert.ToInt32(reader["UnitContent"]);
     if (reader["ClassId"] != DBNull.Value)
         model.ClassId = Convert.ToInt32(reader["ClassId"]);
     if (reader["Score"] != DBNull.Value)
         model.Score = Convert.ToDouble(reader["Score"]);
     if (reader["QuestionCnt"] != DBNull.Value)
         model.QuestionCnt = Convert.ToInt32(reader["QuestionCnt"]);
     if (reader["RightAnswer"] != DBNull.Value)
         model.RightAnswer = Convert.ToInt32(reader["RightAnswer"]);
     if (reader["WrongAnswer"] != DBNull.Value)
         model.WrongAnswer = Convert.ToInt32(reader["WrongAnswer"]);
     if (reader["Result"] != DBNull.Value)
         model.Result = Convert.ToBoolean(reader["Result"]);
     if (reader["AccountId"] != DBNull.Value)
         model.AccountId = Convert.ToInt32(reader["AccountId"]);
     if (reader["Delflag"] != DBNull.Value)
         model.Delflag = Convert.ToBoolean(reader["Delflag"]);
     if (reader["CreateDate"] != DBNull.Value)
         model.CreateDate = Convert.ToDateTime(reader["CreateDate"]);
 }
 /// <summary>
 /// 更新一条记录
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public int Update(Member_CourseContentTestAnswerResult model)
 {
     StringBuilder sql = new StringBuilder();
     sql.Append("update [dbo].[Member_CourseContentTestAnswerResult] set ");
     sql.Append("[Verson]=@Verson,[UnitContent]=@UnitContent,[ClassId]=@ClassId,[Score]=@Score,[QuestionCnt]=@QuestionCnt,[RightAnswer]=@RightAnswer,[WrongAnswer]=@WrongAnswer,[Result]=@Result,[AccountId]=@AccountId,[Delflag]=@Delflag,[CreateDate]=@CreateDate");
     sql.Append(" where [Id]=@Id");
     SqlParameter[] cmdParams = new SqlParameter[] {
         new SqlParameter("@Id", SqlDbType.Int, 4) { Value = model.Id },
         new SqlParameter("@Verson", SqlDbType.VarChar, 200) { Value = model.Verson },
         new SqlParameter("@UnitContent", SqlDbType.Int, 4) { Value = model.UnitContent },
         new SqlParameter("@ClassId", SqlDbType.Int, 4) { Value = model.ClassId },
         new SqlParameter("@Score", SqlDbType.Float, 8) { Value = model.Score },
         new SqlParameter("@QuestionCnt", SqlDbType.Int, 4) { Value = model.QuestionCnt },
         new SqlParameter("@RightAnswer", SqlDbType.Int, 4) { Value = model.RightAnswer },
         new SqlParameter("@WrongAnswer", SqlDbType.Int, 4) { Value = model.WrongAnswer },
         new SqlParameter("@Result", SqlDbType.Bit, 1) { Value = model.Result },
         new SqlParameter("@AccountId", SqlDbType.Int, 4) { Value = model.AccountId },
         new SqlParameter("@Delflag", SqlDbType.Bit, 1) { Value = model.Delflag },
         new SqlParameter("@CreateDate", SqlDbType.DateTime, 8) { Value = model.CreateDate }
     };
     return MSEntLibSqlHelper.ExecuteNonQueryBySql(sql.ToString(), cmdParams);
 }
 /// <summary>
 /// 取得一条记录
 /// </summary>
 /// <param name="id"></param>
 /// <param name="where"></param>
 /// <returns></returns>
 public Member_CourseContentTestAnswerResult GetModel(int id, string where)
 {
     string sql = "select * from [dbo].[Member_CourseContentTestAnswerResult] where [Id]=@Id";
     if (!string.IsNullOrEmpty(where))
         sql += " and " + where;
     SqlParameter[] cmdParams = new SqlParameter[]{
         new SqlParameter("@Id", SqlDbType.Int, 4) { Value = id }
     };
     using (IDataReader reader = MSEntLibSqlHelper.ExecuteDataReaderBySql(sql, cmdParams))
     {
         if (reader.Read())
         {
             Member_CourseContentTestAnswerResult model = new Member_CourseContentTestAnswerResult();
             ConvertToModel(reader, model);
             return model;
         }
         else
         {
             return null;
         }
     }
 }