123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416 |
- 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 EMISOnline.DataLogic.Educational;
- namespace EMISOnline.CommonLogic.ExamServices
- {
- public class ExamSettingServices : IExamSettingServices
- {
- public ExamSettingDAL ExamSettingDAL { get; set; }
- public TestPaperDAL PaperDAL { get; set; }
- public UserDAL UserDAL { get; set; }
- public EducationMissionClassDAL EducationMissionClassDAL { get; set; }
- public IGridResultSet<OnlineTestView> GetOnlinetestList(string testname, int pageIndex, int pageSize)
- {
- Expression<Func<test_onlinetest, bool>> exp = (x => true);
- if (!string.IsNullOrEmpty(testname))
- exp = exp.And(q => q.test_name.Contains(testname));
- return ExamSettingDAL.GetOnlinetestList(exp).Select(q => new OnlineTestView()
- {
- test_name = q.test_name,
- onlinetest_id = q.onlinetest_id,
- test_method_set = q.test_method_set_id == 0 ? "在线考试" : "现场考试",
- test_begin_date = q.test_begin_date,
- limited_minutes = q.limited_minutes,
- status = q.status_id == (int)OnlineTestStatus.公开成绩 ? "成绩已发布" : "成绩未发布"
- }).OrderBy(q => q.onlinetest_id).ToGridResultSet(pageIndex, pageSize);
- }
- public IGridResultSet<OnlineTestView> GetStudentOnlinetestList(string testname, DateTime? beginTime, DateTime? endTime, string UserID, int pageIndex, int pageSize)
- {
- Expression<Func<test_onlinetest, bool>> exp = (x => true);
- if (!string.IsNullOrEmpty(testname))
- exp = exp.And(q => q.test_name.Contains(testname));
- if (beginTime.HasValue)
- exp = exp.And(q => q.test_begin_date >= beginTime);
- if (endTime.HasValue)
- exp = exp.And(q => q.test_end_date <= endTime);
- //根据UserID,查询用户对应的年级专业
- var Executable = EducationMissionClassDAL.GetEducationMissionClassByUserID(Guid.Parse(UserID)).Select(q => q.EducationMissionClassID).ToArray();
- exp = exp.And(q => Executable.Contains(q.EducationMissionClassID.Value));
- return ExamSettingDAL.GetStudentOnlinetestList(exp, UserID).Select(q => new OnlineTestView()
- {
- test_name = q.test_name,
- onlinetest_id = q.onlinetest_id,
- test_method_set = q.test_method_set_id == 0 ? "在线考试" : "现场考试",
- test_begin_date = q.test_begin_date,
- limited_minutes = q.limited_minutes,
- status = q.status_id == (int)OnlineTestStatus.公开成绩 ? "成绩已发布" : "成绩未发布"
- }).OrderBy(q => q.onlinetest_id).ToGridResultSet(pageIndex, pageSize);
- }
- public OnlineTestView GetOnlineTestByID(decimal test_id)
- {
- OnlineTestView test = new OnlineTestView();
- var view = ExamSettingDAL.OnlinetestRepository.GetSingle(q => q.onlinetest_id == test_id);
- test.onlinetest_id = view.onlinetest_id;
- test.breaking_id = view.breaking_id;
- test.breaking_id = view.breaking_id;
- test.display_type = view.display_type;
- test.ExamerState = view.ExamerState;
- test.ExamID = view.ExamID;
- test.ISautoBegin = view.ISautoBegin;
- test.isControllable = view.isControllable;
- test.isOpenAnswer = view.isOpenAnswer;
- test.isPublishScore = view.isPublishScore;
- test.isReadPaper = view.isReadPaper;
- test.limited_minutes = view.limited_minutes;
- test.ModityContent = view.ModityContent;
- test.notice_datetime = view.notice_datetime;
- test.notice_method_id = view.notice_method_id;
- test.PassRate = view.PassRate;
- test.rand_test_count = view.rand_test_count;
- test.rand_test_point_setid = view.rand_test_point_setid;
- test.rand_test_point_type = view.rand_test_point_type;
- test.rand_Test_time = view.rand_Test_time;
- test.relogin_count = view.relogin_count;
- test.status_id = view.status_id;
- test.SubCode = view.SubCode;
- test.subjectiveQAutoRead = view.subjectiveQAutoRead;
- test.test_address = view.test_address;
- test.test_begin_date = view.test_begin_date;
- test.test_code = view.test_code;
- test.test_end_date = view.test_end_date;
- test.test_method_set_id = view.test_method_set_id;
- test.test_name = view.test_name;
- test.test_paper_id = view.test_paper_id;
- test.time_of_filling = view.time_of_filling;
- test.version = view.version;
- if (view.EducationMissionClassID.HasValue)
- {
- var executable = EducationMissionClassDAL.EducationMissionClassRepository.GetSingle(x => view.EducationMissionClassID == x.EducationMissionClassID);
- test.EducationMissionClassID = view.EducationMissionClassID.Value;
- test.ExecutablePlanData.Add(test.EducationMissionClassID.ToString(), executable.Name);
- }
- return test;
- }
- public bool ExamSettingSave(OnlineTestView view, string LoginID)
- {
- test_onlinetest test = new test_onlinetest();
- if (view.onlinetest_id > 0)
- {
- test = ExamSettingDAL.OnlinetestRepository.GetSingle(q => q.onlinetest_id == view.onlinetest_id);
- test.breaking_id = view.breaking_id;
- test.breaking_id = view.breaking_id;
- test.display_type = view.display_type;
- test.ExamerState = view.ExamerState;
- test.ExamID = view.ExamID;
- test.ISautoBegin = view.ISautoBegin;
- test.isControllable = view.isControllable;
- test.isOpenAnswer = view.isOpenAnswer;
- test.isPublishScore = view.isPublishScore;
- test.isReadPaper = view.isReadPaper;
- test.limited_minutes = view.limited_minutes;
- test.ModityContent = view.ModityContent;
- test.notice_datetime = view.notice_datetime;
- test.notice_method_id = view.notice_method_id;
- test.PassRate = view.PassRate;
- test.rand_test_count = view.rand_test_count;
- test.rand_test_point_setid = view.rand_test_point_setid;
- test.rand_test_point_type = view.rand_test_point_type;
- test.rand_Test_time = view.rand_Test_time;
- test.relogin_count = view.relogin_count;
- test.status_id = view.status_id;
- test.SubCode = view.SubCode;
- test.subjectiveQAutoRead = view.subjectiveQAutoRead;
- test.test_address = view.test_address;
- test.test_begin_date = view.test_begin_date;
- test.test_code = view.test_code;
- test.test_end_date = view.test_end_date;
- test.test_method_set_id = view.test_method_set_id;
- test.test_name = view.test_name;
- test.test_paper_id = view.test_paper_id;
- test.time_of_filling = view.time_of_filling;
- test.version = view.version;
- test.EducationMissionClassID = view.EducationMissionClassID;
- }
- else
- {
- test.breaking_id = view.breaking_id;
- test.created_by = LoginID;
- test.created_date = DateTime.Now;
- test.display_type = view.display_type;
- test.ExamerState = view.ExamerState;
- test.ExamID = Guid.NewGuid();
- test.ISautoBegin = view.ISautoBegin;
- test.isControllable = view.isControllable;
- test.isOpenAnswer = view.isOpenAnswer;
- test.isPublishScore = view.isPublishScore;
- test.isReadPaper = view.isReadPaper;
- test.limited_minutes = view.limited_minutes;
- test.ModityContent = view.ModityContent;
- test.notice_datetime = view.notice_datetime;
- test.notice_method_id = view.notice_method_id;
- test.PassRate = view.PassRate;
- test.rand_test_count = view.rand_test_count;
- test.rand_test_point_setid = view.rand_test_point_setid;
- test.rand_test_point_type = view.rand_test_point_type;
- test.rand_Test_time = view.rand_Test_time;
- test.relogin_count = view.relogin_count;
- test.status_id = view.status_id;
- test.SubCode = view.SubCode;
- test.subjectiveQAutoRead = view.subjectiveQAutoRead;
- test.test_address = view.test_address;
- test.test_begin_date = view.test_begin_date;
- test.test_code = view.test_code;
- test.test_end_date = view.test_end_date;
- test.test_method_set_id = view.test_method_set_id;
- test.test_name = view.test_name;
- test.test_paper_id = view.test_paper_id;
- test.time_of_filling = view.time_of_filling;
- test.version = view.version;
- test.EducationMissionClassID = view.EducationMissionClassID;
- ExamSettingDAL.OnlinetestRepository.UnitOfWork.Add(test);
- }
- ExamSettingDAL.OnlinetestRepository.UnitOfWork.Commit();
- //WinUpdateExam(test);
- return true;
- }
- public object GetPaperList(string papername, int pageIndex, int pageSize)
- {
- Expression<Func<test_paper, bool>> exp = (x => true);
- if (!string.IsNullOrEmpty(papername))
- exp = exp.And(q => q.PaperName.Contains(papername));
- return ExamSettingDAL.GetPaperList(exp).ToList().Select(paper => new
- {
- paper.PaperName,
- paper.paper_score,
- Creator = paper.created_by,
- is_dynamic = paper.is_dynamic ? "是" : "否",
- created_date = paper.created_date.Value.ToString("yyyy-MM-dd"),
- paper.test_paper_id
- }).OrderBy(q => q.test_paper_id).AsQueryable().ToGridResultSet(pageIndex, pageSize);
- }
- /// <summary>
- /// 生成考生信息及试卷信息
- /// </summary>
- /// <param name="setting"></param>
- /// <returns></returns>
- public bool WinUpdateExam(test_onlinetest setting)
- {
- bool bool_rev = false;
- decimal testid = setting.onlinetest_id;
- bool isChangePaper = setting.ExamerState.HasValue ? (setting.ExamerState.Equals(2) ? true : false) : false;//是否修改试卷
- InsertExamResult(testid);
- if (isChangePaper)//如果有更换考卷
- {
- //删除考试结果
- ExamSettingDAL.ExamineeAnswerRepository.UnitOfWork.Delete<ExamineeAnswer>(q => q.onlinetest_id == testid);
- }
- setting.ExamerState = 1;
- ExamSettingDAL.OnlinetestRepository.UnitOfWork.Commit();
- bool_rev = true;
- return bool_rev;
- }
- public void InsertExamResult(decimal testid)
- {
- var TestMans = ExamSettingDAL.GetExamUsers(testid);
- var TestOnlie = ExamSettingDAL.OnlinetestRepository.GetSingle(q => q.onlinetest_id == testid);
- List<ExamResult> Mans = new List<ExamResult>();
- foreach (var Man in TestMans)
- {
- ExamResult result = new ExamResult()
- {
- user_id = Man.UserID.ToString(),
- test_name = TestOnlie.test_name,
- test_paper_id = TestOnlie.test_paper_id.Value,
- test_begin_date = TestOnlie.test_begin_date,
- test_end_date = TestOnlie.test_end_date,
- limited_minutes = TestOnlie.limited_minutes,
- test_address = TestOnlie.test_address,
- onlinetest_id = TestOnlie.onlinetest_id,
- OrgId = Man.ClassmajorID.ToString(),
- username = Man.StudentCardNo
- };
- Mans.Add(result);
- }
- ExamSettingDAL.ExamResultRepository.UnitOfWork.AddRange(Mans);
- }
- public ExamResult GetExam(string userid, decimal test_id)
- {
- var exam = ExamSettingDAL.GetExam(userid, test_id);
- //首次进入考试,如果该考生拥有该场考试,则把该考生信息插入到考生信息表
- if (exam == null)
- {
- Expression<Func<test_onlinetest, bool>> exp = (x => x.onlinetest_id == test_id);
- //根据UserID,查询用户对应的年级专业
- var Executable = EducationMissionClassDAL.GetEducationMissionClassByUserID(Guid.Parse(userid)).Select(q => q.EducationMissionClassID).ToArray();
- exp = exp.And(q => Executable.Contains(q.EducationMissionClassID.Value));
- var test = ExamSettingDAL.GetStudentOnlinetestList(exp, userid).FirstOrDefault();
- if (test != null)
- {
- exam = new ExamResult()
- {
- is_auto_read = test.isReadPaper,
- test_name = test.test_name,
- test_paper_id = test.test_paper_id,
- test_begin_date = test.test_begin_date,
- limited_minutes = test.limited_minutes,
- test_end_date = test.test_end_date,
- onlinetest_id = test.onlinetest_id,
- user_id = userid,
- filled = false,
- };
- ExamSettingDAL.ExamResultRepository.UnitOfWork.Add(exam);
- ExamSettingDAL.ExamResultRepository.UnitOfWork.Commit();
- exam = ExamSettingDAL.GetExam(userid, test_id);
- }
- }
- return exam;
- }
- public Examinee_ExamStatus GetExamStartLength(decimal test_id, string userid, out double limit)
- {
- limit = 0;
- var testman = ExamSettingDAL.GetExam(userid, test_id);
- var now = DateTime.Now;
- if (testman == null)
- return Examinee_ExamStatus.不能参加该场考试;
- if (testman.test_onlinetest.status_id == 0)
- return Examinee_ExamStatus.考试未开始;
- if (testman.test_onlinetest.test_method_set_id.Value == 1)
- {
- // 现场考试
- if (now > testman.test_begin_date.Value.AddMinutes(testman.limited_minutes.Value))
- return Examinee_ExamStatus.考试已结束;
- if (testman.state >= 2)
- return Examinee_ExamStatus.已交卷;
- }
- else
- {
- if (testman.test_end_date.HasValue && testman.test_end_date < now && !testman.lastLoginTime.HasValue)
- return Examinee_ExamStatus.考试已结束;
- // 在线考试不受考试时间限制
- if (testman.test_end_date.HasValue && testman.test_begin_date.HasValue && now > testman.test_end_date.Value.AddMinutes(testman.limited_minutes.Value))
- return Examinee_ExamStatus.考试已结束;
- }
- //if (testman.reloginCount >= testman.test_onlinetest.relogin_count)
- // return Examinee_ExamStatus.登录次数已大于规定的次数;
- limit = (testman.test_begin_date.Value - DateTime.Now).TotalSeconds;
- return Examinee_ExamStatus.考试中;
- }
- /// <summary>
- /// 获取考试对应的试卷
- /// </summary>
- /// <param name="testid"></param>
- /// <returns></returns>
- public test_paper getPaper(decimal testid)
- {
- var q = ExamSettingDAL.OnlinetestRepository.UnitOfWork.Set<test_onlinetest>().Include("test_paper").Single(qx => qx.onlinetest_id == testid).test_paper;
- return q;
- }
- public bool TakePaper(decimal test_id, string userid, string answer)
- {
- ExamSettingDAL.ExamineeAnswerRepository.UnitOfWork.Delete<ExamineeAnswer>(e => e.onlinetest_id == test_id && e.user_id == userid);
- string errText = string.Empty;
- if (!string.IsNullOrEmpty(answer))
- {
- var json = new JavaScriptSerializer();
- var answers = json.Deserialize<answerEntry[]>(answer);
- List<AnswerXml> xmlValues = new List<AnswerXml>();
- foreach (var a in answers)
- {
- decimal question_id = 0;
- if (decimal.TryParse(a.key, out question_id))
- {
- xmlValues.Add(new AnswerXml()
- {
- act_score = 0,
- answers = a.value,
- memo = "",
- src_score = 0,
- test_question_Id = question_id
- });
- }
- }
- try
- {
- errText += "0-----\r\n";
- XmlSerializer serializer = new XmlSerializer(typeof(List<AnswerXml>));
- MemoryStream mstream = new MemoryStream();
- serializer.Serialize(mstream, xmlValues);
- mstream.Close();
- errText += "1-----\r\n";
- errText += Encoding.Default.GetString(mstream.ToArray());
- var examAnswer = new ExamineeAnswer()
- {
- ID = Guid.NewGuid(),
- onlinetest_id = test_id,
- user_id = userid,
- resultXml = XElement.Parse(Encoding.UTF8.GetString(mstream.ToArray())).ToString()
- };
- errText += "2-----\r\n";
- errText = examAnswer.resultXml.ToString();
- ExamSettingDAL.ExamineeAnswerRepository.UnitOfWork.Add(examAnswer);
- }
- catch (Exception ex)
- {
- //System.IO.StreamWriter sw = new System.IO.StreamWriter(Server.Current.Request.PhysicalApplicationPath + "\\lingx.txt", true, System.Text.Encoding.UTF8);
- //sw.WriteLine(DateTime.Now.ToString());
- //sw.WriteLine(errText); ;
- //sw.Close();
- }
- }
- var test_man = PaperDAL.ExamResultRepository.GetSingle(m => m.user_id == userid && m.onlinetest_id == test_id);
- if (test_man != null)
- {
- test_man.state = 2;
- test_man.test_end_date = DateTime.Now;
- }
- PaperDAL.ExamResultRepository.UnitOfWork.Commit();
- return true;
- }
- }
- public class answerEntry
- {
- public string key { get; set; }
- public string value { get; set; }
- }
- }
|