Exemplo n.º 1
0
        /*
         * EventName: btnFailResults_Click
         * Summary: Prints the Pass report of the requested course, with threshold above or below the grade selected.
         */
        private void btnPassReport_Click(object sender, EventArgs e)
        {
            rtbResults.Clear();
            tbZid.Clear();
            cmbThreshGrade.SelectedIndex = -1;
            tbThreshCour.Clear();
            cmbFMajor.SelectedIndex = -1;
            tbFailCour.Clear();
            textBox3.Clear();
            nudPercent.Value = 0;
            Program       p             = new Program();
            string        grade         = cmbPassGrade.Text.ToUpper();
            var           passStudents  = new ListWithDuplicates(); //store percentage of passed students in each course
            var           totalStudents = new ListWithDuplicates();
            var           percentages   = new ListWithDup();
            var           output        = new ListWithDup();
            int           index         = 0;
            List <Grades> passGrades    = new List <Grades>();
            List <string> dis_grades    = new List <string>();
            List <string> thresh_grades = new List <string>();

            dis_grades.AddRange(new string[] { "A", "A-", "B+", "B", "B-", "C++", "C", "C-", "D" });
            List <string> coursename    = new List <string>();
            List <string> distinct_cour = new List <string>();
            int           percent       = Convert.ToInt32(nudPercent.Value);
            List <string> gr            = new List <string>();

            for (int i = 0; i < p.NewGrades.Count; i++)
            {
                string c = p.NewGrades[i].Major + "-" + p.NewGrades[i].Cnum;
                coursename.Add(c);
            }
            distinct_cour = coursename.Distinct().ToList();


            if (rbPLess.Checked)
            {
                index = dis_grades.FindIndex(a => a == grade);               //query to find the grade which the user wants.
                for (int i = index; i < dis_grades.Count; i++)
                {
                    thresh_grades.Add(dis_grades[i]);                               //consider all the grades less than the requested grade
                }
                var result = from g in p.NewGrades orderby g.Major, g.Cnum select g;
                var groupedresult = from s in result
                                    group s by new { s.Major, s.Cnum };
                var pStudents = from g in groupedresult                         //counting the number of failures for each course
                                select new { Course = g.Key, totalcount = g.Count(S => thresh_grades.Contains(S.Grade)) };
                foreach (var i in pStudents)
                {
                    passStudents.Add(i.Course.ToString(), i.totalcount);
                }
                var tStudents = from g in groupedresult
                                select new { Course = g.Key, totalcount = g.Count() };
                foreach (var j in tStudents)
                {
                    totalStudents.Add(j.Course.ToString(), j.totalcount);
                }

                for (int i = 0; i < passStudents.Count; i++)
                {
                    int   pcount     = passStudents[i].Value;
                    int   tcount     = totalStudents[i].Value;
                    float percentage = ((float)pcount / (float)tcount) * 100;
                    percentages.Combine(passStudents[i].Key, (float)Math.Round(percentage, 2));
                    string res = "Out of " + tcount + " enrolled in " + distinct_cour[i] + ", " + pcount + " passed at or below this threshold (" + (float)Math.Round(percentage, 2) + "% )";
                    output.Combine(res, (float)Math.Round(percentage, 2));
                }

                int nor = 0;
                rtbResults.AppendText("Fail Percentage (<= " + grade + ") Report for Classes." + "\n-----------------------------------------------\n");
                for (int i = 0; i < output.Count; i++)
                {
                    if (output[i].Value != 0)
                    {
                        rtbResults.AppendText(output[i].Key + "\n\n");
                        nor++;
                    }
                }
                if (nor == 0)
                {
                    rtbResults.AppendText("No courses matched the query criteria.");
                }
                else
                {
                    rtbResults.AppendText("\n###END RESULTS###");
                }
            }
            else if (rbPGreater.Checked)
            {
                index = dis_grades.FindIndex(a => a == grade);               //query to find the grade which the user wants.
                for (int i = index; i >= 0; i--)
                {
                    thresh_grades.Add(dis_grades[i]);                               //consider all the grades greater than the requested grade
                }

                var result = from g in p.NewGrades orderby g.Major, g.Cnum select g;
                var groupedresult = from s in result
                                    group s by new { s.Major, s.Cnum };
                var pStudents = from g in groupedresult                         //counting the number of passedstudents for each course
                                select new { Course = g.Key, totalcount = g.Count(S => thresh_grades.Contains(S.Grade)) };

                foreach (var i in pStudents)
                {
                    passStudents.Add(i.Course.ToString(), i.totalcount);
                }
                var tStudents = from g in groupedresult
                                select new { Course = g.Key, totalcount = g.Count() };
                foreach (var j in tStudents)
                {
                    totalStudents.Add(j.Course.ToString(), j.totalcount);
                }


                for (int i = 0; i < passStudents.Count; i++)
                {
                    int   pcount     = passStudents[i].Value;
                    int   tcount     = totalStudents[i].Value;
                    float percentage = ((float)pcount / (float)tcount) * 100;
                    percentages.Combine(passStudents[i].Key, (float)Math.Round(percentage, 2));
                    string res = "Out of " + tcount + " enrolled in " + distinct_cour[i] + ", " + pcount + " passed at or above this threshold (" + (float)Math.Round(percentage, 2) + "% )";
                    output.Combine(res, (float)Math.Round(percentage, 2));
                }

                int nor = 0;
                rtbResults.AppendText("Fail Percentage (>= " + grade + ") Report for Classes." + "\n-----------------------------------------------\n");
                for (int i = 0; i < output.Count; i++)
                {
                    if (output[i].Value != 0)
                    {
                        rtbResults.AppendText(output[i].Key + "\n\n");
                        nor++;
                    }
                }
                if (nor == 0)
                {
                    rtbResults.AppendText("No courses matched the query criteria");
                }
                else
                {
                    rtbResults.AppendText("\n###END RESULTS###");
                }
            }
            else
            {
                MessageBox.Show("Please select one of the threshold's (from the radio buttons)");
            }
        }
