void _wbWork_DoWork(object sender, DoWorkEventArgs e) { // 取得學生類別完整名稱 _StudentTypeList = DALTransfer.GetStudTypeConfigFullNameList(); // 取得特種身分名稱 _JoinStudSpceTypeList = DALTransfer.GetJoinStudSpecTypeName(); }
/// <summary> /// 將學生編號轉換成 SCStudent 物件。 /// </summary> /// <remarks>使用指定的學生編號,向 DAL 取得 VO 後轉換成 SCStudent 物件。</remarks> public static List <ReportStudent> ToReportStudent(this IEnumerable <string> studentIDs) { List <string> StudentIDList = new List <string>(); List <ReportStudent> students = new List <ReportStudent>(); foreach (JHStudentRecord each in JHStudent.SelectByIDs(studentIDs)) { StudentIDList.Add(each.ID); students.Add(new ReportStudent(each)); } // 取得學生類別List List <StudentTagRecord> StudTagRecList = StudentTag.SelectByStudentIDs(StudentIDList); // 取得特種身分學生,加分比 Dictionary <string, decimal> StudAddWeightDict = DALTransfer.GetStudentAddWeightFormUDTByStudentTag(StudTagRecList, DALTransfer.SchoolType.高中); // 取得特種身分學生名稱 Dictionary <string, string> StudSpecTypeDict = DALTransfer.GetStudentSpcTypeFormUDTByStudentTag(StudTagRecList, DALTransfer.SchoolType.高中); Dictionary <string, K12.Data.UpdateRecordRecord> studUpdateRec = DALTransfer.GetStudentUpdareDate3ByStudentID(StudentIDList); foreach (ReportStudent rs in students) { // 加分比 if (StudAddWeightDict.ContainsKey(rs.StudentID)) { rs.AddWeight = StudAddWeightDict[rs.StudentID]; } // 學生身分 if (StudSpecTypeDict.ContainsKey(rs.StudentID)) { rs.SpcStudTypeName = StudSpecTypeDict[rs.StudentID]; } // 轉入學生異動 if (studUpdateRec.ContainsKey(rs.StudentID)) { if (studUpdateRec[rs.StudentID] != null) { DateTime dt; if (DateTime.TryParse(studUpdateRec[rs.StudentID].UpdateDate, out dt)) { rs.TransUpdateDateStr = (dt.Year - 1911).ToString() + "/" + dt.Month + "/" + dt.Day; } else { rs.TransUpdateDateStr = ""; } rs.LastEnterSchoolyear = studUpdateRec[rs.StudentID].SchoolYear; rs.LastEnterSemester = studUpdateRec[rs.StudentID].Semester; int gr; if (int.TryParse(studUpdateRec[rs.StudentID].GradeYear, out gr)) { rs.LastEnterGradeYear = gr; } } } } return(students); }
private void MasterWorker_DoWork(object sender, DoWorkEventArgs e) { StudentScore.SetClassMapping(); // 取得學生類別List // List<K12.Data.StudentTagRecord> StudTagRecList = K12.Data.StudentTag.SelectByStudentIDs(StudentIDs); List <K12.Data.StudentTagRecord> StudTagRecList = K12.Data.StudentTag.SelectAll(); // 過濾不排學生ID List <string> NonStudentIDList = DALTransfer.GetNonRankStudentIDFromUDTByStudentTag(StudTagRecList, DALTransfer.SchoolType.高中); foreach (string id in NonStudentIDList) { if (StudentIDs.Contains(id)) { StudentIDs.Remove(id); } } PrintStudents = StudentIDs.ToReportStudent(); if (Preference.PrintRank || Preference.PrintRankPercentage || Preference.FilterRankScope) { #region 如果要排名。 //List<ReportStudent> RatingStudents = Util.GetAllStudents(); List <ReportStudent> RatingStudents = Util.GetStudentsDef(NonStudentIDList); RatingStudents.ToSC().ReadSemesterScore(this); RatingStudents.ToSC().ReadSemesterHistory(this); List <IScoreParser <ReportStudent> > parsers = new List <IScoreParser <ReportStudent> >(); List <SLearningDomainParser> allsems = new List <SLearningDomainParser>(); parsers.Add(new LearningDomainParser(Preference.PrintSemesters)); allsems.Add(new SLearningDomainParser(1, 1)); allsems.Add(new SLearningDomainParser(1, 2)); allsems.Add(new SLearningDomainParser(2, 1)); allsems.Add(new SLearningDomainParser(2, 2)); allsems.Add(new SLearningDomainParser(3, 1)); allsems.Add(new SLearningDomainParser(3, 2)); allsems.Add(new SLearningDomainParser(7, 1)); allsems.Add(new SLearningDomainParser(7, 2)); allsems.Add(new SLearningDomainParser(8, 1)); allsems.Add(new SLearningDomainParser(8, 2)); allsems.Add(new SLearningDomainParser(9, 1)); allsems.Add(new SLearningDomainParser(9, 2)); foreach (SLearningDomainParser each in allsems) { parsers.Add(each); } // 將學生加入年排名 List <RatingScope <ReportStudent> > scopes = RatingStudents.ToGradeYearScopes(); foreach (RatingScope <ReportStudent> each in scopes) { foreach (IScoreParser <ReportStudent> parser in parsers) { each.Rank(parser, PlaceOptions.Unsequence); } } Dictionary <string, StudentScore> DicPrintStudents = PrintStudents.ToSC().ToDictionary(); foreach (ReportStudent each in RatingStudents) { if (DicPrintStudents.ContainsKey(each.Id)) { DicPrintStudents[each.Id] = each; } //each.Places["學習領域"].Percentage //each.Places["學習領域"].GetPercentage(); //each.Places["學習領域"].Score } // 整理全部學生年排名 DALTransfer.StudRankScoreDict.Clear(); // 建立Key foreach (RatingScope <ReportStudent> scope in scopes) { DALTransfer.StudRankScoreDict.Add(scope.Name, new Dictionary <string, List <StudRankScore> >()); DALTransfer.StudRankScoreDict[scope.Name].Add("學期總平均", new List <StudRankScore>()); foreach (SLearningDomainParser semsIndex in allsems) { DALTransfer.StudRankScoreDict[scope.Name].Add(semsIndex.Name, new List <StudRankScore>()); } } foreach (RatingScope <ReportStudent> scope in scopes) { // 學習領域 foreach (ReportStudent stud in (from xx in scope where xx.Places.NS("年排名").Contains("學習領域") select xx).ToList()) { StudRankScore srs = new StudRankScore(); srs.StudentID = stud.StudentID; srs.Place = stud.Places.NS("年排名")["學習領域"]; DALTransfer.StudRankScoreDict[scope.Name]["學期總平均"].Add(srs); } foreach (SLearningDomainParser semsIndex in allsems) { foreach (ReportStudent stud in (from xx in scope where xx.Places.NS("年排名").Contains(semsIndex.Name) select xx).ToList()) { StudRankScore srs = new StudRankScore(); srs.StudentID = stud.StudentID; srs.Place = stud.Places.NS("年排名")[semsIndex.Name]; DALTransfer.StudRankScoreDict[scope.Name][semsIndex.Name].Add(srs); } } } #region 註解掉的程式 //foreach (ReportStudent stud in RatingStudents) //{ //----------------- //foreach (RatingScope<ReportStudent> scope in scopes) //{ // if (!DALTransfer.StudRankScoreDict.ContainsKey(scope.Name)) // DALTransfer.StudRankScoreDict.Add(scope.Name, new Dictionary<string, List<StudRankScore>>()); // foreach (ReportStudent stud in scope) // { // // 學期總平均 // if (stud.Places.NS("年排名").Contains("學習領域")) // { // StudRankScore srs = new StudRankScore(); // srs.StudentID = stud.StudentID; // srs.Place = stud.Places.NS("年排名")["學習領域"]; // if (DALTransfer.StudRankScoreDict[scope.Name].ContainsKey("學期總平均")) // { // DALTransfer.StudRankScoreDict[scope.Name]["學期總平均"].Add(srs); // } // else // { // List<StudRankScore> srsList = new List<StudRankScore>(); // srsList.Add(srs); // DALTransfer.StudRankScoreDict[scope.Name].Add("學期總平均", srsList); // } // } // foreach (SLearningDomainParser semsIndex in allsems) // { // if (stud.Places.NS("年排名").Contains(semsIndex.Name)) // { // StudRankScore srs = new StudRankScore(); // srs.StudentID = stud.StudentID; // srs.Place = stud.Places.NS("年排名")[semsIndex.Name]; // if (DALTransfer.StudRankScoreDict[scope.Name].ContainsKey(semsIndex.Name)) // { // DALTransfer.StudRankScoreDict[scope.Name][semsIndex.Name].Add(srs); // } // else // { // List<StudRankScore> srsList = new List<StudRankScore>(); // srsList.Add(srs); // DALTransfer.StudRankScoreDict[scope.Name].Add(semsIndex.Name, srsList); // } // } // } // } //} //------------------------------------ //} //// 排序對照年排名資料 debug 用 //for (int i = 1; i <= 9; i++) //{ // if (DALTransfer.StudRankScoreDict.ContainsKey(i.ToString())) // { // string idx = i.ToString(); // foreach (SLearningDomainParser semsIndex in allsems) // { // if (DALTransfer.StudRankScoreDict[idx].ContainsKey(semsIndex.Name)) // { // var x = from xx in DALTransfer.StudRankScoreDict[idx][semsIndex.Name] orderby xx.Place.Score descending select xx; // DALTransfer.StudRankScoreDict[idx][semsIndex.Name] = x.ToList(); // } // } // } //} #endregion #region Debug 用區斷 Workbook wb = new Workbook(); Dictionary <string, ReportStudent> students = RatingStudents.ToDictionary(x => x.Id); int wstCot = 0; // 排序對照年排名資料 debug 用 foreach (RatingScope <ReportStudent> scope in scopes) { if (DALTransfer.StudRankScoreDict.ContainsKey(scope.Name)) { string idx = scope.Name; string AvggName = "學期總平均"; if (DALTransfer.StudRankScoreDict[idx].ContainsKey(AvggName)) { int row = 1; wb.Worksheets.Add(); wb.Worksheets[wstCot].Name = idx + AvggName; wb.Worksheets[wstCot].Cells[0, 0].PutValue("成績"); wb.Worksheets[wstCot].Cells[0, 1].PutValue("年排名"); wb.Worksheets[wstCot].Cells[0, 2].PutValue("分類"); wb.Worksheets[wstCot].Cells[0, 3].PutValue("年級"); wb.Worksheets[wstCot].Cells[0, 4].PutValue("SID"); wb.Worksheets[wstCot].Cells[0, 5].PutValue("StudCount"); foreach (StudRankScore xx in DALTransfer.StudRankScoreDict[idx][AvggName].OrderByDescending(x => x.Place.Score)) { wb.Worksheets[wstCot].Cells[row, 0].PutValue(xx.Place.Score); wb.Worksheets[wstCot].Cells[row, 1].PutValue(xx.Place.Percentage); wb.Worksheets[wstCot].Cells[row, 2].PutValue(AvggName); wb.Worksheets[wstCot].Cells[row, 3].PutValue(idx); wb.Worksheets[wstCot].Cells[row, 4].PutValue(xx.StudentID); wb.Worksheets[wstCot].Cells[row, 5].PutValue(xx.Place.Radix); wb.Worksheets[wstCot].Cells[row, 6].PutValue(students[xx.StudentID].GradeYear); row++; } wstCot++; } foreach (SLearningDomainParser semsIndex in allsems) { int row = 1; wb.Worksheets.Add(); wb.Worksheets[wstCot].Name = idx + semsIndex.Name.Replace(":", "-"); wb.Worksheets[wstCot].Cells[0, 0].PutValue("成績"); wb.Worksheets[wstCot].Cells[0, 1].PutValue("年排名"); wb.Worksheets[wstCot].Cells[0, 2].PutValue("分類"); wb.Worksheets[wstCot].Cells[0, 3].PutValue("年級"); wb.Worksheets[wstCot].Cells[0, 4].PutValue("SID"); wb.Worksheets[wstCot].Cells[0, 5].PutValue("StudCount"); if (DALTransfer.StudRankScoreDict[idx].ContainsKey(semsIndex.Name)) { foreach (StudRankScore xx in DALTransfer.StudRankScoreDict[idx][semsIndex.Name].OrderByDescending(x => x.Place.Score)) { wb.Worksheets[wstCot].Cells[row, 0].PutValue(xx.Place.Score); wb.Worksheets[wstCot].Cells[row, 1].PutValue(xx.Place.Percentage); wb.Worksheets[wstCot].Cells[row, 2].PutValue(semsIndex.Name); wb.Worksheets[wstCot].Cells[row, 3].PutValue(semsIndex.Grade); wb.Worksheets[wstCot].Cells[row, 4].PutValue(xx.StudentID); wb.Worksheets[wstCot].Cells[row, 5].PutValue(xx.Place.Radix); wb.Worksheets[wstCot].Cells[row, 6].PutValue(students[xx.StudentID].GradeYear); row++; } } wstCot++; } } } for (int i = 0; i < wb.Worksheets.Count; i++) { if (wb.Worksheets[i].Cells.MaxDataRow < 2) { wb.Worksheets.RemoveAt(i); } } try { wb.Save(Application.StartupPath + "\\樂學成績debug.xls", FileFormatType.Excel2003); // System.Diagnostics.Process.Start(Application.StartupPath + "\\樂學成績debug.xls"); } catch (Exception ex) { } #endregion if (Preference.FilterRankScope) { List <ReportStudent> filteredStudent = new List <ReportStudent>(); foreach (ReportStudent each in DicPrintStudents.Values.ToSS()) { //看是否有「學習領域」的年排名。 if (each.Places.NS("年排名").Contains(LearningDomainParser.PlaceName)) { Place place = each.Places.NS("年排名")[LearningDomainParser.PlaceName]; if (place.Level >= Preference.RankStart && place.Level <= Preference.RankEnd) { filteredStudent.Add(each); } } PrintStudents = filteredStudent; } } else { PrintStudents = new List <ReportStudent>(DicPrintStudents.Values.ToSS()); } #endregion } else { PrintStudents.ToSC().ReadSemesterScore(this); PrintStudents.ToSC().ReadSemesterHistory(this); } List <StudentScore> CalcStudents; if (PrintStudents.Count <= 0) { Feedback("", -1); //把 Status bar Reset... throw new ArgumentException("沒有任何學生資料可列印。"); } else { CalcStudents = PrintStudents.ToSC(); CalcStudents.ReadCalculationRule(this); //讀取成績計算規則。 #region 讀取缺曠獎懲。 //List<JHMoralScoreRecord> jhmorals = JHSchool.Data.JHMoralScore.SelectByStudentIDs(StudentIDs); List <AutoSummaryRecord> jhsummary = AutoSummary.Select(StudentIDs, null); Dictionary <string, ReportStudent> DicStudents = PrintStudents.ToDictionary(); //foreach (JHMoralScoreRecord each in jhmorals) foreach (AutoSummaryRecord each in jhsummary) { if (!DicStudents.ContainsKey(each.RefStudentID)) { continue; } SemesterData semester = new SemesterData(0, each.SchoolYear, each.Semester); ReportStudent student = DicStudents[each.RefStudentID]; if (!student.Summaries.ContainsKey(semester)) { student.Summaries.Add(semester, each.AutoSummary); } } #endregion PrintStudents.ReadUpdateRecordDate(this); e.Result = new Report(PrintStudents, Preference).Print(); e_For_ConvertToPDF_Worker = e; Feedback("列印完成", -1); } }