示例#1
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (!Page.IsPostBack)
     {
         if (TermId == -1)
         {
             TermId = DateRange.GetCurrentOrLastTerm();
         }
         using (WebhostEntities db = new WebhostEntities())
         {
             int  year   = DateRange.GetCurrentAcademicYear();
             int  termid = Import.GetCurrentOrLastTerm();
             Term term   = db.Terms.Where(t => t.id == termid).Single();
             TermSelectDDL.ClearSelection();
             TermSelectDDL.SelectedValue = term.Name;
         }
     }
 }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                using (WebhostEntities db = new WebhostEntities())
                {
                    Faculty    currentUser = db.Faculties.Where(f => f.ID == this.user.ID).Single();
                    List <int> advisees    = currentUser.Students.Where(s => s.isActive).Select(s => s.ID).ToList();

                    int year        = DateRange.GetCurrentAcademicYear();
                    int currentTerm = DateRange.GetCurrentOrLastTerm();

                    AcademicYear ay = db.AcademicYears.Where(y => y.id == year).Single();

                    AdviseeSelectDDL.DataSource     = StudentListItem.GetDataSource(advisees);
                    AdviseeSelectDDL.DataTextField  = "Text";
                    AdviseeSelectDDL.DataValueField = "ID";
                    AdviseeSelectDDL.DataBind();

                    if (advisees.Contains(SelectedAdvisee))
                    {
                        AdviseeSelectDDL.ClearSelection();
                        AdviseeSelectDDL.SelectedValue = Convert.ToString(SelectedAdvisee);
                    }
                    else
                    {
                        SelectedAdvisee = Convert.ToInt32(AdviseeSelectDDL.SelectedValue);
                    }

                    TermSelectDDL.DataSource     = TermListItem.GetDataSource(ay.Terms.Select(t => t.id).ToList());
                    TermSelectDDL.DataTextField  = "Text";
                    TermSelectDDL.DataValueField = "ID";
                    TermSelectDDL.DataBind();

                    TermSelectDDL.ClearSelection();
                    TermSelectDDL.SelectedValue = Convert.ToString(SelectedTerm);

                    Student            selectedAdvisee = currentUser.Students.Where(s => s.ID == SelectedAdvisee).Single();
                    List <MiniComment> comments        = new List <MiniComment>();

                    foreach (StudentComment comment in selectedAdvisee.StudentComments.Where(c => c.CommentHeader.TermIndex == SelectedTerm).ToList())
                    {
                        comments.Add(new MiniComment()
                        {
                            id        = comment.id,
                            className = comment.CommentHeader.Section.Course.Name
                        });
                    }

                    if (comments.Count == 0)
                    {
                        ClassSelectDDL.Enabled = false;
                    }
                    else
                    {
                        ClassSelectDDL.Enabled        = true;
                        ClassSelectDDL.DataSource     = comments;
                        ClassSelectDDL.DataTextField  = "className";
                        ClassSelectDDL.DataValueField = "id";
                        ClassSelectDDL.DataBind();

                        if (SelectedComment != -1)
                        {
                            ClassSelectDDL.ClearSelection();
                            ClassSelectDDL.SelectedValue = Convert.ToString(SelectedComment);
                        }
                        else
                        {
                            SelectedComment = Convert.ToInt32(ClassSelectDDL.SelectedValue);
                        }

                        AdviseeCommentViewer.LoadComment(SelectedComment);
                    }
                }
            }
        }