Exemplo n.º 2
0
        /*
         * EventName: btnFailResults_Click
         * Summary: Prints the Fail report of the requested course, with threshold above or below the percentage given.
         */
        private void btnFailResults_Click(object sender, EventArgs e)
        {
            rtbResults.Clear();
            tbZid.Clear();
            cmbThreshGrade.SelectedIndex = -1;
            tbThreshCour.Clear();
            cmbFMajor.SelectedIndex = -1;
            tbFailCour.Clear();
            textBox3.Clear();
            cmbPassGrade.SelectedIndex = -1;
            Program p             = new Program();
            var     failStudents  = new ListWithDuplicates(); //store percentage of failures in each course
            var     totalStudents = new ListWithDuplicates();
            var     percentages   = new ListWithDup();
            var     output        = new ListWithDup();

            List <string> coursename    = new List <string>();
            List <string> distinct_cour = new List <string>();
            int           percent       = Convert.ToInt32(nudPercent.Value);
            List <string> gr            = new List <string>();

            for (int i = 0; i < p.NewGrades.Count; i++)
            {
                string c = p.NewGrades[i].Major + "-" + p.NewGrades[i].Cnum;
                coursename.Add(c);
            }
            distinct_cour = coursename.Distinct().ToList();

            var result = from g in p.NewGrades orderby g.Major, g.Cnum select g;
            var groupedresult = from s in result
                                group s by new { s.Major, s.Cnum };

            var fStudents = from g in groupedresult                         //counting the number of failures for each course
                            select new { Course = g.Key, totalcount = g.Count(S => S.Grade == "F") };

            foreach (var i in fStudents)
            {
                failStudents.Add(i.Course.ToString(), i.totalcount);
            }

            var tStudents = from g in groupedresult
                            select new { Course = g.Key, totalcount = g.Count() };

            foreach (var j in tStudents)
            {
                totalStudents.Add(j.Course.ToString(), j.totalcount);
            }

            for (int i = 0; i < failStudents.Count; i++)
            {
                int   fcount     = failStudents[i].Value;
                int   tcount     = totalStudents[i].Value;
                float percentage = ((float)fcount / (float)tcount) * 100;
                percentages.Combine(failStudents[i].Key, (float)Math.Round(percentage, 2));
                string res = "Out of " + tcount + " enrolled in " + distinct_cour[i] + ", " + fcount + " failed (" + (float)Math.Round(percentage, 2) + "% )";
                output.Combine(res, (float)Math.Round(percentage, 2));
            }

            if (rbFLess.Checked)
            {
                int nor = 0;
                rtbResults.AppendText("Fail Percentage (<= " + percent + "%) Report for Classes." + "\n-----------------------------------------------\n");
                for (int i = 0; i < output.Count; i++)
                {
                    if (output[i].Value <= (float)percent && output[i].Value != 0)
                    {
                        rtbResults.AppendText(output[i].Key + "\n\n");
                        nor++;
                    }
                }
                if (nor == 0)
                {
                    rtbResults.AppendText("No courses matched the query criteria.");
                }
                else
                {
                    rtbResults.AppendText("\n###END RESULTS###");
                }
            }
            else if (rbFGreater.Checked)
            {
                int nor = 0;
                rtbResults.AppendText("Fail Percentage (>= " + percent + "%) Report for Classes." + "\n-----------------------------------------------\n");
                for (int i = 0; i < output.Count; i++)
                {
                    if (output[i].Value >= (float)percent && output[i].Value != 0)
                    {
                        nor++;
                        rtbResults.AppendText(output[i].Key + "\n\n");
                    }
                }
                if (nor == 0)
                {
                    rtbResults.AppendText("No courses matched the query criteria");
                }
                else
                {
                    rtbResults.AppendText("\n###END RESULTS###");
                }
            }
            else
            {
                MessageBox.Show("Please select one of the threshold's (from the radio buttons)");
            }
        }