protected void MorningOnlyCB_CheckedChanged(object sender, EventArgs e)
        {
            if (MorningOnlyCB.Checked)
            {
                DateTime date = TodayCB.Checked ? DateTime.Today : DateRange.GetDateTimeFromString(DateInput.Text);
                AfternoonOnlyCB.Checked = false;
                BlocksCBL.ClearSelection();
                Dictionary <DateRange, int> BlockTimes = DateRange.BlockIdsByTime(date);

                List <String> vals = new List <string>();

                foreach (DateRange dr in BlockTimes.Keys)
                {
                    if (dr.Intersects(DateRange.FirstBlock(date)) || dr.Intersects(DateRange.SecondBlock(date)) || dr.Intersects(DateRange.ThirdBlock(date)))
                    {
                        vals.Add(BlockTimes[dr].ToString());
                    }
                }

                /* vals.Add(Convert.ToString(BlockTimes[DateRange.FirstBlock(date)]));
                 * vals.Add(Convert.ToString(BlockTimes[DateRange.SecondBlock(date)]));
                 * vals.Add(Convert.ToString(BlockTimes[DateRange.ThirdBlock(date)]));
                 */
                foreach (ListItem item in BlocksCBL.Items)
                {
                    if (vals.Contains(item.Value))
                    {
                        item.Selected = true;
                    }
                }
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                using (WebhostEntities db = new WebhostEntities())
                {
                    StudentNameCBX.DataSource = (from student in db.Students
                                                 where student.isActive
                                                 orderby student.LastName, student.FirstName
                                                 select new
                    {
                        Text = student.FirstName + " " + student.LastName + " (" + student.GraduationYear + ")",
                        id = student.ID
                    }).ToList();
                    StudentNameCBX.DataTextField  = "Text";
                    StudentNameCBX.DataValueField = "id";
                    StudentNameCBX.DataBind();

                    // Preload Current Block.
                    AllDayCB.Checked        = false;
                    MorningOnlyCB.Checked   = false;
                    AfternoonOnlyCB.Checked = false;
                    EveningCB.Checked       = false;

                    Dictionary <DateRange, int> BlockTimes = DateRange.BlockIdsByTime(DateTime.Today);

                    List <int> blockIds = BlockTimes.Values.ToList();

                    BlocksCBL.DataSource = (from block in db.Blocks
                                            where blockIds.Contains(block.id)
                                            select block).ToList();
                    BlocksCBL.DataTextField  = "Name";
                    BlocksCBL.DataValueField = "id";
                    BlocksCBL.DataBind();

                    foreach (DateRange dr in BlockTimes.Keys)
                    {
                        if (dr.Contains(DateTime.Now))
                        {
                            BlocksCBL.ClearSelection();
                            BlocksCBL.SelectedValue = Convert.ToString(BlockTimes[dr]);
                            break;
                        }
                    }
                }
            }
        }
        protected void SelectDateBtn_Click(object sender, EventArgs e)
        {
            DateTime date = DateRange.GetDateTimeFromString(DateInput.Text);
            Dictionary <DateRange, int> BlockTimes = DateRange.BlockIdsByTime(date);

            using (WebhostEntities db = new WebhostEntities())
            {
                List <int> blockIds = BlockTimes.Values.ToList();

                BlocksCBL.DataSource = (from block in db.Blocks
                                        where blockIds.Contains(block.id)
                                        select block).ToList();
                BlocksCBL.DataTextField  = "Name";
                BlocksCBL.DataValueField = "id";
                BlocksCBL.DataBind();
            }
        }
        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);
            }
        }
예제 #5
0
        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);
            int uid = ((BasePage)Page).user.ID;

            using (WebhostEntities db = new WebhostEntities())
            {
                Faculty faculty = db.Faculties.Where(f => f.ID == uid).Single();
                int     year    = DateRange.GetCurrentAcademicYear();

                List <Section> currentSections = db.Sections.Where(sec => sec.Course.Name.Equals("Meds Attendance") && sec.Course.AcademicYearID == year).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;
                                }
                            }
                        }
                    }
                }


                BlockSelectDDL.DataSource = (from section in currentSections
                                             select new
                {
                    Text = section.Block.LongName,
                    ID = section.id
                });
                BlockSelectDDL.DataTextField  = "Text";
                BlockSelectDDL.DataValueField = "ID";
                BlockSelectDDL.DataBind();

                TodayCB.Visible       = false;
                DateInput.Visible     = false;
                DateSelectBtn.Visible = false;
                SubmitBtn.Visible     = false;
            }

            if (this.SectionId != -1)
            {
                LoadInfo(SectionId, AttendanceDate);
            }
        }