private void buttonBooking_Click(object sender, EventArgs e) { passList.Add(paObj); //to file using (streamWrite = new StreamWriter("Passengers.txt", true)) { streamWrite.WriteLine(paObj.firstName); streamWrite.WriteLine(paObj.lastName); streamWrite.WriteLine(paObj.way); streamWrite.WriteLine(paObj.dateOfFlight.ToString()); streamWrite.WriteLine(paObj.row); streamWrite.WriteLine(paObj.seatAl); streamWrite.WriteLine(paObj.flightOfPassanger.FlightID); } MessageBox.Show("Passenger Ticket booked! \n" + paObj.firstName + "\n" + paObj.lastName + "\n" + paObj.row + paObj.seatAl + "\n" + paObj.dateOfFlight.ToShortDateString() + "\n" + paObj.way + "\n" + paObj.flightOfPassanger.takeOffDestination + "-" + paObj.flightOfPassanger.landingDestination, "Booking", MessageBoxButtons.OK); textBoxFIrstName.Text = null; textBoxLastName.Text = null; comboBoxFLight.Items.Clear(); comboBoxFLight.Text = null; dateTimePickerFlight.Value = DateTime.Now; radioButtonOneWay.Checked = true; radioButtonTwoWay.Checked = false; comboBoxRow.Text = null; comboBoxSeats.Text = null; paObj = new Passengers(); paObj.way = "One-way"; }
public Form1() { InitializeComponent(); dateTimePickerFlight.MinDate = DateTime.Now; DateTakeoff.MinDate = DateTime.Now; DateLanding.MinDate = DateTime.Now; //Loading from files //Flights using (streamRead = new StreamReader("Flights.txt")) { while (!streamRead.EndOfStream) { FliObj.FlightID = streamRead.ReadLine(); FliObj.takeOffDestination = streamRead.ReadLine(); FliObj.landingDestination = streamRead.ReadLine(); FliObj.DateTakeoff = Convert.ToDateTime(streamRead.ReadLine()); FliObj.DateLanding = Convert.ToDateTime(streamRead.ReadLine()); FliObj.stopOver = streamRead.ReadLine(); FliObj.planeType = streamRead.ReadLine(); fliList.Add(FliObj); FliObj = new Flight(); } } //Passengers using (streamRead = new StreamReader("Passengers.txt")) { string probe; while (!streamRead.EndOfStream) { paObj.firstName = streamRead.ReadLine(); paObj.lastName = streamRead.ReadLine(); paObj.way = streamRead.ReadLine(); paObj.dateOfFlight = Convert.ToDateTime(streamRead.ReadLine()); paObj.row = streamRead.ReadLine(); paObj.seatAl = streamRead.ReadLine(); probe = streamRead.ReadLine(); foreach (Flight a in fliList) { if (probe == a.FlightID) { paObj.flightOfPassanger = a; } } passList.Add(paObj); paObj = new Passengers(); } } paObj.way = "One-way"; }