Esempio n. 1
0
        //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);
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
        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);
        }
        //method that saves all the currently entered categories and associated information
        private void btnCategorySave_Click(object sender, EventArgs e)
        {
            double sum = 0;

            //check if user has entered one but not both of the required fields (not the use of
            // XOR; two empty fields are allowed and this entry is simply ignored)
            for (int i = 0; i < locationCounter; i++)
            {
                if (this.Controls["cbCategory" + i].Text.Equals("") == true ^
                    this.Controls["txtPercentage" + i].Text.Equals("") == true)
                {
                    Util.displayRequiredFieldsError(new string[] { "Category", "Percentage" });
                    return;
                }
            }

            //ensure no duplicates exist
            if (duplicateTypeCheck() == false)
            {
                Util.displayError("Two categories cannot have the same name", "Duplicate Grade Categories");
                return;
            }

            //calculate sum
            for (int i = 0; i < locationCounter; i++)
            {
                if (this.Controls["cbCategory" + i].Text.Equals("") == false &&
                    this.Controls["txtPercentage" + i].Text.Equals("") == false)
                {
                    double categoryPercentage;
                    if (double.TryParse(this.Controls["txtPercentage" + i].Text, out categoryPercentage) == false)
                    {
                        Util.displayError("Each category percentage must be a valid decimal", "Invalid Category Percentage");
                        return;
                    }

                    //store running sum
                    sum += categoryPercentage;
                }
            }

            //check if sum of categories adds up to 100%
            if (Math.Abs(100 - sum) > 0.001)
            {
                Util.displayError("Sum of Category Percentages do not add up to 100", "Error");
                return;
            }

            Database.beginTransaction();

            //perform update on existing grades
            for (int i = 0; i < locationToInsert; i++)
            {
                if (this.Controls["cbCategory" + i].Text.Equals("") == true &&
                    this.Controls["txtPercentage" + i].Text.Equals("") == true)
                {
                    continue;
                }

                //get currently entered information for the specified line
                string      gradeType  = Util.quote(this.Controls["cbCategory" + i].Text);
                double      percentage = double.Parse(this.Controls["txtPercentage" + i].Text);
                string      method     = "Percentage";
                RadioButton points     = (RadioButton)this.Controls["gradingMethod" + i + "Panel"].Controls["rbPoints" + i];
                if (points.Checked == true)
                {
                    method = "Points";
                }

                //modify database
                Database.modifyDatabase("UPDATE GradeCategory SET Type = " + gradeType + ", Percentage = '" + percentage + "', GradingMethod = '"
                                        + method + "' WHERE ClassID = '" + currentClassId + "' AND Type = '" + category[i] + "';");
            }

            //insert new grade categories
            for (int i = locationToInsert; i < locationCounter; i++)
            {
                if (this.Controls["cbCategory" + i].Text.Equals("") == true &&
                    this.Controls["txtPercentage" + i].Text.Equals("") == true)
                {
                    continue;
                }

                //get currently entered information for the specified line
                string      category   = Util.quote(this.Controls["cbCategory" + i].Text);
                double      percentage = double.Parse(this.Controls["txtPercentage" + i].Text);
                string      method     = "Percentage";
                RadioButton points     = (RadioButton)this.Controls["gradingMethod" + i + "Panel"].Controls["rbPoints" + i];
                if (points.Checked == true)
                {
                    method = "Points";
                }

                //add new values into database
                Database.modifyDatabase("INSERT INTO GradeCategory VALUES(" + category + ", '" + currentClassId + "', '" +
                                        percentage + "', null, '" + method + "');");
            }

            Database.commit();

            //return to edit class tab
            Close();
        }
        private bool saveEvent()
        {
            //current get event id
            int currentEventId = eventId[cbEvent.SelectedIndex];

            //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("UPDATE Event SET Title = " + Util.quote(txtEventTitle.Text) + ", Description = " +
                                    Util.quote(txtEventDescription.Text) + ", Location = " + Util.quote(txtLocation.Text) + ", StartDateTime = DATETIME('" + startDate + " " + dtEventStartTime.Value.TimeOfDay + "'), EndDateTime = DATETIME('" +
                                    endDate + " " + dtEventEndTime.Value.TimeOfDay + "'), IsAllDay = '" + chkAllDayEvent.Checked + "' "
                                    + " WHERE EventID = '" + currentEventId + "';");



            //check if the event is a graded assignment
            if (chkGradedAssignment.Checked == true)
            {
                //ensure a valid assignment name has been entered
                if (txtAssignmentName.Equals("") == true)
                {
                    Util.displayRequiredFieldsError("Assignment Name");
                    Database.abort();
                    return(false);
                }

                double grade      = Double.MaxValue;
                double gradeTotal = Double.MaxValue;

                //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");
                    Database.abort();
                    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");
                    Database.abort();
                    return(false);
                }

                //ensure grade and total points are positive
                if (grade < 0 || gradeTotal < 0)
                {
                    Util.displayError("Grade and Total Points must be positive", "Error");
                    Database.abort();
                    return(false);
                }

                //if the graded assignment already exists, simply update database
                if (Database.attributeExists("EventID = '" + currentEventId + "'", "GradedAssignment") == true)
                {
                    //add event details to database including all grade information
                    Database.modifyDatabase("UPDATE GradedAssignment SET AssignmentName = " + Util.quote(txtAssignmentName.Text) +
                                            ", Grade = " + Util.quote(txtEventGrade.Text) + ", GradeTotalWorth = " + Util.quote(txtEventGradeTotalPoints.Text) + ", ClassId = '" + currentClassId[cbEventClass.SelectedIndex] + "', Type = '" + cbEventType.Text + "' " +
                                            "WHERE EventID = '" + currentEventId + "';");
                }
                //otherwise insert into database
                else
                {
                    //add event details to database including all grade information
                    Database.modifyDatabase("INSERT INTO GradedAssignment VALUES ('" + currentEventId + "', " + Util.quote(txtAssignmentName.Text) +
                                            ", " + Util.quote(txtEventGrade.Text) + ", " + Util.quote(txtEventGradeTotalPoints.Text) + ", '" + currentClassId[cbEventClass.SelectedIndex] + "', '" + cbEventType.Text + "');");
                }
            }
            else
            {
                //delete graded assignment portion of event
                Database.modifyDatabase("DELETE FROM GradedAssignment WHERE EventID = '" + currentEventId + "';");
            }

            //get event in calendar that has the specified event id
            bool        containsEvent = eventsHash.ContainsKey(currentEventId);
            Appointment appt;

            if (containsEvent == true)
            {
                appt = eventsHash[currentEventId];
            }
            else
            {
                appt = new Appointment();
            }

            //update appointment information
            appt.StartDate = new DateTime(dtEventStartDate.Value.Year, dtEventStartDate.Value.Month, dtEventStartDate.Value.Day, dtEventStartTime.Value.Hour, dtEventStartTime.Value.Minute, 0);
            appt.EndDate   = new DateTime(dtEventEndDate.Value.Year, dtEventEndDate.Value.Month, dtEventEndDate.Value.Day, dtEventEndTime.Value.Hour, dtEventEndTime.Value.Minute, 0);
            appt.Subject   = txtEventTitle.Text;
            appt.Note      = txtEventDescription.Text;
            appt.Location  = txtLocation.Text;
            appt.Color     = Color.Honeydew;

            //determine whether event is an all day event and update appointment
            if (chkAllDayEvent.Checked == true)
            {
                appt.AllDayEvent = true;
                appt.EndDate     = appt.EndDate.AddDays(1);
                appt.Color       = Color.Coral;
            }
            else if (chkGradedAssignment.Checked == true)
            {
                appt.AllDayEvent = false;
                appt.Color       = AssignmentPlanner.classColors[currentClassId[cbEventClass.SelectedIndex] % AssignmentPlanner.classColors.Length];
            }
            else
            {
                appt.AllDayEvent = false;
            }

            if (PlannerSettings.Default.SyncEvents == true)
            {
                GoogleCalendarSync.updateEvent(appt);
            }

            //commit changes to database (end transaction)
            Database.commit();

            return(true);
        }
Esempio n. 6
0
        //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);
        }