// method to add a student to the list and also to the tf public void addStudent() { String studentType = ""; String fName = ""; String lName = ""; String stuId = ""; System.Console.WriteLine("Would you like to add a Full Time student [F] or Distant student [D]? (Enter in F or D)"); studentType = Console.ReadLine(); while (!(studentType.Equals("F") || studentType.Equals("D"))) { System.Console.WriteLine("Please select 'F' for full time student or 'D' for distant student. "); studentType = Console.ReadLine(); } System.Console.Write("Student first name >>"); fName = Console.ReadLine(); System.Console.Write("Student last name >>"); lName = Console.ReadLine(); System.Console.Write("Student ID >>"); stuId = Console.ReadLine(); switch (studentType) { case "F": String campus = ""; System.Console.Write("Campus >>"); campus = Console.ReadLine(); FullTime newFullTime = new FullTime(fName, lName, stuId, campus); tfWorker.writeStudentToFile(newFullTime); lstFullTime.Add(newFullTime); break; case "D": String facilitator = ""; System.Console.Write("Facilitator >>"); facilitator = Console.ReadLine(); Distant newDistant = new Distant(fName, lName, stuId, facilitator); tfWorker.writeStudentToFile(newDistant); lstDistant.Add(newDistant); break; } }
// reads the values from the textfile public void readInValues() { string line; FullTime fullTime = new FullTime(); Distant distant = new Distant(); try { StreamReader file = new StreamReader("Students.txt"); while ((line = file.ReadLine()) != null) { var lineParts = line.Split('|'); if (lineParts[0].ElementAt(0).Equals('F')) { fullTime = new FullTime(lineParts[1], lineParts[2], lineParts[0], lineParts[3]); lstFullTime.Add(fullTime); } else if (lineParts[0].ElementAt(0).Equals('D')) { distant = new Distant(lineParts[1], lineParts[2], lineParts[0], lineParts[3]); lstDistant.Add(distant); } } file.Close(); } catch (FileNotFoundException) { StreamWriter sw = new StreamWriter("Students.txt"); sw.Close(); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } }