public decimal?GetScore(ReportStudent student) { SemesterScore score = null; foreach (SemesterData each in student.SHistory.GetGradeYearSemester()) { SemesterData gysemester = new SemesterData(each.GradeYear, 0, each.Semester); if (gysemester == Semester) { SemesterData sd = new SemesterData(0, each.SchoolYear, each.Semester); if (student.SemestersScore.Contains(sd)) { score = student.SemestersScore[sd]; } break; } } if (score == null) { return(null); } else { return(score.LearnDomainScore); } }
/// <summary> /// 根據科目前置名稱計算領域成績及權重 /// </summary> /// <param name="Score"></param> /// <param name="StartName"></param> /// <returns></returns> public static Tuple <decimal, decimal, decimal> GetDomainScoreFromSubject(this SemesterScore Score, string StartName) { decimal resultTotal = 0; decimal resultWeight = 0; decimal resultAverage = 0; foreach (string subject in Score.Subject) { if (Program.Mode == ModuleMode.HsinChu) { if (subject.IndexOf(StartName) > -1 && Score.RawScore.Subjects[subject].Domain.Equals("語文")) { if (Score.Subject[subject].Value.HasValue && Score.Subject[subject].Weight.HasValue) { resultTotal += Score.Subject[subject].Value.Value * Score.Subject[subject].Weight.Value; resultWeight += Score.Subject[subject].Weight.Value; } } } } if (resultWeight > 0) { resultAverage = Math.Round(resultTotal / resultWeight, 2, MidpointRounding.AwayFromZero); } //傳回領域成績,以及此領域的權重 return(new Tuple <decimal, decimal, decimal>(resultAverage, resultWeight, Math.Round(resultTotal, 2, MidpointRounding.AwayFromZero))); }
/// <summary> /// 計算學習領域成績 /// </summary> /// <param name="defaultRule"></param> public void CalculateLearningDomainScore(ScoreCalculator defaultRule) { foreach (StudentScore student in Students) { SemesterScore semsscore = student.SemestersScore[SemesterData.Empty]; SemesterDomainScoreCollection dscores = semsscore.Domain; ScoreCalculator rule = student.CalculationRule; if (rule == null) { rule = defaultRule; } #region 計算各領域加權平均。 //計算學習領域成績。 //decimal? result = CalcDomainWeightAvgScore(dscores, Util.VariableDomains); ScoreResult result = CalcDomainWeightAvgScore(dscores, Util.VariableDomains);; if (result.Score.HasValue) { semsscore.LearnDomainScore = rule.ParseLearnDomainScore(result.Score.Value); } if (result.ScoreOrigin.HasValue) { semsscore.LearnDomainScoreOrigin = rule.ParseLearnDomainScore(result.ScoreOrigin.Value); } #endregion } }
/// <summary> /// 單純從學期科目成績的文字描述加總到學期領域成績的文字描述 /// </summary> /// <param name="defaultRule"></param> public void SumDomainTextScore() { foreach (StudentScore student in Students) { SemesterScore semsscore = student.SemestersScore[SemesterData.Empty]; SemesterDomainScoreCollection dscores = semsscore.Domain; SemesterSubjectScoreCollection jscores = semsscore.Subject; Dictionary <string, string> domainText = new Dictionary <string, string>(); #region 總計各領域的總分、權重、節數。 foreach (string strSubj in jscores) { SemesterSubjectScore objSubj = jscores[strSubj]; string strDomain = objSubj.Domain.Injection(); //不計算的領域就不算。 if (!IsValidItem(strDomain)) { continue; } if (objSubj.Value.HasValue && objSubj.Weight.HasValue && objSubj.Period.HasValue) { if (!domainText.ContainsKey(strDomain)) { domainText.Add(strDomain, string.Empty); } domainText[strDomain] += GetDomainSubjectText(strSubj, objSubj.Text); } } #endregion #region 計算各領域加權平均。 foreach (string strDomain in domainText.Keys) { string text = string.Join(";", domainText[strDomain].Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries)); //將成績更新回學生。 SemesterDomainScore dscore = null; if (dscores.Contains(strDomain)) { dscore = dscores[strDomain]; } else { dscore = new SemesterDomainScore(); dscores.Add(strDomain, dscore); } dscore.Text = text; } #endregion } }
public decimal?GetScore(ReportStudent student) { SemesterScore score = null; foreach (SemesterData each in student.SHistory.GetGradeYearSemester()) { //// 處理轉入生之前不列入排名 //if (student.LastEnterSchoolyear.HasValue && student.LastEnterSemester.HasValue && student.LastEnterGradeYear.HasValue) //{ // if (each.SchoolYear < student.LastEnterSchoolyear.Value) // continue; // else // { // if (each.SchoolYear == student.LastEnterSchoolyear.Value && each.Semester < student.LastEnterSemester.Value) // continue; // } //} SemesterData gysemester = new SemesterData(each.GradeYear, 0, each.Semester); if (gysemester == Semester) { SemesterData sd = new SemesterData(0, each.SchoolYear, each.Semester); if (student.SemestersScore.Contains(sd)) { score = student.SemestersScore[sd]; } break; } } if (score == null) { return(0); } else if (score.LearnDomainScore.HasValue) { return(Math.Round(score.LearnDomainScore.Value, 2, MidpointRounding.AwayFromZero)); // 小數下第3位四捨五入 } else { return(0); } }
private void btnPrint_Click(object sender, EventArgs e) { if (K12.Presentation.NLDPanels.Student.SelectedSource.Count < 1) { FISCA.Presentation.Controls.MsgBox.Show("請先選擇學生"); return; } btnPrint.Enabled = false; filter f = new filter { GradeType = comboBoxEx2.Text }; Document document = new Document(); BackgroundWorker bgw = new BackgroundWorker(); Dictionary <StudentRecord, List <string> > errCheck = new Dictionary <StudentRecord, List <string> >(); bgw.DoWork += delegate { #region DoWork Byte[] template; if (K12.Presentation.NLDPanels.Student.SelectedSource.Count <= 0) { return; } List <string> sids = K12.Presentation.NLDPanels.Student.SelectedSource; Dictionary <string, SemesterHistoryRecord> dshr = SemesterHistory.SelectByStudentIDs(sids).ToDictionary(x => x.RefStudentID, x => x); Dictionary <string, StudentRecord> dsr = Student.SelectByIDs(sids).ToDictionary(x => x.ID, x => x); Dictionary <string, SemesterScoreRecord> dssr = SemesterScore.SelectByStudentIDs(sids).ToDictionary(x => x.RefStudentID + "#" + x.SchoolYear + "#" + x.Semester, x => x); DataTable dt = tool._Q.Select("select ref_student_id,entrance_date,leaving_date from $jhcore_bilingual.studentrecordext where ref_student_id in ('" + string.Join("','", sids) + "')"); Dictionary <string, edld> dedld = new Dictionary <string, edld>(); DateTime tmp; foreach (DataRow row in dt.Rows) { if (!dedld.ContainsKey("" + row["ref_student_id"])) { dedld.Add("" + row["ref_student_id"], new edld() { }); } if (DateTime.TryParse("" + row["entrance_date"], out tmp)) { dedld["" + row["ref_student_id"]].entrance_date = tmp; } if (DateTime.TryParse("" + row["leaving_date"], out tmp)) { dedld["" + row["ref_student_id"]].leaving_date = tmp; } } List <string> gradeYearList; int domainDicKey; switch (f.GradeType) { case "3~6": case "6": gradeYearList = new List <string> { "3", "4", "5", "6" }; domainDicKey = 6; template = (ReportConfiguration3_6.Template != null) //單頁範本 ? ReportConfiguration3_6.Template.ToBinary() : new Campus.Report.ReportTemplate(Properties.Resources._6樣版, Campus.Report.TemplateType.Word).ToBinary(); Choose3to6Grade = true; break; case "7~8": case "8": gradeYearList = new List <string> { "7", "8" }; domainDicKey = 8; template = (ReportConfiguration7_8.Template != null) //單頁範本 ? ReportConfiguration7_8.Template.ToBinary() : new Campus.Report.ReportTemplate(Properties.Resources._8樣版, Campus.Report.TemplateType.Word).ToBinary(); Choose7to8Grade = true; break; case "9~12": case "12": gradeYearList = new List <string> { "9", "10", "11", "12" }; domainDicKey = 12; template = (ReportConfiguration9_12.Template != null) //單頁範本 ? ReportConfiguration9_12.Template.ToBinary() : new Campus.Report.ReportTemplate(Properties.Resources._9_12_grade樣板, Campus.Report.TemplateType.Word).ToBinary(); break; default: return; } List <CourseGradeB.Tool.Domain> cgbdl = CourseGradeB.Tool.DomainDic[domainDicKey]; // 2016/5/18 穎驊新增功能,因原本3~6年級其Domain 並無English、Western Social Studies ,會造成如果沒有成績,而不顯示N/A直接空白的問題 if (Choose3to6Grade) { English.Hours = 6; English.Name = "English"; English.ShortName = "English"; WesternSocialStudies.Hours = 2; WesternSocialStudies.Name = "Western Social Studies"; WesternSocialStudies.ShortName = "W.S.S"; cgbdl.Add(English); cgbdl.Add(WesternSocialStudies); } // 2016/5/20(蔡英文上任)穎驊新增功能,因原本7~8年級其Domain 並無Elective ,會造成如果沒有成績,而不顯示N/A直接空白的問題 if (Choose7to8Grade) { Elective.Hours = 2; Elective.Name = "Elective"; Elective.ShortName = "Elective"; cgbdl.Add(Elective); } cgbdl.Sort(delegate(CourseGradeB.Tool.Domain x, CourseGradeB.Tool.Domain y) { return(x.DisplayOrder.CompareTo(y.DisplayOrder)); }); //int domainCount; Dictionary <string, string> NationalityMapping = K12.EduAdminDataMapping.Utility.GetNationalityMappingDict(); Dictionary <string, object> mailmerge = new Dictionary <string, object>(); GradeCumulateGPA gcgpa = new GradeCumulateGPA(); foreach (var studentID in dshr.Keys) {//學生 System.IO.Stream docStream = new System.IO.MemoryStream(template); Document each = new Document(docStream); //DocumentBuilder db = new DocumentBuilder(each); //Table table = (Table)each.GetChild(NodeType.Table, 1, true); //table.AllowAutoFit = true; //not work,why ? // 2016/4/28 取得樣板上,所有的功能變數,以利以後核對使用。 string[] fieldNames = each.MailMerge.GetFieldNames(); grade lastGrade = null; mailmerge.Clear(); mailmerge.Add("列印日期", DateTime.Today.ToString("MMMM d, yyyy", new System.Globalization.CultureInfo("en-US"))); #region 學生資料 StudentRecord sr = dsr[studentID]; mailmerge.Add("學生系統編號", sr.ID); mailmerge.Add("學號", sr.StudentNumber); mailmerge.Add("姓名", sr.Name); mailmerge.Add("英文名", sr.EnglishName); string gender; switch (sr.Gender) { case "男": gender = "Male"; break; case "女": gender = "Female"; break; default: gender = sr.Gender; break; } mailmerge.Add("性別", gender); mailmerge.Add("國籍", sr.Nationality); if (NationalityMapping.ContainsKey(sr.Nationality)) { mailmerge["國籍"] = NationalityMapping[sr.Nationality]; } mailmerge.Add("生日", sr.Birthday.HasValue ? sr.Birthday.Value.ToString("d-MMMM-yyyy", new System.Globalization.CultureInfo("en-US")) : ""); string esy = "", edog = ""; if (dedld.ContainsKey(studentID)) { if (dedld[studentID].entrance_date != null) { esy = dedld[studentID].entrance_date.Value.ToString("MMMM-yyyy", new System.Globalization.CultureInfo("en-US")); } if (dedld[studentID].leaving_date != null) { edog = dedld[studentID].leaving_date.Value.ToString("MMMM-yyyy", new System.Globalization.CultureInfo("en-US")); } } mailmerge.Add("入學日期", esy); mailmerge.Add("預計畢業日期", edog); //mailmerge.Add("Registrar", row.Value[0].SeatNo); //mailmerge.Add("Dean", row.Value[0].SeatNo); //mailmerge.Add("Principal", row.Value[0].SeatNo); #endregion #region 學生成績 Dictionary <int, grade> dgrade = new Dictionary <int, grade>(); #region 整理學生成績及年級 foreach (SemesterHistoryItem shi in dshr[studentID].SemesterHistoryItems) { if (!gradeYearList.Contains("" + shi.GradeYear)) { continue; } int _gradeYear = shi.GradeYear; string key = shi.RefStudentID + "#" + shi.SchoolYear + "#" + shi.Semester; if (!dgrade.ContainsKey(_gradeYear)) { dgrade.Add(_gradeYear, new grade() { grade_year = shi.GradeYear, school_year = shi.SchoolYear }); } if (shi.Semester == 1) { dgrade[_gradeYear].semester = 1; if (dssr.ContainsKey(key)) { dgrade[_gradeYear].sems1 = dssr[key]; } } else if (shi.Semester == 2) { dgrade[_gradeYear].semester = 2; if (dssr.ContainsKey(key)) { dgrade[_gradeYear].sems2 = dssr[key]; } } } #endregion mailmerge.Add("GPA", ""); int gradeCount = 1; foreach (string gy in gradeYearList) {//級別_ //群 , 科目 , 分數 //Dictionary<string, Dictionary<string, course>> dcl = new Dictionary<string, Dictionary<string, course>>(); Dictionary <string, List <SubjectScore> > dcl = new Dictionary <string, List <SubjectScore> >(); mailmerge.Add(string.Format("級別{0}", gradeCount), gy); mailmerge.Add(string.Format("學年度{0}", gradeCount), ""); if (dgrade.ContainsKey(int.Parse(gy))) { grade g = dgrade[int.Parse(gy)]; mailmerge[string.Format("學年度{0}", gradeCount)] = (g.school_year + 1911) + "-" + (g.school_year + 1912); foreach (var semScore in new SemesterScoreRecord[] { g.sems1, g.sems2 }) { if (semScore != null) { foreach (var subjectScore in semScore.Subjects.Values) { //if (!dcl.ContainsKey(subjectScore.Domain)) // dcl.Add(subjectScore.Domain, new Dictionary<string, course>()); //if (!dcl[subjectScore.Domain].ContainsKey(subjectScore.Subject)) // dcl[subjectScore.Domain].Add(subjectScore.Subject, new course()); //switch (subjectScore.Semester) //{ // case 1: // dcl[subjectScore.Domain][subjectScore.Subject].sems1_title = subjectScore.Subject; // dcl[subjectScore.Domain][subjectScore.Subject].sems1_score = subjectScore.Score.HasValue ? Math.Round(subjectScore.Score.Value, 0, MidpointRounding.AwayFromZero) : 0; // break; // case 2: // dcl[subjectScore.Domain][subjectScore.Subject].sems2_title = subjectScore.Subject; // dcl[subjectScore.Domain][subjectScore.Subject].sems2_score = subjectScore.Score.HasValue ? Math.Round(subjectScore.Score.Value, 0, MidpointRounding.AwayFromZero) : 0; // break; //} if (!dcl.ContainsKey(subjectScore.Domain)) { dcl.Add(subjectScore.Domain, new List <SubjectScore>()); } subjectScore.Score = subjectScore.Score.HasValue ? Math.Round(subjectScore.Score.Value, 0, MidpointRounding.AwayFromZero) : 0; dcl[subjectScore.Domain].Add(subjectScore); } } } //使用學期歷程最後一筆的學年度學期 if (g.sems1 != null) { mailmerge["GPA"] = g.sems1.CumulateGPA; } if (g.sems2 != null) { mailmerge["GPA"] = g.sems2.CumulateGPA; } lastGrade = g; } //檢查預設清單,缺漏處補回空資料 foreach (CourseGradeB.Tool.Domain domain in cgbdl) { //if (!dcl.ContainsKey(domain.Name)) // dcl.Add(domain.Name, new Dictionary<string, course>()); if (!dcl.ContainsKey(domain.Name)) { dcl.Add(domain.Name, new List <SubjectScore>()); } } foreach (var domain in dcl.Keys) { foreach (var semester in new int[] { 1, 2 }) { //群 int courseCount = 1; dcl[domain].Sort((SubjectScore s1, SubjectScore s2) => { return((s1.Subject + " (" + s1.Credit + ")").CompareTo(s2.Subject + " (" + s2.Credit + ")")); }); foreach (var item in dcl[domain]) { if (item.Semester == semester) { mailmerge.Add(string.Format("{0}_級{1}_學期{2}_科目{3}", domain.FixFieldName(), gradeCount, semester, courseCount), item.Subject + " (" + item.Credit + ")"); mailmerge.Add(string.Format("{0}_級{1}_學期{2}_科目級別{3}", domain.FixFieldName(), gradeCount, semester, courseCount), "Level:" + item.Level); mailmerge.Add(string.Format("{0}_級{1}_學期{2}_科目成績{3}", domain.FixFieldName(), gradeCount, semester, courseCount), "" + item.Score); // 2016/4/28 穎驊筆記,下面為檢察功能,fieldName為目前樣板的所有功能變數,假如樣版沒有完整的對應功能變數,會加入錯誤訊息提醒。 if (!fieldNames.Contains(string.Format("{0}_級{1}_學期{2}_科目成績{3}", domain.FixFieldName(), gradeCount, semester, courseCount))) { if (!errCheck.ContainsKey(sr)) { errCheck.Add(sr, new List <string>()); } errCheck[sr].Add("合併欄位「" + string.Format("{0}_級{1}_學期{2}_科目成績{3}", domain.FixFieldName(), gradeCount, semester, courseCount) + "」在樣板中不存在(" + item.SchoolYear + "學年度第" + item.Semester + "學期 科目名稱 " + item.Subject + ")。"); } courseCount++; //mailmerge.Add(string.Format("{0}_級{1}_學期1_科目{2}", domain.FixFieldName(), gradeCount, courseCount), item.sems1_title); //mailmerge.Add(string.Format("{0}_級{1}_學期2_科目{2}", domain.FixFieldName(), gradeCount, courseCount), item.sems2_title); ////都存在且相同才需要合併 //if (item.sems1_title != null && item.sems2_title != null && item.sems1_title == item.sems2_title) //{ // mailmerge[string.Format("{0}_級{1}_學期1_科目{2}", domain.FixFieldName(), gradeCount, courseCount)] = new mailmergeSpecial() { cellmerge = Aspose.Words.Tables.CellMerge.First, value = item.sems1_title }; // mailmerge[string.Format("{0}_級{1}_學期2_科目{2}", domain.FixFieldName(), gradeCount, courseCount)] = new mailmergeSpecial() { cellmerge = Aspose.Words.Tables.CellMerge.Previous, value = item.sems2_title }; //} //mailmerge.Add(string.Format("{0}_級{1}_學期1_科目成績{2}", domain.FixFieldName(), gradeCount, courseCount), // item.sems1_title != null ? "" + item.sems1_score : "N/A"); //mailmerge.Add(string.Format("{0}_級{1}_學期2_科目成績{2}", domain.FixFieldName(), gradeCount, courseCount), // item.sems2_title != null ? "" + item.sems2_score : "N/A"); //courseCount++; } } for (; courseCount <= 3; courseCount++) { mailmerge.Add(string.Format("{0}_級{1}_學期{2}_科目{3}", domain.FixFieldName(), gradeCount, semester, courseCount), ""); mailmerge.Add(string.Format("{0}_級{1}_學期{2}_科目級別{3}", domain.FixFieldName(), gradeCount, semester, courseCount), ""); mailmerge.Add(string.Format("{0}_級{1}_學期{2}_科目成績{3}", domain.FixFieldName(), gradeCount, semester, courseCount), "N/A"); //mailmerge.Add(string.Format("{0}_級{1}_學期1_科目{2}", domain.FixFieldName(), gradeCount, courseCount), new mailmergeSpecial() { cellmerge = Aspose.Words.Tables.CellMerge.First, value = "" }); //mailmerge.Add(string.Format("{0}_級{1}_學期2_科目{2}", domain.FixFieldName(), gradeCount, courseCount), new mailmergeSpecial() { cellmerge = Aspose.Words.Tables.CellMerge.Previous, value = "" }); //mailmerge.Add(string.Format("{0}_級{1}_學期1_科目成績{2}", domain.FixFieldName(), gradeCount, courseCount), "N/A"); //mailmerge.Add(string.Format("{0}_級{1}_學期2_科目成績{2}", domain.FixFieldName(), gradeCount, courseCount), "N/A"); } } for (var courseCount = 1; courseCount <= 3; courseCount++) { var subjName1 = "" + mailmerge[string.Format("{0}_級{1}_學期{2}_科目{3}", domain.FixFieldName(), gradeCount, 1, courseCount)]; var subjName2 = "" + mailmerge[string.Format("{0}_級{1}_學期{2}_科目{3}", domain.FixFieldName(), gradeCount, 2, courseCount)]; if (subjName1 == subjName2 || subjName1 == "" || subjName2 == "") { mailmerge[string.Format("{0}_級{1}_學期1_科目{2}", domain.FixFieldName(), gradeCount, courseCount)] = new mailmergeSpecial() { cellmerge = Aspose.Words.Tables.CellMerge.First, value = subjName1 }; mailmerge[string.Format("{0}_級{1}_學期2_科目{2}", domain.FixFieldName(), gradeCount, courseCount)] = new mailmergeSpecial() { cellmerge = Aspose.Words.Tables.CellMerge.Previous, value = subjName1 }; } if (subjName1 != "" && subjName2 == "") { mailmerge[string.Format("{0}_級{1}_學期1_科目{2}", domain.FixFieldName(), gradeCount, courseCount)] = new mailmergeSpecial() { cellmerge = Aspose.Words.Tables.CellMerge.First, value = subjName1 }; mailmerge[string.Format("{0}_級{1}_學期2_科目{2}", domain.FixFieldName(), gradeCount, courseCount)] = new mailmergeSpecial() { cellmerge = Aspose.Words.Tables.CellMerge.Previous, value = subjName1 }; } if (subjName1 == "" && subjName2 != "") { mailmerge[string.Format("{0}_級{1}_學期1_科目{2}", domain.FixFieldName(), gradeCount, courseCount)] = new mailmergeSpecial() { cellmerge = Aspose.Words.Tables.CellMerge.First, value = subjName2 }; mailmerge[string.Format("{0}_級{1}_學期2_科目{2}", domain.FixFieldName(), gradeCount, courseCount)] = new mailmergeSpecial() { cellmerge = Aspose.Words.Tables.CellMerge.Previous, value = subjName2 }; } var subjLevel1 = "" + mailmerge[string.Format("{0}_級{1}_學期{2}_科目級別{3}", domain.FixFieldName(), gradeCount, 1, courseCount)]; var subjLevel2 = "" + mailmerge[string.Format("{0}_級{1}_學期{2}_科目級別{3}", domain.FixFieldName(), gradeCount, 2, courseCount)]; if (subjLevel1 == subjLevel2) { mailmerge[string.Format("{0}_級{1}_學期1_科目級別{2}", domain.FixFieldName(), gradeCount, courseCount)] = new mailmergeSpecial() { cellmerge = Aspose.Words.Tables.CellMerge.First, value = subjLevel1 }; mailmerge[string.Format("{0}_級{1}_學期2_科目級別{2}", domain.FixFieldName(), gradeCount, courseCount)] = new mailmergeSpecial() { cellmerge = Aspose.Words.Tables.CellMerge.Previous, value = subjLevel1 }; } if (subjLevel1 != "" && subjLevel2 == "") { mailmerge[string.Format("{0}_級{1}_學期1_科目級別{2}", domain.FixFieldName(), gradeCount, courseCount)] = new mailmergeSpecial() { cellmerge = Aspose.Words.Tables.CellMerge.First, value = subjLevel1 }; mailmerge[string.Format("{0}_級{1}_學期2_科目級別{2}", domain.FixFieldName(), gradeCount, courseCount)] = new mailmergeSpecial() { cellmerge = Aspose.Words.Tables.CellMerge.Previous, value = subjLevel1 }; } if (subjLevel1 == "" && subjLevel2 != "") { mailmerge[string.Format("{0}_級{1}_學期1_科目級別{2}", domain.FixFieldName(), gradeCount, courseCount)] = new mailmergeSpecial() { cellmerge = Aspose.Words.Tables.CellMerge.First, value = subjLevel2 }; mailmerge[string.Format("{0}_級{1}_學期2_科目級別{2}", domain.FixFieldName(), gradeCount, courseCount)] = new mailmergeSpecial() { cellmerge = Aspose.Words.Tables.CellMerge.Previous, value = subjLevel2 }; } } } gradeCount++; } GradeCumulateGPARecord gcgpar; mailmerge.Add("級最高GPA", ""); mailmerge.Add("級平均GPA", ""); if (lastGrade != null && sr.Class != null) { //if (lastGrade.semester != null) //{ gcgpar = gcgpa.GetGradeCumulateGPARecord(lastGrade.school_year, lastGrade.semester, lastGrade.grade_year); if (gcgpar != null) { mailmerge["級最高GPA"] = decimal.Round(gcgpar.MaxGPA, 2, MidpointRounding.AwayFromZero); mailmerge["級平均GPA"] = decimal.Round(gcgpar.AvgGPA, 2, MidpointRounding.AwayFromZero); } //} } #endregion // 正式把MailMerge資料 給填上去,2015/4/27 驊紀錄 each.MailMerge.FieldMergingCallback = new MailMerge_MergeField(); each.MailMerge.Execute(mailmerge.Keys.ToArray(), mailmerge.Values.ToArray()); each.MailMerge.DeleteFields(); document.Sections.Add(document.ImportNode(each.FirstSection, true)); //2016/4/28 以下是恩正給穎驊的程式碼,可以輸出本程式MergeField 所有功能變數的縮寫成一個獨立Doc檔 // 在未來如果要要大量更動新增表格很方便可以直接複製貼上使用,如要使用,將上方原本的輸出MergeField、下面的//document.Sections.RemoveAt(0);註解掉即可。 //{ // Document doc = new Document(); // DocumentBuilder bu = new DocumentBuilder(doc); // bu.MoveToDocumentStart(); // bu.CellFormat.Borders.LineStyle = LineStyle.Single; // bu.CellFormat.VerticalAlignment = CellVerticalAlignment.Center; // Table table = bu.StartTable(); // foreach (String col in mailmerge.Keys) // { // bu.InsertCell(); // bu.CellFormat.Width = 15; // bu.InsertField("MERGEFIELD " + col + @" \* MERGEFORMAT", "«.»"); // bu.ParagraphFormat.Alignment = ParagraphAlignment.Center; // bu.InsertCell(); // bu.CellFormat.Width = 125; // bu.Write(col); // bu.ParagraphFormat.Alignment = ParagraphAlignment.Left; // bu.EndRow(); // } // table.AllowAutoFit = false; // bu.EndTable(); // document = doc; // break; //} } document.Sections.RemoveAt(0); #endregion }; bgw.RunWorkerCompleted += delegate { if (errCheck.Count > 0) { StringBuilder sb = new StringBuilder(); foreach (var stuRec in errCheck.Keys) { foreach (var err in errCheck[stuRec]) { sb.AppendLine(string.Format("{0} {1}({2}) {3}:{4}", stuRec.StudentNumber, stuRec.Class != null ? stuRec.Class.Name : "", stuRec.SeatNo, stuRec.Name, err)); } } MessageBox.Show(sb.ToString()); } #region Completed btnPrint.Enabled = true; //if (e.Error != null) //{ // MessageBox.Show(e.Error.Message); // return; //} Document inResult = document; try { SaveFileDialog SaveFileDialog1 = new SaveFileDialog(); SaveFileDialog1.Filter = "Word (*.doc)|*.doc|所有檔案 (*.*)|*.*"; SaveFileDialog1.FileName = "國外成績單"; if (SaveFileDialog1.ShowDialog() == DialogResult.OK) { inResult.Save(SaveFileDialog1.FileName); Process.Start(SaveFileDialog1.FileName); FISCA.Presentation.MotherForm.SetStatusBarMessage(SaveFileDialog1.FileName + ",列印完成!!"); //Update_ePaper ue = new Update_ePaper(new List<Document> { inResult }, current, PrefixStudent.學號); //ue.ShowDialog(); } else { FISCA.Presentation.Controls.MsgBox.Show("檔案未儲存"); return; } } catch (Exception exp) { string msg = "檔案儲存錯誤,請檢查檔案是否開啟中!!"; FISCA.Presentation.Controls.MsgBox.Show(msg + "\n" + exp.Message); FISCA.Presentation.MotherForm.SetStatusBarMessage(msg + "\n" + exp.Message); } #endregion }; bgw.RunWorkerAsync(); }
/// <summary> /// 從學期科目成績,計算核心學習領域成績 /// </summary> /// <param name="Score"></param> /// <returns></returns> public static decimal GetCoreDomainLearningScore(this SemesterScore Score) { decimal result = 0; decimal resultWeight = 0; //取得核心學習領域 List <string> Domains = DALTransfer.GetCoreDomainNameList(); //若是新竹版本 if (Program.Mode == ModuleMode.HsinChu) { //國語文及英語領域,由科目成績計算 List <string> ExceptDomains = new List <string>() { "國語文", "英語" }; #region 計算國文領域成績及權重 Tuple <decimal, decimal, decimal> resultChinese = Score.GetDomainScoreFromSubject("國"); result += resultChinese.Item3; //加上國文領域成績 resultWeight += resultChinese.Item2; //加上國文領域權重 #endregion #region 計算英文領域成績及權重 Tuple <decimal, decimal, decimal> resultEnglish = Score.GetDomainScoreFromSubject("英"); result += resultEnglish.Item3; //加上英文領域成績 resultWeight += resultEnglish.Item2; //加上英文領域權重 #endregion //加總其他領域成績 foreach (string Domain in Domains) { //假設不在排外清單中 if (!ExceptDomains.Contains(Domain) && Score.Domain.Contains(Domain)) { if (Score.Domain[Domain].Value.HasValue && Score.Domain[Domain].Weight.HasValue) { result += Score.Domain[Domain].Value.Value * Score.Domain[Domain].Weight.Value; resultWeight += Score.Domain[Domain].Weight.Value; } } } if (resultWeight > 0) { result /= resultWeight; } return(result); } else { //當高雄時直接依照領域判斷 foreach (string Domain in Domains) { if (Score.Domain.Contains(Domain)) { if (Score.Domain[Domain].Value.HasValue && Score.Domain[Domain].Weight.HasValue) { result += Score.Domain[Domain].Value.Value * Score.Domain[Domain].Weight.Value; //計算加權總分 resultWeight += Score.Domain[Domain].Weight.Value; //計算加權分數 } } } if (resultWeight > 0) { result = result / resultWeight; //加權平均 } return(Math.Round(result, 2, MidpointRounding.AwayFromZero)); } }
/// <summary> /// 計算領域成績 /// </summary> /// <param name="defaultRule"></param> //public void CalculateDomainScore(ScoreCalculator defaultRule,bool clearDomainScore) public void CalculateDomainScore(ScoreCalculator defaultRule, DomainScoreSetting setting) { EffortMap effortmap = new EffortMap(); //努力程度對照表。 foreach (StudentScore student in Students) { SemesterScore semsscore = student.SemestersScore[SemesterData.Empty]; SemesterDomainScoreCollection dscores = semsscore.Domain; SemesterSubjectScoreCollection jscores = semsscore.Subject; ScoreCalculator rule = student.CalculationRule; if (rule == null) { rule = defaultRule; } //各領域分數加總。 Dictionary <string, decimal> domainTotal = new Dictionary <string, decimal>(); //各領域原始分數加總。 Dictionary <string, decimal> domainOriginTotal = new Dictionary <string, decimal>(); //各領域權重加總。 Dictionary <string, decimal> domainWeight = new Dictionary <string, decimal>(); //各領域節數加總。 Dictionary <string, decimal> domainPeriod = new Dictionary <string, decimal>(); //文字評量串接。 Dictionary <string, string> domainText = new Dictionary <string, string>(); //各領域補考分數加總。 Dictionary <string, decimal> domainMakeUpScoreTotal = new Dictionary <string, decimal>(); //該領域的科目有補考成績清單 List <string> haveMakeUpScoreDomains = new List <string>(); // 只計算領域成績,不計算科目 bool OnlyCalcDomainScore = false; // 檢查科目成績是否有成績,當有成績且成績的科目領域名稱非空白才計算 int CheckSubjDomainisNotNullCot = 0; // 檢查是否有非科目領域是空白的科目 foreach (string str in jscores) { SemesterSubjectScore objSubj = jscores[str]; string strDomainName = objSubj.Domain.Trim(); if (!string.IsNullOrEmpty(strDomainName)) { CheckSubjDomainisNotNullCot++; } //該領域的科目有補考成績將被加入 if (objSubj.ScoreMakeup.HasValue && !haveMakeUpScoreDomains.Contains(strDomainName)) { haveMakeUpScoreDomains.Add(strDomainName); } } // 當沒有科目成績或科目成績內領域沒有非空白,只計算領域成績。 if (jscores.Count == 0 || CheckSubjDomainisNotNullCot == 0) { OnlyCalcDomainScore = true; } else { OnlyCalcDomainScore = false; } if (OnlyCalcDomainScore == false) { // 從科目計算到領域 #region 總計各領域的總分、權重、節數。 foreach (string strSubj in jscores) { SemesterSubjectScore objSubj = jscores[strSubj]; string strDomain = objSubj.Domain.Injection(); //不計算的領域就不算。 if (!IsValidItem(strDomain)) { continue; } if (objSubj.Value.HasValue && objSubj.Weight.HasValue && objSubj.Period.HasValue) { if (!objSubj.ScoreOrigin.HasValue) { objSubj.ScoreOrigin = objSubj.Value; } //// 針對高雄處理 國語文跟英語合成語文領域 //if (Program.Mode == ModuleMode.KaoHsiung && (strDomain == "國語文" || strDomain == "英語")) //{ // if (!domainTotal.ContainsKey(khDomain)) // { // domainTotal.Add(khDomain, 0); // domainOriginTotal.Add(khDomain, 0); // domainWeight.Add(khDomain, 0); // domainPeriod.Add(khDomain, 0); // domainText.Add(khDomain, string.Empty); // //領域補考成績 // domain_MakeUpScore_Total.Add(khDomain, 0); // } // domainTotal[khDomain] += objSubj.Value.Value * objSubj.Weight.Value; // //科目的原始成績加總 // domainOriginTotal[khDomain] += objSubj.ScoreOrigin.Value * objSubj.Weight.Value; // domainWeight[khDomain] += objSubj.Weight.Value; // domainPeriod[khDomain] += objSubj.Period.Value; // // 2016/2/26 經高雄繼斌與蔡主任討論,語文領域文字描述不需要儲存 // domainText[khDomain] = "";//+= GetDomainSubjectText(strSubj, objSubj.Text); // //領域補考成績總和 ,算法為 先用各科目的"成績" 加權計算 , 之後會再判斷, 此成績總和 是否含有"補考成績" 是否為"補考成績總和" // domain_MakeUpScore_Total[khDomain] += objSubj.Value.Value * objSubj.Weight.Value; //} if (!domainTotal.ContainsKey(strDomain)) { domainTotal.Add(strDomain, 0); domainOriginTotal.Add(strDomain, 0); domainWeight.Add(strDomain, 0); domainPeriod.Add(strDomain, 0); domainText.Add(strDomain, string.Empty); //領域補考成績 domainMakeUpScoreTotal.Add(strDomain, 0); } domainTotal[strDomain] += objSubj.Value.Value * objSubj.Weight.Value; //科目的原始成績加總 domainOriginTotal[strDomain] += objSubj.ScoreOrigin.Value * objSubj.Weight.Value; domainWeight[strDomain] += objSubj.Weight.Value; domainPeriod[strDomain] += objSubj.Period.Value; domainText[strDomain] += GetDomainSubjectText(strSubj, objSubj.Text); //領域補考成績總和 ,算法為 先用各科目的"成績" 加權計算 , 之後會再判斷, 此成績總和 是否含有"補考成績" 是否為"補考成績總和" // 有科目補考的領域會使用科目補考成績與科目原始成績去計算出領域補考成績 if (haveMakeUpScoreDomains.Contains(strDomain)) { if (objSubj.ScoreMakeup.HasValue && objSubj.Weight.HasValue) { if (Program.Mode == ModuleMode.KaoHsiung) { // 補考不擇優 domainMakeUpScoreTotal[strDomain] += objSubj.ScoreMakeup.Value * objSubj.Weight.Value; } else { // 公版 // 有補考需要與原始比較擇優 if (objSubj.ScoreOrigin.HasValue) { if (objSubj.ScoreMakeup.Value > objSubj.ScoreOrigin.Value) { domainMakeUpScoreTotal[strDomain] += objSubj.ScoreMakeup.Value * objSubj.Weight.Value; } else { // 原始 domainMakeUpScoreTotal[strDomain] += objSubj.ScoreOrigin.Value * objSubj.Weight.Value; } } else { // 沒有原始使用補考 domainMakeUpScoreTotal[strDomain] += objSubj.ScoreMakeup.Value * objSubj.Weight.Value; } } } else { // 沒有補考成績使用原始成績來當補考 if (objSubj.ScoreOrigin.HasValue && objSubj.Weight.HasValue) { domainMakeUpScoreTotal[strDomain] += objSubj.ScoreOrigin.Value * objSubj.Weight.Value; } } } else { if (objSubj.ScoreMakeup.HasValue && objSubj.Weight.HasValue) { domainMakeUpScoreTotal[strDomain] += objSubj.ScoreMakeup.Value * objSubj.Weight.Value; } } } } #endregion #region 計算各領域加權平均。 /* (2014/11/18 補考調整)調整為保留領域成績中的資訊,但是移除多的領域成績項目。 */ // 從科目算過來清空原來領域成績,以科目成績的領域為主 //dscores.Clear(); foreach (string strDomain in domainTotal.Keys) { decimal total = domainTotal[strDomain]; decimal totalOrigin = domainOriginTotal[strDomain]; decimal weight = domainWeight[strDomain]; decimal period = domainPeriod[strDomain]; string text = ""; // 補考總分 decimal makeupScoreTotal = domainMakeUpScoreTotal[strDomain]; if (domainText.ContainsKey(strDomain)) { text = string.Join(";", domainText[strDomain].Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries)); } if (weight <= 0) { continue; //沒有權重就不計算,保留原來的成績。 } decimal weightOriginAvg = rule.ParseDomainScore(totalOrigin / weight); // 補考總分平均 decimal?makeup_score_total_Avg = rule.ParseDomainScore(makeupScoreTotal / weight); //將成績更新回學生。 SemesterDomainScore dscore = null; if (dscores.Contains(strDomain)) { dscore = dscores[strDomain]; } else { dscore = new SemesterDomainScore(); dscores.Add(strDomain, dscore); } //先將算好的成績帶入領域成績,後面的擇優判斷才不會有問題 dscore.ScoreOrigin = weightOriginAvg; dscore.Weight = weight; dscore.Period = period; dscore.Text = text; dscore.Effort = effortmap.GetCodeByScore(weightOriginAvg); dscore.ScoreMakeup = haveMakeUpScoreDomains.Contains(strDomain) ? makeup_score_total_Avg : dscore.ScoreMakeup;//補考成績若無更新則保留原值 //填入dscore.Value if (dscore.ScoreOrigin.HasValue || dscore.ScoreMakeup.HasValue) { dscore.BetterScoreSelection(setting.DomainScoreLimit); } } #endregion #region 高雄專用語文領域成績結算 //高雄市特有領域成績 if (Program.Mode == ModuleMode.KaoHsiung) { decimal total = 0; decimal totalOrigin = 0; decimal totalScoreMakeup = 0; decimal totalScoreMakeupCredit = 0; decimal totalEffort = 0; int chiHasMakupCount = 0; int engHasMakupCount = 0; decimal weight = 0; decimal period = 0; // 先計算國語文與英語有幾個 foreach (string key in jscores) { if (jscores[key].Domain == "國語文" || jscores[key].Domain == "英語") { var subScore = jscores[key]; if (subScore.ScoreMakeup.HasValue) { if (subScore.Domain == "國語文") { chiHasMakupCount++; } if (subScore.Domain == "英語") { engHasMakupCount++; } } } } bool hasMakeupScore = false; // 計算國語文、英語 舊寫法 //foreach (var subDomain in new string[] { "國語文", "英語" }) //{ // if (dscores.Contains(subDomain)) // { // var subScore = dscores[subDomain]; // total += subScore.Value.Value * subScore.Weight.Value; // totalOrigin += subScore.ScoreOrigin.Value * subScore.Weight.Value; // totalEffort += subScore.Effort.Value * subScore.Weight.Value; // weight += subScore.Weight.HasValue ? subScore.Weight.Value : 0; // period += subScore.Period.HasValue ? subScore.Period.Value : 0; // if (subScore.ScoreMakeup.HasValue) // hasMakeupScore = true; // } //} // 2020/9/25,宏安與高雄王主任確認語文領域成績處理方式: // 語文領域是由科目成績來,科目有(國語文與英語)補考成績,由這2個加權平均,如果只有補考其中一科目,補考成績由該科目補考成績與另一科原始成績做加權平均算出語文領域補考成績。只要有語文領域成績是有科目領域國語文與英語加權平均計算過來的結果。 decimal?langScore = null, chiScore = null, engScore = null, chiScoreOrigin = null, engScoreOrigin = null, chiMakeupScore = null, engMakeupScore = null; foreach (string key in jscores) { if (jscores[key].Domain == "國語文" || jscores[key].Domain == "英語") { var subScore = jscores[key]; if (subScore.Weight.HasValue) { if (subScore.Domain == "國語文") { if (subScore.Value.HasValue) { if (chiScore.HasValue == false) { chiScore = 0; } chiScore += subScore.Value.Value * subScore.Weight.Value; } if (subScore.ScoreOrigin.HasValue) { if (chiScoreOrigin.HasValue == false) { chiScoreOrigin = 0; } chiScoreOrigin += subScore.ScoreOrigin.Value * subScore.Weight.Value; } // 有補考,有補考值使用補考,沒有使用原始 if (chiHasMakupCount > 0) { if (chiMakeupScore.HasValue == false) { chiMakeupScore = 0; } if (subScore.ScoreMakeup.HasValue) { chiMakeupScore += subScore.ScoreMakeup.Value * subScore.Weight.Value; } else { chiMakeupScore += subScore.ScoreOrigin.Value * subScore.Weight.Value; } } else { if (chiMakeupScore.HasValue == false) { chiMakeupScore = 0; } if (subScore.ScoreMakeup.HasValue) { chiMakeupScore += subScore.ScoreMakeup.Value * subScore.Weight.Value; } } } if (subScore.Domain == "英語") { if (subScore.Value.HasValue) { if (engScore.HasValue == false) { engScore = 0; } engScore = +subScore.Value.Value * subScore.Weight.Value; } if (subScore.ScoreOrigin.HasValue) { if (engScoreOrigin.HasValue == false) { engScoreOrigin = 0; } engScoreOrigin += subScore.ScoreOrigin.Value * subScore.Weight.Value; } // 有補考,有補考值使用補考,沒有使用原始 if (engHasMakupCount > 0) { if (engMakeupScore.HasValue == false) { engMakeupScore = 0; } if (subScore.ScoreMakeup.HasValue) { engMakeupScore += subScore.ScoreMakeup.Value * subScore.Weight.Value; } else { engMakeupScore += subScore.ScoreOrigin.Value * subScore.Weight.Value; } } else { if (engMakeupScore.HasValue == false) { engMakeupScore = 0; } if (subScore.ScoreMakeup.HasValue) { engMakeupScore += subScore.ScoreMakeup.Value * subScore.Weight.Value; } } } if (subScore.Effort.HasValue) { totalEffort += subScore.Effort.Value * subScore.Weight.Value; } } weight += subScore.Weight.HasValue ? subScore.Weight.Value : 0; period += subScore.Period.HasValue ? subScore.Period.Value : 0; } } if (weight > 0) { decimal weightValueAvg = rule.ParseDomainScore(total / weight); // decimal weightOriginAvg = rule.ParseDomainScore(totalOrigin / weight); // 領域成績國語文英語擇優 if (chiScore.HasValue && engScore.HasValue) { langScore = rule.ParseDomainScore((chiScore.Value + engScore.Value) / weight); } decimal?weightScoreMakeup = null; if (totalScoreMakeupCredit > 0) { weightScoreMakeup = rule.ParseDomainScore(totalScoreMakeup / totalScoreMakeupCredit); } int effortAvg = Convert.ToInt32(decimal.Round(totalEffort / weight, 0, MidpointRounding.AwayFromZero)); var strDomain = "語文"; //將成績更新回學生。 SemesterDomainScore dscore = null; if (dscores.Contains(strDomain)) { dscore = dscores[strDomain]; } else { dscore = new SemesterDomainScore(); dscores.Add(strDomain, dscore, 0); } //先將算好的成績帶入領域成績,後面的擇優判斷才不會有問題 if (chiScoreOrigin.HasValue && engScoreOrigin.HasValue) { dscore.ScoreOrigin = rule.ParseDomainScore((chiScoreOrigin.Value + engScoreOrigin.Value) / weight); } dscore.Weight = weight; dscore.Period = period; dscore.Text = ""; dscore.Effort = effortAvg; if (chiMakeupScore.HasValue && chiMakeupScore.Value == 0) { chiMakeupScore = null; } if (engMakeupScore.HasValue && engMakeupScore.Value == 0) { engMakeupScore = null; } // 補考成績 if (chiMakeupScore.HasValue && engMakeupScore.HasValue) { // 都補考 dscore.ScoreMakeup = rule.ParseDomainScore((chiMakeupScore.Value + engMakeupScore.Value) / weight); // 不會有補考 if (dscore.ScoreMakeup.Value == 0 && chiMakeupScore.Value == 0 && engMakeupScore.Value == 0) { dscore.ScoreMakeup = null; } } else if (chiMakeupScore.HasValue && (engMakeupScore.HasValue == false)) { // 只有補國語文 if (engScoreOrigin.HasValue) { // 補考與原始加權平均 dscore.ScoreMakeup = rule.ParseDomainScore((chiMakeupScore.Value + engScoreOrigin.Value) / weight); } } else if (chiMakeupScore.HasValue == false && engMakeupScore.HasValue) { if (chiScoreOrigin.HasValue) { // 補考與原始加權平均 dscore.ScoreMakeup = rule.ParseDomainScore((engMakeupScore.Value + chiScoreOrigin.Value) / weight); } } else { // dscore.ScoreMakeup = null; } //if (weightScoreMakeup.HasValue) // dscore.ScoreMakeup = weightScoreMakeup.Value; // 語文成績 if (chiMakeupScore.HasValue == false && engMakeupScore.HasValue == false) { //// 語文領域補考直接輸入補考 if (dscore.ScoreOrigin.HasValue || dscore.ScoreMakeup.HasValue) { dscore.BetterScoreSelection(setting.DomainScoreLimit); } } else { // 當有輸入補考,又有勾選不能超過 60 分 if (setting.DomainScoreLimit) { // 2021/3/10 修改,當語文計算出來有超過60分有勾最高60分 // 計算出來語文 if (langScore.HasValue) { if (langScore.Value > 60) { langScore = 60; } } } // 先放入原始成績 if (dscore.ScoreOrigin.HasValue) { dscore.Value = dscore.ScoreOrigin.Value; } else { dscore.Value = 0; } // 分數取最高 if (dscore.ScoreOrigin.HasValue) { if (dscore.ScoreOrigin.Value > dscore.Value) { dscore.Value = dscore.ScoreOrigin.Value; } } // 補考 if (dscore.ScoreMakeup.HasValue) { decimal SCMScore = dscore.ScoreMakeup.Value; // 當有勾補考不能超過60分 if (setting.DomainScoreLimit) { if (SCMScore > 60) { SCMScore = 60; } } if (SCMScore > dscore.Value) { dscore.Value = SCMScore; } } // 處理從科目算來語文領域 if (langScore.HasValue) { decimal LCMScore = langScore.Value; // 當有勾補考不能超過60分 if (setting.DomainScoreLimit) { if (LCMScore > 60) { LCMScore = 60; } } if (LCMScore > dscore.Value) { dscore.Value = LCMScore; } } } ////填入dscore.Value //if (dscore.ScoreOrigin.HasValue || dscore.ScoreMakeup.HasValue) // dscore.BetterScoreSelection(setting.DomainScoreLimit); } } #endregion //清除不應該存在領域成績 //if (clearDomainScore) if (setting.DomainScoreClear) { foreach (var domainName in dscores.ToArray()) { //如果新計算的領域成績中不包含在原領域清單中,就移除他。 if (!domainTotal.ContainsKey(domainName)) { dscores.Remove(domainName); } } } } //2018/1/8 穎驊因應高雄項目[11-01][02] 學期領域成績結算BUG 問題新增 // 將所有的領域成績一併擇優計算,以防止有些僅有領域成績,但是卻沒有科目成績的領域,其補考成績被漏算的問題 foreach (var domain in dscores.ToArray()) { SemesterDomainScore dscore = dscores[domain]; //擇優 if (Program.Mode == ModuleMode.KaoHsiung && domain == "語文") { continue; } dscore.BetterScoreSelection(setting.DomainScoreLimit); } // 載入108課綱比對使用 Util.LoadDomainMap108(); //計算課程學習成績。 ScoreResult result = CalcDomainWeightAvgScore(dscores, new UniqueSet <string>()); if (result.Score.HasValue) { semsscore.CourseLearnScore = rule.ParseLearnDomainScore(result.Score.Value); } if (result.ScoreOrigin.HasValue) { semsscore.CourseLearnScoreOrigin = rule.ParseLearnDomainScore(result.ScoreOrigin.Value); } //計算學習領域成績。 result = CalcDomainWeightAvgScore(dscores, Util.VariableDomains); if (result.Score.HasValue) { semsscore.LearnDomainScore = rule.ParseLearnDomainScore(result.Score.Value); } if (result.ScoreOrigin.HasValue) { semsscore.LearnDomainScoreOrigin = rule.ParseLearnDomainScore(result.ScoreOrigin.Value); } } }
private void PrintDomainOnly(DocumentBuilder builder, ReportStudent student, Row template, Table table) { #region 列印領域 UniqueSet <RowHeader> RowIndexs = new UniqueSet <RowHeader>(); #region 列印 RowHeader foreach (SemesterData semester in student.SHistory.GetGradeYearSemester()) { SemesterData sysems = new SemesterData(0, semester.SchoolYear, semester.Semester); //如果不包含該學期成績資料,就跳過。 if (!student.SemestersScore.Contains(sysems)) { continue; } SemesterScore semsscore = student.SemestersScore[sysems]; //準備彈性課程的科目(要詳列出來)。 foreach (string strSubject in semsscore.Subject) { SemesterSubjectScore subject = semsscore.Subject[strSubject]; if (DetailDomain.Contains(subject.Domain)) { RowHeader header = new RowHeader(subject.Domain, strSubject); header.IsDomain = false; if (!RowIndexs.Contains(header)) { RowIndexs.Add(header); } } } //準備領域資料。 foreach (string strDomain in semsscore.Domain) { if (!Subj.Domains.Contains(strDomain)) { continue; } SemesterDomainScore domain = semsscore.Domain[strDomain]; if (!DetailDomain.Contains(strDomain)) { RowHeader header = new RowHeader(strDomain, string.Empty); header.IsDomain = true; if (!RowIndexs.Contains(header)) { RowIndexs.Add(header); } } } } List <RowHeader> sortedHeaders = SortHeader(RowIndexs.ToList()); //產生 Row。 List <RowHeader> indexHeaders = new List <RowHeader>(); Row current = template; int rowIndex = 0; foreach (RowHeader header in sortedHeaders) { RowHeader indexH = header; indexH.Index = rowIndex++; indexHeaders.Add(indexH); bool hasGroup = !string.IsNullOrEmpty(Subj.GetDomainGroup(header.Domain)); string groupName = Subj.GetDomainGroup(header.Domain); Row datarow = table.InsertBefore(template.Clone(true), current) as Row; if (header.IsDomain) { string domainCName = header.Domain; //string domainEName = Subj.GetDomainEnglish(header.Domain); string domainEName = _SubjDomainEngNameMapping.GetDomainEngName(header.Domain); string domainString = domainCName + (string.IsNullOrEmpty(domainEName) ? "" : domainEName); if (hasGroup) { string gn = groupName; if (groupName == "語文") { gn = "語文\nLanguage"; } datarow.Cells[0].Write(builder, gn); datarow.Cells[1].Write(builder, domainString); } else { datarow.Cells[0].Write(builder, domainString); } } else { string gn = ""; //Additional Classes if (IsFlexible(header.Domain)) { gn = "彈性課程\nAdditional Classes"; } else { gn = header.Domain; } string subjCName = header.Subject; //string subjEName = Subj.GetSubjectEnglish(header.Subject); string subjEName = _SubjDomainEngNameMapping.GetSubjectEngName(header.Subject); string subjString = header.Subject + (string.IsNullOrEmpty(subjEName) ? "" : "\n" + subjEName); //把空白的領域當成「彈性課程」。 string domain = gn; string domainEName = _SubjDomainEngNameMapping.GetDomainEngName(domain); domain += string.IsNullOrWhiteSpace(domainEName) ? "" : "\n" + domainEName; datarow.Cells[0].Write(builder, domain); datarow.Cells[1].Write(builder, subjString); } } #endregion #region 填資料 //Row RatingRow = null; foreach (RowHeader header in indexHeaders) { SemesterDataCollection semesters = new SemesterDataCollection(); Row row = table.Rows[header.Index + DataRowOffset]; foreach (SemesterData semester in student.SHistory.GetGradeYearSemester()) { SemesterData sysems = new SemesterData(0, semester.SchoolYear, semester.Semester); semesters.Add(sysems); if (!student.SemestersScore.Contains(sysems)) { continue; } if (!student.HeaderList.ContainsKey(sysems)) { continue; } int columnIndex = student.HeaderList[sysems]; SemesterScore semsscore = student.SemestersScore[sysems]; decimal?score = null; decimal?weight = null; if (header.IsDomain) { if (semsscore.Domain.Contains(header.Domain)) { score = semsscore.Domain[header.Domain].Value; weight = semsscore.Domain[header.Domain].Weight; } } else { if (semsscore.Subject.Contains(header.Subject)) { score = semsscore.Subject[header.Subject].Value; weight = semsscore.Subject[header.Subject].Weight; } } if (!score.HasValue) { continue; } if (!weight.HasValue) { weight = 0; } //if (PrintScore) // row.Cells[columnIndex + 2].Write(builder, score.Value + ""); //else // row.Cells[columnIndex + 2].Write(builder, Util.GetDegreeEnglish(score.Value)); if (PrintScore) { if (Global.ShowCredit) { row.Cells[columnIndex * 2 + 2].Write(builder, score.Value + ""); row.Cells[columnIndex * 2 + 3].Write(builder, weight.Value + ""); } else { row.Cells[columnIndex + 2].Write(builder, score.Value + ""); } } else { if (Global.ShowCredit) { row.Cells[columnIndex * 2 + 2].Write(builder, Util.GetDegreeEnglish(score.Value)); row.Cells[columnIndex * 2 + 3].Write(builder, weight.Value + ""); } else { row.Cells[columnIndex + 2].Write(builder, Util.GetDegreeEnglish(score.Value)); } } } } #endregion #region 合併相關欄位。 string previousCellDomain = string.Empty; foreach (RowHeader header in indexHeaders) { bool hasGroup = !string.IsNullOrEmpty(Subj.GetDomainGroup(header.Domain)); string groupName = Subj.GetDomainGroup(header.Domain); Row row = table.Rows[header.Index + DataRowOffset]; if (previousCellDomain == row.Cells[0].ToTxt()) { row.Cells[0].CellFormat.VerticalMerge = CellMerge.Previous; } else { row.Cells[0].CellFormat.VerticalMerge = CellMerge.First; } if (header.IsDomain) { if (!hasGroup) { row.Cells[0].CellFormat.HorizontalMerge = CellMerge.First; row.Cells[1].CellFormat.HorizontalMerge = CellMerge.Previous; } } previousCellDomain = row.Cells[0].ToTxt(); } #endregion #endregion }
private void PrintSubjectOnly(DocumentBuilder builder, ReportStudent student, Row template, Table table) { #region 列印科目 UniqueSet <RowHeader> RowIndexs = new UniqueSet <RowHeader>(); #region 列印 RowHeader Dictionary <string, string> subjToDomain = new Dictionary <string, string>(); foreach (SemesterData semester in student.SHistory.GetGradeYearSemester()) { SemesterData sysems = new SemesterData(0, semester.SchoolYear, semester.Semester); if (!student.SemestersScore.Contains(sysems)) { continue; } SemesterScore semsscore = student.SemestersScore[sysems]; foreach (string strSubject in semsscore.Subject) { SemesterSubjectScore subject = semsscore.Subject[strSubject]; if (!subjToDomain.ContainsKey(strSubject)) { subjToDomain.Add(strSubject, subject.Domain); } RowHeader header = new RowHeader(subjToDomain[strSubject], strSubject); header.IsDomain = false; if (!RowIndexs.Contains(header)) { RowIndexs.Add(header); } } } List <RowHeader> sortedHeaders = RowIndexs.ToList(); sortedHeaders.Sort(delegate(RowHeader x, RowHeader y) { Subj xx = new JHSchool.Evaluation.Subject(x.Subject, x.Domain); Subj yy = new JHSchool.Evaluation.Subject(y.Subject, y.Domain); return(xx.CompareTo(yy)); }); //產生 Row。 List <RowHeader> indexHeaders = new List <RowHeader>(); Row current = template; int rowIndex = 0; foreach (RowHeader header in sortedHeaders) { RowHeader indexH = header; indexH.Index = rowIndex++; indexHeaders.Add(indexH); Row datarow = table.InsertBefore(template.Clone(true), current) as Row; string gn = ""; //Additional Classes string subjCName = header.Subject; //string subjEName = Subj.GetSubjectEnglish(header.Subject); string subjEName = _SubjDomainEngNameMapping.GetSubjectEngName(header.Subject); string subjString = header.Subject + (string.IsNullOrEmpty(subjEName) ? "" : " " + subjEName); datarow.Cells[0].Write(builder, subjString); //if (IsFlexible(header.Domain)) //{ // gn = "彈性課程\nAdditional Classes"; // //把空白的領域當成「彈性課程」。 // datarow.Cells[0].Write(builder, gn); // datarow.Cells[1].Write(builder, subjString); //} //else //{ //} } #endregion #region 填資料 //填資料 foreach (RowHeader header in indexHeaders) { SemesterDataCollection semesters = new SemesterDataCollection(); Row row = table.Rows[header.Index + DataRowOffset]; foreach (SemesterData semester in student.SHistory.GetGradeYearSemester()) { SemesterData sysems = new SemesterData(0, semester.SchoolYear, semester.Semester); semesters.Add(sysems); if (!student.SemestersScore.Contains(sysems)) { continue; } if (!student.HeaderList.ContainsKey(sysems)) { continue; } int columnIndex = student.HeaderList[sysems]; SemesterScore semsscore = student.SemestersScore[sysems]; decimal?score = null; decimal?weight = null; //if (header.IsDomain) //{ // if (semsscore.Domain.Contains(header.Domain)) // { // score = semsscore.Domain[header.Domain].Value; // weight = semsscore.Domain[header.Domain].Weight; // } //} //else //{ if (semsscore.Subject.Contains(header.Subject)) { score = semsscore.Subject[header.Subject].Value; weight = semsscore.Subject[header.Subject].Weight; } //} if (!score.HasValue) { continue; } if (!weight.HasValue) { weight = 0; } //if (PrintScore) // row.Cells[columnIndex + 2].Write(builder, score.Value + ""); //else // row.Cells[columnIndex + 2].Write(builder, Util.GetDegreeEnglish(score.Value)); if (PrintScore) { if (Global.ShowCredit) { row.Cells[columnIndex * 2 + 2].Write(builder, score.Value + ""); row.Cells[columnIndex * 2 + 3].Write(builder, weight.Value + ""); } else { row.Cells[columnIndex + 2].Write(builder, score.Value + ""); } } else { if (Global.ShowCredit) { row.Cells[columnIndex * 2 + 2].Write(builder, Util.GetDegreeEnglish(score.Value)); row.Cells[columnIndex * 2 + 3].Write(builder, weight.Value + ""); } else { row.Cells[columnIndex + 2].Write(builder, Util.GetDegreeEnglish(score.Value)); } } } } #endregion #region 合併相關欄位。 string previousCellDomain = string.Empty; foreach (RowHeader header in indexHeaders) { Row row = table.Rows[header.Index + DataRowOffset]; //if (IsFlexible(header.Domain)) //{ // if (previousCellDomain == row.Cells[0].ToTxt()) // row.Cells[0].CellFormat.VerticalMerge = CellMerge.Previous; // else // row.Cells[0].CellFormat.VerticalMerge = CellMerge.First; //} //else { row.Cells[0].CellFormat.HorizontalMerge = CellMerge.First; row.Cells[1].CellFormat.HorizontalMerge = CellMerge.Previous; } previousCellDomain = row.Cells[0].ToTxt(); } #endregion #endregion }
/// <summary> /// 計算領域成績 /// </summary> /// <param name="defaultRule"></param> //public void CalculateDomainScore(ScoreCalculator defaultRule,bool clearDomainScore) public void CalculateDomainScore(ScoreCalculator defaultRule, DomainScoreSetting setting) { EffortMap effortmap = new EffortMap(); //努力程度對照表。 foreach (StudentScore student in Students) { SemesterScore semsscore = student.SemestersScore[SemesterData.Empty]; SemesterDomainScoreCollection dscores = semsscore.Domain; SemesterSubjectScoreCollection jscores = semsscore.Subject; ScoreCalculator rule = student.CalculationRule; if (rule == null) { rule = defaultRule; } //各領域分數加總。 Dictionary <string, decimal> domainTotal = new Dictionary <string, decimal>(); //各領域原始分數加總。 Dictionary <string, decimal> domainOriginTotal = new Dictionary <string, decimal>(); //各領域權重加總。 Dictionary <string, decimal> domainWeight = new Dictionary <string, decimal>(); //各領域節數加總。 Dictionary <string, decimal> domainPeriod = new Dictionary <string, decimal>(); //文字評量串接。 Dictionary <string, string> domainText = new Dictionary <string, string>(); //各領域補考分數加總。 Dictionary <string, decimal> domainMakeUpScoreTotal = new Dictionary <string, decimal>(); //該領域的科目有補考成績清單 List <string> haveMakeUpScoreDomains = new List <string>(); // 只計算領域成績,不計算科目 bool OnlyCalcDomainScore = false; // 檢查科目成績是否有成績,當有成績且成績的科目領域名稱非空白才計算 int CheckSubjDomainisNotNullCot = 0; // 檢查是否有非科目領域是空白的科目 foreach (string str in jscores) { SemesterSubjectScore objSubj = jscores[str]; string strDomainName = objSubj.Domain.Trim(); if (!string.IsNullOrEmpty(strDomainName)) { CheckSubjDomainisNotNullCot++; } //該領域的科目有補考成績將被加入 if (objSubj.ScoreMakeup.HasValue && !haveMakeUpScoreDomains.Contains(strDomainName)) { haveMakeUpScoreDomains.Add(strDomainName); } } // 當沒有科目成績或科目成績內領域沒有非空白,只計算領域成績。 if (jscores.Count == 0 || CheckSubjDomainisNotNullCot == 0) { OnlyCalcDomainScore = true; } else { OnlyCalcDomainScore = false; } if (OnlyCalcDomainScore == false) { // 從科目計算到領域 #region 總計各領域的總分、權重、節數。 foreach (string strSubj in jscores) { SemesterSubjectScore objSubj = jscores[strSubj]; string strDomain = objSubj.Domain.Injection(); //不計算的領域就不算。 if (!IsValidItem(strDomain)) { continue; } if (objSubj.Value.HasValue && objSubj.Weight.HasValue && objSubj.Period.HasValue) { if (!objSubj.ScoreOrigin.HasValue) { objSubj.ScoreOrigin = objSubj.Value; } //// 針對高雄處理 國語文跟英語合成語文領域 //if (Program.Mode == ModuleMode.KaoHsiung && (strDomain == "國語文" || strDomain == "英語")) //{ // if (!domainTotal.ContainsKey(khDomain)) // { // domainTotal.Add(khDomain, 0); // domainOriginTotal.Add(khDomain, 0); // domainWeight.Add(khDomain, 0); // domainPeriod.Add(khDomain, 0); // domainText.Add(khDomain, string.Empty); // //領域補考成績 // domain_MakeUpScore_Total.Add(khDomain, 0); // } // domainTotal[khDomain] += objSubj.Value.Value * objSubj.Weight.Value; // //科目的原始成績加總 // domainOriginTotal[khDomain] += objSubj.ScoreOrigin.Value * objSubj.Weight.Value; // domainWeight[khDomain] += objSubj.Weight.Value; // domainPeriod[khDomain] += objSubj.Period.Value; // // 2016/2/26 經高雄繼斌與蔡主任討論,語文領域文字描述不需要儲存 // domainText[khDomain] = "";//+= GetDomainSubjectText(strSubj, objSubj.Text); // //領域補考成績總和 ,算法為 先用各科目的"成績" 加權計算 , 之後會再判斷, 此成績總和 是否含有"補考成績" 是否為"補考成績總和" // domain_MakeUpScore_Total[khDomain] += objSubj.Value.Value * objSubj.Weight.Value; //} if (!domainTotal.ContainsKey(strDomain)) { domainTotal.Add(strDomain, 0); domainOriginTotal.Add(strDomain, 0); domainWeight.Add(strDomain, 0); domainPeriod.Add(strDomain, 0); domainText.Add(strDomain, string.Empty); //領域補考成績 domainMakeUpScoreTotal.Add(strDomain, 0); } domainTotal[strDomain] += objSubj.Value.Value * objSubj.Weight.Value; //科目的原始成績加總 domainOriginTotal[strDomain] += objSubj.ScoreOrigin.Value * objSubj.Weight.Value; domainWeight[strDomain] += objSubj.Weight.Value; domainPeriod[strDomain] += objSubj.Period.Value; domainText[strDomain] += GetDomainSubjectText(strSubj, objSubj.Text); //領域補考成績總和 ,算法為 先用各科目的"成績" 加權計算 , 之後會再判斷, 此成績總和 是否含有"補考成績" 是否為"補考成績總和" domainMakeUpScoreTotal[strDomain] += objSubj.Value.Value * objSubj.Weight.Value; } } #endregion #region 計算各領域加權平均。 /* (2014/11/18 補考調整)調整為保留領域成績中的資訊,但是移除多的領域成績項目。 */ // 從科目算過來清空原來領域成績,以科目成績的領域為主 //dscores.Clear(); foreach (string strDomain in domainTotal.Keys) { decimal total = domainTotal[strDomain]; decimal totalOrigin = domainOriginTotal[strDomain]; decimal weight = domainWeight[strDomain]; decimal period = domainPeriod[strDomain]; string text = ""; // 補考總分 decimal makeupScoreTotal = domainMakeUpScoreTotal[strDomain]; if (domainText.ContainsKey(strDomain)) { text = string.Join(";", domainText[strDomain].Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries)); } if (weight <= 0) { continue; //沒有權重就不計算,保留原來的成績。 } decimal weightOriginAvg = rule.ParseDomainScore(totalOrigin / weight); // 補考總分平均 decimal?makeup_score_total_Avg = rule.ParseDomainScore(makeupScoreTotal / weight); //將成績更新回學生。 SemesterDomainScore dscore = null; if (dscores.Contains(strDomain)) { dscore = dscores[strDomain]; } else { dscore = new SemesterDomainScore(); dscores.Add(strDomain, dscore); } //先將算好的成績帶入領域成績,後面的擇優判斷才不會有問題 dscore.ScoreOrigin = weightOriginAvg; dscore.Weight = weight; dscore.Period = period; dscore.Text = text; dscore.Effort = effortmap.GetCodeByScore(weightOriginAvg); dscore.ScoreMakeup = haveMakeUpScoreDomains.Contains(strDomain) ? makeup_score_total_Avg : dscore.ScoreMakeup;//補考成績若無更新則保留原值 //填入dscore.Value if (dscore.ScoreOrigin.HasValue || dscore.ScoreMakeup.HasValue) { dscore.BetterScoreSelection(setting.DomainScoreLimit); } } #endregion #region 高雄專用語文領域成績結算 //高雄市特有領域成績 if (Program.Mode == ModuleMode.KaoHsiung) { decimal total = 0; decimal totalOrigin = 0; decimal totalEffort = 0; decimal weight = 0; decimal period = 0; bool hasMakeupScore = false; foreach (var subDomain in new string[] { "國語文", "英語" }) { if (dscores.Contains(subDomain)) { var subScore = dscores[subDomain]; total += subScore.Value.Value * subScore.Weight.Value; totalOrigin += subScore.ScoreOrigin.Value * subScore.Weight.Value; totalEffort += subScore.Effort.Value * subScore.Weight.Value; weight += subScore.Weight.HasValue ? subScore.Weight.Value : 0; period += subScore.Period.HasValue ? subScore.Period.Value : 0; if (subScore.ScoreMakeup.HasValue) { hasMakeupScore = true; } } } if (weight > 0) { decimal weightValueAvg = rule.ParseDomainScore(total / weight); decimal weightOriginAvg = rule.ParseDomainScore(totalOrigin / weight); int effortAvg = Convert.ToInt32(decimal.Round(totalEffort / weight, 0, MidpointRounding.AwayFromZero)); var strDomain = "語文"; //將成績更新回學生。 SemesterDomainScore dscore = null; if (dscores.Contains(strDomain)) { dscore = dscores[strDomain]; } else { dscore = new SemesterDomainScore(); dscores.Add(strDomain, dscore, 0); } //先將算好的成績帶入領域成績,後面的擇優判斷才不會有問題 dscore.ScoreOrigin = weightOriginAvg; dscore.Weight = weight; dscore.Period = period; dscore.Text = ""; dscore.Effort = effortAvg; dscore.ScoreMakeup = hasMakeupScore ? weightValueAvg : dscore.ScoreMakeup;//補考成績若無更新則保留原值 //填入dscore.Value if (dscore.ScoreOrigin.HasValue || dscore.ScoreMakeup.HasValue) { dscore.BetterScoreSelection(setting.DomainScoreLimit); } } } #endregion //清除不應該存在領域成績 //if (clearDomainScore) if (setting.DomainScoreClear) { foreach (var domainName in dscores.ToArray()) { //如果新計算的領域成績中不包含在原領域清單中,就移除他。 if (!domainTotal.ContainsKey(domainName)) { dscores.Remove(domainName); } } } } //計算課程學習成績。 ScoreResult result = CalcDomainWeightAvgScore(dscores, new UniqueSet <string>()); if (result.Score.HasValue) { semsscore.CourseLearnScore = rule.ParseLearnDomainScore(result.Score.Value); } if (result.ScoreOrigin.HasValue) { semsscore.CourseLearnScoreOrigin = rule.ParseLearnDomainScore(result.ScoreOrigin.Value); } //計算學習領域成績。 result = CalcDomainWeightAvgScore(dscores, Util.VariableDomains); if (result.Score.HasValue) { semsscore.LearnDomainScore = rule.ParseLearnDomainScore(result.Score.Value); } if (result.ScoreOrigin.HasValue) { semsscore.LearnDomainScoreOrigin = rule.ParseLearnDomainScore(result.ScoreOrigin.Value); } } }
/// <summary> /// 計算領域成績 /// </summary> /// <param name="defaultRule"></param> public void CalculateDomainScore(ScoreCalculator defaultRule) { EffortMap effortmap = new EffortMap(); //努力程度對照表。 foreach (StudentScore student in Students) { SemesterScore semsscore = student.SemestersScore[SemesterData.Empty]; SemesterDomainScoreCollection dscores = semsscore.Domain; SemesterSubjectScoreCollection jscores = semsscore.Subject; ScoreCalculator rule = student.CalculationRule; if (rule == null) { rule = defaultRule; } //各領域分數加總。 Dictionary <string, decimal> domainTotal = new Dictionary <string, decimal>(); //各領域權重加總。 Dictionary <string, decimal> domainWeight = new Dictionary <string, decimal>(); //各領域節數加總。 Dictionary <string, decimal> domainPeriod = new Dictionary <string, decimal>(); //文字評量串接。 Dictionary <string, string> domainText = new Dictionary <string, string>(); // 只計算領域成績,不計算科目 bool OnlyCalcDomainScore = false; // 檢查科目成績是否有成績,當有成績且成績的科目領域名稱非空白才計算 int CheckSubjDomainisNotNullCot = 0; // 檢查是否有非科目領域是空白的科目 foreach (string str in jscores) { SemesterSubjectScore objSubj = jscores[str]; string strDomainName = objSubj.Domain.Trim(); if (!string.IsNullOrEmpty(strDomainName)) { CheckSubjDomainisNotNullCot++; } } // 當沒有科目成績或科目成績內領域沒有非空白,只計算領域成績。 if (jscores.Count == 0 || CheckSubjDomainisNotNullCot == 0) { OnlyCalcDomainScore = true; } else { OnlyCalcDomainScore = false; } if (OnlyCalcDomainScore == false) { // 從科目計算到領域 #region 總計各領域的總分、權重、節數。 foreach (string strSubj in jscores) { SemesterSubjectScore objSubj = jscores[strSubj]; string strDomain = objSubj.Domain.Injection(); //不計算的領域就不算。 if (!IsValidItem(strDomain)) { continue; } if (objSubj.Value.HasValue && objSubj.Weight.HasValue && objSubj.Period.HasValue) { if (!domainTotal.ContainsKey(strDomain)) { domainTotal.Add(strDomain, 0); domainWeight.Add(strDomain, 0); domainPeriod.Add(strDomain, 0); domainText.Add(strDomain, string.Empty); } domainTotal[strDomain] += objSubj.Value.Value * objSubj.Weight.Value; domainWeight[strDomain] += objSubj.Weight.Value; domainPeriod[strDomain] += objSubj.Period.Value; domainText[strDomain] += GetDomainSubjectText(strSubj, objSubj.Text); } } #endregion #region 計算各領域加權平均。 // 從科目算過來清空原來領域成績,以科目成績的領域為主 dscores.Clear(); foreach (string strDomain in domainTotal.Keys) { decimal total = domainTotal[strDomain]; decimal weight = domainWeight[strDomain]; decimal period = domainPeriod[strDomain]; string text = string.Join(";", domainText[strDomain].Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries)); if (weight <= 0) { continue; //沒有權重就不計算,保留原來的成績。 } decimal weightAvg = rule.ParseDomainScore(total / weight); //將成績更新回學生。 SemesterDomainScore dscore = null; //if (dscores.Contains(strDomain)) // dscore = dscores[strDomain]; //else //{ dscore = new SemesterDomainScore(); dscores.Add(strDomain, dscore); //} dscore.Value = weightAvg; dscore.Weight = weight; dscore.Period = period; dscore.Text = text; dscore.Effort = effortmap.GetCodeByScore(weightAvg); } } else { // 因為原本就會計算學期領域成績,所以不處理。 } //計算課程學習成績。 decimal?result = CalcDomainWeightAvgScore(dscores, new UniqueSet <string>()); if (result.HasValue) { semsscore.CourseLearnScore = rule.ParseLearnDomainScore(result.Value); } //計算學習領域成績。 result = CalcDomainWeightAvgScore(dscores, Util.VariableDomains); if (result.HasValue) { semsscore.LearnDomainScore = rule.ParseLearnDomainScore(result.Value); } #endregion } }
public decimal?GetScore(ReportStudent student) { SemesterScore score = null; foreach (SemesterData each in student.SHistory.GetGradeYearSemester()) { //// 處理轉入生之前不列入排名 //if (student.LastEnterSchoolyear.HasValue && student.LastEnterSemester.HasValue && student.LastEnterGradeYear.HasValue) //{ // if (each.GradeYear < student.LastEnterGradeYear.Value) // continue; // else // { // if (each.GradeYear == student.LastEnterGradeYear.Value && each.Semester < student.LastEnterSemester.Value) // continue; // } //} //// 處理轉入生之前不列入排名 //if (student.LastEnterSchoolyear.HasValue && student.LastEnterSemester.HasValue && student.LastEnterGradeYear.HasValue) //{ // if (each.SchoolYear < student.LastEnterSchoolyear.Value) // continue; // else // { // if (each.SchoolYear == student.LastEnterSchoolyear.Value && each.Semester < student.LastEnterSemester.Value) // continue; // } //} SemesterData gysemester = new SemesterData(each.GradeYear, 0, each.Semester); if (gysemester == Semester) { SemesterData sd = new SemesterData(0, each.SchoolYear, each.Semester); if (student.SemestersScore.Contains(sd)) { score = student.SemestersScore[sd]; } break; } } //if (score == null) // return null; //else // return score.LearnDomainScore; if (score == null) { return(0); } else if (score.LearnDomainScore.HasValue) { //return score.LearnDomainScore.Value; // 修改讀取成績計算規則 if (student.CalculationRule == null) { return(score.LearnDomainScore.Value); } else { return(student.CalculationRule.ParseLearnDomainScore(score.LearnDomainScore.Value)); } } else { return(0); } }