private void DisplayInfo()
        {
            //set name and position
            nameTextBox.Text      = selectedStudentWorker.Name;
            positionComboBox.Text = selectedStudentWorker.JobPosition;

            selectedStudentWorker.UpdateTotalHours();
            totalHoursLabel.Text = "Total Work Hours: " + selectedStudentWorker.TotalHours;

            //set color
            int baseColor = selectedStudentWorker.DisplayColor;
            int red       = baseColor / 256 / 256;
            int green     = baseColor % (256 * 256) / 256;
            int blue      = baseColor % 256;

            colorButton.BackColor = Color.FromArgb(255, red, green, blue);

            //set subjects
            DisplaySubjects();

            //set classes
            DisplayClasses();
        }
Beispiel #2
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();
            }
        }