protected void Page_Load(object sender, EventArgs e) { Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); string selectedStudentID = "106757957"; int selectedReportPeriodID = 479; using (SqlConnection connection = new SqlConnection(LSKYCommon.dbConnectionString_SchoolLogic)) { Student selectedStudent = Student.loadThisStudent(connection, selectedStudentID); displayString("<B>Selected Student: </B>" + selectedStudent); // Derive the term to get classes from Term selectedTerm = Term.loadTermFromReportPeriod(connection, selectedReportPeriodID); displayString("<B>Term:</B> " + selectedTerm); // Track is already loaded from the student load function displayString("<B>Student Track: </B>" + selectedStudent.track); // Load student timetable entries selectedStudent.TimeTable = TimeTableEntry.loadStudentTimeTable(connection, selectedStudent, selectedTerm); // Load absences from the last month (for testing) selectedStudent.absences = Absence.loadAbsencesForThisStudentAndTimePeriod(connection, selectedStudent, DateTime.Now.AddDays(-30), DateTime.Now); // Display absences displayList("Absences", selectedStudent.absences); } displayString("<BR><BR>"); stopwatch.Stop(); displayString("Elapsed time: " + stopwatch.Elapsed); }
/// <summary> /// Loads mark data for a student for report cards. Loads terms, report periods, enrolled classes, class marks, outcomes, outcome marks, and attendance /// </summary> /// <param name="connection">Database connection</param> /// <param name="thisStudent">The student to load data for</param> /// <param name="theseReportPeriods">Report periods to load data for</param> /// <returns>Student object loaded with terms, report periods, enrolled classes, class marks, outcomes, outcome marks, and attendance</returns> public static Student loadStudentMarkData(SqlConnection connection, Student thisStudent, List <ReportPeriod> theseReportPeriods) { Student returnedStudent = thisStudent; // ************************************************************** // * Report Period Comments // ************************************************************** // Load report period comments for the selected report periods List <ReportPeriodComment> allRPComments = ReportPeriodComment.loadRPCommentsForStudent(connection, thisStudent.getStudentID()); List <ReportPeriodComment> filteredRPComments = ReportPeriodComment.getCommentsForTheseReportPeriods(allRPComments, theseReportPeriods); returnedStudent.ReportPeriodComments = filteredRPComments; // ************************************************************** // * Report Periods // ************************************************************** // Find the earliest report period and the last report period, for attendance dates DateTime earliestDate = DateTime.MaxValue; DateTime lastDate = DateTime.MinValue; List <int> detectedTermIDs = new List <int>(); List <int> selectedReportPeriodIDs = new List <int>(); List <ReportPeriod> reportPeriods = new List <ReportPeriod>(); // Validate report periods so we aren't working with nulls foreach (ReportPeriod rp in theseReportPeriods) { if (rp != null) { reportPeriods.Add(rp); } } foreach (ReportPeriod rp in reportPeriods) { // Create a list of loaded report period IDs for later use if (!selectedReportPeriodIDs.Contains(rp.ID)) { selectedReportPeriodIDs.Add(rp.ID); } // Find the earliest report period and the last report period, for attendance dates if (rp.startDate < earliestDate) { earliestDate = rp.startDate; } if (rp.endDate > lastDate) { lastDate = rp.endDate; } // Derive some terms from the given report periods while we are cycling through them if (!detectedTermIDs.Contains(rp.termID)) { detectedTermIDs.Add(rp.termID); } } // ************************************************************** // * Terms // ************************************************************** // Derive some terms from the given report periods while we are cycling through them List <Term> detectedTerms = new List <Term>(); foreach (int termid in detectedTermIDs) { detectedTerms.Add(Term.loadThisTerm(connection, termid)); } foreach (Term term in detectedTerms) { foreach (ReportPeriod rp in reportPeriods) { // Put report periods into their respective terms if (rp.termID == term.ID) { term.ReportPeriods.Add(rp); } // Determine the final report period in a term, and assign it appropriately if it was loaded if ( (rp.endDate.Year == term.endDate.Year) && (rp.endDate.Month == term.endDate.Month) && (rp.endDate.Day == term.endDate.Day) ) { term.FinalReportPeriod = rp; } } } if (returnedStudent != null) { // ************************************************************** // * Load student data // ************************************************************** // Load all outcome marks (which will also load the outcomes themselves). We will filter this list by class later List <OutcomeMark> studentOutcomeMarks_All = OutcomeMark.loadOutcomeMarksForThisStudent(connection, reportPeriods, returnedStudent); returnedStudent.school = School.loadThisSchool(connection, thisStudent.getSchoolIDAsInt()); returnedStudent.track = Track.loadThisTrack(connection, returnedStudent.getTrackID()); returnedStudent.track.terms = detectedTerms; // Marks List <Mark> studentMarks_All = Mark.loadMarksFromTheseReportPeriods(connection, reportPeriods, returnedStudent); // ************************************************************** // * Attendance // ************************************************************** // Load this student's attendance returnedStudent.absences = Absence.loadAbsencesForThisStudentAndTimePeriod(connection, thisStudent, earliestDate, lastDate); foreach (Term thisTerm in returnedStudent.track.terms) { // ************************************************************** // * Enrolled Classes // ************************************************************** // Load classes this student is enrolled in thisTerm.Courses = SchoolClass.loadStudentEnrolledClassesForThisTerm(connection, returnedStudent, thisTerm); foreach (SchoolClass thisClass in thisTerm.Courses) { thisClass.term = thisTerm; // Put list of report periods into each class so we can easily reference it later thisClass.ReportPeriods = reportPeriods; // ************************************************************** // * Outcomes and Life Skills (or SLBs / Successful Learner Behaviors) // ************************************************************** string lifeSkillsCategoryName = "Successful Learner Behaviours"; // From the main list of this student's outcome marks, select just the ones for this course //List<OutcomeMark> classOutcomeMarks_All = OutcomeMark.loadOutcomeMarksForThisCourse(connection, thisTerm, returnedStudent, thisClass); List <OutcomeMark> classOutcomeMarks_All = new List <OutcomeMark>(); foreach (OutcomeMark om in studentOutcomeMarks_All) { if (om.courseID == thisClass.courseid) { classOutcomeMarks_All.Add(om); } } // Split marks into life skills and not life skills List <Outcome> classNormalOutcomes = new List <Outcome>(); List <Outcome> classLifeSkills = new List <Outcome>(); List <OutcomeMark> classMarks_LifeSkills = new List <OutcomeMark>(); List <OutcomeMark> classMarks_Outcomes = new List <OutcomeMark>(); foreach (OutcomeMark om in classOutcomeMarks_All) { // Associate some of the loaded report period objects with the outcome marks foreach (ReportPeriod rp in reportPeriods) { if (rp.ID == om.reportPeriodID) { om.reportPeriod = rp; } } // Split marks into life skills and not life skills lists if (om.outcome.category == lifeSkillsCategoryName) { classMarks_LifeSkills.Add(om); classLifeSkills.Add(om.outcome); } else { classMarks_Outcomes.Add(om); // While we are iterating through the list, derive a list of outcomes from the outcome marks, since we didn't load one earlier // Check to see if this outcome exists already bool outcomeExists = false; foreach (Outcome o in classNormalOutcomes) { if (o.id == om.outcome.id) { outcomeExists = true; o.marks.Add(om); } } if (!outcomeExists) { classNormalOutcomes.Add(om.outcome); } } } // Put the outcomes and outcome marks into the course object thisClass.Outcomes = classNormalOutcomes; thisClass.LifeSkills = classLifeSkills; thisClass.OutcomeMarks = classMarks_Outcomes; thisClass.LifeSkillMarks = classMarks_LifeSkills; } // ************************************************************** // * Class marks and comments // ************************************************************** foreach (Mark m in studentMarks_All) { foreach (SchoolClass c in thisTerm.Courses) { if (m.classID == c.classid) { c.Marks.Add(m); } } } } } return(returnedStudent); }
public static List <Absence> loadAbsencesForThisDate(SqlConnection connection, DateTime date) { List <Absence> returnMe = new List <Absence>(); SqlCommand sqlCommand = new SqlCommand(); sqlCommand.Connection = connection; sqlCommand.CommandType = CommandType.Text; StringBuilder SQL = new StringBuilder(); /* Load all attendance blocks, so we can reference them */ List <AttendanceBlock> blocks = AttendanceBlock.loadAllAttendanceBlocks(connection); SQL.Append("SELECT * FROM LSKY_Attendance WHERE dDate='" + date.Year + "-" + date.Month + "-" + date.Day + " 00:00:00' ORDER BY dDate ASC, block ASC;"); sqlCommand.CommandText = SQL.ToString(); sqlCommand.Connection.Open(); SqlDataReader dataReader = sqlCommand.ExecuteReader(); if (dataReader.HasRows) { while (dataReader.Read()) { Absence newAbsence = new Absence( DateTime.Parse(dataReader["dDate"].ToString()), int.Parse(dataReader["iTrackID"].ToString().Trim()), dataReader["StudentNumber"].ToString().Trim(), dataReader["ClassName"].ToString().Trim(), dataReader["ClassID"].ToString().Trim(), dataReader["Status"].ToString().Trim(), dataReader["Reason"].ToString().Trim(), dataReader["Comment"].ToString().Trim(), int.Parse(dataReader["Block"].ToString()), int.Parse(dataReader["Minutes"].ToString()), parseExcused(dataReader["lExcusable"].ToString()) ); newAbsence.period = newAbsence.getBlock().ToString(); foreach (AttendanceBlock atBlock in blocks) { if (atBlock.block == newAbsence.block) { if (atBlock.track == newAbsence.track) { newAbsence.period = atBlock.name; newAbsence.attendanceBlock = atBlock; } } } returnMe.Add(newAbsence); } } sqlCommand.Connection.Close(); foreach (Absence abs in returnMe) { } return(returnMe); }
public void addAbsence(Absence thisAbs) { this.absences.Add(thisAbs); }