Пример #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, FlightsForPeriodSimpleDataOrdinals ordinals)
 {
     if (!reader.IsDBNull(ordinals.FlightId))
     {
         FlightId = reader.GetGuid(ordinals.FlightId);
     }
     if (!reader.IsDBNull(ordinals.FromDateTime))
     {
         FromDateTime = reader.GetDateTime(ordinals.FromDateTime);
     }
     if (!reader.IsDBNull(ordinals.UntilDateTime))
     {
         UntilDateTime = reader.GetDateTime(ordinals.UntilDateTime);
     }
 }
Пример #2
0
        /// <summary>Get flights for a duration</summary>
        /// <cardinality>Many</cardinality>
        /// <generatelayer>DataAccessLayer</generatelayer>
        public static List <FlightsForPeriodSimpleData> FlightsForPeriodSimple(
            DateTime fromDateTime,
            DateTime untilDateTime
            )
        {
            var ret = new List <FlightsForPeriodSimpleData>();

            string sql = @" 
                    select 
                         fl.flight_id   
	                    ,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
							where fs.flight_id = fl.flight_id
							)									as flights_booked_count
	                    ,(	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
*/
                    from flight                                 as fl
                    
                    --realwhere

                    where (fl.from_date_time between @from_date_time and @until_date_time
                        or fl.until_date_time between @from_date_time and @until_date_time)
                      and fl.became_flight_id is null

                    order by fl.from_date_time
                ";

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

                using (var command = new SqlCommand(sql, conn)) {
                    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.FlightsForPeriodSimple");
                    IDataReader reader = command.ExecuteReader(CommandBehavior.SingleResult);
                    log.PerformanceTimeStop(sql, command);

                    var ordinals = new FlightsForPeriodSimpleDataOrdinals(reader);

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

                    reader.Close();
                }

                return(ret);
            }
        }