using System; using System.Collections.Generic; using System.Linq; using System.Text; using EMISOnline.Entities; using EMISOnline.DataLogic.Repositories; using System.Linq.Expressions; using System.Data; using EMISOnline.ViewModel.ExamView; using Bowin.Common.Linq; namespace EMISOnline.DataLogic.ExamSetting { public class QuestionDAL : SqlHelper { public base_question_typeRepository typeRepository { get; set; } public questionRepository questionRepository { get; set; } public question_provid_answerRepository answerRepository { get; set; } public question_libaryRepository libaryRepository { get; set; } public test_base_question_type[] ListAllQuestionType() { return typeRepository.Entities.OrderBy(q => q.diplay_order).ToArray(); } public decimal[] GeneratePractice(string[] libaryids, List typeID, int? num) { var ds = Query("dbo.[SP_GeneratePractice]", new KeyValuePair("@libryid", string.Join(",", libaryids)), new KeyValuePair("@questionType", typeID.Count > 0 ? string.Join(",", typeID.ToArray()) : ""), new KeyValuePair("@questionLength", num)); return ds.Tables[0].AsEnumerable().Select(d => d.Field("test_question_Id")).ToArray(); } public object GetQuestion(decimal[] question_ids) { var query = from q in questionRepository.Entities //let answer = answerRepository. where question_ids.Contains(q.test_question_Id) where !q.filled select new { typeName = q.test_base_question_type.Name, q.content, q.test_question_Id, q.base_question_type_id, hasImg = q.question_file_id.HasValue, url = q.question_file_id.HasValue ? q.test_question_file.url : "", q.score, rightAnswer = q.answers, Answers = q.test_question_provid_answer.Select(a => new { a.answer_name, a.provid_answer_id, hasImg = a.file_id.HasValue, url = a.file_id.HasValue ? a.test_question_file.url : "", }) }; return query.SingleOrDefault(); } public IQueryable GetPaperQuestion(decimal[] question_ids) { var query = from q in questionRepository.Entities //let answer = answerRepository. where question_ids.Contains(q.test_question_Id) where !q.filled select new PaperQuestionView { content = q.content, question_id = q.test_question_Id, question_typeid=q.base_question_type_id.Value, hasImg = q.question_file_id.HasValue, url = q.question_file_id.HasValue ? q.test_question_file.url : "", score = q.score.HasValue ? q.score.Value : 0, rightAnswer = q.answers, answers = q.test_question_provid_answer.Select(a => new Answers { content = a.answer_name, answer_id=a.provid_answer_id, hasImg = a.file_id.HasValue, url = a.file_id.HasValue ? a.test_question_file.url : "", }) }; return query.AsQueryable(); } /// /// 获取所有的题库目录树数据 /// /// public System.Data.DataTable ListQuesLibTreeStu() { var query = from lib in libaryRepository.Entities where lib.filled == false select new { lib.test_question_libary_id, lib.name, lib.parent_id }; return query.ToTable(); } } }