CourseGradeServices.cs 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using EMIS.DataLogic.StudentSystem.MyGrade;
  6. using EMIS.ViewModel.Students;
  7. using Bowin.Common.Linq.Entity;
  8. using EMIS.Entities;
  9. using System.Dynamic;
  10. using EMIS.Utility;
  11. using EMIS.ViewModel;
  12. using EMIS.DataLogic.Repositories;
  13. namespace EMIS.CommonLogic.Students
  14. {
  15. public class CourseGradeServices : BaseServices, ICourseGradeServices
  16. {
  17. public CourseGradeDAL CourseGradeDAL { get; set; }
  18. public SubmitedScoreRepository SubmitedScoreRepository { get; set; }
  19. public FinallyScoreRepository FinallyScoreRepository { get; set; }
  20. public IList<CourseGradeView> GetStudentCourseGrade(Guid UserID)
  21. {
  22. return CourseGradeDAL.GetStudentCourseGrade(UserID);
  23. }
  24. /// <summary>
  25. /// 获取已提交成绩
  26. /// </summary>
  27. /// <param name="CoursematerialID"></param>
  28. /// <param name="SchoolyearID"></param>
  29. /// <param name="UserID"></param>
  30. public IGridResultSet<SubmitedScoreView> GetSubmitedScoreList(Guid? CoursematerialID, int? StartTermID, Guid? UserID)
  31. {
  32. var data = CourseGradeDAL.GetSubmitedScoreList(CoursematerialID, StartTermID, UserID);
  33. foreach (var Grade in data)
  34. {
  35. var ScoreDetail = CourseGradeDAL.GetScoreDetail(Grade.SubmitedScoreID);
  36. var pingshi = ScoreDetail.SingleOrDefault(q => q.ScoreTypeID == (int)EMIS.ViewModel.CF_ScoreType.Peacetime);
  37. var jishu = ScoreDetail.SingleOrDefault(q => q.ScoreTypeID == (int)EMIS.ViewModel.CF_ScoreType.Technique);
  38. var lilun = ScoreDetail.SingleOrDefault(q => q.ScoreTypeID == (int)EMIS.ViewModel.CF_ScoreType.Theoretical);
  39. Grade.Pingshi = pingshi != null ? pingshi.Score : 0;
  40. Grade.Jishu = jishu != null ? jishu.Score : 0;
  41. Grade.Lilun = lilun != null ? lilun.Score : 0;
  42. }
  43. return data.AsQueryable().OrderBy(x=>x.LoginID.Length).ThenBy(x=>x.LoginID)
  44. .ThenBy(x=>x.CourseCode.Length).ThenBy(x=>x.CourseCode)
  45. .ThenByDescending(x=>x.CreateTime)
  46. .ToGridResultSet<SubmitedScoreView>();
  47. }
  48. /// <summary>
  49. /// 获取学生个人成绩预览信息
  50. /// </summary>
  51. /// <param name="StudentID"></param>
  52. /// <returns></returns>
  53. public StudentGradView GetStudentInfo(Guid StudentID)
  54. {
  55. var student = CourseGradeDAL.GetStudentInfo(StudentID);
  56. return student;
  57. }
  58. /// <summary>
  59. /// 获取学生个人成绩预览信息
  60. /// </summary>
  61. /// <param name="userID"></param>
  62. /// <returns></returns>
  63. public StudentGradView GetStudentPersonalScore(Guid? userID)
  64. {
  65. var student = CourseGradeDAL.GetStudentPersonalScore(userID);
  66. return student;
  67. }
  68. /// <summary>
  69. /// 获取学生个人成绩预览信息(GT)
  70. /// </summary>
  71. /// <param name="userID"></param>
  72. /// <returns></returns>
  73. public StudentGradView GetStudentPersonalScoreGT(Guid? userID)
  74. {
  75. var student = CourseGradeDAL.GetStudentPersonalScoreGT(userID);
  76. return student;
  77. }
  78. /// <summary>
  79. /// 已提交成绩详细
  80. /// </summary>
  81. /// <param name="submitedScoreID"></param>
  82. /// <returns></returns>
  83. public ViewModel.ScoreManage.SubmitedScoreDetailView GetSubmitedScoreDetailView(Guid? submitedScoreID)
  84. {
  85. var query = CourseGradeDAL.GetSubmitedScoreViewQueryable();
  86. if (submitedScoreID.HasValue)
  87. query = query.Where(x => x.SubmitedScoreID == submitedScoreID);
  88. return query.FirstOrDefault();
  89. }
  90. /// <summary>
  91. /// 添加修改
  92. /// </summary>
  93. /// <param name="submitedScoreDetailView"></param>
  94. /// <param name="atype">1、新增 0、修改</param>
  95. public void SubmitedScoreAdd(ViewModel.ScoreManage.SubmitedScoreDetailView submitedScoreDetailView, int atype, List<ExpandoObject> listExpandoObject)
  96. {
  97. try
  98. {
  99. if (submitedScoreDetailView.Remark == "Add")
  100. {
  101. //复制型新增
  102. submitedScoreDetailView.SubmitedScoreID = null;
  103. }
  104. ER_SubmitedScore submitedScore = null;
  105. //新增
  106. if (atype == 1)
  107. {
  108. submitedScore = new ER_SubmitedScore();
  109. submitedScore.SubmitedScoreID = Guid.NewGuid();
  110. submitedScore.SchoolyearID = submitedScoreDetailView.SchoolyearID;
  111. submitedScore.SchoolyearNumID = submitedScoreDetailView.SchoolyearNumID;
  112. submitedScore.DepartmentID = submitedScoreDetailView.DepartmentID;
  113. submitedScore.ClassName = submitedScoreDetailView.ClassName;
  114. submitedScore.CoursematerialID = submitedScoreDetailView.CoursematerialID;
  115. submitedScore.CourseTypeID = submitedScoreDetailView.CourseTypeID;
  116. submitedScore.ExamsCategoryID = submitedScoreDetailView.ExamsCategoryID;
  117. submitedScore.ExaminationModeID = submitedScoreDetailView.ExaminationModeID;
  118. submitedScore.Credit = submitedScoreDetailView.Credit;
  119. submitedScore.ExamsDatetime = submitedScoreDetailView.ExamsDatetime;
  120. submitedScore.CreatorUserID = submitedScoreDetailView.CreatorUserID;
  121. submitedScore.EntryDeadlineTime = submitedScoreDetailView.EntryDeadlineTime;
  122. submitedScore.ExaminationType = submitedScoreDetailView.ExaminationTypeID;
  123. submitedScore.StarttermID = submitedScoreDetailView.StarttermID;
  124. submitedScore.UserID = submitedScoreDetailView.UserID;
  125. submitedScore.ExamsStateID = submitedScoreDetailView.ExamsStateID;
  126. submitedScore.TotalScore = submitedScoreDetailView.TotalScore;
  127. submitedScore.ScoreCredit = submitedScoreDetailView.ScoreCredit;
  128. submitedScore.GradePoint = submitedScoreDetailView.GradePoint;
  129. SetNewStatus(submitedScore);
  130. UnitOfWork.Add(submitedScore);
  131. foreach (dynamic expandoObject in listExpandoObject)
  132. {
  133. var dic = (IDictionary<string, object>)expandoObject;
  134. ER_SubmitedScoreDetail submitedScoreDetail = new ER_SubmitedScoreDetail();
  135. submitedScoreDetail.SubmitedScoreDetailID = Guid.NewGuid();
  136. submitedScoreDetail.SubmitedScoreID = submitedScore.SubmitedScoreID;
  137. submitedScoreDetail.ScoreTypeID = expandoObject.ScoreTypeID;
  138. submitedScoreDetail.Score = expandoObject.Score;
  139. SetNewStatus(submitedScoreDetail);
  140. UnitOfWork.Add(submitedScoreDetail);
  141. }
  142. }
  143. else
  144. {
  145. submitedScore = CourseGradeDAL.SubmitedScoreRepository.GetSingle(x => x.SubmitedScoreID == submitedScoreDetailView.SubmitedScoreID, (x => x.ER_SubmitedScoreDetail));
  146. if (submitedScore == null)
  147. throw new Exception("未找到相对应的数据!");
  148. submitedScore.SchoolyearID = submitedScoreDetailView.SchoolyearID;
  149. submitedScore.SchoolyearNumID = submitedScoreDetailView.SchoolyearNumID;
  150. submitedScore.DepartmentID = submitedScoreDetailView.DepartmentID;
  151. submitedScore.ClassName = submitedScoreDetailView.ClassName;
  152. submitedScore.CoursematerialID = submitedScoreDetailView.CoursematerialID;
  153. submitedScore.CourseTypeID = submitedScoreDetailView.CourseTypeID;
  154. submitedScore.ExamsCategoryID = submitedScoreDetailView.ExamsCategoryID;
  155. submitedScore.ExaminationModeID = submitedScoreDetailView.ExaminationModeID;
  156. submitedScore.Credit = submitedScoreDetailView.Credit;
  157. submitedScore.ExamsDatetime = submitedScoreDetailView.ExamsDatetime;
  158. submitedScore.CreatorUserID = submitedScoreDetailView.CreatorUserID;
  159. submitedScore.EntryDeadlineTime = submitedScoreDetailView.EntryDeadlineTime;
  160. submitedScore.ExaminationType = submitedScoreDetailView.ExaminationTypeID;
  161. submitedScore.StarttermID = submitedScoreDetailView.StarttermID;
  162. submitedScore.UserID = submitedScoreDetailView.UserID;
  163. submitedScore.ExamsStateID = submitedScoreDetailView.ExamsStateID;
  164. submitedScore.TotalScore = submitedScoreDetailView.TotalScore;
  165. submitedScore.ScoreCredit = submitedScoreDetailView.ScoreCredit;
  166. submitedScore.GradePoint = submitedScoreDetailView.GradePoint;
  167. SetModifyStatus(submitedScore);
  168. foreach (dynamic expandoObject in listExpandoObject)
  169. {
  170. int scoreTypeID = expandoObject.ScoreTypeID;
  171. ER_SubmitedScoreDetail submitedScoreDetail = submitedScore.ER_SubmitedScoreDetail.Where(x => x.ScoreTypeID == scoreTypeID).FirstOrDefault();
  172. submitedScoreDetail.ScoreTypeID = expandoObject.ScoreTypeID;
  173. submitedScoreDetail.Score = expandoObject.Score;
  174. SetModifyStatus(submitedScoreDetail);
  175. }
  176. }
  177. UnitOfWork.Commit();
  178. //提取到该成绩对应的最大考试性质信息
  179. int? ExamsCategoryIDMax = SubmitedScoreRepository.GetList(x => x.SchoolyearID == submitedScoreDetailView.SchoolyearID
  180. && x.DepartmentID == submitedScoreDetailView.DepartmentID
  181. && x.CoursematerialID == submitedScoreDetailView.CoursematerialID
  182. && x.UserID == submitedScoreDetailView.UserID).Max(w => w.ExamsCategoryID).Value;
  183. //学生成绩操作完成以后、同步最终成绩表对应的信息
  184. if (ExamsCategoryIDMax != null)
  185. {
  186. ER_SubmitedScore entity = SubmitedScoreRepository.GetSingle(x => x.SchoolyearID == submitedScoreDetailView.SchoolyearID
  187. && x.DepartmentID == submitedScoreDetailView.DepartmentID
  188. && x.CoursematerialID == submitedScoreDetailView.CoursematerialID
  189. && x.UserID == submitedScoreDetailView.UserID && x.ExamsCategoryID == ExamsCategoryIDMax);
  190. //判断是否存在最终成绩
  191. ER_FinallyScore finallyScore = CourseGradeDAL.ScoreRepository.GetSingle(x => x.SchoolyearID == submitedScoreDetailView.SchoolyearID && x.CoursematerialID == submitedScoreDetailView.CoursematerialID && x.DepartmentID == submitedScoreDetailView.DepartmentID
  192. && x.StarttermID == submitedScoreDetailView.StarttermID && x.UserID == submitedScoreDetailView.UserID, (x => x.ER_FinallyScoreDetail));
  193. if (finallyScore == null)
  194. {
  195. finallyScore = new ER_FinallyScore();
  196. finallyScore.FinallyScoreID = Guid.NewGuid();
  197. finallyScore.SchoolyearID = submitedScoreDetailView.SchoolyearID;
  198. finallyScore.SchoolyearNumID = submitedScoreDetailView.SchoolyearNumID;
  199. finallyScore.DepartmentID = submitedScoreDetailView.DepartmentID;
  200. finallyScore.ClassName = submitedScoreDetailView.ClassName;
  201. finallyScore.CoursematerialID = submitedScoreDetailView.CoursematerialID;
  202. finallyScore.CourseTypeID = submitedScoreDetailView.CourseTypeID;
  203. finallyScore.ExamsCategoryID = submitedScoreDetailView.ExamsCategoryID;
  204. finallyScore.ExaminationModeID = submitedScoreDetailView.ExaminationModeID;
  205. finallyScore.Credit = submitedScoreDetailView.Credit;
  206. finallyScore.ExamsDatetime = submitedScoreDetailView.ExamsDatetime;
  207. finallyScore.CreatorUserID = submitedScoreDetailView.CreatorUserID;
  208. finallyScore.EntryDeadlineTime = submitedScoreDetailView.EntryDeadlineTime;
  209. finallyScore.ExaminationType = submitedScoreDetailView.ExaminationTypeID;
  210. finallyScore.StarttermID = submitedScoreDetailView.StarttermID;
  211. finallyScore.UserID = submitedScoreDetailView.UserID;
  212. finallyScore.ExamsStateID = submitedScoreDetailView.ExamsStateID;
  213. finallyScore.TotalScore = submitedScoreDetailView.TotalScore;
  214. finallyScore.ScoreCredit = submitedScoreDetailView.ScoreCredit;
  215. finallyScore.GradePoint = submitedScoreDetailView.GradePoint;
  216. SetNewStatus(finallyScore);
  217. UnitOfWork.Add(finallyScore);
  218. foreach (dynamic expandoObject in listExpandoObject)
  219. {
  220. var dic = (IDictionary<string, object>)expandoObject;
  221. ER_FinallyScoreDetail finallyScoreDetail = new ER_FinallyScoreDetail();
  222. finallyScoreDetail.FinallyScoreDetailID = Guid.NewGuid();
  223. finallyScoreDetail.FinallyScoreID = finallyScore.FinallyScoreID;
  224. finallyScoreDetail.ScoreTypeID = expandoObject.ScoreTypeID;
  225. finallyScoreDetail.Score = expandoObject.Score;
  226. SetNewStatus(finallyScoreDetail);
  227. UnitOfWork.Add(finallyScoreDetail);
  228. }
  229. }
  230. else
  231. {
  232. finallyScore.SchoolyearID = submitedScoreDetailView.SchoolyearID;
  233. finallyScore.SchoolyearNumID = submitedScoreDetailView.SchoolyearNumID;
  234. finallyScore.DepartmentID = submitedScoreDetailView.DepartmentID;
  235. finallyScore.ClassName = submitedScoreDetailView.ClassName;
  236. finallyScore.CoursematerialID = submitedScoreDetailView.CoursematerialID;
  237. finallyScore.CourseTypeID = submitedScoreDetailView.CourseTypeID;
  238. finallyScore.ExamsCategoryID = submitedScoreDetailView.ExamsCategoryID;
  239. finallyScore.ExaminationModeID = submitedScoreDetailView.ExaminationModeID;
  240. finallyScore.Credit = submitedScoreDetailView.Credit;
  241. finallyScore.ExamsDatetime = submitedScoreDetailView.ExamsDatetime;
  242. finallyScore.CreatorUserID = submitedScoreDetailView.CreatorUserID;
  243. finallyScore.EntryDeadlineTime = submitedScoreDetailView.EntryDeadlineTime;
  244. finallyScore.ExaminationType = submitedScoreDetailView.ExaminationTypeID;
  245. finallyScore.StarttermID = submitedScoreDetailView.StarttermID;
  246. finallyScore.UserID = submitedScoreDetailView.UserID;
  247. finallyScore.ExamsStateID = submitedScoreDetailView.ExamsStateID;
  248. finallyScore.TotalScore = submitedScoreDetailView.TotalScore;
  249. finallyScore.ScoreCredit = submitedScoreDetailView.ScoreCredit;
  250. finallyScore.GradePoint = submitedScoreDetailView.GradePoint;
  251. SetModifyStatus(finallyScore);
  252. foreach (dynamic expandoObject in listExpandoObject)
  253. {
  254. int scoreTypeID = expandoObject.ScoreTypeID;
  255. ER_FinallyScoreDetail finallyScoreDetail = finallyScore.ER_FinallyScoreDetail.Where(x => x.ScoreTypeID == scoreTypeID).FirstOrDefault();
  256. finallyScoreDetail.ScoreTypeID = expandoObject.ScoreTypeID;
  257. finallyScoreDetail.Score = expandoObject.Score;
  258. SetModifyStatus(finallyScoreDetail);
  259. }
  260. }
  261. }
  262. UnitOfWork.Commit();
  263. }
  264. catch (Exception)
  265. {
  266. throw;
  267. }
  268. }
  269. /// <summary>
  270. /// 删除
  271. /// </summary>
  272. /// <param name="submitedScoreIDs"></param>
  273. public void SubmitedScoreDelete(List<Guid> submitedScoreIDs, Guid? schoolyearID, Guid? coursematerialID, int? starttermID, Guid? userID)
  274. {
  275. try
  276. {
  277. if (submitedScoreIDs.Count > 0)
  278. {
  279. UnitOfWork.Delete<ER_SubmitedScoreDetail>(x => submitedScoreIDs.Contains(x.SubmitedScoreID.Value));
  280. UnitOfWork.Delete<ER_SubmitedScore>(x => submitedScoreIDs.Contains(x.SubmitedScoreID));
  281. var listSubmitedScore = CourseGradeDAL.SubmitedScoreRepository.GetList(x => x.SchoolyearID == schoolyearID && x.CoursematerialID == coursematerialID && x.StarttermID == starttermID && x.UserID == userID).ToList();
  282. if (listSubmitedScore.Count == 0)
  283. {
  284. UnitOfWork.Delete<ER_FinallyScore>(x => x.SchoolyearID == schoolyearID && x.CoursematerialID == coursematerialID && x.StarttermID == starttermID && x.UserID == userID);
  285. }
  286. else
  287. {
  288. ER_SubmitedScore submitedScore = CourseGradeDAL.SubmitedScoreRepository.GetList(x => x.SchoolyearID == schoolyearID && x.CoursematerialID == coursematerialID && x.StarttermID == starttermID && x.UserID == userID, (x => x.ER_SubmitedScoreDetail)).OrderByDescending(x => x.CreateTime).ToList().FirstOrDefault();
  289. if (submitedScore != null)
  290. {
  291. ER_FinallyScore finallyScore = CourseGradeDAL.ScoreRepository.GetSingle(x => x.SchoolyearID == schoolyearID && x.CoursematerialID == coursematerialID && x.StarttermID == starttermID && x.UserID == userID, (x => x.ER_FinallyScoreDetail));
  292. if (finallyScore != null)
  293. {
  294. var scoreDynamicTypes = DictionaryHelper.GetDictionaryValue(DictionaryItem.CF_ScoreType);
  295. finallyScore.SchoolyearID = submitedScore.SchoolyearID;
  296. finallyScore.SchoolyearNumID = submitedScore.SchoolyearNumID;
  297. finallyScore.DepartmentID = submitedScore.DepartmentID;
  298. finallyScore.ClassName = submitedScore.ClassName;
  299. finallyScore.CoursematerialID = submitedScore.CoursematerialID;
  300. finallyScore.CourseTypeID = submitedScore.CourseTypeID;
  301. finallyScore.ExamsCategoryID = submitedScore.ExamsCategoryID;
  302. finallyScore.ExaminationModeID = submitedScore.ExaminationModeID;
  303. finallyScore.Credit = submitedScore.Credit;
  304. finallyScore.ExamsDatetime = submitedScore.ExamsDatetime;
  305. finallyScore.CreatorUserID = submitedScore.CreatorUserID;
  306. finallyScore.EntryDeadlineTime = submitedScore.EntryDeadlineTime;
  307. finallyScore.ExaminationType = submitedScore.ExaminationType;
  308. finallyScore.StarttermID = submitedScore.StarttermID;
  309. finallyScore.UserID = submitedScore.UserID;
  310. finallyScore.ExamsStateID = submitedScore.ExamsStateID;
  311. finallyScore.TotalScore = submitedScore.TotalScore;
  312. finallyScore.ScoreCredit = submitedScore.ScoreCredit;
  313. finallyScore.GradePoint = submitedScore.GradePoint;
  314. finallyScore.Remark = submitedScore.Remark;
  315. SetModifyStatus(finallyScore);
  316. foreach (var scoreDynamicType in scoreDynamicTypes)
  317. {
  318. ER_SubmitedScoreDetail submitedScoreDetail = submitedScore.ER_SubmitedScoreDetail.Where(x => x.ScoreTypeID == scoreDynamicType.Value).FirstOrDefault();
  319. ER_FinallyScoreDetail finallyScoreDetail = finallyScore.ER_FinallyScoreDetail.Where(x => x.ScoreTypeID == scoreDynamicType.Value).FirstOrDefault();
  320. finallyScoreDetail.ScoreTypeID = submitedScoreDetail.ScoreTypeID;
  321. finallyScoreDetail.Score = submitedScoreDetail.Score;
  322. SetModifyStatus(finallyScoreDetail);
  323. }
  324. }
  325. UnitOfWork.Commit();
  326. }
  327. }
  328. }
  329. }
  330. catch (Exception)
  331. {
  332. throw;
  333. }
  334. }
  335. /// <summary>
  336. /// 获取已提交成绩
  337. /// </summary>
  338. /// <param name="submitedScoreID"></param>
  339. /// <returns></returns>
  340. public ER_SubmitedScore GetSubmitedScore(Guid? submitedScoreID)
  341. {
  342. return CourseGradeDAL.SubmitedScoreRepository.GetSingle(x => x.SubmitedScoreID == submitedScoreID, (x => x.ER_SubmitedScoreDetail));
  343. }
  344. public List<SubmitedScoreView> GetStudentPersonalScoreViewList(ConfiguretView configuretView, Guid? coursematerialID, int? starttermID, Guid? userID)
  345. {
  346. if (!coursematerialID.HasValue)
  347. {
  348. coursematerialID = Guid.Empty;
  349. starttermID = null;
  350. userID = Guid.Empty;
  351. }
  352. var data = CourseGradeDAL.GetSubmitedScoreList((Guid)coursematerialID, starttermID, (Guid)userID);
  353. foreach (var Grade in data)
  354. {
  355. var ScoreDetail = CourseGradeDAL.GetScoreDetail(Grade.SubmitedScoreID);
  356. var pingshi = ScoreDetail.SingleOrDefault(q => q.ScoreTypeID == (int)EMIS.ViewModel.CF_ScoreType.Peacetime);
  357. var jishu = ScoreDetail.SingleOrDefault(q => q.ScoreTypeID == (int)EMIS.ViewModel.CF_ScoreType.Technique);
  358. var lilun = ScoreDetail.SingleOrDefault(q => q.ScoreTypeID == (int)EMIS.ViewModel.CF_ScoreType.Theoretical);
  359. Grade.Pingshi = pingshi != null ? pingshi.Score : 0;
  360. Grade.Jishu = jishu != null ? jishu.Score : 0;
  361. Grade.Lilun = lilun != null ? lilun.Score : 0;
  362. }
  363. return data.ToList();
  364. }
  365. }
  366. }