public EditClass(StudentWorker selectedStudentWorker, int eventDetailsID) { InitializeComponent(); deleteButton.Visible = true; checkBoxes = new CheckBox[] { mondayCheckBox, tuesdayCheckBox, wednesdayCheckBox, thursdayCheckBox, fridayCheckBox }; studentWorker = selectedStudentWorker; studentWorkerNameLabel.Text = selectedStudentWorker.Name; isNewClass = false; EventDetailsID = eventDetailsID; // add class meeting times for the class to edit oldClass = DatabaseManager.GetClass(EventDetailsID); DatabaseManager.RemoveClass(EventDetailsID); // remove the class from database while editing so new times will not conflict with times of the same class if (oldClass.Count > 0) { classNameTextBox.Text = oldClass[0].EventName; } foreach (CalendarEvent classEvent in oldClass) { newClassSchedule.AddEvent(classEvent); ClassMeetingTimePanel newTimePanel = new ClassMeetingTimePanel(); classTimePanel.Controls.Add(newTimePanel); } LayoutTimePanels(); }
/// <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); }
/// <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); }
//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(); } } }