Exemple #1
0
        public decimal?GetScore(RatingStudent student)
        {
            ItemWeightCollection exists = new ItemWeightCollection();

            foreach (string each in Items.Keys)
            {
                if (student.Scores[ThisToken].Contains(each))
                {
                    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));
            }
        }
Exemple #2
0
        /// <summary>
        /// 把使用者已選擇的科目資訊(權重)更新到 SelectedSubjects 變數。
        /// </summary>
        /// <returns>true 為資料正確沒有發生任何錯誤。</returns>
        private bool RefreshSelectedSubjects()
        {
            bool result = true;

            SelectedSubjects = 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  subject   = "" + each.Cells[chSubject.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;
                        SelectedSubjects.Add(subject, period);
                    }
                    else
                    {
                        each.Cells[chPeriod.Index].ErrorText = "計算比例必須是大於 0 的數字。";
                        result = false;
                    }
                }
            }

            return(result);
        }
Exemple #3
0
 /// <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;
     ThisToken     = token;
 }
Exemple #4
0
        private decimal 合計總分(RatingStudent student, ItemWeightCollection exists)
        {
            decimal sum = 0;

            foreach (string each in exists.Keys)
            {
                sum += student.Scores[ThisToken][each];
            }

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

            foreach (string each in exists.Keys)
            {
                sum += student.Scores[ThisToken][each];
            }

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

            foreach (string each in exists.Keys)
            {
                sum += (student.Scores[ThisToken][each] * exists[each]);
            }

            return(Round(sum / weight));
        }
Exemple #7
0
        /// <summary>
        /// 把使用者已選擇的科目資訊(權重)更新到 SelectedSubjects 變數。
        /// </summary>
        /// <returns>true 為資料正確沒有發生任何錯誤。</returns>
        private bool RefreshSelectedSubjects()
        {
            bool result = true;

            SelectedSubjects = 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 subject = "" + each.Cells[chSubject.Index].Value;
                    SelectedSubjects.Add(subject, 1);
                    result = true;
                }
            }

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