123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using EMISOnline.DataLogic.ExamSetting;
- using System.Web.Script.Serialization;
- using System.Collections;
- using EMISOnline.ViewModel.ExamView;
- using Bowin.Web.Controls.Mvc;
- using System.Data;
- namespace EMISOnline.CommonLogic.ExamServices
- {
- public class QuestionServices : IQuestionServices
- {
- public QuestionDAL QuestionDAL { get; set; }
- public Entities.test_base_question_type[] ListAllQuestionType()
- {
- return QuestionDAL.ListAllQuestionType();
- }
- public decimal[] GeneratePractice(string[] libaryids, List<string> typeID, int? num)
- {
- return QuestionDAL.GeneratePractice(libaryids, typeID, num);
- }
- public string GetQuestion(decimal question_id)
- {
- var question = QuestionDAL.GetQuestion(new decimal[] { question_id });
- var js = new JavaScriptSerializer();
- return js.Serialize(question);
- }
- public string ShowPaperQuestion(decimal[] QeustionSet, Dictionary<string, string> Answers)
- {
- var questions = QuestionDAL.GetPaperQuestion(Answers.Keys.Select(q => decimal.Parse(q)).ToArray()).ToList();
- var questionTypes = QuestionDAL.ListAllQuestionType();
- var result = new ArrayList();
- questions.ForEach(q =>
- {
- q.userAnswer = Answers[q.question_id.ToString()];
- ReadQuestion(q, q.userAnswer, (int)q.question_typeid);
- });
- foreach (var type in questionTypes)
- {
- if (questions.Any(q => q.question_typeid == type.base_question_type_id))
- result.Add(new { id = type.base_question_type_id, name = type.Name, questions = questions });
- }
- var data = new
- {
- score = questions.Sum(q => q.score),//试题总分
- studentscore = questions.Sum(q => q.userscore), //你的得分
- questionnumber = QeustionSet.Count(),//试题总数
- rightnumber = questions.Count(q => q.userscore > 0),//答对题数
- errornumber = questions.Count(q => q.userscore == 0 && !string.IsNullOrEmpty(q.userAnswer)),//答错题数
- unquestion = QeustionSet.Count() - Answers.Count,//未答题数
- };
- var js = new JavaScriptSerializer();
- return js.Serialize(new { data = data, result = result });
- }
- private void ReadQuestion(PaperQuestionView question, string useranser, int questionType)
- {
- var isRight = false;
- switch (questionType)
- {
- case 1:
- isRight = question.rightAnswer == useranser.Trim();
- break;
- case 2:
- var provid = question.answers.Select(q => true).ToArray();
- isRight = string.Join("|", provid) == useranser.Trim();
- break;
- case 3:
- isRight = question.rightAnswer == OrderAnswer(useranser);
- break;
- case 4:
- isRight = question.rightAnswer == useranser.Trim();
- break;
- default:
- break;
- }
- if (isRight)
- question.userscore = question.score;
- }
- private string OrderAnswer(string answer)
- {
- var answerArr = answer.Split('|');
- return string.Join(",", answerArr.OrderBy(q => q).ToArray());
- }
- public List<TreeItem> ListQuesLibTreeStu()
- {
- List<TreeItem> rtn = new List<TreeItem>();
- var TreeDT = QuestionDAL.ListQuesLibTreeStu();
- var query = TreeDT.AsEnumerable().Where(e => e.Field<decimal>("parent_id") == 1);
- foreach (var node in query.ToList())
- {
- TreeItem item = new TreeItem();
- item.id = node.Field<decimal>("test_question_libary_id").ToString();
- item.text = node.Field<string>("name").ToString(); ;
- item.attributes = "";
- item.children = CreateChildTree(TreeDT, node.Field<decimal>("test_question_libary_id"));
-
- rtn.Add(item);
- }
- return rtn;
- }
- public List<TreeItem> CreateChildTree(DataTable TreeDT, decimal parent_id)
- {
- List<TreeItem> rtn = new List<TreeItem>();
- var query = TreeDT.AsEnumerable().Where(e => e.Field<decimal>("parent_id") == parent_id);
- foreach (var node in query.ToList())
- {
- TreeItem item = new TreeItem();
- item.id = node.Field<decimal>("test_question_libary_id").ToString();
- item.text = node.Field<string>("name").ToString(); ;
- item.attributes = "";
- item.children = CreateChildTree(TreeDT, node.Field<decimal>("test_question_libary_id"));
-
- rtn.Add(item);
- }
- return rtn;
- }
- }
- }
|