Ejemplo n.º 1
0
        public static Dictionary <string, decimal> CalculateSchoolYearEntryScore(this StudentRecord student, Dictionary <string, bool> calcEntry, Dictionary <string, bool> calcInStudy, int schoolyear, int gradeyear, WearyDogComputer.RoundMode mode, int decimals)
        {
            Dictionary <string, decimal> entryCalcScores = new Dictionary <string, decimal>();

            //學年科目成績的學分數
            Dictionary <string, decimal> subjectCreditCount = new Dictionary <string, decimal>();

            //各個分項成績的學分數
            Dictionary <string, decimal> entryCreditCount = new Dictionary <string, decimal>();

            //學年科目成績的各個科目成績列表
            Dictionary <string, List <decimal> > entrySubjectScores = new Dictionary <string, List <decimal> >();

            //學年科目成績的加權總計
            Dictionary <string, decimal> entryDividend = new Dictionary <string, decimal>();

            #region 加總學年科目成績對應到的學期科目成績,各個科目的學分數加總
            foreach (SemesterSubjectScoreInfo score in student.SemesterSubjectScoreList)
            {
                if (!subjectCreditCount.ContainsKey(score.Subject))
                {
                    subjectCreditCount.Add(score.Subject, 0);
                }
                subjectCreditCount[score.Subject] += score.CreditDec();
            }
            #endregion

            #region 計算該年級的分項成績
            //Dictionary<string, List<decimal>> entryScores = new Dictionary<string, List<decimal>>();

            //foreach (SemesterEntryScoreInfo score in Scores)
            //{
            //    if (calcEntry.ContainsKey(score.Entry) && score.SchoolYear <= schoolyear && score.GradeYear == gradeyear)
            //    {
            //        if (!entryScores.ContainsKey(score.Entry))
            //            entryScores.Add(score.Entry, new List<decimal>());
            //        entryScores[score.Entry].Add(score.Score);
            //    }
            //}

            //foreach (string key in entryScores.Keys)
            //{
            //    decimal sum = 0;
            //    decimal count = 0;
            //    foreach (decimal sc in entryScores[key])
            //    {
            //        sum += sc;
            //        count += 1;
            //    }
            //    if (count > 0)
            //        entryCalcScores.Add(key, WearyDogComputer.GetRoundScore(sum / count, decimals, mode));
            //}
            #endregion

            #region 將成績分到各分項類別中
            foreach (SchoolYearSubjectScoreInfo subjectNode in student.SchoolYearSubjectScoreList)
            {
                //if (subjectNode.SchoolYear == schoolyear && subjectNode.Semester == semester)
                //留意是==schoolyear或是<=schoolyear
                if (subjectNode.SchoolYear == schoolyear && subjectNode.GradeYear == gradeyear)
                {
                    //不計學分或不需評分不用算
                    //if (subjectNode.Detail.GetAttribute("不需評分") == "是" || subjectNode.Detail.GetAttribute("不計學分") == "是")
                    //    continue;
                    #region 分項類別跟學分數
                    //string entry = subjectNode.Detail.GetAttribute("開課分項類別");
                    //int credit = subjectNode.CreditDec();
                    decimal credit = subjectCreditCount.ContainsKey(subjectNode.Subject)?subjectCreditCount[subjectNode.Subject]:0;
                    #endregion
                    decimal maxScore = subjectNode.Score;
                    #region 取得最高分數
                    //decimal tryParseDecimal;
                    //if (decimal.TryParse(subjectNode.Detail.GetAttribute("原始成績"), out tryParseDecimal))
                    //    maxScore = tryParseDecimal;
                    //if (decimal.TryParse(subjectNode.Detail.GetAttribute("學年調整成績"), out tryParseDecimal) && maxScore < tryParseDecimal)
                    //    maxScore = tryParseDecimal;
                    //if (decimal.TryParse(subjectNode.Detail.GetAttribute("擇優採計成績"), out tryParseDecimal) && maxScore < tryParseDecimal)
                    //    maxScore = tryParseDecimal;
                    //if (decimal.TryParse(subjectNode.Detail.GetAttribute("補考成績"), out tryParseDecimal) && maxScore < tryParseDecimal)
                    //    maxScore = tryParseDecimal;
                    //if (decimal.TryParse(subjectNode.Detail.GetAttribute("重修成績"), out tryParseDecimal) && maxScore < tryParseDecimal)
                    //    maxScore = tryParseDecimal;
                    #endregion

                    //加總學分數
                    if (!entryCreditCount.ContainsKey("學業"))
                    {
                        entryCreditCount.Add("學業", credit);
                    }
                    else
                    {
                        entryCreditCount["學業"] += credit;
                    }
                    //加入將成績資料分項
                    if (!entrySubjectScores.ContainsKey("學業"))
                    {
                        entrySubjectScores.Add("學業", new List <decimal>());
                    }
                    entrySubjectScores["學業"].Add(maxScore);
                    //加權總計
                    if (!entryDividend.ContainsKey("學業"))
                    {
                        entryDividend.Add("學業", maxScore * credit);
                    }
                    else
                    {
                        entryDividend["學業"] += (maxScore * credit);
                    }

                    //switch (entry)
                    //{
                    //    case "體育":
                    //    case "國防通識":
                    //    case "健康與護理":
                    //    case "實習科目":
                    //        //計算分項成績
                    //        if (calcEntry[entry])
                    //        {
                    //            //加總學分數
                    //            if (!entryCreditCount.ContainsKey(entry))
                    //                entryCreditCount.Add(entry, credit);
                    //            else
                    //                entryCreditCount[entry] += credit;
                    //            //加入將成績資料分項
                    //            if (!entrySubjectScores.ContainsKey(entry)) entrySubjectScores.Add(entry, new List<decimal>());
                    //            entrySubjectScores[entry].Add(maxScore);
                    //            //加權總計
                    //            if (!entryDividend.ContainsKey(entry))
                    //                entryDividend.Add(entry, maxScore * credit);
                    //            else
                    //                entryDividend[entry] += (maxScore * credit);
                    //        }
                    //        //將科目成績與學業成績一併計算
                    //        if (calcInStudy[entry])
                    //        {
                    //            //加總學分數
                    //            if (!entryCreditCount.ContainsKey("學業"))
                    //                entryCreditCount.Add("學業", credit);
                    //            else
                    //                entryCreditCount["學業"] += credit;
                    //            //加入將成績資料分項
                    //            if (!entrySubjectScores.ContainsKey("學業")) entrySubjectScores.Add("學業", new List<decimal>());
                    //            entrySubjectScores["學業"].Add(maxScore);
                    //            //加權總計
                    //            if (!entryDividend.ContainsKey("學業"))
                    //                entryDividend.Add("學業", maxScore * credit);
                    //            else
                    //                entryDividend["學業"] += (maxScore * credit);
                    //        }
                    //        break;

                    //    case "學業":
                    //    default:
                    //        //加總學分數
                    //        if (!entryCreditCount.ContainsKey("學業"))
                    //            entryCreditCount.Add("學業", credit);
                    //        else
                    //            entryCreditCount["學業"] += credit;
                    //        //加入將成績資料分項
                    //        if (!entrySubjectScores.ContainsKey("學業")) entrySubjectScores.Add("學業", new List<decimal>());
                    //        entrySubjectScores["學業"].Add(maxScore);
                    //        //加權總計
                    //        if (!entryDividend.ContainsKey("學業"))
                    //            entryDividend.Add("學業", maxScore * credit);
                    //        else
                    //            entryDividend["學業"] += (maxScore * credit);
                    //        break;
                    //}
                }
            }
            #endregion
            #region 處理計算各分項類別的成績
            foreach (string entry in entryCreditCount.Keys)
            {
                decimal entryScore = 0;
                #region 計算entryScore
                if (entryCreditCount[entry] == 0)
                {
                    foreach (decimal score in entrySubjectScores[entry])
                    {
                        entryScore += score;
                    }
                    entryScore = (entryScore / entrySubjectScores[entry].Count);
                }
                else
                {
                    //用加權總分除學分數
                    entryScore = (entryDividend[entry] / entryCreditCount[entry]);
                }
                #endregion
                //精準位數處理
                entryScore = WearyDogComputer.GetRoundScore(entryScore, decimals, mode);
                #region 填入EntryScores
                entryCalcScores.Add(entry, entryScore);
                #endregion
            }
            #endregion

            return(entryCalcScores);
        }
