new protected void Page_Init(object sender, EventArgs e) { base.Page_Init(sender, e); int uid = user.ID; using (WebhostEntities db = new WebhostEntities()) { Faculty faculty = db.Faculties.Find(MasqId == -1 ? uid : MasqId); if (faculty == null) { LogError("Unable to locate faculty id {0}", uid); return; } int term = DateRange.GetCurrentOrLastTerm(); List <Section> currentSections = faculty.Sections.Where(sec => sec.Terms.Where(t => t.id == term).Count() > 0).ToList(); State.log.WriteLine("{1} {0}: Found {2} current sections.", DateTime.Now.ToLongTimeString(), DateTime.Today.ToShortDateString(), currentSections.Count); if (SectionId == -1) { int currentBlockId = -1; Dictionary <DateRange, int> data = DateRange.BlockIdsByTime(DateTime.Today); foreach (DateRange classtime in data.Keys) { if (classtime.Contains(DateTime.Now)) { currentBlockId = data[classtime]; if (currentSections.Where(sec => sec.BlockIndex == currentBlockId).Count() > 0) { SectionId = currentSections.Where(sec => sec.BlockIndex == currentBlockId).ToList().First().id; break; } } } if (SectionId == -1) { foreach (DateRange classtime in data.Keys) { if (classtime.Intersects(DateTime.Now.AddMinutes(-30), DateTime.Now)) { currentBlockId = data[classtime]; if (currentSections.Where(sec => sec.BlockIndex == currentBlockId).Count() > 0) { SectionId = currentSections.Where(sec => sec.BlockIndex == currentBlockId).ToList().First().id; break; } } } } } ClassSelectCB.DataSource = SectionListItem.GetDataSource(currentSections.Select(sec => sec.id).ToList()); ClassSelectCB.DataTextField = "Text"; ClassSelectCB.DataValueField = "ID"; ClassSelectCB.DataBind(); foreach (ListItem classItem in ClassSelectCB.Items) { int sectionId = Convert.ToInt32(classItem.Value); Section section = db.Sections.Find(sectionId); if (DateTime.Today.DayOfWeek.Equals(DayOfWeek.Saturday) || DateTime.Today.DayOfWeek.Equals(DayOfWeek.Sunday)) { continue; } bool attendanceTaken = true; foreach (Student student in section.Students.ToList()) { if (section.AttendanceMarkings.Where(att => att.AttendanceDate.Equals(DateTime.Today) && att.StudentID.Equals(student.ID)).Count() <= 0) { attendanceTaken = false; break; } } bool meetsThisDay = false; switch (DateTime.Today.DayOfWeek) { case DayOfWeek.Monday: meetsThisDay = section.Block.MeetsMonday; break; case DayOfWeek.Tuesday: meetsThisDay = section.Block.MeetsTuesday; break; case DayOfWeek.Wednesday: if (!section.Block.MeetsWednesday) { meetsThisDay = false; } else if (section.Block.IsSpecial || db.WednesdaySchedules.Where(w => w.Day.Equals(DateTime.Today)).Count() <= 0) { meetsThisDay = section.Block.MeetsWednesday; } else { meetsThisDay = DateRange.BlockOrderByDayOfWeek(DateTime.Today).Contains(section.Block.Name[0]); } break; case DayOfWeek.Thursday: meetsThisDay = section.Block.MeetsThursday; break; case DayOfWeek.Friday: meetsThisDay = section.Block.MeetsFriday; break; default: break; } if (attendanceTaken) { classItem.Text += " [Done]"; } else if (!meetsThisDay) { classItem.Text += " [No Meeting Today]"; } else { classItem.Text += " [Incomplete]"; } } TodayCB.Visible = false; DateInput.Visible = false; DateSelectBtn.Visible = false; SubmitBtn.Visible = false; } if (this.SectionId != -1) { LoadInfo(SectionId, AttendanceDate); } }
new protected void Page_Init(object sender, EventArgs e) { base.Page_Init(sender, e); WeekLabel.Text = string.Format("Week of {0} through {1}", thisWeek.Start.ToString("dddd, dd MMM"), thisWeek.End.ToString("dddd, dd MMM")); using (WebhostEntities db = new WebhostEntities()) { TableHeaderRow hr = new TableHeaderRow(); hr.Cells.Add(new TableHeaderCell() { Text = "Class" }); foreach (DateTime date in thisWeek.ToList()) { if (date.DayOfWeek.Equals(DayOfWeek.Saturday) || date.DayOfWeek.Equals(DayOfWeek.Sunday)) { continue; } hr.Cells.Add(new TableHeaderCell() { Text = date.ToString("dddd, dd MMM") }); } ClassesTable.Rows.Add(hr); int curTerm = DateRange.GetCurrentOrLastTerm(); if (user.IsStudent || StudentMasq != -1) { AdminPanel.Visible = false; Student student = db.Students.Find(user.IsStudent ? user.ID : StudentMasq); if (StudentMasq != -1) { Faculty teacher = db.Faculties.Find(user.ID); LoadAdminPanel(db, teacher, curTerm); AdminPanel.Visible = true; WeekLabel.Text += String.Format(". For {0} {1}", student.FirstName, student.LastName); } foreach (Section section in student.Sections.Where(s => s.Terms.Where(t => t.id == curTerm).Count() > 0).ToList()) { TableRow row = new TableRow(); String teachersNames = ""; foreach (Faculty fac in section.Teachers.ToList()) { teachersNames += String.Format("{0} {1} ", fac.FirstName, fac.LastName); } row.Cells.Add(new TableCell() { Text = String.Format("[{0}] {1}", section.Block.LongName, section.Course.Name), ToolTip = teachersNames }); foreach (DateTime date in thisWeek.ToList()) { if (date.DayOfWeek.Equals(DayOfWeek.Saturday) || date.DayOfWeek.Equals(DayOfWeek.Sunday)) { continue; } bool meetsThisDay = false; switch (date.DayOfWeek) { case DayOfWeek.Monday: meetsThisDay = section.Block.MeetsMonday; break; case DayOfWeek.Tuesday: meetsThisDay = section.Block.MeetsTuesday; break; case DayOfWeek.Wednesday: if (!section.Block.MeetsWednesday || section.Course.Name.Contains("Tutorial")) { meetsThisDay = false; } else if (section.Block.IsSpecial || db.WednesdaySchedules.Where(w => w.Day.Equals(date)).Count() <= 0) { meetsThisDay = section.Block.MeetsWednesday; } else { meetsThisDay = DateRange.BlockOrderByDayOfWeek(date).Contains(section.Block.Name[0]); } break; case DayOfWeek.Thursday: meetsThisDay = section.Block.MeetsThursday; break; case DayOfWeek.Friday: meetsThisDay = section.Block.MeetsFriday; break; default: break; } String attendanceMarking = meetsThisDay?"*":"No Meeting"; String note = "No Data"; if (section.AttendanceMarkings.Where(att => att.AttendanceDate.Equals(date) && att.StudentID.Equals(StudentMasq == -1 ? user.ID: StudentMasq)).Count() > 0) { AttendanceMarking mark = section.AttendanceMarkings.Where(att => att.AttendanceDate.Equals(date) && att.StudentID.Equals(StudentMasq == -1 ? user.ID : StudentMasq)).Single(); attendanceMarking = mark.Marking.Name; note = mark.Notes; } row.Cells.Add(new TableCell() { Text = attendanceMarking, BackColor = attendanceMarking.Equals("Present") ? System.Drawing.Color.Green : attendanceMarking.Equals("Late") ? System.Drawing.Color.LightGoldenrodYellow : attendanceMarking.Equals("Cut") ? System.Drawing.Color.Red : attendanceMarking.Equals("Excused") ? System.Drawing.Color.LightSeaGreen : meetsThisDay ? System.Drawing.Color.LightCoral : System.Drawing.Color.LavenderBlush, ToolTip = note }); } ClassesTable.Rows.Add(row); } } else { AdminPanel.Visible = true; Faculty teacher = db.Faculties.Find(user.ID); //int curTerm = DateRange.GetCurrentOrLastTerm(); LoadAdminPanel(db, teacher, curTerm); if (TeacherMasq != -1) { teacher = db.Faculties.Find(TeacherMasq); WeekLabel.Text += String.Format(". For {0} {1}", teacher.FirstName, teacher.LastName); } foreach (Section section in teacher.Sections.Where(s => s.Terms.Where(t => t.id == curTerm).Count() > 0).ToList()) { TableRow row = new TableRow(); String teachersNames = ""; foreach (Faculty fac in section.Teachers.ToList()) { teachersNames += String.Format("{0} {1} ", fac.FirstName, fac.LastName); } row.Cells.Add(new TableCell() { Text = String.Format("[{0}] {1}", section.Block.LongName, section.Course.Name), ToolTip = teachersNames }); foreach (DateTime date in thisWeek.ToList()) { if (date.DayOfWeek.Equals(DayOfWeek.Saturday) || date.DayOfWeek.Equals(DayOfWeek.Sunday)) { continue; } bool attendanceTaken = true; foreach (Student student in section.Students.ToList()) { if (section.AttendanceMarkings.Where(att => att.AttendanceDate.Equals(date) && att.StudentID.Equals(student.ID)).Count() <= 0) { attendanceTaken = false; break; } } bool meetsThisDay = false; switch (date.DayOfWeek) { case DayOfWeek.Monday: meetsThisDay = section.Block.MeetsMonday; break; case DayOfWeek.Tuesday: meetsThisDay = section.Block.MeetsTuesday; break; case DayOfWeek.Wednesday: if (!section.Block.MeetsWednesday || section.Course.Name.Contains("Tutorial")) { meetsThisDay = false; } else if (section.Block.IsSpecial || db.WednesdaySchedules.Where(w => w.Day.Equals(date)).Count() <= 0) { meetsThisDay = section.Block.MeetsWednesday; } else { meetsThisDay = DateRange.BlockOrderByDayOfWeek(date).Contains(section.Block.Name[0]); } break; case DayOfWeek.Thursday: meetsThisDay = section.Block.MeetsThursday; break; case DayOfWeek.Friday: meetsThisDay = section.Block.MeetsFriday; break; default: break; } row.Cells.Add(new TableCell() { Text = attendanceTaken ? "Complete" : meetsThisDay? "Incomplete": "No Meeting", BackColor = attendanceTaken ? System.Drawing.Color.Green : meetsThisDay? System.Drawing.Color.Red : System.Drawing.Color.AliceBlue }); } ClassesTable.Rows.Add(row); } } } }