Example #1
0
 public FlightPassenger(String Id, Airport DepartureAirport, Airport DestinationAirport,
                        TimeSpan EstimatedDuration, DateTime DepartureTime, DateTime ArrivalTime, int NrOfPassengers)
     : base(Id, DepartureAirport, DestinationAirport, EstimatedDuration, DepartureTime, ArrivalTime)
 {
     this.nrOfPassengers = NrOfPassengers;
 }
Example #2
0
        private void btn_create_plane_Click(object sender, EventArgs e)
        {
            created = false;
            //Time Helpers
            TimeSpan estimatedDuration = new TimeSpan(02, 25, 00);
            DateTime currentTime       = GlobalVariables.globalTime;

            //Airplane properties
            int    capacity = Convert.ToInt32(nud_capacity.Value);
            double speed    = Convert.ToDouble(nud_speed.Value);
            double fuel     = Convert.ToDouble(nud_fuel.Value);

            //Find the next ID for the plane
            int id_plane = airNetwork.nextAvailableAirplaneId();

            //Flight properties
            string origin_countryName      = cb_auto_orig.Text;
            string destination_countryName = cb_auto_dest.Text;
            int    loaded = Convert.ToInt32(numericUpDown4.Value);

            //Find the next ID for the flight
            int id_flight = airNetwork.nextAvailableFlightId();

            //Initializing Airport and Airplane objects to be passed
            Airport  origin_airport      = null;
            Airport  destination_airport = null;
            Airplane airplane            = null;
            Flight   flight = null;

            //Bulk properties
            int bulkAmount = Convert.ToInt32(nud_blk_amount.Value);

            origin_airport      = returnAirportObject(origin_countryName);
            destination_airport = returnAirportObject(destination_countryName);

            if (origin_airport != null && destination_airport != null)
            {
                //Check if there are problems in the airports
                if (origin_airport.Problems.Count > 0 || destination_airport.Problems.Count > 0)
                {
                    MessageBox.Show("Airplane was not created since there was a problem in one of the airports.");
                    return;
                }
                //Check if it should be a bulk create
                if (cb_bulkCreate.Checked)
                {
                    if (speed > 0 && fuel > 0)
                    {
                        for (int i = 0; i < bulkAmount; i++)
                        {
                            id_flight++;
                            id_plane++;
                            if (capacity > loaded)
                            {
                                if (speed > 0 && fuel > 0)
                                {
                                    if (rb_cargo.Checked)
                                    {
                                        // Adding a cargo Airplane and Flight
                                        //Creating the plane and flight
                                        flight   = new FlightCargo(id_flight.ToString(), origin_airport, destination_airport, estimatedDuration, currentTime, currentTime + estimatedDuration, loaded);
                                        airplane = new AirplaneCargo(id_plane.ToString(), capacity, speed, fuel, origin_airport.Location);
                                    }
                                    else if (rb_passanger.Checked)
                                    {
                                        //Adding a passanger Airplane and Flight
                                        //Creating the plane and flight
                                        flight   = new FlightPassenger(id_flight.ToString(), origin_airport, destination_airport, estimatedDuration, currentTime, currentTime + estimatedDuration, loaded);
                                        airplane = new AirplanePassenger(id_plane.ToString(), capacity, speed, fuel, origin_airport.Location);
                                    }

                                    if (flight != null && airplane != null)
                                    {
                                        created = true;
                                        //Adding the flight to the network
                                        airNetwork.Airplanes.Add(airplane);
                                        //Adding the plane to the flight
                                        airplane.AddFlight(flight);
                                    }
                                }
                                else //If speed is <=0
                                {
                                    MessageBox.Show("Please make sure both speed and fuel are more than 0");
                                }
                            }
                            else
                            {
                                MessageBox.Show("There is more cargo on the plane than the capacity would allow!");
                            }
                        }
                    }
                    else
                    {
                        MessageBox.Show("Please make sure both speed and fuel are more than 0");
                    }
                    if (created)
                    {
                        MessageBox.Show(bulkAmount + " airplanes from " + origin_countryName + " to " + destination_countryName + " were succesffully created!");
                        resetAllBoxes();
                        panelDrawing.Invalidate();
                    }
                }
                else //Proceed with a single airplane creation
                {
                    if (capacity > loaded)
                    {
                        if (speed > 0 && fuel > 0)
                        {
                            if (rb_cargo.Checked)
                            {
                                // Adding a cargo Airplane and Flight
                                //Creating the plane and flight
                                flight   = new FlightCargo(id_flight.ToString(), origin_airport, destination_airport, estimatedDuration, currentTime, currentTime + estimatedDuration, loaded);
                                airplane = new AirplaneCargo(id_plane.ToString(), capacity, speed, fuel, origin_airport.Location);
                            }
                            else if (rb_passanger.Checked)
                            {
                                //Adding a passanger Airplane and Flight
                                //Creating the plane and flight
                                flight   = new FlightPassenger(id_flight.ToString(), origin_airport, destination_airport, estimatedDuration, currentTime, currentTime + estimatedDuration, loaded);
                                airplane = new AirplanePassenger(id_plane.ToString(), capacity, speed, fuel, origin_airport.Location);
                            }

                            if (flight != null && airplane != null)
                            {
                                created = true;
                                //Adding the flight to the network
                                airNetwork.Airplanes.Add(airplane);
                                //Adding the plane to the flight
                                airplane.AddFlight(flight);
                            }
                        }
                        else //If speed is <=0
                        {
                            MessageBox.Show("Please make sure both speed and fuel are more than 0");
                        }
                    }
                    else
                    {
                        MessageBox.Show("There is more cargo on the plane than the capacity would allow!");
                    }
                    if (created)
                    {
                        MessageBox.Show("Airplane from " + origin_countryName + " to " + destination_countryName + " was succesffully created!");
                        resetAllBoxes();
                        panelDrawing.Invalidate();
                    }
                }
            }
            else
            {
                MessageBox.Show("Please select both origin and destination airports");
            }
            autoCompleteAirport(cb_auto_orig);
            autoCompleteAirport(cb_auto_dest);
        }
