private TableRow createStudentRow(Student student, DateTime startDate, DateTime endDate)
        {
            // Split absences into explained / unexplained
            List <Absence> explainedAbsences   = new List <Absence>();
            List <Absence> unExplainedAbsences = new List <Absence>();

            foreach (Absence abs in student.absences)
            {
                if (abs.excused)
                {
                    explainedAbsences.Add(abs);
                }
                else
                {
                    unExplainedAbsences.Add(abs);
                }
            }

            string calculationExplaination_Total       = string.Empty;
            string calculationExplaination_Explained   = string.Empty;
            string calculationExplaination_Unexplained = string.Empty;
            float  daysAbsent_Total       = LSKY_INAC.getDaysAbsent(student, out calculationExplaination_Total);
            float  daysAbsent_Explained   = LSKY_INAC.getDaysAbsent_Explained(student, out calculationExplaination_Explained);
            float  daysAbsent_Unexplained = LSKY_INAC.getDaysAbsent_Unexplained(student, out calculationExplaination_Unexplained);

            /* figure out guardian(s) */
            List <Contact> guardiansList = LSKY_INAC.getINACGuardians(student.contacts);
            StringBuilder  guardians     = new StringBuilder();

            foreach (Contact contact in guardiansList)
            {
                guardians.Append(contact.firstName + " " + contact.lastName + " </i>(" + contact.relation + ")</i><br>");
            }


            TableRow newRow = new TableRow();

            newRow.CssClass = "datatable_row";

            TableCell gradeCell = new TableCell();

            gradeCell.Text          = student.getGradeFormatted();
            gradeCell.VerticalAlign = VerticalAlign.Top;
            newRow.Cells.Add(gradeCell);

            TableCell nameCell = new TableCell();

            nameCell.Text          = student.getDisplayName();
            nameCell.VerticalAlign = VerticalAlign.Top;
            newRow.Cells.Add(nameCell);

            TableCell birthdayCell = new TableCell();

            birthdayCell.Text            = student.getDateOfBirth().Month + "/" + student.getDateOfBirth().Day + "/" + student.getDateOfBirth().Year;
            birthdayCell.VerticalAlign   = VerticalAlign.Top;
            birthdayCell.HorizontalAlign = HorizontalAlign.Right;
            newRow.Cells.Add(birthdayCell);

            TableCell bandCell = new TableCell();

            bandCell.Text          = student.getBandName();
            bandCell.VerticalAlign = VerticalAlign.Top;
            newRow.Cells.Add(bandCell);

            TableCell statusNoCell = new TableCell();

            statusNoCell.Text          = student.getStatusNo();
            statusNoCell.VerticalAlign = VerticalAlign.Top;
            newRow.Cells.Add(statusNoCell);

            TableCell reserveCell = new TableCell();

            reserveCell.Text          = student.getReserveName();
            reserveCell.VerticalAlign = VerticalAlign.Top;
            newRow.Cells.Add(reserveCell);

            TableCell houseNoCell = new TableCell();

            houseNoCell.Text          = student.getReserveHouse();
            houseNoCell.VerticalAlign = VerticalAlign.Top;
            newRow.Cells.Add(houseNoCell);

            TableCell guardianCell = new TableCell();

            guardianCell.Text          = guardians.ToString();
            guardianCell.VerticalAlign = VerticalAlign.Top;
            newRow.Cells.Add(guardianCell);


            // Unexplained absences
            TableCell daysAbsent_UnexplainedCell = new TableCell();

            if (daysAbsent_Unexplained == 0)
            {
                daysAbsent_UnexplainedCell.Text = "<i style=\"color: #707070;\">No Absences</i>";
            }
            else if (daysAbsent_Unexplained >= 0)
            {
                daysAbsent_UnexplainedCell.Text = "<abbr title=\"" + calculationExplaination_Unexplained + "\">" + Math.Round(daysAbsent_Unexplained, 2) + " days</abbr>";
            }
            daysAbsent_UnexplainedCell.VerticalAlign = VerticalAlign.Top;
            daysAbsent_UnexplainedCell.BorderColor   = System.Drawing.ColorTranslator.FromHtml("#E8ADAA");
            newRow.Cells.Add(daysAbsent_UnexplainedCell);

            TableCell blocksAbsent_UnexplainedCell = new TableCell();

            blocksAbsent_UnexplainedCell.Text          = unExplainedAbsences.Count + " blocks";
            blocksAbsent_UnexplainedCell.VerticalAlign = VerticalAlign.Top;
            blocksAbsent_UnexplainedCell.BorderColor   = System.Drawing.ColorTranslator.FromHtml("#E8ADAA");
            newRow.Cells.Add(blocksAbsent_UnexplainedCell);

            // Explained absences

            /*
             * TableCell daysAbsent_ExplainedCell = new TableCell();
             * if (daysAbsent_Explained == 0)
             * {
             *  daysAbsent_ExplainedCell.Text = "<i style=\"color: #707070;\">No Absences</i>";
             * }
             * else if (daysAbsent_Explained >= 0)
             * {
             *  daysAbsent_ExplainedCell.Text = "<abbr title=\"" + calculationExplaination_Explained + "\">" + Math.Round(daysAbsent_Explained, 2) + " days</abbr>";
             * }
             * daysAbsent_ExplainedCell.VerticalAlign = VerticalAlign.Top;
             * daysAbsent_ExplainedCell.BorderColor = System.Drawing.ColorTranslator.FromHtml("#C3FDB8");
             * newRow.Cells.Add(daysAbsent_ExplainedCell);
             *
             * TableCell blocksAbsent_ExplainedCell = new TableCell();
             * blocksAbsent_ExplainedCell.Text = explainedAbsences.Count + " blocks";
             * blocksAbsent_ExplainedCell.VerticalAlign = VerticalAlign.Top;
             * blocksAbsent_ExplainedCell.BorderColor = System.Drawing.ColorTranslator.FromHtml("#C3FDB8");
             * newRow.Cells.Add(blocksAbsent_ExplainedCell);
             */


            // total absences
            TableCell daysAbsent_TotalCell = new TableCell();

            if (daysAbsent_Total == 0)
            {
                daysAbsent_TotalCell.Text = "<i style=\"color: #707070;\">No Absences</i>";
            }
            else if (daysAbsent_Total >= 0)
            {
                daysAbsent_TotalCell.Text = "<abbr title=\"" + calculationExplaination_Total + "\">" + Math.Round(daysAbsent_Total, 2) + " days</abbr>";
            }
            daysAbsent_TotalCell.VerticalAlign = VerticalAlign.Top;
            newRow.Cells.Add(daysAbsent_TotalCell);

            TableCell blocksAbsent_TotalCell = new TableCell();

            blocksAbsent_TotalCell.Text          = student.absences.Count + " blocks";
            blocksAbsent_TotalCell.VerticalAlign = VerticalAlign.Top;
            newRow.Cells.Add(blocksAbsent_TotalCell);

            TableCell dateRegisterCell = new TableCell();

            dateRegisterCell.Text          = student.getEnrollDate().Month + "/" + student.getEnrollDate().Day + "/" + student.getEnrollDate().Year;
            dateRegisterCell.VerticalAlign = VerticalAlign.Top;
            newRow.Cells.Add(dateRegisterCell);

            TableCell absenceLinkCell = new TableCell();

            absenceLinkCell.Text          = "<a href=\"../Attendance/getAttendance.aspx?from_year=" + startDate.Year + "&from_month=" + startDate.Month + "&from_day=" + startDate.Day + "&to_year=" + endDate.Year + "&to_month=" + endDate.Month + "&to_day=" + endDate.Day + "&studentid=" + student.getStudentID() + "\" TARGET=\"_blank\">View absences</a>";
            absenceLinkCell.VerticalAlign = VerticalAlign.Top;
            newRow.Cells.Add(absenceLinkCell);

            return(newRow);
        }
        protected MemoryStream GenerateCSV(List <Student> students)
        {
            MemoryStream csvFile = new MemoryStream();
            StreamWriter writer  = new StreamWriter(csvFile, Encoding.UTF8);

            // CSV Headings
            StringBuilder headingLine = new StringBuilder();

            headingLine.Append("Grade, StudentName, DateOfBirth, BandAffiliation, StatusNo, ReserveOfResidence, HouseNo, ParentOrGuardian, DaysAbsentUnexcused, BlocksAbsentUnexcused, DaysAbsentExcused, BlocksAbsentExcused, DaysAbsentTotal, BlocksAbsentTotal, InStatusDate");
            writer.WriteLine(headingLine.ToString());

            // CSV Data
            foreach (Student student in students)
            {
                // Get explained / unexplained counts
                int excused   = 0;
                int unexcused = 0;
                foreach (Absence abs in student.absences)
                {
                    if (abs.excused)
                    {
                        excused++;
                    }
                    else
                    {
                        unexcused++;
                    }
                }

                // Figure out days absent
                float daysAbsent             = LSKY_INAC.getDaysAbsent(student);
                float daysAbsent_Explained   = LSKY_INAC.getDaysAbsent_Explained(student);
                float daysAbsent_Unexplained = LSKY_INAC.getDaysAbsent_Unexplained(student);

                // Figure out guardians
                List <Contact> guardiansList = LSKY_INAC.getINACGuardians(student.contacts);
                StringBuilder  guardians     = new StringBuilder();

                for (int x = 0; x < guardiansList.Count; x++)
                {
                    guardians.Append(guardiansList[x].firstName + " " + guardiansList[x].lastName + " (" + guardiansList[x].relation + ")");
                    if (x < guardiansList.Count - 1)
                    {
                        guardians.Append("; ");
                    }
                }

                StringBuilder studentLine = new StringBuilder();
                studentLine.Append(student.getGradeFormatted());
                studentLine.Append(",");

                studentLine.Append(student.getDisplayName());
                studentLine.Append(",");

                studentLine.Append(student.getDateOfBirth().Month + "/" + student.getDateOfBirth().Day + "/" + student.getDateOfBirth().Year);
                studentLine.Append(",");

                studentLine.Append(student.getBandName());
                studentLine.Append(",");

                studentLine.Append(student.getStatusNo());
                studentLine.Append(",");

                studentLine.Append(student.getReserveName());
                studentLine.Append(",");

                studentLine.Append(student.getReserveHouse());
                studentLine.Append(",");

                studentLine.Append(guardians.ToString());
                studentLine.Append(",");

                // Unexplained
                studentLine.Append(Math.Round(daysAbsent_Unexplained, 2).ToString());
                studentLine.Append(",");

                studentLine.Append(unexcused.ToString());
                studentLine.Append(",");


                // Excused
                studentLine.Append(Math.Round(daysAbsent_Explained, 2).ToString());
                studentLine.Append(",");

                studentLine.Append(excused.ToString());
                studentLine.Append(",");


                // Total
                studentLine.Append(Math.Round(daysAbsent, 2).ToString());
                studentLine.Append(",");

                studentLine.Append(student.absences.Count.ToString());
                studentLine.Append(",");

                studentLine.Append(student.getEnrollDate().Month + "/" + student.getEnrollDate().Day + "/" + student.getEnrollDate().Year);

                writer.WriteLine(studentLine.ToString());
            }
            writer.Flush();
            csvFile.Flush();
            return(csvFile);
        }