public List <StudentScore> Read() { #region 讀取成績計算規則。 IStatusReporter Rep = Reporter; Rep.Feedback("讀取成績計算規則...", 0); UniqueSet <string> ruleids = new UniqueSet <string>(); foreach (StudentScore each in Students) { if (!string.IsNullOrEmpty(each.RefCalculationRuleID)) { if (!ruleids.Contains(each.RefCalculationRuleID)) { ruleids.Add(each.RefCalculationRuleID); } } JHClassRecord cr = each.Class; if (cr != null) { if (string.IsNullOrEmpty(cr.RefScoreCalcRuleID)) { continue; } if (!ruleids.Contains(cr.RefScoreCalcRuleID)) { ruleids.Add(cr.RefScoreCalcRuleID); } } } FunctionSpliter <string, JHScoreCalcRuleRecord> spliter = new FunctionSpliter <string, JHScoreCalcRuleRecord>(10, Util.MaxThread); spliter.Function = delegate(List <string> idsPart) { return(JHScoreCalcRule.SelectByIDs(idsPart)); }; spliter.ProgressChange = delegate(int progress) { Rep.Feedback("讀取成績計算規則...", Util.CalculatePercentage(ruleids.Count, progress)); }; StudentScore.SetRuleMapping(spliter.Execute(ruleids.ToList())); List <StudentScore> noRule = new List <StudentScore>(); foreach (StudentScore each in Students) { if (each.CalculationRule == null) { noRule.Add(each); } } return(noRule); #endregion }
private List <SemesterHistoryRecord> ReadSemesterHistory() { FunctionSpliter <string, SemesterHistoryRecord> selectData = new FunctionSpliter <string, SemesterHistoryRecord>(500, Util.MaxThread); selectData.Function = delegate(List <string> p) { return(K12.Data.SemesterHistory.SelectByStudentIDs(p)); }; selectData.ProgressChange = delegate(int progress) { Reporter.Feedback("讀取學期歷程...", Util.CalculatePercentage(Students.Count, progress)); }; return(selectData.Execute(Students.Values.ToKeys())); }
private List <GradScoreRecord> ReadGraduateScore() { List <string> studIds = Students.Values.ToKeys(); FunctionSpliter <string, GradScoreRecord> spliter = new FunctionSpliter <string, GradScoreRecord>(300, Util.MaxThread); spliter.Function = delegate(List <string> ps) { return(GradScore.SelectByIDs <GradScoreRecord>(ps)); }; spliter.ProgressChange = delegate(int progress) { Reporter.Feedback("讀取畢業成績資料...", Util.CalculatePercentage(studIds.Count, progress)); }; return(spliter.Execute(studIds)); }
private List <JHSemesterScoreRecord> ReadSemesterScore() { List <string> studIds = Students.Values.ToKeys(); FunctionSpliter <string, JHSemesterScoreRecord> spliter = new FunctionSpliter <string, JHSemesterScoreRecord>(100, Util.MaxThread); spliter.Function = delegate(List <string> studIdPart) { return(JHSemesterScore.SelectBySchoolYearAndSemester(studIdPart, null, null)); }; spliter.ProgressChange = delegate(int progress) { Reporter.Feedback("讀取學期成績資料...", Util.CalculatePercentage(studIds.Count, progress)); }; return(spliter.Execute(studIds)); }
public void Save() { #region 儲存課程成績。 List <JHSCAttendRecord> attends = new List <JHSCAttendRecord>(); foreach (StudentScore student in Students) { foreach (string subject in student.AttendScore) { if (FilterSubject.Contains(subject) || FilterSubject.Count <= 0) { AttendScore attend = student.AttendScore[subject]; JHSCAttendRecord DALAttend = attend.RawAttend; DALAttend.Score = attend.Value; DALAttend.Effort = attend.Effort; DALAttend.Text = attend.Text; attends.Add(DALAttend); } } } if (attends.Count <= 0) { return; } FunctionSpliter <JHSCAttendRecord, JHSCAttendRecord> spliter = new FunctionSpliter <JHSCAttendRecord, JHSCAttendRecord>(300 * 10, Util.MaxThread); spliter.Function = delegate(List <JHSCAttendRecord> attendPart) { JHSCAttend.Update(attendPart); return(new List <JHSCAttendRecord>()); }; spliter.ProgressChange = delegate(int progress) { Reporter.Feedback("儲存計算結果...", Util.CalculatePercentage(attends.Count, progress)); }; spliter.Execute(attends); #endregion }
private List <JHSCETakeRecord> ReadSCETake() { Reporter.Feedback("讀取評量成績資料...", 0); List <string> attendids = new List <string>(); foreach (JHSCAttendRecord each in Attends.Values) { attendids.Add(each.ID); } FunctionSpliter <string, JHSCETakeRecord> selectData = new FunctionSpliter <string, JHSCETakeRecord>(300 * 10, Util.MaxThread); selectData.Function = delegate(List <string> attendIdsPart) { return(JHSCETake.Select(new string[] { }, new string[] { }, new string[] { }, new string[] { }, attendIdsPart)); }; selectData.ProgressChange = delegate(int progress) { Reporter.Feedback("讀取評量成績資料...", Util.CalculatePercentage(attendids.Count, progress)); }; return(selectData.Execute(attendids)); }
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 }
protected override void PrepareDataBackground() { FunctionSpliter <string, JHSCETakeRecord> selectData = new FunctionSpliter <string, JHSCETakeRecord>(500, 5); selectData.Function = delegate(List <string> ps) { return(JHSCETake.SelectByCourseAndExam(ps, ExamId)); }; List <JHSCETakeRecord> scetakes = selectData.Execute(Courses.Values.ToKeys()); JHClass.RemoveAll(); RatingStudent.SetClassMapping(JHClass.SelectAll()); //快取班級對照資訊。 Dictionary <string, RatingStudent> dicstuds = Students.ToDictionary(); //將學生的成績清除,並新增一個 Token 用來放成績。 foreach (RatingStudent each in Students) { each.Clear(); each.Scores.Add(ScoreType.Domain.Regulation(Token), new ScoreCollection()); each.Scores.Add(ScoreType.Subject.Regulation(Token), new ScoreCollection()); each.Scores.Add(ScoreType.SummaryDomain.Regulation(Token), new ScoreCollection()); } //記錄每一位學生的領域成績。 Dictionary <string, DomainScoreCalculator> domainscores = new Dictionary <string, DomainScoreCalculator>(); //計算領域成績。 foreach (JHSCETakeRecord take in scetakes) //特別注意 take.Score 是 Extensions 裡面的 Score 不是實體欄位的 Score。 { if (!take.Score.HasValue) { continue; //沒有成績就不處理。 } JHSCAttendRecord attend; JHCourseRecord course; RatingStudent student; if (!SCAttends.TryGetValue(take.RefSCAttendID, out attend)) { continue; //找不到該修課記錄。 } if (!dicstuds.TryGetValue(attend.RefStudentID, out student)) { continue; //找不到該學生。 } if (!Courses.TryGetValue(take.RefCourseID, out course)) { continue; //找不到該課程。 } ScoreItem subject = new ScoreItem(course.Subject.Trim(), ScoreType.Subject); ScoreItem domain = new ScoreItem(course.Domain.Trim(), ScoreType.Domain); //--- Subject ProcessSubject(subject, student, take); //--- Domain ProcessDomain(domainscores, take, course, student, subject, domain); } foreach (KeyValuePair <string, DomainScoreCalculator> eachStudent in domainscores) { string studentId = eachStudent.Key; //學生編號。 DomainScoreCalculator calculator = eachStudent.Value; //領域成績。 foreach (DomainScore eachDomain in calculator.Domains) { dicstuds[studentId].Scores[ScoreType.Domain.Regulation(Token)].Add(eachDomain.Name, eachDomain.GetScore()); } } }
private Dictionary <string, JHSCAttendRecord> ReadCurrentSemesterAttend() { Reporter.Feedback("讀取修課資料...", 0); List <string> studKeys = Students.Values.ToKeys(); Dictionary <string, JHSCAttendRecord> currentAttends = new Dictionary <string, JHSCAttendRecord>(); //分批取得資料。 FunctionSpliter <string, JHSCAttendRecord> spliter = new FunctionSpliter <string, JHSCAttendRecord>(300, Util.MaxThread); spliter.Function = delegate(List <string> studKeysPart) { return(JHSCAttend.SelectByStudentIDs(studKeysPart)); }; spliter.ProgressChange = delegate(int progress) { Reporter.Feedback("讀取修課資料...", Util.CalculatePercentage(studKeys.Count, progress)); }; List <JHSCAttendRecord> allAttends = spliter.Execute(studKeys); //用於檢查重覆修習科目。 //Dictionary<string, Dictionary<string, string>> duplicate = new Dictionary<string, Dictionary<string, string>>(); //過濾修課記錄的學年度、學期,只要本學期的成績。 foreach (JHSCAttendRecord each in allAttends) { if (!Courses.ContainsKey(each.RefCourseID)) { continue; } JHCourseRecord course = Courses[each.RefCourseID]; if (!course.SchoolYear.HasValue) { continue; } if (!course.Semester.HasValue) { continue; } if (course.SchoolYear.Value != SchoolYear) { continue; } if (course.Semester.Value != Semester) { continue; } currentAttends.Add(each.ID, each); //// 2016/5/25 穎驊新增 ,只有在該科目需要列入計算才更進一步加到currentAttends,如此一來可以濾掉科目名稱為空的社團課(不列入計算的課) //if (each.Course.CalculationFlag == "1") //{ // #region 檢查重覆修習科目。 // if (!duplicate.ContainsKey(each.RefStudentID)) // duplicate.Add(each.RefStudentID, new Dictionary<string, string>()); // if (duplicate[each.RefStudentID].ContainsKey(course.Subject.Trim())) // { // if (!Students.ContainsKey(each.RefStudentID)) continue; // StudentScore student = Students[each.RefStudentID]; // // 2016/5/25 穎驊新增,針對如果同一學生同一學期有修習同一門科目名稱的課,會跳出視窗提醒。 // MessageBox.Show(string.Format("學生「{0}」在「{1}」學年「{2}」學期,重覆修習科目「{3}」,將使學期科目成績計算遺漏誤植,請確認並修正該科目。", student.Name, course.SchoolYear, course.Semester, course.Subject)); // break; // //throw new ArgumentException(string.Format("學生「{0}」重覆修習科目「{1}」。", student.Name, course.Subject)); // //continue; //先略過不管。 // } // duplicate[each.RefStudentID].Add(course.Subject.Trim(), null); // #endregion; // currentAttends.Add(each.ID, each); //} } return(currentAttends); }
public void Save() { List <JHSemesterScoreRecord> addSemsScore = new List <JHSemesterScoreRecord>(); List <JHSemesterScoreRecord> updateSemsScore = new List <JHSemesterScoreRecord>(); SubjectScoreLogFormater subjLogFormater = new SubjectScoreLogFormater(); DomainScoreLogFormater domainLogFormater = new DomainScoreLogFormater(); foreach (StudentScore student in Students) { #region 決定要新增還是更新。 JHSemesterScoreRecord JHScore = GetJHSemesterScore(student.Id, student.SemestersScore[SemesterData.Empty]); SCSemsScore SCScore = student.SemestersScore[SemesterData.Empty]; if (string.IsNullOrEmpty(JHScore.ID)) { addSemsScore.Add(JHScore); } else { updateSemsScore.Add(JHScore); } #endregion #region 產生科目資料。 JHScore.Subjects.Clear(); foreach (string strSubject in SCScore.Subject) { SemesterSubjectScore objSCSubject = SCScore.Subject[strSubject]; SubjectScore objJHSubject = GetJHSubjectScore(strSubject, objSCSubject); LogData subjLog = new LogData(strSubject); subjLog.Formater = subjLogFormater; decimal?score = objSCSubject.Value.HasValue ? (decimal?)(double)objSCSubject.Value : null; //記錄 Log subjLog.Add(new LogData("成績", objJHSubject.Score + "", score.ToString())); subjLog.Add(new LogData("權重", objJHSubject.Credit + "", objSCSubject.Weight + "")); subjLog.Add(new LogData("節數", objJHSubject.Period + "", objSCSubject.Period + "")); if (Program.Mode == ModuleMode.KaoHsiung) { subjLog.Add(new LogData("努力程度", objJHSubject.Effort + "", objSCSubject.Effort + "")); } subjLog.Add(new LogData("文字評量", objJHSubject.Text + "", objSCSubject.Text)); subjLog.Add(new LogData("領域", objJHSubject.Domain + "", objSCSubject.Domain)); SCScore.Subject.Log.Add(subjLog); objJHSubject.Score = score; objJHSubject.Credit = objSCSubject.Weight; objJHSubject.Period = objSCSubject.Period; objJHSubject.Effort = objSCSubject.Effort; objJHSubject.Text = objSCSubject.Text; objJHSubject.Domain = objSCSubject.Domain; JHScore.Subjects.Add(strSubject, objJHSubject); } //排序科目名稱。 Dictionary <string, SubjectScore> orderSubject = new Dictionary <string, SubjectScore>(JHScore.Subjects); JHScore.Subjects.Clear(); foreach (string subjName in Util.SortSubjectDomain(orderSubject.Keys)) { JHScore.Subjects.Add(subjName, orderSubject[subjName]); } #endregion #region 產生領域資料。 JHScore.Domains.Clear(); foreach (string strDomain in SCScore.Domain) { //彈性課程不記錄領域領域。 if (Util.IsVariableDomain(strDomain)) { continue; } SemesterDomainScore objSCDomain = SCScore.Domain[strDomain]; DomainScore objJHDomain = GetJHDomainScore(strDomain, objSCDomain); LogData domainLog = new LogData(strDomain); domainLog.Formater = subjLogFormater; decimal?score = objSCDomain.Value.HasValue ? (decimal?)(double)objSCDomain.Value : null; //記錄 Log domainLog.Add(new LogData("成績", objJHDomain.Score + "", score + "")); domainLog.Add(new LogData("權重", objJHDomain.Credit + "", objSCDomain.Weight + "")); domainLog.Add(new LogData("節數", objJHDomain.Period + "", objSCDomain.Period + "")); if (Program.Mode == ModuleMode.KaoHsiung) { domainLog.Add(new LogData("努力程度", objJHDomain.Effort + "", objSCDomain.Effort + "")); } domainLog.Add(new LogData("文字評量", objJHDomain.Text + "", objSCDomain.Text)); SCScore.Domain.Log.Add(domainLog); objJHDomain.Score = score; objJHDomain.Credit = objSCDomain.Weight; objJHDomain.Period = objSCDomain.Period; objJHDomain.Effort = objSCDomain.Effort; objJHDomain.Text = objSCDomain.Text; JHScore.Domains.Add(strDomain, objJHDomain); } //記錄 Log SCScore.LearningLog.Formater = domainLogFormater; SCScore.LearningLog.OriginValue = JHScore.CourseLearnScore + ""; SCScore.LearningLog.NewValue = SCScore.LearnDomainScore + ""; SCScore.CourseLog.Formater = domainLogFormater; SCScore.CourseLog.OriginValue = JHScore.CourseLearnScore + ""; SCScore.CourseLog.NewValue = SCScore.CourseLearnScore + ""; JHScore.LearnDomainScore = SCScore.LearnDomainScore; JHScore.CourseLearnScore = SCScore.CourseLearnScore; //排序領域名稱。 Dictionary <string, DomainScore> orderDomain = new Dictionary <string, DomainScore>(JHScore.Domains); JHScore.Domains.Clear(); foreach (string domainName in Util.SortSubjectDomain(orderDomain.Keys)) { JHScore.Domains.Add(domainName, orderDomain[domainName]); } #endregion } #region 新增科目成績 FunctionSpliter <JHSemesterScoreRecord, JHSemesterScoreRecord> addSpliter = new FunctionSpliter <JHSemesterScoreRecord, JHSemesterScoreRecord>(500, 5); addSpliter.Function = delegate(List <JHSemesterScoreRecord> part) { // 加入檢查當科目與領域成績筆數0不新增 List <JHSemesterScoreRecord> insertPart = new List <JHSemesterScoreRecord> (); foreach (JHSemesterScoreRecord rec in part) { // 沒有任何領域或科目成績 if (rec.Domains.Count == 0 && rec.Subjects.Count == 0) { continue; } insertPart.Add(rec); } if (insertPart.Count > 0) { JHSemesterScore.Insert(insertPart); } return(new List <JHSemesterScoreRecord>()); }; addSpliter.ProgressChange = delegate(int progress) { Reporter.Feedback("新增科目成績...", Util.CalculatePercentage(addSemsScore.Count, progress)); }; addSpliter.Execute(addSemsScore); #endregion #region 更新科目成績 FunctionSpliter <JHSemesterScoreRecord, JHSemesterScoreRecord> updateSpliter = new FunctionSpliter <JHSemesterScoreRecord, JHSemesterScoreRecord>(500, 5); updateSpliter.Function = delegate(List <JHSemesterScoreRecord> part) { JHSemesterScore.Update(part); return(new List <JHSemesterScoreRecord>()); }; updateSpliter.ProgressChange = delegate(int progress) { Reporter.Feedback("更新科目成績...", Util.CalculatePercentage(updateSemsScore.Count, progress)); }; updateSpliter.Execute(updateSemsScore); #endregion }
/// <summary> /// 開始匯入 /// </summary> private void StartImport() { mImportWizard.Prepare(mImportOption); List<string> Result = new List<string>(); #region 已由Validator提供 //要匯入的IRowStream列表 List<IRowStream> Rows = mValidatedInfo.ValidatedPairs[0].Rows; pgImport.Maximum = Rows.Count; #endregion #region 實際執行匯入動作 if (mImportWizard.IsSplit) { try { FunctionSpliter<IRowStream, string> Spliter = new FunctionSpliter<IRowStream, string>(mImportWizard.SplitSize, mImportWizard.SplitThreadCount); Spliter.Function = ExecuteImport; //指定Spliter的執行函式 BackgroundWorker workder = new BackgroundWorker(); workder.DoWork += (sender, e) => e.Result = Spliter.Execute(Rows); workder.RunWorkerCompleted += (sender, e) => { CompleteImport((List<string>)e.Result); }; //Spliter.ProgressChange = x => Invoke(new Action(() => pgImport.Value = x)); workder.RunWorkerAsync(); } catch (Exception e) { MessageBox.Show("匯入過程中發生錯誤,以下為詳細訊息:"+System.Environment.NewLine+e.Message); //SmartSchool.ErrorReporting.ReportingService.ReportException(e); this.Close(); this.Dispose(); this.NextButtonEnabled = true; return; } } else { #region 重新讀取Rows //Rows = new List<IRowStream>(); ////建立SheetRowSource物件,用來讀取Excel上的資料 //SheetRowSource RowSource = new SheetRowSource(mValidatedInfo.ResultHelper); //int FirstDataRowIndex = mValidatedInfo.ResultHelper.FirstDataRowIndex; //int MaxDataRowIndex = mValidatedInfo.ResultHelper.MaxDataRowIndex; ////將所有的SheetRowSource物件複製一份並放到IRowStream列表中 //for (int i = FirstDataRowIndex; i <= MaxDataRowIndex; i++) //{ // RowSource.BindRow(i); //將SheetRowSource指定到某列 // RowStream RowStream = RowSource.Clone() as RowStream; //將SheetRowSource目前所指向的內容複製 // Rows.Add(RowStream); //將RowStream加入到集合中 //} #endregion try { //Result = ExecuteImport(Rows); //CompleteImport(Result); // 核心機制修正後再改用下列程式: BackgroundWorker workder = new BackgroundWorker(); workder.DoWork += (sender, e) => e.Result = ExecuteImport(Rows); workder.RunWorkerCompleted += (sender, e) => { CompleteImport((List<string>)e.Result); }; workder.RunWorkerAsync(); } catch (Exception e) { MessageBox.Show("匯入過程中發生錯誤,以下為詳細訊息:" + System.Environment.NewLine + e.Message); //SmartSchool.ErrorReporting.ReportingService.ReportException(e); this.Close(); this.Dispose(); this.NextButtonEnabled = true; return; } } #endregion }
/// <summary> /// 开始汇入 /// </summary> private void StartImport() { mImportWizard.Prepare(mImportOption); List<string> Result = new List<string>(); #region 已由Validator提供 //要汇入的IRowStream列表 List<IRowStream> Rows = mValidatedInfo.ValidatedPairs[0].Rows; pgImport.Maximum = Rows.Count; #endregion #region 实际执行汇入动作 if (mImportWizard.IsSplit) { try { FunctionSpliter<IRowStream, string> Spliter = new FunctionSpliter<IRowStream, string>(mImportWizard.SplitSize, mImportWizard.SplitThreadCount); Spliter.Function = ExecuteImport; //指定Spliter的执行函式 BackgroundWorker workder = new BackgroundWorker(); workder.DoWork += (sender, e) => e.Result = Spliter.Execute(Rows); workder.RunWorkerCompleted += (sender, e) => CompleteImport((List<string>)e.Result); Spliter.ProgressChange = x => Invoke(new Action(() => pgImport.Value = x)); workder.RunWorkerAsync(); } catch (Exception e) { MessageBox.Show("汇入过程中发生错误,以下为详细讯息:" + System.Environment.NewLine + e.Message); SmartSchool.ErrorReporting.ReportingService.ReportException(e); this.Close(); this.Dispose(); return; } } else { #region 重新读取Rows //Rows = new List<IRowStream>(); ////建立SheetRowSource对象,用来读取Excel上的数据 //SheetRowSource RowSource = new SheetRowSource(mValidatedInfo.ResultHelper); //int FirstDataRowIndex = mValidatedInfo.ResultHelper.FirstDataRowIndex; //int MaxDataRowIndex = mValidatedInfo.ResultHelper.MaxDataRowIndex; ////将所有的SheetRowSource对象复制一份并放到IRowStream列表中 //for (int i = FirstDataRowIndex; i <= MaxDataRowIndex; i++) //{ // RowSource.BindRow(i); //将SheetRowSource指定到某列 // RowStream RowStream = RowSource.Clone() as RowStream; //将SheetRowSource目前所指向的内容复制 // Rows.Add(RowStream); //将RowStream加入到集合中 //} #endregion try { mImportWizard.PropertyChanged += (sender, e) => { if (e.PropertyName.Equals("ImportProgress")) Invoke(new Action(() => pgImport.Value = mImportWizard.ImportProgress)); }; Result = ExecuteImport(Rows); CompleteImport(Result); } catch (Exception e) { MessageBox.Show("汇入过程中发生错误,以下为详细讯息:" + System.Environment.NewLine + e.Message); SmartSchool.ErrorReporting.ReportingService.ReportException(e); this.Close(); this.Dispose(); return; } } #endregion }
private Dictionary <string, JHSCAttendRecord> ReadCurrentSemesterAttend() { Reporter.Feedback("讀取修課資料...", 0); List <string> studKeys = Students.Values.ToKeys(); Dictionary <string, JHSCAttendRecord> currentAttends = new Dictionary <string, JHSCAttendRecord>(); //分批取得資料。 FunctionSpliter <string, JHSCAttendRecord> spliter = new FunctionSpliter <string, JHSCAttendRecord>(300, Util.MaxThread); spliter.Function = delegate(List <string> studKeysPart) { return(JHSCAttend.SelectByStudentIDs(studKeysPart)); }; spliter.ProgressChange = delegate(int progress) { Reporter.Feedback("讀取修課資料...", Util.CalculatePercentage(studKeys.Count, progress)); }; List <JHSCAttendRecord> allAttends = spliter.Execute(studKeys); //用於檢查重覆修習科目。 Dictionary <string, Dictionary <string, string> > duplicate = new Dictionary <string, Dictionary <string, string> >(); //過濾修課記錄的學年度、學期,只要本學期的成績。 foreach (JHSCAttendRecord each in allAttends) { if (!Courses.ContainsKey(each.RefCourseID)) { continue; } JHCourseRecord course = Courses[each.RefCourseID]; if (!course.SchoolYear.HasValue) { continue; } if (!course.Semester.HasValue) { continue; } if (course.SchoolYear.Value != SchoolYear) { continue; } if (course.Semester.Value != Semester) { continue; } #region 檢查重覆修習科目。 if (!duplicate.ContainsKey(each.RefStudentID)) { duplicate.Add(each.RefStudentID, new Dictionary <string, string>()); } if (duplicate[each.RefStudentID].ContainsKey(course.Subject.Trim())) { if (!Students.ContainsKey(each.RefStudentID)) { continue; } StudentScore student = Students[each.RefStudentID]; //throw new ArgumentException(string.Format("學生「{0}」重覆修習科目「{1}」。", student.Name, course.Subject)); continue; //先略過不管。 } duplicate[each.RefStudentID].Add(course.Subject.Trim(), null); #endregion ; currentAttends.Add(each.ID, each); } return(currentAttends); }