Example #3
0
        private void searchBtn_Click(object sender, EventArgs e)
        {
            Airport tempairport = null;

            lbBack2.Visible = true;
            string airname = cbSearch.Text;

            foreach (Airport a in airNetwork.Airports)
            {
                if (a.Name == airname)
                {
                    tempairport = a;
                }
            }
            if (tempairport != null)
            {
                if (cbFrom.Checked)
                {
                    foreach (Airplane a in airNetwork.Airplanes)
                    {
                        foreach (Flight f in airNetwork.Flights)
                        {
                            if (f.DepartureAirport.Name == airname)
                            {
                                if (a.Flight == f)
                                {
                                    f.DepartureAirport.ChangeIcon(GlobalVariables.selectedAirport);
                                    a.ChangeIcon(GlobalVariables.selectedAirplane);
                                }
                            }
                        }
                    }
                }
                if (cbTo.Checked)
                {
                    foreach (Flight f in airNetwork.Flights)
                    {
                        if (f.DestinationAirport.Name == airname)
                        {
                            foreach (Airplane a in airNetwork.Airplanes)
                            {
                                if (a.Flight == f)
                                {
                                    f.DestinationAirport.ChangeIcon(GlobalVariables.selectedAirport);
                                    a.ChangeIcon(GlobalVariables.selectedAirplane);
                                }
                            }
                        }
                    }
                }
                if (cbTo.Checked && cbFrom.Checked && tempairport != null)
                {
                    tempairport.ChangeIcon(GlobalVariables.selectedAirport);
                    foreach (Airplane a in airNetwork.Airplanes)
                    {
                        foreach (Flight f in airNetwork.Flights)
                        {
                            if (f.DepartureAirport.Name == airname || f.DestinationAirport.Name == airname)
                            {
                                if (a.Flight == f)
                                {
                                    a.ChangeIcon(GlobalVariables.selectedAirplane);
                                }
                            }
                        }
                    }
                }

                if (!cbTo.Checked && !cbFrom.Checked && tempairport != null)
                {
                    tempairport.ChangeIcon(GlobalVariables.selectedAirport);
                }
                panelDrawing.Invalidate();
                searchBtn.Visible = false;
                cbSearch.Visible  = false;
                lblSearch.Text    = airname;
            }
            else
            {
                MessageBox.Show("No such airport");
            }
        }
Example #4
0
 public Queue(Airport airport)
 {
     this.Airport = airport;
     pQueue       = new PriorityQueue <int, Airplane>(new MaxQueueComparer());
 }