StudentScoreServices.cs 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Data.Entity;
  5. using System.Text;
  6. using System.Linq.Expressions;
  7. using EMIS.Entities;
  8. using EMIS.DataLogic.ScoreManage;
  9. using EMIS.ViewModel;
  10. using Bowin.Common.Linq.Entity;
  11. using Bowin.Common.Linq;
  12. using EMIS.ViewModel.ScoreManage;
  13. using EMIS.ViewModel.Students;
  14. using System.Dynamic;
  15. using EMIS.Utility;
  16. using EMIS.DataLogic.Repositories;
  17. using EMIS.ViewModel.Cultureplan;
  18. using System.Transactions;
  19. namespace EMIS.CommonLogic.ScoreManage
  20. {
  21. public class StudentScoreServices : BaseServices, IStudentScoreServices
  22. {
  23. public StudentScoreDAL studentScoreDAL { get; set; }
  24. public ResultTypeDetailDAL resultTypeDetailDAL { get; set; }
  25. public FinallyScoreRepository FinallyScoreRepository { get; set; }
  26. public SubmitedScoreRepository SubmitedScoreRepository { get; set; }
  27. public ScoreParameterSettingDAL scoreParameterSettingDAL { get; set; }
  28. public GradePointFormulaRepository gradePointFormulaRepository { get; set; }
  29. public Lazy<IScoreParameterSettingServices> ScoreParameterSettingServices { get; set; }
  30. public ResultTypeDetailRepository resultTypeDetailRepository { get; set; }
  31. public ExamsStateSettingRepository examsStateSettingRepository { get; set; }
  32. /// <summary>
  33. /// 查询已提交成绩
  34. /// </summary>
  35. /// <param name="configuretView"></param>
  36. /// <param name="collegeID"></param>
  37. /// <param name="departmentID"></param>
  38. /// <param name="schoolyearID"></param>
  39. /// <param name="coursematerialID"></param>
  40. /// <param name="courseTypeID"></param>
  41. /// <param name="examsCategoryID"></param>
  42. /// <param name="examinationType"></param>
  43. /// <param name="pageIndex"></param>
  44. /// <param name="pageSize"></param>
  45. /// <returns></returns>
  46. public IGridResultSet<StudentScoreView> GetStudentScoreViewGrid(ConfiguretView configuretView, Guid? collegeID, Guid? departmentID, Guid? schoolyearID, Guid? coursematerialID, int? courseTypeID, int? examsCategoryID,
  47. int? standardID, Guid? classmajorID, int? starttermBegin, int? starttermEnd, int? yearID, int? learningformID, int? handleModeID, int? education, string LearnSystem, int pageIndex, int pageSize)
  48. {
  49. Expression<Func<ER_SubmitedScore, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  50. if (collegeID.HasValue)
  51. exp = exp.And(x => x.CF_Student.CF_Classmajor.CF_Grademajor.CF_Facultymajor.CollegeID == collegeID);
  52. if (departmentID.HasValue)
  53. exp = exp.And(x => x.DepartmentID == departmentID);
  54. if (yearID.HasValue)
  55. exp = exp.And(x => x.CF_Student.CF_Classmajor.CF_Grademajor.GradeID == yearID);
  56. if (standardID.HasValue)
  57. exp = exp.And(x => x.CF_Student.CF_Classmajor.CF_Grademajor.CF_Facultymajor.StandardID == standardID);
  58. if (classmajorID.HasValue)
  59. exp = exp.And(x => x.CF_Student.ClassmajorID == classmajorID);
  60. if (schoolyearID.HasValue)
  61. exp = exp.And(x => x.SchoolyearID == schoolyearID);
  62. if (coursematerialID.HasValue)
  63. exp = exp.And(x => x.CoursematerialID == coursematerialID);
  64. if (courseTypeID.HasValue)
  65. exp = exp.And(x => x.CourseTypeID == courseTypeID);
  66. if (examsCategoryID.HasValue)
  67. exp = exp.And(x => x.ExamsCategoryID == examsCategoryID);
  68. if (learningformID.HasValue)
  69. exp = exp.And(x => x.CF_Student.CF_Classmajor.CF_Grademajor.CF_Facultymajor.LearningformID == learningformID);
  70. if (handleModeID.HasValue)
  71. exp = exp.And(x => x.HandleModeID == handleModeID);
  72. if (!string.IsNullOrEmpty(LearnSystem) && LearnSystem != "-1")
  73. {
  74. var LearnSystems = Convert.ToDecimal(LearnSystem);
  75. exp = exp.And(x => x.CF_Student.CF_Classmajor.CF_Grademajor.CF_Facultymajor.LearnSystem == LearnSystems);
  76. }
  77. if (education.HasValue)
  78. {
  79. exp = exp.And(x =>x.CF_Student.CF_Classmajor.CF_Grademajor.CF_Facultymajor.EducationID == education.Value);
  80. }
  81. if (starttermBegin.HasValue && starttermEnd.HasValue)
  82. {
  83. exp = exp.And(x => x.StarttermID >= starttermBegin && x.StarttermID <= starttermEnd);
  84. }
  85. var query = studentScoreDAL.GetStudentScoreViewQueryable(exp);
  86. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  87. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
  88. return this.GetQueryByAssistant(query, (x => x.ClassmajorID),this.GetQueryByDataRangeByCollege(query)).OrderByDescending(x => x.SchoolyearCode).ThenBy(x => x.CourseName)
  89. .ThenBy(x => x.ExamsCategoryID).ThenBy(x => x.ClassName).ThenBy(x => x.LoginID).ToGridResultSet<StudentScoreView>(pageIndex, pageSize);
  90. }
  91. /// <summary>
  92. /// 查询已提交成绩
  93. /// </summary>
  94. /// <param name="configuretView"></param>
  95. /// <param name="collegeID"></param>
  96. /// <param name="departmentID"></param>
  97. /// <param name="schoolyearID"></param>
  98. /// <param name="coursematerialID"></param>
  99. /// <param name="courseTypeID"></param>
  100. /// <param name="examsCategoryID"></param>
  101. /// <param name="examinationType"></param>
  102. /// <param name="pageIndex"></param>
  103. /// <param name="pageSize"></param>
  104. /// <returns></returns>
  105. public List<ViewModel.ScoreManage.StudentScoreView> GetStudentScoreViewList(ViewModel.ConfiguretView configuretView, Guid? collegeID, Guid? departmentID, Guid? schoolyearID, Guid? coursematerialID, int? courseTypeID, int? examsCategoryID
  106. , Guid? grademajorID, Guid? classmajorID, int? yearID, int? learningformID, int? education, string LearnSystem, List<Guid?> submitedScoreIDList)
  107. {
  108. Expression<Func<ER_SubmitedScore, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  109. if (submitedScoreIDList != null)
  110. {
  111. exp = exp.And(x => submitedScoreIDList.Contains(x.SubmitedScoreID));
  112. }
  113. if (collegeID.HasValue)
  114. exp = exp.And(x => x.CF_Student.CF_Classmajor.CF_Grademajor.CF_Facultymajor.CollegeID == collegeID);
  115. if (departmentID.HasValue)
  116. exp = exp.And(x => x.DepartmentID == departmentID);
  117. if (yearID.HasValue)
  118. exp = exp.And(x => x.CF_Student.CF_Classmajor.CF_Grademajor.GradeID == yearID);
  119. if (grademajorID.HasValue)
  120. exp = exp.And(x => x.CF_Student.CF_Classmajor.GrademajorID == grademajorID);
  121. if (classmajorID.HasValue)
  122. exp = exp.And(x => x.CF_Student.ClassmajorID == classmajorID);
  123. if (schoolyearID.HasValue)
  124. exp = exp.And(x => x.SchoolyearID == schoolyearID);
  125. if (coursematerialID.HasValue)
  126. exp = exp.And(x => x.CoursematerialID == coursematerialID);
  127. if (courseTypeID.HasValue)
  128. exp = exp.And(x => x.CourseTypeID == courseTypeID);
  129. if (examsCategoryID.HasValue)
  130. exp = exp.And(x => x.ExamsCategoryID == examsCategoryID);
  131. if (learningformID.HasValue)
  132. exp = exp.And(x => x.CF_Student.CF_Classmajor.CF_Grademajor.CF_Facultymajor.LearningformID == learningformID);
  133. if (!string.IsNullOrEmpty(LearnSystem) && LearnSystem != "-1")
  134. {
  135. var LearnSystems = Convert.ToDecimal(LearnSystem);
  136. exp = exp.And(x => x.CF_Student.CF_Classmajor.CF_Grademajor.CF_Facultymajor.LearnSystem == LearnSystems);
  137. }
  138. if (education.HasValue)
  139. {
  140. exp = exp.And(x => x.CF_Student.CF_Classmajor.CF_Grademajor.CF_Facultymajor.EducationID == education.Value);
  141. }
  142. var query = studentScoreDAL.GetStudentScoreViewQueryable(exp);
  143. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  144. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
  145. return this.GetQueryByDataRangeByCollege(query).OrderByDescending(x => x.SchoolyearCode).ThenBy(x => x.CourseName)
  146. .ThenBy(x => x.ExamsCategoryID).ThenBy(x => x.ClassName).ThenBy(x => x.LoginID).ToList();
  147. }
  148. /// <summary>
  149. /// 查询已提交成绩信息
  150. /// </summary>
  151. /// <param name="submitedScoreID"></param>
  152. /// <returns></returns>
  153. public ViewModel.ScoreManage.StudentScoreView GetStudentScoreView(Guid? submitedScoreID)
  154. {
  155. Expression<Func<ER_SubmitedScore, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE && x.SubmitedScoreID == submitedScoreID);
  156. var query = studentScoreDAL.GetStudentScoreViewQueryable(exp);
  157. return query.FirstOrDefault();
  158. }
  159. /// <summary>
  160. /// 查询已提交成绩信息
  161. /// </summary>
  162. /// <param name="submitedScoreID"></param>
  163. /// <returns></returns>
  164. public Entities.ER_SubmitedScore GetSubmitedScore(Guid? submitedScoreID)
  165. {
  166. Expression<Func<ER_SubmitedScore, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE && x.SubmitedScoreID == submitedScoreID);
  167. return studentScoreDAL.submitedScoreRepository.GetSingle(exp, (x => x.CF_Student.Sys_User), (x => x.ER_SubmitedScoreDetail));
  168. }
  169. //计算绩点
  170. public decimal? GetGradePoint(Guid? collegeID, int? year, int? examsCategoryID, int? courseTypeID, decimal? totalScore)
  171. {
  172. decimal? GradePoint = 0;
  173. var scoreParameterSetting = ScoreParameterSettingServices.Value.GetScoreParameterSettingList(collegeID, year, examsCategoryID, courseTypeID);
  174. if (scoreParameterSetting != null)
  175. {
  176. ER_GradePointFormula gradePointFormula = gradePointFormulaRepository.GetSingle(x => x.GradePointFormulaID == scoreParameterSetting.GradePointFormulaID);
  177. if (gradePointFormula != null)
  178. {
  179. if (totalScore >= gradePointFormula.GradePointlimit)
  180. {
  181. GradePoint = 1;
  182. int tscore = (int)totalScore;
  183. if (tscore > gradePointFormula.GradePointlimit)
  184. {
  185. GradePoint += (tscore - gradePointFormula.GradePointlimit) * gradePointFormula.GradePointFloor;
  186. }
  187. }
  188. }
  189. }
  190. return GradePoint;
  191. }
  192. /// <summary>
  193. /// 添加/修改
  194. /// </summary>
  195. /// <param name="studentScoreView"></param>
  196. public void StudentScoreAdd(ViewModel.ScoreManage.StudentScoreView studentScoreView, List<ExpandoObject> listExpandoObject)
  197. {
  198. try
  199. {
  200. //ER_ScoreParameterSetting scoreParameterSetting = GetGradePoint(studentScoreView.ExamsCategoryID, studentScoreView.CourseTypeID);
  201. var scoreDynamicTypes = DictionaryHelper.GetDictionaryValue(DictionaryItem.CF_ScoreType);
  202. var student = this.studentScoreDAL.studentRepository.GetSingle(x => x.UserID == studentScoreView.UserID,
  203. (x => x.CF_Classmajor.CF_Grademajor.CF_Facultymajor));
  204. Guid? collegeID;
  205. int? year;
  206. try
  207. {
  208. collegeID = student.CF_Classmajor.CF_Grademajor.CF_Facultymajor.CollegeID;
  209. year = student.CF_Classmajor.CF_Grademajor.GradeID;
  210. }
  211. catch
  212. {
  213. throw new Exception("该学生没有对应的班级信息,无法录入。");
  214. }
  215. ER_SubmitedScore submitedScoreEntity = SubmitedScoreRepository.GetSingle(x => x.SubmitedScoreID == studentScoreView.SubmitedScoreID);
  216. ER_SubmitedScore submitedScore = null;
  217. if (studentScoreView.Remarks == "Add")
  218. {
  219. //学年学期-学号-课程代码-考试性质
  220. //ER_SubmitedScore DBsubmitedScore = SubmitedScoreRepository.GetSingle(x => x.SchoolyearID == studentScoreView.SchoolyearID && x.UserID == studentScoreView.UserID && x.CoursematerialID == studentScoreView.CoursematerialID && x.ExamsCategoryID == studentScoreView.ExamsCategoryID);
  221. //if (DBsubmitedScore != null)
  222. //{
  223. // throw new Exception("该学生在该学期已经有相同课程的考试,考试性质也相同。不能重复添加!");
  224. //}
  225. //复制型新增
  226. studentScoreView.SubmitedScoreID = null;
  227. }
  228. if (studentScoreView.SubmitedScoreID == null || studentScoreView.SubmitedScoreID == Guid.Empty)
  229. {
  230. submitedScore = new ER_SubmitedScore();
  231. submitedScore.SubmitedScoreID = Guid.NewGuid();
  232. submitedScore.SchoolyearID = studentScoreView.SchoolyearID;
  233. submitedScore.SchoolyearNumID = studentScoreView.SchoolyearNumID;
  234. submitedScore.DepartmentID = studentScoreView.DepartmentID;
  235. submitedScore.ClassName = studentScoreView.ClassName;
  236. submitedScore.CoursematerialID = studentScoreView.CoursematerialID;
  237. submitedScore.CourseTypeID = studentScoreView.CourseTypeID;
  238. submitedScore.ExamsCategoryID = studentScoreView.ExamsCategoryID;
  239. submitedScore.ExaminationModeID = studentScoreView.ExaminationModeID;
  240. submitedScore.Credit = studentScoreView.Credit;
  241. submitedScore.ExamsDatetime = studentScoreView.ExamsDatetime;
  242. submitedScore.ResultTypeID = studentScoreView.ResultTypeID == null ? (int)CF_ResultType.Percentage : studentScoreView.ResultTypeID;
  243. submitedScore.CreatorUserID = studentScoreView.CreatorUserID;
  244. submitedScore.EntryDeadlineTime = studentScoreView.EntryDeadlineTime;
  245. submitedScore.IsEntry = true;
  246. submitedScore.ExaminationType = studentScoreView.ExaminationType;
  247. submitedScore.StarttermID = studentScoreView.StarttermID;
  248. submitedScore.UserID = studentScoreView.UserID;
  249. submitedScore.ExamsStateID = studentScoreView.ExamsStateID;
  250. //暂时按此种逻辑处理。。后续优化(廖兵良)
  251. if (studentScoreView.ExamsStateID != (int)CF_ExamsState.NormalExams && studentScoreView.ExamsStateID != 10)
  252. {
  253. submitedScore.TotalScore = studentScoreDAL.examsStateSettingRepository.GetSingle(x => x.ExamsStateID == studentScoreView.ExamsStateID).Score;
  254. }
  255. else {
  256. submitedScore.TotalScore = studentScoreView.TotalScore;
  257. }
  258. submitedScore.ScoreCredit = submitedScore.TotalScore >= 60 ? studentScoreView.Credit : 0;
  259. submitedScore.GradePoint = GetGradePoint(collegeID, year, studentScoreView.ExamsCategoryID, studentScoreView.CourseTypeID, studentScoreView.TotalScore);
  260. //submitedScore.GradePoint = studentScoreView.GradePoint;
  261. submitedScore.Remark = studentScoreView.StudentScoreRemark;
  262. SetNewStatus(submitedScore);
  263. UnitOfWork.Add(submitedScore);
  264. foreach (dynamic expandoObject in listExpandoObject)
  265. {
  266. var dic = (IDictionary<string, object>)expandoObject;
  267. ER_SubmitedScoreDetail submitedScoreDetail = new ER_SubmitedScoreDetail();
  268. submitedScoreDetail.SubmitedScoreDetailID = Guid.NewGuid();
  269. submitedScoreDetail.SubmitedScoreID = submitedScore.SubmitedScoreID;
  270. submitedScoreDetail.ScoreTypeID = expandoObject.ScoreTypeID;
  271. submitedScoreDetail.Score = expandoObject.Score == "" ? null : Convert.ToDecimal(expandoObject.Score);
  272. SetNewStatus(submitedScoreDetail);
  273. UnitOfWork.Add(submitedScoreDetail);
  274. }
  275. }
  276. else
  277. {
  278. submitedScore = GetSubmitedScore(studentScoreView.SubmitedScoreID);
  279. var oldCoursematerialID = submitedScore.CoursematerialID;
  280. var oldUserID = submitedScore.UserID;
  281. var oldStartTerm = submitedScore.StarttermID;
  282. if (submitedScore == null)
  283. throw new Exception("未找到相对应的数据!");
  284. submitedScore.SchoolyearID = studentScoreView.SchoolyearID;
  285. submitedScore.SchoolyearNumID = studentScoreView.SchoolyearNumID;
  286. submitedScore.DepartmentID = studentScoreView.DepartmentID;
  287. submitedScore.ClassName = studentScoreView.ClassName;
  288. submitedScore.CoursematerialID = studentScoreView.CoursematerialID;
  289. submitedScore.CourseTypeID = studentScoreView.CourseTypeID;
  290. submitedScore.ExamsCategoryID = studentScoreView.ExamsCategoryID;
  291. submitedScore.ExaminationModeID = studentScoreView.ExaminationModeID;
  292. submitedScore.Credit = studentScoreView.Credit;
  293. submitedScore.ExamsDatetime = studentScoreView.ExamsDatetime;
  294. submitedScore.ResultTypeID = studentScoreView.ResultTypeID == null ? (int)CF_ResultType.Percentage : studentScoreView.ResultTypeID;
  295. submitedScore.CreatorUserID = studentScoreView.CreatorUserID;
  296. submitedScore.EntryDeadlineTime = studentScoreView.EntryDeadlineTime;
  297. submitedScore.ExaminationType = studentScoreView.ExaminationType;
  298. submitedScore.StarttermID = studentScoreView.StarttermID;
  299. submitedScore.UserID = studentScoreView.UserID;
  300. submitedScore.ExamsStateID = studentScoreView.ExamsStateID;
  301. //暂时按此种逻辑处理。。后续优化(廖兵良)
  302. if (studentScoreView.ExamsStateID != (int)CF_ExamsState.NormalExams && studentScoreView.ExamsStateID != 10)
  303. {
  304. submitedScore.TotalScore = studentScoreDAL.examsStateSettingRepository.GetSingle(x => x.ExamsStateID == studentScoreView.ExamsStateID).Score;
  305. }
  306. else
  307. {
  308. submitedScore.TotalScore = studentScoreView.TotalScore;
  309. }
  310. submitedScore.ScoreCredit = submitedScore.TotalScore >= 60 ? studentScoreView.Credit : 0;
  311. //submitedScore.ScoreCredit = studentScoreView.ScoreCredit;
  312. submitedScore.GradePoint = GetGradePoint(collegeID, year, studentScoreView.ExamsCategoryID, studentScoreView.CourseTypeID, studentScoreView.TotalScore);
  313. //submitedScore.GradePoint = studentScoreView.GradePoint;
  314. submitedScore.Remark = studentScoreView.StudentScoreRemark;
  315. SetModifyStatus(submitedScore);
  316. foreach (dynamic expandoObject in listExpandoObject)
  317. {
  318. int scoreTypeID = expandoObject.ScoreTypeID;
  319. ER_SubmitedScoreDetail submitedScoreDetail = submitedScore.ER_SubmitedScoreDetail.Where(x => x.ScoreTypeID == scoreTypeID).FirstOrDefault();
  320. submitedScoreDetail.ScoreTypeID = expandoObject.ScoreTypeID;
  321. submitedScoreDetail.Score = expandoObject.Score == "" ? null : Convert.ToDecimal(expandoObject.Score);
  322. SetModifyStatus(submitedScoreDetail);
  323. }
  324. if (oldUserID != studentScoreView.UserID || oldCoursematerialID != studentScoreView.CoursematerialID || oldStartTerm != studentScoreView.StarttermID)
  325. {
  326. this.RefreshFinallyScore(oldCoursematerialID ?? Guid.Empty, oldUserID, oldStartTerm);
  327. }
  328. }
  329. UnitOfWork.Commit();
  330. this.RefreshFinallyScore(studentScoreView.CoursematerialID ?? Guid.Empty, studentScoreView.UserID, studentScoreView.StarttermID);
  331. UnitOfWork.Commit();
  332. }
  333. catch (Exception)
  334. {
  335. throw;
  336. }
  337. }
  338. /// <summary>
  339. /// 删除
  340. /// </summary>
  341. /// <param name="submitedScoreIDs"></param>
  342. public void StudentScoreDelete(List<Guid> submitedScoreIDs)
  343. {
  344. try
  345. {
  346. if (submitedScoreIDs.Count > 0)
  347. {
  348. var submitedScoreSelectList = SubmitedScoreRepository.GetList(x => submitedScoreIDs.Contains(x.SubmitedScoreID)).Select(p => new { p.StarttermID, p.DepartmentID, p.CoursematerialID, p.UserID }).ToList();
  349. this.RefreshFinallyScoreBeforeDelete(x => submitedScoreIDs.Contains(x.SubmitedScoreID));
  350. UnitOfWork.Delete<ER_SubmitedScoreDetail>(x => submitedScoreIDs.Contains(x.SubmitedScoreID.Value));
  351. UnitOfWork.Delete<ER_SubmitedScore>(x => submitedScoreIDs.Contains(x.SubmitedScoreID));
  352. //if (submitedScoreSelectList != null && submitedScoreSelectList.Count > 0)
  353. //{
  354. // var scoreDynamicTypes = DictionaryHelper.GetDictionaryValue(DictionaryItem.CF_ScoreType);
  355. // submitedScoreSelectList.ForEach(x =>
  356. // {
  357. // //1.0 用同一开课学期,教研室,课程,学生 取已提交最大的考试性质
  358. // /************************************************************************************************************************/
  359. // int? ExamsCategoryIDMax = SubmitedScoreRepository.GetList(w => w.StarttermID == w.StarttermID
  360. // && w.DepartmentID == x.DepartmentID
  361. // && w.CoursematerialID == x.CoursematerialID
  362. // && w.UserID == x.UserID).Max(w => w.ExamsCategoryID).Value;
  363. // //2.0 查询同一开课学期,教研室,课程,学生,拿已提交最大的考试性质信息
  364. // /************************************************************************************************************************/
  365. // ER_SubmitedScore SubEntity = SubmitedScoreRepository.GetSingle(w => w.StarttermID == w.StarttermID
  366. // && w.DepartmentID == x.DepartmentID
  367. // && w.CoursematerialID == x.CoursematerialID
  368. // && w.UserID == x.UserID
  369. // && w.ExamsCategoryID == ExamsCategoryIDMax, ((w => w.ER_SubmitedScoreDetail)));
  370. // //3.0 查询同一开课学期,教研室,课程,学生,拿最终成绩最大的考试性质信息
  371. // /************************************************************************************************************************/
  372. // ER_FinallyScore Fllentity = FinallyScoreRepository.GetSingle(w => x.StarttermID == x.StarttermID
  373. // && w.DepartmentID == x.DepartmentID
  374. // && w.CoursematerialID == x.CoursematerialID
  375. // && w.UserID == x.UserID, (w => w.ER_FinallyScoreDetail));
  376. // //4.0更新以上子级表信息
  377. // /************************************************************************************************************************/
  378. // foreach (var scoreDynamicType in scoreDynamicTypes)
  379. // {
  380. // ER_SubmitedScoreDetail submitedScoreDetail = SubEntity.ER_SubmitedScoreDetail.Where(w => w.ScoreTypeID == scoreDynamicType.Value).FirstOrDefault();
  381. // ER_FinallyScoreDetail finallyScoreDetail = Fllentity.ER_FinallyScoreDetail.Where(w => w.ScoreTypeID == scoreDynamicType.Value).FirstOrDefault();
  382. // finallyScoreDetail.ScoreTypeID = submitedScoreDetail.ScoreTypeID;
  383. // finallyScoreDetail.Score = submitedScoreDetail.Score;
  384. // SetModifyStatus(finallyScoreDetail);
  385. // }
  386. // /************************************************************************************************************************/
  387. // if (Fllentity != null)
  388. // {
  389. // Fllentity.TotalScore = Math.Round(SubEntity.TotalScore ?? 0, 0);
  390. // Fllentity.ExamsCategoryID = ExamsCategoryIDMax;
  391. // SetModifyStatus(Fllentity);
  392. // UnitOfWork.Update(Fllentity);
  393. // }
  394. // /***********************************************************End*************************************************************/
  395. // });
  396. //}
  397. UnitOfWork.Commit();
  398. }
  399. }
  400. catch (Exception)
  401. {
  402. throw;
  403. }
  404. }
  405. public void ValidateDuplicate(Guid? submitedScoreID, Guid? userID, Guid? coursematerialID, int? examsCategoryID, int? startTermID)
  406. {
  407. //学号-课程代码-学年数-考试性质-开课学期
  408. if (SubmitedScoreRepository.GetList(x => x.UserID == userID
  409. && x.CoursematerialID == coursematerialID
  410. && x.ExamsCategoryID == examsCategoryID
  411. && x.StarttermID == startTermID
  412. && x.SubmitedScoreID != submitedScoreID).Count() > 0)
  413. {
  414. throw new Exception("该学生在该学期已经有相同课程的考试,考试性质也相同,是否继续操作?如果确认添加,毕业成绩将按照新的成绩计算。");
  415. }
  416. }
  417. public void RefreshFinallyScore(Guid coursematerialID, IList<Guid?> userIDList, int? startTermID)
  418. {
  419. Expression<Func<ER_SubmitedScore, bool>> exp = (x => x.CoursematerialID == coursematerialID);
  420. if (userIDList != null)
  421. {
  422. exp = exp.And(x => userIDList.Contains(x.UserID));
  423. }
  424. if (startTermID.HasValue)
  425. {
  426. exp = exp.And(x => x.StarttermID == startTermID);
  427. }
  428. RefreshFinallyScore(exp);
  429. }
  430. public void RefreshFinallyScore(Guid coursematerialID, Guid? userID, int? startTermID)
  431. {
  432. Expression<Func<ER_SubmitedScore, bool>> exp = (x => x.CoursematerialID == coursematerialID);
  433. if (userID.HasValue)
  434. {
  435. exp = exp.And(x => x.UserID == userID);
  436. }
  437. if (startTermID.HasValue)
  438. {
  439. exp = exp.And(x => x.StarttermID == startTermID);
  440. }
  441. RefreshFinallyScore(exp);
  442. }
  443. public void RefreshFinallyScoreBySubmitedScoreID(IList<Guid> submitedScoreIDList)
  444. {
  445. this.RefreshFinallyScore(x => submitedScoreIDList.Contains(x.SubmitedScoreID));
  446. }
  447. private void RefreshFinallyScore(Expression<Func<ER_SubmitedScore, bool>> exp)
  448. {
  449. UnitOfWork.Configuration.ProxyCreationEnabled = true;
  450. UnitOfWork.Configuration.LazyLoadingEnabled = true;
  451. var lastSubmitedScoreList = this.studentScoreDAL.GetLastSubmittedScore(exp).ToList();
  452. var detailList = lastSubmitedScoreList.SelectMany(x => x.ER_SubmitedScoreDetail).ToList();
  453. var finallyScoreList = this.studentScoreDAL.GetFinallyScoreBySubmittedScore(exp).ToList();
  454. UnitOfWork.Configuration.LazyLoadingEnabled = false;
  455. UnitOfWork.Configuration.ProxyCreationEnabled = false;
  456. RefreshFinallyScore(lastSubmitedScoreList, finallyScoreList);
  457. }
  458. public void RefreshFinallyScoreBySubmitedBeforeDeleteScoreID(IList<Guid> submitedScoreIDList)
  459. {
  460. this.RefreshFinallyScoreBeforeDelete(x => submitedScoreIDList.Contains(x.SubmitedScoreID));
  461. }
  462. public void RefreshFinallyScoreBeforeDelete(Expression<Func<ER_SubmitedScore, bool>> exp)
  463. {
  464. UnitOfWork.Configuration.ProxyCreationEnabled = true;
  465. UnitOfWork.Configuration.LazyLoadingEnabled = true;
  466. var lastSubmitedScoreList = this.studentScoreDAL.GetLastSubmittedScoreBeforDelete(exp).ToList();
  467. var detailList = lastSubmitedScoreList.SelectMany(x => x.ER_SubmitedScoreDetail).ToList();
  468. var finallyScoreList = this.studentScoreDAL.GetFinallyScoreBySubmittedScore(exp).ToList();
  469. UnitOfWork.Configuration.LazyLoadingEnabled = false;
  470. UnitOfWork.Configuration.ProxyCreationEnabled = false;
  471. RefreshFinallyScore(lastSubmitedScoreList, finallyScoreList);
  472. }
  473. private void RefreshFinallyScore(IList<ER_SubmitedScore> lastSubmitedScoreList, IList<ER_FinallyScore> finallyScoreList)
  474. {
  475. //var deletedIDList = finallyScoreList.Select(x => x.FinallyScoreID).ToList();
  476. var insertFinallyScoreList = new List<ER_FinallyScore>();
  477. var insertFinallyScoreDetailList = new List<ER_FinallyScoreDetail>();
  478. var finalScoreIDList = finallyScoreList.Select(y => y.FinallyScoreID).ToList();
  479. var finalScoredetailList = studentScoreDAL.FinallyScoreDetailRepository.GetList(x => finalScoreIDList.Contains(x.FinallyScoreID.Value)).ToList();
  480. //UnitOfWork.Delete<ER_FinallyScore>(x => deletedIDList.Contains(x.FinallyScoreID));
  481. UnitOfWork.Delete(finalScoredetailList);
  482. UnitOfWork.Delete(finallyScoreList);
  483. //this.UnitOfWork.Commit();
  484. foreach (var lastSubmitedScore in lastSubmitedScoreList)
  485. {
  486. ER_FinallyScore finallyScore = new ER_FinallyScore();
  487. finallyScore.FinallyScoreID = Guid.NewGuid();
  488. finallyScore.SchoolyearID = lastSubmitedScore.SchoolyearID;
  489. finallyScore.SchoolyearNumID = lastSubmitedScore.SchoolyearNumID;
  490. finallyScore.DepartmentID = lastSubmitedScore.DepartmentID;
  491. finallyScore.ClassName = lastSubmitedScore.ClassName;
  492. finallyScore.CoursematerialID = lastSubmitedScore.CoursematerialID;
  493. finallyScore.CourseTypeID = lastSubmitedScore.CourseTypeID;
  494. finallyScore.ExamsCategoryID = lastSubmitedScore.ExamsCategoryID;
  495. finallyScore.ExaminationModeID = lastSubmitedScore.ExaminationModeID;
  496. finallyScore.HandleModeID = lastSubmitedScore.HandleModeID;
  497. finallyScore.Credit = lastSubmitedScore.Credit;
  498. finallyScore.ExamsDatetime = lastSubmitedScore.ExamsDatetime;
  499. finallyScore.ResultTypeID = lastSubmitedScore.ResultTypeID;
  500. finallyScore.CreatorUserID = lastSubmitedScore.CreatorUserID;
  501. finallyScore.EntryDeadlineTime = lastSubmitedScore.EntryDeadlineTime;
  502. finallyScore.IsEntry = true;
  503. finallyScore.ExaminationType = lastSubmitedScore.ExaminationType;
  504. finallyScore.StarttermID = lastSubmitedScore.StarttermID;
  505. finallyScore.UserID = lastSubmitedScore.UserID;
  506. finallyScore.ExamsStateID = lastSubmitedScore.ExamsStateID;
  507. //媚姐说所有的学校录成绩都不用四舍五入了
  508. //finallyScore.TotalScore = Math.Round(lastSubmitedScore.TotalScore ?? 0, 0);
  509. finallyScore.TotalScore = lastSubmitedScore.TotalScore;
  510. finallyScore.ScoreCredit = lastSubmitedScore.ScoreCredit;
  511. finallyScore.GradePoint = lastSubmitedScore.GradePoint;
  512. //在期末设定、已提交成绩、最终成绩增加总学时字段,最终成绩总学时来源于已提交成绩
  513. finallyScore.TotalHours = lastSubmitedScore.TotalHours;
  514. SetNewStatus(finallyScore);
  515. insertFinallyScoreList.Add(finallyScore);
  516. foreach (var scoreDetail in lastSubmitedScore.ER_SubmitedScoreDetail)
  517. {
  518. ER_FinallyScoreDetail finallyScoreDetail = new ER_FinallyScoreDetail();
  519. finallyScoreDetail.FinallyScoreDetailID = Guid.NewGuid();
  520. finallyScoreDetail.FinallyScoreID = finallyScore.FinallyScoreID;
  521. finallyScoreDetail.ScoreTypeID = scoreDetail.ScoreTypeID;
  522. finallyScoreDetail.Score = scoreDetail.Score;
  523. SetNewStatus(finallyScoreDetail);
  524. insertFinallyScoreDetailList.Add(finallyScoreDetail);
  525. }
  526. }
  527. UnitOfWork.BulkInsert(insertFinallyScoreList);
  528. UnitOfWork.BulkInsert(insertFinallyScoreDetailList);
  529. }
  530. public string GetClassByUserID(Guid userID)
  531. {
  532. CF_Student student = studentScoreDAL.studentRepository.GetSingle(x => x.UserID == userID);
  533. CF_Classmajor classmajor = studentScoreDAL.classmajorRepository.GetSingle(x => x.ClassmajorID == student.ClassmajorID);
  534. string className = classmajor.Name;
  535. return className;
  536. }
  537. public List<ResultTypeDetailView> GetResultTypeDetail(int typeID)
  538. {
  539. Expression<Func<ER_ResultTypeDetail, bool>> exp = x => x.ResultTypeID == typeID;
  540. var query = resultTypeDetailDAL.GetResultsTypeDetailView(exp);
  541. //.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
  542. return query.OrderByDescending(x => x.Score).ToList();
  543. }
  544. public ER_ResultTypeDetail GetResultTypeDetailByDetaliID(Guid resultTypedetailID)
  545. {
  546. return resultTypeDetailRepository.GetSingle(x => x.ResultTypeDetailID == resultTypedetailID);
  547. }
  548. public ER_ResultTypeDetail GetResultTypeDetailByIDandScore(int typeID, decimal Score)
  549. {
  550. return resultTypeDetailRepository.GetSingle(x => x.ResultTypeID == typeID && x.Score == Score);
  551. }
  552. public Guid? GetDepartmentByUserID(Guid UserID)
  553. {
  554. if (studentScoreDAL.staffRepository.GetSingle(x => x.UserID == UserID) != null)
  555. {
  556. return studentScoreDAL.staffRepository.GetSingle(x => x.UserID == UserID).DepartmentID.Value;
  557. }
  558. else {
  559. return null;
  560. }
  561. }
  562. public List<int?> GetNormalExamsState()
  563. {
  564. List<int?> examsStateList = examsStateSettingRepository.GetList(x => x.IsNormal == true).Select(x => x.ExamsStateID).ToList();
  565. return examsStateList;
  566. }
  567. public List<StudentScoreView> GetStarttermList(int? year)
  568. {
  569. var StarttermvalueList = studentScoreDAL.DictionaryItemRepository.GetList(x => x.DictionaryCode == "cf_Startterm").Select(x => x.Value).ToList();
  570. List<StudentScoreView> StarttermList = new List<StudentScoreView>();
  571. if (year != null)
  572. {
  573. for (int i = 0; i <= 1; i++)
  574. {
  575. StudentScoreView Startterm = new StudentScoreView();
  576. Startterm.StarttermID = (year.Value*2-1) + i;
  577. if (StarttermvalueList.Contains(Startterm.StarttermID))
  578. {
  579. StarttermList.Add(Startterm);
  580. }
  581. }
  582. }
  583. else
  584. {
  585. var SchoolyearNum=studentScoreDAL.DictionaryItemRepository.GetList(x => x.DictionaryCode == "CF_SchoolyearNum").Select(x=>x.Value).ToList();
  586. int num = (int)SchoolyearNum.Max()*2;
  587. for (int i = 0; i < num; i++)
  588. {
  589. StudentScoreView Startterm = new StudentScoreView();
  590. Startterm.StarttermID = i+1;
  591. if (StarttermvalueList.Contains(Startterm.StarttermID))
  592. {
  593. StarttermList.Add(Startterm);
  594. }
  595. }
  596. }
  597. return StarttermList;
  598. }
  599. public IGridResultSet<CoursematerialView> GetFinallyScoreCoursematerialViewGrid(ConfiguretView conditionView, Guid userID, int? pageIndex, int? pageSize)
  600. {
  601. Expression<Func<ER_FinallyScore, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  602. exp = exp.And(x => x.UserID == userID);
  603. var query = studentScoreDAL.GetCoursematerialViewQueryableByFinallyScore(exp);
  604. if (!string.IsNullOrEmpty(conditionView.ConditionValue))
  605. {
  606. query = query.DynamicWhere(conditionView.Attribute, conditionView.Condition, conditionView.ConditionValue.Trim());
  607. }
  608. query = query.OrderByDescending(x => x.CourseCode).ThenBy(x => x.CourseName);
  609. return query.ToGridResultSet<CoursematerialView>(pageIndex, pageSize);
  610. }
  611. public FinallyScoreView GetFinallyScoreView(Guid userID, Guid coursematerialID)
  612. {
  613. Expression<Func<ER_FinallyScore, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE
  614. && x.UserID == userID && x.CoursematerialID == coursematerialID);
  615. var finallyScoreView = this.studentScoreDAL.GetFinallyScoreViewQueryable(exp).OrderByDescending(x => x.TotalScore).FirstOrDefault();
  616. return finallyScoreView;
  617. }
  618. }
  619. }