コード例 #1
0
        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            int ID      = Convert.ToInt32(GridAttendance.Rows[e.RowIndex].Cells[0].Value);
            var element = GridAttendance.Columns["Delete"].Index;
            var update  = GridAttendance.Columns["Update"].Index;

            if (e.ColumnIndex == element)
            {
                string     cmd     = String.Format("DELETE FROM StudentAttendance WHERE AttendanceId = @id");
                SqlCommand command = new SqlCommand(cmd, conn);

                command.Parameters.Add(new SqlParameter("@id", ID));
                conn.Open();
                SqlDataReader reader = command.ExecuteReader();
                conn.Close();

                conn.Open();
                cmd     = String.Format("DELETE FROM ClassAttendance WHERE Id = @id1");
                command = new SqlCommand(cmd, conn);
                command.Parameters.Add(new SqlParameter("@id1", ID));
                reader = command.ExecuteReader();
                conn.Close();
                cmd     = "SELECT * FROM ClassAttendance";
                command = new SqlCommand(cmd, conn);

                conn.Open();
                reader = command.ExecuteReader();
                SqlDataAdapter adapter = new SqlDataAdapter(cmd, conn);
                DataTable      table   = new DataTable();
                adapter.Fill(table);
                GridAttendance.DataSource = table;
                conn.Close();
            }
            else if (e.ColumnIndex == GridAttendance.Columns["Update"].Index)
            {
                lblHide.Hide();
                var item = GridAttendance.Rows[e.RowIndex].Cells[0].Value;

                string     cmd     = String.Format("SELECT * FROM ClassAttendance WHERE Id = @item");
                SqlCommand command = new SqlCommand(cmd, conn);
                command.Parameters.Add(new SqlParameter("@item", item));
                conn.Open();
                SqlDataReader reader = command.ExecuteReader();
                Student       s      = new Student();

                btnAddAttendance.Text = "Update Attendance";
                while (reader.Read())
                {
                    lblHide.Text = Convert.ToString(reader[0]);
                    string   d    = Convert.ToString(reader[1]);
                    DateTime date = Convert.ToDateTime(d);
                    AttendanceMarking.SetDate(date);
                }
                TabPageAddClassAttendance.Show();
                conn.Close();
            }
        }
コード例 #2
0
        public static String SyncAttendanceForSection(int webhost_section_id, DateRange period = null)
        {
            String report = "";

            using (WebhostEntities db = new WebhostEntities())
            {
                Section section = db.Sections.Where(sec => sec.id == webhost_section_id).Single();
                int     schoology_section_id = section.SchoologyId;
                int     attmarkid            = db.AttendanceMarkings.Count() > 0 ? db.AttendanceMarkings.OrderBy(att => att.id).ToList().Last().id : 0;
                List <SchoologyAttendance> schoologyAttendances = SchoologyAttendance.Download(schoology_section_id, period);
                report += String.Format("Found {0} Attendance Markings{1}", schoologyAttendances.Count, Environment.NewLine);
                foreach (SchoologyAttendance sch_att in schoologyAttendances)
                {
                    AttendanceMarking marking;
                    if (section.AttendanceMarkings.Where(mk =>
                                                         mk.AttendanceDate.Date.Equals(sch_att.date) && mk.StudentID == sch_att.enrollment.user_id).Count() <= 0)
                    {
                        marking = new AttendanceMarking()
                        {
                            id             = ++attmarkid,
                            AttendanceDate = sch_att.date,
                            StudentID      = sch_att.enrollment.user_id,
                            SectionIndex   = webhost_section_id,
                            MarkingIndex   = AttendanceControl.LookupAttendanceIdByName(sch_att.AttendanceMarking),
                            Notes          = sch_att.Notes,
                            SubmissionTime = DateTime.Now,
                            SubmittedBy    = 9997
                        };

                        db.AttendanceMarkings.Add(marking);
                        Student         student = db.Students.Where(s => s.ID == sch_att.enrollment.user_id).Single();
                        GradeTableEntry entry   = db.GradeTableEntries.Where(e => e.id == marking.MarkingIndex).Single();
                        report += String.Format("Created new attendance [{3}] for {0} {1} on {2}{4}", student.FirstName, student.LastName, marking.AttendanceDate.ToShortDateString(), entry.Name, Environment.NewLine);
                    }
                    else
                    {
                        marking = section.AttendanceMarkings.Where(mk =>
                                                                   mk.AttendanceDate.Date.Equals(sch_att.date) && mk.StudentID == sch_att.enrollment.user_id).Single();
                        if (marking.MarkingIndex == AttendanceControl.LookupAttendanceIdByName("Excused"))
                        {
                            report += String.Format("Skipping previously excused absence for {0} {1} on {3}{2}", marking.Student.FirstName, marking.Student.LastName, Environment.NewLine, marking.AttendanceDate.ToShortDateString());
                            continue; // Do not overwrite an excused absence.
                        }
                        marking.MarkingIndex   = AttendanceControl.LookupAttendanceIdByName(sch_att.AttendanceMarking);
                        marking.Notes          = sch_att.Notes;
                        marking.SubmissionTime = DateTime.Now;

                        report += String.Format("Updated attendance [{4}] for {0} {1} on {3}{2}", marking.Student.FirstName, marking.Student.LastName, Environment.NewLine, marking.AttendanceDate.ToShortDateString(), marking.Marking.Name);
                    }
                }

                db.SaveChanges();
            }

            return(report);
        }
