Example #1
0
        public static Employee.Employee GetSerializedEmployee(int id)
        {
            Stream          s = File.Open(fileLocationSerial + $"\\{id}.ser", FileMode.Open);
            BinaryFormatter binaryFormatter = new BinaryFormatter();

            Employee.Employee e = (Employee.Employee)binaryFormatter.Deserialize(s);
            s.Close();

            return(e);
        }
Example #2
0
        public static void PrintEmployees(string path)
        {
            string text = File.ReadAllText(path);

            string[] words = text.Split(',');
            Int32.TryParse(words[0], out int id);
            Int32.TryParse(words[3], out int year);

            Employee.Employee emp = new Employee.Employee(id, words[1], words[2], year);
            Console.WriteLine(emp.ToString());
        }
Example #3
0
        public static void PrintSerializedDetails(string path)
        {
            BinaryFormatter binaryFormatter = new BinaryFormatter();
            var             files           = Directory.GetFiles(path);

            foreach (var f in files)
            {
                Stream            s = File.Open(f, FileMode.Open);
                Employee.Employee e = (Employee.Employee)binaryFormatter.Deserialize(s);
                Console.WriteLine(e.ToString());
            }
        }
Example #4
0
        public static Dictionary <int, Employee.Employee> getAllEmployees(string path)
        {
            Dictionary <int, Employee.Employee> employees = new Dictionary <int, Employee.Employee>();


            BinaryFormatter binaryFormatter = new BinaryFormatter();
            var             files           = Directory.GetFiles(path);

            foreach (var f in files)
            {
                Stream            s = File.Open(f, FileMode.Open);
                Employee.Employee e = (Employee.Employee)binaryFormatter.Deserialize(s);
                employees.Add(e.Id, e);
            }


            return(employees);
        }
Example #5
0
        public static Employee.Employee FindEmployeeById(int id)
        {
            Employee.Employee emp = new Employee.Employee(0, "N/A", "N/A", 0);
            var files             = Directory.GetFiles(fileLocation);

            foreach (var f in files)
            {
                if (Path.GetFileName(f) == id + ".txt")
                {
                    string   text  = File.ReadAllText(f);
                    string[] words = text.Split(',');
                    Int32.TryParse(words[3], out int year);

                    emp = new Employee.Employee(id, words[1], words[2], year);
                }
            }
            return(emp);
        }
Example #6
0
        public static Employee.Employee FindEmployeeByLastName(string lastName)
        {
            Employee.Employee emp = new Employee.Employee(0, "N/A", "N/A", 0);
            var files             = Directory.GetFiles(fileLocation);

            foreach (var f in files)
            {
                string   text  = File.ReadAllText(f);
                string[] words = text.Split(',');
                if (lastName.ToLower().Equals(words[2].ToLower().Trim()))
                {
                    Int32.TryParse(words[3], out int id);
                    Int32.TryParse(words[3], out int year);
                    emp = new Employee.Employee(id, words[1], words[2], year);
                    break;
                }
            }
            return(emp);
        }
Example #7
0
        public static List <Employee.Employee> FindAllEmployeesByLastName(string lastName)
        {
            List <Employee.Employee> empList = new List <Employee.Employee>();

            var files = Directory.GetFiles(fileLocation);

            foreach (var f in files)
            {
                string   text  = File.ReadAllText(f);
                string[] words = text.Split(',');
                if (lastName.ToLower().Equals(words[2].ToLower().Trim()))
                {
                    Int32.TryParse(words[0], out int id);
                    Int32.TryParse(words[3], out int year);
                    Employee.Employee emp = new Employee.Employee(id, words[1], words[2], year);
                    empList.Add(emp);
                }
            }
            return(empList);
        }
Example #8
0
        public static void SerializeAllEmployees()
        {
            //DataContractSerializer ser = new DataContractSerializer(typeof(Employee.Employee));
            BinaryFormatter binaryFormatter = new BinaryFormatter();

            var files = Directory.GetFiles(fileLocation);

            foreach (var f in files)
            {
                string   text  = File.ReadAllText(f);
                string[] words = text.Split(',');
                Int32.TryParse(words[0], out int id);
                Int32.TryParse(words[3], out int year);

                Employee.Employee emp = new Employee.Employee(id, words[1], words[2], year);
                Stream            s   = File.Open(fileLocationSerial + $"\\{id}.ser", FileMode.Create);
                binaryFormatter.Serialize(s, emp);
                Console.WriteLine($"Serialized employee ID: {id}");
                s.Close();
            }
        }