示例#1
0
 public Report(Ticket[] tickets)
 {
     if (tickets.Length == 0)
     {
         return;
     }
     Tickets = tickets.Select(ticket => new TicketResult
     {
         ExecutionTime = ticket.ExecutionTime,
         Report        = this,
         Title         = ticket.Title,
         Id            = ticket.Id,
         Status        = ticket.Status.ToString()
     }).ToArray();
     AverageExecutionTime = new TimeSpan(Convert.ToInt64(Tickets.Average(result => result.ExecutionTime.Ticks)));
 }
示例#2
0
        static void Main(string[] args)
        {
            //1

            // проверка
            //var costs = Tickets.Select(c => c);
            //foreach (var item in costs)
            //{
            //    Console.Write(item.Cost + " ");
            //}
            Console.WriteLine("Пункт первый: ");
            var average = Tickets.Average(ticket => ticket.Cost);

            Console.WriteLine($"Среднее стоимость билета: {average} рублей");
            Console.WriteLine("1.1");
            var average1 = (from ticket in Tickets
                            select ticket.Cost).Average();

            Console.WriteLine($"Среднее стоимость билета: {average1} рублей");

            //2

            //проверка
            //var planes = Planes.Select(p => p);
            //foreach (var item in planes)
            //{
            //    Console.Write(item.Capacity + " ");
            //}
            Console.WriteLine("Пункт второй: ");
            int n            = 150;
            var countPlanes  = Planes.Where(plane => plane.Capacity > n).Count();
            var countPlanes1 = (from plane in Planes
                                where plane.Capacity > n
                                select plane).Count();

            Console.WriteLine($"Количество самолетов с вместимостью больше {n} человек: {countPlanes}");
            Console.WriteLine("2.1");
            Console.WriteLine($"Количество самолетов с вместимостью больше {n} человек: {countPlanes1}");

            //3
            Console.WriteLine("Пункт третий: ");

            var informationFlight = from flight in Flights
                                    join flightCrew in FlightCrews on flight.Id equals flightCrew.FlightId
                                    join employee in Employees on flightCrew.EmployeeId equals employee.Id
                                    select new
            {
                flight.Id,
                flight.PlaneId,
                flight.AirportArrivalId,
                flight.AirportDepartureId,
                flight.ArrivalDate,
                flight.DepartureDate,
                IdCrew       = flightCrew.Id,
                employeeName = employee.LastName
            };

            foreach (var fullFlight in informationFlight)
            {
                Console.WriteLine($"Id рейса: {fullFlight.Id}, модель самолета: {fullFlight.PlaneId}");
                Console.WriteLine($"Дата прибытия: {fullFlight.ArrivalDate}, Аэропорт прибытия: {fullFlight.AirportArrivalId}");
                Console.WriteLine($"Дата отбытия: {fullFlight.DepartureDate}, Аэропорт отбытия: {fullFlight.AirportArrivalId}");
                Console.WriteLine($"Id экипажа: {fullFlight.IdCrew}, Сотрудник: {fullFlight.employeeName}");
            }

            Console.WriteLine("3.1");
            var informationFlight1 = Flights.Join(FlightCrews, f => f.Id, c => c.FlightId, (f, c) => new
            {
                f.Id,
                f.PlaneId,
                f.AirportArrivalId,
                f.AirportDepartureId,
                f.ArrivalDate,
                f.DepartureDate,
                IdCrew = c.Id
            }).Join(Employees, f => f.IdCrew, e => e.Id, (f, e) => new
            {
                f.Id,
                f.PlaneId,
                f.AirportArrivalId,
                f.AirportDepartureId,
                f.ArrivalDate,
                f.DepartureDate,
                f.IdCrew,
                e.LastName
            });

            foreach (var fullFlight in informationFlight1)
            {
                Console.WriteLine($"Id рейса: {fullFlight.Id}, модель самолета: {fullFlight.PlaneId}");
                Console.WriteLine($"Дата прибытия: {fullFlight.ArrivalDate}, Аэропорт прибытия: {fullFlight.AirportArrivalId}");
                Console.WriteLine($"Дата отбытия: {fullFlight.DepartureDate}, Аэропорт отбытия: {fullFlight.AirportArrivalId}");
                Console.WriteLine($"Id экипажа: {fullFlight.IdCrew}, Сотрудник: {fullFlight.LastName}");
            }
            //4
            Console.WriteLine("Пункт четвертый:");
            var fullEmployee = from employee in Employees
                               join position in Positions on employee.PositionId equals position.Id
                               select new
            {
                employee.Id,
                employee.FirstName,
                employee.LastName,
                employee.WorkExperience,
                positionName = position.Name
            };

            foreach (var employee in fullEmployee)
            {
                Console.WriteLine($"Id сотрудника: {employee.Id}, Полное имя сотрудника: {employee.FirstName}" +
                                  $"{employee.LastName}, Стаж работы: {employee.WorkExperience} лет, Занимаемая должность: {employee.positionName}");
            }
            Console.WriteLine("4.1");
            var fullEmployee1 = Employees.Join(Positions, e => e.PositionId, f => f.Id, (e, f) => new
            {
                e.Id,
                e.FirstName,
                e.LastName,
                e.WorkExperience,
                f.Name
            });

            foreach (var employee in fullEmployee1)
            {
                Console.WriteLine($"Id сотрудника: {employee.Id}, Полное имя сотрудника: {employee.FirstName}" +
                                  $"{employee.LastName}, Стаж работы: {employee.WorkExperience} лет, Занимаемая должность: {employee.Name}");
            }
            //5
            Console.WriteLine("Пункт пятый:");
            DateTime actulTime     = new DateTime(2020, 06, 30);
            var      sortedClients = from client in Clients
                                     join ticket in Tickets on client.Id equals ticket.ClientId
                                     join flight in Flights on ticket.FlightId equals flight.Id
                                     orderby client.BirthDate
                                     select new
            {
                client.Id,
                client.FirstName,
                client.LastName,
                ticketId = ticket.Id,
                flight.DepartureDate,
                client.BirthDate
            };

            var clientWithTickets = from client in sortedClients
                                    where client.DepartureDate > actulTime
                                    select client;

            foreach (var client in clientWithTickets)
            {
                Console.WriteLine($"Id пассажира: {client.Id}, Полное имя: {client.FirstName} {client.LastName}" +
                                  $", Дата рождения: {client.BirthDate}, Дата отбытия: {client.DepartureDate}");
            }
            Console.WriteLine("5.1");
            var clientWithTickets1 = Clients.Join(Tickets, s => s.Id, t => t.ClientId, (s, t) => new
            {
                s.Id,
                s.FirstName,
                s.LastName,
                ticketId = t.Id,
                t.FlightId,
                s.BirthDate
            }).Join(Flights, s => s.FlightId, f => f.Id, (s, f) => new
            {
                s.Id,
                s.FirstName,
                s.LastName,
                ticketId = s.Id,
                s.BirthDate,
                f.DepartureDate
            }).OrderBy(s => s.BirthDate).Where(s => s.DepartureDate > actulTime);

            foreach (var client in clientWithTickets1)
            {
                Console.WriteLine($"Id пассажира: {client.Id}, Полное имя: {client.FirstName} {client.LastName}" +
                                  $", Дата рождения: {client.BirthDate}, Дата отбытия: {client.DepartureDate}");
            }

            //6
            Console.WriteLine("Пункт шестой: ");
            var sortedPlanes = from plane in Planes
                               orderby plane.FlightHours, plane.IssueYear, plane.Capacity
            select plane;

            foreach (var plane in sortedPlanes)
            {
                Console.WriteLine($"Id самолета: {plane.Id}, Количество часов в полете: {plane.FlightHours}" +
                                  $", Год выпуска: {plane.IssueYear}, Вместимость самолета: {plane.Capacity}");
            }
            Console.WriteLine("6.1");
            var sortedPlanes1 = Planes.OrderBy(p => p.FlightHours).ThenBy(p => p.IssueYear).ThenBy(p => p.Capacity);

            foreach (var plane in sortedPlanes1)
            {
                Console.WriteLine($"Id самолета: {plane.Id}, Количество часов в полете: {plane.FlightHours}" +
                                  $", Год выпуска: {plane.IssueYear}, Вместимость самолета: {plane.Capacity}");
            }
            //7
            Console.WriteLine("Пункт седьмой:");
        }