Ejemplo n.º 2
0
        public XmlElement CalculateSemesterEntryScore(XmlElement semesterSubjectScore)
        {
            Dictionary <string, decimal>         entryCreditCount   = new Dictionary <string, decimal>();
            Dictionary <string, List <decimal> > entrySubjectScores = new Dictionary <string, List <decimal> >();
            Dictionary <string, decimal>         entryDividend      = new Dictionary <string, decimal>();
            Dictionary <string, bool>            calcEntry          = new Dictionary <string, bool>();
            Dictionary <string, bool>            calcInStudy        = new Dictionary <string, bool>();
            List <string> takeScore = new List <string>();
            //精準位數
            int decimals = 2;

            //進位模式
            WearyDogComputer.RoundMode mode = WearyDogComputer.RoundMode.四捨五入;
            //成績年級及計算規則皆存在,允許計算成績
            bool canCalc = true;

            #region 取得成績年級跟計算規則

            #region 處理計算規則
            XmlElement scoreCalcRule = (XmlElement)_ScoreCalcRuleElement;//ScoreCalcRule.ScoreCalcRule.Instance.GetStudentScoreCalcRuleInfo(var.StudentID) == null ? null : ScoreCalcRule.ScoreCalcRule.Instance.GetStudentScoreCalcRuleInfo(var.StudentID).ScoreCalcRuleElement;

            DSXmlHelper helper = new DSXmlHelper(scoreCalcRule);
            bool        tryParsebool;
            int         tryParseint;
            decimal     tryParseDecimal;

            #region 精準位數
            if (scoreCalcRule.SelectSingleNode("各項成績計算位數/學期分項成績計算位數") != null)
            {
                if (int.TryParse(helper.GetText("各項成績計算位數/學期分項成績計算位數/@位數"), out tryParseint))
                {
                    decimals = tryParseint;
                }
                if (bool.TryParse(helper.GetText("各項成績計算位數/學期分項成績計算位數/@四捨五入"), out tryParsebool) && tryParsebool)
                {
                    mode = WearyDogComputer.RoundMode.四捨五入;
                }
                if (bool.TryParse(helper.GetText("各項成績計算位數/學期分項成績計算位數/@無條件捨去"), out tryParsebool) && tryParsebool)
                {
                    mode = WearyDogComputer.RoundMode.無條件捨去;
                }
                if (bool.TryParse(helper.GetText("各項成績計算位數/學期分項成績計算位數/@無條件進位"), out tryParsebool) && tryParsebool)
                {
                    mode = WearyDogComputer.RoundMode.無條件進位;
                }
            }
            #endregion
            #region 計算類別
            foreach (string entry in new string[] { "體育", "學業", "國防通識", "健康與護理", "實習科目", "專業科目" })
            {
                if (scoreCalcRule.SelectSingleNode("分項成績計算項目") == null || scoreCalcRule.SelectSingleNode("分項成績計算項目/" + entry) == null || ((XmlElement)scoreCalcRule.SelectSingleNode("分項成績計算項目/" + entry)).GetAttribute("計算成績") == "True")
                {
                    calcEntry.Add(entry, true);
                }
                else
                {
                    calcEntry.Add(entry, false);
                }

                // 2014/3/20,修改當沒有勾選 預設併入學期學業成績 ChenCT
                if (scoreCalcRule.SelectSingleNode("分項成績計算項目") == null || scoreCalcRule.SelectSingleNode("分項成績計算項目/" + entry) == null || ((XmlElement)scoreCalcRule.SelectSingleNode("分項成績計算項目/" + entry)).GetAttribute("併入學期學業成績") == "True")
                {
                    calcInStudy.Add(entry, true);
                }
                else
                {
                    calcInStudy.Add(entry, false);
                }
            }
            #endregion
            #region 採計成績欄位
            foreach (string item in new string[] { "原始成績", "補考成績", "重修成績", "擇優採計成績", "學年調整成績" })
            {
                if (!bool.TryParse(helper.GetText("分項成績計算採計成績欄位/@" + item), out tryParsebool) || tryParsebool)
                {//沒有設定這項成績設定規則(預設true)或者設定值是true
                    takeScore.Add(item);
                }
            }
            #endregion

            #endregion

            #endregion
            Dictionary <string, decimal> entryScores = new Dictionary <string, decimal>();

            #region 將成績分到各分項類別中
            foreach (XmlNode subjectNode in semesterSubjectScore.SelectNodes("Subject"))
            {
                XmlElement subjectElement = (XmlElement)subjectNode;
                //不計學分或不需評分不用算
                if (subjectElement.GetAttribute("不需評分") == "是" || subjectElement.GetAttribute("不計學分") == "是")
                {
                    continue;
                }
                #region 分項類別跟學分數
                string  entry  = subjectElement.GetAttribute("開課分項類別");
                decimal credit = 0;
                decimal.TryParse(subjectElement.GetAttribute("開課學分數"), out credit);
                #endregion
                decimal maxScore = 0;
                decimal original = 0;
                if (decimal.TryParse(subjectElement.GetAttribute("原始成績"), out tryParseDecimal))
                {
                    original = tryParseDecimal;
                }
                #region 取得最高分數
                foreach (var item in takeScore)
                {
                    if (decimal.TryParse(subjectElement.GetAttribute(item), out tryParseDecimal) && maxScore < tryParseDecimal)
                    {
                        maxScore = tryParseDecimal;
                    }
                }
                #endregion
                switch (entry)
                {
                case "體育":
                case "國防通識":
                case "健康與護理":
                case "實習科目":
                case "專業科目":
                    //計算分項成績
                    if (calcEntry[entry])
                    {
                        #region original
                        //加總學分數
                        if (!entryCreditCount.ContainsKey(entry + "(原始)"))
                        {
                            entryCreditCount.Add(entry + "(原始)", credit);
                        }
                        else
                        {
                            entryCreditCount[entry + "(原始)"] += credit;
                        }
                        //加入將成績資料分項
                        if (!entrySubjectScores.ContainsKey(entry + "(原始)"))
                        {
                            entrySubjectScores.Add(entry + "(原始)", new List <decimal>());
                        }
                        entrySubjectScores[entry + "(原始)"].Add(original);
                        //加權總計
                        if (!entryDividend.ContainsKey(entry + "(原始)"))
                        {
                            entryDividend.Add(entry + "(原始)", original * credit);
                        }
                        else
                        {
                            entryDividend[entry + "(原始)"] += (original * credit);
                        }
                        #endregion
                        #region maxScore
                        //加總學分數
                        if (!entryCreditCount.ContainsKey(entry))
                        {
                            entryCreditCount.Add(entry, credit);
                        }
                        else
                        {
                            entryCreditCount[entry] += credit;
                        }
                        //加入將成績資料分項
                        if (!entrySubjectScores.ContainsKey(entry))
                        {
                            entrySubjectScores.Add(entry, new List <decimal>());
                        }
                        entrySubjectScores[entry].Add(maxScore);
                        //加權總計
                        if (!entryDividend.ContainsKey(entry))
                        {
                            entryDividend.Add(entry, maxScore * credit);
                        }
                        else
                        {
                            entryDividend[entry] += (maxScore * credit);
                        }
                        #endregion
                    }
                    //將科目成績與學業成績一併計算
                    if (calcInStudy[entry])
                    {
                        #region original
                        //加總學分數
                        if (!entryCreditCount.ContainsKey("學業" + "(原始)"))
                        {
                            entryCreditCount.Add("學業" + "(原始)", credit);
                        }
                        else
                        {
                            entryCreditCount["學業" + "(原始)"] += credit;
                        }
                        //加入將成績資料分項
                        if (!entrySubjectScores.ContainsKey("學業" + "(原始)"))
                        {
                            entrySubjectScores.Add("學業" + "(原始)", new List <decimal>());
                        }
                        entrySubjectScores["學業" + "(原始)"].Add(original);
                        //加權總計
                        if (!entryDividend.ContainsKey("學業" + "(原始)"))
                        {
                            entryDividend.Add("學業" + "(原始)", original * credit);
                        }
                        else
                        {
                            entryDividend["學業" + "(原始)"] += (original * credit);
                        }
                        #endregion
                        #region maxScore
                        //加總學分數
                        if (!entryCreditCount.ContainsKey("學業"))
                        {
                            entryCreditCount.Add("學業", credit);
                        }
                        else
                        {
                            entryCreditCount["學業"] += credit;
                        }
                        //加入將成績資料分項
                        if (!entrySubjectScores.ContainsKey("學業"))
                        {
                            entrySubjectScores.Add("學業", new List <decimal>());
                        }
                        entrySubjectScores["學業"].Add(maxScore);
                        //加權總計
                        if (!entryDividend.ContainsKey("學業"))
                        {
                            entryDividend.Add("學業", maxScore * credit);
                        }
                        else
                        {
                            entryDividend["學業"] += (maxScore * credit);
                        }
                        #endregion
                    }
                    break;

                case "學業":
                default:
                    #region original
                    //加總學分數
                    if (!entryCreditCount.ContainsKey("學業" + "(原始)"))
                    {
                        entryCreditCount.Add("學業" + "(原始)", credit);
                    }
                    else
                    {
                        entryCreditCount["學業" + "(原始)"] += credit;
                    }
                    //加入將成績資料分項
                    if (!entrySubjectScores.ContainsKey("學業" + "(原始)"))
                    {
                        entrySubjectScores.Add("學業" + "(原始)", new List <decimal>());
                    }
                    entrySubjectScores["學業" + "(原始)"].Add(original);
                    //加權總計
                    if (!entryDividend.ContainsKey("學業" + "(原始)"))
                    {
                        entryDividend.Add("學業" + "(原始)", original * credit);
                    }
                    else
                    {
                        entryDividend["學業" + "(原始)"] += (original * credit);
                    }
                    #endregion
                    #region maxScore
                    //加總學分數
                    if (!entryCreditCount.ContainsKey("學業"))
                    {
                        entryCreditCount.Add("學業", credit);
                    }
                    else
                    {
                        entryCreditCount["學業"] += credit;
                    }
                    //加入將成績資料分項
                    if (!entrySubjectScores.ContainsKey("學業"))
                    {
                        entrySubjectScores.Add("學業", new List <decimal>());
                    }
                    entrySubjectScores["學業"].Add(maxScore);
                    //加權總計
                    if (!entryDividend.ContainsKey("學業"))
                    {
                        entryDividend.Add("學業", maxScore * credit);
                    }
                    else
                    {
                        entryDividend["學業"] += (maxScore * credit);
                    }
                    #endregion
                    break;
                }
            }
            #endregion

            XmlDocument doc            = new XmlDocument();
            XmlElement  entryScoreRoot = doc.CreateElement("SemesterEntryScore");
            #region 處理計算各分項類別的成績
            foreach (string entry in entryCreditCount.Keys)
            {
                decimal entryScore = 0;
                #region 計算entryScore
                if (entryCreditCount[entry] == 0)
                {
                    foreach (decimal score in entrySubjectScores[entry])
                    {
                        entryScore += score;
                    }
                    entryScore = (entryScore / entrySubjectScores[entry].Count);
                }
                else
                {
                    //用加權總分除學分數
                    entryScore = (entryDividend[entry] / entryCreditCount[entry]);
                }
                #endregion
                //精準位數處理
                entryScore = WearyDogComputer.GetRoundScore(entryScore, decimals, mode);
                #region 填入Xml
                XmlElement entryElement = doc.CreateElement("Entry");
                entryElement.SetAttribute("分項", entry);
                entryElement.SetAttribute("成績", entryScore.ToString());
                entryScoreRoot.AppendChild(entryElement);
                #endregion
            }
            #endregion
            return(entryScoreRoot);
        }