//saves professor information, returning true if successful or false if there was an error private bool saveProfessorInfo() { //ensure user has entered a last name (a required field) if (txtProfessorLName.Text.Equals("")) { Util.displayRequiredFieldsError("Last Name"); return(false); } //begin database transaction Database.beginTransaction(); Database.modifyDatabase("INSERT INTO Professor VALUES (null, " + Util.quote(txtProfessorTitle.Text) + ", " + Util.quote(txtProfessorFName.Text) + ", " + Util.quote(txtProfessorLName.Text) + ", " + Util.quote(txtProfessorEmail.Text) + ", " + Util.quote(txtProfessorOfficeLoc.Text) + ");"); //get the id of the value just inserted object profID = Database.getInsertedID(); //insert phone hours for (int i = 0; i < phoneNumbers.Count; i++) { Database.modifyDatabase("INSERT INTO Phone VALUES('" + phoneNumbers[i] + "', '" + profID + "', '" + phoneTypes[i] + "');"); } //insert office hours for (int i = 0; i < officeHoursDays.Count; i++) { string startTime = officeHoursStart[i].TimeOfDay.ToString(); string endTime = officeHoursEnd[i].TimeOfDay.ToString(); Database.modifyDatabase("INSERT INTO OfficeHour VALUES(null, '" + officeHoursDays[i][0] + "', '" + officeHoursDays[i][1] + "', '" + officeHoursDays[i][2] + "', '" + officeHoursDays[i][3] + "', '" + officeHoursDays[i][4] + "', TIME('" + startTime + "'), TIME('" + endTime + "'), '" + profID + "');"); } //commit all inserts to database Database.commit(); //clear all arrays after updating database phoneNumbers.Clear(); phoneTypes.Clear(); officeHoursStart.Clear(); officeHoursEnd.Clear(); officeHoursDays.Clear(); return(true); }
private bool saveEvent() { //ensure user entered a title since it is a required field if (txtEventTitle.Text.Equals("") == true) { Util.displayRequiredFieldsError("Event Title"); return(false); } //ensure start time is not later than end time (note this does not apply if an all day event) if (chkAllDayEvent.Checked == false && dtEventStartTime.Value.TimeOfDay > dtEventEndTime.Value.TimeOfDay) { Util.displayError("Invalid Start and End Times", "Error"); return(false); } //ensure start date is not later than end date (note this does not apply if an all day event) if (chkAllDayEvent.Checked == false && dtEventStartDate.Value > dtEventEndDate.Value) { Util.displayError("Invalid Start and End Dates", "Error"); return(false); } //get date in SQLite format string startDate = Database.getDate(dtEventStartDate.Value); string endDate = Database.getDate(dtEventEndDate.Value); //begin transaction Database.beginTransaction(); //add basic event details database Database.modifyDatabase("INSERT INTO Event VALUES (null, " + Util.quote(txtEventTitle.Text) + ", " + Util.quote(txtEventDescription.Text) + ", " + Util.quote(txtLocation.Text) + ", DATETIME('" + startDate + " " + dtEventStartTime.Value.TimeOfDay + "'), DATETIME('" + endDate + " " + dtEventEndTime.Value.TimeOfDay + "'), '" + chkAllDayEvent.Checked + "', null);"); //check if the event is a graded assignment if (chkGradedAssignment.Checked == true) { //get id of recently inserted event object eventID = Database.getInsertedID(); double grade = Double.MaxValue; double gradeTotal = Double.MaxValue; //ensure an assignment name was given if (txtAssignmentName.Text.Equals("")) { Util.displayRequiredFieldsError("Assignment Name"); return(false); } //if a graded assignment, force user to select class and category if (cbEventClass.Text.Equals("") || cbEventType.Text.Equals("")) { Util.displayError("Please select a value for both the class and assignment type", "Error"); return(false); } //check that grade and total points are valid number (note that the grade can be empty) if ((txtEventGrade.Text.Equals("") == false && double.TryParse(txtEventGrade.Text, out grade) == false) || (txtEventGradeTotalPoints.Text.Equals("") == false && double.TryParse(txtEventGradeTotalPoints.Text, out gradeTotal) == false)) { Util.displayError("Grade and Total Points must be valid decimal numbers", "Invalid Number"); return(false); } //ensure grade and total points are positive if (grade < 0 || gradeTotal < 0) { Util.displayError("Grade and Total Points must be positive", "Error"); return(false); } //if the grade was an empty string, we need to insert null in the database; otherwise add // user specified value string gradeVal = "null"; if (txtEventGrade.Text.Equals("") == false) { gradeVal = "'" + grade + "'"; } //if the grade total was an empty string, we need to insert null into the database string gradeTotalVal = "null"; if (txtEventGradeTotalPoints.Text.Equals("") == false) { gradeTotalVal = "'" + gradeTotal + "'"; } //add event details to database including all grade information Database.modifyDatabase("INSERT INTO GradedAssignment VALUES ('" + eventID + "', " + Util.quote(txtAssignmentName.Text) + ", " + gradeVal + ", " + gradeTotalVal + ", '" + classId[cbEventClass.SelectedIndex] + "', '" + cbEventType.Text + "');"); } //add event to calendar view newAppt = new Appointment(); newAppt.StartDate = new DateTime(dtEventStartDate.Value.Year, dtEventStartDate.Value.Month, dtEventStartDate.Value.Day, dtEventStartTime.Value.Hour, dtEventStartTime.Value.Minute, 0); newAppt.EndDate = new DateTime(dtEventEndDate.Value.Year, dtEventEndDate.Value.Month, dtEventEndDate.Value.Day, dtEventEndTime.Value.Hour, dtEventEndTime.Value.Minute, 0); newAppt.Subject = txtEventTitle.Text; newAppt.Note = txtEventDescription.Text; newAppt.Location = txtLocation.Text; newAppt.AppointmentId = int.Parse(Database.getInsertedID().ToString()); //store unique event id in calendar appointment note newAppt.Color = Color.Honeydew; newAppt.BorderColor = Color.DarkBlue; if (chkAllDayEvent.Checked == true) { newAppt.AllDayEvent = true; newAppt.EndDate = newAppt.EndDate.AddDays(1); newAppt.Color = Color.Coral; } else if (chkGradedAssignment.Checked == true) { newAppt.Color = AssignmentPlanner.classColors[classId[cbEventClass.SelectedIndex] % AssignmentPlanner.classColors.Length]; } if (PlannerSettings.Default.SyncEvents == true) { GoogleCalendarSync.addEvent(newAppt); } return(true); }
//save office hours, returing true if sucessful and false if there is an error private bool saveOfficeHours() { //ignore if one day is checked if (chkOfficeHoursMon.Checked == false && chkOfficeHoursTue.Checked == false && chkOfficeHoursWed.Checked == false && chkOfficeHoursThu.Checked == false && chkOfficeHoursFri.Checked == false) { return(true); } //ensure end time is later than start time if (dtOfficeHoursEnd.Value.TimeOfDay > dtOfficeHoursStart.Value.TimeOfDay == false) { Util.displayError("The end time must be later than the start time.", "Invalid Date"); displayMessage("Error Saving Office Hour Period", Color.DarkRed); return(false); } //check if we should insert new value into database if (useInsert == true || officeHoursDays.Count == 0) { //add new value to database Database.modifyDatabase("INSERT INTO OfficeHour VALUES(null, '" + chkOfficeHoursMon.Checked + "', '" + chkOfficeHoursTue.Checked + "', '" + chkOfficeHoursWed.Checked + "', '" + chkOfficeHoursThu.Checked + "', '" + chkOfficeHoursFri.Checked + "', TIME('" + dtOfficeHoursStart.Value.TimeOfDay + "'), TIME('" + dtOfficeHoursEnd.Value.TimeOfDay + "'), '" + currentProfId + "');"); //get id of inserted office hour period and store in list object insertId = Database.getInsertedID(); officeHoursId.Add(Convert.ToInt32(insertId)); //store current information in lists bool[] days = { chkOfficeHoursMon.Checked, chkOfficeHoursTue.Checked, chkOfficeHoursWed.Checked, chkOfficeHoursThu.Checked, chkOfficeHoursFri.Checked }; officeHoursDays.Add(days); officeHoursStart.Add(dtOfficeHoursStart.Value); officeHoursEnd.Add(dtOfficeHoursEnd.Value); //reset current office hour pointer and assume next action will be an update currentOfficeHour = officeHoursDays.Count - 1; useInsert = false; } //otherwise, we update an existing value else { //get current start and end times string startTime = dtOfficeHoursStart.Value.TimeOfDay.ToString(); string endTime = dtOfficeHoursEnd.Value.TimeOfDay.ToString(); //update information in database Database.modifyDatabase("UPDATE OfficeHour SET OnMonday = '" + chkOfficeHoursMon.Checked + "', OnTuesday = '" + chkOfficeHoursTue.Checked + "', OnWednesday = '" + chkOfficeHoursWed.Checked + "', OnThursday = '" + chkOfficeHoursThu.Checked + "', OnFriday = '" + chkOfficeHoursFri.Checked + "', StartTime = TIME('" + startTime + "'), EndTime = TIME('" + endTime + "') WHERE OfficeHoursID = '" + officeHoursId[currentOfficeHour] + "';"); //update lists officeHoursDays[currentOfficeHour][0] = chkOfficeHoursMon.Checked; officeHoursDays[currentOfficeHour][1] = chkOfficeHoursTue.Checked; officeHoursDays[currentOfficeHour][2] = chkOfficeHoursWed.Checked; officeHoursDays[currentOfficeHour][3] = chkOfficeHoursThu.Checked; officeHoursDays[currentOfficeHour][4] = chkOfficeHoursFri.Checked; officeHoursStart[currentOfficeHour] = dtOfficeHoursStart.Value; officeHoursEnd[currentOfficeHour] = dtOfficeHoursEnd.Value; } displayMessage("Office Hours Successfully Saved", Color.DarkGreen); return(true); }
//saves the class information, returning true if successful and false if there was an error 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); } //grade categories required if class is not finished if (chkClassFinished.Checked == false && categories.Count == 0) { Util.displayRequiredFieldsError("Grade Categories"); 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); } //set current grade to null unless the class is finished, upon which get the entered grade string currentGrade = "null"; 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); } currentGrade = "'" + cbFinalLetterGrade.Text + "'"; } //check if a semester has been selected string semesterIdValue = "null"; if (cbSemester.SelectedIndex >= 0) { semesterIdValue = "'" + semesterId[cbSemester.SelectedIndex] + "'"; } //begin database transaction Database.beginTransaction(); Database.modifyDatabase("INSERT INTO Class VALUES (null, " + Util.quote(txtClassName.Text) + ", '" + ctrCredits.Value + "', '" + chkClassMonday.Checked + "', '" + chkClassTuesday.Checked + "', '" + chkClassWednesday.Checked + "', '" + chkClassThursday.Checked + "', '" + chkClassFriday.Checked + "'," + semesterIdValue + ", TIME('" + dtClassStartTime.Value.TimeOfDay + "'), TIME('" + dtClassEndTime.Value.TimeOfDay + "'), " + Util.quote(txtClassLocation.Text) + ", null, null," + currentGrade + ");"); //get the id of the value just inserted object classID = Database.getInsertedID(); //insert into database the class professor assignment if (cbClassProfessor.SelectedIndex >= 0) { Database.modifyDatabase("INSERT INTO ClassProfessor VALUES ('" + profId[cbClassProfessor.SelectedIndex] + "', '" + classID + "');"); } //insert grading scale for (int i = 0; i < gradingScale.Length; i++) { Database.modifyDatabase("INSERT INTO GradingScaleValue VALUES('" + gradeLetter[i] + "', '" + classID + "', '" + gradingScale[i] + "');"); } //add value for F Database.modifyDatabase("INSERT INTO GradingScaleValue VALUES('F', '" + classID + "', '0.00');"); //insert grade category for (int i = 0; i < categories.Count; i++) { Database.modifyDatabase("INSERT INTO GradeCategory VALUES('" + categories[i] + "', '" + classID + "', '" + percentages[i] + "', null, '" + methods[i] + "');"); } //commit all inserts to database Database.commit(); //clear all arrays after updating database categories.Clear(); percentages.Clear(); methods.Clear(); return(true); }