public FlightsList searchMatches(string data, int option) { FlightsList filterFlightsList = new FlightsList(); switch (option) { case 1: { for (int i = 0; i < this.Count; i++) { int j; for (j = 0; j < data.Length && j < this[i].getRoute().Length; j++) { if (data[j] != this[i].getRoute()[j]) { break; } } if (j == data.Length) { filterFlightsList.Add(this[i]); } } break; } case 2: { for (int i = 0; i < this.Count; i++) { if (data == this[i].getOriginCity().ToString()) { filterFlightsList.Add(this[i]); } } break; } case 3: { for (int i = 0; i < this.Count; i++) { if (data == this[i].getDestinationCity().ToString()) { filterFlightsList.Add(this[i]); } } break; } default: break; } return(filterFlightsList); }
private void buttonAdd_Click(object sender, EventArgs e) { Flight newflight; string route; bool parseInt; int time, cost; int x1, y1, x2, y2; x1 = y1 = x2 = y2 = 0; if (textBoxOrigin.Text != "") { if (textBoxOrigin.Text.Length == 1) { if (textBoxDestination.Text != "") { if (textBoxDestination.Text.Length == 1) { if (textBoxDestination.Text != textBoxOrigin.Text) { if (textBoxTime.Text != "") { parseInt = int.TryParse(textBoxTime.Text, out time); if (parseInt) { if (textBoxCost.Text != "") { parseInt = int.TryParse(textBoxCost.Text, out cost); if (parseInt) { route = "SK1" + textBoxOrigin.Text + textBoxDestination.Text; if (!flights.flightExistence(route)) { newflight = new Flight(textBoxOrigin.Text, textBoxDestination.Text, time, cost); flights.Add(newflight); GraphForm graphForm = new GraphForm(1, graph, flights); if (!graph.excistenceCity(textBoxOrigin.Text)) { MessageBox.Show("Ciudad Origen", "Informacion", MessageBoxButtons.OK, MessageBoxIcon.Information); graphForm.ShowDialog(); x1 = graphForm.getX(); y1 = graphForm.getY(); } if (!graph.excistenceCity(textBoxDestination.Text)) { MessageBox.Show("Ciudad Destino", "Informacion", MessageBoxButtons.OK, MessageBoxIcon.Information); graphForm.ShowDialog(); x2 = graphForm.getX(); y2 = graphForm.getY(); } graph.addRoute(newflight, x1, y1, x2, y2); MessageBox.Show("Vuelo agregado exitosamente", "Informacion", MessageBoxButtons.OK, MessageBoxIcon.Information); textBoxOrigin.Text = ""; textBoxDestination.Text = ""; textBoxTime.Text = ""; textBoxCost.Text = ""; viewsFlghtsUpdate(flights); } else { MessageBox.Show("El vuelo ya existe", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { MessageBox.Show("Introduzca un costo valido", "Advertencia", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } else { MessageBox.Show("Introduzca el costo", "Advertencia", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } else { MessageBox.Show("Introduzca un timepo valido", "Advertencia", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } else { MessageBox.Show("Introduzca el Tiempo", "Advertencia", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } else { MessageBox.Show("No se puede mismo origen y destino", "Advertencia", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } else { MessageBox.Show("Destino no valido", "Advertencia", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } else { MessageBox.Show("Introduzca un Destino", "Advertencia", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } else { MessageBox.Show("Origen no valido", "Advertencia", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } else { MessageBox.Show("Introduzca un Origen", "Advertencia", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } }