/// <summary>
        /// Load the class or work schedule from the database for the specified student worker.
        /// </summary>
        /// <param name="studentID">The studentID of the student worker whose schedule will be loaded</param>
        /// <returns>Schedule of class or work events for the specified student worker</returns>
        public static IndividualSchedule GetSchedule(int studentID, int scheduleType)
        {
            DataTable table = new DataTable();

            try
            {
                Console.Write("Connecting to MySql... ");
                conn.Open();
                string       sql = @"SELECT eventID, eventType, startHour, startMinute, endHour, endMinute, 
                            day, Details, eventName, studentName, sw.studentID, displayColor
                            FROM studentworker sw JOIN scheduleevent e ON e.studentID = sw.studentID JOIN EventDetails d ON e.Details = d.EventDetailsID
                            WHERE sw.studentID = @id AND e.eventType = @scheduleType 
                                AND e.ScheduleID = (SELECT (ScheduleID) FROM CurrentSchedule);";
                MySqlCommand cmd = new MySqlCommand(sql, conn);
                cmd.Parameters.AddWithValue("@id", studentID);
                cmd.Parameters.AddWithValue("@scheduleType", scheduleType);
                MySqlDataAdapter myAdapter = new MySqlDataAdapter(cmd);
                myAdapter.Fill(table);
                cmd.Dispose();
                myAdapter.Dispose();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }

            // close connection
            conn.Close();
            Console.WriteLine("Done.");

            IndividualSchedule newSchedule = new IndividualSchedule();

            foreach (DataRow row in table.Rows)
            {
                string        eventName    = row["eventName"].ToString();
                int           eventID      = (int)row["eventID"];
                int           eventType    = (int)row["eventType"];
                int           startHour    = (int)row["startHour"];
                int           startMinute  = (int)row["startMinute"];
                int           endHour      = (int)row["endHour"];
                int           endMinute    = (int)row["endMinute"];
                int           day          = (int)row["day"];
                string        studentName  = row["studentName"].ToString();
                int           newStudentID = (int)row["studentID"];
                int           displayColor = (int)row["displayColor"];
                int           details      = (int)row["Details"];
                Time          startTime    = new Time(startHour, startMinute);
                Time          endTime      = new Time(endHour, endMinute);
                CalendarEvent newEvent     = new CalendarEvent(eventName, startTime, endTime, day, eventType, studentName, newStudentID, displayColor);

                // set the EventDetailsID for the new event
                newEvent.DetailsID = details;

                newEvent.EventID = eventID;
                newSchedule.AddEvent(newEvent);
            }

            table.Dispose();
            return(newSchedule);
        }
Example #2
0
        /// <summary>
        /// Build an IndividualSchedule for all the times a subject is tutored to show on subject flyers
        /// </summary>
        /// <returns>IndividualSchedule containing all the times the subject is tutored</returns>
        public IndividualSchedule SetFlyer()
        {
            List <StudentWorker> tutorList       = GetTutors();
            IndividualSchedule   subjectSchedule = new IndividualSchedule();
            IndividualSchedule   tutorSchedule   = new IndividualSchedule();

            foreach (StudentWorker tutor in tutorList)
            {
                tutor.GetWorkSchedule();
                foreach (CalendarEvent newEvent in tutor.WorkSchedule.Events)
                {
                    tutorSchedule.AddEvent(newEvent);
                }
            }

            foreach (CalendarEvent shift in tutorSchedule.Events)
            {
                if (!subjectSchedule.Contains(shift))
                {
                    if (!subjectSchedule.CoverageOverlaps(shift))
                    {
                        subjectSchedule.AddEvent(shift);
                    }
                    else
                    {
                        subjectSchedule.Merge(shift);
                    }
                }
            }

            return(subjectSchedule);
        }
Example #3
0
 private void SetLabels(IndividualSchedule subjectSchedule)
 {
     Label[] labels = { mondayLabel, tuesdayLabel, wednesdayLabel, thursdayLabel, fridayLabel };
     foreach (CalendarEvent workEvent in subjectSchedule.Events)
     {
         labels[workEvent.Day].Text += workEvent.StartTime.ToString() + " - " + workEvent.EndTime.ToString() + "; ";
     }
     foreach (Label label in labels)
     {
         label.Text = label.Text.Substring(0, label.Text.Length - 2);
     }
 }
Example #4
0
        private void PopulateCalendars()
        {
            // refresh student workers from the database
            StudentWorker.allStudentWorkers = StudentWorker.GetStudentWorkers();

            calendarWeekView1.Clear();
            calendarDayView1.Clear();

            // TODO - only get selected student workers
            foreach (StudentWorker sw in StudentWorker.allStudentWorkers)
            {
                if (!sw.Selected)
                {
                    continue;
                }
                // Show work schedule
                IndividualSchedule w = sw.WorkSchedule;
                calendarWeekView1.AddSchedule(w);
                calendarDayView1.AddSchedule(w);

                // include class schedule only if enabled
                if (showClasses)
                {
                    IndividualSchedule s = sw.ClassSchedule;
                    calendarWeekView1.AddSchedule(s);
                    calendarDayView1.AddSchedule(s);
                }

                // include availability schedule only if enabled
                if (showAvailability)
                {
                    IndividualSchedule a = sw.GetAvailabilitySchedule();
                    calendarWeekView1.AddSchedule(a);
                    calendarDayView1.AddSchedule(a);
                }
            }

            calendarWeekView1.Invalidate(false);
            calendarDayView1.Invalidate();
        }
