using System; using System.Collections.Generic; using System.Linq; using System.Text; using EMIS.DataLogic.ScoreManage; using EMIS.ViewModel.ScoreManage; using EMIS.Entities; namespace EMIS.CommonLogic.ScoreManage { public class ScoreParameterSettingServices : BaseServices, IScoreParameterSettingServices { public FinalExaminationDAL FinalExaminationDAL { get; set; } public ScoreParameterSettingDAL scoreParameterSettingDAL { get; set; } public ScoreParameterCollegeSettingDAL ScoreParameterCollegeSettingDAL { get; set; } public ScoreDAL scoreDAL { get; set; } public List GetScoreParameterSettingViewGrid() { return scoreParameterSettingDAL.GetScoreParameterSettingViewQueryable().ToList(); } /// /// 添加 /// /// public void ScoreParameterSettingServicesAdd(List listScoreParameterSetting) { try { UnitOfWork.Delete(x=>true); listScoreParameterSetting.ToList().ForEach(x => { var detail = new ER_ScoreParameterSetting(); detail.ScoreParameterSettingID = Guid.NewGuid(); detail.ExamsTypeID = x.ExamsTypeID; detail.CourseTypeID = x.CourseTypeID; detail.ScoreFormulaID = x.ScoreFormulaID; detail.IsTotalFormula = x.IsTotalFormula; detail.CreditFormulaID = x.CreditFormulaID; detail.IsCreditFormula = x.IsCreditFormula; detail.GradePointFormulaID = x.GradePointFormulaID; detail.IsGradePointFormula = x.IsGradePointFormula; this.SetNewStatus(detail); UnitOfWork.Add(detail); }); this.UnitOfWork.Commit(); } catch (Exception) { throw; } } /// /// 获取优先设置 /// /// 考试类型 /// 课程类型 /// public ScoreParameterSettingView GetScoreParameterSettingList(Guid? finalExaminationID) { var finalExaminationView = FinalExaminationDAL.GetFinalExaminationViewQueryable(x => x.FinalExaminationID == finalExaminationID).FirstOrDefault(); if (finalExaminationView == null) { throw new Exception("获取公式设置失败,找不到对应的期末设定。"); } var studentScoreList = scoreDAL.ScoreRepository.GetList(x => x.FinalExaminationID == finalExaminationID).ToList(); var ScoreParameterSettingList=GetScoreParameterSettingList(finalExaminationView.CollegeID, finalExaminationView.GradeYearID, finalExaminationView.ExamsCategoryID, finalExaminationView.CourseTypeID); if (studentScoreList.Count>0) { foreach (var studentScore in studentScoreList) { if (studentScore.RecordStatus== (int)EMIS.ViewModel.SYS_STATUS.UNUSABLE) { ScoreParameterSettingList.IsTotalFormula = false; ScoreParameterSettingList.IsCreditFormula = false; ScoreParameterSettingList.IsGradePointFormula = false; break; } } } return ScoreParameterSettingList; } public ScoreParameterSettingView GetScoreParameterSettingList(Guid? collegeID, int? year, int? examsCategoryID, int? courseTypeID) { ScoreParameterSettingView scoreParameterSetting = new ScoreParameterSettingView(); List commonScoreParameterSettingList = this.GetScoreParameterSettingViewGrid().ToList(); ; List collegeScoreParameterSettingList = commonScoreParameterSettingList; //获取各院系的个性化设置,优先获取指定了自己院系的设置 var collegeScoreParameterSetting = this.ScoreParameterCollegeSettingDAL .GetScoreParameterCollegeSettingViewQueryable(x => x.Years == year && x.CollegeID == collegeID).FirstOrDefault(); //找不到再找该年级的通用设置 if (collegeScoreParameterSetting == null) { collegeScoreParameterSetting = this.ScoreParameterCollegeSettingDAL .GetScoreParameterCollegeSettingViewQueryable(x => x.Years == year && x.CollegeID == null).FirstOrDefault(); } //有可能以上两种都没有,所以要判断一下 if (collegeScoreParameterSetting != null) { collegeScoreParameterSettingList = this.ScoreParameterCollegeSettingDAL .GetScoreParameterSettingViewQueryable(x => x.ScoreParameterCollegeSettingID == collegeScoreParameterSetting.ScoreParameterCollegeSettingID) .ToList(); } //总分公式、学分公式和绩点公式是分开读取的,未必来源于同一条设置 #region 先找总分公式 #region 按个性化设置先找 var totalScoreParameterSetting = collegeScoreParameterSettingList.FirstOrDefault(x => x.CourseTypeID == courseTypeID && x.ExamsTypeID == examsCategoryID && x.ScoreFormulaID != null); if (totalScoreParameterSetting == null) { totalScoreParameterSetting = collegeScoreParameterSettingList.FirstOrDefault(x => x.CourseTypeID == courseTypeID && x.ExamsTypeID == null && x.ScoreFormulaID != null); } if (totalScoreParameterSetting == null) { totalScoreParameterSetting = collegeScoreParameterSettingList.FirstOrDefault(x => x.CourseTypeID == null && x.ExamsTypeID == examsCategoryID && x.ScoreFormulaID != null); } if (totalScoreParameterSetting == null) { totalScoreParameterSetting = collegeScoreParameterSettingList.FirstOrDefault(x => x.CourseTypeID == null && x.ExamsTypeID == null); } scoreParameterSetting.ScoreFormulaID = totalScoreParameterSetting.ScoreFormulaID; scoreParameterSetting.IsTotalFormula = totalScoreParameterSetting.IsTotalFormula; #endregion #region 再按通用设置找 if (scoreParameterSetting.ScoreFormulaID == null) { totalScoreParameterSetting = commonScoreParameterSettingList.FirstOrDefault(x => x.CourseTypeID == courseTypeID && x.ExamsTypeID == examsCategoryID && x.ScoreFormulaID != null); if (totalScoreParameterSetting == null) { totalScoreParameterSetting = commonScoreParameterSettingList.FirstOrDefault(x => x.CourseTypeID == courseTypeID && x.ExamsTypeID == null && x.ScoreFormulaID != null); } if (totalScoreParameterSetting == null) { totalScoreParameterSetting = commonScoreParameterSettingList.FirstOrDefault(x => x.CourseTypeID == null && x.ExamsTypeID == examsCategoryID && x.ScoreFormulaID != null); } if (totalScoreParameterSetting == null) { totalScoreParameterSetting = commonScoreParameterSettingList.FirstOrDefault(x => x.CourseTypeID == null && x.ExamsTypeID == null); } scoreParameterSetting.ScoreFormulaID = totalScoreParameterSetting.ScoreFormulaID; scoreParameterSetting.IsTotalFormula = totalScoreParameterSetting.IsTotalFormula; } #endregion #endregion #region 再找学分公式 #region 按个性化设置先找 var creditParameterSetting = collegeScoreParameterSettingList.FirstOrDefault(x => x.CourseTypeID == courseTypeID && x.ExamsTypeID == examsCategoryID && x.CreditFormulaID != null); if (creditParameterSetting == null) { creditParameterSetting = collegeScoreParameterSettingList.FirstOrDefault(x => x.CourseTypeID == courseTypeID && x.ExamsTypeID == null && x.CreditFormulaID != null); } if (creditParameterSetting == null) { creditParameterSetting = collegeScoreParameterSettingList.FirstOrDefault(x => x.CourseTypeID == null && x.ExamsTypeID == examsCategoryID && x.CreditFormulaID != null); } if (creditParameterSetting == null) { creditParameterSetting = collegeScoreParameterSettingList.FirstOrDefault(x => x.CourseTypeID == null && x.ExamsTypeID == null); } scoreParameterSetting.CreditFormulaID = creditParameterSetting.CreditFormulaID; scoreParameterSetting.IsCreditFormula = creditParameterSetting.IsCreditFormula; #endregion #region 再按通用设置找 if (scoreParameterSetting.CreditFormulaID == null) { creditParameterSetting = commonScoreParameterSettingList.FirstOrDefault(x => x.CourseTypeID == courseTypeID && x.ExamsTypeID == examsCategoryID && x.CreditFormulaID != null); if (creditParameterSetting == null) { creditParameterSetting = commonScoreParameterSettingList.FirstOrDefault(x => x.CourseTypeID == courseTypeID && x.ExamsTypeID == null && x.CreditFormulaID != null); } if (creditParameterSetting == null) { creditParameterSetting = commonScoreParameterSettingList.FirstOrDefault(x => x.CourseTypeID == null && x.ExamsTypeID == examsCategoryID && x.CreditFormulaID != null); } if (creditParameterSetting == null) { creditParameterSetting = commonScoreParameterSettingList.FirstOrDefault(x => x.CourseTypeID == null && x.ExamsTypeID == null); } scoreParameterSetting.CreditFormulaID = creditParameterSetting.CreditFormulaID; scoreParameterSetting.IsCreditFormula = creditParameterSetting.IsCreditFormula; } #endregion #endregion #region 再找绩点公式 #region 按个性化设置先找 var gradePointParameterSetting = collegeScoreParameterSettingList.FirstOrDefault(x => x.CourseTypeID == courseTypeID && x.ExamsTypeID == examsCategoryID && x.GradePointFormulaID != null); if (gradePointParameterSetting == null) { gradePointParameterSetting = collegeScoreParameterSettingList.FirstOrDefault(x => x.CourseTypeID == courseTypeID && x.ExamsTypeID == null && x.GradePointFormulaID != null); } if (gradePointParameterSetting == null) { gradePointParameterSetting = collegeScoreParameterSettingList.FirstOrDefault(x => x.CourseTypeID == null && x.ExamsTypeID == examsCategoryID && x.GradePointFormulaID != null); } if (gradePointParameterSetting == null) { gradePointParameterSetting = collegeScoreParameterSettingList.FirstOrDefault(x => x.CourseTypeID == null && x.ExamsTypeID == null); } scoreParameterSetting.GradePointFormulaID = gradePointParameterSetting.GradePointFormulaID; scoreParameterSetting.IsGradePointFormula = gradePointParameterSetting.IsGradePointFormula; #endregion #region 再按通用设置找 if (scoreParameterSetting.GradePointFormulaID == null) { gradePointParameterSetting = commonScoreParameterSettingList.FirstOrDefault(x => x.CourseTypeID == courseTypeID && x.ExamsTypeID == examsCategoryID && x.GradePointFormulaID != null); if (gradePointParameterSetting == null) { gradePointParameterSetting = commonScoreParameterSettingList.FirstOrDefault(x => x.CourseTypeID == courseTypeID && x.ExamsTypeID == null && x.GradePointFormulaID != null); } if (gradePointParameterSetting == null) { gradePointParameterSetting = commonScoreParameterSettingList.FirstOrDefault(x => x.CourseTypeID == null && x.ExamsTypeID == examsCategoryID && x.GradePointFormulaID != null); } if (gradePointParameterSetting == null) { gradePointParameterSetting = commonScoreParameterSettingList.FirstOrDefault(x => x.CourseTypeID == null && x.ExamsTypeID == null); } scoreParameterSetting.GradePointFormulaID = gradePointParameterSetting.GradePointFormulaID; scoreParameterSetting.IsGradePointFormula = gradePointParameterSetting.IsGradePointFormula; } #endregion #endregion return scoreParameterSetting; } } }