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(); }
private void SaveButton_Click(object sender, EventArgs e) { //Get user's input string idString = IDTextbox.Text; string name = nameTextbox.Text; string position = positionComboBox.Text; int color = colorButton.BackColor.ToArgb() & 0x00FFFFFF; //verify user input if (!StudentWorker.VerifyID(idString)) { return; } int id = Int32.Parse(idString); //Create and save student worker bool success = StudentWorker.CreateStudentWorker(id, name, position, color); if (success) { this.DialogResult = DialogResult.Yes; this.Close(); } else { new AlertDialog("Could not save new student worker.").ShowDialog(); } }
public EditClass(StudentWorker selectedStudentWorker) { InitializeComponent(); checkBoxes = new CheckBox[] { mondayCheckBox, tuesdayCheckBox, wednesdayCheckBox, thursdayCheckBox, fridayCheckBox }; studentWorker = selectedStudentWorker; studentWorkerNameLabel.Text = selectedStudentWorker.Name; isNewClass = true; }
private void NewStudentWorkerButton_Click(object sender, EventArgs e) { AddNewStudentWorker newWorker = new AddNewStudentWorker(); newWorker.ShowDialog(); StudentWorker.allStudentWorkers = StudentWorker.GetStudentWorkers(); DisplayStudentWorkers(); }
private void StudentWorkerListView_DoubleClick(object sender, EventArgs e) { if (studentWorkerListView.SelectedIndices.Count != 0) { StudentWorker selectedStudentWorker = StudentWorker.allStudentWorkers[studentWorkerListView.SelectedItems[0].Index]; new StudentWorkerInfoForm(selectedStudentWorker).ShowDialog(); StudentWorker.allStudentWorkers = StudentWorker.GetStudentWorkers(); DisplayStudentWorkers(); } }
public static bool CreateStudentWorker(int studentID, string name, string position, int color) { StudentWorker newStudentWorker = new StudentWorker(studentID, name, position, color); newStudentWorker.Selected = true; // display the new student worker by default //Call save function from DBMgr bool success = DatabaseManager.SaveStudentWorker(newStudentWorker); if (success) { // go ahead and add student worker so the database does not need to be queried for all student workers immediately allStudentWorkers.Add(newStudentWorker); } return(success); }
/// <summary> /// Retrieves a list of studentIDs of the student workers who tutor a selected subject /// </summary> /// <param name="subjectID">The id of the subject</param> /// <returns>A list of integers containing the studentIDs of the students who tutor the subject</returns> public static List <StudentWorker> GetTutorsForSubject(int subjectID) { List <StudentWorker> tutorList = new List <StudentWorker>(); DataTable table = new DataTable(); try { Console.Write("Connecting to MySql... "); conn.Open(); string sql = @"SELECT sw.studentID, sw.studentName FROM studentworker sw JOIN subjecttutored sub on sw.studentID = sub.studentID WHERE sub.subjectID = @subID AND sw.studentID IN (SELECT StudentWorkerID FROM StudentWorkerSchedule WHERE ScheduleID = (SELECT ScheduleID FROM CurrentSchedule) );"; MySqlCommand cmd = new MySqlCommand(sql, conn); cmd.Parameters.AddWithValue("@subID", subjectID); 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."); foreach (DataRow row in table.Rows) { int studentID = (int)row["studentID"]; string name = row["studentName"].ToString(); StudentWorker tutor = new StudentWorker(studentID, name); tutorList.Add(tutor); } table.Dispose(); return(tutorList); }
public static List <StudentWorker> GetStudentWorkers() { List <StudentWorker> studentWorkers = new List <StudentWorker>(); DataTable table = new DataTable(); try { Console.Write("Connecting to MySql... "); conn.Open(); string sql = @"SELECT studentID, studentName, displayColor, jobPosition FROM studentworker WHERE studentID IN (SELECT StudentWorkerID FROM StudentWorkerSchedule WHERE ScheduleID = (SELECT ScheduleID FROM CurrentSchedule) );" ; MySqlCommand cmd = new MySqlCommand(sql, conn); 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."); foreach (DataRow row in table.Rows) { string name = row["studentName"].ToString(); string jobPosition = row["jobPosition"].ToString(); int displayColor = (int)row["displayColor"]; int studentID = (int)row["studentID"]; StudentWorker sw = new StudentWorker(studentID, name, jobPosition, displayColor); studentWorkers.Add(sw); } table.Dispose(); return(studentWorkers); }
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(); } } }
private string GetSubjectString(StudentWorker studentWorker) { string subjectString = ""; //Get all subjects tutored by the student worker List <Subject> subjectList = studentWorker.GetSubjectsTutored(); //Add each subject into string foreach (Subject subject in subjectList) { subjectString += subject.abbreviation + " " + subject.subjectNumber + ", "; } //Remove the final comma if (subjectString.Length > 0) { subjectString = subjectString.Substring(0, (subjectString.Length - 2)); } return(subjectString); }
public static StudentWorker[] GetStudentWorkerByID(int studentID) { StudentWorker [] studentWorkers = new StudentWorker[1]; try { Console.Write("Connecting to MySql... "); conn.Open(); string sql = @"SELECT studentName, displayColor, jobPosition FROM studentworker WHERE studentID = @studentID AND studentID IN (SELECT StudentWorkerID FROM StudentWorkerSchedule WHERE ScheduleID = (SELECT ScheduleID FROM CurrentSchedule) );" ; MySqlCommand cmd = new MySqlCommand(sql, conn); cmd.Parameters.AddWithValue("@studentID", studentID); MySqlDataReader reader = cmd.ExecuteReader(); if (reader.Read()) { string name = reader["studentName"].ToString(); string jobPosition = reader["jobPosition"].ToString(); int displayColor = (int)reader["displayColor"]; studentWorkers[0] = new StudentWorker(studentID, name, jobPosition, displayColor); } cmd.Dispose(); reader.Dispose(); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } // close connection conn.Close(); Console.WriteLine("Done."); return(studentWorkers); }
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(); }
/// <summary> /// Saves a new student worker in the database, and add them to the current schedule /// </summary> /// <param name="student">A student worker object containing the information for the new student worker</param> /// <returns>True if the save was successful. False if there was an error.</returns> public static bool SaveStudentWorker(StudentWorker student) { bool success = false; try { Console.Write("Connecting to MySql... "); conn.Open(); string sql = @"REPLACE studentworker (studentID, studentName, displayColor, jobPosition) VALUES (@studentID, @name, @color, @position);"; MySqlCommand cmd = new MySqlCommand(sql, conn); cmd.Parameters.AddWithValue("@studentID", student.StudentID); cmd.Parameters.AddWithValue("@name", student.Name); cmd.Parameters.AddWithValue("@color", student.DisplayColor); cmd.Parameters.AddWithValue("@position", student.JobPosition); cmd.ExecuteNonQuery(); cmd.Dispose(); // add student worker to the current schedule sql = @"INSERT INTO StudentWorkerSchedule (StudentWorkerID, ScheduleID) VALUES (@studentID, (SELECT (ScheduleID) FROM CurrentSchedule));"; cmd = new MySqlCommand(sql, conn); cmd.Parameters.AddWithValue("@studentID", student.StudentID); cmd.ExecuteNonQuery(); cmd.Dispose(); Console.WriteLine("Student Worker created."); success = true; } catch (Exception ex) { Console.WriteLine(ex.ToString()); } // close connection conn.Close(); Console.WriteLine("Done."); return(success); }
//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(); } } }
public AddSubjectToStudentWorker(StudentWorker selected) { InitializeComponent(); selectedStudentWorker = selected; }
private void ViewAllWorkers_Load(object sender, EventArgs e) { StudentWorker.allStudentWorkers = StudentWorker.GetStudentWorkers(); DisplayStudentWorkers(); }
public bool Equals(StudentWorker other) { return(other != null && StudentID == other.StudentID); }
public StudentWorkerInfoForm(StudentWorker selected) { InitializeComponent(); selectedStudentWorker = selected; }
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(); } }