Пример #1
0
        public void PopulateTable()
        {
            List <int> sections = new List <int>();
            int        year     = DateRange.GetCurrentAcademicYear();

            using (WebhostEntities db = new WebhostEntities())
            {
                try
                {
                    if (IsStudent)
                    {
                        Student student = db.Students.Where(s => s.ID == UserId).Single();
                        NameLabel.Text = String.Format("{0} {1} ({2})", student.FirstName, student.LastName, student.GraduationYear);
                        sections       = student.Sections.Where(sec => sec.Course.AcademicYearID == year).OrderBy(sec => sec.BlockIndex).Select(sec => sec.id).ToList();
                    }
                    else
                    {
                        Faculty faculty = db.Faculties.Where(f => f.ID == UserId).Single();
                        NameLabel.Text = String.Format("{0} {1}", faculty.FirstName, faculty.LastName);
                        sections       = faculty.Sections.Where(sec => sec.Course.AcademicYearID == year).OrderBy(sec => sec.BlockIndex).Select(sec => sec.id).ToList();
                    }
                }
                catch (Exception e)
                {
                    State.log.WriteLine("Failed to load ScheduleTable.{0}{1}", Environment.NewLine, e.Message);
                    AddClassBtn.Enabled  = false;
                    DropClassBtn.Enabled = false;
                    return;
                }
            }

            AddClassBtn.Enabled  = true;
            DropClassBtn.Enabled = true;

            ScheduleTable.Rows.Clear();
            ScheduleTable.Rows.Add(new ScheduleTableRow());
            using (WebhostEntities db = new WebhostEntities())
                foreach (int id in sections)
                {
                    Section section = db.Sections.Where(sec => sec.id == id).Single();
                    if (!section.Block.ShowInSchedule)
                    {
                        continue;
                    }
                    ScheduleTable.Rows.Add(new ScheduleTableRow(id));
                }

            DropClassDDL.DataSource     = SectionListItem.GetDataSource(sections);
            DropClassDDL.DataTextField  = "Text";
            DropClassDDL.DataValueField = "ID";
            DropClassDDL.DataBind();
        }
Пример #2
0
        public static List <SectionListItem> GetDataSource(List <int> ids)
        {
            List <SectionListItem> items = new List <SectionListItem>();

            foreach (int id in ids)
            {
                SectionListItem item = new SectionListItem(id);
                if (item.ID != -1)
                {
                    items.Add(item);
                }
            }
            return(items);
        }
Пример #3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                List <int> allSections = new List <int>();
                int        year        = DateRange.GetCurrentAcademicYear();
                using (WebhostEntities db = new WebhostEntities())
                {
                    allSections = db.Sections.Where(sec => sec.Course.AcademicYearID == year).OrderBy(sec => sec.Course.Name).Select(sec => sec.id).ToList();
                }

                AddClassDDL.DataSource     = SectionListItem.GetDataSource(allSections);
                AddClassDDL.DataTextField  = "Text";
                AddClassDDL.DataValueField = "ID";
                AddClassDDL.DataBind();
            }
        }
Пример #4
0
        public void ResetPage()
        {
            State.log.WriteLine("{1} {0}:  Beginning Comment Letter Page From Scratch.", DateTime.Now.ToLongTimeString(), DateTime.Today.ToShortDateString());
            WebhostEventLog.CommentLog.LogInformation("Beginning Comment Letter Page From Scratch.");
            using (WebhostEntities db = new WebhostEntities())
            {
                State.log.WriteLine("{1} {0}:  Database Connection Established.", DateTime.Now.ToLongTimeString(), DateTime.Today.ToShortDateString());
                Faculty faculty = db.Faculties.Find(FacultyId);
                if (faculty == null)
                {
                    WebhostEventLog.CommentLog.LogError("Faculty ID {0} is invalid.", FacultyId);
                    throw new InvalidOperationException("Faculty Id is Invalid");
                }
                State.log.WriteLine("{1} {0}:  Editing Comments as {2} {3}", DateTime.Now.ToLongTimeString(), DateTime.Today.ToShortDateString(), faculty.FirstName, faculty.LastName);

                EditorLabel.Text = String.Format("Comments for {0} {1}", faculty.FirstName, faculty.LastName);

                int year = DateRange.GetCurrentAcademicYear();
                int term = SelectedTermId == -1? Import.GetCurrentOrLastTerm(): SelectedTermId;

                if (SelectedTermId != -1)
                {
                    Term t = db.Terms.Find(SelectedTermId);
                    year = t.AcademicYearID;
                }

                if (SelectedTermId != -1)
                {
                    EditorLabel.Text = "Select a class to Edit it's header, or load Students.";
                }
                else
                {
                    EditorLabel.Text = "To change terms, select from the dropdown.  Or continue to edit classes for the current term.";
                    TermDDL.ClearSelection();
                    TermDDL.SelectedValue = Convert.ToString(term);
                }
                TermDDL.DataSource = (from t in db.Terms
                                      where t.AcademicYearID == year
                                      select t).ToList();
                TermDDL.DataTextField  = "Name";
                TermDDL.DataValueField = "id";
                TermDDL.DataBind();

                List <int> currentSections = new List <int>();

                if (DepartmentHeadMode == -1)
                {
                    currentSections = faculty.Sections.Where(sec => sec.Course.AcademicYearID == year && sec.Terms.Where(t => t.id == term).Count() > 0).Select(sec => sec.id).ToList();
                    State.log.WriteLine("{1} {0}:  Found {2} current sections.", DateTime.Now.ToLongTimeString(), DateTime.Today.ToShortDateString(), currentSections.Count);
                    LogInformation("Got {0} sections for this period.", currentSections.Count);
                }
                else
                {
                    State.log.WriteLine("DepartmentHead mode enabled.");
                    currentSections = db.Sections.Where(sec => sec.Course.DepartmentID == DepartmentHeadMode && sec.Course.AcademicYearID == year && sec.Terms.Where(t => t.id == term).Count() > 0).Select(sec => sec.id).ToList();
                    State.log.WriteLine("{1} {0}:  Found {2} current sections.", DateTime.Now.ToLongTimeString(), DateTime.Today.ToShortDateString(), currentSections.Count);
                    LogInformation("Department Head Mode:  found {0} sections this period.", currentSections.Count);
                }

                ClassSelectCmbBx.DataSource     = SectionListItem.GetDataSource(currentSections);
                ClassSelectCmbBx.DataTextField  = DepartmentHeadMode == -1 ? "Text" : "ExtendedText";
                ClassSelectCmbBx.DataValueField = "ID";
                ClassSelectCmbBx.DataBind();

                StudentSelectCmbBx.Visible = false;
                HeaderPanel.Visible        = false;
                StudentPanel.Visible       = false;

                HeaderHTML         = "";
                StudentCommentHTML = "";

                SelectedSectionId = -1;
                SelectedStudentId = -1;
                LoadedHeaderId    = -1;
                LoadedCommentId   = -1;
            }
            HeaderBtn.Visible        = false;
            PreviewBtn.Visible       = false;
            DownloadClassBtn.Visible = false;
            ClassReviewBtn.Visible   = false;

            State.log.WriteLine("{1} {0}:  End of Page Reset Method.", DateTime.Now.ToLongTimeString(), DateTime.Today.ToShortDateString());
            WebhostEventLog.CommentLog.LogInformation("Page Reset Successful.");
        }