Exemple #1
0
    static void Main(string[] args)
    {
        Paths          path         = new Paths();
        DateTimeFormat dateTimeForm = new DateTimeFormat();

        string file = path.GetFile();

        //Prompts the user to select the desired DateTime format:
        string dateTimeFormatString = dateTimeForm.GetDateTimeFormatFromUser();

        try
        {
            List <Employee> allEmployees = ReadEmployeeAssignments(file, dateTimeFormatString);

            List <Employee> employeesResult = new List <Employee>();
            double          count           = 0.0;

            for (int i = 0; i < allEmployees.Count; i++)
            {
                for (int j = i + 1; j < allEmployees.Count; j++)
                {
                    if (i == j)
                    {
                        continue;
                    }
                    if (allEmployees[i].ProjectID == allEmployees[j].ProjectID)
                    {
                        if (allEmployees[i].DateFrom < allEmployees[j].DateTo && allEmployees[j].DateFrom < allEmployees[i].DateTo)
                        {
                            var overlappingDays = GetOverlappingDays(allEmployees[i].DateFrom, allEmployees[i].DateTo, allEmployees[j].DateFrom, allEmployees[j].DateTo);

                            if (overlappingDays > count)
                            {
                                employeesResult.Add(allEmployees[i]);
                                employeesResult.Add(allEmployees[j]);
                                count = overlappingDays;
                            }
                        }
                    }
                }
            }

            foreach (var employee in employeesResult)
            {
                Console.Write($"Employee: {employee.EmployeeID}, Working on project: {employee.ProjectID} From: {employee.DateFrom.ToString(dateTimeFormatString)} Untill: {employee.DateTo.ToString(dateTimeFormatString)}");
                Console.WriteLine();
            }
            Console.WriteLine($"Both employees worked together on the same project a total of {count} days.");
        }
        catch (FormatException ex)
        {
            Console.WriteLine("The file that was specified contains date formats different than the selected one. Please run the program again and select compatible file and date format!");
        }
    }