Ejemplo n.º 1
0
        public void CalculateScore()
        {
            if (Course.ExamTemplate == null)
            {
                return;
            }

            if (!Course.ExamRequired)
            {
                return;
            }

            //AllowUpload 為 True 時,略過成績計算,因為成績是由老師提供。
            if (Course.ExamTemplate.AllowUpload)
            {
                return;
            }

            decimal total = 0;

            foreach (TEInclude exam in Course.RefExams)
            {
                decimal score = 0;
                if (SCETakes.ContainsKey(exam.ExamId))
                {
                    SCETake take = SCETakes[exam.ExamId];
                    if (!decimal.TryParse(take.Score, out score)) //如果缺考會 0 分處理。
                    {
                        _contains_lack = true;
                    }
                }
                else
                {
                    _contains_lack = true;
                }

                total += (score * ((decimal)exam.Weight / 100m));
            }

            //SetScore(Math.Round(total, 2).ToString());
            SetScore(total.ToString());
        }
Ejemplo n.º 2
0
        public void CalculateScore()
        {
            if (Course.ExamTemplate == null)
            {
                return;
            }

            if (!Course.ExamRequired)
            {
                return;
            }

            //AllowUpload 為 True 時,略過成績計算,因為成績是由老師提供。
            //if (Course.ExamTemplate.AllowUpload)
            //    return;

            decimal total        = 0;
            int     effort_total = 0;
            int     effort_count = 0;
            bool    hasScore     = false;
            bool    hasEffort    = false;

            if (new List <TEInclude>(Course.RefExams).Count == 0)
            {
                _no_exam = true;
                return;
            }

            foreach (TEInclude exam in Course.RefExams)
            {
                decimal score  = 0;
                int     effort = 0;
                if (SCETakes.ContainsKey(exam.ExamId))
                {
                    SCETake take = SCETakes[exam.ExamId];

                    if (exam.UseScore)
                    {
                        if (!decimal.TryParse(take.Score, out score))
                        {
                            _contains_lack = true;
                            SetScoreLack(exam.ExamName);
                        }
                        else
                        {
                            total   += (score * ((decimal)exam.Weight / 100m));
                            hasScore = true;
                        }
                    }

                    if (exam.UseEffort)
                    {
                        if (!int.TryParse(take.Effort, out effort))
                        {
                            _contains_lack = true;
                            SetEffortLack(exam.ExamName);
                        }
                        else
                        {
                            effort_count++;
                            effort_total += effort;
                            hasEffort     = true;
                        }
                    }
                }
                else
                {
                    if (exam.UseScore)
                    {
                        _contains_lack = true;
                        SetScoreLack(exam.ExamName);
                    }
                    if (exam.UseEffort)
                    {
                        _contains_lack = true;
                        SetEffortLack(exam.ExamName);
                    }
                }
            }

            //SetScore(Math.Round(total, 2).ToString());
            if (hasScore)
            {
                SetScore(total.ToString());
            }
            if (hasEffort)
            {
                SetEffort("");
                if (effort_count > 0)
                {
                    SetEffort("" + (effort_total / effort_count));
                }
            }
        }