예제 #1
0
        public IList <IDynamicClass> GetList(string sql, params object[] args)
        {
            LOG.DebugEnter(MethodBase.GetCurrentMethod(), sql, args);


            IDbParameters pars = null;

            sql = LoadGenericParameters(sql, out pars, args);

            IList <IDynamicClass> list = new List <IDynamicClass>();

            AdoTemplate.QueryWithRowCallbackDelegate(CommandType.Text, sql,
                                                     delegate(IDataReader reader)
            {
                DynamicClass dic = new DynamicClass();

                for (int i = 0; i < reader.FieldCount; i++)
                {
                    dic.Add(reader.GetName(i), reader.GetValue(i));
                }

                list.Add(dic);
            }, pars);

            return(list);
        }
예제 #2
0
        private static int RunQuery(AdoTemplate template, string query)
        {
            int rowCount = 0;

            template.QueryWithRowCallbackDelegate(CommandType.Text, query, r => rowCount++);
            return(rowCount);
        }
예제 #3
0
        /// <summary>
        /// Gets the most active users as recorded in the activity table
        /// </summary>
        /// <param name="maxCount"></param>
        /// <returns></returns>
        public Dictionary <string, string> GetMostActiveUsers(int maxCount)
        {
            Dictionary <string, string> list = new Dictionary <string, string>();
            int recordCount = 0;

            AdoTemplate.QueryWithRowCallbackDelegate(CommandType.Text, SQL_ACIVE_USERS,
                                                     delegate(IDataReader reader)
            {
                //Yes, we could do it all in SQL but there is no clean way to do it in a db-agnostic way
                //We are talking max of 10-20 users here
                if (recordCount < maxCount)
                {
                    object intValue  = reader.GetValue(1);
                    int numOfRecords = int.Parse(intValue.ToString());
                    list.Add(reader.GetString(0), numOfRecords.ToString());
                    recordCount++;
                }
            }
                                                     );

            return(list);
        }
예제 #4
0
        public FlightCollection GetFlights(Airport origin, Airport destination, DateTime departureDate)
        {
            #region Sanity Checks
            AssertUtils.ArgumentNotNull(origin, "origin");
            AssertUtils.ArgumentNotNull(destination, "destination");
            #endregion

            FlightCollection flights = new FlightCollection();


            IDbParametersBuilder builder = new DbParametersBuilder(DbProvider);
            builder.Create().Name("departureDate").Type(DbType.Date).Value(departureDate);
            builder.Create().Name("departureAirport").Type(DbType.Int32).Value(origin.Id);
            builder.Create().Name("destinationAirport").Type(DbType.Int32).Value(destination.Id);

#if NET_2_0
            AdoTemplate.QueryWithRowCallbackDelegate(CommandType.Text, FlightsQuery,
                                                     delegate(IDataReader dataReader)
            {
                int flightId        = dataReader.GetInt32(0);
                string flightNumber = dataReader.GetString(1);
                Aircraft aircraft   = aircraftDao.GetAircraft(dataReader.GetInt32(2));

                //TODO: Load cabins from the database
                Cabin[] cabins = aircraft.Cabins;

                Flight flight = new Flight(flightId, flightNumber, origin, destination, aircraft, departureDate, cabins);
                flights.Add(flight);
            },


                                                     builder.GetParameters());
#else
            AdoTemplate.QueryWithRowCallback(CommandType.Text, FlightsQuery,
                                             new FlightRowCallback(flights, aircraftDao, origin, destination, departureDate),
                                             builder.GetParameters());
#endif


            /*
             * IDbCommand command = GetCommand(FlightsQuery);
             * using(new ConnectionManager(command.Connection))
             * {
             *  SetFlightQueryParameters(command, departureDate, origin.Id, destination.Id);
             *  using (SqlDataReader reader = (SqlDataReader) command.ExecuteReader())
             *  {
             *      while(reader.Read())
             *      {
             *          int flightId = reader.GetInt32(0);
             *          string flightNumber = reader.GetString(1);
             *          Aircraft aircraft = aircraftDao.GetAircraft(reader.GetInt32(2));
             *
             *          //TODO: Load cabins from the database
             *          Cabin[] cabins = aircraft.Cabins;
             *
             *          Flight flight = new Flight(flightId, flightNumber, origin, destination, aircraft, departureDate, cabins);
             *          flights.Add(flight);
             *      }
             *  }
             * }
             */
            return(flights);
        }