using System; using System.Collections.Generic; using System.Linq; using System.Text; using EMIS.DataLogic.StudentSystem.MyGrade; using EMIS.ViewModel.Students; using Bowin.Common.Linq.Entity; using EMIS.Entities; using System.Dynamic; using EMIS.Utility; using EMIS.ViewModel; using EMIS.DataLogic.Repositories; namespace EMIS.CommonLogic.Students { public class CourseGradeServices : BaseServices, ICourseGradeServices { public CourseGradeDAL CourseGradeDAL { get; set; } public SubmitedScoreRepository SubmitedScoreRepository { get; set; } public FinallyScoreRepository FinallyScoreRepository { get; set; } public IList GetStudentCourseGrade(Guid UserID) { return CourseGradeDAL.GetStudentCourseGrade(UserID); } /// /// 获取已提交成绩 /// /// /// /// public IGridResultSet GetSubmitedScoreList(Guid? CoursematerialID, int? StartTermID, Guid? UserID) { var data = CourseGradeDAL.GetSubmitedScoreList(CoursematerialID, StartTermID, UserID); foreach (var Grade in data) { var ScoreDetail = CourseGradeDAL.GetScoreDetail(Grade.SubmitedScoreID); var pingshi = ScoreDetail.SingleOrDefault(q => q.ScoreTypeID == (int)EMIS.ViewModel.CF_ScoreType.Peacetime); var jishu = ScoreDetail.SingleOrDefault(q => q.ScoreTypeID == (int)EMIS.ViewModel.CF_ScoreType.Technique); var lilun = ScoreDetail.SingleOrDefault(q => q.ScoreTypeID == (int)EMIS.ViewModel.CF_ScoreType.Theoretical); Grade.Pingshi = pingshi != null ? pingshi.Score : 0; Grade.Jishu = jishu != null ? jishu.Score : 0; Grade.Lilun = lilun != null ? lilun.Score : 0; } return data.AsQueryable().OrderBy(x=>x.LoginID.Length).ThenBy(x=>x.LoginID) .ThenBy(x=>x.CourseCode.Length).ThenBy(x=>x.CourseCode) .ThenByDescending(x=>x.CreateTime) .ToGridResultSet(); } /// /// 获取学生个人成绩预览信息 /// /// /// public StudentGradView GetStudentInfo(Guid StudentID) { var student = CourseGradeDAL.GetStudentInfo(StudentID); return student; } /// /// 获取学生个人成绩预览信息 /// /// /// public StudentGradView GetStudentPersonalScore(Guid? userID) { var student = CourseGradeDAL.GetStudentPersonalScore(userID); return student; } /// /// 获取学生个人成绩预览信息(GT) /// /// /// public StudentGradView GetStudentPersonalScoreGT(Guid? userID) { var student = CourseGradeDAL.GetStudentPersonalScoreGT(userID); return student; } /// /// 已提交成绩详细 /// /// /// public ViewModel.ScoreManage.SubmitedScoreDetailView GetSubmitedScoreDetailView(Guid? submitedScoreID) { var query = CourseGradeDAL.GetSubmitedScoreViewQueryable(); if (submitedScoreID.HasValue) query = query.Where(x => x.SubmitedScoreID == submitedScoreID); return query.FirstOrDefault(); } /// /// 添加修改 /// /// /// 1、新增 0、修改 public void SubmitedScoreAdd(ViewModel.ScoreManage.SubmitedScoreDetailView submitedScoreDetailView, int atype, List listExpandoObject) { try { if (submitedScoreDetailView.Remark == "Add") { //复制型新增 submitedScoreDetailView.SubmitedScoreID = null; } ER_SubmitedScore submitedScore = null; //新增 if (atype == 1) { submitedScore = new ER_SubmitedScore(); submitedScore.SubmitedScoreID = Guid.NewGuid(); submitedScore.SchoolyearID = submitedScoreDetailView.SchoolyearID; submitedScore.SchoolyearNumID = submitedScoreDetailView.SchoolyearNumID; submitedScore.DepartmentID = submitedScoreDetailView.DepartmentID; submitedScore.ClassName = submitedScoreDetailView.ClassName; submitedScore.CoursematerialID = submitedScoreDetailView.CoursematerialID; submitedScore.CourseTypeID = submitedScoreDetailView.CourseTypeID; submitedScore.ExamsCategoryID = submitedScoreDetailView.ExamsCategoryID; submitedScore.ExaminationModeID = submitedScoreDetailView.ExaminationModeID; submitedScore.Credit = submitedScoreDetailView.Credit; submitedScore.ExamsDatetime = submitedScoreDetailView.ExamsDatetime; submitedScore.CreatorUserID = submitedScoreDetailView.CreatorUserID; submitedScore.EntryDeadlineTime = submitedScoreDetailView.EntryDeadlineTime; submitedScore.ExaminationType = submitedScoreDetailView.ExaminationTypeID; submitedScore.StarttermID = submitedScoreDetailView.StarttermID; submitedScore.UserID = submitedScoreDetailView.UserID; submitedScore.ExamsStateID = submitedScoreDetailView.ExamsStateID; submitedScore.TotalScore = submitedScoreDetailView.TotalScore; submitedScore.ScoreCredit = submitedScoreDetailView.ScoreCredit; submitedScore.GradePoint = submitedScoreDetailView.GradePoint; SetNewStatus(submitedScore); UnitOfWork.Add(submitedScore); foreach (dynamic expandoObject in listExpandoObject) { var dic = (IDictionary)expandoObject; ER_SubmitedScoreDetail submitedScoreDetail = new ER_SubmitedScoreDetail(); submitedScoreDetail.SubmitedScoreDetailID = Guid.NewGuid(); submitedScoreDetail.SubmitedScoreID = submitedScore.SubmitedScoreID; submitedScoreDetail.ScoreTypeID = expandoObject.ScoreTypeID; submitedScoreDetail.Score = expandoObject.Score; SetNewStatus(submitedScoreDetail); UnitOfWork.Add(submitedScoreDetail); } } else { submitedScore = CourseGradeDAL.SubmitedScoreRepository.GetSingle(x => x.SubmitedScoreID == submitedScoreDetailView.SubmitedScoreID, (x => x.ER_SubmitedScoreDetail)); if (submitedScore == null) throw new Exception("未找到相对应的数据!"); submitedScore.SchoolyearID = submitedScoreDetailView.SchoolyearID; submitedScore.SchoolyearNumID = submitedScoreDetailView.SchoolyearNumID; submitedScore.DepartmentID = submitedScoreDetailView.DepartmentID; submitedScore.ClassName = submitedScoreDetailView.ClassName; submitedScore.CoursematerialID = submitedScoreDetailView.CoursematerialID; submitedScore.CourseTypeID = submitedScoreDetailView.CourseTypeID; submitedScore.ExamsCategoryID = submitedScoreDetailView.ExamsCategoryID; submitedScore.ExaminationModeID = submitedScoreDetailView.ExaminationModeID; submitedScore.Credit = submitedScoreDetailView.Credit; submitedScore.ExamsDatetime = submitedScoreDetailView.ExamsDatetime; submitedScore.CreatorUserID = submitedScoreDetailView.CreatorUserID; submitedScore.EntryDeadlineTime = submitedScoreDetailView.EntryDeadlineTime; submitedScore.ExaminationType = submitedScoreDetailView.ExaminationTypeID; submitedScore.StarttermID = submitedScoreDetailView.StarttermID; submitedScore.UserID = submitedScoreDetailView.UserID; submitedScore.ExamsStateID = submitedScoreDetailView.ExamsStateID; submitedScore.TotalScore = submitedScoreDetailView.TotalScore; submitedScore.ScoreCredit = submitedScoreDetailView.ScoreCredit; submitedScore.GradePoint = submitedScoreDetailView.GradePoint; SetModifyStatus(submitedScore); foreach (dynamic expandoObject in listExpandoObject) { int scoreTypeID = expandoObject.ScoreTypeID; ER_SubmitedScoreDetail submitedScoreDetail = submitedScore.ER_SubmitedScoreDetail.Where(x => x.ScoreTypeID == scoreTypeID).FirstOrDefault(); submitedScoreDetail.ScoreTypeID = expandoObject.ScoreTypeID; submitedScoreDetail.Score = expandoObject.Score; SetModifyStatus(submitedScoreDetail); } } UnitOfWork.Commit(); //提取到该成绩对应的最大考试性质信息 int? ExamsCategoryIDMax = SubmitedScoreRepository.GetList(x => x.SchoolyearID == submitedScoreDetailView.SchoolyearID && x.DepartmentID == submitedScoreDetailView.DepartmentID && x.CoursematerialID == submitedScoreDetailView.CoursematerialID && x.UserID == submitedScoreDetailView.UserID).Max(w => w.ExamsCategoryID).Value; //学生成绩操作完成以后、同步最终成绩表对应的信息 if (ExamsCategoryIDMax != null) { ER_SubmitedScore entity = SubmitedScoreRepository.GetSingle(x => x.SchoolyearID == submitedScoreDetailView.SchoolyearID && x.DepartmentID == submitedScoreDetailView.DepartmentID && x.CoursematerialID == submitedScoreDetailView.CoursematerialID && x.UserID == submitedScoreDetailView.UserID && x.ExamsCategoryID == ExamsCategoryIDMax); //判断是否存在最终成绩 ER_FinallyScore finallyScore = CourseGradeDAL.ScoreRepository.GetSingle(x => x.SchoolyearID == submitedScoreDetailView.SchoolyearID && x.CoursematerialID == submitedScoreDetailView.CoursematerialID && x.DepartmentID == submitedScoreDetailView.DepartmentID && x.StarttermID == submitedScoreDetailView.StarttermID && x.UserID == submitedScoreDetailView.UserID, (x => x.ER_FinallyScoreDetail)); if (finallyScore == null) { finallyScore = new ER_FinallyScore(); finallyScore.FinallyScoreID = Guid.NewGuid(); finallyScore.SchoolyearID = submitedScoreDetailView.SchoolyearID; finallyScore.SchoolyearNumID = submitedScoreDetailView.SchoolyearNumID; finallyScore.DepartmentID = submitedScoreDetailView.DepartmentID; finallyScore.ClassName = submitedScoreDetailView.ClassName; finallyScore.CoursematerialID = submitedScoreDetailView.CoursematerialID; finallyScore.CourseTypeID = submitedScoreDetailView.CourseTypeID; finallyScore.ExamsCategoryID = submitedScoreDetailView.ExamsCategoryID; finallyScore.ExaminationModeID = submitedScoreDetailView.ExaminationModeID; finallyScore.Credit = submitedScoreDetailView.Credit; finallyScore.ExamsDatetime = submitedScoreDetailView.ExamsDatetime; finallyScore.CreatorUserID = submitedScoreDetailView.CreatorUserID; finallyScore.EntryDeadlineTime = submitedScoreDetailView.EntryDeadlineTime; finallyScore.ExaminationType = submitedScoreDetailView.ExaminationTypeID; finallyScore.StarttermID = submitedScoreDetailView.StarttermID; finallyScore.UserID = submitedScoreDetailView.UserID; finallyScore.ExamsStateID = submitedScoreDetailView.ExamsStateID; finallyScore.TotalScore = submitedScoreDetailView.TotalScore; finallyScore.ScoreCredit = submitedScoreDetailView.ScoreCredit; finallyScore.GradePoint = submitedScoreDetailView.GradePoint; SetNewStatus(finallyScore); UnitOfWork.Add(finallyScore); foreach (dynamic expandoObject in listExpandoObject) { var dic = (IDictionary)expandoObject; ER_FinallyScoreDetail finallyScoreDetail = new ER_FinallyScoreDetail(); finallyScoreDetail.FinallyScoreDetailID = Guid.NewGuid(); finallyScoreDetail.FinallyScoreID = finallyScore.FinallyScoreID; finallyScoreDetail.ScoreTypeID = expandoObject.ScoreTypeID; finallyScoreDetail.Score = expandoObject.Score; SetNewStatus(finallyScoreDetail); UnitOfWork.Add(finallyScoreDetail); } } else { finallyScore.SchoolyearID = submitedScoreDetailView.SchoolyearID; finallyScore.SchoolyearNumID = submitedScoreDetailView.SchoolyearNumID; finallyScore.DepartmentID = submitedScoreDetailView.DepartmentID; finallyScore.ClassName = submitedScoreDetailView.ClassName; finallyScore.CoursematerialID = submitedScoreDetailView.CoursematerialID; finallyScore.CourseTypeID = submitedScoreDetailView.CourseTypeID; finallyScore.ExamsCategoryID = submitedScoreDetailView.ExamsCategoryID; finallyScore.ExaminationModeID = submitedScoreDetailView.ExaminationModeID; finallyScore.Credit = submitedScoreDetailView.Credit; finallyScore.ExamsDatetime = submitedScoreDetailView.ExamsDatetime; finallyScore.CreatorUserID = submitedScoreDetailView.CreatorUserID; finallyScore.EntryDeadlineTime = submitedScoreDetailView.EntryDeadlineTime; finallyScore.ExaminationType = submitedScoreDetailView.ExaminationTypeID; finallyScore.StarttermID = submitedScoreDetailView.StarttermID; finallyScore.UserID = submitedScoreDetailView.UserID; finallyScore.ExamsStateID = submitedScoreDetailView.ExamsStateID; finallyScore.TotalScore = submitedScoreDetailView.TotalScore; finallyScore.ScoreCredit = submitedScoreDetailView.ScoreCredit; finallyScore.GradePoint = submitedScoreDetailView.GradePoint; SetModifyStatus(finallyScore); foreach (dynamic expandoObject in listExpandoObject) { int scoreTypeID = expandoObject.ScoreTypeID; ER_FinallyScoreDetail finallyScoreDetail = finallyScore.ER_FinallyScoreDetail.Where(x => x.ScoreTypeID == scoreTypeID).FirstOrDefault(); finallyScoreDetail.ScoreTypeID = expandoObject.ScoreTypeID; finallyScoreDetail.Score = expandoObject.Score; SetModifyStatus(finallyScoreDetail); } } } UnitOfWork.Commit(); } catch (Exception) { throw; } } /// /// 删除 /// /// public void SubmitedScoreDelete(List submitedScoreIDs, Guid? schoolyearID, Guid? coursematerialID, int? starttermID, Guid? userID) { try { if (submitedScoreIDs.Count > 0) { UnitOfWork.Delete(x => submitedScoreIDs.Contains(x.SubmitedScoreID.Value)); UnitOfWork.Delete(x => submitedScoreIDs.Contains(x.SubmitedScoreID)); var listSubmitedScore = CourseGradeDAL.SubmitedScoreRepository.GetList(x => x.SchoolyearID == schoolyearID && x.CoursematerialID == coursematerialID && x.StarttermID == starttermID && x.UserID == userID).ToList(); if (listSubmitedScore.Count == 0) { UnitOfWork.Delete(x => x.SchoolyearID == schoolyearID && x.CoursematerialID == coursematerialID && x.StarttermID == starttermID && x.UserID == userID); } else { 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(); if (submitedScore != null) { ER_FinallyScore finallyScore = CourseGradeDAL.ScoreRepository.GetSingle(x => x.SchoolyearID == schoolyearID && x.CoursematerialID == coursematerialID && x.StarttermID == starttermID && x.UserID == userID, (x => x.ER_FinallyScoreDetail)); if (finallyScore != null) { var scoreDynamicTypes = DictionaryHelper.GetDictionaryValue(DictionaryItem.CF_ScoreType); finallyScore.SchoolyearID = submitedScore.SchoolyearID; finallyScore.SchoolyearNumID = submitedScore.SchoolyearNumID; finallyScore.DepartmentID = submitedScore.DepartmentID; finallyScore.ClassName = submitedScore.ClassName; finallyScore.CoursematerialID = submitedScore.CoursematerialID; finallyScore.CourseTypeID = submitedScore.CourseTypeID; finallyScore.ExamsCategoryID = submitedScore.ExamsCategoryID; finallyScore.ExaminationModeID = submitedScore.ExaminationModeID; finallyScore.Credit = submitedScore.Credit; finallyScore.ExamsDatetime = submitedScore.ExamsDatetime; finallyScore.CreatorUserID = submitedScore.CreatorUserID; finallyScore.EntryDeadlineTime = submitedScore.EntryDeadlineTime; finallyScore.ExaminationType = submitedScore.ExaminationType; finallyScore.StarttermID = submitedScore.StarttermID; finallyScore.UserID = submitedScore.UserID; finallyScore.ExamsStateID = submitedScore.ExamsStateID; finallyScore.TotalScore = submitedScore.TotalScore; finallyScore.ScoreCredit = submitedScore.ScoreCredit; finallyScore.GradePoint = submitedScore.GradePoint; finallyScore.Remark = submitedScore.Remark; SetModifyStatus(finallyScore); foreach (var scoreDynamicType in scoreDynamicTypes) { ER_SubmitedScoreDetail submitedScoreDetail = submitedScore.ER_SubmitedScoreDetail.Where(x => x.ScoreTypeID == scoreDynamicType.Value).FirstOrDefault(); ER_FinallyScoreDetail finallyScoreDetail = finallyScore.ER_FinallyScoreDetail.Where(x => x.ScoreTypeID == scoreDynamicType.Value).FirstOrDefault(); finallyScoreDetail.ScoreTypeID = submitedScoreDetail.ScoreTypeID; finallyScoreDetail.Score = submitedScoreDetail.Score; SetModifyStatus(finallyScoreDetail); } } UnitOfWork.Commit(); } } } } catch (Exception) { throw; } } /// /// 获取已提交成绩 /// /// /// public ER_SubmitedScore GetSubmitedScore(Guid? submitedScoreID) { return CourseGradeDAL.SubmitedScoreRepository.GetSingle(x => x.SubmitedScoreID == submitedScoreID, (x => x.ER_SubmitedScoreDetail)); } public List GetStudentPersonalScoreViewList(ConfiguretView configuretView, Guid? coursematerialID, int? starttermID, Guid? userID) { if (!coursematerialID.HasValue) { coursematerialID = Guid.Empty; starttermID = null; userID = Guid.Empty; } var data = CourseGradeDAL.GetSubmitedScoreList((Guid)coursematerialID, starttermID, (Guid)userID); foreach (var Grade in data) { var ScoreDetail = CourseGradeDAL.GetScoreDetail(Grade.SubmitedScoreID); var pingshi = ScoreDetail.SingleOrDefault(q => q.ScoreTypeID == (int)EMIS.ViewModel.CF_ScoreType.Peacetime); var jishu = ScoreDetail.SingleOrDefault(q => q.ScoreTypeID == (int)EMIS.ViewModel.CF_ScoreType.Technique); var lilun = ScoreDetail.SingleOrDefault(q => q.ScoreTypeID == (int)EMIS.ViewModel.CF_ScoreType.Theoretical); Grade.Pingshi = pingshi != null ? pingshi.Score : 0; Grade.Jishu = jishu != null ? jishu.Score : 0; Grade.Lilun = lilun != null ? lilun.Score : 0; } return data.ToList(); } } }