コード例 #3
0
 /// <summary>
 /// Generate this given the <see cref="AttendanceMarking.id"/>.
 /// </summary>
 /// <param name="id"><see cref="AttendanceMarking.id"/></param>
 /// <param name="fullDetails">Fills in all of the non-mandatory fields if true.  Otherwise, only provides the mandatory data.</param>
 public AttendanceInfo(int id, bool fullDetails = false)
 {
     using (WebhostEntities db = new WebhostAPI.WebhostEntities())
     {
         AttendanceMarking marking = db.AttendanceMarkings.Find(id);
         Id        = id;
         StudentId = marking.StudentID;
         SectionId = marking.SectionIndex;
         Marking   = marking.GradeTableEntry.Name;
         Date      = marking.AttendanceDate;
         Notes     = marking.Notes;
         EnteredBy = new TeacherInfo(marking.SubmittedBy);
         if (fullDetails)
         {
             Student = new StudentInfo(StudentId);
             Section = new SectionInfo(SectionId);
         }
     }
 }
コード例 #4
0
        protected void LoadInfo(int sectionId, DateTime date)
        {
            using (WebhostEntities db = new WebhostEntities())
            {
                int        year        = DateRange.GetCurrentAcademicYear();
                GradeTable attMarkings = db.GradeTables.Where(t => t.AcademicYearID == year && t.Name.Equals("Attendance")).Single();
                AttendanceTable.Rows.Clear();
                Section section = db.Sections.Where(sec => sec.id == sectionId).Single();
                ClassNameLabel.Text = String.Format("[{0}] {1}", section.Block.LongName, section.Course.Name);

                AttendancePageInfo api = new AttendancePageInfo()
                {
                    SectionId   = sectionId,
                    Date        = date,
                    Name        = ClassNameLabel.Text,
                    Attendances = new List <AttendanceData>()
                };

                List <Student> StudentRoster = section.Course.Name.Equals("Morning Meeting") ?
                                               section.Students.OrderBy(s => s.GraduationYear).ThenBy(s => s.LastName).ThenBy(s => s.FirstName).ToList() :
                                               section.Students.OrderBy(s => s.LastName).ThenBy(s => s.FirstName).ToList();

                bool allSubmitted = true;

                foreach (Student student in StudentRoster)
                {
                    AttendanceMarking mark = null;
                    AttendanceData    atd  = new AttendanceData()
                    {
                        StudentId = student.ID, Name = String.Format("{0} {1}", student.FirstName, student.LastName)
                    };

                    if (section.AttendanceMarkings.Where(m => m.StudentID == student.ID && m.AttendanceDate.Equals(date)).Count() > 0)
                    {
                        mark = section.AttendanceMarkings.Where(m => m.StudentID == student.ID && m.AttendanceDate.Equals(date)).Single();
                    }
                    else
                    {
                        allSubmitted = false;
                    }

                    TableRow  row       = new TableRow();
                    TableCell nameCell  = new TableCell();
                    Label     nameLabel = new Label()
                    {
                        Text    = student.FirstName + " " + student.LastName,
                        ToolTip = "Advisor:  " + student.Advisor.FirstName + " " + student.Advisor.LastName,
                        Width   = Unit.Percentage(50)
                    };
                    HiddenField sidf = new HiddenField()
                    {
                        Value = Convert.ToString(student.ID)
                    };

                    nameCell.Controls.Add(sidf);
                    nameCell.Controls.Add(nameLabel);

                    TableCell    markingCell = new TableCell();
                    DropDownList markddl     = new DropDownList();
                    int          presentId   = attMarkings.GradeTableEntries.Where(m => m.Name.Equals("Present")).Single().id;
                    markddl.DataSource     = attMarkings.GradeTableEntries.ToList();
                    markddl.DataTextField  = "Name";
                    markddl.DataValueField = "id";
                    markddl.DataBind();

                    if (mark != null)
                    {
                        markddl.ClearSelection();
                        markddl.SelectedValue = Convert.ToString(mark.MarkingIndex);
                        atd.Marking           = mark.Marking.Name;
                    }
                    else
                    {
                        markddl.ClearSelection();
                        markddl.SelectedValue = Convert.ToString(presentId);
                        atd.Marking           = "Present";
                    }

                    markingCell.Controls.Add(markddl);

                    TableCell noteCell = new TableCell()
                    {
                        Width = Unit.Percentage(25)
                    };
                    TextBox noteinput = new TextBox()
                    {
                        TextMode = TextBoxMode.MultiLine
                    };

                    if (mark != null)
                    {
                        noteinput.Text = mark.Notes;
                    }
                    row.BorderWidth = Unit.Pixel(2);
                    row.BorderStyle = BorderStyle.Solid;
                    noteCell.Controls.Add(noteinput);
                    row.Cells.Add(nameCell);
                    row.Cells.Add(markingCell);
                    row.Cells.Add(noteCell);
                    AttendanceTable.Rows.Add(row);
                }

                if (allSubmitted)
                {
                    SubmittedLabel.Text     = "Successfully Submitted.";
                    SubmittedLabel.CssClass = "success_highlight";
                }
                else
                {
                    SubmittedLabel.Text     = "You have not yet entered attendance data.";
                    SubmittedLabel.CssClass = "incomplete_highlight";
                }

                LogCurrentData(api);
            }
        }
