コード例 #1
0
        protected void StudentSelectCmbBx_SelectedIndexChanged(object sender, EventArgs e)
        {
            CommentGrades.ResetBar();
            State.log.WriteLine("{0} {1}:  Loading new student selection.", DateTime.Today.ToShortDateString(), DateTime.Now.ToLongTimeString());
            if (Saving)
            {
                State.log.WriteLine("{1} {0}:  Aborted Changing Comment while Saving.", DateTime.Now.ToLongTimeString(), DateTime.Today.ToShortDateString());
                WebhostEventLog.CommentLog.LogWarning("Aborted changing comment while saving.");
                return;
            }
            if (LoadedHeaderId == -1)
            {
                State.log.WriteLine("{0} {1}:  No Header is Loaded... There's a problem...", DateTime.Today.ToShortDateString(), DateTime.Now.ToLongTimeString());
                StudentSelectCmbBx.DataSource = new List <string>();
                StudentSelectCmbBx.DataBind();
                WebhostEventLog.CommentLog.LogError("Cannot Select a student while no Header is loaded...");
                return;
            }

            try
            {
                SelectedStudentId = Convert.ToInt32(StudentSelectCmbBx.SelectedValue);
            }
            catch (Exception ex)
            {
                State.log.WriteLine("{1} {0}:  Failed:  {2}", DateTime.Now.ToLongTimeString(), DateTime.Today.ToShortDateString(), ex.Message);
                WebhostEventLog.CommentLog.LogError("Failed to select Student: {0}", ex.Message);
                return;
            }

            using (WebhostEntities db = new WebhostEntities())
            {
                CommentHeader header = db.CommentHeaders.Where(hdr => hdr.id == LoadedHeaderId).Single();
                // check for existing comments.
                if (header.StudentComments.Where(com => com.StudentID == SelectedStudentId).Count() > 0)
                {
                    // check for multiples.
                    if (header.StudentComments.Where(com => com.StudentID == SelectedStudentId).Count() > 1)
                    {
                        State.log.WriteLine("{1} {0}:  Something went wrong!  Too many comments for Student.id={2} and CommentHeader.id={3}", DateTime.Now.ToLongTimeString(), DateTime.Today.ToShortDateString(), SelectedStudentId, LoadedHeaderId);
                        MailControler.MailToWebmaster("Class has Too Many comment paragraphs....", String.Format("{0} objects match comment paragraph for Student.id={4} in [{1}] {2} {3} comments.",
                                                                                                                 header.StudentComments.Where(com => com.StudentID == SelectedStudentId).Count(), header.Section.Block.LongName, header.Section.Course.Name, header.Term.Name), ((BasePage)Page).user);

                        WebhostEventLog.CommentLog.LogError("Something went wrong!  Too many comments for Student.id={0} and CommentHeader.id={1}", SelectedStudentId, LoadedHeaderId);

                        /*********************************************************************
                        * TODO:
                        * Handle This some how!
                        *
                        * Make a pop-up to choose which to keep.
                        *
                        *********************************************************************/

                        State.log.WriteLine("{1} {0}:  Aborting the defunct Header Loader.", DateTime.Now.ToLongTimeString(), DateTime.Today.ToShortDateString());
                        return;
                    }

                    // Load the unique comment.

                    StudentComment comment = header.StudentComments.Where(com => com.StudentID == SelectedStudentId).Single();
                    LoadedCommentId = comment.id;

                    State.log.WriteLine("{0} {1}:  Loading unique comment id={2}", DateTime.Today.ToShortDateString(), DateTime.Now.ToLongTimeString(), LoadedCommentId);
                    WebhostEventLog.CommentLog.LogInformation("Loaded Comment id {0}", LoadedCommentId);
                    StudentCommentHTML             = comment.HTML;
                    CommentGrades.EffortGradeID    = comment.EffortGradeID;
                    CommentGrades.FinalGradeID     = comment.FinalGradeID;
                    CommentGrades.ExamGradeID      = comment.ExamGradeID;
                    CommentGrades.TrimesterGradeID = comment.TermGradeID;
                    StudentEditor.Content          = comment.HTML;

                    StudentNameLabel.Text = String.Format("Comment for {0} {1}", comment.Student.FirstName, comment.Student.LastName);
                }
                else
                {
                    // Create new blank comment.
                    State.log.WriteLine("{0} {1}:  Creating a new Student Comment paragraph.", DateTime.Today.ToShortDateString(), DateTime.Now.ToLongTimeString());
                    WebhostEventLog.CommentLog.LogInformation("Creating new student comment.");
                    StudentComment comment = new StudentComment()
                    {
                        id            = db.StudentComments.Count() > 0 ? db.StudentComments.OrderBy(com => com.id).ToList().Last().id + 1 : 0,
                        StudentID     = SelectedStudentId,
                        Student       = db.Students.Where(s => s.ID == SelectedStudentId).Single(),
                        HeaderIndex   = header.id,
                        HTML          = "",
                        TermGradeID   = CommentGrades.AFDefault,
                        EffortGradeID = CommentGrades.EffortDefault,
                        FinalGradeID  = CommentGrades.AFDefault,
                        ExamGradeID   = CommentGrades.AFDefault
                    };


                    db.StudentComments.Add(comment);
                    db.SaveChanges();
                    LoadedCommentId       = comment.id;
                    comment               = db.StudentComments.Where(c => c.id == LoadedCommentId).Single();
                    StudentEditor.Content = "";
                    StudentNameLabel.Text = String.Format("Comment for {0} {1}", comment.Student.FirstName, comment.Student.LastName);
                    State.log.WriteLine("{0} {1}:  New blank comment is saved to the database.", DateTime.Today.ToShortDateString(), DateTime.Now.ToLongTimeString());
                }

                EditorLabel.Text     = "Editing Student Individual Comment.";
                HeaderBtn.Visible    = true;
                HeaderPanel.Visible  = false;
                StudentPanel.Visible = true;
                PreviewBtn.Visible   = true;
            }
        }
