예제 #1
0
        /// <summary>Get current schedule based on airport and date with checkin information</summary>
        /// <cardinality>Many</cardinality>
        public List <FlightsWithCheckinInformationData> FlightsWithCheckinInformation(
            Guid departureAirportId,
            Guid arrivalAirportId,
            DateTime fromDateTime,
            DateTime untilDateTime
            )
        {
            var ret = new List <FlightsWithCheckinInformationData>();

            string sql = @" 
                    select 
                         fl.flight_id   
						,ai.airline_identifier_code
						,fi.flight_identifier_code			    as flight_number
	                    ,dai.airport_identifier_code		    as departure_airport_identifier_code
	                    ,da.airport_name					    as departure_airport_name
	                    ,aai.airport_identifier_code		    as arrival_airport_identifier_code
	                    ,aa.airport_name					    as arrival_airport_name
	                    ,fl.from_date_time
	                    ,fl.until_date_time
						,(	select count(*)
							from flight_segment					as fs
							inner join booking_flight_segment	as bfs	on	bfs.flight_segment_id = fs.flight_segment_id
																		and bfs.became_booking_flight_segment_id is null
							inner join booking_passenger		as bp	on	bp.booking_id = bfs.booking_id
																		and bp.became_booking_passenger_id is null
							where fs.flight_id = fl.flight_id
							)									as passengers_booked_count
						,(	select count(*)
							from flight_segment					as fs
							inner join booking_flight_segment	as bfs	on	bfs.flight_segment_id = fs.flight_segment_id
																		and bfs.became_booking_flight_segment_id is null
							inner join booking_passenger		as bp	on	bp.booking_id = bfs.booking_id
																		and bp.became_booking_passenger_id is null
							inner join passenger				as p	on	p.passenger_id = bp.passenger_id
																		and p.passenger_type_rcd = dbo.ref('passenger_type_ref.AD')
							where fs.flight_id = fl.flight_id
							)									as adult_booked_count
						,(	select count(*)
							from flight_segment					as fs
							inner join booking_flight_segment	as bfs	on	bfs.flight_segment_id = fs.flight_segment_id
																		and bfs.became_booking_flight_segment_id is null
							inner join booking_passenger		as bp	on	bp.booking_id = bfs.booking_id
																		and bp.became_booking_passenger_id is null
							inner join passenger				as p	on	p.passenger_id = bp.passenger_id
																		and p.passenger_type_rcd = dbo.ref('passenger_type_ref.CHD')
							where fs.flight_id = fl.flight_id
							)									as child_booked_count
						,(	select count(*)
							from flight_segment					as fs
							inner join booking_flight_segment	as bfs	on	bfs.flight_segment_id = fs.flight_segment_id
																		and bfs.became_booking_flight_segment_id is null
							inner join booking_passenger		as bp	on	bp.booking_id = bfs.booking_id
																		and bp.became_booking_passenger_id is null
							inner join passenger				as p	on	p.passenger_id = bp.passenger_id
																		and p.passenger_type_rcd = dbo.ref('passenger_type_ref.INF')
							where fs.flight_id = fl.flight_id
							)									as infant_booked_count
	                    ,(	select
								top 1 dttr.date_time_type_name
							from  flight_event				    as fe
							inner join date_time_type_ref	    as dttr on dttr.date_time_type_rcd = fe.date_time_type_rcd
							where fe.flight_id = fl.flight_id
							order by fe.date_time desc
							)								    as last_date_time_type_name
	                    ,(	select
								top 1 fe.new_date_time
							from  flight_event				    as fe
							where	fe.flight_id = fl.flight_id
								and fe.date_time_type_rcd = dbo.ref('date_time_type_ref.PD')
							order by fe.date_time desc
							)								    as planned_departure_date_time
	                    ,(	select
								top 1 fe.new_date_time
							from  flight_event				    as fe
							where	fe.flight_id = fl.flight_id
								and fe.date_time_type_rcd = dbo.ref('date_time_type_ref.ED')
							order by fe.date_time desc
							)								    as estimated_departure_date_time

                    from flight                                 as fl
	                inner join airline_identifier	            as ai	on ai.airline_id = fl.airline_id
													                    and ai.airline_identifier_type_rcd = dbo.ref('airline_identifier_type_ref.AC3')
                    inner join airport				            as da	on da.airport_id = fl.departure_airport_id
                    inner join airport				            as aa	on aa.airport_id = fl.arrival_airport_id
                    inner join airport_identifier	            as dai	on dai.airport_id = fl.departure_airport_id
										                                and dai.airport_identifier_type_rcd = dbo.ref('airport_identifier_type_ref.AC3')
                    inner join airport_identifier	            as aai	on aai.airport_id = fl.arrival_airport_id
										                                and aai.airport_identifier_type_rcd = dbo.ref('airport_identifier_type_ref.AC3')
	                 left join flight_identifier	            as fi	on fi.flight_id = fl.flight_id
															            and fi.flight_identifier_type_rcd = dbo.ref('flight_identifier_type_ref.FN3')
                    
                    --realwhere

                    where fl.from_date_time between @from_date_time and @until_date_time
                      and fl.became_flight_id is null
					  and dbo.FlightEventOneIsLast(
								fl.flight_id, 
								dbo.ref('date_time_type_ref.CO'), 
								dbo.ref('date_time_type_ref.CC')
								) = 1
                ";

            if (departureAirportId != Guid.Empty)
            {
                sql += "                      and fl.departure_airport_id = @departure_airport_id\r\n";
            }

            if (arrivalAirportId != Guid.Empty)
            {
                sql += "                      and fl.arrival_airport_id = @arrival_airport_id\r\n";
            }

            sql += "                    order by fl.from_date_time\r\n";

            using (var conn = new SqlConnection(Conn.ConnectionString)) {
                conn.Open();
                conn.BeginTransaction(IsolationLevel.ReadUncommitted).Commit();

                using (var command = new SqlCommand(sql, conn)) {
                    command.Parameters.Add("@departure_airport_id", SqlDbType.UniqueIdentifier).Value = departureAirportId;
                    command.Parameters.Add("@arrival_airport_id", SqlDbType.UniqueIdentifier).Value   = arrivalAirportId;
                    command.Parameters.Add("@from_date_time", SqlDbType.DateTime).Value  = fromDateTime;
                    command.Parameters.Add("@until_date_time", SqlDbType.DateTime).Value = untilDateTime;

                    Logging log = Logging.PerformanceTimeStart("SolutionNorSolutionPort.DataAccessLayer.FlightSearch.FlightsWithCheckinInformation");

                    IDataReader reader = command.ExecuteReader(CommandBehavior.SingleResult);

                    log.PerformanceTimeStop(sql, command);

                    var ordinals = new FlightsWithCheckinInformationDataOrdinals(reader);

                    while (reader.Read())
                    {
                        var data = new FlightsWithCheckinInformationData();
                        data.Populate(reader, ordinals);
                        ret.Add(data);
                    }

                    reader.Close();
                }

                return(ret);
            }
        }
 // use ordinals to speed up access to DataReader
 // links:
 //  crud definition: https://en.wikipedia.org/wiki/Create,_read,_update_and_delete
 //  docLink: http://sql2x.org/documentationLink/327451c3-64a8-4de8-b359-76742d634497
 // parameters:
 //  reader: IDataReader from SQLClient
 public void Populate(IDataReader reader, FlightsWithCheckinInformationDataOrdinals ordinals)
 {
     if (!reader.IsDBNull(ordinals.FlightId))
     {
         FlightId = reader.GetGuid(ordinals.FlightId);
     }
     if (!reader.IsDBNull(ordinals.AirlineIdentifierCode))
     {
         AirlineIdentifierCode = reader.GetString(ordinals.AirlineIdentifierCode);
     }
     if (!reader.IsDBNull(ordinals.FlightNumber))
     {
         FlightNumber = reader.GetString(ordinals.FlightNumber);
     }
     if (!reader.IsDBNull(ordinals.DepartureAirportIdentifierCode))
     {
         DepartureAirportIdentifierCode = reader.GetString(ordinals.DepartureAirportIdentifierCode);
     }
     if (!reader.IsDBNull(ordinals.DepartureAirportName))
     {
         DepartureAirportName = reader.GetString(ordinals.DepartureAirportName);
     }
     if (!reader.IsDBNull(ordinals.ArrivalAirportIdentifierCode))
     {
         ArrivalAirportIdentifierCode = reader.GetString(ordinals.ArrivalAirportIdentifierCode);
     }
     if (!reader.IsDBNull(ordinals.ArrivalAirportName))
     {
         ArrivalAirportName = reader.GetString(ordinals.ArrivalAirportName);
     }
     if (!reader.IsDBNull(ordinals.FromDateTime))
     {
         FromDateTime = reader.GetDateTime(ordinals.FromDateTime);
     }
     if (!reader.IsDBNull(ordinals.UntilDateTime))
     {
         UntilDateTime = reader.GetDateTime(ordinals.UntilDateTime);
     }
     if (!reader.IsDBNull(ordinals.PassengersBookedCount))
     {
         PassengersBookedCount = reader.GetInt32(ordinals.PassengersBookedCount);
     }
     if (!reader.IsDBNull(ordinals.AdultBookedCount))
     {
         AdultBookedCount = reader.GetInt32(ordinals.AdultBookedCount);
     }
     if (!reader.IsDBNull(ordinals.ChildBookedCount))
     {
         ChildBookedCount = reader.GetInt32(ordinals.ChildBookedCount);
     }
     if (!reader.IsDBNull(ordinals.InfantBookedCount))
     {
         InfantBookedCount = reader.GetInt32(ordinals.InfantBookedCount);
     }
     if (!reader.IsDBNull(ordinals.LastDateTimeTypeName))
     {
         LastDateTimeTypeName = reader.GetString(ordinals.LastDateTimeTypeName);
     }
     if (!reader.IsDBNull(ordinals.PlannedDepartureDateTime))
     {
         PlannedDepartureDateTime = reader.GetDateTime(ordinals.PlannedDepartureDateTime);
     }
     if (!reader.IsDBNull(ordinals.EstimatedDepartureDateTime))
     {
         EstimatedDepartureDateTime = reader.GetDateTime(ordinals.EstimatedDepartureDateTime);
     }
 }