コード例 #5
0
        protected void LoadInfo(int sectionId, DateTime date)
        {
            using (WebhostEntities db = new WebhostEntities())
            {
                int        year        = DateRange.GetCurrentAcademicYear();
                GradeTable attMarkings = db.GradeTables.Where(t => t.AcademicYearID == year && t.Name.Equals("Attendance")).Single();
                AttendanceTable.Rows.Clear();
                Section section = db.Sections.Where(sec => sec.id == sectionId).Single();
                ClassNameLabel.Text = String.Format("[{0}] {1}", section.Block.LongName, section.Course.Name);



                AttendancePageInfo api = new AttendancePageInfo()
                {
                    SectionId   = sectionId,
                    Date        = date,
                    Name        = ClassNameLabel.Text,
                    Attendances = new List <AttendanceData>()
                };

                List <Student> StudentRoster = section.Course.Name.Equals("Morning Meeting") ?
                                               section.Students.OrderBy(s => s.GraduationYear).ThenBy(s => s.LastName).ThenBy(s => s.FirstName).ToList() :
                                               section.Students.OrderBy(s => s.LastName).ThenBy(s => s.FirstName).ToList();

                bool allSubmitted = true;

                foreach (Student student in StudentRoster)
                {
                    AttendanceMarking mark = null;
                    AttendanceData    atd  = new AttendanceData()
                    {
                        StudentId = student.ID, Name = String.Format("{0} {1}", student.FirstName, student.LastName)
                    };

                    if (section.AttendanceMarkings.Where(m => m.StudentID == student.ID && m.AttendanceDate.Equals(date)).Count() == 1)
                    {
                        mark = section.AttendanceMarkings.Where(m => m.StudentID == student.ID && m.AttendanceDate.Equals(date)).Single();
                    }
                    else if (section.AttendanceMarkings.Where(m => m.StudentID == student.ID && m.AttendanceDate.Equals(date)).Count() > 1)
                    {
                        LogError("Multiple Attendance Markings found for {0} {1} in [{2}] {3} on {4}", student.FirstName, student.LastName, section.Block.LongName, section.Course.Name, date.ToString("DDD dd MMM, yyyy"));
                        AttendanceMarking        toKeep   = null;
                        List <AttendanceMarking> toDelete = section.AttendanceMarkings.Where(m => m.StudentID == student.ID && m.AttendanceDate.Equals(date)).ToList();
                        foreach (AttendanceMarking errMark in toDelete)
                        {
                            if (toKeep == null)
                            {
                                toKeep = errMark;
                            }

                            if (toKeep.Marking.Name.Equals("Excused"))
                            {
                                break;
                            }

                            if (errMark.SubmissionTime > toKeep.SubmissionTime)
                            {
                                toKeep = errMark;
                            }
                        }

                        toDelete.Remove(toKeep);

                        db.AttendanceMarkings.RemoveRange(toDelete);
                        db.SaveChanges();
                        foreach (Faculty teacher in section.Teachers.ToList())
                        {
                            MailControler.MailToUser("Attendance Needs Checking.",
                                                     String.Format("There was a problem with the marking for {0} {1} in [{2}] {3} on {4}.  I have attempted to correct the error, but you should double check it.  Currently, they are marked as {5}.", student.FirstName, student.LastName, section.Block.LongName, section.Course.Name, date.ToString("DDD dd MMM, yyyy"), toKeep.Marking.Name),
                                                     String.Format("{0}@dublinschool.org", teacher.UserName),
                                                     String.Format("{0} {1}", teacher.FirstName, teacher.LastName));
                        }
                    }
                    else
                    {
                        allSubmitted = false;
                    }

                    TableRow  row       = new TableRow();
                    TableCell nameCell  = new TableCell();
                    Label     nameLabel = new Label()
                    {
                        Text    = student.FirstName + " " + student.LastName,
                        ToolTip = "Advisor:  " + student.Advisor.FirstName + " " + student.Advisor.LastName,
                        Width   = Unit.Percentage(60)
                    };
                    HiddenField sidf = new HiddenField()
                    {
                        Value = Convert.ToString(student.ID)
                    };

                    nameCell.Controls.Add(sidf);
                    nameCell.Controls.Add(nameLabel);

                    TableCell       markingCell = new TableCell();
                    RadioButtonList markddl     = new RadioButtonList()
                    {
                        Width = Unit.Percentage(100), RepeatLayout = RepeatLayout.Table, RepeatDirection = RepeatDirection.Horizontal, RepeatColumns = 2, CssClass = "table_fixed"
                    };
                    int presentId = attMarkings.GradeTableEntries.Where(m => m.Name.Equals("Present")).Single().id;
                    markddl.DataSource     = attMarkings.GradeTableEntries.ToList();
                    markddl.DataTextField  = "Name";
                    markddl.DataValueField = "id";
                    markddl.DataBind();

                    if (mark != null)
                    {
                        markddl.ClearSelection();
                        markddl.SelectedValue = Convert.ToString(mark.MarkingIndex);
                        atd.Marking           = mark.Marking.Name;
                    }
                    else
                    {
                        markddl.ClearSelection();
                        markddl.SelectedValue = Convert.ToString(presentId);
                        atd.Marking           = "Present";
                    }

                    markingCell.Controls.Add(markddl);
                    ((List <AttendanceData>)api.Attendances).Add(atd);
                    row.BorderWidth = Unit.Pixel(2);
                    row.BorderStyle = BorderStyle.Solid;

                    row.Cells.Add(nameCell);
                    row.Cells.Add(markingCell);
                    AttendanceTable.Rows.Add(row);
                }

                if (section.AttendanceSubmissionStatuses.Where(s => s.Day.Equals(date) && s.AttendanceStatus.Blocking).Count() > 0)
                {
                    AttendanceSubmissionStatus status = section.AttendanceSubmissionStatuses.Where(s => s.Day.Equals(date)).Single();
                    if (status.TimeStamp.AddSeconds(5 * section.Students.Count) < DateTime.Now)
                    {
                        LogError("There was a problem entering attendance for [{0}] {1} at {2}. I will let the user know that there was a problem.",
                                 section.Block.LongName, section.Course.Name, status.TimeStamp.ToString("dddd, dd MM - h:mm:ss"));

                        if (allSubmitted) // calculated manually above!
                        {
                            LogInformation("Attendance was submitted earlier--but may not have been updated correctly.");
                            MailControler.MailToUser("Attendance Problem",
                                                     String.Format("Hello,{0}" +
                                                                   "Your attendance entry for [{1}] {2} had a problem when you tried to submit it at {3}.  There are saved attendance entries, but they may not be correct.  Please double check the entries and resubmit if necessary.{0}{0}Thanks!",
                                                                   Environment.NewLine, section.Block.LongName, section.Course.Name, status.TimeStamp.ToString("dddd, dd MM - h:mm:ss")), user, "*****@*****.**", "Attendance Bot");
                            SubmittedLabel.Text     = "You have not yet entered attendance data.";
                            SubmittedLabel.CssClass = "incomplete_highlight";
                            status.TimeStamp        = DateTime.Now;
                            status.StatusId         = db.AttendanceStatuses.Where(st => st.Name.Equals("Not Submitted")).Single().id;
                        }
                        else
                        {
                            LogInformation("Attendance was not submitted prior to this attempt.");
                            MailControler.MailToUser("Attendance Problem",
                                                     String.Format("Hello,{0}" +
                                                                   "Your attendance entry for [{1}] {2} had a problem when you tried to submit it at {3}.  There are incomplete attendance records right now.  Please double check the entries and resubmit your attendance for this class.{0}{0}Thanks!",
                                                                   Environment.NewLine, section.Block.LongName, section.Course.Name, status.TimeStamp.ToString("dddd, dd MM - h:mm:ss")), user, "*****@*****.**", "Attendance Bot");
                            SubmittedLabel.Text     = "Successfully Submitted.";
                            SubmittedLabel.CssClass = "success_highlight";
                            status.TimeStamp        = DateTime.Now;
                            status.StatusId         = db.AttendanceStatuses.Where(st => st.Name.Equals("Submitted")).Single().id;
                        }
                        db.SaveChanges();
                    }
                    else
                    {
                        LogWarning("The attendance for [{0}] {1} is still processing (less than the alotted {2} seconds have passed).", section.Block.LongName, section.Course.Name, (5 * section.Students.Count));
                        MailControler.MailToUser(String.Format("Attendance Submission Status for [{0}] {1}", section.Block.LongName, section.Course.Name),
                                                 String.Format("Hello,{0}Your attendance for [{1}] {2} is still processing.  Because of the number of students in your class, this may take as long as {3}:{4} minutes.  Wait at least that long and check again to see if it has submitted properly.",
                                                               Environment.NewLine, section.Block.LongName, section.Course.Name, (5 * section.Students.Count) / 60, (5 * section.Students.Count) % 60), user, "*****@*****.**", "Attendance Bot");
                        SubmittedLabel.Text     = "Attendance for this section is Currently Processing.";
                        SubmittedLabel.CssClass = "working_highlight";
                    }
                }
                else if (allSubmitted)
                {
                    SubmittedLabel.Text     = "Successfully Submitted.";
                    SubmittedLabel.CssClass = "success_highlight";
                }
                else
                {
                    SubmittedLabel.Text     = "You have not yet entered attendance data.";
                    SubmittedLabel.CssClass = "incomplete_highlight";
                }

                LogCurrentData(api);
            }
        }
