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;
        }
Example #2
0
        public void AddToEnd(Employee data)
        {
            if (next == null) {
                next = new Node(data);
                next.previous = this;

            } else {
                next.AddToEnd(data);
            }
        }
Example #3
0
        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);
            }
        }
Example #4
0
 public Node(Employee data)
 {
     this.data = data;
     this.next = null;
     this.previous = null;
 }