public void Save() { List <GradScoreRecord> updateSemsScore = new List <GradScoreRecord>(); DomainScoreLogFormater logFormater = new DomainScoreLogFormater(); foreach (StudentScore student in Students) { GraduateScoreCollection gscore = student.GraduateScore; //畢業成績(自定 Object)。 GradScoreRecord grecord = gscore.RawScore; //畢業成績記錄(DAL)。 //如果該筆成績沒有對應的畢業成績,就新增一筆。 if (grecord == null) { grecord = new GradScoreRecord(); grecord.RefStudentID = student.Id; } #region 複製領域成績。 foreach (string strDomain in gscore) { GraduateScore gs = gscore[strDomain]; if (!grecord.Domains.ContainsKey(strDomain)) { grecord.Domains.Add(strDomain, new GradDomainScore(strDomain)); } gscore.Log.Add(new LogData(strDomain, grecord.Domains[strDomain].Score + "", gs.Value + "")); grecord.Domains[strDomain].Score = gs.Value; } foreach (LogData each in gscore.Log) { each.Formater = logFormater; } gscore.LearningLog.Formater = logFormater; gscore.LearningLog.OriginValue = grecord.LearnDomainScore + ""; gscore.LearningLog.NewValue = gscore.LearnDomainScore + ""; gscore.CourseLog.Formater = logFormater; gscore.CourseLog.OriginValue = grecord.CourseLearnScore + ""; gscore.CourseLog.NewValue = gscore.CourseLearnScore + ""; grecord.LearnDomainScore = gscore.LearnDomainScore; grecord.CourseLearnScore = gscore.CourseLearnScore; #endregion //新增到「更新」清單中。 updateSemsScore.Add(grecord); } #region 更新科目成績 FunctionSpliter <GradScoreRecord, GradScoreRecord> updateData = new FunctionSpliter <GradScoreRecord, GradScoreRecord>(300, 5); updateData.Function = delegate(List <GradScoreRecord> ps) { GradScore.Update(ps); return(new List <GradScoreRecord>()); }; updateData.ProgressChange = delegate(int progress) { Reporter.Feedback("更新畢業成績...", Util.CalculatePercentage(updateSemsScore.Count, progress)); }; updateData.Execute(updateSemsScore); #endregion }
private void worker_DoWork(object sender, DoWorkEventArgs e) { List <StudentScore> Students = StudentIDs.ToStudentScore(); List <StudentScore> noValid = Students.ReadCalculationRule(this); //沒有計算規則的學生。 if (noValid.Count > 0) { throw new CalculationException(noValid, "下列學生沒有計算規則,無法計算畢業成績。"); } Students.ReadSemesterScore(this); //讀取所有學期的成績。 Students.ReadSemesterHistory(this); //讀取學期歷程。 noValid = Students.VaidSixSemesterHistory(); //驗證學期歷程是否完整。 if (noValid.Count > 0) { throw new CalculationException(noValid, "下列學生學期歷程不完整,無法計算畢業成績。"); } noValid = Students.ValidSixSemesterDomainScore(); //驗證學期成績是否完整。 if (noValid.Count > 0) { throw new CalculationException(noValid, "下列學生並沒有完整的十二學期成績,無法計算畢業成績。"); } Students.ReadGraduateScore(this); //讀取畢業成績。 Students.CalculateGraduateScore(); //計算畢業成績。 // 取得學生 ID List <string> StudIDs = (from Stud in Students select Stud.Id).ToList(); // 學生科目成績(彈性課程) Dictionary <string, List <K12.Data.SubjectScore> > StudSubjScore = new Dictionary <string, List <K12.Data.SubjectScore> >(); Dictionary <string, decimal> StudDomainNullScore = new Dictionary <string, decimal>(); foreach (JHSemesterScoreRecord Scr in JHSemesterScore.SelectByStudentIDs(StudentIDs)) { // 取得領域名稱空白 List <K12.Data.SubjectScore> ss = (from ss1 in Scr.Subjects where ss1.Value.Domain == "" select ss1.Value).ToList(); if (ss.Count > 0) { if (StudSubjScore.ContainsKey(Scr.RefStudentID)) { StudSubjScore[Scr.RefStudentID].AddRange(ss); } else { StudSubjScore.Add(Scr.RefStudentID, ss); } } } // 計算彈性課程成績 foreach (KeyValuePair <string, List <K12.Data.SubjectScore> > data in StudSubjScore) { decimal sum = 0, Credit = 0; foreach (K12.Data.SubjectScore ss in data.Value) { if (ss.Credit.HasValue) { Credit += ss.Credit.Value; } if (ss.Score.HasValue) { sum += ss.Score.Value; } } if (!StudDomainNullScore.ContainsKey(data.Key)) { if (Credit > 0) { decimal score = sum / Credit; StudDomainNullScore.Add(data.Key, score); } } } foreach (StudentScore ss in Students) { if (StudDomainNullScore.ContainsKey(ss.Id)) { //2017/5/9 穎驊修正 ,因應 高雄 [08-05][03] 畢業資格判斷成績及格標準調整 項目, // 領域 分數超過60分 ,以 四捨五入取到小數第二位 , 低於60分 採用 無條件進位至整數 (EX : 59.01 =60) //decimal score = ss.CalculationRule.ParseDomainScore(StudDomainNullScore[ss.Id]); decimal score = 0; if (JHEvaluation.ScoreCalculation.Program.Mode == JHEvaluation.ScoreCalculation.ModuleMode.HsinChu) { score = ss.CalculationRule.ParseDomainScore(StudDomainNullScore[ss.Id]); } if (JHEvaluation.ScoreCalculation.Program.Mode == JHEvaluation.ScoreCalculation.ModuleMode.KaoHsiung) { if (StudDomainNullScore[ss.Id] >= 60) { score = ss.CalculationRule.ParseDomainScore(StudDomainNullScore[ss.Id]); } else { score = Math.Ceiling(StudDomainNullScore[ss.Id]); } } if (ss.GraduateScore.Contains("彈性課程")) { ss.GraduateScore["彈性課程"].Value = score; } else { GraduateScore gs = new GraduateScore(); gs.Value = score; ss.GraduateScore.Add("彈性課程", gs); } } } Students.SaveGraduateScore(this);//儲存畢業成績。 //儲存 Log。 try { LogSaver logger = FISCA.LogAgent.ApplicationLog.CreateLogSaverInstance(); logger.Log("學生畢業成績計算(學生)", "計算學生畢業成績", "計算學生數:" + Students.Count); //logger.BatchLogCompleted += delegate(object sender1, EventArgs e1) { }; //logger.BatchLogFailure += delegate(object sender1, LogErrorEventArgs e1) { }; foreach (StudentScore each in Students) { StringBuilder description = new StringBuilder(); description.AppendLine(string.Format("學生:{0}({1})", each.Name, each.StudentNumber)); foreach (LogData log in each.GraduateScore.Log) { description.Append(log.ToString()); } description.Append(each.GraduateScore.LearningLog.ToString()); description.Append(each.GraduateScore.CourseLog.ToString()); logger.AddBatch("學生畢業成績計算", "計算學生畢業成績", "student", each.Id, description.ToString()); } logger.LogBatch(); } catch { } Feedback("", 0); }