Пример #1
0
        public static void mergeChanges()
        {
            if (authenticated == true)
            {
                MySqlDataReader events = Database.executeQuery("SELECT GoogleEventID FROM EVENT WHERE GoogleEventID IS NOT NULL AND StartDateTime > DATETIME('now', 'localtime')");
                while (events.Read() == true)
                {
                    try {
                        EventQuery myQuery = new EventQuery(postUri.ToString() + "/" + events.GetString(0));
                        lock (threadLock) {
                            EventFeed resultFeed = (EventFeed)service.Query(myQuery);

                            //only update if an event is found
                            if (resultFeed.Entries.Count > 0)
                            {
                                EventEntry calendar = (EventEntry)resultFeed.Entries[0];
                                Database.modifyDatabase("UPDATE Event SET Title = " + Util.quote(calendar.Title.Text) + ", Description = "
                                                        + Util.quote(calendar.Content.Content) + ", Location = " + Util.quote(calendar.Locations[0].ValueString)
                                                        + ", StartDateTime = DATETIME('" + Database.getDateTime(calendar.Times[0].StartTime) + "'), EndDateTime = DATETIME('"
                                                        + Database.getDateTime(calendar.Times[0].EndTime) + "') WHERE GoogleEventID = '" + events.GetString(0) + "';");
                            }
                        }
                    }
                    catch (Exception e) {
                        Util.logError("Google Calendar Error: " + e.Message);
                    }
                }
                events.Close();
            }
        }
