示例#1
0
        public static decimal GetAverage(int subject_id)
        {
            decimal      allclassworks         = 0;
            decimal      allnormaltests        = 0;
            decimal      average               = 0;
            decimal      allclassworksaverage  = 0;
            decimal      allnormaltestsaverage = 0;
            List <Grade> classwork_list        = new List <Grade> {
            };
            List <Grade> normaltest_list       = new List <Grade> {
            };

            Subject actual_subject = SubjectManager.GetSubject(subject_id);

            foreach (Grade grade in actual_subject.grades)
            {
                if (grade.type.typename == "classwork")
                {
                    classwork_list.Add(grade);
                }
                if (grade.type.typename == "normaltest")
                {
                    normaltest_list.Add(grade);
                }
            }

            foreach (Grade grade in classwork_list)
            {
                allclassworks += grade.grade;
            }
            foreach (Grade grade in normaltest_list)
            {
                allnormaltests += grade.grade;
            }

            if (allclassworks != 0)
            {
                allclassworksaverage = allclassworks / classwork_list.Count();
            }
            if (allnormaltests != 0)
            {
                allnormaltestsaverage = allnormaltests / normaltest_list.Count();
            }

            if (allclassworksaverage != 0 && allnormaltestsaverage != 0)
            {
                average = (allclassworksaverage + allnormaltestsaverage) / 2;
            }
            else
            {
                if (allclassworksaverage == 0 && allnormaltestsaverage != 0)
                {
                    average = allnormaltestsaverage;
                }
                if (allnormaltestsaverage == 0 && allclassworksaverage != 0)
                {
                    average = allclassworksaverage;
                }
            }

            average = Math.Round(average, 2);

            return(average);
        }
示例#2
0
 public SubjectDetail()
 {
     this.InitializeComponent();
     subject_to_show = SubjectManager.GetSubject(SubjectManager.selected_subject_id);
 }