Exemplo n.º 1
0
        // if prepare is false, don't show it!
        public bool Prepare(DbFace dbface, string lastrun)
        {
            // Try to look up any new annoucements
            List<Dictionary<string, object>> rows = dbface.AssocEnumerate(string.Format("select * from announces where date_created > '{0} 23:59' order by id asc", DbFace.EscapeSingles(lastrun)));
            if (rows != null && rows.Count == 0)
                rows = null;

            // Are there any messages to display?
            if (userMessages.Count == 0 && rows == null)
                return false;

            // fill out the messages box
            StringBuilder messages = new StringBuilder();
            // basic definitions
            messages.Append("{\\rtf1\\ansi\\deff0{\\colortbl;\\red0\\green0\\blue0;\\red128\\green128\\blue0;}");
            foreach (string message in userMessages) {
                messages.AppendLine("\\cf2");
                messages.AppendLine("\\bullet  " + message + "\\line");
            }

            // Add in any annoucements
            if (rows != null)
            {
                foreach (Dictionary<string, object> row in rows)
                {
                    messages.AppendLine("\\bullet {\\b " + row["subject"] + "}\\line\\line");
                    messages.AppendLine(row["body"] + "\\line\\line");
                }
            }
            messages.AppendLine("}");

            rtbMessages.Rtf = messages.ToString();
            return true;
        }
Exemplo n.º 2
0
        public static List<Airport> LoadAllAirports(DbFace dbface, string order)
        {
            string sql = "select * from airports";
            if (!string.IsNullOrEmpty(order))
                sql += " order by " + order;

            List<Dictionary<string, object>> rows = dbface.AssocEnumerate(sql);
            if (rows == null)
                return null; // failed!

            List<Airport> airports = new List<Airport>();
            foreach (Dictionary<string, object> row in rows)
                airports.Add(Airport.RecordAirport(row));

            return airports;
        }
Exemplo n.º 3
0
        // Get a random airport, based on salience.  Defaults to BOS, if there's an error.
        public static string GetSalientAirportCode(DbFace dbface)
        {
            lock (dbface)
            {
                List<Dictionary<string, object>> rows = dbface.AssocEnumerate("select * from airports order by salience * rand() desc limit " + (countDisabled + 1));
                if (rows == null)
                    return "BOS";

                foreach (Dictionary<string, object> row in rows)
                {
                    Airport airport = RecordAirport(row);
                    if (!airport.enabled)
                        continue;

                    return airport.code;
                }

                return "BOS";
            }
        }
Exemplo n.º 4
0
        // Get an airport, either from the cache or the database
        public static Airport GetAirport(string code, DbFace dbface)
        {
            lock (cache)
            {
                // look in the cache
                Airport airport;
                if (cache.TryGetValue(code, out airport))
                    return airport;

                // look in the database
                List<Dictionary<string, object>> rows = dbface.AssocEnumerate(string.Format("select * from airports where code = '{0}' limit 1", code));
                if (rows == null || rows.Count != 1)
                    return new Airport(code, "Unknown", "Unknown");

                Dictionary<string, object> row = rows[0];

                airport = new Airport((string)row["code"], (string)row["title"], (string)row["country"]);
                cache[code] = airport;

                return airport;
            }
        }
Exemplo n.º 5
0
        // Find all flights that fit the search criteria
        // if nextstart = 0, don't try again
        public List<Flight> FindStoredFlights(DbFace dbface, string order, int start, int limit, int maxgive, out int nextstart)
        {
            List<Flight> flights = new List<Flight>();

            string[] origins = Airport.ParseAirportCodes(txtOrigins.Text);
            List<Dictionary<string, object>> rows = dbface.AssocEnumerate(string.Format("select flights.*, airports.country as destcountry from flights left join airports on flights.destination = airports.code where (origin = '{0}') and date_leave >= '{1}' and date_leave <= '{2}' and datediff(date_return, date_leave) >= {3} and datediff(date_return, date_leave) <= {4} order by {5} limit {6}, {7}", string.Join("' or origin = '", origins), MyDate(earliest.Value), MyDate(latest.Value), GetNum(shortest.Text, false).Value, GetNum(longest.Text, false).Value, order, start, limit));

            nextstart = start;
            foreach (Dictionary<string, object> row in rows)
            {
                nextstart++;

                Flight flight = new Flight(row);
                // Is this airport enabled?
                if (Airport.IsAirportEnabled(flight.Destination))
                {
                    flights.Add(flight);
                    if (flights.Count == maxgive)
                        return flights;
                }
            }

            if (rows.Count < limit)
                nextstart = 0;
            return flights;
        }
Exemplo n.º 6
0
        // Find all flights that fit the search criteria
        // if nextstart = 0, don't try again
        public List<AtoCFlight> FindStoredAtoCFlights(DbFace dbface, string order, int start, int limit, int maxgive, out int nextstart)
        {
            List<AtoCFlight> flights = new List<AtoCFlight>();

            string[] pointas = Airport.ParseAirportCodes(txtPointA.Text);
            string[] pointcs = Airport.ParseAirportCodes(txtPointC.Text);
            List<Dictionary<string, object>> rows = dbface.AssocEnumerate(string.Format("select atob.id as atob_id, atob.origin as atob_origin, atob.destination as atob_destination, atob.date as atob_date, atob.price as atob_price, atob.km as atob_km, atob.date_created as atob_date_created, btoc.id as btoc_id, btoc.origin as btoc_origin, btoc.destination as btoc_destination, btoc.date as btoc_date, btoc.price as btoc_price, btoc.km as btoc_km, btoc.date_created as btoc_date_created from oneways atob left join oneways btoc on atob.destination = btoc.origin where (atob.origin = '{0}') and (btoc.destination = '{1}') and atob.date >= '{2}' and atob.date <= '{3}' and btoc.date >= '{4}' and btoc.date <= '{5}' and datediff(btoc.date, atob.date) >= {6} and datediff(btoc.date, atob.date) <= {7} order by {8} limit {9}, {10}", string.Join("' or atob.origin = '", pointas), string.Join("' or btoc.destination = '", pointcs), MyDate(earliest.Value), MyDate(latest.Value.AddDays(-GetNum(shortest.Text, false).Value)), MyDate(earliest.Value.AddDays(GetNum(shortest.Text, false).Value)), MyDate(latest.Value), GetNum(shortest.Text, false).Value, GetNum(longest.Text, false).Value, order, start, limit));

            nextstart = start;
            foreach (Dictionary<string, object> row in rows)
            {
                nextstart++;

                AtoCFlight flight = new AtoCFlight(row);
                // Is this airport enabled?
                if (Airport.IsAirportEnabled(flight.PointB))
                {
                    flights.Add(flight);
                    if (flights.Count == maxgive)
                        return flights;
                }
            }

            if (rows.Count < limit)
                nextstart = 0;
            return flights;
        }