Пример #2
0
 private bool saveSemesterInfo()
 {
     //ensure a semester name was entered
     if (txtSemesterName.Text.Equals(""))
     {
         Util.displayRequiredFieldsError("Semester Name");
     }
     //ensure a semester with the same semester id does not already exist
     else if (Database.attributeExists("semesterID = '" + ctrSemester.Value + "'", "Semester"))
     {
         Util.displayError("The Entered Semester Number Already Exists", "Invalid Semester Number");
     }
     //ensure the end semester date occurs on or after the start semester date
     else if (dtSemesterEndDate.Value < dtSemesterStartDate.Value)
     {
         Util.displayError("The End Date Must Be Later Than The Start Date", "Invalid Semester Dates");
     }
     else
     {
         //update the semester fields in the database
         Database.modifyDatabase("INSERT INTO Semester VALUES('" + ctrSemester.Value + "',"
                                 + Util.quote(txtSemesterName.Text) + ","
                                 + "DATE('" + Database.getDate(dtSemesterStartDate.Value) + "'),"
                                 + "DATE('" + Database.getDate(dtSemesterEndDate.Value) + "'))");
         return(true);
     }
     return(false);
 }
        //deletes currently selected phone number from database
        private void btnDeletePhoneNum_Click(object sender, EventArgs e)
        {
            //display confirmation message
            DialogResult reallyDelete = MessageBox.Show("Are you sure you really want to delete this phone number?", "Really Delete?", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

            if (reallyDelete == DialogResult.Yes)
            {
                if (phoneNum.Count > 0)
                {
                    //delete from database and from lists
                    Database.modifyDatabase("DELETE FROM Phone WHERE ProfID = '" + currentProfId + "' AND PhoneNumber = '" + phoneNum[currentPhoneNum] + "';");
                    phoneNum.RemoveAt(currentPhoneNum);
                    phoneType.RemoveAt(currentPhoneNum);

                    //if there are not two items or more, there is nothing to cycle through
                    if (phoneNum.Count < 1)
                    {
                        lnkPreviousPhone.Enabled = false;
                        lnkNextPhone.Enabled     = false;
                    }

                    //result form
                    resetPhoneNumberForm();

                    //decrement (go to previous) phone number without saving current information (which will just be blank)
                    changePhoneNumber(false, false);
                }
            }
        }
        //deletes office hour period information from database
        private void btnDeleteOfficeHours_Click(object sender, EventArgs e)
        {
            //displays confirmation message
            DialogResult reallyDelete = MessageBox.Show("Are you sure you really want to delete this office hour?", "Really Delete?", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

            if (reallyDelete == DialogResult.Yes)
            {
                if (officeHoursId.Count > 0)
                {
                    //delete from database
                    Database.modifyDatabase("DELETE FROM OfficeHour WHERE OfficeHoursID = '" + officeHoursId[currentOfficeHour] + "';");

                    //remove items from lists
                    officeHoursId.RemoveAt(currentOfficeHour);
                    officeHoursDays.RemoveAt(currentOfficeHour);
                    officeHoursStart.RemoveAt(currentOfficeHour);
                    officeHoursEnd.RemoveAt(currentOfficeHour);

                    //reset office hours form
                    resetOfficeHoursForm();

                    //decrement (go to previous) office hours period without saving (since form will be empty)
                    changeOfficeHours(false, false);
                }
            }
        }
Пример #5
0
        //button to delete event from database
        private void btnDeleteEvent_Click(object sender, EventArgs e)
        {
            //display confirmation message
            DialogResult reallyDelete = MessageBox.Show("Are you sure you really want to delete this event?", "Really Delete?", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

            if (reallyDelete == DialogResult.Yes)
            {
                //delete from database
                Database.modifyDatabase("DELETE FROM Event WHERE EventID = '" + eventId[cbEvent.SelectedIndex] + "';");

                if (PlannerSettings.Default.SyncEvents == true)
                {
                    GoogleCalendarSync.deleteEvent(eventsHash[eventId[cbEvent.SelectedIndex]]);
                }

                //ensure associated google event information tied to this event is removed
                GoogleCalendarSync.deleteEventID(eventId[cbEvent.SelectedIndex]);

                //remove from calendar view
                calendarEvents.Remove(eventsHash[eventId[cbEvent.SelectedIndex]]);

                //close form if deleting event
                Close();
            }
        }
Пример #6
0
        //method to delete currently selected semester
        private void btnDeleteSemester_Click(object sender, EventArgs e)
        {
            //display confirmation message
            DialogResult reallyDelete = MessageBox.Show("Are you sure you really want to delete this semester?", "Really Delete?", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

            if (reallyDelete == DialogResult.Yes)
            {
                //delete from database
                Database.modifyDatabase("DELETE FROM Semester WHERE SemesterID = '" + semesterId[cbEditSemester.SelectedIndex] + "';");
                Close();
            }
        }
Пример #7
0
        //deletes a class from the database (will also delete any events associated with given class)
        private void btnDeleteClass_Click(object sender, EventArgs e)
        {
            //display confirmation
            DialogResult reallyDelete = MessageBox.Show("Are you sure you really want to delete this class? This will also delete "
                                                        + "all events associated with this class.", "Really Delete?", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

            if (reallyDelete == DialogResult.Yes)
            {
                //delete from database
                Database.modifyDatabase("DELETE FROM Class WHERE ClassID = '" + currentClassId + "';");
                Close();
            }
        }
Пример #8
0
        //add an event to google calendar
        public static void addEvent(Appointment appt)
        {
            if (authenticated == true)
            {
                Dictionary <int, string> insertedId = new Dictionary <int, string>();

                //create new thread for add event
                BackgroundWorker bw = new BackgroundWorker();
                bw.DoWork += delegate(object s, DoWorkEventArgs args) {
                    try {
                        //add event to Google Calendar
                        EventEntry entry = new EventEntry();

                        // Set the title and content of the entry.
                        entry.Title.Text      = appt.Subject;
                        entry.Content.Content = appt.Note;

                        // Set a location for the event.
                        Where eventLocation = new Where();
                        eventLocation.ValueString = appt.Location;
                        entry.Locations.Add(eventLocation);


                        When eventTime = new When(appt.StartDate, appt.EndDate);
                        entry.Times.Add(eventTime);

                        lock (threadLock) {
                            EventEntry insertedEntry = service.Insert(postUri, entry);
                            eventIDs.Add(appt.AppointmentId, insertedEntry.EventId);
                            insertedId.Add(appt.AppointmentId, insertedEntry.EventId);
                        }
                    }
                    catch (Exception e) {
                        Util.logError("Google Calendar Error: " + e.Message);
                    }
                };

                bw.RunWorkerCompleted += delegate(object s, RunWorkerCompletedEventArgs args) {
                    foreach (int apptId in insertedId.Keys)
                    {
                        Database.modifyDatabase("UPDATE Event SET GoogleEventID = '" + insertedId[apptId] + "' WHERE EventID = '" + apptId + "';");
                    }
                };

                //start the thread
                bw.RunWorkerAsync();
            }
        }
Пример #9
0
        //saves professor information to the database
        private void btnSaveProfessor_Click(object sender, EventArgs e)
        {
            //ensure user has entered a last name (a required field)
            if (txtProfessorLName.Text.Equals(""))
            {
                Util.displayRequiredFieldsError("Last Name");
                displayMessage("Error Saving Professor Information", Color.DarkRed);
                return;
            }

            //update the professor fields in the database
            Database.modifyDatabase("UPDATE Professor SET Title = " + Util.quote(txtProfessorTitle.Text) + ", FirstName = " + Util.quote(txtProfessorFName.Text)
                                    + ", LastName = " + Util.quote(txtProfessorLName.Text) + ", Email = " + Util.quote(txtProfessorEmail.Text) + ", OfficeLocation = " + Util.quote(txtProfessorOfficeLoc.Text) + " "
                                    + "WHERE ProfID = '" + profId[cbEditProfessor.SelectedIndex] + "';");

            displayMessage("Professor Information Successfully Saved", Color.DarkGreen);
        }
        //deletes a single category from the database (if currently present)
        private void deleteCategoryLine(int lineNum)
        {
            //show confirmation message
            DialogResult reallyDelete = MessageBox.Show("Are you sure you really want to delete this grade category?", "Really Delete?", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

            if (reallyDelete == DialogResult.Yes)
            {
                //we need to remove from database
                if (lineNum < locationToInsert)
                {
                    //delete from database
                    Database.modifyDatabase("DELETE FROM GradeCategory WHERE ClassID = '" + currentClassId + "' AND Type = '" + category[lineNum] + "';");

                    //delete from lists
                    category.RemoveAt(lineNum);
                    percentage.RemoveAt(lineNum);
                    type.RemoveAt(lineNum);

                    //decrement location to insert (there the last item that requires an update is now one less)
                    locationToInsert--;
                }

                //shift all the information below the deleted line up one line
                for (int i = lineNum; i < locationCounter - 1; i++)
                {
                    this.Controls["cbCategory" + i].Text    = this.Controls["cbCategory" + (i + 1)].Text;
                    this.Controls["txtPercentage" + i].Text = this.Controls["txtPercentage" + (i + 1)].Text;
                    RadioButton next = (RadioButton)this.Controls["gradingMethod" + (i + 1) + "Panel"].Controls["rbPoints" + (i + 1)];
                    RadioButton curr = (RadioButton)this.Controls["gradingMethod" + i + "Panel"].Controls["rbPoints" + i];
                    if (next.Checked == true && curr.Checked == false)
                    {
                        curr.Checked = true;
                    }
                    if (next.Checked == false && curr.Checked == true)
                    {
                        curr         = (RadioButton)this.Controls["gradingMethod" + i + "Panel"].Controls["rbPercentage" + i];
                        curr.Checked = true;
                    }
                }
                //set last item to defaults
                this.Controls["cbCategory" + (locationCounter - 1)].Text    = "";
                this.Controls["txtPercentage" + (locationCounter - 1)].Text = "";
                RadioButton last = (RadioButton)this.Controls["gradingMethod" + (locationCounter - 1) + "Panel"].Controls["rbPoints" + (locationCounter - 1)];
                last.Checked = true;
            }
        }
Пример #11
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);
        }
Пример #12
0
        private bool saveSemester()
        {
            //ensure a semester name was entered
            if (txtSemesterName.Text.Equals(""))
            {
                Util.displayRequiredFieldsError("Semester Name");
            }
            //ensure a semester with the same semester id does not already exist
            else if (semesterId[cbEditSemester.SelectedIndex] != ctrSemesterNum.Value && Database.attributeExists("semesterID = '" + ctrSemesterNum.Value + "'", "Semester"))
            {
                Util.displayError("The Entered Semester Number Already Exists", "Invalid Semester Number");
            }
            //ensure the end semester date occurs on or after the start semester date
            else if (dtSemesterEndDate.Value < dtSemesterStartDate.Value)
            {
                Util.displayError("The End Date Must Be Later Than The Start Date", "Invalid Semester Dates");
            }
            else
            {
                //update the semester fields in the database
                Database.modifyDatabase("UPDATE Semester SET Name = " + Util.quote(txtSemesterName.Text)
                                        + ", StartDate = DATE('" + Database.getDate(dtSemesterStartDate.Value) + "')"
                                        + ", StartDate = DATE('" + Database.getDate(dtSemesterEndDate.Value) + "')"
                                        + " WHERE SemesterID = '" + semesterId[cbEditSemester.SelectedIndex] + "';");

                //update semester id if necessary
                if (semesterId[cbEditSemester.SelectedIndex] != ctrSemesterNum.Value)
                {
                    Database.modifyDatabase("UPDATE Semester SET SemesterID = '" + ctrSemesterNum.Value + "'"
                                            + " WHERE SemesterID = '" + semesterId[cbEditSemester.SelectedIndex] + "';");
                }

                //refresh values in semester combobox
                int previousIndex = cbEditSemester.SelectedIndex;
                Util.addSemesters(cbEditSemester, semesterId, false);
                cbEditSemester.SelectedIndex = previousIndex;

                return(true);
            }
            return(false);
        }
Пример #13
0
        //save grading scale information
        private void btnSaveGradingScale_Click(object sender, EventArgs e)
        {
            //ensure entered grading scale is valid
            if (ctrA.Value <= ctrAminus.Value || ctrAminus.Value <= ctrBplus.Value ||
                ctrBplus.Value <= ctrB.Value || ctrB.Value <= ctrBminus.Value ||
                ctrBminus.Value <= ctrCplus.Value || ctrCplus.Value <= ctrC.Value ||
                ctrC.Value <= ctrCminus.Value || ctrCminus.Value <= ctrDplus.Value ||
                ctrDplus.Value <= ctrD.Value || ctrD.Value <= ctrDminus.Value)
            {
                Util.displayError("Each letter grade value must be higher than the preceding value.",
                                  "Invalid Grading Scale");
                return;
            }

            //grading scale information
            decimal[] gradingScale = new decimal[11];
            string[]  gradeLetter  = { "A", "A-", "B+", "B", "B-", "C+", "C", "C-", "D+", "D", "D-" };

            //store grading scale information
            gradingScale[0]  = ctrA.Value;
            gradingScale[1]  = ctrAminus.Value;
            gradingScale[2]  = ctrBplus.Value;
            gradingScale[3]  = ctrB.Value;
            gradingScale[4]  = ctrBminus.Value;
            gradingScale[5]  = ctrCplus.Value;
            gradingScale[6]  = ctrC.Value;
            gradingScale[7]  = ctrCminus.Value;
            gradingScale[8]  = ctrDplus.Value;
            gradingScale[9]  = ctrD.Value;
            gradingScale[10] = ctrDminus.Value;

            //insert grading scale
            for (int i = 0; i < gradingScale.Length; i++)
            {
                Database.modifyDatabase("UPDATE GradingScaleValue SET BottomPercentage = '" + gradingScale[i] + "' WHERE ClassID = '" + currentClassId + "' AND GradeLetter = '" + gradeLetter[i] + "';");
            }
        }
Пример #14
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);
        }
Пример #15
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);
        }
        //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();
        }
        //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);
        }
