Esempio n. 1
0
        /// <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
            }
        }
        private static Dictionary <string, SubjectScore> ToSubjects(SemesterSubjectScoreCollection semesterSubjectScoreCollection)
        {
            Dictionary <string, SubjectScore> dictSubjectScore = new Dictionary <string, SubjectScore>();

            foreach (string key in semesterSubjectScoreCollection)
            {
                SemesterSubjectScore score        = semesterSubjectScoreCollection[key];
                SubjectScore         subjectScore = new SubjectScore();
                subjectScore.Domain  = score.Domain;
                subjectScore.Subject = key;
                subjectScore.Period  = score.Period;
                subjectScore.Credit  = score.Weight;
                subjectScore.Score   = score.Value;
                dictSubjectScore.Add(subjectScore.Subject, subjectScore);
            }

            return(dictSubjectScore);
        }
Esempio n. 3
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);
                        }
                    }
                }
            }
        }
Esempio n. 4
0
        /// <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);
                }
            }
        }
Esempio n. 5
0
        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
        }
Esempio n. 6
0
        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
        }
Esempio n. 7
0
        /// <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);
                }
            }
        }
Esempio n. 8
0
        /// <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
            }
        }
Esempio n. 9
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);
                        }
                    }
                }
            }
        }
Esempio n. 10
0
 private void RefineDomain(SemesterSubjectScore subject)
 {
     if (subject.Domain.Trim() == "彈性課程")
         subject.Domain = string.Empty;
 }