コード例 #6
0
        protected void LoadInfo(int sectionId, DateTime date)
        {
            using (WebhostEntities db = new WebhostEntities())
            {
                int        year        = DateRange.GetCurrentAcademicYear();
                GradeTable attMarkings = db.GradeTables.Where(t => t.AcademicYearID == year && t.Name.Equals("Attendance")).Single();
                AttendanceTable.Rows.Clear();
                Section section = db.Sections.Where(sec => sec.id == sectionId).Single();
                BlockNameLabel.Text = String.Format("{0} Attendance", section.Block.Name);
                foreach (Student student in section.Students.OrderBy(s => s.LastName).ThenBy(s => s.FirstName).ToList())
                {
                    AttendanceMarking mark = null;

                    if (section.AttendanceMarkings.Where(m => m.StudentID == student.ID && m.AttendanceDate.Equals(date)).Count() > 0)
                    {
                        mark = section.AttendanceMarkings.Where(m => m.StudentID == student.ID && m.AttendanceDate.Equals(date)).Single();
                    }

                    TableRow  row       = new TableRow();
                    TableCell nameCell  = new TableCell();
                    Label     nameLabel = new Label()
                    {
                        Text    = student.FirstName + " " + student.LastName,
                        ToolTip = "Advisor:  " + student.Advisor.FirstName + " " + student.Advisor.LastName
                    };
                    HiddenField sidf = new HiddenField()
                    {
                        Value = Convert.ToString(student.ID)
                    };

                    nameCell.Controls.Add(sidf);
                    nameCell.Controls.Add(nameLabel);

                    TableCell       markingCell = new TableCell();
                    RadioButtonList markddl     = new RadioButtonList();
                    markddl.RepeatLayout    = RepeatLayout.Flow;
                    markddl.RepeatDirection = RepeatDirection.Horizontal;
                    markddl.RepeatColumns   = 4;
                    markddl.DataSource      = MedAttendanceMarking.GetDatasource();
                    markddl.DataTextField   = "Text";
                    markddl.DataValueField  = "ID";
                    markddl.DataBind();

                    markddl.ClearSelection();
                    if (mark != null)
                    {
                        markddl.SelectedValue = Convert.ToString(mark.MarkingIndex);
                    }
                    else
                    {
                        markddl.SelectedIndex = 2;
                    }

                    markingCell.Controls.Add(markddl);

                    row.Cells.Add(nameCell);
                    row.Cells.Add(markingCell);
                    AttendanceTable.Rows.Add(row);
                }
            }
        }
