/// <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);
        }
        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));
            }
        }
Exemple #3
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);
        }