Skip to content

Instantly share code, notes, and snippets.

@fado
Forked from LordNairu/refundTransaction.java
Last active August 29, 2015 14:06
Show Gist options
  • Save fado/cb5e9827b06c46043eab to your computer and use it in GitHub Desktop.
Save fado/cb5e9827b06c46043eab to your computer and use it in GitHub Desktop.
public void locateAndRefundTicket(int ticketID) {
Database database = new Database();
System.out.println(this.ticketHandler.getSoldTicketsList().size());
List<Ticket> ticketsToBeRemoved = new ArrayList<>();
for (Ticket ticket : this.ticketHandler.getSoldTicketsList()) {
if (ticket.getTicketID() == ticketID) {
ticket.setIsRefunded(true);
System.out.println("traced");
ticketsToBeRemoved.add(ticket);
try {
database.logRefundInRefundTable(ticket);
} catch (SQLException e) {
e.printStackTrace();
}
System.out.println("tracey");
}
}
for(Ticket ticket : ticketsToBeRemoved) {
this.ticketHandler.getSoldTicketsList().remove(ticket);
}
System.out.println("traces");
ScreenHandler.INSTANCE.updateRemainingSeats(
this.ticketHandler.getScreen(), this.ticketHandler);
System.out.println("tracedas");
System.out.println(this.ticketHandler.getSoldTicketsList().size());
}
public boolean locateTransactionAndRefund(int transactionID) throws SQLException {
Connection con = this.databaseConnect();
ResultSet results = getResults(con, SEARCH_FOR_TRANSACTION);
Boolean ticketFound = false;
TransactionHandler handlerToRefund = null;
int timesCalled = 0;
int handlerToSet = 0;
ArrayList <Integer> idList = new ArrayList<Integer> ();
while (results.next()){
if (transactionID == Integer.parseInt(results.getString("transaction_id"))){
ticketFound = true;
PreparedStatement deleteTransaction;
deleteTransaction = con.prepareStatement(DELETE_TRANSACTION);
deleteTransaction.setLong(1, transactionID);
deleteTransaction.executeUpdate();
idList.add(results.getInt("ticket_id"));
handlerToSet = results.getInt("screen_number");
}
}
timesCalled++;
if (timesCalled == 1){
handlerToRefund = SystemInfo.INSTANCE.getHandler(handlerToSet);
for (Integer ticketID : idList){
handlerToRefund.locateAndRefundTicket(ticketID);
}
}
return ticketFound;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment