private static JHSemesterScoreRecord GetJHSemesterScore(string studentID, SCSemsScore scsemsscore)
        {
            JHSemesterScoreRecord semsscore = scsemsscore.RawScore;

            if (semsscore == null)
            {
                semsscore = new JHSemesterScoreRecord();
                semsscore.RefStudentID = studentID;
                semsscore.SchoolYear   = scsemsscore.SchoolYear;
                semsscore.Semester     = scsemsscore.Semester;
            }

            return(semsscore);
        }
Example #2
0
        /// <summary>
        /// 計算科目成績
        /// </summary>
        public void CalculateSubjectScore()
        {
            foreach (StudentScore student in Students)
            {
                if (student.CalculationRule == null)
                {
                    continue;                                  //沒有成績計算規則就不計算。
                }
                SCSemsScore Sems = student.SemestersScore[SemesterData.Empty];

                //對全部的學期科目成績作一次擇優
                foreach (string subject in Sems.Subject)
                {
                    if (Sems.Subject.Contains(subject))
                    {
                        SemesterSubjectScore sss = Sems.Subject[subject];

                        //沒有原始成績就將既有的成績填入
                        if (!sss.ScoreOrigin.HasValue)
                        {
                            sss.ScoreOrigin = sss.Value;
                        }

                        //有原始或補考成績才做擇優
                        if (sss.ScoreOrigin.HasValue || sss.ScoreMakeup.HasValue)
                        {
                            sss.BetterScoreSelection();
                        }
                    }
                }



                // 2016/7/13 穎驊註解,原本為整理重覆科目使用,後來功能被另外取代掉,又保留Dic_StudentAttendScore 的話,
                // 如果再 //處理修課課程 foreach (string subject in student.AttendScore),不使用in student.AttendScore 而是用 in Dic_StudentAttendScore
                // 則會出現 下一個學生使用上一個學生的修課紀錄,假如上一個學生有著下一個學生沒有的修課內容,就會造成錯誤


                //foreach (string subject in student.AttendScore)
                //{

                //    if (!Dic_StudentAttendScore.ContainsKey(subject))
                //    {
                //        Dic_StudentAttendScore.Add(subject, subject);

                //    }
                //    else {

                //        //MessageBox.Show("科目:" + subject + "在課程科目名稱有重覆," + "如繼續匯入將導致學期科目成績遺漏誤植,請確認您在" + subject + "這一科的課程資料無誤");
                //    }

                //}



                //處理修課課程
                foreach (string subject in student.AttendScore)
                {
                    if (!IsValidItem(subject))
                    {
                        continue;                        //慮掉不算的科目。
                    }
                    AttendScore          attend   = student.AttendScore[subject];
                    SemesterSubjectScore SemsSubj = null;

                    if (Sems.Subject.Contains(subject))
                    {
                        SemsSubj = Sems.Subject[subject];
                    }
                    else
                    {
                        SemsSubj = new SemesterSubjectScore();
                    }

                    if (attend.ToSemester) //列入學期成績。
                    {
                        //分數、權數都有資料才進行計算科目成績。
                        if (attend.Value.HasValue && attend.Weight.HasValue && attend.Period.HasValue)
                        {
                            decimal score = student.CalculationRule.ParseSubjectScore(attend.Value.Value); //進位處理。
                            //SemsSubj.Value = score;
                            SemsSubj.Weight = attend.Weight.Value;
                            SemsSubj.Period = attend.Period.Value;
                            SemsSubj.Effort = attend.Effort;
                            SemsSubj.Text   = attend.Text;
                            SemsSubj.Domain = attend.Domain;

                            //填到原始成績
                            SemsSubj.ScoreOrigin = score;
                            //擇優成績
                            SemsSubj.BetterScoreSelection();
                        }
                        else //資料不合理,保持原來的分數狀態。
                        {
                            continue;
                        }

                        if (!Sems.Subject.Contains(subject))
                        {
                            Sems.Subject.Add(subject, SemsSubj);
                        }
                    }
                    else
                    {
                        //不計入學期成績,就將其刪除掉。
                        if (Sems.Subject.Contains(subject))
                        {
                            Sems.Subject.Remove(subject);
                        }
                    }
                }
            }
        }
        public void Calculate()
        {
            foreach (StudentScore student in Students)
            {
                //成績計算規則。
                ScoreCalculator calcRule = student.CalculationRule;

                //沒有成績計算規則的不計算。
                if (calcRule == null)
                {
                    continue;
                }

                //領域總分。
                Dictionary <string, decimal> domainTotal = new Dictionary <string, decimal>();
                //學期數計數。
                Dictionary <string, decimal> semsCount = new Dictionary <string, decimal>();
                //計算六學期的總分。
                foreach (SemesterData sems in student.SHistory.GetGradeYearSemester())
                {
                    SemesterData sd = new SemesterData(0, sems.SchoolYear, sems.Semester);

                    //學生不包含該學期的成績,直接跳過。
                    if (!student.SemestersScore.Contains(sd))
                    {
                        continue;
                    }

                    //將該學期的成績資料取出。
                    SCSemsScore scscore = student.SemestersScore[sd];

                    //加總各領域成績。
                    foreach (string strDomain in scscore.Domain)
                    {
                        SCSemsDomainScore objDomain = scscore.Domain[strDomain];

                        if (!objDomain.Value.HasValue)
                        {
                            continue;                            //沒有成績不計算。
                        }
                        SumDomainScore(domainTotal, semsCount, strDomain, objDomain.Value.Value);
                    }
                    //學習領域。
                    if (scscore.LearnDomainScore.HasValue)
                    {
                        SumDomainScore(domainTotal, semsCount, LearnDomain, scscore.LearnDomainScore.Value);
                    }
                    //課程學習。
                    if (scscore.CourseLearnScore.HasValue)
                    {
                        SumDomainScore(domainTotal, semsCount, CourseLearning, scscore.CourseLearnScore.Value);
                    }
                }

                //計算總分的算數平均。
                //2017/5/9 穎驊修正 ,因應 高雄 [08-05][03] 畢業資格判斷成績及格標準調整 項目,
                // 領域 分數超過60分 ,以 四捨五入取到小數第二位 , 低於60分 採用 無條件進位至整數 (EX : 59.01 =60)
                // (只有高雄版有如此機制,新竹版照舊不管分數高低都是四捨五入)
                foreach (string strDomain in domainTotal.Keys)
                {
                    //學期數是「0」的不計算。
                    if (semsCount[strDomain] <= 0)
                    {
                        continue;
                    }

                    decimal score = 0;

                    if (JHEvaluation.ScoreCalculation.Program.Mode == JHEvaluation.ScoreCalculation.ModuleMode.HsinChu)
                    {
                        score = calcRule.ParseGraduateScore(domainTotal[strDomain] / semsCount[strDomain]);
                    }

                    if (JHEvaluation.ScoreCalculation.Program.Mode == JHEvaluation.ScoreCalculation.ModuleMode.KaoHsiung)
                    {
                        if ((domainTotal[strDomain] / semsCount[strDomain]) >= 60)
                        {
                            score = calcRule.ParseGraduateScore(domainTotal[strDomain] / semsCount[strDomain]);
                        }
                        else
                        {
                            score = Math.Ceiling(domainTotal[strDomain] / semsCount[strDomain]);
                        }
                    }



                    if (strDomain == LearnDomain)
                    {
                        student.GraduateScore.LearnDomainScore = score;
                    }
                    else if (strDomain == CourseLearning)
                    {
                        student.GraduateScore.CourseLearnScore = score;
                    }
                    else
                    {
                        if (!student.GraduateScore.Contains(strDomain))
                        {
                            student.GraduateScore.Add(strDomain, new GraduateScore());
                        }

                        student.GraduateScore[strDomain].Value = score;
                    }
                }
            }
        }
        public void Calculate()
        {
            foreach (StudentScore student in Students)
            {
                //成績計算規則。
                ScoreCalculator calcRule = student.CalculationRule;

                //沒有成績計算規則的不計算。
                if (calcRule == null)
                {
                    continue;
                }

                //領域總分。
                Dictionary <string, decimal> domainTotal = new Dictionary <string, decimal>();
                //學期數計數。
                Dictionary <string, decimal> semsCount = new Dictionary <string, decimal>();
                //計算六學期的總分。
                foreach (SemesterData sems in student.SHistory.GetGradeYearSemester())
                {
                    SemesterData sd = new SemesterData(0, sems.SchoolYear, sems.Semester);

                    //學生不包含該學期的成績,直接跳過。
                    if (!student.SemestersScore.Contains(sd))
                    {
                        continue;
                    }

                    //將該學期的成績資料取出。
                    SCSemsScore scscore = student.SemestersScore[sd];

                    //加總各領域成績。
                    foreach (string strDomain in scscore.Domain)
                    {
                        SCSemsDomainScore objDomain = scscore.Domain[strDomain];

                        if (!objDomain.Value.HasValue)
                        {
                            continue;                            //沒有成績不計算。
                        }
                        SumDomainScore(domainTotal, semsCount, strDomain, objDomain.Value.Value);
                    }
                    //學習領域。
                    if (scscore.LearnDomainScore.HasValue)
                    {
                        SumDomainScore(domainTotal, semsCount, LearnDomain, scscore.LearnDomainScore.Value);
                    }
                    //課程學習。
                    if (scscore.CourseLearnScore.HasValue)
                    {
                        SumDomainScore(domainTotal, semsCount, CourseLearning, scscore.CourseLearnScore.Value);
                    }
                }

                //計算總分的算數平均。
                foreach (string strDomain in domainTotal.Keys)
                {
                    //學期數是「0」的不計算。
                    if (semsCount[strDomain] <= 0)
                    {
                        continue;
                    }

                    decimal score = calcRule.ParseGraduateScore(domainTotal[strDomain] / semsCount[strDomain]);

                    if (strDomain == LearnDomain)
                    {
                        student.GraduateScore.LearnDomainScore = score;
                    }
                    else if (strDomain == CourseLearning)
                    {
                        student.GraduateScore.CourseLearnScore = score;
                    }
                    else
                    {
                        if (!student.GraduateScore.Contains(strDomain))
                        {
                            student.GraduateScore.Add(strDomain, new GraduateScore());
                        }

                        student.GraduateScore[strDomain].Value = score;
                    }
                }
            }
        }
        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
        }
