/// <summary> /// Book flight on click /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btn_bookFlight_Click(object sender, RoutedEventArgs e) { try { Database db = new Database(); Insert insert = new Insert(); flightIndex = SelectedFlightIndex(); customerIndex = SelectedCustomerIndex(); // open connection MySqlConnection conn = db.CreateConnection(); conn.Open(); if (flightIndex != -1 && customerIndex != -1) { // booking flight if (insert.BookFlight(db.CreateCommand(conn), customerList[customerIndex], flightList[flightIndex])) { MessageBox.Show("Flight booked!"); } else { MessageBox.Show("Failed to book flight!"); } // close connection conn.Close(); } else { // Not selected MessageBox.Show("Please select both flight and customer to book a flight!"); } } catch (Exception ex) { MessageBox.Show("Book flight error: " + ex.Message.ToString()); } }