// Cancel customer booking based on Seat selection private void btnCancelBooking(object sender, EventArgs e) { // clear messages lblMessages.Text = ""; // it only needs the seat selection. if not empty, REMOVE IT! try { string row = lstBoxRow.SelectedItem.ToString(); string seat = lstBoxSeat.SelectedItem.ToString(); string seatSelection = row + seat; // if seat is not occupied, present message if (AirplaneService.SeatStatus(seatSelection)) { lblMessages.Text = "Selected seat is empty."; ResetSelection(); // unselect and clears everything return; // forces the end of the method. } // at this point, removal of seat is possible. string warningMessage = "The removal of a customer will enforce the first name, if any, " + "on the waitlist to take it's place and cannot be undone.\r\n" + "Do you want to proceed?"; DialogResult result = MessageBox.Show(warningMessage, "Cancel Booking", MessageBoxButtons.YesNo); // user confirm he wants to proceed if (result == DialogResult.Yes) { AirplaneService.UnassignSeat(seatSelection); // get the first element of the waitlist. if (WaitlistService.HasNext()) { // Dequeue element and put on the txtName txtName.Text = WaitlistService.RemoveFromTheWaitlist(); // Assign the customer to the seat. btnBookSeat(sender, e); } btnShowWaitingList(sender, e); btnShowAllSeats(sender, e); ResetSelection(); } else { // clear form entirely ResetSelection(); } } // NRE is caused by the lstBoxRow and Seat. It means that seat was not properly selected. catch (NullReferenceException) { lblMessages.Text += "Select a seat first"; } }