コード例 #7
0
        public AttendanceTickerRow(int id)
        {
            using (WebhostEntities db = new WebhostEntities())
            {
                if (db.AttendanceMarkings.Where(mk => mk.id == id).Count() <= 0)
                {
                    throw new WebhostMySQLConnection.Web.WebhostException("Invalid AttendanceMarkingId.");
                }

                AttendanceMarking marking = db.AttendanceMarkings.Where(mk => mk.id == id).Single();
                this.AttendanceMarkId = id;

                TableCell nameCell = new TableCell()
                {
                    Text    = String.Format("{0} {1} [{2}]", marking.Student.FirstName, marking.Student.LastName, marking.Student.GraduationYear),
                    ToolTip = String.Format("{0} {1}", marking.Student.Advisor.FirstName, marking.Student.Advisor.LastName)
                };
                this.Cells.Add(nameCell);

                TableCell     classCell = new TableCell();
                List <String> blocks    = new List <string>()
                {
                    "A", "B", "C", "D", "E", "F"
                };
                if (blocks.Contains(marking.Section.Block.Name))
                {
                    classCell.Text = String.Format("[{0}] {1}", marking.Section.Block.LongName, marking.Section.Course.Name);
                    bool first = true;
                    foreach (Faculty teacher in marking.Section.Teachers)
                    {
                        classCell.ToolTip += String.Format("{0}{1} {2}", first ? "" : Environment.NewLine, teacher.FirstName, teacher.LastName);
                        first              = false;
                    }
                }
                else
                {
                    classCell.Text = marking.Section.Course.Name;
                }

                this.Cells.Add(classCell);

                TableCell markingCell = new TableCell()
                {
                    Text    = marking.Marking.Name,
                    ToolTip = marking.Notes
                };
                this.Cells.Add(markingCell);

                TableCell timeCell = new TableCell()
                {
                    Text    = marking.SubmissionTime.ToLongTimeString(),
                    ToolTip = marking.AttendanceDate.ToLongDateString()
                };
                this.Cells.Add(timeCell);


                TableCell facCell = new TableCell()
                {
                    Text = marking.Notes.IndexOf("]") > 0 ? marking.Notes.Substring(1, marking.Notes.IndexOf("]") - 1) : "Unknown"
                };
                this.Cells.Add(facCell);
            }
        }
