private void buttonVehicleDelete_Click(object sender, EventArgs e) { if (listBoxVehicle.SelectedItem != null) { if (listBoxVehicle.SelectedItem is Vehicle vehicle) { if (DBController.TryCheckOpenBookingVehicle(vehicle, out bool result)) { //If car isn't booked if (!result) { DialogResult dialog = Feedback.AskVehicleDelete(); if (dialog == DialogResult.Yes) { //Try delete vehicle if (DBController.TryDeleteVehicle(vehicle)) { if (!DBController.TryCheckVehicleTypeIsNeeded(vehicle)) { Feedback.ErrorDatabaseVehicleTypeDelete(); } Feedback.SuccessVehicleDelete(); FormController.MainView.UpdateVehicleList(); } else { Feedback.ErrorDatabaseVehicleDelete(); } } } else //If car is booked { Feedback.ErrorDatabaseBookedVehicleDelete(); } } else //If check fails { Feedback.ErrorDatabaseConnection(); } } else //If selected item isn't a vehicle { Feedback.ErrorNoValidSelectedItem(); } } else //If selected item is null { Feedback.ErrorNoSelectedItem(); } }