コード例 #1
0
        public static BaseEmployee GetFromString(string line)
        {
            string[] splitedData = line.Split(';');

            if (splitedData.Length != 4)
            {
                throw new Exception("Строка имеет неверный формат");
            }

            BaseEmployee employee = default;

            string lineId     = splitedData[0].Substring(splitedData[0].IndexOf(":") + 1);
            string lineName   = splitedData[1].Substring(splitedData[1].IndexOf(":") + 1);
            string lineSalary = splitedData[2].Substring(splitedData[2].IndexOf(":") + 1);
            string lineType   = splitedData[3].Substring(splitedData[3].IndexOf(":") + 1);

            if (lineType == FixedEmployee.EMPLOYEE_TYPE_NAME)
            {
                employee = new FixedEmployee();
            }
            else
            {
                employee = new HourlyEmployee();
            }

            employee.Id     = int.Parse(lineId);
            employee.Name   = lineName;
            employee.Salary = double.Parse(lineSalary);

            return(employee);
        }
コード例 #2
0
        private static void GenerateEmployees()
        {
            employeeList.Clear();
            Random random = new Random(DateTime.Now.Millisecond);

            int count = random.Next(10, 20);

            for (int i = 0; i < count; i++)
            {
                BaseEmployee employee;
                bool         isHourlyEmployee = random.Next(10) > 4;
                bool         isNeedDuplicate  = random.Next(10) < 3;

                if (isHourlyEmployee)
                {
                    employee = new HourlyEmployee();
                }
                else
                {
                    employee = new FixedEmployee();
                }

                employee.Id     = i;
                employee.Name   = RandomString(random.Next(5, 11), new Random(i));
                employee.Salary = isNeedDuplicate ? 150.55 : Math.Round(random.NextDouble() * random.Next(150, 480), 2);

                employeeList.Add(employee);
            }
        }