CourseworkDAL.cs 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using EMISOnline.DataLogic.Repositories;
  6. using System.Linq.Expressions;
  7. using EMISOnline.Entities;
  8. using System.Data;
  9. using EMISOnline.DataLogic.ExamSetting;
  10. using EMISOnline.ViewModel.Coursework;
  11. using EMISOnline.ViewModel.ExamView;
  12. using System.Xml.Linq;
  13. namespace EMISOnline.DataLogic.CourseworkMgr
  14. {
  15. public class CourseworkDAL : SqlHelper
  16. {
  17. public CourseworkRepository CourseworkRepository { get; set; }
  18. public CourseworkResultRepository ResultRepository { get; set; }
  19. public CourseworkAnswerRepository AnswerRepository { get; set; }
  20. public paper_question_setRepository question_setRepository { get; set; }
  21. public EducationMissionClassRepository EducationMissionClassRepository { get; set; }
  22. public EducationMissionRepository EducationMissionRepository { get; set; }
  23. public ExecutablePlanRepository ExecutablePlanRepository { get; set; }
  24. public CoursematerialRepository CoursematerialRepository { get; set; }
  25. public GrademajorRepository GrademajorRepository { get; set; }
  26. public SchoolyearRepository SchoolyearRepository { get; set; }
  27. public IQueryable<CourseworkAddView> GetCourseworkList(Expression<Func<Coursework, bool>> testExpression)
  28. {
  29. var query = from q in CourseworkRepository.Entities.Where(testExpression)
  30. join emc in EducationMissionClassRepository.Entities on q.EducationMissionClassID equals emc.EducationMissionClassID
  31. join em in EducationMissionRepository.Entities on emc.EducationMissionID equals em.EducationMissionID
  32. join cm in CoursematerialRepository.Entities on emc.CoursematerialID equals cm.CoursematerialID
  33. join sy in SchoolyearRepository.Entities on em.SchoolyearID equals sy.SchoolyearID
  34. select new CourseworkAddView()
  35. {
  36. test_paper_name = q.test_paper.PaperName,
  37. WorkName = q.WorkName,
  38. id = q.ID,
  39. test_begin_date = q.BeginTime,
  40. test_end_date = q.EndTime,
  41. CoursematerialName=cm.CourseName
  42. };
  43. return query.AsQueryable();
  44. }
  45. public IQueryable<CourseworkReviewView> GetReviewList(Expression<Func<CourseworkResult, bool>> testExpression)
  46. {
  47. var query = from r in ResultRepository.Entities.Where(testExpression)
  48. join c in CourseworkRepository.Entities on r.workid equals c.ID
  49. select new CourseworkReviewView()
  50. {
  51. ResultID = r.ID,
  52. user_id = r.user_id,
  53. username = r.username,
  54. test_end_date = r.test_end_date,
  55. score = r.score,
  56. state = r.state,
  57. WorkName = c.WorkName,
  58. PaperName = c.test_paper.PaperName
  59. };
  60. return query.AsQueryable();
  61. }
  62. /// <summary>
  63. /// 修改分配的试卷ID
  64. /// </summary>
  65. /// <param name="test_id"></param>
  66. /// <param name="userid"></param>
  67. /// <param name="paperID"></param>
  68. /// <returns></returns>
  69. public bool UpdatePaperID(decimal workid, string userid, decimal paperID)
  70. {
  71. //删除原试卷数据
  72. var paper = from p in PaperRepository.Entities
  73. join t in CourseworkRepository.Entities on p.test_paper_parent_id equals t.PaperID
  74. where t.ID == workid
  75. select p;
  76. if (paper != null && paper.Count() > 0)
  77. {
  78. var paperid = paper.ToArray()[0].test_paper_id;
  79. Expression<Func<test_paper_question_set, bool>> whereExpression = (q => q.test_paper_id == paperid);
  80. question_setRepository.UnitOfWork.Delete(whereExpression);
  81. //context.test_paper_question_set_fortest.Delete(q => q.test_paper_id == paperid);
  82. Expression<Func<test_paper, bool>> paperExpression = (q => q.test_paper_id == paperid);
  83. PaperRepository.UnitOfWork.Delete(paperExpression);
  84. question_setRepository.UnitOfWork.Commit();
  85. }
  86. var result = ResultRepository.Entities.Where(q => q.workid == workid && q.user_id == userid).FirstOrDefault();
  87. if (result != null)
  88. {
  89. result.test_paper_id = paperID;
  90. question_setRepository.UnitOfWork.Commit();
  91. return true;
  92. }
  93. return false;
  94. }
  95. public DataSet PaperBuilder(decimal workid, decimal paper_id)
  96. {
  97. var ds = Query("dbo.sp_coursework_paper",
  98. new KeyValuePair<string, object>("@workid", workid),
  99. new KeyValuePair<string, object>("@test_paper_id", paper_id));
  100. return (ds);
  101. }
  102. public List<AnswerXml> ExamineeAnswers(decimal workid)
  103. {
  104. var paperset = AnswerRepository.GetSingle(q => q.workid == workid);
  105. XElement xml = XElement.Parse(paperset.resultXml);
  106. var question_set = from c in xml.Descendants("AnswerXml")
  107. select new AnswerXml
  108. {
  109. test_question_Id = decimal.Parse(c.Element("test_question_Id").Value),
  110. answers = c.Element("answers").Value,
  111. src_score = decimal.Parse(c.Element("src_score").Value),
  112. act_score = decimal.Parse(c.Element("act_score").Value),
  113. };
  114. return question_set.ToList();
  115. }
  116. }
  117. }