/// <summary> /// Save the schedule for the new class when save button clicked /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void SaveClassButton_Click(object sender, EventArgs e) { if (newClassSchedule.Events.Count > 0) { // save the class newClassSchedule.SaveSchedule(studentWorker.StudentID); studentWorker.GetClassSchedule(); isSaved = true; this.Close(); } }
//Create button is clicked private void CreateButton_Click(object sender, EventArgs e) { if (studentWorkerListView.SelectedIndices.Count != 0) { StudentWorker selectedStudentWorker = studentWorkerList[studentWorkerListView.SelectedItems[0].Index]; selectedStudentWorker.UpdateTotalHours(); IndividualSchedule newShifts = new IndividualSchedule(); bool shouldSave = true; bool boxChecked = false; for (int i = 0; i < checkBoxes.Length; i++) { if (checkBoxes[i].Checked) { boxChecked = true; Time startTime = new Time(startTimePicker.Value.TimeOfDay.Hours, startTimePicker.Value.TimeOfDay.Minutes); Time endTime = new Time(endTimePicker.Value.TimeOfDay.Hours, endTimePicker.Value.TimeOfDay.Minutes); if (endTime < startTime) { new AlertDialog("Start time should be before end time.").ShowDialog(); shouldSave = false; } else if (endTime.hours - startTime.hours > 5 && (selectedStudentWorker.JobPosition.Equals("Guru") || selectedStudentWorker.JobPosition.Equals("Lead Guru"))) { new AlertDialog("A work shift should not be longer than 5 hours.").ShowDialog(); shouldSave = false; } else { DialogResult result = DialogResult.OK; if ((selectedStudentWorker.JobPosition.Equals("Guru") || selectedStudentWorker.JobPosition.Equals("Lead Guru")) && selectedStudentWorker.TotalHours + (endTime - startTime).ToDouble() > 20) { result = new ConfirmationPopup("Adding this work shift will put " + selectedStudentWorker.Name + " over 20 hours a week.", "Are you sure you want to do this?").ShowDialog(); if (!(result == DialogResult.OK)) { shouldSave = false; } } if (result == DialogResult.OK) { //Create new event CalendarEvent newWorkEvent = new CalendarEvent("Work", startTime, endTime, i, CalendarEvent.WORK, selectedStudentWorker.Name, selectedStudentWorker.StudentID, selectedStudentWorker.DisplayColor); //Make sure that the new work shift doesn't conflict with student worker's class schedule //if the new work event is in the student's availability schedule if (selectedStudentWorker.GetAvailabilitySchedule().Contains(newWorkEvent) && !selectedStudentWorker.WorkSchedule.Overlaps(newWorkEvent)) { newShifts.AddEvent(newWorkEvent); } else { //Display conflict error //TODO: Display better error message new AlertDialog("The shift conflicts with one of the student worker's classes or work shifts").ShowDialog(); shouldSave = false; } } } } } if (boxChecked && shouldSave) { newShifts.SaveSchedule(selectedStudentWorker.StudentID); this.Close(); } else if (!boxChecked) { new AlertDialog("You must select a day for the shift.").ShowDialog(); } } }