Esempio n. 1
0
        public static Employee LoadEmployeeInformation(string[] lines, ref int index)
        {
            Employee employee = new Employee();
            var assembly = Assembly.GetExecutingAssembly();
            var userType = assembly.GetType("GarageManagementSystem.Employee");
            int propertiesCount = Service.PropertiesCount(employee); // Get the number of properties

            for (int i = 0; i < propertiesCount; i++, index++)
            {
                var property = userType.GetProperty(lines[index]);
                index++;

                if (property.Name == "Address")
                {
                    if (lines[index] != "-")
                    {
                        index++;
                        Address address = Address.LoadAddressInformation(lines, ref index);
                        property.SetValue(employee, address, null);
                    }
                }
                else if (property.Name == "Position")
                {
                    if (lines[index] != "-")
                    {
                        var currentPropertyType = property.PropertyType;
                        Position position = (Position)Enum.Parse(typeof(Position), lines[index], false);
                        property.SetValue(employee, position, null);
                    }
                }
                else
                {
                    if (lines[index] != "-")
                    {
                        var currentPropertyType = property.PropertyType;
                        var convertedValue = Convert.ChangeType(lines[index], currentPropertyType, null);
                        property.SetValue(employee, convertedValue, null);
                    }
                }
            }

            return employee;
        }
Esempio n. 2
0
 public void RemoveEmployee(Employee employee)
 {
     this.employees.Remove(employee);
 }
Esempio n. 3
0
 public void AddEmployee(Employee employee)
 {
     this.employees.Add(employee);
 }
Esempio n. 4
0
        public static string SaveEmployeeInformation(Employee employee)
        {
            StringBuilder builder = new StringBuilder();

            var assembly = Assembly.GetExecutingAssembly();

            var employeeProperties = assembly.GetType("GarageManagementSystem.Employee").GetProperties();

            foreach (var property in employeeProperties)
            {
                if (property.Name == "Address")
                {
                    builder.AppendLine("Address");
                    if (employee.Address == null)
                    {
                        builder.AppendLine("-");
                    }
                    else
                    {
                        builder.AppendLine("1");
                        builder.Append(Address.SaveAddressInformation(employee.Address));
                    }
                }
                else
                {
                    builder.AppendLine(property.Name);
                    try
                    {
                        builder.AppendLine(property.GetValue(employee, null).ToString());
                    }
                    catch (NullReferenceException)
                    {
                        builder.AppendLine("-");
                    }
                }
            }

            return builder.ToString();
        }