Example #1
0
        private void showFlights_btn_Click(object sender, EventArgs e)
        {
            if (origin_comboBox.SelectedItem != null && destination_comboBox.SelectedItem != null)
            {
                String originCity = origin_comboBox.SelectedItem.ToString();
                String destCity   = destination_comboBox.SelectedItem.ToString();

                String originAbv = FormDatabaseHelper.getAirportAbvFromCity(originCity);
                String destAbv   = FormDatabaseHelper.getAirportAbvFromCity(destCity);

                DateTime currSysTime = currSysTime_DTP.Value;
                DateTime deptDate    = deptDate_dtp.Value;
                DateTime returnDate;
                bool     oneWay        = oneWay_rBtn.Checked;
                bool     returnBooking = return_rBtn.Checked;

                oneway_groupBox.Text = originCity + "-->" + destCity;
                return_groupBox.Text = destCity + "-->" + originCity;

                if (originAbv != destAbv && (deptDate <= currSysTime.AddDays(60)))
                {
                    if (returnBooking)
                    {
                        returnDate = returnDate_dtp.Value;
                        if (returnDate > deptDate)
                        {
                            oneway_groupBox.Show();
                            DataTable onewayOptionsTable = FormDatabaseHelper.getAvailableFlights(originAbv, destAbv, deptDate);
                            populateDataGridView(oneway_datagridview, onewayOptionsTable);
                            return_groupBox.Show();
                            DataTable returnOptionsTable = FormDatabaseHelper.getAvailableFlights(destAbv, originAbv, returnDate);
                            populateDataGridView(return_datagridview, returnOptionsTable);
                        }
                        else
                        {
                            Console.WriteLine("return should be after departure date");
                        }
                    }
                    else
                    {
                        return_groupBox.Hide();
                        oneway_groupBox.Show();
                        DataTable onewayOptionsTable = FormDatabaseHelper.getAvailableFlights(originAbv, destAbv, deptDate);
                        populateDataGridView(oneway_datagridview, onewayOptionsTable);
                    }
                }
                else
                {
                    Console.WriteLine("Depature date should be within 6 months AND ");
                    Console.WriteLine("origin and dest cannot be same");
                }
            }
        }