Beispiel #1
0
 public MainForm(FlightList flightList, PassengerList passengerList, Graph graph)
 {
     FlightList    = flightList;
     PassengerList = passengerList;
     FlightsGraph  = graph;
     InitializeComponent();
 }
Beispiel #2
0
        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 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);
 }
Beispiel #4
0
 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);
 }
Beispiel #5
0
 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 loadPassengerList(PassengerList passengerList)
 {
     passengersListView.Items.Clear();
     foreach (var passenger in passengerList)
     {
         string[] aux = new string[5];
         aux[0] = passenger.FirstName;
         aux[1] = passenger.LastName;
         aux[2] = passenger.Age.ToString();
         aux[3] = passenger.Flight;
         aux[4] = passenger.Seat.ToString();
         ListViewItem item = new ListViewItem(aux);
         passengersListView.Items.Add(item);
     }
 }
        public PassengerList multipleSearch(int opc, string data)
        {
            PassengerList aux = new PassengerList();

            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].FirstName.Length)
                        {
                            if (this[i].FirstName[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++)
                {
                    int j;
                    for (j = 0; j < data.Length; j++)
                    {
                        if (j < this[i].LastName.Length)
                        {
                            if (this[i].LastName[j] != data[j])
                            {
                                break;
                            }
                        }
                        else
                        {
                            break;
                        }
                    }
                    if (j == data.Length)
                    {
                        aux.Add(this[i]);
                    }
                }
                break;

            case 3:
                for (int i = 0; i < this.Count; i++)
                {
                    int j;
                    for (j = 0; j < data.Length; j++)
                    {
                        if (j < this[i].Flight.Length)
                        {
                            if (this[i].Flight[j] != data[j])
                            {
                                break;
                            }
                        }
                        else
                        {
                            break;
                        }
                    }
                    if (j == data.Length)
                    {
                        aux.Add(this[i]);
                    }
                }
                break;

            case 4:
                for (int i = 0; i < this.Count; i++)
                {
                    if (this[i].Seat == Int32.Parse(data))
                    {
                        aux.Add(this[i]);
                    }
                }
                break;

            default:
                break;
            }

            return(aux);
        }
        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();
            }
        }