Пример #1
0
        public AirportFinder(TextBox txtOrigins, DbFace dbface, StatusManager status)
        {
            this.txtOrigins = txtOrigins;
            idleEnumerator = null;

            InitializeComponent();

            // Collect All Airports
            airports = Airport.LoadAllAirports(dbface, "country asc");
            if (airports == null)
            {
                status.AddNow("Could not access airport information", 0, 0);
                this.Close();
                return;
            }

            txtSearch.Text = "";

            catalog = new Dictionary<string,Airport>();

            // Display all airports
            foreach (Airport airport in airports)
            {
                string line = airport.ToString();
                catalog.Add(line.ToLower(), airport);
                lstAirports.Items.Add(airport);
            }
        }
Пример #2
0
        public SelectDestinations(DbFace dbface, StatusManager status)
        {
            this.dbface = dbface;

            InitializeComponent();

            // Select all countries and their airports
            List<Airport> airports = Airport.LoadAllAirports(dbface, "country asc");

            if (airports == null)
            {
                status.AddNow("Could not access airport information", 0, 0);
                this.Close();
                return;
            }

            TreeNode node = null;   // the current node we're adding t
            int lastchecked = 0, lastunchecked = 0;
            foreach (Airport airport in airports)
            {
                string country = airport.Country;
                if (node == null || node.Text != country)
                {
                    if (node != null)
                    {
                        if (lastchecked == 0)
                            node.StateImageIndex = 0;
                        else if (lastunchecked == 0)
                            node.StateImageIndex = 1;
                        else
                            node.StateImageIndex = 2;
                    }

                    lastchecked = lastunchecked = 0;

                    // need to add the country
                    node = destinations.Nodes.Add(country, country);
                }

                // Add this
                TreeNode child = node.Nodes.Add(airport.Code, airport.Title + " (" + airport.Code + ")");
                child.StateImageIndex = airport.IsEnabled ? 1 : 0;
                if (airport.IsEnabled)
                    lastchecked++;
                else
                    lastunchecked++;
            }

            if (lastchecked == 0)
                node.StateImageIndex = 0;
            else if (lastunchecked == 0)
                node.StateImageIndex = 1;
            else
                node.StateImageIndex = 2;
        }
Пример #3
0
        public MainWindow()
        {
            // The announcements may include configuration errors and community-wide notices
            Announcements announcer = new Announcements();

            InitializeComponent();

            // set up our connection to the database
            masterdbface = new DbFace();
            source = "orbitz";
            user = GetIpAddress();

            // read the configuration file
            DateTime earlyDate, lateDate;
            if (!DateTime.TryParse(ConfigurationManager.AppSettings["earliest"], out earlyDate))
            {
                announcer.AddMessage("Could not understand 'earliest' configuration date format; resetting to today.");
                earlyDate = DateTime.Now;
            }
            if (!DateTime.TryParse(ConfigurationManager.AppSettings["latest"], out lateDate))
            {
                announcer.AddMessage("Could not understand 'latest' configuration date format; resetting to five months from now.");
                lateDate = DateTime.Now.AddMonths(5);
            }
            // adjust the dates to maintain the difference
            if (earlyDate < DateTime.Now)
            {
                TimeSpan diff = lateDate.Subtract(earlyDate);
                earlyDate = DateTime.Now;
                lateDate = DateTime.Now.Add(diff);
            }
            else if (lateDate < DateTime.Now)
            {
                announcer.AddMessage("Invalid 'latest' date; resetting to five months from 'earliest'.");
                lateDate = earlyDate.AddMonths(5);
            }
            earliest.Value = earlyDate;
            latest.Value = lateDate;

            int shortNumber, longNumber;
            if (!int.TryParse(ConfigurationManager.AppSettings["shortest"], out shortNumber))
            {
                announcer.AddMessage("The 'shortest' configuration is not a number; resetting to 5");
                shortNumber = 5;
            }
            if (!int.TryParse(ConfigurationManager.AppSettings["longest"], out longNumber))
            {
                announcer.AddMessage("The 'longest' configuration is not a number; resetting to 12");
                longNumber = 12;
            }

            shortest.Text = shortNumber.ToString();
            longest.Text = longNumber.ToString();

            txtOrigins.Text = ConfigurationManager.AppSettings["origins"];
            if (txtOrigins.Text == null || txtOrigins.Text.Length == 0) {
                announcer.AddMessage("The 'origins' configuration is missing: resetting to JFK, LGA, EWR, DCA, BWI, IAD, BOS");
                txtOrigins.Text = "JFK, LGA, EWR, DCA, BWI, IAD, BOS";
            }

            txtPointA.Text = ConfigurationManager.AppSettings["pointas"];
            if (txtPointA.Text == null || txtPointA.Text.Length == 0) {
                announcer.AddMessage("The 'pointas' configuration is missing: resetting to JFK, LGA, EWR");
                txtPointA.Text = "JFK, LGA, EWR";
            }
            txtPointC.Text = ConfigurationManager.AppSettings["pointcs"];
            if (txtPointC.Text == null || txtPointC.Text.Length == 0) {
                announcer.AddMessage("The 'pointcs' configuration is missing: resetting to DCA, BWI, IAD");
                txtPointC.Text = "DCA, BWI, IAD";
            }

            if (ConfigurationManager.AppSettings["mode"] != null)
                cmbSearch.SelectedText = ConfigurationManager.AppSettings["mode"];

            Airport.DisableCodes(ConfigurationManager.AppSettings["disabled"], masterdbface);

            int simulNumber;
            if (!int.TryParse(ConfigurationManager.AppSettings["simultaneous"], out simulNumber))
            {
                announcer.AddMessage("The 'simultaneous' configuration is not a number: resetting to 2");
                simulNumber = 2;
            }
            else if (simulNumber > 9)
            {
                announcer.AddMessage("The 'simultaneous' configuration is more than 9; resetting to 9");
                simulNumber = 9;
            }
            numSimul.Value = simulNumber;

            cmbSearch.SelectedIndex = 0;

            results = new OrderedListBox(lstResults);
            status = new StatusManager(statusStrip1, toolStripStatusLabel1, toolStripProgressBar1);

            lstResults.Click += this.lstResults_SelectedIndexChanged;
            FormClosing += Form1_Closing;
            Application.Idle += OnIdle;
            status.AddNow("Initialized.", 1, 0);

            // display the annoucements box
            DateTime lastrun = DateTime.Now;
            if (!DateTime.TryParse(ConfigurationManager.AppSettings["lastrun"], out lastrun))
                lastrun = DateTime.Now;

            if (announcer.Prepare(masterdbface, MyDate(lastrun)))
                announcer.Show();
        }