private void SaveBtn_Click(object sender, EventArgs e) { try { DateTime start = StartDateTimePicker.Value; string temp = "0"; string minute_temp = "0"; // store temp time int hour = 0; // parsed hour int minute = 0; bool reminderset = false; // To Check if User Wants a Reminder or Not if (PlaceCombo.SelectedItem == null) // Task Has no associated place { if (ReminderHourCombo.SelectedItem != null) { if (!ReminderHourCombo.SelectedItem.Equals("No Alarm")) { temp = ReminderHourCombo.SelectedItem.ToString(); // parse the hour reminderset = true; } else { reminderset = false; } } if (ReminderMinutesCombo.SelectedItem != null) { if (!ReminderMinutesCombo.SelectedItem.Equals("No Alarm")) { minute_temp = ReminderMinutesCombo.SelectedItem.ToString(); reminderset = true; } else { reminderset = false; } } hour = int.Parse(temp); // convert hour to int minute = int.Parse(minute_temp); // convert minutes to int DateTime due = new DateTime(DueDateTimePicker.Value.Year, DueDateTimePicker.Value.Month, DueDateTimePicker.Value.Day, hour, minute, 0); // pass the integer hour as parameter to constructor task = new Task(); task.Subject = SubjectCombo.Text; task.Complete = complete; task.StartDate = StartDateTimePicker.Value; task.DueDate = due; if (reminderset == true) { task.ReminderTime = due; } OutlookSession os = new OutlookSession(); TaskFolder folder = os.Tasks; if (SubjectCombo.Text.ToString() != "") { folder.Items.Add(task); // save to folder MessageBox.Show("Task Saved Successfully", "Success", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button2); } else { MessageBox.Show("Subject Can't Be Empty"); } } else //Task has an associated place { if (ReminderHourCombo.SelectedItem != null) { if (!ReminderHourCombo.SelectedItem.Equals("No Alarm")) { temp = ReminderHourCombo.SelectedItem.ToString(); // parse the hour reminderset = true; } else { reminderset = false; } } if (ReminderMinutesCombo.SelectedItem != null) { if (!ReminderMinutesCombo.SelectedItem.Equals("No Alarm")) { minute_temp = ReminderMinutesCombo.SelectedItem.ToString(); reminderset = true; } else { reminderset = false; } } hour = int.Parse(temp); // convert hour to int minute = int.Parse(minute_temp); // convert minutes to int foreach (Place p in place_list) { if (p.PlaceNameProp.Equals(PlaceCombo.SelectedItem.ToString())) { Selected_Place_ID = p.PlaceIDProp; } } hour = int.Parse(temp); // convert hour to int minute = int.Parse(minute_temp); // convert minutes to int DateTime due = new DateTime(DueDateTimePicker.Value.Year, DueDateTimePicker.Value.Month, DueDateTimePicker.Value.Day, hour, minute, 0); // pass the integer hour as parameter to constructor tsk = new CustomTask(SubjectCombo.Text.ToString(), complete, start, due, reminderset , due, Selected_Place_ID); if (SubjectCombo.Text != null) { tsk.SaveTaskToOutlookFolder(); // save to folder tsk.SaveTaskToDbase(tsk); } else { MessageBox.Show("Subject Can't Be Empty"); } ////////////////////////////////////////////////// Save to Dbase // set selected place id to Task Object MessageBox.Show("Task Saved Successfully", "Success", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button2); } } catch (Exception ex) { MessageBox.Show(ex.ToString()); MessageBox.Show("Error Saving Task...Please Retry", "Error", MessageBoxButtons.RetryCancel, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button2); } SubjectCombo.Text = null; ReminderHourCombo.Text = null; PlaceCombo.Text = null; }