//when the user changes the event type, determine what grading method is used (points or percentage) // and take the appropriate action (enable/disable total points textbox) private void cbEventType_SelectedIndexChanged(object sender, EventArgs e) { //if no class is selected, simply ignore if (cbEventType.Text.Equals("")) { return; } //get the grading method currently selected grade category object gradingMethod = Database.executeScalarQuery("SELECT GradingMethod FROM GradeCategory WHERE ClassID = '" + currentClassId[cbEventClass.SelectedIndex] + "' AND Type = '" + cbEventType.Text + "';"); //check if grading method is points based if (gradingMethod.Equals("Points")) { txtEventGradeTotalPoints.Enabled = true; } else { txtEventGradeTotalPoints.Enabled = false; //since assignment is a percentage, set total points to 100 (this makes calculating // overall grade easier later) txtEventGradeTotalPoints.Text = "100"; } }
public AddSemesterForm() { InitializeComponent(); //set semester id to one more than greatest id currently in database ctrSemester.Value = Int32.Parse(Database.executeScalarQuery("SELECT count(*) from Semester;").ToString()) + 1; //set start and end dates to current date dtSemesterStartDate.Value = DateTime.Now; dtSemesterEndDate.Value = DateTime.Now; }
private void cbClass_SelectedIndexChanged(object sender, EventArgs e) { txtDesiredPercentage.ResetText(); txtCurrentGrade.ResetText(); //get current grade in class object result = Database.executeScalarQuery("SELECT CurrentGrade FROM Class WHERE ClassID = '" + classId[cbClass.SelectedIndex] + "';"); double currentGrade; if (Double.TryParse(result.ToString(), out currentGrade) == true) { txtCurrentGrade.Text = currentGrade.ToString("F4"); } //try to get percentage that final is worth result = Database.executeScalarQuery("SELECT Percentage FROM GradeCategory WHERE (Type LIKE '%Final%') AND ClassID = '" + classId[cbClass.SelectedIndex] + "';"); txtFinalExamPercentage.ResetText(); //get final exam percentage worth txtFinalExamPercentage.Text = result + ""; cbFinalLetterGrade.Items.Clear(); //populate the desired grade percentage based on a selected latter grade MySqlDataReader grades = Database.executeQuery("SELECT GradeLetter, BottomPercentage FROM GradingScaleValue WHERE ClassID = '" + classId[cbClass.SelectedIndex] + "' ORDER BY BottomPercentage DESC"); while (grades.Read() == true) { gradeLetter.Add(grades.GetString(0)); cbFinalLetterGrade.Items.Add(grades.GetString(0)); gradePerc.Add(grades.GetDouble(1)); } grades.Close(); cbFinalLetterGrade.Enabled = true; }
//get the letter grade in a class when providing a grade (percentage) and the class id public static string getLetterGrade(double grade, int classID) { object letterGrade = Database.executeScalarQuery("SELECT GradeLetter FROM GradingScaleValue WHERE " + grade + " >= BottomPercentage AND ClassID = '" + classID + "' ORDER BY BottomPercentage DESC;"); return(letterGrade.ToString()); }
private bool SaveClass() { //ensure at least one day is checked if (txtClassName.Text.Equals("") || (chkClassMonday.Checked == false && chkClassTuesday.Checked == false && chkClassWednesday.Checked == false && chkClassThursday.Checked == false && chkClassFriday.Checked == false) || (chkClassFinished.Checked == true && cbFinalLetterGrade.Text.Equals(""))) { Util.displayRequiredFieldsError(new string[] { "Class Name", "Days" }); return(false); } //ensure start and end times are legal if (dtClassStartTime.Value.TimeOfDay > dtClassEndTime.Value.TimeOfDay) { Util.displayError("Invalid Start and End Times", "Error"); return(false); } //check that a valid letter grade has been entered if (chkClassFinished.Checked == true) { //make sure user has selected a value if (cbFinalLetterGrade.Equals("")) { Util.displayError("Please select a valid letter grade for the class", "Invalid Letter Grade"); return(false); } } else { object attr = Database.executeScalarQuery("SELECT Type FROM GradeCategory WHERE ClassID = '" + currentClassId + "'"); if (attr == null && chkClassFinished.Checked == false) { Util.displayRequiredFieldsError("Grading Categories"); return(false); } } //check if a semester has been selected string semesterIdValue = "null"; if (cbSemester.SelectedIndex >= 0) { semesterIdValue = "'" + semesterId[cbSemester.SelectedIndex] + "'"; } //begin the database transaction Database.beginTransaction(); Database.modifyDatabase("UPDATE Class SET Name = " + Util.quote(txtClassName.Text) + ", Credits = '" + ctrCredits.Value + "', OnMonday = '" + chkClassMonday.Checked + "', OnTuesday = '" + chkClassTuesday.Checked + "', OnWednesday = '" + chkClassWednesday.Checked + "', OnThursday = '" + chkClassThursday.Checked + "', OnFriday = '" + chkClassFriday.Checked + "', SemesterID = " + semesterIdValue + ", StartTime = TIME('" + dtClassStartTime.Value.TimeOfDay + "'), EndTime = TIME('" + dtClassEndTime.Value.TimeOfDay + "'), Location = " + Util.quote(txtClassLocation.Text) + ", FinalLetterGrade = " + Util.quote(cbFinalLetterGrade.Text) + " WHERE ClassID = '" + currentClassId + "';"); //insert into database or update the class professor assignment if (cbClassProfessor.Text.Equals("") == false) { //if the assignment has not been already created if (classHasProf == false) { Database.modifyDatabase("INSERT INTO ClassProfessor VALUES('" + profId[cbClassProfessor.SelectedIndex] + "', '" + currentClassId + "');"); classHasProf = true; } //else update the database else { Database.modifyDatabase("UPDATE ClassProfessor SET ProfID = '" + profId[cbClassProfessor.SelectedIndex] + "' WHERE ClassID = '" + currentClassId + "';"); } } //commit all inserts to database Database.commit(); return(true); }