private void searchTextBox_TextChanged(object sender, EventArgs e) { FlightList aux; if (searchTextBox.Text == "") { aux = FlightList; } else { if (routeRadioButton.Checked) { aux = FlightList.muntipleSearch(1, searchTextBox.Text); } else if (OriginRadioButton.Checked) { aux = FlightList.muntipleSearch(2, searchTextBox.Text); } else { aux = FlightList.muntipleSearch(3, searchTextBox.Text); } } loadFlights(aux); }
private void deleteFlightButton_Click(object sender, EventArgs e) { Flight aux = getSelectedFlight(); if (aux == null) { flightsErrorProvider.SetError(flightsListView, "Seleccione un vuelo para borrar"); } else { for (int i = 0; i < PassengerList.Count; i++) { if (PassengerList[i].Flight == aux.Route) { PassengerList.Remove(PassengerList[i]); } } FlightList.Remove(aux); Node auxOrigin = FlightsGraph.searchNode(aux.Origin[0]); Node auxDestiny = FlightsGraph.searchNode(aux.Destiny[0]); FlightsGraph.deleteEdge(auxOrigin, auxDestiny); FlightsGraph.deleteEdge(auxDestiny, auxOrigin); if (FlightsGraph.isIsolated(auxOrigin)) { FlightsGraph.deleteNode(auxOrigin); } if (FlightsGraph.isIsolated(auxDestiny)) { FlightsGraph.deleteNode(auxDestiny); } loadFlights(FlightList); } }
public Graph(FlightList flights) { NodeList = new List <Node>(); ConectedComponents = new List <string>(); foreach (Flight flight in flights) { addNode(flight.Origin[0]); addNode(flight.Destiny[0]); } foreach (Flight flight in flights) { foreach (Node node in NodeList) { if (flight.Origin[0] == node.City) { Node aux = searchNode(flight.Destiny[0]); if (aux.City != '@') { addEdge(node, aux); } } } } }
public MainForm(FlightList flightList, PassengerList passengerList, Graph graph) { FlightList = flightList; PassengerList = passengerList; FlightsGraph = graph; InitializeComponent(); }
private void timeSortRadioButton_CheckedChanged(object sender, EventArgs e) { if (timeSortRadioButton.Checked == true) { FlightList.quickSort(0, FlightList.Count - 1, 2); } loadFlights(FlightList); }
public PassengersForm(PassengerList passengerList, FlightList flightList) { Passengers = passengerList; Flights = flightList; InitializeComponent(); passengersListView.FullRowSelect = true; passengersListView.MultiSelect = false; Passengers.quickSort(0, Passengers.Count - 1, 1); loadPassengerList(Passengers); }
public FlightList muntipleSearch(int opc, string data) { FlightList aux = new FlightList(); switch (opc) { case 1: for (int i = 0; i < this.Count; i++) { int j; for (j = 0; j < data.Length; j++) { if (j < this[i].Route.Length) { if (this[i].Route[j] != data[j]) { break; } } else { break; } } if (j == data.Length) { aux.Add(this[i]); } } break; case 2: for (int i = 0; i < this.Count; i++) { if (this[i].Origin == data) { aux.Add(this[i]); } } break; case 3: for (int i = 0; i < this.Count; i++) { if (this[i].Destiny == data) { aux.Add(this[i]); } } break; } return(aux); }
public FlightsForm(FlightList flightList, PassengerList passengerList, Graph graph) { InitializeComponent(); PassengerList = passengerList; FlightList = flightList; FlightsGraph = graph; flightsListView.FullRowSelect = true; flightsListView.MultiSelect = false; FlightList.quickSort(0, FlightList.Count - 1, 3); loadFlights(FlightList); }
private Flight getSelectedFlight() { if (flightsListView.SelectedItems.Count > 0) { Flight aux = FlightList.searchFlightByRoute(flightsListView.SelectedItems[0].SubItems[0].Text); return(aux); } else { return(null); } }
public GraphForm(Graph graph, FlightList flights, PassengerList passengerList) { InitializeComponent(); this.graph = graph; Flights = flights; Passengers = passengerList; WillDraw = false; Drawed = false; foreach (var node in graph.NodeList) { cityComboBox.Items.Add(node.City); } }
private void loadFlights(FlightList flights) { flightsListView.Items.Clear(); foreach (var flight in flights) { string[] aux = new string[4]; aux[0] = flight.Route; aux[1] = flight.Cost.ToString(); aux[2] = flight.Time.ToString(); aux[3] = flight.aviableSeats().ToString(); ListViewItem item = new ListViewItem(aux); flightsListView.Items.Add(item); } }
public NewFlightForm(FlightList flightList, Graph graph) { InitializeComponent(); Flights = flightList; FlightsGraph = graph; foreach (Node node in FlightsGraph.NodeList) { originComboBox.Items.Add(node.City.ToString()); destinyComboBox.Items.Add(node.City.ToString()); } originComboBox.Items.Add("Nuevo"); destinyComboBox.Items.Add("Nuevo"); destinyTextBox.Hide(); originTextBox.Hide(); }
public void createGraph(FlightList flights) { foreach (Flight flight in flights) { addNode(flight.Origin[0]); addNode(flight.Destiny[0]); } foreach (Flight flight in flights) { foreach (Node node in NodeList) { if (flight.Origin[0] == node.City) { Node aux = searchNode(flight.Destiny[0]); if (aux.City != '@') { addEdge(node, aux, flight.Cost); } } } } }
private void registerFlightButton_Click(object sender, EventArgs e) { if (!System.Text.RegularExpressions.Regex.IsMatch(originTextBox.Text, "^[a-zA-Z]")) { newFlightErrorProvider.SetError(originTextBox, "Solo caracteres alfabeticos en el origen"); } else if (originTextBox.Text.Length > 1) { newFlightErrorProvider.SetError(originTextBox, "Solo un caracter en el origen"); } else if (!System.Text.RegularExpressions.Regex.IsMatch(destinyTextBox.Text, "^[a-zA-Z]")) { newFlightErrorProvider.SetError(destinyTextBox, "Solo caracteres alfabeticos en el destino"); } else if (destinyTextBox.Text.Length > 1) { newFlightErrorProvider.SetError(destinyTextBox, "Solo un caracter en el destino"); } else if (!System.Text.RegularExpressions.Regex.IsMatch(costTextBox.Text, "^[0-9]")) { newFlightErrorProvider.SetError(costTextBox, "Solo caracteres numericos en el costo"); } else if (!System.Text.RegularExpressions.Regex.IsMatch(timeTextBox.Text, "^[0-9]")) { newFlightErrorProvider.SetError(timeTextBox, "Solo caracteres numericos en el tiempo"); } else if (originTextBox.Text.Length == 0 || destinyTextBox.Text.Length == 0 || costTextBox.Text.Length == 0 || timeTextBox.TextLength == 0) { newFlightErrorProvider.SetError(registerFlightButton, "Los campos no pueden estar vacios"); } else if (originTextBox.Text == destinyTextBox.Text) { newFlightErrorProvider.SetError(registerFlightButton, "No se puede ir del mismo origen al mismo destino"); } else { Flight flight = new Flight(originTextBox.Text, destinyTextBox.Text, Int32.Parse(costTextBox.Text), Int32.Parse(timeTextBox.Text)); FlightList aux = Flights.muntipleSearch(1, flight.Route); if (aux.Count > 0) { newFlightErrorProvider.SetError(registerFlightButton, "El vuelo ya existe"); flight = null; } else { Flights.Add(flight); FlightsGraph.addNode(flight.Origin[0]); FlightsGraph.addNode(flight.Destiny[0]); Node aux1 = FlightsGraph.searchNode(flight.Origin[0]); Node aux2 = FlightsGraph.searchNode(flight.Destiny[0]); if (aux1.City != '@' && aux2.City != '@') { FlightsGraph.addEdge(aux1, aux2, flight.Cost); if (aux1.X == null) { GraphForm graphForm = new GraphForm(aux1, FlightsGraph); graphForm.ShowDialog(); } if (aux2.X == null) { GraphForm graphForm = new GraphForm(aux2, FlightsGraph); graphForm.ShowDialog(); } } this.Close(); } } }
static void Main() { FlightList flightList = new FlightList(); PassengerList passengerList = new PassengerList(); Graph graph = new Graph(); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); string flightsFile = "Flights.data"; string passengersFile = "Passengers.data"; string graphFile = "Graph.data"; if (File.Exists(passengersFile)) { using (Stream stream = File.Open(passengersFile, FileMode.Open)) { var bformater = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter(); passengerList = (PassengerList)bformater.Deserialize(stream); } } if (File.Exists(flightsFile)) { using (Stream stream = File.Open(flightsFile, FileMode.Open)) { var bformatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter(); flightList = (FlightList)bformatter.Deserialize(stream); } } else { Flight f1 = new Flight("a", "b", 600, 50); Flight f2 = new Flight("a", "f", 1050, 90); Flight f3 = new Flight("a", "g", 1150, 80); Flight f4 = new Flight("b", "a", 600, 50); Flight f5 = new Flight("b", "c", 750, 40); Flight f6 = new Flight("b", "d", 650, 60); Flight f7 = new Flight("b", "e", 1850, 70); Flight f8 = new Flight("c", "b", 800, 35); Flight f9 = new Flight("c", "e", 850, 50); Flight f10 = new Flight("e", "c", 750, 45); Flight f11 = new Flight("e", "g", 1150, 80); Flight f12 = new Flight("e", "l", 1650, 60); Flight f13 = new Flight("e", "d", 700, 35); Flight f14 = new Flight("d", "e", 900, 45); Flight f15 = new Flight("d", "b", 700, 55); Flight f16 = new Flight("f", "b", 800, 65); Flight f17 = new Flight("f", "l", 2850, 140); Flight f18 = new Flight("g", "a", 1250, 95); Flight f19 = new Flight("g", "e", 1175, 75); Flight f20 = new Flight("g", "l", 2675, 135); Flight f21 = new Flight("g", "u", 1400, 60); Flight f22 = new Flight("g", "h", 450, 25); Flight f23 = new Flight("h", "g", 350, 30); Flight f24 = new Flight("h", "i", 400, 35); Flight f25 = new Flight("i", "h", 400, 35); Flight f26 = new Flight("i", "k", 400, 35); Flight f27 = new Flight("k", "i", 400, 35); Flight f28 = new Flight("k", "j", 300, 25); Flight f29 = new Flight("j", "l", 750, 40); Flight f30 = new Flight("j", "m", 1450, 70); Flight f31 = new Flight("l", "m", 650, 40); Flight f32 = new Flight("l", "k", 700, 70); Flight f33 = new Flight("l", "e", 1550, 60); Flight f34 = new Flight("m", "l", 700, 40); flightList.Add(f1); flightList.Add(f2); flightList.Add(f3); flightList.Add(f4); flightList.Add(f5); flightList.Add(f6); flightList.Add(f7); flightList.Add(f8); flightList.Add(f9); flightList.Add(f10); flightList.Add(f11); flightList.Add(f12); flightList.Add(f13); flightList.Add(f14); flightList.Add(f15); flightList.Add(f16); flightList.Add(f17); flightList.Add(f18); flightList.Add(f19); flightList.Add(f20); flightList.Add(f21); flightList.Add(f22); flightList.Add(f23); flightList.Add(f24); flightList.Add(f25); flightList.Add(f26); flightList.Add(f27); flightList.Add(f28); flightList.Add(f29); flightList.Add(f30); flightList.Add(f31); flightList.Add(f32); flightList.Add(f33); flightList.Add(f34); } if (File.Exists(graphFile)) { using (Stream stream = File.Open(graphFile, FileMode.Open)) { var bformatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter(); graph = (Graph)bformatter.Deserialize(stream); } } else { graph.createGraph(flightList); } foreach (Node node in graph.NodeList) { bool drawed = true; do { if (node.X == null) { GraphForm graphForm = new GraphForm(node, graph); graphForm.ShowDialog(); drawed = graphForm.Drawed; } } while (!drawed); } flightList.quickSort(0, flightList.Count - 1, 3); passengerList.quickSort(0, passengerList.Count - 1, 1); MainForm mainWindow = new MainForm(flightList, passengerList, graph); mainWindow.ShowDialog(); File.Delete(graphFile); File.Delete(passengersFile); File.Delete(flightsFile); using (Stream graphStream = File.Open(graphFile, FileMode.Create)) { var bformatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter(); bformatter.Serialize(graphStream, graph); graphStream.Close(); } using (Stream passengerStream = File.Open(passengersFile, FileMode.Create)) { var bformatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter(); bformatter.Serialize(passengerStream, passengerList); passengerStream.Close(); } using (Stream flightStream = File.Open(flightsFile, FileMode.Create)) { var bformatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter(); bformatter.Serialize(flightStream, flightList); flightStream.Close(); } }