//Remove button is clicked
        private void RemoveSubject_Click(object sender, EventArgs e)
        {
            if (subjectListView.SelectedIndices.Count != 0)
            {
                Subject      selectedSubject = subjectList[subjectListView.SelectedItems[0].Index];
                DialogResult dialogResult    = new ConfirmationPopup("Are you sure you want to remove " + selectedSubject.abbreviation + " " + selectedSubject.subjectNumber, "This will remove it from all student workers.").ShowDialog();
                if (dialogResult == DialogResult.OK)
                {
                    selectedSubject.RemoveSubject();

                    subjectList = Subject.GetSubjects();
                    displaySubjects();
                }
            }
        }
        private void RemoveSubjectButton_Click(object sender, EventArgs e)
        {
            DialogResult dialogResult = new ConfirmationPopup("Are you sure you want to remove the subject(s)?", "This will only remove them from " + selectedStudentWorker.Name).ShowDialog();

            if (dialogResult == DialogResult.OK)
            {
                int i = 0;
                foreach (Subject subject in subjectsTutored)
                {
                    if (subjectListView.Items[i].Checked)
                    {
                        selectedStudentWorker.RemoveSubjectTutored(subject.subjectID);
                    }
                    i++;
                }

                //Refresh list of subjects
                DisplaySubjects();
            }
        }
        private void RemoveButton_Click(object sender, EventArgs e)
        {
            if (studentWorkerListView.SelectedIndices.Count != 0)
            {
                //Get selected student worker
                StudentWorker selectedStudentWorker = StudentWorker.allStudentWorkers[studentWorkerListView.SelectedItems[0].Index];

                //Ask for confirmation from the user
                DialogResult dialogResult = new ConfirmationPopup("Are you sure you want to remove " + selectedStudentWorker.Name + "?", "This will remove them from the schedule.").ShowDialog();
                if (dialogResult == DialogResult.OK)
                {
                    //Remove the student worker
                    selectedStudentWorker.RemoveStudentWorker();
                    //TODO: Remove all the student worker's schedule events and subjects

                    StudentWorker.allStudentWorkers = StudentWorker.GetStudentWorkers();
                    DisplayStudentWorkers();
                }
            }
        }
Example #4
0
        //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();
                }
            }
        }
        private void CreateButton_Click(object sender, EventArgs e)
        {
            bool shouldSave = true;

            StudentWorker[] sw = DatabaseManager.GetStudentWorkerByID(selectedEvent.StudentID);

            // if StudentWorker could not be found there is an error
            if (sw[0] == null)
            {
                Console.Error.WriteLine("StudentWorker not found for selected Work event.");
                return;
            }

            StudentWorker selectedStudentWorker = sw[0];

            selectedStudentWorker.WorkSchedule  = DatabaseManager.GetSchedule(selectedStudentWorker.StudentID, CalendarEvent.WORK);
            selectedStudentWorker.ClassSchedule = DatabaseManager.GetSchedule(selectedStudentWorker.StudentID, CalendarEvent.CLASS);
            selectedStudentWorker.BuildAvailabilitySchedule();
            selectedStudentWorker.UpdateTotalHours();
            Time          startTime = new Time(startTimePicker.Value.TimeOfDay.Hours, startTimePicker.Value.TimeOfDay.Minutes);
            Time          endTime   = new Time(endTimePicker.Value.TimeOfDay.Hours, endTimePicker.Value.TimeOfDay.Minutes);
            CalendarEvent newEvent  = new CalendarEvent(selectedEvent.EventName, startTime, endTime, selectedEvent.Day, selectedEvent.type, selectedEvent.PrimaryText,
                                                        selectedEvent.StudentID, selectedStudentWorker.DisplayColor);

            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 - (selectedEvent.EndTime - selectedEvent.StartTime).ToDouble() + (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)
                {
                    // 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(newEvent))
                    {
                        //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 (shouldSave)
            {
                // save the updated event details
                selectedEvent.UpdateEvent(startTimePicker.Value.Hour, startTimePicker.Value.Minute, endTimePicker.Value.Hour, endTimePicker.Value.Minute);
                this.Close();
            }
        }