Example #6
0
        /// <summary>
        /// 計算科目成績
        /// </summary>
        public void CalculateSubjectScore()
        {
            foreach (StudentScore student in Students)
            {
                if (student.CalculationRule == null)
                {
                    continue;                                  //沒有成績計算規則就不計算。
                }
                foreach (string subject in student.AttendScore)
                {
                    if (!IsValidItem(subject))
                    {
                        continue;                        //慮掉不算的科目。
                    }
                    AttendScore          attend   = student.AttendScore[subject];
                    SemesterSubjectScore SemsSubj = null;
                    SCSemsScore          Sems     = student.SemestersScore[SemesterData.Empty];

                    if (Sems.Subject.Contains(subject))
                    {
                        SemsSubj = Sems.Subject[subject];
                    }
                    else
                    {
                        SemsSubj = new SemesterSubjectScore();
                    }

                    if (attend.ToSemester) //列入學期成績。
                    {
                        //分數、權數都有資料才進行計算科目成績。
                        if (attend.Value.HasValue && attend.Weight.HasValue && attend.Period.HasValue)
                        {
                            decimal score = student.CalculationRule.ParseSubjectScore(attend.Value.Value); //進位處理。
                            SemsSubj.Value  = score;
                            SemsSubj.Weight = attend.Weight.Value;
                            SemsSubj.Period = attend.Period.Value;
                            SemsSubj.Effort = attend.Effort;
                            SemsSubj.Text   = attend.Text;
                            SemsSubj.Domain = attend.Domain;
                        }
                        else //資料不合理,保持原來的分數狀態。
                        {
                            continue;
                        }

                        if (!Sems.Subject.Contains(subject))
                        {
                            Sems.Subject.Add(subject, SemsSubj);
                        }
                    }
                    else
                    {
                        //不計入學期成績,就將其刪除掉。
                        if (Sems.Subject.Contains(subject))
                        {
                            Sems.Subject.Remove(subject);
                        }
                    }
                }
            }
        }