public static List <StudentListItem> GetDataSource(List <int> ids) { List <StudentListItem> items = new List <StudentListItem>(); foreach (int id in ids) { StudentListItem item = new StudentListItem(id); if (item.ID != -1) { items.Add(item); } } return(items); }
protected void Page_Init(object sender, EventArgs e) { using (WebhostEntities db = new WebhostEntities()) { StudentSelector.DataSource = StudentListItem.GetDataSource(db.Students.Where(s => s.isActive).Select(s => s.ID).ToList()); StudentSelector.DataTextField = "Text"; StudentSelector.DataValueField = "ID"; StudentSelector.DataBind(); RemoveList.DataSource = StudentListItem.GetDataSource(GroupIds); RemoveList.DataTextField = "Text"; RemoveList.DataValueField = "ID"; RemoveList.DataBind(); } }
protected void LoadTable() { using (WebhostEntities db = new WebhostEntities()) { SelectedTable.Rows.Clear(); if (GroupIds.Count == 0) { RemoveBtn.Visible = false; RemoveList.Visible = false; return; } foreach (int id in GroupIds) { Student Student = db.Students.Where(f => f.ID == id).Single(); TableRow row = new TableRow(); TableCell cell = new TableCell(); Label lbl = new Label() { Text = String.Format("{0} {1} ({2})", Student.FirstName, Student.LastName, Student.GraduationYear) }; cell.Controls.Add(lbl); row.Cells.Add(cell); SelectedTable.Rows.Add(row); } RemoveList.Visible = true; RemoveBtn.Visible = true; RemoveList.DataSource = StudentListItem.GetDataSource(GroupIds); RemoveList.DataTextField = "Text"; RemoveList.DataValueField = "ID"; RemoveList.DataBind(); } }
protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { int year = DateRange.GetCurrentAcademicYear(); using (WebhostEntities db = new WebhostEntities()) { StudentSelect.DataSource = StudentListItem.GetDataSource(db.Students.Where(s => s.isActive).OrderBy(s => s.GraduationYear).ThenBy(s => s.LastName).ThenBy(s => s.FirstName).Select(s => s.ID).ToList()); StudentSelect.DataTextField = "Text"; StudentSelect.DataValueField = "ID"; StudentSelect.DataBind(); CreditTypeDDL.DataSource = GradeTableEntryListItem.GetDataSource(db.GradeTables.Where(t => t.Name.Equals("Credit Types") && t.AcademicYearID == year).Single().GradeTableEntries.Select(d => d.id).ToList()); CreditTypeDDL.DataTextField = "Text"; CreditTypeDDL.DataValueField = "ID"; CreditTypeDDL.DataBind(); CreditValueDDL.DataSource = GradeTableEntryListItem.GetDataSource(db.GradeTables.Where(t => t.Name.Equals("Credit Values") && t.AcademicYearID == year).Single().GradeTableEntries.Select(d => d.id).ToList()); CreditValueDDL.DataTextField = "Text"; CreditValueDDL.DataValueField = "ID"; CreditValueDDL.DataBind(); } } }
protected void LoadTable() { int year = DateRange.GetCurrentAcademicYear(); using (WebhostEntities db = new WebhostEntities()) { Dictionary <string, int> dict = new Dictionary <string, int>(); List <Section> sections = db.Courses.Where(c => c.Name.Equals("Meds Attendance") && c.AcademicYearID == year).Single().Sections.ToList(); Dictionary <int, MedTimes> studentMeds = new Dictionary <int, MedTimes>(); foreach (Section sec in sections) { if (!dict.Keys.Contains(sec.Block.Name.Split(' ')[0])) { dict.Add(sec.Block.Name.Split(' ')[0], sec.id); } MedTimes mt = new MedTimes() { morning = false, lunch = false, dinner = false, bedtiem = false }; switch (sec.Block.Name.Split(' ')[0]) { case "Morning": mt.morning = true; break; case "Lunch": mt.lunch = true; break; case "Dinner": mt.dinner = true; break; case "Bedtime": mt.bedtiem = true; break; default: break; } foreach (Student student in sec.Students.ToList()) { if (studentMeds.ContainsKey(student.ID)) { studentMeds[student.ID] = merge(studentMeds[student.ID], mt); } else { studentMeds.Add(student.ID, mt); } } MedsTable.Rows.Clear(); MedsTable.Rows.Add(MedsAttendanceViewRow.Header); foreach (int id in studentMeds.Keys) { StudentListItem item = new StudentListItem(id); MedsAttendanceViewRow row = new MedsAttendanceViewRow(item.Text, studentMeds[id].morning, studentMeds[id].lunch, studentMeds[id].dinner, studentMeds[id].bedtiem); MedsTable.Rows.Add(row); } } Session["med_sections"] = dict; StudentSelectComboBox.DataSource = StudentListItem.GetDataSource(db.Students.Where(s => s.isActive).OrderBy(s => s.LastName).ThenBy(s => s.FirstName).Select(s => s.ID).ToList()); StudentSelectComboBox.DataTextField = "Text"; StudentSelectComboBox.DataValueField = "ID"; StudentSelectComboBox.DataBind(); } }