private void UpdateStudents() { studentsList.Items.Clear(); studentsInListView.Clear(); using (StudentDbContext db = new StudentDbContext()) { DbSet <Student> students = db.Students; foreach (var student in students) { // Fetch presences of student db.Entry(student).Collection(x => x.Presences).Load(); Console.WriteLine(student.Presences.Count); int days = DateTime.DaysInMonth(listedDate.Year, listedDate.Month); string[] itemData = new string[days + 1]; itemData[0] = student.Name; foreach (Presence presence in student.Presences) { Console.WriteLine(presence.Date); if (presence.Date.Year == listedDate.Year && presence.Date.Month == listedDate.Month) { int i; if ((i = FindIndexInDayIndexes(presence.Date.Day)) != -1) { itemData[i] = PresenceTypeEnum.ToString(presence.Type, true); } } } ListViewItem item = new ListViewItem(itemData); studentsList.Items.Add(item); studentsInListView.Add(student, item); } } ColorStundentList(); }
public WriteAbsenceForm(Student student, DateTime date) { InitializeComponent(); saveBtn.DialogResult = DialogResult.OK; _student = student; presences.Add(PresenceTypeEnum.ToString(PresenceType.Present), PresenceType.Present); presences.Add(PresenceTypeEnum.ToString(PresenceType.Absent), PresenceType.Absent); presences.Add(PresenceTypeEnum.ToString(PresenceType.Excused), PresenceType.Excused); int first = absenceTypeBox.Items.Add(PresenceTypeEnum.ToString(PresenceType.Present)); absenceTypeBox.Items.Add(PresenceTypeEnum.ToString(PresenceType.Absent)); absenceTypeBox.Items.Add(PresenceTypeEnum.ToString(PresenceType.Excused)); absenceTypeBox.SelectedIndex = first; studentsNameLabel.Text = student.Name; dateTimePicker1.Value = date; }
public override string ToString() { return(string.Format("ID: {0}; Student: {1}; Date: {2}; Presence: {3};", Id, Student.Name, Date.ToShortDateString(), PresenceTypeEnum.ToString(Type))); }
private void OnPresenceChangedCallback(Student student, Presence presence) { Console.WriteLine(presence); DateTime date = presence.Date; ListViewItem item = studentsInListView[student]; ListViewItem.ListViewSubItemCollection itemData = item.SubItems; itemData[FindIndexInDayIndexes(date.Day)] = new ListViewItem.ListViewSubItem(item, PresenceTypeEnum.ToString(presence.Type, true)); }