Ejemplo n.º 1
0
        public float CalculateGPA()
        {
            if (isTeacher || classes.Length == 0)
            {
                return(-1); // return -1 if trying to calculate the gpa of a teacher
            }
            string[]    allClasses      = classes.Substring(0, classes.Length - 1).Split('@');
            int         averagePerClass = 0;
            float       totalGpa        = 0;
            SchoolClass tempClass       = null;
            float       classCount      = allClasses.Length;

            foreach (string className in allClasses)
            {
                tempClass = Database.classes[className];
                if (tempClass.grades.Count > 0)
                {
                    averagePerClass = tempClass.grades[this].GetAverage();
                    if (averagePerClass > 89)
                    {
                        totalGpa += 4.0f;
                    }
                    else if (averagePerClass > 79)
                    {
                        totalGpa += 3.0f;
                    }
                    else if (averagePerClass > 69)
                    {
                        totalGpa += 2.0f;
                    }
                    else if (averagePerClass > 59)
                    {
                        totalGpa += 1.0f;
                    }
                }
                else
                {
                    classCount--;
                }
            }
            return(totalGpa / classCount);
        }
Ejemplo n.º 2
0
        public static bool AddSchoolClass(string _className, string _classID)
        {
            if (classes.ContainsKey(_classID)) // If the class already exists, let the user know
            {
                return(false);
            }
            // Otherwise register the teacher
            SchoolClass newClass = new SchoolClass(_className, _classID, currentUser); // Create new class

            classes.Add(_classID, newClass);                                           // Adds the SchoolClass to the List of classes
            currentClasses.Add(newClass);
            classNames.Add(_classID);
            currentUser.AddClass(newClass.classID);
            // Now Store in file
            string classFileLocation = String.Format(@"{0}\" + _classID + ".txt", Application.StartupPath);

            File.AppendAllText(classFileLocation, newClass.Encoded());
            File.AppendAllText(classFileName, _classID + "|");
            SaveUsers();
            return(true);
        }
Ejemplo n.º 3
0
        private void ChangeGrade(TabPage tab, SchoolClass currentClass, User currentUser, Ambiance_Panel currentPanel)
        {
            List <int> currentGrades = currentClass.grades[currentUser].grades;
            bool       errorShown    = false;

            Control[] gradeBoxs = currentPanel.Controls.Find("grade", false);
            for (int i = 0; i < currentGrades.Count; i++)
            {
                try
                {
                    if (Int32.Parse(gradeBoxs[i].Text) <= 100 && Int32.Parse(((Ambiance_TextBox)gradeBoxs[i]).Text) >= 0)
                    {
                        currentGrades[i] = Int32.Parse(((Ambiance_TextBox)gradeBoxs[i]).Text);
                    }
                    else
                    if (!errorShown)
                    {
                        MessageBox.Show("Grades must be 0-100");
                        errorShown = false;
                    }
                }
                catch (Exception)
                {
                    if (!errorShown)
                    {
                        MessageBox.Show("Grades can be numbers only!");
                        errorShown = true;
                    }
                }
            }
            if (!errorShown)
            {
                MessageBox.Show("Grades Successfully Updated");
            }
            Database.SaveClass(currentClass);
            tab.Controls.Find("studentGPALabel", false)[0].Text = "GPA : " + String.Format("{0:0.00}", currentUser.CalculateGPA());
        }
Ejemplo n.º 4
0
 public static bool AddStudent(string _firstName, string _lastName, string _studentID, string _studentPass, SchoolClass _class)
 {
     // Checks if student exists, and is already in the class they are being added to
     if (users.ContainsKey(_studentID) && users[_studentID].classes.Contains(_class.classID))
     {
         return(false);
     }
     if (users.ContainsKey(_studentID))
     {
         users[_studentID].AddClass(_class.classID);
         Database.classes[_class.classID].AddStudent(users[_studentID]);
     }
     else
     {
         User tempUser = new User(_studentID, _studentPass, _firstName, _lastName, _class.classID + "@", false);
         users.Add(_studentID, tempUser);
         Database.classes[_class.classID].AddStudent(tempUser);
     }
     SaveUsers();
     SaveClass(_class);
     return(true);
 }
Ejemplo n.º 5
0
        public void AddTab(SchoolClass classTab, int index) // This method adds a tab to the main page based on the info of a SchoolClass
        {
            TabPage tab = new System.Windows.Forms.TabPage  // Create a new tab with className
            {
                Text     = classTab.className,
                Name     = classTab.classID,
                Size     = new System.Drawing.Size(256, 214),
                TabIndex = index
            };

            allTabs.Add(tab);            // Store all tabs in a list
            classTabs.Controls.Add(tab); // Add tab to display
            Ambiance_HeaderLabel teacherLabel = new Ambiance_HeaderLabel
            {
                AutoSize = true,
                Location = new System.Drawing.Point(16, 7),
                Name     = "teacherLabel",
                //   Font = new Font("Segoe UI", 12.0f, FontStyle.Bold),
                Size = new System.Drawing.Size(43, 90),
                Text = ("Teacher : " + Database.currentClasses[index].teacher.firstName + " " + Database.currentClasses[index].teacher.lastName)
            };
            Ambiance_Label classIDLabel = new Ambiance_Label
            {
                AutoSize = true,
                Location = new System.Drawing.Point(16, 27),
                Name     = "classIDLabel",
                //    Font = new Font("Segoe UI", 12.0f, FontStyle.Regular),
                Size = new System.Drawing.Size(43, 13),
                Text = ("Class ID  : " + Database.currentClasses[index].classID)
            };

            tab.Controls.Add(teacherLabel);
            tab.Controls.Add(classIDLabel);

            if (Database.isTeacher) // If user is a teacher, add these elements to tabs
            {
                Ambiance_ComboBox studentBox = new Ambiance_ComboBox
                {
                    Location = new System.Drawing.Point(700, 10),
                    Name     = "studentBox",
                    Size     = new System.Drawing.Size(204, 26)
                };
                Ambiance_HeaderLabel studentLabel = new Ambiance_HeaderLabel
                {
                    AutoSize = true,
                    Location = new System.Drawing.Point(565, 13),
                    Name     = "studentLabel",
                    //    Font = new Font("Segoe UI", 12.0f, FontStyle.Regular),
                    Size = new System.Drawing.Size(129, 20),
                    Text = ("Current Student :")
                };
                Ambiance_HeaderLabel selectStudentLabel = new Ambiance_HeaderLabel
                {
                    AutoSize = true,
                    Location = new System.Drawing.Point(72, 180),
                    Name     = "selectStudentLabel",
                    Font     = new Font("Segoe UI", 32.0f, FontStyle.Bold),
                    Size     = new System.Drawing.Size(773, 59),
                    Text     = ("Select a student to view their grades.")
                };
                foreach (User userInClass in classTab.students)
                {
                    studentBox.Items.Add(userInClass.firstName + " " + userInClass.lastName);
                }
                studentBox.SelectedIndexChanged += new EventHandler(DynamicComboBox_OnChange);

                tab.Controls.Add(studentLabel);
                tab.Controls.Add(studentBox);
                tab.Controls.Add(selectStudentLabel);
            }
            else // If the user is a student, add these elements
            {
                ShowInfo(tab, classTab, Database.currentUser);
            }
        }
Ejemplo n.º 6
0
        private void ShowInfo(TabPage tab, SchoolClass currentClass, User currentUser)                                                         // Shows grades for particular student
        {
            if (tab.Controls.ContainsKey("selectStudentLabel"))                                                                                // If tab has selectStudentLabel...
            {
                tab.Controls.Remove(tab.Controls.Find("selectStudentLabel", false)[0]);                                                        // Delete it
            }
            if (tab.Controls.ContainsKey("studentNameLabel"))                                                                                  // If the tab has studentNameLabel
            {
                tab.Controls.Find("studentNameLabel", false)[0].Text = "Student Name : " + currentUser.firstName + " " + currentUser.lastName; // Change text
            }
            else // otherwise..
            {
                Ambiance_Label studentNameLabel = new Ambiance_Label // Create it
                {
                    AutoSize = true,
                    Location = new System.Drawing.Point(326, 16),
                    Name     = "studentNameLabel",
                    Size     = new System.Drawing.Size(185, 20),
                    Text     = ("Student Name : " + currentUser.firstName + " " + currentUser.lastName)
                };
                tab.Controls.Add(studentNameLabel);
            }

            if (tab.Controls.ContainsKey("studentIDLabel"))                                                  // If the tab has studentIDLabel
            {
                tab.Controls.Find("studentIDLabel", false)[0].Text = "Student ID : " + currentUser.username; // Change text
            }
            else // otherwise...
            {
                Ambiance_Label studentIDLabel = new Ambiance_Label // Create it
                {
                    AutoSize = true,
                    Location = new System.Drawing.Point(351, 56),
                    Name     = "studentIDLabel",
                    Size     = new System.Drawing.Size(138, 20),
                    Text     = ("Student ID : " + currentUser.username)
                };
                tab.Controls.Add(studentIDLabel);
            }

            if (tab.Controls.ContainsKey("studentGPALabel"))                                                                            // If the tab has studentGPALabel
            {
                tab.Controls.Find("studentGPALabel", false)[0].Text = "GPA : " + String.Format("{0:0.00}", currentUser.CalculateGPA()); // Change text
            }
            else // otherwise...
            {
                Ambiance_Label studentGPALabel = new Ambiance_Label // Create it
                {
                    AutoSize = true,
                    Location = new System.Drawing.Point(395, 95),
                    Name     = "studentGPALabel",
                    Size     = new System.Drawing.Size(74, 20),
                    Text     = ("GPA : " + String.Format("{0:0.00}", currentUser.CalculateGPA()))
                };
                tab.Controls.Add(studentGPALabel);
            }

            if (!tab.Controls.ContainsKey("gradeButton") && Database.isTeacher) // If the tab has studentGPALabel
            {
                Ambiance_Button_1 gradeButton = new Ambiance_Button_1           // Create it
                {
                    Location = new System.Drawing.Point(566, 307),
                    Name     = "gradeButton",
                    Size     = new System.Drawing.Size(139, 30),
                    Text     = ("Add Test Score")
                };
                Ambiance_Button_2 gradeButton1 = new Ambiance_Button_2 // Create it
                {
                    Location = new System.Drawing.Point(566, 346),
                    Name     = "gradeButton1",
                    Size     = new System.Drawing.Size(139, 30),
                    Text     = ("Commit Changes")
                };
                gradeButton.Click  += new EventHandler(DynamicAddGrade_Click);
                gradeButton1.Click += new EventHandler(DynamicChangeGrade_Click);
                tab.Controls.Add(gradeButton);
                tab.Controls.Add(gradeButton1);
            }

            if (tab.Controls.ContainsKey("studentGradesPanel"))                         // If the tab has studentGradesPanel
            {
                tab.Controls.Remove(tab.Controls.Find("studentGradesPanel", false)[0]); // Remove it
            }
            Ambiance_Panel studentGradesPanel = new Ambiance_Panel                      // Make a new one
            {
                Location   = new System.Drawing.Point(721, 56),
                Name       = "studentGradesPanel",
                Size       = new System.Drawing.Size(172, 320),
                AutoScroll = true
            };

            studentGradesPanel.VerticalScroll.Visible = true;

            List <int> currentGrades = currentClass.grades[currentUser].grades;

            #region testing
            //currentGrades.Add(12);
            //currentGrades.Add(55);
            //currentGrades.Add(99);
            //currentGrades.Add(12);
            //currentGrades.Add(55);
            //currentGrades.Add(99);
            //currentGrades.Add(12);
            //currentGrades.Add(55);
            //currentGrades.Add(99);
            #endregion
            for (int i = 0; i < currentGrades.Count; i++)
            {
                studentGradesPanel.Controls.Add(new Ambiance_Label
                {
                    AutoSize = true,
                    Location = new System.Drawing.Point(12, 48 * i + 12),
                    Name     = "label" + i,
                    Size     = new System.Drawing.Size(54, 20),
                    Text     = ("Test " + i + " : ")
                });
                studentGradesPanel.Controls.Add(new Ambiance_Separator
                {
                    Location = new System.Drawing.Point(4, 48 * i + 42),
                    Name     = "separator" + i,
                    Size     = new System.Drawing.Size(139, 10)
                });
                if (Database.currentUser.isTeacher)
                {
                    studentGradesPanel.Controls.Add(new Ambiance_TextBox
                    {
                        Location      = new System.Drawing.Point(73, 48 * i + 9),
                        Name          = "grade",
                        Size          = new System.Drawing.Size(69, 28),
                        Text          = (currentGrades[i].ToString()),
                        MaxLength     = 3,
                        TextAlignment = HorizontalAlignment.Center
                    });
                }
                else
                {
                    studentGradesPanel.Controls.Add(new Ambiance_Label
                    {
                        Location = new System.Drawing.Point(73, 48 * i + 12),
                        Name     = "grade",
                        Size     = new System.Drawing.Size(69, 28),
                        Text     = (currentGrades[i].ToString())
                    });
                }
            }
            tab.Controls.Add(studentGradesPanel);
        }