private void RemoveLastRental(object sender, EventArgs e) { if (rentals.Count < 1) { errorLabel.Text = ErrorMessages.NO_RENTALS_TO_REMOVE; timerClearErrors.Stop(); timerClearErrors.Start(); return; } string action = "remove the last rental"; FormConfirmation formConfirmation = new FormConfirmation(action); var result = formConfirmation.ShowDialog(); if (result != DialogResult.OK) { return; } Rental lastRental = rentals[rentals.Count - 1]; IDManagement.MarkRentalIDAsAvailable(lastRental.ID); lastRental.Selected = false; RemoveRental(lastRental); errorLabel.Text = ""; }
public void RemoveRental(Rental rental, bool makeRentalIDAvailable = true, bool makeVehicleIDAvailable = true) { if (makeRentalIDAvailable) { IDManagement.MarkRentalIDAsAvailable(rental.ID); } if (makeVehicleIDAvailable) { IDManagement.MarkVehicleIDAsAvailable(rental.Vehicle.ID); } rentedCarsElementsPanel.VerticalScroll.Value = 0; rentals.Remove(rental); PopulateRentalsPanel(); }
private void RemoveSelectedRentals(object sender, EventArgs e) { if (indexesOfSelectedRentals.Count > 0) { string action = "remove the selected rentals"; FormConfirmation formConfirmation = new FormConfirmation(action); var result = formConfirmation.ShowDialog(); if (result != DialogResult.OK) { return; } errorLabel.Text = ""; // Store the rentals to be removed in a temporary List List <Rental> rentalsToBeRemoved = new List <Rental>(); foreach (int index in indexesOfSelectedRentals) { short idToBeMarkedAsAvailable = rentals[index].ID; IDManagement.MarkRentalIDAsAvailable(idToBeMarkedAsAvailable); rentalsToBeRemoved.Add(rentals.ElementAt(index)); } // Remove the stored vehicles from the vehicles List foreach (Rental rental in rentalsToBeRemoved) { rentals.Remove(rental); } PopulateRentalsPanel(); indexesOfSelectedRentals.Clear(); } else { errorLabel.Text = ErrorMessages.NO_RENTALS_SELECTED; timerClearErrors.Stop(); timerClearErrors.Start(); } }