Exemplo n.º 1
0
        //save office hours
        private bool saveOfficeHours()
        {
            //ignore if no days are 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");
                return(false);
            }

            //determine which days were selected
            bool[] days = { chkOfficeHoursMon.Checked, chkOfficeHoursTue.Checked, chkOfficeHoursWed.Checked,
                            chkOfficeHoursThu.Checked, chkOfficeHoursFri.Checked };

            //add current values to lists
            officeHoursDays.Add(days);
            officeHoursStart.Add(dtOfficeHoursStart.Value);
            officeHoursEnd.Add(dtOfficeHoursEnd.Value);
            return(true);
        }
Exemplo n.º 2
0
        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;
            }

            //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;
            Close();
        }
Exemplo n.º 3
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);
 }
Exemplo n.º 4
0
        //save the phone number values
        private bool savePhoneNum()
        {
            //if both fields are blank, just ignore (don't save)
            if (txtPhoneNum.Text.Equals("") && cbPhoneType.Text.Equals(""))
            {
                return(true);
            }

            if (txtPhoneNum.Text.Equals(""))
            {
                Util.displayRequiredFieldsError("Phone Number");
                return(false);
            }

            //check if phone number is already been added
            if (phoneNumbers.Contains(txtPhoneNum.Text))
            {
                Util.displayError("You have already added this phone number.", "Duplicate Phone Number");
                return(false);
            }

            phoneNumbers.Add(Util.escape(txtPhoneNum.Text));
            phoneTypes.Add(Util.escape(cbPhoneType.Text));
            return(true);
        }
Exemplo n.º 5
0
        //save all entered settings
        private void btnSave_Click(object sender, EventArgs e)
        {
            int port;

            if (int.TryParse(txtSmtpPort.Text, out port) == false)
            {
                Util.displayError("Port number must be an integer value", "Invalid Port Number");
                return;
            }

            //update settings
            PlannerSettings.Default.UseDefaultClient = rbUseMailClient.Checked;
            PlannerSettings.Default.EmailAddress     = txtEmail.Text;

            //only save smtp settings if user has that option checked
            if (rbUseMailClient.Checked == false)
            {
                PlannerSettings.Default.SmtpPort              = port;
                PlannerSettings.Default.SmtpServer            = txtSmtpServer.Text;
                PlannerSettings.Default.RequireAuthentication = chkRequiresAuthentication.Checked;
            }

            //save settings to file
            PlannerSettings.Default.Save();
            Close();
        }
Exemplo n.º 6
0
 static void Main()
 {
     Application.EnableVisualStyles();
     try {
         Application.Run(new AssignmentPlanner());
     }
     catch (Exception ex) {
         Util.displayError("An unexpected error occured. Check the error log for more information.", "Unexpected Error");
         Util.logError(ex.Message);
     }
 }
Exemplo n.º 7
0
        //calculates needed grade on final in order to get desired grade in class
        private void btnCalculate_Click(object sender, EventArgs e)
        {
            double currentGrade, finalWorth, desiredGrade;

            lblGradeNeededValue.Text = "";

            //parse text, ensuring values can be parsed as doubles
            if (double.TryParse(txtCurrentGrade.Text, out currentGrade) == false)
            {
                Util.displayError("Current grade is not a valid number", "Invalid Number");
                return;
            }
            if (double.TryParse(txtFinalExamPercentage.Text, out finalWorth) == false)
            {
                Util.displayError("Final exam percentage is not a valid number", "Invalid Number");
                return;
            }
            if (double.TryParse(txtDesiredPercentage.Text, out desiredGrade) == false)
            {
                Util.displayError("Desired Percentage is not a valid number", "Invalid Number");
                return;
            }

            //check for invalid numbers
            if (currentGrade < 0)
            {
                Util.displayError("Current grade must be positive", "Error");
                return;
            }
            else if (finalWorth < 0 || finalWorth > 100)
            {
                Util.displayError("The final exam percentage must be between 0 and 100", "Error");
                return;
            }
            else if (desiredGrade < 0)
            {
                Util.displayError("Desired grade must be positive", "Error");
                return;
            }

            //calculate needed greed
            double currentPoints = currentGrade * (1.00 - (finalWorth / 100));
            double gradeNeeded   = (desiredGrade - currentPoints) / finalWorth;

            if (gradeNeeded < 0)
            {
                lblGradeNeededValue.Text = "< 0.0000%";
            }
            else
            {
                lblGradeNeededValue.Text = (Math.Round(gradeNeeded * 100, 4)).ToString("F3") + "%";
            }
        }
        //prevent the user from closing without saving if the sum no longer equals 100
        //  (such as after deleting an item)
        private void btnCategoryClose_Click(object sender, EventArgs e)
        {
            //calculate sum
            double sum = 0;

            foreach (double val in percentage)
            {
                sum += val;
            }

            //check if sum equals 100
            if (Math.Abs(100 - sum) > 0.001)
            {
                Util.displayError("After deleting an item, the sum of category percentages no longer add up to 100", "Error");
                return;
            }
            //return to class tab
            Close();
        }
Exemplo n.º 9
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);
        }
Exemplo n.º 10
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            //if database is encrypted
            if (chkEncryptDatabase.Checked == true)
            {
                //check if passwords match
                if (txtPassword.Text.Equals(txtConfirmedPassword.Text) == false)
                {
                    Util.displayError("Passwords do not match", "Invalid Password");
                    return;
                }

                //if passwords match, change password
//                Database.changePassword(txtPassword.Text);    No more password.
            }
            //to permanently decrypt database, set password to null
            else
            {
//                Database.changePassword(null);                No more password.
            }
            Close();
        }
Exemplo n.º 11
0
        private void lnkAddCategory_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            //currently a max of only 15 categories is supported
            if (locationCounter > 14)
            {
                Util.displayError("Too Many Categories. A maximum of 15 categories are currently only supported.", "Too Many Categories");
                return;
            }

            //set the hidden controls to visible for the next line
            this.Controls["cbCategory" + locationCounter].Visible              = true;
            this.Controls["txtPercentage" + locationCounter].Visible           = true;
            this.Controls["gradingMethod" + locationCounter + "Panel"].Visible = true;
            locationCounter++;

            //move buttons down
            lnkAddCategory.Location   = new Point(lnkAddCategory.Location.X, lnkAddCategory.Location.Y + 27);
            btnCategorySave.Location  = new Point(btnCategorySave.Location.X, btnCategorySave.Location.Y + 27);
            btnCategoryClose.Location = new Point(btnCategoryClose.Location.X, btnCategoryClose.Location.Y + 27);

            //resize form
            this.Height += 27;
        }
Exemplo n.º 12
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] + "';");
            }
        }
        //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();
        }
Exemplo n.º 14
0
        private void button1_Click(object sender, EventArgs e)
        {
            //extract user entered information
            string MyFrom    = txtEmailFrom.Text;
            string MyTo      = txtEmailTo.Text;
            string MySubject = txtEmailSubject.Text;
            string MyMessage = txtEmailMessage.Text;

            //check if to open with default email client
            if (PlannerSettings.Default.UseDefaultClient == true)
            {
                //open in email client with entered fields already populated
                openMailClient(MyTo, MySubject, MyMessage);
            }
            else
            {
                string MySmtpMailServerName = PlannerSettings.Default.SmtpServer;
                //ex: "smtp.cedarville.edu" or "smtp.google.com"

                int MySmtpMailServerPort = PlannerSettings.Default.SmtpPort;
                //25 is the default for SMTP (587 for Google)

                SmtpClient MySmtpClient = new SmtpClient(MySmtpMailServerName, MySmtpMailServerPort);

                if (PlannerSettings.Default.RequireAuthentication == true)
                {
                    //get authentication details from user
                    AuthenticationForm credentials = new AuthenticationForm(PlannerSettings.Default.EmailAddress);
                    credentials.ShowDialog(this);

                    //configure credentials
                    MySmtpClient.EnableSsl             = true;
                    MySmtpClient.Timeout               = 3000;
                    MySmtpClient.UseDefaultCredentials = false;
                    MySmtpClient.Credentials           = new NetworkCredential(credentials.username, credentials.password);
                    credentials.eraseCredentials();
                }

                //indicate message is in process of sending
                parent.updateStatus("Status: Message Sending...");

                //send message using new thread so it won't freeze main thread if there is an error
                String           errorMessage = "";
                BackgroundWorker bw           = new BackgroundWorker();
                bw.DoWork += delegate(object s, DoWorkEventArgs args){
                    try {
                        MySmtpClient.Send(MyFrom, MyTo, MySubject, MyMessage);
                    }
                    catch (Exception ex) {
                        errorMessage = ex.Message;
                    }
                };

                bw.RunWorkerCompleted += delegate(object s, RunWorkerCompletedEventArgs args) {
                    if (errorMessage.Equals("") == false)
                    {
                        //display any errors with sending the message
                        Util.displayError(errorMessage, "Error");
                        parent.updateStatus("Status: Message Not Sent");
                        parent.Refresh();
                    }
                    else
                    {
                        //update message status if message sent successfully
                        parent.updateStatus("Status: Message Successfully Sent");
                        parent.Refresh();
                    }
                };

                //start sending message
                bw.RunWorkerAsync();
            }
        }
Exemplo n.º 15
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);
        }
        //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);
        }
