public Form1(Regions region) { InitializeComponent(); airNetwork = new Network(region); helper = new DataHelper(airNetwork); airNetwork.Airports = helper.GetAllAirports(); //consider sending the Airports of airNetwork as a parameter into GetAllAirports instead of assigning it as reference airNetwork.Airplanes = helper.GetAllAirplanes(); airNetwork.Flights = helper.GetAllFlights(); painter = new Painter(); selectedAirplane = null; selectedAirport = null; this.panelDrawing.Paint -= panelDrawing_Paint; this.panelDrawing.Paint += new PaintEventHandler(DrawNetwork); this.Invalidate(); this.panelDrawing.Paint += panelDrawing_Paint; autoCompleteAirport(cbSearch); autoCompleteAirport(cbChangeDestination); if (region == Regions.AUSTRALIA) { this.panelDrawing.BackgroundImage = Properties.Resources.australia; } GlobalVariables.globalTime = new DateTime(2017, 06, 8, 17, 0, 0); lbTimeSpan.Text = GlobalVariables.globalTime.ToString(); }
private void panelDrawing_MouseUp(object sender, MouseEventArgs e) { X = e.X; Y = e.Y; tbLocation.Text = Convert.ToString("X: " + X + " " + "Y: " + Y); selectedAirplane = null; selectedAirport = null; string temp; if (airNetwork.GetAirplane(e.Location) != null) { SelectAirplane(e.Location); temp = lbPlaneName.Text; foreach (Airplane a in airNetwork.Airplanes) { if (a.Id == temp) { selectedAirplane = a; } } } if (airNetwork.GetAirport(e.Location) != null) { SelectAirport(e.Location); temp = lbPlaneName.Text; foreach (Airport a in airNetwork.Airports) { if (a.Name == temp) { selectedAirport = a; } } } panelDrawing.Invalidate(); }
public void AddAirplane(Airplane airplane) { Airplanes.Add(airplane); }
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); }
public void AddPlaneToQueueTest(int priority, Airplane airplane) { pQueue.Enqueue(priority, airplane); }
public void AddPlaneToQueue(Airplane airplane) { pQueue.Enqueue(this.CalculatePriority(airplane), airplane); }