//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(); } }
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); }
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); }