public static List<Employee> LoadEntries() { List<Employee> list = null; try { using (FileStream fileStream = new FileStream(inputFile, FileMode.Open, FileAccess.Read)) { using (StreamReader reader = new StreamReader(fileStream)) { //Populate List from lines in file list = new List<Employee>(); while (reader.Peek() != -1) { Employee employee = new Employee(); for (int i = 0; i <= 3; i++) { string line; if (reader.Peek() != -1) { line = reader.ReadLine(); } else { break; } switch (i) { case 0: employee.firstName = line; break; case 1: employee.lastName = line; break; case 2: employee.employeeID = Convert.ToInt32(line.Substring(2)); break; case 3: employee.department = line; break; } } list.Add(employee); if (reader.Peek() != -1) { reader.ReadLine(); } } } } } catch (FileNotFoundException) { MessageBox.Show("File not found: " + inputFile, "File Error"); } catch (DirectoryNotFoundException) { MessageBox.Show("Directory not found: " + inputDir, "Directory Error"); } catch (IOException ex) { MessageBox.Show(ex.GetType() + ": " + ex.Message, "IOException"); } return list; }
public void AddToEnd(Employee data) { if (next == null) { next = new Node(data); next.previous = this; } else { next.AddToEnd(data); } }
public void AddSortedByID(Employee data) { if (next == null) { next = new Node(data); } else if (data.employeeID < next.data.employeeID) { Node temp = new Node(data); temp.next = this.next; temp.previous = this; this.next.previous = temp; this.next = temp; } else { next.AddSortedByID(data); } }
public Node(Employee data) { this.data = data; this.next = null; this.previous = null; }