예제 #1
0
 // 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, FlightHistoryDataOrdinals ordinals)
 {
     if (!reader.IsDBNull(ordinals.DateTime))
     {
         DateTime = reader.GetDateTime(ordinals.DateTime);
     }
     if (!reader.IsDBNull(ordinals.FlightId))
     {
         FlightId = reader.GetGuid(ordinals.FlightId);
     }
     if (!reader.IsDBNull(ordinals.AirlineIdentifierCode))
     {
         AirlineIdentifierCode = reader.GetString(ordinals.AirlineIdentifierCode);
     }
     if (!reader.IsDBNull(ordinals.AirlineName))
     {
         AirlineName = reader.GetString(ordinals.AirlineName);
     }
     if (!reader.IsDBNull(ordinals.FlightNumber))
     {
         FlightNumber = reader.GetString(ordinals.FlightNumber);
     }
     if (!reader.IsDBNull(ordinals.AircraftTypeName))
     {
         AircraftTypeName = reader.GetString(ordinals.AircraftTypeName);
     }
     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.SegmentCount))
     {
         SegmentCount = reader.GetInt32(ordinals.SegmentCount);
     }
 }
예제 #2
0
        /// <summary>Get flight history</summary>
        /// <cardinality>Many</cardinality>
        public List <FlightHistoryData> FlightHistory(
            Guid flightId
            )
        {
            var ret = new List <FlightHistoryData>();

            string sql = @" 
                    select 
						 f.date_time
                        ,f.flight_id
	                    ,ai.airline_identifier_code
	                    ,a.airline_name
						,fi.flight_identifier_code		as flight_number
	                    ,atr.aircraft_type_name
	                    ,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
	                    ,f.from_date_time
	                    ,f.until_date_time
						,(	select count(1) 
							from flight_segment as fs
							where fs.flight_id = f.flight_id
						 )								as segment_count
                    from flight								as f
                    inner join airline				        as a	on a.airline_id = f.airline_id
                    inner join aircraft_type_ref	        as atr	on atr.aircraft_type_rcd = f.aircraft_type_rcd
                    inner join airport				        as da	on da.airport_id = f.departure_airport_id
                    inner join airport				        as aa	on aa.airport_id = f.arrival_airport_id
                    inner join airport_identifier	        as dai	on dai.airport_id = f.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 = f.arrival_airport_id
										                            and aai.airport_identifier_type_rcd = dbo.ref('airport_identifier_type_ref.AC3')
                    inner join airline_identifier	        as ai	on ai.airline_id = f.airline_id
										                            and ai.airline_identifier_type_rcd = dbo.ref('airline_identifier_type_ref.AC2')
	                 left join flight_identifier			as fi	on fi.flight_id = f.flight_id
															        and fi.flight_identifier_type_rcd = dbo.ref('flight_identifier_type_ref.FN3')
                    --realwhere
                    where f.binding_flight_id = @flight_id
					order by f.date_time desc
                ";

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

                using (var command = new SqlCommand(sql, conn)) {
                    command.Parameters.Add("@flight_id", SqlDbType.UniqueIdentifier).Value = flightId;

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

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

                    log.PerformanceTimeStop(sql, command);

                    var ordinals = new FlightHistoryDataOrdinals(reader);

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

                    reader.Close();
                }

                return(ret);
            }
        }