private void ToolStripButton_AddFlight_Click(object sender, EventArgs e) { FlightDialog fd = new FlightDialog(); if (fd.ShowDialog() == DialogResult.OK) { SaveFlight(fd); LoadFormData(); } }
private void ManageFlightToolStripMenuItem_Click(object sender, EventArgs e) { if (listView_Flights.SelectedItems.Count > 0) { int flightID = (int)listView_Flights.SelectedItems[0].Tag; FlightDialog fd = new FlightDialog((int)listView_Flights.SelectedItems[0].Tag); if (fd.ShowDialog() == DialogResult.OK) { SaveFlight(fd, flightID); LoadFormData(); } } }
private void SaveFlight(FlightDialog fd, int flightID = 0) { var flight = new Flight(flightID, fd.dateTimePicker_DepartureTime.Value, fd.dateTimePicker_ArrivalTime.Value, fd.StartLocation, fd.EndLocation, Convert.ToDecimal(fd.textBox_Cost.Text)); Database.SaveFlight(ref flight); var boardingPasses = flight.Reservations; foreach (var boardingPass in boardingPasses) { if (boardingPass.Issued) { boardingPass.Issued = false; boardingPass.SeatID = 0; Database.SaveBoardingPass(boardingPass); } } var connection = Database.OpenConnection(); var seats = flight.Seats; Database.ClearSeats(connection, flight.ID); for (int i = 0; i < Convert.ToInt32(fd.textBox_FirstClassRows.Text); i++) { for (int j = 0; j < 10; j++) { Database.SaveSeat(connection, new Seat(0, string.Format("{0}{1}", i + 1, Convert.ToChar(j + 65)), "First Class", 0, flight.ID)); } } for (int i = 0; i < Convert.ToInt32(fd.textBox_BusinessClassRows.Text); i++) { for (int j = 0; j < 10; j++) { Database.SaveSeat(connection, new Seat(0, string.Format("{0}{1}", i + 1, Convert.ToChar(j + 65)), "Business Class", 0, flight.ID)); } } for (int i = 0; i < Convert.ToInt32(fd.textBox_EconomyClassRows.Text); i++) { for (int j = 0; j < 10; j++) { Database.SaveSeat(connection, new Seat(0, string.Format("{0}{1}", i + 1, Convert.ToChar(j + 65)), "Economy Class", 0, flight.ID)); } } connection.Close(); }