コード例 #8
0
        public void LoadTable()
        {
            using (WebhostEntities db = new WebhostEntities())
            {
                int     termId  = DateRange.GetCurrentOrLastTerm();
                Student student = db.Students.Where(s => s.ID == StudentId).Single();

                ((BasePage)Page).log.WriteLine("{0} Loading Attendance Table for {1} {2} [{3}].", Log.TimeStamp(), student.FirstName, student.LastName, student.GraduationYear);
                List <AttendanceMarking> markings = student.AttendanceMarkings.Where(mk => mk.AttendanceDate >= AttendancePeriod.Start && mk.AttendanceDate <= AttendancePeriod.End).ToList();
                ((BasePage)Page).log.WriteLine("{0} Grabbed {1} attendances.", Log.TimeStamp(), markings.Count);
                int lates = 0, cuts = 0, excused = 0;

                foreach (AttendanceMarking mark in markings)
                {
                    switch (mark.Marking.Name)
                    {
                    case "Late": lates++;
                        break;

                    case "Cut": cuts++;
                        break;

                    case "Excused": excused++;
                        break;

                    default: break;
                    }
                }
                ((BasePage)Page).log.WriteLine("{0} Counted:  {1} lates, {2} cuts, and {3} excused.", Log.TimeStamp(), lates, cuts, excused);
                NameLabel.Text    = String.Format("{0} {1} [{2}]", student.FirstName, student.LastName, student.GraduationYear);
                LatesLabel.Text   = Convert.ToString(lates);
                CutsLabel.Text    = Convert.ToString(cuts);
                ExcusedLabel.Text = Convert.ToString(excused);
                ((BasePage)Page).log.WriteLine("{0} Generating Table", Log.TimeStamp());
                TableHeaderRow  hrow  = new TableHeaderRow();
                TableHeaderCell ncell = new TableHeaderCell()
                {
                    Text = "Class"
                };
                hrow.Cells.Add(ncell);
                foreach (DateTime date in AttendancePeriod.ToList())
                {
                    TableHeaderCell dc = new TableHeaderCell()
                    {
                        Text = date.ToLongDateString()
                    };
                    hrow.Cells.Add(dc);
                }

                ScheduleTable.Rows.Add(hrow);
                ((BasePage)Page).log.WriteLine("{0} Header Added.", Log.TimeStamp());

                foreach (Section section in student.Sections.Where(sec => sec.Terms.Count <= 0 || sec.Terms.Contains(db.Terms.Where(t => t.id == termId).Single())).OrderBy(sec => sec.BlockIndex).ToList())
                {
                    ((BasePage)Page).log.WriteLine("{0} Adding Row for [{1}] {2}", Log.TimeStamp(), section.Block.LongName, section.Course.Name);
                    TableRow        row         = new TableRow();
                    TableHeaderCell sectionCell = new TableHeaderCell()
                    {
                        Text = String.Format("[{0}] {1}", section.Block.LongName, section.Course.Name)
                    };
                    row.Cells.Add(sectionCell);
                    foreach (DateTime date in AttendancePeriod.ToList())
                    {
                        ((BasePage)Page).log.WriteLine("{0} Examining {1}", Log.TimeStamp(), date.ToShortDateString());
                        TableCell cell = new TableCell();
                        if (student.AttendanceMarkings.Where(mk => mk.Section.Equals(section) && mk.AttendanceDate.Equals(date)).Count() == 1)
                        {
                            AttendanceMarking mark = student.AttendanceMarkings.Where(mk => mk.Section.Equals(section) && mk.AttendanceDate.Equals(date)).Single();
                            cell.Text    = mark.Marking.Name;
                            cell.ToolTip = mark.Notes;
                            ((BasePage)Page).log.WriteLine("{0} Displaying {1}.", Log.TimeStamp(), mark.Marking.Name);
                        }
                        else if (student.AttendanceMarkings.Where(mk => mk.Section.Equals(section) && mk.AttendanceDate.Equals(date)).Count() > 1)
                        {
                            ((BasePage)Page).log.WriteLine("{0} Too many markings!.", Log.TimeStamp());
                            cell.Text = "Multiple attendance markings!!!";
                            foreach (AttendanceMarking mark in student.AttendanceMarkings.Where(mk => mk.Section.Equals(section) && mk.AttendanceDate.Equals(date)).ToList())
                            {
                                cell.ToolTip += mark.Marking.Name + Environment.NewLine;
                            }
                        }
                        else
                        {
                            ((BasePage)Page).log.WriteLine("{0} No Data.", Log.TimeStamp());
                            cell.Text    = "*";
                            cell.ToolTip = "No Data.";
                        }
                        row.Cells.Add(cell);
                    }

                    ScheduleTable.Rows.Add(row);

                    ((BasePage)Page).log.WriteLine("{0} Added Row to Table.", Log.TimeStamp());
                }
            }

            ((BasePage)Page).log.WriteLine("{0} Done.", Log.TimeStamp());
        }