Пример #18
0
        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);
        }
        //saves the phone number, returning true if successful and false if there is an error
        private bool savePhoneNumber()
        {
            //require phone number if a phone type is currently entered
            if (txtPhoneNum.Text.Equals("") && cbPhoneType.Text.Equals("") == false)
            {
                Util.displayRequiredFieldsError("Phone Number");
                return(false);
            }

            //if both fields are blank, just ignore (don't save)
            if (txtPhoneNum.Text.Equals("") && cbPhoneType.Text.Equals(""))
            {
                return(true);
            }

            //if simply updating existing value
            if (useInsert == false && phoneNum.Count != 0)
            {
                //ensure a second instance of the phone number doesn't already exist
                if (phoneNum.Contains(txtPhoneNum.Text) && phoneNum.IndexOf(txtPhoneNum.Text) != currentPhoneNum)
                {
                    Util.displayError("This professor has already been assigned this phone number.", "Duplicate Phone Numbers");
                    return(false);
                }
                else
                {
                    //update database
                    Database.modifyDatabase("UPDATE Phone SET PhoneNumber = " + Util.quote(txtPhoneNum.Text) + ", Type = " + Util.quote(cbPhoneType.Text)
                                            + " WHERE ProfId = '" + currentProfId + "' AND PhoneNumber = '" + phoneNum[currentPhoneNum] + "';");

                    //update information in lists (needed for cycling through)
                    phoneNum[currentPhoneNum]  = txtPhoneNum.Text;
                    phoneType[currentPhoneNum] = cbPhoneType.Text;
                }
            }
            //if inserting new value
            else
            {
                //ensure phone number doesn't already exist
                if (phoneNum.Contains(txtPhoneNum.Text) == true)
                {
                    Util.displayError("This professor has already been assigned this phone number.", "Duplicate Phone Numbers");
                }
                else
                {
                    //add to database
                    Database.modifyDatabase("INSERT INTO Phone VALUES(" + Util.quote(txtPhoneNum.Text) + ", '" + currentProfId + "', " + Util.quote(cbPhoneType.Text) + ");");

                    //add to lists and update current phone number pointer
                    phoneNum.Add(txtPhoneNum.Text);
                    phoneType.Add(cbPhoneType.Text);
                    currentPhoneNum = phoneNum.Count - 1;

                    if (phoneNum.Count > 0)
                    {
                        lnkPreviousPhone.Enabled = true;
                        lnkNextPhone.Enabled     = true;
                    }
                }
                //after inserting, assume next operation will be an update
                useInsert = false;
            }
            displayMessage("Phone Number Successfully Saved", Color.DarkGreen);
            return(true);
        }
Пример #20
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);
        }