Example #5
0
        /// <summary>
        /// Add every event of each schedule to the calendar, maintaining sequential order by merging. Assumes each schedule is sorted.
        /// </summary>
        /// <param name="schedules">List of schedule objects containing events sorted in sequential order</param>
        public void AddSchedule(IndividualSchedule schedule)
        {
            int events_index = 0, schedule_index = 0;

            // merge events from the schedule with current events on the calendar
            while (events_index < CalendarEvents.Count && schedule_index < schedule.Events.Count)
            {
                while (events_index < CalendarEvents.Count && CalendarEvents[events_index] < schedule.Events[schedule_index])
                {
                    events_index++;
                }
                CalendarEvents.Insert(events_index, schedule.Events[schedule_index]);
                schedule_index++;
                events_index++;
            }

            // add remaining events on the schedule to the calendar
            for (; schedule_index < schedule.Events.Count; schedule_index++)
            {
                CalendarEvents.Add(schedule.Events[schedule_index]);
            }
        }
 private void SaveSubjectSchedulesButton_Click(object sender, EventArgs e)
 {
     using (StreamWriter w = File.CreateText("Subject Schedule.txt"))
     {
         foreach (Subject s in subjectList)
         {
             w.WriteLine("<p><u><strong>" + s.abbreviation + "&nbsp;" + s.subjectNumber + "</strong></u></p>");
             IndividualSchedule coverageSchedule = s.SetFlyer();
             string[]           dayTimes         = { "Monday: ", "Tuesday: ", "Wednesday: ", "Thursday: ", "Friday: " };
             foreach (CalendarEvent workEvent in coverageSchedule.Events)
             {
                 dayTimes[workEvent.Day] += workEvent.StartTime.ToString() + " - " + workEvent.EndTime.ToString() + "; ";
             }
             foreach (string timeString in dayTimes)
             {
                 string times = timeString.Replace(" ", "&nbsp;");
                 w.WriteLine("<p>" + times + "</p>");
             }
             w.WriteLine();
         }
     }
 }
Example #7
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();
                }
            }
        }
Example #8
0
        /// <summary>
        /// Build the schedule of available work times for the student from their class schedule, if it is set.
        /// </summary>
        public void BuildAvailabilitySchedule()
        {
            Availability.Clear();

            if (ClassSchedule == null)
            {
                return;
            }

            List <CalendarEvent>[] dailyEvents = new List <CalendarEvent>[]
            {
                new List <CalendarEvent>(),
                new List <CalendarEvent>(),
                new List <CalendarEvent>(),
                new List <CalendarEvent>(),
                new List <CalendarEvent>()
            };

            foreach (CalendarEvent classMeeting in ClassSchedule.Events)
            {
                dailyEvents[(int)classMeeting.Day].Add(classMeeting);
            }

            int  day = 0;
            Time minimumShiftTime = new Time(0, 30);

            foreach (List <CalendarEvent> dayClasses in dailyEvents)
            {
                // if no classes for the day, available hours equal open hours
                if (dayClasses.Count == 0)
                {
                    Time availableStart = WorkLocation.openingTimes[(int)day];
                    Time availableStop  = WorkLocation.closingTimes[(int)day];
                    Availability.AddEvent(new CalendarEvent("Availability", availableStart, availableStop, day, CalendarEvent.AVAILABILITY, Name, StudentID, DisplayColor));
                }
                for (int i = 0; i < dayClasses.Count; i++)
                {
                    if (i == 0)
                    {
                        // check if at least 45 minutes between opening time and start of first class
                        if (dayClasses[i].StartTime - WorkLocation.openingTimes[(int)day] >= new Time(0, 45))
                        {
                            Time availableStart = WorkLocation.openingTimes[(int)day];
                            Time availableStop  = IndividualSchedule.GetPrecedingStopTime(dayClasses[i].StartTime);
                            Availability.AddEvent(new CalendarEvent("Availability", availableStart, availableStop, day, CalendarEvent.AVAILABILITY, Name, StudentID, DisplayColor));
                        }
                    }
                    else            // attempt to schedule availability between classes
                    {
                        // check if at least 1 hour between end of previous class and start of this class
                        if (dayClasses[i].StartTime.SubtractTime(dayClasses[i - 1].EndTime) >= new Time(1, 0))
                        {
                            Time availableStart = IndividualSchedule.GetSucceedingStartTime(dayClasses[i - 1].EndTime);
                            Time availableStop  = IndividualSchedule.GetPrecedingStopTime(dayClasses[i].StartTime);

                            // check that available stop time is before closing time; if not, set available stop time to the closing time
                            if (availableStop > WorkLocation.closingTimes[day])
                            {
                                availableStop = WorkLocation.closingTimes[day];

                                // if available time was set to the closing time, make sure the shift is still at least 1.5 hours long
                                if (availableStop.SubtractTime(availableStart) >= minimumShiftTime)
                                {
                                    Availability.AddEvent(new CalendarEvent("Availability", availableStart, availableStop, day, CalendarEvent.AVAILABILITY, Name, StudentID, DisplayColor));
                                }
                            }
                            else
                            {
                                Availability.AddEvent(new CalendarEvent("Availability", availableStart, availableStop, day, CalendarEvent.AVAILABILITY, Name, StudentID, DisplayColor));
                            }
                        }
                    }

                    if (i == dayClasses.Count - 1)         // attempt to schedule availability between latest class and closing time
                    {
                        // check if at least 45 minutes between end of this class and closing time
                        if (WorkLocation.closingTimes[day].SubtractTime(dayClasses[i].EndTime) >= new Time(0, 45))
                        {
                            Time availableStart = IndividualSchedule.GetSucceedingStartTime(dayClasses[i].EndTime);
                            Time availableStop  = WorkLocation.closingTimes[day];
                            Availability.AddEvent(new CalendarEvent("Availability", availableStart, availableStop, day, CalendarEvent.AVAILABILITY, Name, StudentID, DisplayColor));
                        }
                    }
                }
                day++;
            }
        }