コード例 #9
0
        new protected void Page_Init(object sender, EventArgs e)
        {
            base.Page_Init(sender, e);
            WeekLabel.Text = string.Format("Week of {0} through {1}", thisWeek.Start.ToString("dddd, dd MMM"), thisWeek.End.ToString("dddd, dd MMM"));
            using (WebhostEntities db = new WebhostEntities())
            {
                TableHeaderRow hr = new TableHeaderRow();
                hr.Cells.Add(new TableHeaderCell()
                {
                    Text = "Class"
                });
                foreach (DateTime date in thisWeek.ToList())
                {
                    if (date.DayOfWeek.Equals(DayOfWeek.Saturday) || date.DayOfWeek.Equals(DayOfWeek.Sunday))
                    {
                        continue;
                    }
                    hr.Cells.Add(new TableHeaderCell()
                    {
                        Text = date.ToString("dddd, dd MMM")
                    });
                }

                ClassesTable.Rows.Add(hr);

                int curTerm = DateRange.GetCurrentOrLastTerm();

                if (user.IsStudent || StudentMasq != -1)
                {
                    AdminPanel.Visible = false;
                    Student student = db.Students.Find(user.IsStudent ? user.ID : StudentMasq);
                    if (StudentMasq != -1)
                    {
                        Faculty teacher = db.Faculties.Find(user.ID);

                        LoadAdminPanel(db, teacher, curTerm);
                        AdminPanel.Visible = true;

                        WeekLabel.Text += String.Format(".  For {0} {1}", student.FirstName, student.LastName);
                    }
                    foreach (Section section in student.Sections.Where(s => s.Terms.Where(t => t.id == curTerm).Count() > 0).ToList())
                    {
                        TableRow row           = new TableRow();
                        String   teachersNames = "";
                        foreach (Faculty fac in section.Teachers.ToList())
                        {
                            teachersNames += String.Format("{0} {1}  ", fac.FirstName, fac.LastName);
                        }
                        row.Cells.Add(new TableCell()
                        {
                            Text = String.Format("[{0}] {1}", section.Block.LongName, section.Course.Name), ToolTip = teachersNames
                        });
                        foreach (DateTime date in thisWeek.ToList())
                        {
                            if (date.DayOfWeek.Equals(DayOfWeek.Saturday) || date.DayOfWeek.Equals(DayOfWeek.Sunday))
                            {
                                continue;
                            }
                            bool meetsThisDay = false;
                            switch (date.DayOfWeek)
                            {
                            case DayOfWeek.Monday: meetsThisDay = section.Block.MeetsMonday; break;

                            case DayOfWeek.Tuesday: meetsThisDay = section.Block.MeetsTuesday; break;

                            case DayOfWeek.Wednesday:
                                if (!section.Block.MeetsWednesday || section.Course.Name.Contains("Tutorial"))
                                {
                                    meetsThisDay = false;
                                }
                                else if (section.Block.IsSpecial || db.WednesdaySchedules.Where(w => w.Day.Equals(date)).Count() <= 0)
                                {
                                    meetsThisDay = section.Block.MeetsWednesday;
                                }
                                else
                                {
                                    meetsThisDay = DateRange.BlockOrderByDayOfWeek(date).Contains(section.Block.Name[0]);
                                }
                                break;

                            case DayOfWeek.Thursday: meetsThisDay = section.Block.MeetsThursday; break;

                            case DayOfWeek.Friday: meetsThisDay = section.Block.MeetsFriday; break;

                            default: break;
                            }

                            String attendanceMarking = meetsThisDay?"*":"No Meeting";
                            String note = "No Data";
                            if (section.AttendanceMarkings.Where(att => att.AttendanceDate.Equals(date) && att.StudentID.Equals(StudentMasq == -1 ? user.ID: StudentMasq)).Count() > 0)
                            {
                                AttendanceMarking mark = section.AttendanceMarkings.Where(att => att.AttendanceDate.Equals(date) && att.StudentID.Equals(StudentMasq == -1 ? user.ID : StudentMasq)).Single();
                                attendanceMarking = mark.Marking.Name;
                                note = mark.Notes;
                            }
                            row.Cells.Add(new TableCell()
                            {
                                Text      = attendanceMarking,
                                BackColor = attendanceMarking.Equals("Present") ?
                                            System.Drawing.Color.Green :
                                            attendanceMarking.Equals("Late") ?
                                            System.Drawing.Color.LightGoldenrodYellow :
                                            attendanceMarking.Equals("Cut") ?
                                            System.Drawing.Color.Red :
                                            attendanceMarking.Equals("Excused") ? System.Drawing.Color.LightSeaGreen :
                                            meetsThisDay ?
                                            System.Drawing.Color.LightCoral : System.Drawing.Color.LavenderBlush,
                                ToolTip = note
                            });
                        }

                        ClassesTable.Rows.Add(row);
                    }
                }
                else
                {
                    AdminPanel.Visible = true;
                    Faculty teacher = db.Faculties.Find(user.ID);

                    //int curTerm = DateRange.GetCurrentOrLastTerm();

                    LoadAdminPanel(db, teacher, curTerm);

                    if (TeacherMasq != -1)
                    {
                        teacher         = db.Faculties.Find(TeacherMasq);
                        WeekLabel.Text += String.Format(".  For {0} {1}", teacher.FirstName, teacher.LastName);
                    }

                    foreach (Section section in teacher.Sections.Where(s => s.Terms.Where(t => t.id == curTerm).Count() > 0).ToList())
                    {
                        TableRow row           = new TableRow();
                        String   teachersNames = "";
                        foreach (Faculty fac in section.Teachers.ToList())
                        {
                            teachersNames += String.Format("{0} {1}  ", fac.FirstName, fac.LastName);
                        }
                        row.Cells.Add(new TableCell()
                        {
                            Text = String.Format("[{0}] {1}", section.Block.LongName, section.Course.Name), ToolTip = teachersNames
                        });
                        foreach (DateTime date in thisWeek.ToList())
                        {
                            if (date.DayOfWeek.Equals(DayOfWeek.Saturday) || date.DayOfWeek.Equals(DayOfWeek.Sunday))
                            {
                                continue;
                            }
                            bool attendanceTaken = true;
                            foreach (Student student in section.Students.ToList())
                            {
                                if (section.AttendanceMarkings.Where(att => att.AttendanceDate.Equals(date) && att.StudentID.Equals(student.ID)).Count() <= 0)
                                {
                                    attendanceTaken = false;
                                    break;
                                }
                            }
                            bool meetsThisDay = false;
                            switch (date.DayOfWeek)
                            {
                            case DayOfWeek.Monday: meetsThisDay = section.Block.MeetsMonday; break;

                            case DayOfWeek.Tuesday: meetsThisDay = section.Block.MeetsTuesday; break;

                            case DayOfWeek.Wednesday:
                                if (!section.Block.MeetsWednesday || section.Course.Name.Contains("Tutorial"))
                                {
                                    meetsThisDay = false;
                                }
                                else if (section.Block.IsSpecial || db.WednesdaySchedules.Where(w => w.Day.Equals(date)).Count() <= 0)
                                {
                                    meetsThisDay = section.Block.MeetsWednesday;
                                }
                                else
                                {
                                    meetsThisDay = DateRange.BlockOrderByDayOfWeek(date).Contains(section.Block.Name[0]);
                                }
                                break;

                            case DayOfWeek.Thursday: meetsThisDay = section.Block.MeetsThursday; break;

                            case DayOfWeek.Friday: meetsThisDay = section.Block.MeetsFriday; break;

                            default: break;
                            }
                            row.Cells.Add(new TableCell()
                            {
                                Text      = attendanceTaken ? "Complete" : meetsThisDay? "Incomplete": "No Meeting",
                                BackColor = attendanceTaken ? System.Drawing.Color.Green : meetsThisDay? System.Drawing.Color.Red : System.Drawing.Color.AliceBlue
                            });
                        }

                        ClassesTable.Rows.Add(row);
                    }
                }
            }
        }
