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(uid); if (faculty == null) { LogError("Unable to locate faculty id {0}", uid); return; } int term = Import.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(); 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); 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); } }