Пример #1
0
        public AtoCFlightViewBox(AtoCFlight flight, DbFace dbface)
        {
            InitializeComponent();

            this.flight = flight;

            // Fill out all the data files
            lblPointA.Text = Airport.GetAirport(flight.PointA, dbface).ToString();
            lblPointB.Text = Airport.GetAirport(flight.PointB, dbface).ToString();
            lblPointC.Text = Airport.GetAirport(flight.PointC, dbface).ToString();
            lblDate_AtoB.Text = flight.Date_AtoB.ToString("M/d/yyyy");
            lblDate_BtoC.Text = flight.Date_BtoC.ToString("M/d/yyyy");
            lblPrice.Text = "$" + flight.Price_AtoB.ToString() + " + $" + flight.Price_BtoC.ToString();
            lblDistance.Text = flight.Km_AtoB.ToString() + " km + " + flight.Km_BtoC.ToString() + " km";
            TimeSpan span = DateTime.Now.Subtract(flight.LastChecked);
            if (span.Days > 0)
                lblLastChecked.Text = span.Days + " days and " + span.Hours + " hours ago";
            else
                lblLastChecked.Text = span.Hours + " hours ago";

            lblLink.Text = "http://www.orbitz.com/";
        }
Пример #2
0
        // Record a new flight option
        public void RecordAtoCOption(string pointa, string pointb, string pointc, DateTime start, DateTime end, int priceatob, int pricebtoc, int distanceatob, int distancebtoc, DbFace dbface)
        {
            lock (dbface)
            {
                dbface.Execute(string.Format("insert into oneways (origin, destination, date, price, km, source, user) values ('{0}', '{1}', '{2}', {3}, {4}, '{5}', '{6}') on duplicate key update price = {3}, source = '{5}', user = '******'", pointa, pointb, MyDate(start), priceatob, distanceatob, source, user), false);
                dbface.Execute(string.Format("insert into oneways (origin, destination, date, price, km, source, user) values ('{0}', '{1}', '{2}', {3}, {4}, '{5}', '{6}') on duplicate key update price = {3}, source = '{5}', user = '******'", pointb, pointc, MyDate(end), pricebtoc, distancebtoc, source, user), false);
            }

            lock (results)
            {
                AtoCFlight flight = new AtoCFlight(pointa, pointb, pointc, start, end, (uint) priceatob, (uint) pricebtoc, (uint) distanceatob, (uint) distancebtoc, DateTime.Now);
                results.Add(flight.Score, flight);
            }
        }
Пример #3
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;
        }