Exemplo n.º 1
0
        private void btn_addToHistory_Click(object sender, EventArgs e)
        {
            //Validate Data
            int credits;

            try
            {
                credits = int.Parse(txtBx_credits.Text);
            }
            catch
            {
                return;
            }
            string letterGrade = txtBx_grade.Text;

            Class        newClass = new Class(txtBx_className.Text, credits, letterGrade);
            List <Class> historicClasses;

            try
            {
                historicClasses = DataIO.LoadHistoricClasses();
            }
            catch
            {
                //Could not seralzie. New empty list
                historicClasses = new List <Class>();
            }
            historicClasses.Add(newClass);
            DataIO.SaveHistoricClasses(historicClasses);
            txtBx_credits.Text   = "0";
            txtBx_grade.Text     = "";
            txtBx_className.Text = "Class Name";
        }
Exemplo n.º 2
0
        private void calculateGPA()
        {
            List <string> creditsList = new List <string> {
                credits1.Text, credits2.Text, credits3.Text, credits4.Text, credits5.Text, credits6.Text
            };
            List <string> gradeList = new List <string> {
                grade1.Text, grade2.Text, grade3.Text, grade4.Text, grade5.Text, grade6.Text
            };
            List <string> nameList = new List <string> {
                name1.Text, name2.Text, name3.Text, name4.Text, name5.Text, name6.Text
            };

            List <Class> currentClasses = new List <Class>();

            for (int i = 0; i < 6; i++)
            {
                int credits;
                try
                {
                    credits = int.Parse(creditsList[i]);
                }
                catch
                {
                    break;
                }
                string letterGrade = gradeList[i];

                Class newClass = new Class(nameList[i], credits, letterGrade);
                currentClasses.Add(newClass);
            }
            DataIO.SaveCurrentClasses(currentClasses);
            List <Class> allClasses = DataIO.LoadHistoricClasses(); //Start with historic classes

            allClasses.AddRange(currentClasses);                    //Adds current classes

            float semesterGPA = calculateGPA(currentClasses);
            float cumGPA      = calculateGPA(allClasses);

            statusLbl_semesterGPA.Text = semesterGPA.ToString("F3");
            statusLbl_cumGPA.Text      = cumGPA.ToString("F3");
        }