123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using EMISOnline.DataLogic.ExamSetting;
- using Bowin.Common.Linq.Entity;
- using EMISOnline.ViewModel.ExamView;
- using System.Linq.Expressions;
- using EMISOnline.Entities;
- using System.Linq.Expressions;
- using Bowin.Common.Linq;
- using EMISOnline.ViewModel;
- using Bowin.Common;
- using System.Web.Script.Serialization;
- using System.Xml.Serialization;
- using System.IO;
- using System.Xml.Linq;
- using EMISOnline.DataLogic.SystemDAL;
- using System.Runtime.Remoting.Contexts;
- using System.Data;
- using System.Text.RegularExpressions;
- namespace EMISOnline.CommonLogic.ExamServices
- {
- public class QuestionSettingServices : IQuestionSettingServices
- {
- public QuestionSettingDAL SettingDAL { get; set; }
- public object GetQuestionList(string Content, decimal? QuestionType, decimal? libaryid, int maximumRows, int startRowIndex)
- {
- Expression<Func<test_question, bool>> exp = (x => true);
- if (!string.IsNullOrEmpty(Content))
- exp = exp.And(q => q.content.Contains(Content));
- if (QuestionType.HasValue)
- exp = exp.And(q => q.base_question_type_id == QuestionType);
- if (libaryid.HasValue)
- {
- var libarys = getSubListid(libaryid.Value);
- exp = exp.And(q => libarys.Contains(q.test_question_libary_id.Value ));
- }
- var question = SettingDAL.GetQuestionList(exp);
- return question.OrderBy(q => q.test_question_Id).ToGridResultSet(maximumRows, startRowIndex + 1);
- }
- public List<decimal> getSubListid(decimal libaryid)
- {
- IList<test_question_libary> list = new List<test_question_libary>();
- SettingDAL.GetSubLibary(null, libaryid, list);
- List<decimal> libaryids = list.Select(q => q.test_question_libary_id).ToList();
- libaryids.Add(libaryid);
- return libaryids;
- }
- public QuestionSettingView GetQuestion(decimal test_question_Id)
- {
- var entry = SettingDAL.questionRepository.GetSingle(q => q.test_question_Id == test_question_Id);
- test_question_libary libary = GetQuestionLibary(entry.test_question_libary_id.Value);
- var question_type = SettingDAL.typeRepository.GetSingle(q => q.base_question_type_id == entry.base_question_type_id);
- var question_provid_answer = SettingDAL.answerRepository.Entities.Where(q => q.test_question_Id == test_question_Id).ToList();
- var question = new QuestionSettingView()
- {
- test_question_Id = entry.test_question_Id,
- base_question_type_id = entry.base_question_type_id,
- content = entry.content,
- question_file_id = entry.question_file_id,
- note = entry.note,
- test_question_libary_id = entry.test_question_libary_id,
- score = entry.score,
- difficulty_degree = entry.difficulty_degree,
- is_vaild = entry.is_vaild,
- TypeName = question_type.Name,
- question_provid_answer =
- question_provid_answer.Select(a => new test_question_provid_answer()
- {
- answer_name = a.answer_name,
- provid_answer_id = a.provid_answer_id,
- file_id = a.file_id
- }).ToList(),
- answers = entry.answers,
- libaryName = libary.name
- };
- return question;
- }
- public test_question_libary GetQuestionLibary(decimal libary_Id)
- {
- var question = SettingDAL.libaryRepository.GetSingle(q => q.test_question_libary_id == libary_Id);
- return question;
- }
- public object GetQuestionType(bool? isEmpty)
- {
- var question = SettingDAL.typeRepository.GetList(q => true);
- var result = question.Select(q => new { q.Name, base_question_type_id = q.base_question_type_id.ToString() }).ToList();
- if (isEmpty == true)
- result.Insert(0, new { Name = "全选", base_question_type_id = "" });
- return result;
- }
- public object GetDifficulty()
- {
- var question = SettingDAL.paramRepository.GetList(q => q.base_param_parent_id == 3);
- return question.Select(q => new { q.name }).ToList();
- }
- private static Regex regAnser = new Regex(@"^[A-Z][、]");
- /// <summary>
- /// 保存试题、保存试题答案
- /// </summary>
- public void InsertByTrans(test_question tq, List<test_question_provid_answer> tqpaList, List<string> rightAnswersList, string userid)
- {
- //ToDo:保存到数据库
- tq.question_file_id = tq.question_file_id == 0 ? null : tq.question_file_id;
- tq.created_date = DateTime.Now;
- tq.created_by = "0";
- tq.used_count = 1;
- tq.wrong_count = 0;
- string rightAnswers = "";
- foreach (test_question_provid_answer tqpa in tqpaList)
- {
- tqpa.created_by = userid;
- tqpa.created_date = DateTime.Now;
- tqpa.test_question_Id = tq.test_question_Id;
- tq.test_question_provid_answer.Add(tqpa);
- }
- SettingDAL.questionRepository.UnitOfWork.Add(tq);
- SettingDAL.questionRepository.UnitOfWork.Commit();
- foreach (test_question_provid_answer tqpa in tq.test_question_provid_answer)
- {
- foreach (string s in rightAnswersList)
- {
- if (regAnser.Replace(tqpa.answer_name, "") == regAnser.Replace(s, ""))
- {
- rightAnswers += tqpa.provid_answer_id + ",";
- break;
- }
- }
- }
- if (rightAnswers.EndsWith(","))
- rightAnswers = rightAnswers.TrimEnd(',');
- tq.answers = rightAnswers;
- SettingDAL.questionRepository.UnitOfWork.Update(tq);
- SettingDAL.questionRepository.UnitOfWork.Commit();
- }
- /// <summary>
- /// 更新试题、更新试题答案
- /// </summary>
- public void UpdateByTrans(test_question setting, List<test_question_provid_answer> tqpaList, List<string> rightAnswersList, string userid)
- {
- var question = SettingDAL.questionRepository.GetSingle(q => q.test_question_Id == setting.test_question_Id);
- Entry(setting, question);
- string rightAnswers = "";
- var provid_answer_ids = tqpaList.Select(q => q.provid_answer_id).ToArray();
- SettingDAL.answerRepository.UnitOfWork.Delete<test_question_provid_answer>(q => !provid_answer_ids.Contains(q.provid_answer_id) && q.test_question_Id == question.test_question_Id);
- foreach (test_question_provid_answer tqpa in tqpaList)
- {
- foreach (string s in rightAnswersList)
- {
- if (tqpa.answer_name == s)
- {
- rightAnswers += tqpa.provid_answer_id + ",";
- break;
- }
- }
- tqpa.created_by = userid;
- tqpa.created_date = DateTime.Now;
- tqpa.test_question_Id = question.test_question_Id;
- question.test_question_provid_answer.Add(tqpa);
- if (tqpa.provid_answer_id > 0)
- SettingDAL.answerRepository.UnitOfWork.Update(tqpa);
- else
- SettingDAL.answerRepository.UnitOfWork.Add(tqpa);
- }
- rightAnswers = rightAnswers.TrimEnd(',');
- question.answers = rightAnswers;
- SettingDAL.questionRepository.UnitOfWork.Commit();
- }
- public void Entry(test_question entry, test_question question)
- {
- question.base_question_type_id = entry.base_question_type_id;
- question.content = entry.content;
- question.question_file_id = entry.question_file_id == 0 ? null : entry.question_file_id;
- question.note = entry.note;
- question.test_question_libary_id = entry.test_question_libary_id;
- question.score = entry.score;
- question.difficulty_degree = entry.difficulty_degree;
- question.is_vaild = entry.is_vaild;
- question.answers = entry.answers; ;
- }
- }
- }
|