/// <summary>
 /// 获取数据集
 /// </summary>
 /// <param name="where"></param>
 /// <param name="orderBy"></param>
 /// <returns></returns>
 public List<Member_CourseContentTestAnswer> GetList(string where, string orderBy)
 {
     StringBuilder sql = new StringBuilder();
     sql.Append("select * from [dbo].[Member_CourseContentTestAnswer]");
     if (!string.IsNullOrEmpty(where))
         sql.Append(" where " + where);
     if (!string.IsNullOrEmpty(orderBy))
         sql.Append(" order by " + orderBy);
     List<Member_CourseContentTestAnswer> list = new List<Member_CourseContentTestAnswer>();
     using (IDataReader reader = MSEntLibSqlHelper.ExecuteDataReaderBySql(sql.ToString()))
     {
         while (reader.Read())
         {
             Member_CourseContentTestAnswer model = new Member_CourseContentTestAnswer();
             ConvertToModel(reader, model);
             list.Add(model);
         }
     }
     return list;
 }
 /// <summary>
 /// 新增一条记录
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public int Add(Member_CourseContentTestAnswer model)
 {
     StringBuilder sql = new StringBuilder();
     sql.Append("insert into [dbo].[Member_CourseContentTestAnswer] ([AnswerResult],[Question],[Answer],[Credit],[Result],[AccountId],[Delflag],[CreateDate])");
     sql.Append(" values (@AnswerResult,@Question,@Answer,@Credit,@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("@AnswerResult", SqlDbType.Int, 4) { Value = model.AnswerResult },
         new SqlParameter("@Question", SqlDbType.Int, 4) { Value = model.Question },
         new SqlParameter("@Answer", SqlDbType.VarChar, 100) { Value = model.Answer },
         new SqlParameter("@Credit", SqlDbType.Float, 8) { Value = model.Credit },
         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;
 }
Пример #3
0
        /// <summary>
        /// 提交答案到用户答案表
        /// </summary>
        /// <param name="listResultOther"></param>
        /// <param name="iId">总分表的Id</param>
        /// <returns></returns>
        private bool SaveMember_CourseContentTestAnswer(List<Member_CourseContentTestAnswerOther> listResultOther, int iId)
        {
            var unitTestBll = new Course_UnitTestBLL();
            var TestAnswerBll = new Member_CourseContentTestAnswerBLL();

            int iAccountId = 0;
            bool bolRes = false;

            iAccountId = Code.SiteCache.Instance.LoginInfo.UserId;

            foreach (var item in listResultOther)
            {
                var Model_Answer = new Member_CourseContentTestAnswer();

                //获取该题目的正确答案
                var Model_Test = unitTestBll.GetModel(item.Id, string.Empty);

                double dblGetCreTmp = 0;
                double.TryParse(item.Credits, out dblGetCreTmp);

                Model_Answer.AnswerResult = iId;
                Model_Answer.Question = item.Id;
                Model_Answer.Answer = item.Answer;
                Model_Answer.Result = Model_Test.QTtype == 4 ? true : Model_Test.Answer == item.Answer;//比对正确答案  若是问答题,直接设置为True
                Model_Answer.AccountId = iAccountId;
                Model_Answer.Delflag = false;
                Model_Answer.CreateDate = DateTime.Now;

                //将数据插入到学员答题内容表,用户的[结业考试]答案保存
                bolRes = TestAnswerBll.Add(Model_Answer);
            }

            return bolRes;
        }
Пример #4
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_CourseContentTestAnswer> 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_CourseContentTestAnswer]");
     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_CourseContentTestAnswer]");
     if (!string.IsNullOrEmpty(where))
         sql.Append(" where " + where);
     sql.Append(") as T where [RowNum] between " + start + " and " + end);
     List<Member_CourseContentTestAnswer> list = new List<Member_CourseContentTestAnswer>();
     using (IDataReader reader = MSEntLibSqlHelper.ExecuteDataReaderBySql(sql.ToString()))
     {
         while (reader.Read())
         {
             Member_CourseContentTestAnswer model = new Member_CourseContentTestAnswer();
             ConvertToModel(reader, model);
             list.Add(model);
         }
     }
     return list;
 }
 private void ConvertToModel(IDataReader reader, Member_CourseContentTestAnswer model)
 {
     if (reader["Id"] != DBNull.Value)
         model.Id = Convert.ToInt32(reader["Id"]);
     if (reader["AnswerResult"] != DBNull.Value)
         model.AnswerResult = Convert.ToInt32(reader["AnswerResult"]);
     if (reader["Question"] != DBNull.Value)
         model.Question = Convert.ToInt32(reader["Question"]);
     if (reader["Answer"] != DBNull.Value)
         model.Answer = reader["Answer"].ToString();
     if (reader["Credit"] != DBNull.Value)
         model.Credit = Convert.ToDouble(reader["Credit"]);
     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_CourseContentTestAnswer model)
 {
     StringBuilder sql = new StringBuilder();
     sql.Append("update [dbo].[Member_CourseContentTestAnswer] set ");
     sql.Append("[AnswerResult]=@AnswerResult,[Question]=@Question,[Answer]=@Answer,[Credit]=@Credit,[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("@AnswerResult", SqlDbType.Int, 4) { Value = model.AnswerResult },
         new SqlParameter("@Question", SqlDbType.Int, 4) { Value = model.Question },
         new SqlParameter("@Answer", SqlDbType.VarChar, 100) { Value = model.Answer },
         new SqlParameter("@Credit", SqlDbType.Float, 8) { Value = model.Credit },
         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_CourseContentTestAnswer GetModel(int id, string where)
 {
     string sql = "select * from [dbo].[Member_CourseContentTestAnswer] 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_CourseContentTestAnswer model = new Member_CourseContentTestAnswer();
             ConvertToModel(reader, model);
             return model;
         }
         else
         {
             return null;
         }
     }
 }
 /// <summary>
 /// 更新一条记录
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public bool Update(Member_CourseContentTestAnswer model)
 {
     return dal.Update(model) > 0;
 }
 /// <summary>
 /// 新增一条记录
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public bool Add(Member_CourseContentTestAnswer model)
 {
     return dal.Add(model) > 0;
 }