protected void Page_Load(object sender, EventArgs e)
        {
            List <Student>      students              = new List <Student>();
            List <Student>      displayedStudents     = new List <Student>();
            List <ReportPeriod> selectedReportPeriods = new List <ReportPeriod>();

            bool anonymize = false;

            if (!string.IsNullOrEmpty(Request.QueryString["anon"]))
            {
                anonymize = true;
            }

            bool showPhoto = false;

            if ((!string.IsNullOrEmpty(Request.QueryString["showphoto"])) || (!string.IsNullOrEmpty(Request.QueryString["showphotos"])))
            {
                showPhoto = true;
            }

            bool doubleSided = false;

            if (!string.IsNullOrEmpty(Request.QueryString["doublesided"]))
            {
                doubleSided = true;
            }

            bool showClassAttendance = false;

            if (!string.IsNullOrEmpty(Request.QueryString["showclassattendance"]))
            {
                showClassAttendance = true;
            }

            bool showLegends = false;

            if ((!string.IsNullOrEmpty(Request.QueryString["showlegends"])) || (!string.IsNullOrEmpty(Request.QueryString["showlegend"])))
            {
                showLegends = true;
            }

            bool showAttendanceSummary = false;

            if ((!string.IsNullOrEmpty(Request.QueryString["showattendancesummary"])) || (!string.IsNullOrEmpty(Request.QueryString["showattendancesummaries"])))
            {
                showAttendanceSummary = true;
            }

            using (SqlConnection connection = new SqlConnection(dbConnectionString))
            {
                // Parse student IDs
                if (!string.IsNullOrEmpty(Request.QueryString["students"]))
                {
                    foreach (string student in Request.QueryString["students"].Split(';'))
                    {
                        if (!string.IsNullOrEmpty(student))
                        {
                            int student_id = -1;
                            if (int.TryParse(student, out student_id))
                            {
                                students.Add(Student.loadThisStudent(connection, student_id.ToString()));
                            }
                        }
                    }

                    foreach (string rp in Request.QueryString["reportperiods"].Split(';'))
                    {
                        if (!string.IsNullOrEmpty(rp))
                        {
                            int rp_id = -1;
                            if (int.TryParse(rp, out rp_id))
                            {
                                selectedReportPeriods.Add(ReportPeriod.loadThisReportPeriod(connection, rp_id));
                            }
                        }
                    }
                }
            }

            selectedReportPeriods.Sort();

            using (SqlConnection connection = new SqlConnection(dbConnectionString))
            {
                foreach (Student student in students)
                {
                    if (student != null)
                    {
                        Stopwatch studentStopWatch = new Stopwatch();
                        studentStopWatch.Start();
                        displayedStudents.Add(LSKYCommon.loadStudentMarkData(connection, student, selectedReportPeriods));
                        studentStopWatch.Stop();
                    }
                }
                students.Clear();
            }

            String fileName = "ReportCards_" + DateTime.Today.Year + "_" + DateTime.Today.Month + "_" + DateTime.Today.Day + ".pdf";

            if ((selectedReportPeriods.Count > 0) && (displayedStudents.Count > 0))
            {
                sendPDF(PDFReportCardParts.GeneratePDF(displayedStudents, selectedReportPeriods, anonymize, showPhoto, doubleSided, showClassAttendance, showLegends, showAttendanceSummary, string.Empty), fileName);
            }
        }