コード例 #10
0
        public IHttpActionResult PutMyAttendance(int section_id, [FromBody] List <AttendanceInfo> content)
        {
            using (WebhostEntities db = new WebhostAPI.WebhostEntities())
            {
                WebhostUserPrinciple principal = (WebhostUserPrinciple)ActionContext.RequestContext.Principal;
                int tid = ((WebhostIdentity)principal.Identity).User.Id;

                Faculty self = db.Faculties.Find(tid);

                Section section = db.Sections.Find(section_id);
                if (section == null)
                {
                    return(ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.BadRequest, new ArgumentException("Invalid Section Id."))));
                }

                if (!section.Teachers.Contains(self))
                {
                    return(ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.NotAcceptable, new InvalidOperationException("That is not your class."))));
                }


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

                int nextId = db.AttendanceMarkings.OrderBy(m => m.id).ToList().Last().id;

                foreach (AttendanceInfo info in content)
                {
                    if (info.SectionId != section_id)
                    {
                        continue;
                    }

                    AttendanceMarking marking = null;

                    if (section.AttendanceMarkings.Where(s => s.AttendanceDate.Equals(info.Date) && s.StudentID == info.StudentId).Count() > 0)
                    {
                        marking = section.AttendanceMarkings.Where(s => s.AttendanceDate.Equals(info.Date) && s.StudentID == info.StudentId).Single();
                        marking.MarkingIndex = AttendanceInfo.LookUpAttendanceMarking(info.Marking);
                        marking.SubmittedBy  = tid;
                        if (!String.IsNullOrEmpty(info.Notes))
                        {
                            marking.Notes += String.Format("[{0} {1}] {2}", self.FirstName, self.LastName, info.Notes);
                        }
                        marking.SubmissionTime = DateTime.Now;

                        outputIds.Add(marking.id);
                    }
                    else
                    {
                        marking = new WebhostAPI.AttendanceMarking()
                        {
                            id             = ++nextId,
                            AttendanceDate = info.Date,
                            MarkingIndex   = AttendanceInfo.LookUpAttendanceMarking(info.Marking),
                            SubmittedBy    = tid,
                            Notes          = String.Format("[{0} {1}] {2}", self.FirstName, self.LastName, String.IsNullOrEmpty(info.Notes) ? "" : info.Notes),
                            StudentID      = info.StudentId,
                            SectionIndex   = info.SectionId,
                            SubmissionTime = DateTime.Now
                        };

                        db.AttendanceMarkings.Add(marking);
                        outputIds.Add(marking.id);
                    }
                }

                List <AttendanceInfo> output = new List <AttendanceInfo>();
                foreach (int iid in outputIds)
                {
                    output.Add(new RequestHandlers.AttendanceInfo(iid, true));
                }

                return(ResponseMessage(Request.CreateResponse(HttpStatusCode.OK, output, "text/json")));
            }
        }