public void addPrevCourses(ref courseDatabase crsDB, string nextSemester) { string line; System.IO.StreamReader input = new System.IO.StreamReader(@"..\..\historyDB.in"); while ((line = input.ReadLine()) != null) { string username = line.Substring(0, 10).Trim().ToLower(); // Needed ToLower() string courseNumStr = line.Substring(11, 2).Trim(); int courseNum = int.Parse(courseNumStr); int loc = 14; student std = stdLst.Find(s => s.username.Trim() == username); for (int i = 0; i < courseNum; i++) { string crsID = line.Substring(loc, 10).Trim(); loc += 11; string semester = line.Substring(loc, 3).Trim(); loc += 4; string creditStr = line.Substring(loc, 4).Trim(); float credit = float.Parse(creditStr); loc += 4; string grade; if ((line.Length - loc) >= 3) { grade = line.Substring(loc, 3).Trim().ToString(); } else { grade = line.Substring(loc).Trim().ToString(); } loc += 5; if (semester == nextSemester) { course crs = crsDB.getCourse(crsID); std.addClassToNext(crs); crs.enrollUser(std); } else if (semester == "F14") { previousCourse pcrs = new previousCourse(username, crsID, semester, credit, grade); std.addClassToCurrent(pcrs); } else { previousCourse currentCourse = new previousCourse(username, crsID, semester, credit, grade); std.addClassToPast(currentCourse); } } } input.Close(); foreach (student std in stdLst) { std.calculateGPA(); } }
// Change the database //---------------------------------------- public void addCrsToStd(string crsID, string nextSemester, ref courseDatabase crsDB, student currentStudent) { foreach (course crs in crsDB.getCourseList()) { if (crsID.Trim() == crs.crsID.Trim()) { course selectedCourse = crs; selectedCourse.enrollUser(currentStudent); course courseAdding = selectedCourse; currentStudent.addClassToNext(courseAdding); return; } } }