Exemplo n.º 17
0
        public static void authenticate()
        {
            planner.updateStatus("Authenticating Google Calendar Account Info");
            string calendarURL = PlannerSettings.Default.CalendarURL;

            if (calendarURL.Equals(""))
            {
                MessageBox.Show("No Calendar URL specified.", "Invalid Settings", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            postUri = new Uri(calendarURL);
            BackgroundWorker bw = new BackgroundWorker();

            bw.DoWork += delegate(object s, DoWorkEventArgs args){
                lock (threadLock) {
                    service = new CalendarService("A+StudentPlanner");
                    if (PlannerSettings.Default.StoredGoogleAccount == true)
                    {
                        byte[]   salt           = Encoding.Unicode.GetBytes("A+ Student Planner Developed By David Riggleman");
                        string[] encryptedBytes = PlannerSettings.Default.Password.Split('-');
                        byte[]   encodedBytes   = new byte[encryptedBytes.Length];
                        for (int i = 0; i < encryptedBytes.Length; i++)
                        {
                            encodedBytes[i] = Byte.Parse(encryptedBytes[i]);
                        }
                        byte[] decodedBytes = ProtectedData.Unprotect(encodedBytes, salt, DataProtectionScope.CurrentUser);
                        service.setUserCredentials(PlannerSettings.Default.Username, Encoding.Unicode.GetString(decodedBytes));

                        try {
                            EventQuery myQuery    = new EventQuery(postUri.ToString());
                            EventFeed  resultFeed = (EventFeed)service.Query(myQuery);
                            authenticated = true;
                        }
                        catch {
                            Util.displayError("Error authenticating Google Calendar Account. Check settings.", "Authentication Error");
                            authenticated = false;
                        }
                    }
                    else
                    {
                        AuthenticationForm form = new AuthenticationForm(PlannerSettings.Default.Username);
                        form.changeText("Enter the credentials for your google account. \n(No information will be stored).", "Enter Google Account Credentials");
                        authenticated = false;
                        bool exit = false;
                        while (exit == false)
                        {
                            form.ShowDialog();
                            if (form.cancelled == true)
                            {
                                exit = true;
                            }
                            else
                            {
                                try {
                                    service.setUserCredentials(form.username, form.password);
                                    EventQuery myQuery    = new EventQuery(postUri.ToString());
                                    EventFeed  resultFeed = (EventFeed)service.Query(myQuery);
                                    authenticated = true;
                                    exit          = true;
                                }
                                catch {
                                    DialogResult retry = MessageBox.Show("Incorrect username or password. Try Again?", "Authentication Error", MessageBoxButtons.RetryCancel, MessageBoxIcon.Exclamation);
                                    if (retry != DialogResult.Retry)
                                    {
                                        exit = true;
                                    }
                                }
                            }
                        }
                        form.eraseCredentials();
                    }
                }
            };

            bw.RunWorkerCompleted += delegate(object s, RunWorkerCompletedEventArgs args) {
                if (authenticated == true)
                {
                    planner.updateStatus("Status: Google Authentication Successful");
                    planner.Refresh();
                }
                else
                {
                    planner.updateStatus("Status: Google Authentication Failed");
                    planner.Refresh();
                }
            };

            //start thread
            bw.RunWorkerAsync();
        }
Exemplo n.º 18
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);
        }
        //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);
        }
Exemplo n.º 20
0
        //save the category 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 duplicate grade categories exist
            if (duplicateTypeCheck() == false)
            {
                Util.displayError("Two categories cannot have the same name", "Duplicate Grade Categories");
                return;
            }

            //store added information
            for (int i = 0; i < locationCounter; i++)
            {
                if (this.Controls["cbCategory" + i].Text.Equals("") == false &&
                    this.Controls["txtPercentage" + i].Text.Equals("") == false)
                {
                    category.Add(this.Controls["cbCategory" + i].Text);

                    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");

                        //clear all values currently in lists and return
                        category.Clear();
                        percentage.Clear();
                        method.Clear();
                        return;
                    }

                    //store running sum
                    sum += categoryPercentage;
                    percentage.Add(categoryPercentage);

                    //get the type of grading method to use
                    RadioButton point = (RadioButton)this.Controls["gradingMethod" + i + "Panel"].Controls["rbPoints" + i];
                    RadioButton perc  = (RadioButton)this.Controls["gradingMethod" + i + "Panel"].Controls["rbPercentage" + i];
                    if (point.Checked == true)
                    {
                        method.Add(point.Text);
                    }
                    else
                    {
                        method.Add(perc.Text);
                    }
                }
            }

            //ensure sum of all 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");

                //clear all values currently in lists and return
                category.Clear();
                percentage.Clear();
                method.Clear();
                return;
            }

            Close();
        }
Exemplo n.º 21
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);
        }
Exemplo n.º 22
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);
        }