コード例 #2
0
        protected void ClassSelectCmbBx_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (Saving)
            {
                State.log.WriteLine("{1} {0}:  Aborted Changing Comment while Saving.", DateTime.Now.ToLongTimeString(), DateTime.Today.ToShortDateString());
                WebhostEventLog.CommentLog.LogWarning("Aborted changing comment while saving.");
                return;
            }
            State.log.WriteLine("{1} {0}:  Loading Selected Course.", DateTime.Now.ToLongTimeString(), DateTime.Today.ToShortDateString());
            try
            {
                SelectedSectionId = Convert.ToInt32(ClassSelectCmbBx.SelectedValue);
            }
            catch (Exception ex)
            {
                State.log.WriteLine("{1} {0}:  Failed:  {2}", DateTime.Now.ToLongTimeString(), DateTime.Today.ToShortDateString(), ex.Message);
                WebhostEventLog.CommentLog.LogError("Failed to select section:  {0}", ex.Message);
                return;
            }

            StudentSelectCmbBx.Visible = true;
            int term = SelectedTermId == -1 ? Import.GetCurrentOrLastTerm() : SelectedTermId;

            using (WebhostEntities db = new WebhostEntities())
            {
                Section section = db.Sections.Find(SelectedSectionId);
                if (section == null)
                {
                    WebhostEventLog.CommentLog.LogError("Unable to locate section id {0}.", SelectedSectionId);
                    throw new InvalidOperationException("Invalid Section Id");
                }
                State.log.WriteLine("{1} {0}:  Loading Section [{2}] {3}", DateTime.Now.ToLongTimeString(), DateTime.Today.ToShortDateString(), section.Block.LongName, section.Course.Name);
                WebhostEventLog.CommentLog.LogInformation("Loading Section [{0}] {1}", section.Block.LongName, section.Course.Name);
                // Load Header Paragraph.
                if (section.CommentHeaders.Where(hdr => hdr.TermIndex == term).Count() > 0)
                {
                    if (section.CommentHeaders.Where(hdr => hdr.TermIndex == term).Count() > 1)  // PROBLEM!
                    {
                        MailControler.MailToWebmaster("Class has Too Many header paragraphs....", String.Format("{0} objects match header paragraph for [{1}] {2} {3} comments.",
                                                                                                                section.CommentHeaders.Where(hdr => hdr.TermIndex == term).Count(), section.Block.LongName, section.Course.Name, section.Terms.Where(t => t.id == term).Single().Name), ((BasePage)Page).user);

                        State.log.WriteLine("{1} {0}:  Too many Class header paragraphs are stored in the database!!!", DateTime.Now.ToLongTimeString(), DateTime.Today.ToShortDateString());

                        /*********************************************************************
                        * TODO:
                        * Handle This some how!
                        *
                        * Make a pop-up to choose which to keep.
                        *
                        *********************************************************************/

                        State.log.WriteLine("{1} {0}:  Aborting the defunct Header Loader.", DateTime.Now.ToLongTimeString(), DateTime.Today.ToShortDateString());
                        WebhostEventLog.CommentLog.LogError("Too many Class Header paragraphs stored for section {0} in term id {1}", SelectedSectionId, term);
                        return;
                    }


                    State.log.WriteLine("{1} {0}:  Getting Comment Header HTML.", DateTime.Now.ToLongTimeString(), DateTime.Today.ToShortDateString());
                    CommentHeader header = section.CommentHeaders.Where(hdr => hdr.TermIndex == term).Single();

                    LoadedHeaderId = header.id;

                    HeaderHTML           = header.HTML;
                    HeaderEditor.Content = header.HTML;

                    State.log.WriteLine("{1} {0}:  Done.", DateTime.Now.ToLongTimeString(), DateTime.Today.ToShortDateString());
                    WebhostEventLog.CommentLog.LogInformation("Successfully Loaded header id {0}", LoadedHeaderId);
                }
                else
                {
                    State.log.WriteLine("{0} {1}:  No Header exisits--creating new header.", DateTime.Today.ToShortDateString(), DateTime.Now.ToLongTimeString());
                    WebhostEventLog.CommentLog.LogInformation("Creating a new header paragraph object.");
                    // Create Paragraph!
                    CommentHeader header = new CommentHeader()
                    {
                        id           = db.CommentHeaders.Count() > 0 ? db.CommentHeaders.OrderBy(h => h.id).ToList().Last().id + 1 : 0,
                        HTML         = "",
                        SectionIndex = SelectedSectionId,
                        TermIndex    = term
                    };
                    db.CommentHeaders.Add(header);
                    db.SaveChanges();

                    LoadedHeaderId       = header.id;
                    HeaderEditor.Content = "";

                    State.log.WriteLine("{0} {1}:  Saved new blank header to database.", DateTime.Today.ToShortDateString(), DateTime.Now.ToLongTimeString());
                }

                State.log.WriteLine("{1} {0}:  Loading Student Roster.", DateTime.Now.ToLongTimeString(), DateTime.Today.ToShortDateString());

                StudentPanel.Visible          = false;
                StudentSelectCmbBx.DataSource = (from student in section.Students
                                                 orderby student.LastName, student.FirstName
                                                 select new
                {
                    Name = student.FirstName + " " + student.LastName,
                    ID = student.ID
                }).ToList();
                StudentSelectCmbBx.DataTextField  = "Name";
                StudentSelectCmbBx.DataValueField = "ID";
                StudentSelectCmbBx.DataBind();

                EditorLabel.Text = "Editing Comment Header.  Select a Student to load the Individual Comment.";

                PreviewBtn.Visible       = false;
                DownloadClassBtn.Visible = true;
                ClassReviewBtn.Visible   = true;
                HeaderPanel.Visible      = true;
                HeaderBtn.Visible        = false;
                State.log.WriteLine("{0} {1}:  Completed Loading Class Header.", DateTime.Today.ToShortDateString(), DateTime.Now.ToLongTimeString());
            }
        }