Exemplo n.º 2
0
        protected void btnGenerate_Click(object sender, EventArgs e)
        {
            // Parse the selected school ID
            int schoolID = -1;

            if (int.TryParse(drpSchools.SelectedValue, out schoolID))
            {
                School selectedSchool = null;
                using (SqlConnection connection = new SqlConnection(sqlConnectionString))
                {
                    // Load the school
                    selectedSchool = School.loadThisSchool(connection, schoolID);

                    if (selectedSchool != null)
                    {
                        // Load the selected student
                        Student selectedStudent = Student.loadThisStudent(connection, drpStudents.SelectedValue);

                        if (selectedStudent != null)
                        {
                            List <Student> selectedStudents = new List <Student>();
                            selectedStudents.Add(selectedStudent);

                            // Load checked report periods
                            List <int>          selectedReportPeriodIDs = new List <int>();
                            List <ReportPeriod> selectedReportPeriods   = new List <ReportPeriod>();

                            foreach (ListItem item in chkReportPeriods.Items)
                            {
                                if (item.Selected)
                                {
                                    int parsedValue = -1;
                                    if (int.TryParse(item.Value, out parsedValue))
                                    {
                                        if (!selectedReportPeriodIDs.Contains(parsedValue))
                                        {
                                            selectedReportPeriodIDs.Add(parsedValue);
                                        }
                                    }
                                }
                            }

                            if (selectedReportPeriodIDs.Count > 0)
                            {
                                foreach (int reportPeriodID in selectedReportPeriodIDs)
                                {
                                    ReportPeriod loadedReportPeriod = ReportPeriod.loadThisReportPeriod(connection, reportPeriodID);
                                    if (loadedReportPeriod != null)
                                    {
                                        selectedReportPeriods.Add(loadedReportPeriod);
                                    }
                                }

                                // Load student mark data
                                List <Student> studentsWithMarks = new List <Student>();
                                foreach (Student student in selectedStudents)
                                {
                                    studentsWithMarks.Add(LSKYCommon.loadStudentMarkData(connection, student, selectedReportPeriods));
                                }

                                // Options
                                bool doubleSidedMode = false;
                                if (chkDoubleSidedMode.Checked)
                                {
                                    doubleSidedMode = true;
                                }

                                bool anonymize = false;
                                if (chkAnonymize.Checked)
                                {
                                    anonymize = true;
                                }

                                bool showPhotos = false;
                                if (chkShowPhotos.Checked)
                                {
                                    showPhotos = true;
                                }

                                bool showClassAttendance = false;
                                if (chkClassAttendance.Checked)
                                {
                                    showClassAttendance = true;
                                }

                                bool showLegends = true;

                                bool showAttendanceSummary = false;
                                if (chkShowAttendanceSummary.Checked)
                                {
                                    showAttendanceSummary = true;
                                }

                                string adminComment = txtAdminComment.Text;

                                // Send the report card
                                String fileName = "ReportCards_" + selectedStudent.getStudentID() + "_" + DateTime.Today.Year + "_" + DateTime.Today.Month + "_" + DateTime.Today.Day + ".pdf";
                                if ((selectedReportPeriods.Count > 0) && (selectedStudents.Count > 0))
                                {
                                    sendPDF(PDFReportCardParts.GeneratePDF(selectedStudents, selectedReportPeriods, anonymize, showPhotos, doubleSidedMode, showClassAttendance, showLegends, showAttendanceSummary, adminComment), fileName);
                                }
                            }
                            else
                            {
                                // No report periods were selected - should display some kind of error here
                            }
                        }
                    }
                }
            }
        }
        protected void btnReportPeriod_Click(object sender, EventArgs e)
        {
            string selectedGrade = drpGrades.SelectedValue;

            // Parse the selected school ID
            int schoolID = -1;

            if (int.TryParse(drpSchools.SelectedValue, out schoolID))
            {
                School selectedSchool = null;
                using (SqlConnection connection = new SqlConnection(sqlConnectionString))
                {
                    // Load the school
                    selectedSchool = School.loadThisSchool(connection, schoolID);

                    if (selectedSchool != null)
                    {
                        // Load all students
                        List <Student> schoolStudents = new List <Student>();
                        schoolStudents = Student.loadStudentsFromThisSchool(connection, schoolID);

                        // Filter out the ones for that grade
                        List <Student> selectedStudents = new List <Student>();
                        foreach (Student student in schoolStudents)
                        {
                            if (student != null)
                            {
                                if (student.getGrade() == selectedGrade)
                                {
                                    selectedStudents.Add(student);
                                }
                            }
                        }

                        // Load checked report periods
                        List <int>          selectedReportPeriodIDs = new List <int>();
                        List <ReportPeriod> selectedReportPeriods   = new List <ReportPeriod>();

                        foreach (ListItem item in chkReportPeriods.Items)
                        {
                            if (item.Selected)
                            {
                                int parsedValue = -1;
                                if (int.TryParse(item.Value, out parsedValue))
                                {
                                    if (!selectedReportPeriodIDs.Contains(parsedValue))
                                    {
                                        selectedReportPeriodIDs.Add(parsedValue);
                                    }
                                }
                            }
                        }

                        foreach (int reportPeriodID in selectedReportPeriodIDs)
                        {
                            ReportPeriod loadedReportPeriod = ReportPeriod.loadThisReportPeriod(connection, reportPeriodID);
                            if (loadedReportPeriod != null)
                            {
                                selectedReportPeriods.Add(loadedReportPeriod);
                            }
                        }

                        // Load student mark data
                        List <Student> studentsWithMarks = new List <Student>();
                        foreach (Student student in selectedStudents)
                        {
                            studentsWithMarks.Add(LSKYCommon.loadStudentMarkData(connection, student, selectedReportPeriods));
                        }

                        // Sort students
                        List <Student> reportcardStudents = new List <Student>();
                        if (chkSortByHomeRoom.Checked)
                        {
                            reportcardStudents = studentsWithMarks.OrderBy(c => c.getHomeRoom()).ThenBy(c => c.getLastName()).ToList <Student>();
                        }
                        else
                        {
                            reportcardStudents = studentsWithMarks.OrderBy(c => c.getLastName()).ToList <Student>();
                        }

                        // Options
                        bool doubleSidedMode = false;
                        if (chkDoubleSidedMode.Checked)
                        {
                            doubleSidedMode = true;
                        }

                        bool anonymize = false;
                        if (chkAnonymize.Checked)
                        {
                            anonymize = true;
                        }

                        bool showPhotos = false;
                        if (chkShowPhotos.Checked)
                        {
                            showPhotos = true;
                        }

                        bool showClassAttendance = false;
                        if (chkClassAttendance.Checked)
                        {
                            showClassAttendance = true;
                        }

                        bool showLegends = true;

                        bool showAttendanceSummary = false;
                        if (chkShowAttendanceSummary.Checked)
                        {
                            showAttendanceSummary = true;
                        }

                        string adminComment = txtAdminComment.Text;

                        // Send the report card
                        String fileName = "ReportCards_" + LSKYCommon.removeSpaces(selectedSchool.getName()) + "_Grade" + selectedGrade + "_" + DateTime.Today.Year + "_" + DateTime.Today.Month + "_" + DateTime.Today.Day + ".pdf";
                        if ((selectedReportPeriods.Count > 0) && (reportcardStudents.Count > 0))
                        {
                            sendPDF(PDFReportCardParts.GeneratePDF(reportcardStudents, selectedReportPeriods, anonymize, showPhotos, doubleSidedMode, showClassAttendance, showLegends, showAttendanceSummary, adminComment), fileName);
                        }
                    }
                }
            }
        }