public decimal?GetScore(RatingStudent student)
        {
            ItemWeightCollection exists = new ItemWeightCollection();

            foreach (ScoreItem each in Items)
            {
                if (student.Scores[each.Regulation(Token)].Contains(each.Name))
                {
                    exists.Add(each, Items[each]);
                }
            }

            if (exists.Count <= 0)
            {
                return(null);
            }

            if (Method == CalcMethod.加權平均)
            {
                return(加權平均(student, exists));
            }
            else if (Method == CalcMethod.加權總分)
            {
                return(加權總分(student, exists));
            }
            else if (Method == CalcMethod.合計總分)
            {
                return(合計總分(student, exists));
            }
            else
            {
                return(算術平均(student, exists));
            }
        }
        /// <summary>
        /// 把使用者已選擇的科目資訊(權重)更新到 SelectedSubjects 變數。
        /// </summary>
        /// <returns>true 為資料正確沒有發生任何錯誤。</returns>
        private bool RefreshSelectedItems()
        {
            bool result = true;

            SelectedItems = new ItemWeightCollection();
            foreach (DataGridViewRow each in dgv.Rows)
            {
                if (each.IsNewRow)
                {
                    continue;
                }
                string value = "" + each.Cells[chCheck.Index].Value;
                bool   b;
                if (bool.TryParse(value, out b) && b == true)
                {
                    string  domain    = "" + each.Cells[chScoreItem.Index].Value;
                    string  strPeriod = "" + each.Cells[chPeriod.Index].Value;
                    decimal period;

                    if (decimal.TryParse(strPeriod, out period) && period > 0)
                    {
                        each.Cells[chPeriod.Index].ErrorText = string.Empty;
                        ScoreItem item = (ScoreItem)each.Tag;
                        SelectedItems.Add(item, period);
                    }
                    else
                    {
                        each.Cells[chPeriod.Index].ErrorText = "計算比例必須是大於 0 的數字。";
                        result = false;
                    }
                }
            }

            return(result);
        }
        private decimal 算術平均(RatingStudent student, ItemWeightCollection exists)
        {
            decimal sum = 0, weight = exists.Count;

            foreach (ScoreItem each in exists)
            {
                sum += student.Scores[each.Regulation(Token)][each.Name];
            }

            return(Round(sum / weight));
        }
        private decimal 加權平均(RatingStudent student, ItemWeightCollection exists)
        {
            decimal sum = 0, weight = exists.GetWeightSum();

            foreach (ScoreItem each in exists)
            {
                sum += (student.Scores[each.Regulation(Token)][each.Name] * exists[each]);
            }

            return(Round(sum / weight));
        }
        private decimal 加權總分(RatingStudent student, ItemWeightCollection exists)
        {
            decimal sum = 0;

            foreach (ScoreItem each in exists)
            {
                sum += (student.Scores[each.Regulation(Token)][each.Name] * exists[each]);
            }

            return(sum);
        }
 /// <summary>
 ///
 /// </summary>
 /// <param name="name"></param>
 /// <param name="items"></param>
 /// <param name="method"></param>
 /// <param name="round">計算到小數第幾位。</param>
 public CalculationScoreParser(string name,
                               ItemWeightCollection items,
                               CalcMethod method,
                               int round,
                               string token)
 {
     Name          = name;
     Items         = items;
     Method        = method;
     RoundPosition = round;
     Token         = token;
 }
Beispiel #7
0
        /// <summary>
        /// 把使用者已選擇的科目資訊(權重)更新到 SelectedSubjects 變數。
        /// </summary>
        /// <returns>true 為資料正確沒有發生任何錯誤。</returns>
        private bool RefreshSelectedItems()
        {
            bool result = true;

            SelectedItems = new ItemWeightCollection();
            foreach (DataGridViewRow each in dgv.Rows)
            {
                if (each.IsNewRow)
                {
                    continue;
                }
                string value = "" + each.Cells[chCheck.Index].Value;
                bool   b;
                if (bool.TryParse(value, out b) && b == true)
                {
                    string    scoreName = "" + each.Cells[chScoreItem.Index].Value;
                    ScoreItem si        = (ScoreItem)each.Tag;
                    SelectedItems.Add(si, 1);
                    result = true;
                }
            }

            return(result);
        }
Beispiel #8
0
 public static CalculationScoreParser ToCalcScoreParser(this ItemWeightCollection subjects, string name, CalculationScoreParser.CalcMethod calcMethod, int round, string token)
 {
     return(new CalculationScoreParser(name, subjects, calcMethod, round, token));
 }