Event Reservation System Documentation

83
Event Reservation System Documentation Release 1.0 Event Reservation System Mar 02, 2017

Transcript of Event Reservation System Documentation

Page 1: Event Reservation System Documentation

Event Reservation SystemDocumentation

Release 1.0

Event Reservation System

Mar 02, 2017

Page 2: Event Reservation System Documentation
Page 3: Event Reservation System Documentation

Contents

1 User Guide 3

2 Developer Guide 17

i

Page 4: Event Reservation System Documentation

ii

Page 5: Event Reservation System Documentation

Event Reservation System Documentation, Release 1.0

Team itudb1420

Members

• Edagül Erten

• Aysenur Genç

• Ezgi Deveci

• Rıdvan Çilli

• Halim Beyden

There has been an important advancement in the field of technology over past few decades. These developmentmade it possible for human being to take care of their daily issues easily. For instance, people can make their dailyshopping at home, even they can buy their tickets for any event on internet. Therefore, our project aims to providepeople an event reservation system that holds the activities such theater, cinema, concert, fair and exhibition.

Contents:

Contents 1

Page 6: Event Reservation System Documentation

Event Reservation System Documentation, Release 1.0

2 Contents

Page 7: Event Reservation System Documentation

CHAPTER 1

User Guide

Event Reservation System

Our project aims to provide people an event reservation system that holds the activities such theater, cinema,concert, fair and exhibition.Users can reach the event that they are interested in both links at the top of the homepage and sliders which are supported by a general photo of every event type.

Fig. 1.1: Event Pages

Users also can reach the events via a slider on the homepage.

There is also links named ‘Hakkında’ and ‘Iletisim’ to inform people about us. ‘Hakkında’ Page informs usersabout our project group. ‘Iletisim’ Page makes it possible for users to reach contact information of all groupmembers.

3

Page 8: Event Reservation System Documentation

Event Reservation System Documentation, Release 1.0

About Page informs users about our project group.

Contact Page makes it possible for users to reach contact informations of all group members.

Theatre Page

Theatre Base Page

Theatre Base Page is responsible for showing the theatre events to the user, adding, deleting and updating thetheatres. There is a calendar at the left of the pages which supplies to filter the theatres according to their dates.

It is possible to add new theatres by using ‘YENI TIYATRO EKLE’ button below the calendar.

The users can see the all theatres at the right side of the page if they didn’t filter them. After filtering, they canreach the theatres which are in suitable dates.

Theatre Details Page

After clicking one of the theatres the details of the theatre and delete-update buttons are shown up as in the figurebelow.

If the user make a reservation by clicking ‘HEMEN REZERVASYON YAP’ button, available ticket numbers aredecreased by 1.

To delete an event, it is enough to click ‘TIYATRO SIL’ and then ‘EVET’.

4 Chapter 1. User Guide

Page 9: Event Reservation System Documentation

Event Reservation System Documentation, Release 1.0

Fig. 1.2: Calender

Fig. 1.3: Theatres

1.1. Theatre Page 5

Page 10: Event Reservation System Documentation

Event Reservation System Documentation, Release 1.0

Fig. 1.4: Theatre Details

6 Chapter 1. User Guide

Page 11: Event Reservation System Documentation

Event Reservation System Documentation, Release 1.0

To update an event, the user should click the button named ‘TIYATROYU DÜZENLE’, enter the new values andclick ‘KAYDET’ button as the final step.

Fair Page

Fair Base Page

Fair Base Page is responsible for showing the fairs to the user, adding, deleting and updating the fair events. Thereis a calendar at the left of the pages which supplies to filter the fairs according to their dates.

Fig. 1.5: Calender

The user can add new fairs using ‘YENI FUAR EKLE’ button below the calendar.

The users are able to reach all fairs at the right side of the page if they didn’t filter them. After filtering, they canreach the fairs which are in suitable dates.

Fair Details Page

After clicking one of the fairs, the details of the fair and delete-update buttons are shown up as in the figure below.

If the user make a reservation by clicking ‘HEMEN REZERVASYON YAP’ button, available ticket numbers aredecreased by 1.

To delete a fair, it is enough to click ‘BU FUARI SIL’ and then ‘EVET’.

To update an event, the user should click the button named ‘BU FUARI DÜZENLE’, enter the new values andclick ‘KAYDET’ button as the final step.

1.2. Fair Page 7

Page 12: Event Reservation System Documentation

Event Reservation System Documentation, Release 1.0

Fig. 1.6: Fairs

Fig. 1.7: Fair Details

8 Chapter 1. User Guide

Page 13: Event Reservation System Documentation

Event Reservation System Documentation, Release 1.0

Concert Page

Concert Base Page

Concert Base Page is responsible for showing the fairs to the user, adding, deleting and updating the fair events.There is a calendar at the left of the pages which supplies to filter the concerts according to their dates.

Fig. 1.8: Calender

The user can add new concerts using ‘YENI KONSER EKLE’ button below the calendar.

The users are able to reach all concerts at the right side of the page if they didn’t filter them. After filtering, theycan reach the concerts which are in suitable dates.

Concert Details Page

After clicking one of the concerts, the details of the concert and delete-update buttons are shown up as in the figurebelow.

1.3. Concert Page 9

Page 14: Event Reservation System Documentation

Event Reservation System Documentation, Release 1.0

Fig. 1.9: Concerts

Fig. 1.10: Concert Details

10 Chapter 1. User Guide

Page 15: Event Reservation System Documentation

Event Reservation System Documentation, Release 1.0

If the user make a reservation by clicking ‘HEMEN REZERVASYON YAP’ button, available ticket numbers aredecreased by 1.

To delete a concert, it is enough to click ‘BU KONSERI SIL’ and then ‘EVET’.

To update an event, the user should click the button named ‘BU KONSERI DÜZENLE’, enter the new values andclick ‘KAYDET’ button as the final step.

Movie Page

Movie Base Page

Movie Base Page is responsible for showing the movies to the user, adding, deleting and updating the fair events.There is a calendar at the left of the pages which supplies to filter the movies according to their dates.

The user can add new movies using ‘YENI FILM EKLE’ button below the calendar.

The users are able to reach all movies at the right side of the page if they didn’t filter them. After filtering, theycan reach the movies which are in suitable dates.

Movie Details Page

After clicking one of the movies, the details of the movie and delete-update buttons are shown up as in the figurebelow.

1.4. Movie Page 11

Page 16: Event Reservation System Documentation

Event Reservation System Documentation, Release 1.0

Fig. 1.11: Calender

Fig. 1.12: Movies

Fig. 1.13: Movie Details

12 Chapter 1. User Guide

Page 17: Event Reservation System Documentation

Event Reservation System Documentation, Release 1.0

If the user make a reservation by clicking ‘HEMEN REZERVASYON YAP’ button, available ticket numbers aredecreased by 1.

To delete a movie, it is enough to click ‘FILMI SIL’ and then ‘EVET’.

To update an event, the user should click the button named ‘FILMI DÜZENLE’, enter the new values and click‘KAYDET’ button as the final step.

Exhibition Page

Exhibition Base Page

Exhibition Base Page is responsible for showing the exhibitions to the user, adding, deleting and updating the fairevents. There is a calendar at the left of the pages which supplies to filter the exhibitions according to their dates.

The user can add new exhibitions using ‘YENI SERGI EKLE’ button below the calendar.

The users are able to reach all exhibitions at the right side of the page if they didn’t filter them. After filtering,they can reach the exhibitions which are in suitable dates.

Exhibition Details Page

1.5. Exhibition Page 13

Page 18: Event Reservation System Documentation

Event Reservation System Documentation, Release 1.0

Fig. 1.14: Calender

Fig. 1.15: Exhibitions

14 Chapter 1. User Guide

Page 19: Event Reservation System Documentation

Event Reservation System Documentation, Release 1.0

After clicking one of the exhibitions, the details of the exhibition and delete-update buttons are shown up as in thefigure below.

Fig. 1.16: Exhibition Details

If the user make a reservation by clicking ‘HEMEN REZERVASYON YAP’ button, available ticket numbers aredecreased by 1.

To delete an exhibition, it is enough to click ‘BU SERGIYI SIL’ and then ‘EVET’.

To update an event, the user should click the button named ‘BU SERGIYI DÜZENLE’, enter the new values andclick ‘KAYDET’ button as the final step.

1.5. Exhibition Page 15

Page 20: Event Reservation System Documentation

Event Reservation System Documentation, Release 1.0

16 Chapter 1. User Guide

Page 21: Event Reservation System Documentation

CHAPTER 2

Developer Guide

Database Design

We used 9 tables to design our database. First 4 table (City , City_Match, Date_Match, Person) are common table.They are used in relative pages.

• City

• City_Match

• Date_Match

• Person

• Concert

• Exhibition

• Fair

• Movie

• Theatre

City Table

Fig. 2.1: City Table

In this table we keep id and name of cities. Because there are certain number of cities in Turkey and when a tupleis created for concert, theatre... ext. we have to initialize the city column. Therefore, we created a table city andwe kept all cities in Turkey.

Table contents are like this;

17

Page 22: Event Reservation System Documentation

Event Reservation System Documentation, Release 1.0

There is a part of all cities that figure shows:

City_Match Table

In this table we kept countries of events.

CId for city Id,EvId for id of event and EvType for event type type(Theatre=1, Movie=2, Exhibition=3,Fair=4,Concert=5).

Table content like this;

Here is sample of some city match.

Date_Match Table

This table keep data of which event is on which date.

Table content like this;

Date match of all events are kept in this table.

Person

In this table we kept the people who are directors, writers and musicians. We defined an id for every person andname of the person.

The figure above shows some samples of person table.

E/R Diagram

Code

There is an initalization button for database in Home Page that makes possible to reset all datas according to‘init.sql’ file.:

public class HomePage extends BasePage {public HomePage() {

Form initForm = new InitForm("initForm");this.add(initForm);

}}

There is the class of Navigation bar :

18 Chapter 2. Developer Guide

Page 23: Event Reservation System Documentation

Event Reservation System Documentation, Release 1.0

Fig. 2.2: Date Match Table

Fig. 2.3: Person Table

Fig. 2.4: Contents

2.2. Code 19

Page 24: Event Reservation System Documentation

Event Reservation System Documentation, Release 1.0

Fig. 2.5: E/R Diagram of Database

public class NavigationPanel extends Panel {public NavigationPanel(String id) {

super(id);}

}

We defined all cities in Turkey for all developers to specify the places of their events and Navigationbar is addedto Basepage. All pages that we created are extended from ‘BasePage.java’:

public class BasePage extends WebPage {protected static final long serialVersionUID = 1L;protected static final List<String> Cities = Arrays.asList(new String[] {

"Adana", "Adıyaman", "Afyon", "Agrı", "Amasya", "Ankara","Antalya", "Artvin", "Aydın", "Balıkesir", "Bilecik", "Bingöl","Bitlis", "Bolu", "Burdur", "Bursa", "Çanakkale", "Çankırı","Çorum", "Denizli", "Diyarbakır", "Edirne", "Elazıg", "Erzincan","Erzurum", "Eskisehir", "Gaziantep", "Giresun", "Gümüshane","Hakkari", "Hatay", "Isparta", "Içel", "Istanbul", "Izmir", "Kars","Kastamonu", "Kayseri", "Kırklareli", "Kırsehir", "Kocaeli","Konya", "Kütahya", "Malatya", "Manisa", "K.maras", "Mardin","Mugla", "Mus", "Nevsehir", "Nigde", "Ordu", "Rize", "Sakarya","Samsun", "Siirt", "Sinop", "Sivas", "Tekirdag", "Tokat","Trabzon", "Tunceli", "Sanlıurfa", "Usak", "Van", "Yozgat","Zonguldak", "Aksaray", "Bayburt", "Karaman", "Kırıkkale","Batman", "Sırnak", "Bartın", "Ardahan", "Igdır", "Yalova","Karabük", "Kilis", "Osmaniye", "Düzce" });

protected static final List<String> FairTypes = Arrays.asList(new String[] {"Ihtisas Fuarı", "Uluslararası Ihtisas Fuarı" });

protected static final IModel<String> defaultCity = new Model<String>("Adana");

public BasePage() {this(null);

}

public BasePage(IModel model) {super(model);

20 Chapter 2. Developer Guide

Page 25: Event Reservation System Documentation

Event Reservation System Documentation, Release 1.0

this.add(new NavigationPanel("orangeNav"));}}

This class below makes it possible to ensure the connection of our database and wicket application :

public class ConnectionDB {public static Connection conn = null;

static {

try {Class.forName("org.sqlite.JDBC");String homeDir = System.getProperty("user.home");String dbFilePath = "jdbc:sqlite:" + homeDir + File.separator

+ "Events.sqlite";if (conn == null) {

Locale.setDefault(new Locale("tr", "TR"));conn = DriverManager.getConnection(dbFilePath);

}

} catch (Exception e) {System.err.println(e.getClass().getName() + ": " + e.getMessage());System.exit(0);

}System.out.println("Opened database successfully");

}}

InitForm class defines the initilization button for database :

public class InitForm extends Form {

public InitForm(String id) {super(id);this.add(new FeedbackPanel("feedback"));

}

public void onSubmit() {WicketApplication app = (WicketApplication) this.getApplication();ServletContext context = app.getServletContext();InitDatabase IDatabase = new InitDatabase();IDatabase.Initialize(context);info("Initialize Edildi.");

}}

We created About Page and Cantact Page without using any Java method. Arrangments are made in html.

public class AboutBasePage extends BasePage {public AboutBasePage() {}

}

public class ContactBasePage extends BasePage {public ContactBasePage() {}

}

WicketApplication class makes it possible to connect all the pages which are Concert, Theatre, Homepage, Fair,Cinema, Exhibition, Contact and About.

2.2. Code 21

Page 26: Event Reservation System Documentation

Event Reservation System Documentation, Release 1.0

public class WicketApplication extends WebApplication {public void init() {

super.init();mountPage("/Concert", ConcertBasePage.class);mountPage("/HomePage", HomePage.class);mountPage("/Theatre", TheatreBasePage.class);mountPage("/Fair", FairBasePage.class);mountPage("/Cinema", MovieBasePage.class);mountPage("/Exhibition", ExhibitionBasePage.class);mountPage("/Contact", ContactBasePage.class);mountPage("/About", AboutBasePage.class);

}

public Class<? extends WebPage> getHomePage() {return HomePage.class;

}}

Theatre Page

Theatre Database Design

Theatre Table

Fig. 2.6: Theatre Table

In this table we kept data for id, title, writer id , city id, capacity of saloon, available ticket and status of theatre isdeleted or not.

Table is created like this;

Here is some samples of theatres:

Code

Theatre class consists of Id, Title, Writer, City, Capacity, tDate, AvailableTicket and Deleted.:

22 Chapter 2. Developer Guide

Page 27: Event Reservation System Documentation

Event Reservation System Documentation, Release 1.0

Fig. 2.7: Theatre Michelangelo which has an id 1 has a writer named Irmak Bahçeci where Id = 1. City of theevent is Istanbul (CityId=34) and capacity of theatre is 100. All tickets are available because the number of it isequal to the number of capacity.

public class Theatre {public Integer Id = null;public String Title = null;public String Writer = null;public String City = null;public Integer Capacity = null;public Date tDate = null;public Integer AvailableTicket = null;public Boolean Deleted = null;

public Theatre() {}

}

TheatreBasePage shows all theatres without filtering and makes it possible to filter the thatre events. It providesto add new theatres to database.

public class TheatreBasePage extends BasePage {private static final long serialVersionUID = 1L;

public TheatreBasePage(final PageParameters parameters) {

final DropDownChoice<String> listCities = new DropDownChoice<String>("cityInput", defaultCity, Cities);

listCities.setRequired(true);

final TextField<String> titleInput = new TextField<String>("titleInput", Model.of(""));

titleInput.setRequired(true);

final TextField<String> writerInput = new TextField<String>("writerInput", Model.of(""));

writerInput.setRequired(true);

final NumberTextField<Integer> capacityInput = new NumberTextField<Integer>("capacityInput", new Model(), Integer.class);

capacityInput.add(RangeValidator.minimum(0));capacityInput.setRequired(true);

final TextField<String> DateInput = new TextField<String>("startDateInput", Model.of(""));

DateInput.setRequired(true);

Form<?> addTheatreForm = new Form<Void>("addTheatreForm") {

private static final long serialVersionUID = 1L;

@Overrideprotected void onSubmit() {

String selectedCity = listCities.getModelObject();String newTitle = titleInput.getModelObject();String newWriter = writerInput.getModelObject();

2.2. Code 23

Page 28: Event Reservation System Documentation

Event Reservation System Documentation, Release 1.0

int newCapacity = capacityInput.getModelObject();String newDate = DateInput.getModelObject();SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");

Theatre th = new Theatre();th.Title = newTitle;th.Writer = newWriter;th.Capacity = newCapacity;th.AvailableTicket = newCapacity;th.City = selectedCity;

try {th.tDate = formatter.parse(newDate);

} catch (ParseException e) {// TODO Auto-generated catch blockth.tDate = null;

}

TheatreCollection collection = new TheatreCollection();

collection.AddTheatre(th);setResponsePage(TheatreBasePage.class, getPageParameters());

}};add(addTheatreForm);addTheatreForm.add(listCities);addTheatreForm.add(titleInput);addTheatreForm.add(writerInput);addTheatreForm.add(capacityInput);addTheatreForm.add(DateInput);

final TextField<String> baslangic = new TextField<String>("baslangicTarihi", Model.of(""));

final TextField<String> bitis = new TextField<String>("bitistarihi",Model.of(""));

Form<?> form = new Form<Void>("tarihForm") {private static final long serialVersionUID = 1L;

@Overrideprotected void onSubmit() {

PageParameters pageParameters = new PageParameters();pageParameters.add("baslangicTarihi",

baslangic.getModelObject());pageParameters.add("bitistarihi", bitis.getModelObject());setResponsePage(TheatreBasePage.class, pageParameters);

}};add(form);form.add(baslangic);form.add(bitis);final SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");

Date tarihbaslangic = null;Date tarihbitis = null;if (parameters.getNamedKeys().contains("baslangicTarihi")) {

try {String baslangic_new = parameters.get("baslangicTarihi")

.toString();tarihbaslangic = formatter.parse(baslangic_new);

} catch (ParseException e) {e.printStackTrace();

}}

24 Chapter 2. Developer Guide

Page 29: Event Reservation System Documentation

Event Reservation System Documentation, Release 1.0

if (parameters.getNamedKeys().contains("bitistarihi")) {try {

String bitis_new = parameters.get("bitistarihi").toString();tarihbitis = formatter.parse(bitis_new);

} catch (ParseException e) {e.printStackTrace();

}}

TheatreCollection collection = new TheatreCollection();String query = "";PreparedStatement statement;List<Theatre> theatre;try {

if (parameters.getNamedKeys().contains("bitistarihi")&& parameters.getNamedKeys().contains("baslangicTarihi")) {

theatre = TheatreCollection.GetTheatreWithDate(tarihbaslangic,tarihbitis);

} else {theatre = collection.getAll();

}

final SimpleDateFormat formatter1 = new SimpleDateFormat("dd MMMM yyyy \n EEEE");

PropertyListView theatreListView = new PropertyListView("theatre_list", theatre) {

@Overrideprotected void populateItem(ListItem item) {

Theatre th = (Theatre) item.getModelObject();TheatreDetailsPageLink theatreLink = new TheatreDetailsPageLink(

"theatre_link", th);theatreLink.add(new Label("title", th.Title));theatreLink.add(new Label("writer", th.Writer));theatreLink.add(new Label("city", th.City));theatreLink.add(new Label("date", formatter1

.format(th.tDate)));theatreLink.add(new Label("capacity", th.Capacity));theatreLink.add(new Image("image",

new ContextRelativeResource("/images/theatre/"+ th.Id + ".jpg")));

item.add(theatreLink);}

};this.add(theatreListView);parameters.clearNamed();

} catch (Exception e) {e.printStackTrace();

}

}}

TheatreCollection provides us to add, delete, update, search theatres according to their start date.

public class TheatreCollection {private static List<Theatre> _theatre;

public TheatreCollection() {_theatre = getAll();

}

2.2. Code 25

Page 30: Event Reservation System Documentation

Event Reservation System Documentation, Release 1.0

public static List<Theatre> GetTheatreWithDate(Date startDate, Date endDate) {_theatre = new ArrayList<Theatre>();

String query = "SELECT t.*,dm.StartDate as tDate,p.Name as Writer,c.Name as→˓City_Name FROM Theatre t JOIN Date_Match dm on dm.EventId=t.Id AND dm.→˓EventType=1 JOIN City c on c.Id=t.CityID JOIN Person p on t.writerId = p.Id;";

Connection connection = null;ResultSet resultSet = null;Statement statement = null;

try {connection = ConnectionDB.conn;statement = connection.createStatement();resultSet = statement.executeQuery(query);while (resultSet.next()) {

SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");Date sdate = formatter.parse(resultSet.getString("tDate"));if (sdate.after(endDate) || sdate.before(startDate))

continue;Theatre th = new Theatre();th.Id = resultSet.getInt("Id");th.Title = resultSet.getString("Title");th.Writer = resultSet.getString("Writer");th.City = resultSet.getString("City_Name");th.tDate = resultSet.getDate("tDate");th.Capacity = resultSet.getInt("Capacity");th.AvailableTicket = resultSet.getInt("AvailableTicket");th.Deleted = resultSet.getBoolean("Deleted");_theatre.add(th);

}return _theatre;

} catch (Exception e) {e.printStackTrace();

}return null;

}

public List<Theatre> getAll() {List<Theatre> all = new ArrayList();

String query = "SELECT t.*,dm.StartDate as tDate,p.Name as Writer,c.Name as→˓City_Name FROM theatre t JOIN Date_Match dm on dm.EventId=t.Id AND dm.→˓EventType=1 JOIN City c on c.Id=t.CityID JOIN Person p on t.writerId = p.Id;";

Connection connection = null;ResultSet resultSet = null;Statement statement = null;

try {connection = ConnectionDB.conn;statement = connection.createStatement();resultSet = statement.executeQuery(query);SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");while (resultSet.next()) {

Theatre th = new Theatre();th.Id = resultSet.getInt("Id");th.Title = resultSet.getString("Title");th.Writer = resultSet.getString("Writer");th.City = resultSet.getString("City_Name");String sdate = resultSet.getString("tDate");th.tDate = formatter.parse(sdate);th.Capacity = resultSet.getInt("Capacity");th.AvailableTicket = resultSet.getInt("AvailableTicket");

26 Chapter 2. Developer Guide

Page 31: Event Reservation System Documentation

Event Reservation System Documentation, Release 1.0

th.Deleted = resultSet.getBoolean("Deleted");all.add(th);

}return all;

} catch (Exception e) {e.printStackTrace();

}return null;

}

public Theatre getByID(int id) {Theatre th = new Theatre();

Connection connection = null;ResultSet resultSet = null;Statement statement = null;

String selectSQL = "SELECT t.*,dm.StartDate as tDate,p.Name as Writer,c.Name→˓as City_Name FROM theatre t JOIN Date_Match dm on dm.EventId=t.Id AND dm.→˓EventType=1 JOIN City c on c.Id=t.CityID JOIN Person p on t.writerId = p.Id→˓WHERE Id ="

+ id;try {

connection = ConnectionDB.conn;statement = connection.createStatement();resultSet = statement.executeQuery(selectSQL);SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");while (resultSet.next()) {

th.Id = resultSet.getInt("Id");th.Title = resultSet.getString("Title");th.Writer = resultSet.getString("Writer");th.City = resultSet.getString("City_Name");String sdate = resultSet.getString("tDate");th.tDate = formatter.parse(sdate);th.Capacity = resultSet.getInt("Capacity");th.AvailableTicket = resultSet.getInt("AvailableTicket");th.Deleted = resultSet.getBoolean("Deleted");

}

return th;} catch (Exception e) {

e.printStackTrace();}

finally {try {

resultSet.close();statement.close();connection.close();

} catch (Exception e) {e.printStackTrace();

}}

return null;}

// Add theatrepublic static void AddTheatre(Theatre newTheatre) {

Connection connection = ConnectionDB.conn;Statement statement = null;ResultSet resultSet = null;PreparedStatement preStatement = null;

2.2. Code 27

Page 32: Event Reservation System Documentation

Event Reservation System Documentation, Release 1.0

String query;

int writerID = -1;

// if existsString exist = "Select Id from Person where Name='" + newTheatre.Writer

+ "'";try {

statement = ConnectionDB.conn.createStatement();resultSet = statement.executeQuery(exist);if (resultSet.next()) {

writerID = resultSet.getInt("Id");} else {

query = "Insert Into Person(Name) Values('" + newTheatre.Writer+ "')";

try {preStatement = connection.prepareStatement(query,

Statement.RETURN_GENERATED_KEYS);preStatement.executeUpdate();ResultSet rset = preStatement.getGeneratedKeys();if (rset.next())

writerID = rset.getInt(1);} catch (Exception e) {

e.printStackTrace();}

}} catch (Exception e) {

e.printStackTrace();}

int cityID = -1;query = "SELECT Id FROM City WHERE Name='" + newTheatre.City + "'";try {

statement = ConnectionDB.conn.createStatement();resultSet = statement.executeQuery(query);if (resultSet.next())

cityID = resultSet.getInt("Id");} catch (Exception e) {

e.printStackTrace();}

int insertedID = -1;query = "INSERT INTO theatre (Title,WriterId,CityID,Capacity,AvailableTicket)

→˓"+ "VALUES ('"+ newTheatre.Title+ "','"+ writerID+ "','"+ cityID+ "','"+ newTheatre.Capacity+ "','"+ newTheatre.AvailableTicket + "')";

try {

preStatement = connection.prepareStatement(query,Statement.RETURN_GENERATED_KEYS);

preStatement.executeUpdate();ResultSet rset = preStatement.getGeneratedKeys();if (rset.next())

insertedID = rset.getInt(1);

28 Chapter 2. Developer Guide

Page 33: Event Reservation System Documentation

Event Reservation System Documentation, Release 1.0

} catch (Exception e) {e.printStackTrace();

}

/** query = "INSERT INTO City_Match " + cityID + "," + insertedID + ",1";

* try { statement = ConnectionDB.conn.createStatement();

* statement.executeUpdate(query); } catch (Exception e) {

* e.printStackTrace(); } finally { try { statement.close(); } catch

* (Exception e) { e.printStackTrace(); } }

*/Calendar cal = Calendar.getInstance();cal.setTime(newTheatre.tDate);int Syear = cal.get(Calendar.YEAR);int Smonth = cal.get(Calendar.MONTH) + 1;int Sday = cal.get(Calendar.DAY_OF_MONTH);cal.setTime(newTheatre.tDate);int Eyear = cal.get(Calendar.YEAR);int Emonth = cal.get(Calendar.MONTH) + 1;int Eday = cal.get(Calendar.DAY_OF_MONTH);

query = "INSERT INTO Date_Match VALUES (" + insertedID + ",1,'" + Syear+ "-" + ((Smonth < 10) ? ("0" + Smonth) : Smonth) + "-"+ ((Sday < 10) ? ("0" + Sday) : Sday) + "','" + Eyear + "-"+ ((Emonth < 10) ? ("0" + Emonth) : Emonth) + "-"+ ((Eday < 10) ? ("0" + Eday) : Eday) + "');";

try {statement = ConnectionDB.conn.createStatement();statement.executeUpdate(query);

} catch (Exception e) {e.printStackTrace();

}_theatre.add(newTheatre);

}

// Delete Theatrepublic static void DeleteTheatre(int TheatreId) {

String query = "DELETE FROM Theatre WHERE Id=" + TheatreId;try {

ConnectionDB.conn.createStatement().executeUpdate(query);} catch (Exception e) {

e.printStackTrace();}

query = "DELETE FROM Date_Match WHERE EventId=" + TheatreId+ " AND EventType=1";

try {ConnectionDB.conn.createStatement().executeUpdate(query);

} catch (Exception e) {e.printStackTrace();

}

/** query = "DELETE FROM City_Match WHERE EventId=" + TheatreId +

* " AND EventType=1"; try {

* ConnectionDB.conn.createStatement().executeUpdate(query); } catch

* (Exception e) { e.printStackTrace(); }

*/

}

// Update Theatrepublic static void UpdateTheatre(Theatre theatre) {

2.2. Code 29

Page 34: Event Reservation System Documentation

Event Reservation System Documentation, Release 1.0

PreparedStatement preparedStatement;Statement statement = null;ResultSet resultSet = null;int cityID = -1;int writerId = -1;try {

// CityString query = "SELECT Id FROM City WHERE Name='" + theatre.City

+ "'";statement = ConnectionDB.conn.createStatement();resultSet = statement.executeQuery(query);if (resultSet.next())

cityID = resultSet.getInt("Id");// ////////////////////// Musician From Personquery = "SELECT Id FROM Person WHERE Name='" + theatre.Writer + "'";resultSet = statement.executeQuery(query);if (resultSet.next())

writerId = resultSet.getInt("Id");if (writerId == -1) {

query = "insert into Person(Name) values('" + theatre.Writer+ "');";

preparedStatement = ConnectionDB.conn.prepareStatement(query,Statement.RETURN_GENERATED_KEYS);

preparedStatement.executeUpdate();ResultSet rset = preparedStatement.getGeneratedKeys();if (rset.next())

writerId = rset.getInt(1);} else

writerId = writerId;

preparedStatement = ConnectionDB.conn.prepareStatement("update theatre Set Title=?, WriterId=?,

→˓CityId=?, Capacity=?, AvailableTicket=? where Id=?");preparedStatement.setString(1, theatre.Title);preparedStatement.setInt(2, writerId);preparedStatement.setInt(3, cityID);preparedStatement.setInt(4, theatre.Capacity);preparedStatement.setInt(5, theatre.AvailableTicket);preparedStatement.setInt(6, theatre.Id);preparedStatement.executeUpdate();

Calendar cal = Calendar.getInstance();cal.setTime(theatre.tDate);int year = cal.get(Calendar.YEAR);int month = cal.get(Calendar.MONTH) + 1;int day = cal.get(Calendar.DAY_OF_MONTH);String dateSubQueryString = year + "-"

+ ((month < 10) ? ("0" + month) : month) + "-"+ ((day < 10) ? ("0" + day) : day);

preparedStatement = ConnectionDB.conn.prepareStatement("update Date_Match Set StartDate=?, EndDate=?

→˓where EventType=1 AND EventId=?");preparedStatement.setString(1, dateSubQueryString);preparedStatement.setString(2, dateSubQueryString);preparedStatement.setInt(3, theatre.Id);preparedStatement.executeUpdate();

} catch (Exception e) {e.printStackTrace();

}}

public List<Theatre> getTheatreWithQuery(PreparedStatement preparedStatement) {

30 Chapter 2. Developer Guide

Page 35: Event Reservation System Documentation

Event Reservation System Documentation, Release 1.0

List<Theatre> theatre = new ArrayList();Theatre th = new Theatre();try {

System.out.println(preparedStatement.toString());ResultSet resultSet = preparedStatement.executeQuery();SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");while (resultSet.next()) {

th = new Theatre();th.Id = resultSet.getInt("Id");th.Title = resultSet.getString("Title");th.Writer = resultSet.getString("Writer");th.City = resultSet.getString("City_Name");String sdate = resultSet.getString("tDate");th.tDate = formatter.parse(sdate);th.Capacity = resultSet.getInt("Capacity");th.AvailableTicket = resultSet.getInt("AvailableTicket");th.Deleted = resultSet.getBoolean("Deleted");_theatre.add(th);

}return theatre;

} catch (Exception e) {// TODO Auto-generated catch blocke.printStackTrace();return null;

}}

}

TheatreDetailsPage shows the selected theatre and makes it possible to delete and update the event. Also, there isa form to update the events. We used Ajax to show the Available tickets without refreshing the page.

public class TheatreCollection {private static List<Theatre> _theatre;

public TheatreCollection() {_theatre = getAll();

}

public static List<Theatre> GetTheatreWithDate(Date startDate, Date endDate) {_theatre = new ArrayList<Theatre>();

String query = "SELECT t.*,dm.StartDate as tDate,p.Name as Writer,c.Name as→˓City_Name FROM Theatre t JOIN Date_Match dm on dm.EventId=t.Id AND dm.→˓EventType=1 JOIN City c on c.Id=t.CityID JOIN Person p on t.writerId = p.Id;";

Connection connection = null;ResultSet resultSet = null;Statement statement = null;

try {connection = ConnectionDB.conn;statement = connection.createStatement();resultSet = statement.executeQuery(query);while (resultSet.next()) {

SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");Date sdate = formatter.parse(resultSet.getString("tDate"));if (sdate.after(endDate) || sdate.before(startDate))

continue;Theatre th = new Theatre();th.Id = resultSet.getInt("Id");th.Title = resultSet.getString("Title");th.Writer = resultSet.getString("Writer");

2.2. Code 31

Page 36: Event Reservation System Documentation

Event Reservation System Documentation, Release 1.0

th.City = resultSet.getString("City_Name");th.tDate = resultSet.getDate("tDate");th.Capacity = resultSet.getInt("Capacity");th.AvailableTicket = resultSet.getInt("AvailableTicket");th.Deleted = resultSet.getBoolean("Deleted");_theatre.add(th);

}return _theatre;

} catch (Exception e) {e.printStackTrace();

}return null;

}

public List<Theatre> getAll() {List<Theatre> all = new ArrayList();

String query = "SELECT t.*,dm.StartDate as tDate,p.Name as Writer,c.Name as→˓City_Name FROM theatre t JOIN Date_Match dm on dm.EventId=t.Id AND dm.→˓EventType=1 JOIN City c on c.Id=t.CityID JOIN Person p on t.writerId = p.Id;";

Connection connection = null;ResultSet resultSet = null;Statement statement = null;

try {connection = ConnectionDB.conn;statement = connection.createStatement();resultSet = statement.executeQuery(query);SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");while (resultSet.next()) {

Theatre th = new Theatre();th.Id = resultSet.getInt("Id");th.Title = resultSet.getString("Title");th.Writer = resultSet.getString("Writer");th.City = resultSet.getString("City_Name");String sdate = resultSet.getString("tDate");th.tDate = formatter.parse(sdate);th.Capacity = resultSet.getInt("Capacity");th.AvailableTicket = resultSet.getInt("AvailableTicket");th.Deleted = resultSet.getBoolean("Deleted");all.add(th);

}return all;

} catch (Exception e) {e.printStackTrace();

}return null;

}

public Theatre getByID(int id) {Theatre th = new Theatre();

Connection connection = null;ResultSet resultSet = null;Statement statement = null;

String selectSQL = "SELECT t.*,dm.StartDate as tDate,p.Name as Writer,c.Name→˓as City_Name FROM theatre t JOIN Date_Match dm on dm.EventId=t.Id AND dm.→˓EventType=1 JOIN City c on c.Id=t.CityID JOIN Person p on t.writerId = p.Id→˓WHERE Id ="

+ id;try {

32 Chapter 2. Developer Guide

Page 37: Event Reservation System Documentation

Event Reservation System Documentation, Release 1.0

connection = ConnectionDB.conn;statement = connection.createStatement();resultSet = statement.executeQuery(selectSQL);SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");while (resultSet.next()) {

th.Id = resultSet.getInt("Id");th.Title = resultSet.getString("Title");th.Writer = resultSet.getString("Writer");th.City = resultSet.getString("City_Name");String sdate = resultSet.getString("tDate");th.tDate = formatter.parse(sdate);th.Capacity = resultSet.getInt("Capacity");th.AvailableTicket = resultSet.getInt("AvailableTicket");th.Deleted = resultSet.getBoolean("Deleted");

}

return th;} catch (Exception e) {

e.printStackTrace();}

finally {try {

resultSet.close();statement.close();connection.close();

} catch (Exception e) {e.printStackTrace();

}}

return null;}

// Add theatrepublic static void AddTheatre(Theatre newTheatre) {

Connection connection = ConnectionDB.conn;Statement statement = null;ResultSet resultSet = null;PreparedStatement preStatement = null;

String query;

int writerID = -1;

// if existsString exist = "Select Id from Person where Name='" + newTheatre.Writer

+ "'";try {

statement = ConnectionDB.conn.createStatement();resultSet = statement.executeQuery(exist);if (resultSet.next()) {

writerID = resultSet.getInt("Id");} else {

query = "Insert Into Person(Name) Values('" + newTheatre.Writer+ "')";

try {preStatement = connection.prepareStatement(query,

Statement.RETURN_GENERATED_KEYS);preStatement.executeUpdate();ResultSet rset = preStatement.getGeneratedKeys();if (rset.next())

writerID = rset.getInt(1);

2.2. Code 33

Page 38: Event Reservation System Documentation

Event Reservation System Documentation, Release 1.0

} catch (Exception e) {e.printStackTrace();

}}

} catch (Exception e) {e.printStackTrace();

}

int cityID = -1;query = "SELECT Id FROM City WHERE Name='" + newTheatre.City + "'";try {

statement = ConnectionDB.conn.createStatement();resultSet = statement.executeQuery(query);if (resultSet.next())

cityID = resultSet.getInt("Id");} catch (Exception e) {

e.printStackTrace();}

int insertedID = -1;query = "INSERT INTO theatre (Title,WriterId,CityID,Capacity,AvailableTicket)

→˓"+ "VALUES ('"+ newTheatre.Title+ "','"+ writerID+ "','"+ cityID+ "','"+ newTheatre.Capacity+ "','"+ newTheatre.AvailableTicket + "')";

try {

preStatement = connection.prepareStatement(query,Statement.RETURN_GENERATED_KEYS);

preStatement.executeUpdate();ResultSet rset = preStatement.getGeneratedKeys();if (rset.next())

insertedID = rset.getInt(1);} catch (Exception e) {

e.printStackTrace();}

/** query = "INSERT INTO City_Match " + cityID + "," + insertedID + ",1";

* try { statement = ConnectionDB.conn.createStatement();

* statement.executeUpdate(query); } catch (Exception e) {

* e.printStackTrace(); } finally { try { statement.close(); } catch

* (Exception e) { e.printStackTrace(); } }

*/Calendar cal = Calendar.getInstance();cal.setTime(newTheatre.tDate);int Syear = cal.get(Calendar.YEAR);int Smonth = cal.get(Calendar.MONTH) + 1;int Sday = cal.get(Calendar.DAY_OF_MONTH);cal.setTime(newTheatre.tDate);int Eyear = cal.get(Calendar.YEAR);int Emonth = cal.get(Calendar.MONTH) + 1;int Eday = cal.get(Calendar.DAY_OF_MONTH);

query = "INSERT INTO Date_Match VALUES (" + insertedID + ",1,'" + Syear+ "-" + ((Smonth < 10) ? ("0" + Smonth) : Smonth) + "-"

34 Chapter 2. Developer Guide

Page 39: Event Reservation System Documentation

Event Reservation System Documentation, Release 1.0

+ ((Sday < 10) ? ("0" + Sday) : Sday) + "','" + Eyear + "-"+ ((Emonth < 10) ? ("0" + Emonth) : Emonth) + "-"+ ((Eday < 10) ? ("0" + Eday) : Eday) + "');";

try {statement = ConnectionDB.conn.createStatement();statement.executeUpdate(query);

} catch (Exception e) {e.printStackTrace();

}_theatre.add(newTheatre);

}

// Delete Theatrepublic static void DeleteTheatre(int TheatreId) {

String query = "DELETE FROM Theatre WHERE Id=" + TheatreId;try {

ConnectionDB.conn.createStatement().executeUpdate(query);} catch (Exception e) {

e.printStackTrace();}

query = "DELETE FROM Date_Match WHERE EventId=" + TheatreId+ " AND EventType=1";

try {ConnectionDB.conn.createStatement().executeUpdate(query);

} catch (Exception e) {e.printStackTrace();

}

/** query = "DELETE FROM City_Match WHERE EventId=" + TheatreId +

* " AND EventType=1"; try {

* ConnectionDB.conn.createStatement().executeUpdate(query); } catch

* (Exception e) { e.printStackTrace(); }

*/

}

// Update Theatrepublic static void UpdateTheatre(Theatre theatre) {

PreparedStatement preparedStatement;Statement statement = null;ResultSet resultSet = null;int cityID = -1;int writerId = -1;try {

// CityString query = "SELECT Id FROM City WHERE Name='" + theatre.City

+ "'";statement = ConnectionDB.conn.createStatement();resultSet = statement.executeQuery(query);if (resultSet.next())

cityID = resultSet.getInt("Id");// ////////////////////// Musician From Personquery = "SELECT Id FROM Person WHERE Name='" + theatre.Writer + "'";resultSet = statement.executeQuery(query);if (resultSet.next())

writerId = resultSet.getInt("Id");if (writerId == -1) {

query = "insert into Person(Name) values('" + theatre.Writer+ "');";

preparedStatement = ConnectionDB.conn.prepareStatement(query,

2.2. Code 35

Page 40: Event Reservation System Documentation

Event Reservation System Documentation, Release 1.0

Statement.RETURN_GENERATED_KEYS);preparedStatement.executeUpdate();ResultSet rset = preparedStatement.getGeneratedKeys();if (rset.next())

writerId = rset.getInt(1);} else

writerId = writerId;

preparedStatement = ConnectionDB.conn.prepareStatement("update theatre Set Title=?, WriterId=?,

→˓CityId=?, Capacity=?, AvailableTicket=? where Id=?");preparedStatement.setString(1, theatre.Title);preparedStatement.setInt(2, writerId);preparedStatement.setInt(3, cityID);preparedStatement.setInt(4, theatre.Capacity);preparedStatement.setInt(5, theatre.AvailableTicket);preparedStatement.setInt(6, theatre.Id);preparedStatement.executeUpdate();

Calendar cal = Calendar.getInstance();cal.setTime(theatre.tDate);int year = cal.get(Calendar.YEAR);int month = cal.get(Calendar.MONTH) + 1;int day = cal.get(Calendar.DAY_OF_MONTH);String dateSubQueryString = year + "-"

+ ((month < 10) ? ("0" + month) : month) + "-"+ ((day < 10) ? ("0" + day) : day);

preparedStatement = ConnectionDB.conn.prepareStatement("update Date_Match Set StartDate=?, EndDate=?

→˓where EventType=1 AND EventId=?");preparedStatement.setString(1, dateSubQueryString);preparedStatement.setString(2, dateSubQueryString);preparedStatement.setInt(3, theatre.Id);preparedStatement.executeUpdate();

} catch (Exception e) {e.printStackTrace();

}}

public List<Theatre> getTheatreWithQuery(PreparedStatement preparedStatement) {List<Theatre> theatre = new ArrayList();Theatre th = new Theatre();try {

System.out.println(preparedStatement.toString());ResultSet resultSet = preparedStatement.executeQuery();SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");while (resultSet.next()) {

th = new Theatre();th.Id = resultSet.getInt("Id");th.Title = resultSet.getString("Title");th.Writer = resultSet.getString("Writer");th.City = resultSet.getString("City_Name");String sdate = resultSet.getString("tDate");th.tDate = formatter.parse(sdate);th.Capacity = resultSet.getInt("Capacity");th.AvailableTicket = resultSet.getInt("AvailableTicket");th.Deleted = resultSet.getBoolean("Deleted");_theatre.add(th);

}return theatre;

} catch (Exception e) {// TODO Auto-generated catch block

36 Chapter 2. Developer Guide

Page 41: Event Reservation System Documentation

Event Reservation System Documentation, Release 1.0

e.printStackTrace();return null;

}}

}

TheatreDetailsPageLink connects the pages TheatreBasePage and TheatreDetailsPage.

public class TheatreDetailsPageLink extends Link {private Theatre theatre;

public TheatreDetailsPageLink(String id, Theatre th) {super(id);theatre = th;

}

@Overridepublic void onClick() {

this.setResponsePage(new TheatreDetailsPage(this.theatre));}

}

Movie Page

Movie Database Design

Movie Table

Fig. 2.8: Movie Table

Movie table keeps data for movies. Id of movie, title of movie, director id of movie, year of movie, city id ofmovie ,score of movie, place of movie, capacity of movie, available ticket of movie, and status of movie (deletedor not) are kept in the table.

Table contents are initialized like this;

Sample of some movies are in the below:

Code

Movie class consists of DirectorName, Id, Title, DirectorId, Year, FilmName, Score, AvailableTicket, Capacity,Place, City, Deleted, StartDate, EndDate and date.:

public class Movie {public String DirectorName = null;public Integer Id = null;public String Title = null;

2.2. Code 37

Page 42: Event Reservation System Documentation

Event Reservation System Documentation, Release 1.0

Fig. 2.9: Contents

Fig. 2.10: There is a movie which has the id 1 and named like Metropolis. Director id is 50 and that meansdirector’s name is Fritz Lang. Production year is 1927 and movie is showing in Pera Müzesi / Istanbul (CityId=34).Score of movie is 8,3 and capacity of saloon is 100 and there is 100 available tickets.

38 Chapter 2. Developer Guide

Page 43: Event Reservation System Documentation

Event Reservation System Documentation, Release 1.0

public String FilmName = null;public Integer DirectorId = null;public Integer Year = null;public Double Score = null;public Integer AvailableTicket = null;public Integer Capacity = null;public String Place = null;public String City = null;public Boolean Deleted = null;public Date StartDate = null;public Date EndDate = null;public Date date = null;

}

MovieBasePage shows all movies without filtering and makes it possible to filter the movie events. It provides toadd new movies to database.

public class MovieBasePage extends BasePage {public MovieBasePage(final PageParameters parameters) {

final DropDownChoice<String> listCities = new DropDownChoice<String>("cityInput", defaultCity, Cities);

listCities.setRequired(true);final TextField<String> nameInput = new TextField<String>("nameInput",

Model.of(""));nameInput.setRequired(true);final TextField<String> placeInput = new TextField<String>(

"placeInput", Model.of(""));placeInput.setRequired(true);final NumberTextField<Integer> capacityInput = new NumberTextField<Integer>(

"capacityInput", new Model(), Integer.class);capacityInput.add(RangeValidator.minimum(0));capacityInput.setRequired(true);final NumberTextField<Double> scoreInput = new NumberTextField<Double>(

"scoreInput", new Model(), Double.class);scoreInput.setRequired(true);scoreInput.add(new AttributeModifier("step", "0.1"));final TextField<String> directorInput = new TextField<String>(

"directorInput", Model.of(""));directorInput.setRequired(true);final NumberTextField<Integer> yearInput = new NumberTextField<Integer>(

"yearInput", new Model(), Integer.class);yearInput.add(RangeValidator.minimum(1800));yearInput.setRequired(true);final TextField<String> SDateInput = new TextField<String>(

"startDateInput", Model.of(""));SDateInput.setRequired(true);Form<?> addFairForm = new Form<Void>("addConcertForm") {

private static final long serialVersionUID = 1L;

@Overrideprotected void onSubmit() {

String selectedCity = listCities.getModelObject();String newName = nameInput.getModelObject();String newPlace = placeInput.getModelObject();int newCapacity = capacityInput.getModelObject();String SnewDate = SDateInput.getModelObject();Integer newYear = yearInput.getModelObject();Double newScore = scoreInput.getModelObject();String newDirector = directorInput.getModelObject();SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");Movie newMovie = new Movie();

2.2. Code 39

Page 44: Event Reservation System Documentation

Event Reservation System Documentation, Release 1.0

newMovie.Title = newName;newMovie.Place = newPlace;newMovie.Capacity = newCapacity;newMovie.DirectorName = newDirector;newMovie.Score = newScore;newMovie.Year = newYear;newMovie.AvailableTicket = newCapacity;newMovie.City = selectedCity;try {

newMovie.date = formatter.parse(SnewDate);} catch (ParseException e) {

// TODO Auto-generated catch blocknewMovie.date = null;

}MovieCollection.addMovie(newMovie);setResponsePage(MovieBasePage.class, getPageParameters());

}};add(addFairForm);addFairForm.add(listCities);addFairForm.add(yearInput);addFairForm.add(directorInput);addFairForm.add(scoreInput);addFairForm.add(nameInput);addFairForm.add(placeInput);addFairForm.add(capacityInput);addFairForm.add(SDateInput);

final TextField<String> baslangic = new TextField<String>("inpbaslangic", Model.of(""));

final TextField<String> bitis = new TextField<String>("inpbitis",Model.of(""));

Form<?> form = new Form<Void>("tarihForm") {@Overrideprotected void onSubmit() {

PageParameters pageParameters = new PageParameters();pageParameters.add("inpbaslangic", baslangic.getModelObject());pageParameters.add("inpbitis", bitis.getModelObject());setResponsePage(ConcertBasePage.class, pageParameters);

}};add(form);form.add(baslangic);form.add(bitis);String tarihbaslangic = null;String tarihbitis = null;if (parameters.getNamedKeys().contains("inpbaslangic")) {

tarihbaslangic = parameters.get("inpbaslangic").toString();

}if (parameters.getNamedKeys().contains("inpbitis")) {

tarihbitis = parameters.get("inpbitis").toString();}

MovieCollection collection = new MovieCollection();String query = "";PreparedStatement statement;List<Movie> movies;try {

if (parameters.getNamedKeys().contains("inpbitis")&& parameters.getNamedKeys().contains("inpbaslangic")) {

query = "SELECT cp.*,dm.StartDate as Startdate from ((SELECT c.*,p.→˓Name as MusicianName FROM Concert as c join Person as p on p.Id=c.MusicianId) as→˓cp join Date_Match as dm on cp.id=dm.EventId AND EventType=5) where Startdate→˓between ? and ?";

40 Chapter 2. Developer Guide

Page 45: Event Reservation System Documentation

Event Reservation System Documentation, Release 1.0

statement = ConnectionDB.conn.prepareStatement(query);statement.setString(

1,tarihbaslangic.split("/")[2] + "-"

+ tarihbaslangic.split("/")[1] + "-"+ tarihbaslangic.split("/")[0]);

statement.setString(2,tarihbitis.split("/")[2] + "-"

+ tarihbitis.split("/")[1] + "-"+ tarihbitis.split("/")[0]);

movies = collection.getMoviesWithQuery(statement);} else {

movies = collection.getMovies();}final SimpleDateFormat formatter = new SimpleDateFormat(

"dd MMMM yyyy \n EEEE");PropertyListView movieListView = new PropertyListView("movie_list",

movies) {@Overrideprotected void populateItem(ListItem item) {

Movie movie = (Movie) item.getModelObject();MovieDetailsPageLink movieLink = new MovieDetailsPageLink(

"movie_link", movie);movieLink.add(new Label("filmName", movie.Title));movieLink.add(new Label("dname", movie.DirectorName));movieLink.add(new Label("year", movie.Year));movieLink.add(new Label("score", movie.Score));movieLink.add(new Label("city", movie.City));movieLink.add(new Label("place", movie.Place));movieLink.add(new Label("date", formatter

.format(movie.date)));movieLink.add(new Label("capacity", movie.Capacity));movieLink.add(new Image("image",

new ContextRelativeResource("/images/movie/"+ movie.Id + ".jpg")));

item.add(movieLink);}

};this.add(movieListView);parameters.clearNamed();

} catch (SQLException e) {e.printStackTrace();

}

}}

MovieCollection provides us to add, delete, update, search movies according to their start date.

public class MovieCollection {private static List<Movie> _movies;

public MovieCollection() {String selectSQL = "select wd.*, cty.Name as CityName from City as cty join

→˓(SELECT cp.*,dm.StartDate as Startdate from (SELECT c.*,p.Name as DirectorName→˓FROM Movie as c join Person as p on p.Id=c.DirectorId) as cp join Date_Match as→˓dm on cp.id=dm.EventId AND EventType=2) as wd on wd.CityId=cty.Id";

PreparedStatement statement;try {

statement = ConnectionDB.conn.prepareStatement(selectSQL);_movies = getMoviesWithQuery(statement);

} catch (SQLException e) {

2.2. Code 41

Page 46: Event Reservation System Documentation

Event Reservation System Documentation, Release 1.0

e.printStackTrace();}

}

public List<Movie> getMovies() {return _movies;

}

public static void addMovie(Movie movie) {int cityID = -1;int directorId = -1;Statement statement = null;ResultSet resultSet = null;PreparedStatement preparedStatement;String query = "SELECT Id FROM City WHERE Name='" + movie.City + "'";try {

statement = ConnectionDB.conn.createStatement();resultSet = statement.executeQuery(query);if (resultSet.next())

cityID = resultSet.getInt("Id");query = "SELECT Id FROM Person WHERE Name='" + movie.DirectorName

+ "'";resultSet = statement.executeQuery(query);if (resultSet.next())

directorId = resultSet.getInt("Id");if (directorId == -1) {

query = "insert into Person(Name) values('"+ movie.DirectorName + "');";

preparedStatement = ConnectionDB.conn.prepareStatement(query,Statement.RETURN_GENERATED_KEYS);

preparedStatement.executeUpdate();ResultSet rset = preparedStatement.getGeneratedKeys();if (rset.next())

movie.DirectorId = rset.getInt(1);} else

movie.DirectorId = directorId;} catch (Exception e) {

e.printStackTrace();}

int insertedID = -1;try {

preparedStatement = ConnectionDB.conn.prepareStatement(

"insert into Movie(Title,DirectorId,Year,CityId,Score,→˓Place,Capacity,AvailableTicket) values(?,?,?,?,?,?,?,?)",

PreparedStatement.RETURN_GENERATED_KEYS);preparedStatement.setString(1, movie.Title);preparedStatement.setInt(2, movie.DirectorId);preparedStatement.setString(6, movie.Place);preparedStatement.setInt(7, movie.Capacity);preparedStatement.setInt(8, movie.AvailableTicket);preparedStatement.setInt(4, cityID);preparedStatement.setInt(3, movie.Year);preparedStatement.setDouble(5, movie.Score);preparedStatement.executeUpdate();ResultSet rset = preparedStatement.getGeneratedKeys();if (rset.next())

insertedID = rset.getInt(1);} catch (Exception e) {

// TODO Auto-generated catch blocke.printStackTrace();

}

42 Chapter 2. Developer Guide

Page 47: Event Reservation System Documentation

Event Reservation System Documentation, Release 1.0

Calendar cal = Calendar.getInstance();cal.setTime(movie.date);int Syear = cal.get(Calendar.YEAR);int Smonth = cal.get(Calendar.MONTH) + 1;int Sday = cal.get(Calendar.DAY_OF_MONTH);

query = "INSERT INTO Date_Match VALUES (" + insertedID + ",2,'" + Syear+ "-" + ((Smonth < 10) ? ("0" + Smonth) : Smonth) + "-"+ ((Sday < 10) ? ("0" + Sday) : Sday) + "','" + Syear + "-"+ ((Smonth < 10) ? ("0" + Smonth) : Smonth) + "-"+ ((Sday < 10) ? ("0" + Sday) : Sday) + "');";

try {statement = ConnectionDB.conn.createStatement();statement.executeUpdate(query);

} catch (Exception e) {e.printStackTrace();

}_movies.add(movie);

}

public static void deleteMovie(int Id) {PreparedStatement preparedStatement;try {

preparedStatement = ConnectionDB.conn.prepareStatement("delete from Movie where Id=?");

preparedStatement.setInt(1, Id);preparedStatement.executeUpdate();

} catch (Exception e) {e.printStackTrace();

}try {

preparedStatement = ConnectionDB.conn.prepareStatement("DELETE FROM Date_Match WHERE EventId=? AND

→˓EventType=2");preparedStatement.setInt(1, Id);preparedStatement.executeUpdate();

} catch (Exception e) {e.printStackTrace();

}}

public static void updateMovie(Movie movie) {PreparedStatement preparedStatement;Statement statement = null;ResultSet resultSet = null;int cityID = -1;int directorId = -1;try {

// CityString query = "SELECT Id FROM City WHERE Name='" + movie.City

+ "'";statement = ConnectionDB.conn.createStatement();resultSet = statement.executeQuery(query);if (resultSet.next())

cityID = resultSet.getInt("Id");// ////////////////////// Musician From Personquery = "SELECT Id FROM Person WHERE Name='" + movie.DirectorName

+ "'";resultSet = statement.executeQuery(query);if (resultSet.next())

directorId = resultSet.getInt("Id");if (directorId == -1) {

2.2. Code 43

Page 48: Event Reservation System Documentation

Event Reservation System Documentation, Release 1.0

query = "insert into Person(Name) values('"+ movie.DirectorName + "');";

preparedStatement = ConnectionDB.conn.prepareStatement(query,Statement.RETURN_GENERATED_KEYS);

preparedStatement.executeUpdate();ResultSet rset = preparedStatement.getGeneratedKeys();if (rset.next())

movie.DirectorId = rset.getInt(1);} else

movie.DirectorId = directorId;// /////////////////////////preparedStatement = ConnectionDB.conn

.prepareStatement("update movie Set DirectorId=?, Place=?,→˓Capacity=?, AvailableTicket=?,CityId=? where Id=?");

preparedStatement.setInt(1, movie.DirectorId);preparedStatement.setString(2, movie.Place);preparedStatement.setInt(3, movie.Capacity);preparedStatement.setInt(4, movie.AvailableTicket);preparedStatement.setInt(5, cityID);preparedStatement.setInt(6, movie.Id);preparedStatement.executeUpdate();

Calendar cal = Calendar.getInstance();cal.setTime(movie.date);int year = cal.get(Calendar.YEAR);int month = cal.get(Calendar.MONTH) + 1;int day = cal.get(Calendar.DAY_OF_MONTH);String dateSubQueryString = year + "-"

+ ((month < 10) ? ("0" + month) : month) + "-"+ ((day < 10) ? ("0" + day) : day);

preparedStatement = ConnectionDB.conn.prepareStatement("update Date_Match Set StartDate=?, EndDate=?

→˓where EventType=2 AND EventId=?");preparedStatement.setString(1, dateSubQueryString);preparedStatement.setString(2, dateSubQueryString);preparedStatement.setInt(3, movie.Id);preparedStatement.executeUpdate();

} catch (Exception e) {e.printStackTrace();

}}

public List<Movie> getMoviesWithQuery(PreparedStatement preparedStatement) {_movies = new ArrayList();Movie mm = new Movie();try {

System.out.println(preparedStatement.toString());ResultSet rs = preparedStatement.executeQuery();while (rs.next()) {

mm = new Movie();mm.Id = rs.getInt("Id");mm.DirectorName = rs.getString("DirectorName");mm.Title = rs.getString("Title");DateFormat formatter1 = new SimpleDateFormat("yyyy-MM-dd");String dt = rs.getString("Startdate");mm.City = rs.getString("CityName");mm.date = formatter1.parse(dt);mm.Place = rs.getString("Place");mm.Capacity = rs.getInt("Capacity");mm.AvailableTicket = rs.getInt("AvailableTicket");mm.Deleted = rs.getBoolean("Deleted");mm.Score = rs.getDouble("Score");mm.Year = rs.getInt("Year");

44 Chapter 2. Developer Guide

Page 49: Event Reservation System Documentation

Event Reservation System Documentation, Release 1.0

_movies.add(mm);}return _movies;

} catch (Exception e) {// TODO Auto-generated catch blocke.printStackTrace();return null;

}}

}

MovieDetailsPage shows the selected movie and makes it possible to delete and update the event. Also, there is aform to update the events. We used Ajax to show the available tickets without refreshing the page.

public class MovieDetailsPage extends BasePage {

public MovieDetailsPage(final Movie movie) {

// Start of the Page ComponentsSimpleDateFormat formatter2 = new SimpleDateFormat("dd MMMM yyyy EEEE");final Label label = new Label("availableTicket",

(movie.AvailableTicket != 0 ? "Yalnızca "+ movie.AvailableTicket + " bilet kaldı.": "Biletler tükenmistir."));

label.setOutputMarkupId(true);this.add(new Label("year", movie.Year));this.add(new Label("score", movie.Score));this.add(new Label("title", movie.Title));this.add(new Label("directorName", movie.DirectorName));this.add(new Label("city", movie.City));this.add(new Label("place", movie.Place));this.add(new Label("capacity", movie.Capacity.toString()));this.add(new Label("date", formatter2.format(movie.date)));this.add(label);// this.add(new Label("musicianName",// concert.MusicianName.toUpperCase()));this.add(new Image("image", new ContextRelativeResource(

"/images/movie/" + movie.Id + ".jpg")));

// End of the Page Components

// Start of the Edit Form

SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");final IModel<String> City = new Model<String>(movie.City);final DropDownChoice<String> listCities = new DropDownChoice<String>(

"cityInputEdit", City, Cities);listCities.setRequired(true);final TextField<String> nameInput = new TextField<String>(

"nameInputEdit", Model.of(movie.Title));nameInput.setRequired(true);final TextField<String> directorInput = new TextField<String>(

"directorInputEdit", Model.of(movie.DirectorName));nameInput.setRequired(true);final NumberTextField<Integer> yrInput = new NumberTextField<Integer>(

"yearInputEdit", Model.of(movie.Year));yrInput.setRequired(true);final NumberTextField<Double> scoreInput = new NumberTextField<Double>(

"scoreInputEdit", new Model(), Double.class);scoreInput.setRequired(true);scoreInput.add(new AttributeModifier("step", "0.1"));

2.2. Code 45

Page 50: Event Reservation System Documentation

Event Reservation System Documentation, Release 1.0

final TextField<String> placeInput = new TextField<String>("placeInputEdit", Model.of(movie.Place));

placeInput.setRequired(true);final NumberTextField<Integer> capacityInput = new NumberTextField<Integer>(

"capacityInputEdit", Model.of(movie.Capacity));capacityInput.add(RangeValidator.minimum(0));capacityInput.setRequired(true);final NumberTextField<Integer> availableTicketInput = new NumberTextField

→˓<Integer>("availableTicketInputEdit", Model.of(movie.AvailableTicket));

availableTicketInput.add(RangeValidator.minimum(0));availableTicketInput.setRequired(true);availableTicketInput.setOutputMarkupId(true);final TextField<String> dateInput = new TextField<String>(

"dateInputEdit", Model.of(formatter.format(movie.date)));dateInput.setRequired(true);Form<?> editMovieForm = new Form<Void>("editMovieForm") {

private static final long serialVersionUID = 1L;

@Overrideprotected void onSubmit() {

SimpleDateFormat formatter1 = new SimpleDateFormat("dd/MM/yyyy");String selectedCity = listCities.getModelObject();String newName = nameInput.getModelObject();String newPlace = placeInput.getModelObject();int newCapacity = capacityInput.getModelObject();int newAvailableTicket = availableTicketInput.getModelObject();String newDate = dateInput.getModelObject();int newYear = yrInput.getModelObject();double newScore = scoreInput.getModelObject();String newDirector = directorInput.getModelObject();movie.Score = newScore;movie.Year = newYear;movie.DirectorName = newDirector;movie.Place = newPlace;movie.Capacity = newCapacity;movie.AvailableTicket = newAvailableTicket;movie.City = selectedCity;try {

movie.date = formatter1.parse(newDate);} catch (ParseException e) {

// TODO Auto-generated catch blockmovie.date = null;

}MovieCollection.updateMovie(movie);setResponsePage(new MovieDetailsPage(movie));

}};add(editMovieForm);editMovieForm.add(listCities);editMovieForm.add(nameInput);editMovieForm.add(directorInput);editMovieForm.add(yrInput);editMovieForm.add(scoreInput);editMovieForm.add(placeInput);editMovieForm.add(capacityInput);editMovieForm.add(availableTicketInput);editMovieForm.add(dateInput);

// End of the Edit Form

// Start of the decreasing Available Ticket with AJAXadd(new AjaxLink("ajaxLink") {

46 Chapter 2. Developer Guide

Page 51: Event Reservation System Documentation

Event Reservation System Documentation, Release 1.0

@Overridepublic void onClick(AjaxRequestTarget target) {

if (movie.AvailableTicket == 0) {target.appendJavaScript(";$('#hiddensnackbarfail').snackbar('show

→˓');");return;

}String query = "update Movie SET AvailableTicket="

+ --movie.AvailableTicket + " where id="+ movie.Id.toString();

try {ConnectionDB.conn.prepareStatement(query).executeUpdate();label.setDefaultModelObject(movie.AvailableTicket != 0 ?

→˓"Yalnızca "+ movie.AvailableTicket + " bilet kaldı.": "Biletler tükenmistir.");

availableTicketInput.setDefaultModelObject(movie.AvailableTicket);

target.add(availableTicketInput);target.add(label);

} catch (SQLException e) {// TODO Auto-generated catch blocke.printStackTrace();

}target.appendJavaScript(";$('#hiddensnackbar').snackbar('show');");

}});

// Start of the decreasing Available Ticket with AJAX

// Start of the Delete with AJAX

add(new AjaxLink("ajaxDelete") {@Overridepublic void onClick(AjaxRequestTarget target) {

MovieCollection.deleteMovie(movie.Id);target.appendJavaScript(";window.location='../Cinema';");

}});

// End of the Delete with AJAX

}}

MovieDetailsPageLink connects the pages MovieBasePage and MovieDetailsPage.

public class MovieDetailsPageLink extends Link {private Movie _movie;

public MovieDetailsPageLink(String id, Movie movie) {super(id);_movie = movie;

}

@Overridepublic void onClick() {

this.setResponsePage(new MovieDetailsPage(this._movie));}

}

2.2. Code 47

Page 52: Event Reservation System Documentation

Event Reservation System Documentation, Release 1.0

Exhibition Page

Exhibition Database Design

Exhibition Table

Exhibition table keeps information about id, title, capacity, place, available ticket, content, deleted status about anexhibition.

Fig. 2.11: Exhibition Table

Table is initialized like this;

Here is some samples of exhibition;

Fig. 2.12: There is an exhibition title is Joan Miro Kadınlar, Kuslar, Yıldızlar in Sabancı Müzesi and capacity is100. There is 100 available ticket. Further information user can read the content.

Code

Exhibition class consists of Id, Title, Content, Capacity, AvailableTicket, Place, Deleted, StartDate, Enddate andCities List.:

public class Exhibition {

public Integer Id = null;public String Title = null;public String Content = null;public Integer Capacity = null;public Integer AvailableTicket = null;public String Place = null;public Boolean Deleted = null;

48 Chapter 2. Developer Guide

Page 53: Event Reservation System Documentation

Event Reservation System Documentation, Release 1.0

public Date StartDate = null;public Date EndDate = null;List<String> Cities = new ArrayList<String>();}

ExhibitionBasePage shows all exhibitions without filtering and makes it possible to filter the exhibition events. Itprovides to add new exhibitions to database.

public class ExhibitionBasePage extends BasePage {

private ArrayList<String> selectedCities = new ArrayList<String>();

public ExhibitionBasePage(final PageParameters parameters) {

// Start of add buttonfinal CheckBoxMultipleChoice<String> listCities = new CheckBoxMultipleChoice

→˓<String>("checkGroup", new Model(selectedCities), Cities);

listCities.setRequired(true);final TextField<String> titleInput = new TextField<String>(

"titleInput", Model.of(""));final TextField<String> contentInput = new TextField<String>(

"contentInput", Model.of(""));

titleInput.setRequired(true);final NumberTextField<Integer> capacityInput = new NumberTextField<Integer>(

"capacityInput", new Model(), Integer.class);capacityInput.add(RangeValidator.minimum(0));capacityInput.setRequired(true);final TextField<String> placeInput = new TextField<String>(

"placeInput", Model.of(""));placeInput.setRequired(true);final TextField<String> SDateInput = new TextField<String>(

"startDateInput", Model.of(""));SDateInput.setRequired(true);final TextField<String> EDateInput = new TextField<String>(

"endDateInput", Model.of(""));EDateInput.setRequired(true);Form<?> addExhibitionForm = new Form<Void>("addExhibitionForm") {

private static final long serialVersionUID = 1L;

@Overrideprotected void onSubmit() {

String newName = titleInput.getModelObject();Integer newCapacity = capacityInput.getModelObject();String newPlace = placeInput.getModelObject();String SnewDate = SDateInput.getModelObject();String EnewDate = EDateInput.getModelObject();String newContent = contentInput.getModelObject();

SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");Exhibition newExhibition = new Exhibition();newExhibition.Title = newName;newExhibition.Cities = selectedCities;newExhibition.Capacity = newCapacity;newExhibition.Place = newPlace;newExhibition.AvailableTicket = newCapacity;newExhibition.Content = newContent;try {

newExhibition.StartDate = formatter.parse(SnewDate);newExhibition.EndDate = formatter.parse(EnewDate);

2.2. Code 49

Page 54: Event Reservation System Documentation

Event Reservation System Documentation, Release 1.0

} catch (ParseException e) {newExhibition.StartDate = null;newExhibition.EndDate = null;

}ExhibitionCollection.AddExhibition(newExhibition);setResponsePage(ExhibitionBasePage.class);

}};add(addExhibitionForm);addExhibitionForm.add(titleInput);addExhibitionForm.add(listCities);addExhibitionForm.add(contentInput);addExhibitionForm.add(capacityInput);addExhibitionForm.add(placeInput);addExhibitionForm.add(SDateInput);addExhibitionForm.add(EDateInput);// End of add button

final TextField<String> baslangic = new TextField<String>("inpbaslangic", Model.of(""));

final TextField<String> bitis = new TextField<String>("inpbitis",Model.of(""));

Form<?> form = new Form<Void>("tarihForm") {

private static final long serialVersionUID = 1L;

@Overrideprotected void onSubmit() {

PageParameters pageParameters = new PageParameters();pageParameters.add("inpbaslangic", baslangic.getModelObject());pageParameters.add("inpbitis", bitis.getModelObject());setResponsePage(ExhibitionBasePage.class, pageParameters);

}};add(form);form.add(baslangic);form.add(bitis);SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");String tarihbaslangic = null;String tarihbitis = null;if (parameters.getNamedKeys().contains("inpbaslangic")) {

tarihbaslangic = (parameters.get("inpbaslangic").toString());

}if (parameters.getNamedKeys().contains("inpbitis")) {

tarihbitis = (parameters.get("inpbitis").toString());

}

ExhibitionCollection collection = new ExhibitionCollection();String query = "";PreparedStatement statement;List<Exhibition> exhibition = new ArrayList<Exhibition>();try {

if (parameters.getNamedKeys().contains("inpbitis")&& parameters.getNamedKeys().contains("inpbaslangic")) {

query = "SELECT e.*,dm.StartDate,dm.EndDate FROM Exhibition e JOIN→˓Date_Match dm on dm.EventId=e.Id AND dm.EventType=3 where Startdate between ?→˓and ?";

statement = ConnectionDB.conn.prepareStatement(query);

50 Chapter 2. Developer Guide

Page 55: Event Reservation System Documentation

Event Reservation System Documentation, Release 1.0

statement.setString(1,tarihbaslangic.split("/")[2] + "-"

+ tarihbaslangic.split("/")[1] + "-"+ tarihbaslangic.split("/")[0]);

statement.setString(2,tarihbitis.split("/")[2] + "-"

+ tarihbitis.split("/")[1] + "-"+ tarihbitis.split("/")[0]);

exhibition = collection.getExhibitionsWithStatement(statement);} else {

exhibition = collection.getAll();}ListView<?> ListExhibitions = new ListView<Exhibition>(

"exhibitions", exhibition) {SimpleDateFormat formatStartDayMonth = new SimpleDateFormat(

"dd MMMM");

@Overrideprotected void populateItem(ListItem<Exhibition> listItem) {

// TODO Auto-generated method stubExhibition e = (Exhibition) listItem.getModelObject();listItem.add(new Label("ExDate", formatStartDayMonth

.format(e.EndDate)));ExhibitionDetailsPageLink link = new ExhibitionDetailsPageLink(

"exhibition_link", e);link.add(new Image("exImage", new ContextRelativeResource(

"/images/exhibition/" + e.Id + ".jpg")));listItem.add(link);link.add(new Label("listTitle", e.Title));Label isActive = new Label("active",

e.AvailableTicket > 0 ? "Aktif" : "Kapalı");isActive.add(new AttributeAppender(

"style",e.AvailableTicket > 0 ? new Model<String>(

"color:#0F9D58;"): new Model<String>(

"color:#898989;text-decoration:line-→˓through;")));

link.add(isActive);

}

};this.add(ListExhibitions);

parameters.clearNamed();} catch (SQLException e) {

e.printStackTrace();}

}}

ExhibitionCollection provides us to add, delete, update, search movies according to their start date and end date.

public class ExhibitionCollection {

public ExhibitionCollection() {}

public static List<Exhibition> getAll() {

2.2. Code 51

Page 56: Event Reservation System Documentation

Event Reservation System Documentation, Release 1.0

List<Exhibition> Exhibitions = new ArrayList<Exhibition>();Connection connection = null;ResultSet resultSet = null;Statement statement = null;Statement statementCity = null;ResultSet resultSetCities = null;String query = "SELECT e.*,dm.StartDate,dm.EndDate FROM Exhibition e JOIN

→˓Date_Match dm on dm.EventId=e.Id AND dm.EventType=(SELECT Type FROM EventType→˓WHERE Name='Exhibition')";

String cityQuery = "SELECT e.Id,c.Name as City_Name FROM Exhibition as e JOIN→˓City_Match as cm on e.Id=cm.EvId AND cm.EvType=(SELECT Type FROM EventType WHERE→˓Name='Exhibition') JOIN City as c on c.Id=cm.CId";

// String cityQuery =// "SELECT c.Name as City_Name FROM Exhibition e JOIN Date_Match dm on dm.

→˓EventId=e.Id AND dm.EventType=3 JOIN City_Match cm on e.Id=cm.EvId AND cm.→˓EvType=3 JOIN City c on c.Id=cm.CId";

try {connection = ConnectionDB.conn;statement = connection.createStatement();statementCity = connection.createStatement();resultSet = statement.executeQuery(query);resultSetCities = statementCity.executeQuery(cityQuery);while (resultSet.next()) {

SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");String sdate = resultSet.getString("StartDate");String edate = resultSet.getString("EndDate");Exhibition e = new Exhibition();e.Id = resultSet.getInt("Id");e.Title = resultSet.getString("Title");e.Capacity = resultSet.getInt("Capacity");e.Place = resultSet.getString("Place");e.AvailableTicket = resultSet.getInt("AvailableTicket");e.Deleted = resultSet.getBoolean("Deleted");e.StartDate = formatter.parse(sdate);e.EndDate = formatter.parse(edate);e.Content = resultSet.getString("Content");resultSetCities = statementCity.executeQuery(cityQuery);while (resultSetCities.next()) {

if (resultSetCities.getInt("Id") == e.Id)e.Cities.add(resultSetCities.getString("City_Name"));

}Exhibitions.add(e);// resultSetCities.beforeFirst();

}return Exhibitions;

} catch (Exception e) {e.printStackTrace();

}return Exhibitions;

}

public static void AddExhibition(Exhibition newExhibition) {Connection connection = null;Statement statement = null;ResultSet resultSet = null;PreparedStatement preStatement = null;Statement statementDate = null;String query = null;String queryDate = null;

List<Integer> cityIDs = new ArrayList<Integer>();int cityId = -1;

52 Chapter 2. Developer Guide

Page 57: Event Reservation System Documentation

Event Reservation System Documentation, Release 1.0

try {for (int i = 0; i < newExhibition.Cities.size(); i++) {

query = "SELECT Id FROM City WHERE Name='"+ newExhibition.Cities.get(i) + "'";

statement = ConnectionDB.conn.createStatement();resultSet = statement.executeQuery(query);cityId = resultSet.getInt("Id");cityIDs.add(cityId);

}

} catch (Exception e) {e.printStackTrace();

}

int insertedID = -1;query = "INSERT INTO Exhibition (Title,Capacity,Place,AvailableTicket,

→˓Content) "+ "VALUES ('"+ newExhibition.Title+ "',"+ newExhibition.Capacity+ ",'"+ newExhibition.Place+ "',"+ newExhibition.AvailableTicket+ ",'"+ newExhibition.Content+ "')";

try {connection = ConnectionDB.conn;preStatement = connection.prepareStatement(query,

Statement.RETURN_GENERATED_KEYS);preStatement.executeUpdate();ResultSet rset = preStatement.getGeneratedKeys();if (rset.next())

insertedID = rset.getInt(1);for (int i = 0; i < cityIDs.size(); i++) {

// 3 is the type of Exhibition #City_Match table insertquery = "INSERT INTO City_Match (CId,EvId,EvType) Values("

+ cityIDs.get(i)+ ","+ insertedID+ ",(SELECT Type FROM EventType WHERE Name='Exhibition'));";

preStatement = connection.prepareStatement(query,Statement.RETURN_GENERATED_KEYS);

preStatement.executeUpdate();

}Calendar cal = Calendar.getInstance();cal.setTime(newExhibition.StartDate);int Syear = cal.get(Calendar.YEAR);int Smonth = cal.get(Calendar.MONTH) + 1;int Sday = cal.get(Calendar.DAY_OF_MONTH);cal.setTime(newExhibition.EndDate);int Eyear = cal.get(Calendar.YEAR);int Emonth = cal.get(Calendar.MONTH) + 1;int Eday = cal.get(Calendar.DAY_OF_MONTH);queryDate = "INSERT INTO Date_Match VALUES (" + insertedID

+ ",(SELECT Type FROM EventType WHERE Name='Exhibition'),'"+ Syear + "-" + ((Smonth < 10) ? ("0" + Smonth) : Smonth)+ "-" + ((Sday < 10) ? ("0" + Sday) : Sday) + "','" + Eyear+ "-" + ((Emonth < 10) ? ("0" + Emonth) : Emonth) + "-"+ ((Eday < 10) ? ("0" + Eday) : Eday) + "');";

2.2. Code 53

Page 58: Event Reservation System Documentation

Event Reservation System Documentation, Release 1.0

statementDate = ConnectionDB.conn.createStatement();statementDate.executeUpdate(queryDate);

} catch (Exception e) {e.printStackTrace();

}}

public Exhibition getByID(int id) {Exhibition ex = new Exhibition();

String selectSQL = "SELECT e.*,dm.StartDate,dm.EndDate,c.Name as City_Name→˓FROM Exhibition e JOIN Date_Match dm on dm.EventId=e.Id AND dm.EventType=(SELECT→˓Type FROM EventType WHERE Name='Exhibition') JOIN City_Match cm on e.Id=cm.EvId→˓AND cm.EvType=(SELECT Type FROM EventType WHERE Name='Exhibition') JOIN City c→˓on c.Id=cm.CId WHERE e.Id="

+ id + ";";PreparedStatement preparedStatement;try {

preparedStatement = ConnectionDB.conn.prepareStatement(selectSQL);ResultSet rs = preparedStatement.executeQuery();while (rs.next()) {

ex.Id = rs.getInt("Id");ex.Title = rs.getString("Title");ex.AvailableTicket = rs.getInt("AvailableTicket");ex.Capacity = rs.getInt("Capacity");ex.Place = rs.getString("Place");ex.Deleted = rs.getBoolean("Deleted");ex.StartDate = rs.getDate("StartDate");ex.EndDate = rs.getDate("EndDate");ex.Cities.add(rs.getString("City_Name"));ex.Content = rs.getString("Content");

}// get from database// get informations from database

} catch (Exception e) {// TODO Auto-generated catch block

}

return ex;}

public static void DeleteExhibition(int ExhibitionId) {String query = "DELETE FROM Exhibition WHERE Id=" + ExhibitionId;try {

ConnectionDB.conn.createStatement().executeUpdate(query);} catch (Exception e) {

e.printStackTrace();}

query = "DELETE FROM Date_Match WHERE EventId="+ ExhibitionId+ " AND EventType=(SELECT Type FROM EventType WHERE Name='Exhibition')

→˓";try {

ConnectionDB.conn.createStatement().executeUpdate(query);} catch (Exception e) {

e.printStackTrace();}

query = "DELETE FROM City_Match WHERE EvId="+ ExhibitionId

54 Chapter 2. Developer Guide

Page 59: Event Reservation System Documentation

Event Reservation System Documentation, Release 1.0

+ " AND EvType=(SELECT Type FROM EventType WHERE Name='Exhibition')";try {

ConnectionDB.conn.createStatement().executeUpdate(query);} catch (Exception e) {

e.printStackTrace();}

}

public static void UpdateExhibition(Exhibition newExhibition) {List<Integer> CityIDs = new ArrayList<Integer>();ResultSet resultSet = null;String query = null;try {

for (int i = 0; i < newExhibition.Cities.size(); i++) {query = "SELECT Id FROM City WHERE Name="

+ newExhibition.Cities.get(i);resultSet = ConnectionDB.conn.createStatement().executeQuery(

query);if (resultSet.next())

CityIDs.add(resultSet.getInt("Id"));

}} catch (Exception e) {

e.printStackTrace();}query = "UPDATE Exhibition SET Title='" + newExhibition.Title

+ ", Place='" + newExhibition.Place + "', Capacity='"+ newExhibition.Capacity + "', AvailableCapacity='"+ newExhibition.AvailableTicket + "', Deleted='"+ newExhibition.Deleted + ", Content='" + newExhibition.Content+ "' WHERE Id=" + newExhibition.Id;

String CityMatchquery = null;try {

ConnectionDB.conn.createStatement().executeUpdate(query);for (int i = 0; i < newExhibition.Cities.size(); i++) {

CityMatchquery = "UPDATE City_Match SET CId="+ newExhibition.Cities.get(i)+ " WHERE EvId="+ newExhibition.Id+ " AND EvType=(SELECT Type FROM EventType WHERE Name=

→˓'Exhibition')";ConnectionDB.conn.createStatement().executeUpdate(

CityMatchquery);}

} catch (Exception e) {e.printStackTrace();

}

Calendar cal = Calendar.getInstance();cal.setTime(newExhibition.StartDate);int Syear = cal.get(Calendar.YEAR);int Smonth = cal.get(Calendar.MONTH) + 1;int Sday = cal.get(Calendar.DAY_OF_MONTH);cal.setTime(newExhibition.EndDate);int Eyear = cal.get(Calendar.YEAR);int Emonth = cal.get(Calendar.MONTH) + 1;int Eday = cal.get(Calendar.DAY_OF_MONTH);

query = "UPDATE Date_Match SET StartDate='"+ Syear+ "-"+ ((Smonth < 10) ? ("0" + Smonth) : Smonth)+ "-"

2.2. Code 55

Page 60: Event Reservation System Documentation

Event Reservation System Documentation, Release 1.0

+ ((Sday < 10) ? ("0" + Sday) : Sday)+ "', EndDate='"+ Eyear+ "-"+ ((Emonth < 10) ? ("0" + Emonth) : Emonth)+ "-"+ ((Eday < 10) ? ("0" + Eday) : Eday)+ "' WHERE EventId="+ newExhibition.Id+ " AND EventType=(SELECT Type FROM EventType WHERE Name='Exhibition')

→˓";try {

ConnectionDB.conn.createStatement().executeUpdate(query);} catch (Exception e) {

e.printStackTrace();}

}

public List<Exhibition> getExhibitionsWithStatement(PreparedStatement preparedStatement) {

List<Exhibition> Exhibitions = new ArrayList<Exhibition>();Exhibition ee = new Exhibition();try {

System.out.println(preparedStatement.toString());ResultSet rs = preparedStatement.executeQuery();while (rs.next()) {

ee = new Exhibition();ee.Id = rs.getInt("Id");ee.Title = rs.getString("Title");ee.Content = rs.getString("content");ee.Place = rs.getString("Place");ee.Capacity = rs.getInt("Capacity");ee.AvailableTicket = rs.getInt("AvailableTicket");ee.Deleted = rs.getBoolean("Deleted");Exhibitions.add(ee);

}return Exhibitions;

} catch (Exception e) {// TODO Auto-generated catch blocke.printStackTrace();return null;

}}

}

ExhibitionDetailsPage shows the selected exhibition and makes it possible to delete and update the event. Also,there is a form to update the events. We used Ajax to show the available tickets without refreshing the page.

public class ExhibitionDetailsPage extends BasePage {public ExhibitionDetailsPage(final Exhibition exhibition) {

SimpleDateFormat format = new SimpleDateFormat("dd MMMM yyyy EEEE");

final Label label = new Label("availableTicket",(exhibition.AvailableTicket != 0 ? (exhibition.AvailableTicket < 20 ?

→˓"Son ": "")+ exhibition.AvailableTicket + " bilet kaldı.": "Biletler tükenmistir."));

label.setOutputMarkupId(true);

56 Chapter 2. Developer Guide

Page 61: Event Reservation System Documentation

Event Reservation System Documentation, Release 1.0

this.add(new Label("place", exhibition.Place));this.add(new Label("capacity", exhibition.Capacity.toString()));this.add(new Label("startDate", format.format(exhibition.StartDate)));this.add(new Label("endDate", format.format(exhibition.EndDate)));this.add(new Label("exhibitionTitle", exhibition.Title));this.add(new Label("cityNames", " - " + exhibition.Cities));this.add(new Label("content", " - " + exhibition.Content));this.add(label);this.add(new Image("image", new ContextRelativeResource(

"/images/exhibition/" + exhibition.Id + ".jpg")));

// Start of the Edit FormSimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");

final ArrayList<String> selectedCities = new ArrayList<String>();

final CheckBoxMultipleChoice<String> listCities = new CheckBoxMultipleChoice→˓<String>(

"checkGroup", new Model(selectedCities), Cities);listCities.setRequired(true);final TextField<String> nameInput = new TextField<String>(

"nameInputEdit", Model.of(exhibition.Title));nameInput.setRequired(true);final TextField<String> placeInput = new TextField<String>(

"placeInputEdit", Model.of(exhibition.Place));placeInput.setRequired(true);final TextField<String> contentInput = new TextField<String>(

"contentInputEdit", Model.of(exhibition.Content));contentInput.setRequired(true);final NumberTextField<Integer> capacityInput = new NumberTextField<Integer>(

"capacityInputEdit", Model.of(exhibition.Capacity));capacityInput.add(RangeValidator.minimum(0));capacityInput.setRequired(true);final NumberTextField<Integer> availableTicketInput = new NumberTextField

→˓<Integer>("availableTicketInputEdit",Model.of(exhibition.AvailableTicket));

availableTicketInput.add(RangeValidator.minimum(0));availableTicketInput.setRequired(true);availableTicketInput.setOutputMarkupId(true);final TextField<String> SdateInput = new TextField<String>(

"startDateInputEdit", Model.of(formatter.format(exhibition.StartDate)));

SdateInput.setRequired(true);final TextField<String> EdateInput = new TextField<String>(

"endDateInputEdit", Model.of(formatter.format(exhibition.EndDate)));

EdateInput.setRequired(true);Form<?> editExhibitionForm = new Form<Void>("editExhibitionForm") {

private static final long serialVersionUID = 1L;

@Overrideprotected void onSubmit() {

SimpleDateFormat formatter1 = new SimpleDateFormat("dd/MM/yyyy");String newName = nameInput.getModelObject();String newPlace = placeInput.getModelObject();String newContent = contentInput.getModelObject();int newCapacity = capacityInput.getModelObject();int newAvailableTicket = availableTicketInput.getModelObject();String SnewDate = SdateInput.getModelObject();String EnewDate = EdateInput.getModelObject();exhibition.Title = newName;exhibition.Place = newPlace;

2.2. Code 57

Page 62: Event Reservation System Documentation

Event Reservation System Documentation, Release 1.0

exhibition.Capacity = newCapacity;exhibition.AvailableTicket = newAvailableTicket;exhibition.Content = newContent;exhibition.Cities = selectedCities;try {

exhibition.StartDate = formatter1.parse(SnewDate);exhibition.EndDate = formatter1.parse(EnewDate);

} catch (ParseException e) {// TODO Auto-generated catch blockexhibition.StartDate = null;exhibition.EndDate = null;

}ExhibitionCollection.UpdateExhibition(exhibition);setResponsePage(new ExhibitionDetailsPage(exhibition));

}};add(editExhibitionForm);editExhibitionForm.add(listCities);editExhibitionForm.add(nameInput);editExhibitionForm.add(placeInput);editExhibitionForm.add(capacityInput);editExhibitionForm.add(contentInput);editExhibitionForm.add(availableTicketInput);editExhibitionForm.add(SdateInput);editExhibitionForm.add(EdateInput);// End of the Edit Form

add(new AjaxLink("ajaxLink") {@Overridepublic void onClick(AjaxRequestTarget target) {

if (exhibition.AvailableTicket == 0) {target.appendJavaScript(";$('#hiddensnackbarfail').snackbar('show

→˓');");return;

}String query = "update Exhibition SET AvailableTicket="

+ --exhibition.AvailableTicket + " where id="+ exhibition.Id.toString();

try {ConnectionDB.conn.prepareStatement(query).executeUpdate();label.setDefaultModelObject(exhibition.AvailableTicket != 0 ?

→˓(exhibition.AvailableTicket < 20 ? "Son ": "")+ exhibition.AvailableTicket + " bilet kaldı.": "Biletler tükenmistir.");

availableTicketInput.setDefaultModelObject(exhibition.AvailableTicket);

target.add(availableTicketInput);target.add(label);

} catch (SQLException e) {// TODO Auto-generated catch blocke.printStackTrace();

}target.appendJavaScript(";$('#hiddensnackbar').snackbar('show');");

}});add(new AjaxLink("ajaxDelete") {

@Overridepublic void onClick(AjaxRequestTarget target) {

ExhibitionCollection.DeleteExhibition(exhibition.Id);target.appendJavaScript(";window.location='../Exhibition';");

}});

58 Chapter 2. Developer Guide

Page 63: Event Reservation System Documentation

Event Reservation System Documentation, Release 1.0

}}

ExhibitionDetailsPageLink connects the pages ExhibitionBasePage and ExhibitionDetailsPage.

public class ExhibitionDetailsPageLink extends Link {private Exhibition ex;

public ExhibitionDetailsPageLink(String id, Exhibition exhibition) {super(id);ex = exhibition;

}

@Overridepublic void onClick() {

this.setResponsePage(new ExhibitionDetailsPage(this.ex));}

}

Fair Page

Fair Database Design

Fair Table

Fair table keeps information about id, name, fair type, place, capacity, available ticket, city id and deleted statusabout a fair.

Fig. 2.13: Fair Table

Table contents are like this;

Here is samples of some fairs;

Code

Fair class consists of Id, Name, City, FairType, Place, Capacity, AvailableCapacity, Deleted, StartDate and End-Date.:

2.2. Code 59

Page 64: Event Reservation System Documentation

Event Reservation System Documentation, Release 1.0

Fig. 2.14: There is a fair named ‘Kitap Fuarı’ that has Id =1. Fair type is ‘Ihtisas Fuarı’ and place of the fair isAto Kongre Sarayı in Ankara (City id=6). Capacity is 29 and there is 29 available tickets.

public class Fair {public Integer Id = null;public String Name = null;public String City = null;public String FairType = null;public String Place = null;public Integer Capacity = null;public Integer AvailableCapacity = null;public Boolean Deleted = null;public Date StartDate = null;public Date EndDate = null;

}

FairBasePage shows all fairs without filtering and makes it possible to filter the fair events. It provides to add newfairs to database.

public class FairBasePage extends BasePage {private static final long serialVersionUID = 1L;

private static final IModel<String> defaultCity = new Model<String>("Adana");private static final IModel<String> defaultType = new Model<String>(

"Ihtisas Fuarı");

public FairBasePage(final PageParameters parameters) {

// Add Fair Startfinal DropDownChoice<String> listTypes = new DropDownChoice<String>(

"typeInput", defaultType, FairTypes);listTypes.setRequired(true);final DropDownChoice<String> listCities = new DropDownChoice<String>(

"cityInput", defaultCity, Cities);listCities.setRequired(true);final TextField<String> nameInput = new TextField<String>("nameInput",

Model.of(""));nameInput.setRequired(true);final TextField<String> placeInput = new TextField<String>(

"placeInput", Model.of(""));placeInput.setRequired(true);final NumberTextField<Integer> capacityInput = new NumberTextField<Integer>(

"capacityInput", new Model(), Integer.class);capacityInput.add(RangeValidator.minimum(0));capacityInput.setRequired(true);final TextField<String> SDateInput = new TextField<String>(

"startDateInput", Model.of(""));SDateInput.setRequired(true);final TextField<String> EDateInput = new TextField<String>(

"endDateInput", Model.of(""));EDateInput.setRequired(true);Form<?> addFairForm = new Form<Void>("addFairForm") {

private static final long serialVersionUID = 1L;

60 Chapter 2. Developer Guide

Page 65: Event Reservation System Documentation

Event Reservation System Documentation, Release 1.0

@Overrideprotected void onSubmit() {

String selectedType = listTypes.getModelObject();String selectedCity = listCities.getModelObject();String newName = nameInput.getModelObject();String newPlace = placeInput.getModelObject();Integer newCapacity = capacityInput.getModelObject();String SnewDate = SDateInput.getModelObject();String EnewDate = EDateInput.getModelObject();

SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");Fair newFair = new Fair();newFair.Name = newName;newFair.Place = newPlace;newFair.Capacity = newCapacity;newFair.AvailableCapacity = newCapacity;newFair.FairType = selectedType;newFair.City = selectedCity;try {

newFair.StartDate = formatter.parse(SnewDate);newFair.EndDate = formatter.parse(EnewDate);

} catch (ParseException e) {newFair.StartDate = null;newFair.EndDate = null;

}FairCollection.AddFair(newFair);setResponsePage(FairBasePage.class);

}};add(addFairForm);addFairForm.add(listCities);addFairForm.add(listTypes);addFairForm.add(nameInput);addFairForm.add(placeInput);addFairForm.add(capacityInput);addFairForm.add(SDateInput);addFairForm.add(EDateInput);// Add Fair End

// Date Filter Startfinal TextField<String> baslangic = new TextField<String>("startDate",

Model.of(""));final TextField<String> bitis = new TextField<String>("endDate",

Model.of(""));Form<?> dateform = new Form<Void>("dateForm") {

private static final long serialVersionUID = 1L;

@Overrideprotected void onSubmit() {

PageParameters pageParameters = new PageParameters();pageParameters.add("startDate", baslangic.getModelObject());pageParameters.add("endDate", bitis.getModelObject());setResponsePage(FairBasePage.class, pageParameters);

}};add(dateform);dateform.add(baslangic);dateform.add(bitis);SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");Date tarihbaslangic = null;Date tarihbitis = null;// Date Filter End

2.2. Code 61

Page 66: Event Reservation System Documentation

Event Reservation System Documentation, Release 1.0

if (parameters.getNamedKeys().contains("startDate")) {try {

String baslangicString = parameters.get("startDate").toString();tarihbaslangic = formatter.parse(baslangicString);

} catch (ParseException e) {e.printStackTrace();

}}if (parameters.getNamedKeys().contains("endDate")) {

try {String bitisString = parameters.get("endDate").toString();tarihbitis = formatter.parse(bitisString);

} catch (ParseException e) {e.printStackTrace();

}}List<Fair> Fairs;try {

if (parameters.getNamedKeys().contains("endDate")&& parameters.getNamedKeys().contains("startDate")) {

Fairs = FairCollection.GetFairsWithDate(tarihbaslangic,tarihbitis);

} else {Fairs = FairCollection.GetAllFairs();

}ListView<?> ListFairs = new ListView<Fair>("rows", Fairs) {

private static final long serialVersionUID = 1L;SimpleDateFormat formatter = new SimpleDateFormat(

"EEE,d/MM/yyyy");

@Overrideprotected void populateItem(ListItem<Fair> item) {

Fair f = (Fair) item.getModelObject();FairDetailsPageLink link = new FairDetailsPageLink(

"fair_link", f);link.add(new Label("name", f.Name));item.add(link);item.add(new Label("startdate", formatter

.format(f.StartDate)+ " "+ formatter.format(f.EndDate)));

item.add(new Label("place", f.Place));item.add(new Image("fairImage",

new ContextRelativeResource("/images/fair/" + f.Id+ ".jpg")));

Label isActive = new Label("active",f.AvailableCapacity > 0 ? "Aktif" : "Kapalı");

isActive.add(new AttributeAppender("style",f.AvailableCapacity > 0 ? new Model<String>(

"color:#0F9D58;"): new Model<String>(

"color:#898989;text-decoration:line-→˓through;")));

item.add(isActive);}

};this.add(ListFairs);parameters.clearNamed();

} catch (Exception e) {e.printStackTrace();

}

62 Chapter 2. Developer Guide

Page 67: Event Reservation System Documentation

Event Reservation System Documentation, Release 1.0

}}

FairCollection provides us to add, delete, update, search movies according to their start date and end date.

public class FairCollection {

public static List<Fair> GetAllFairs() {List<Fair> Fairs = new ArrayList<Fair>();

String query = "SELECT f.*,dm.StartDate,dm.EndDate,c.Name as City_Name FROM→˓Fair f JOIN Date_Match dm on dm.EventId=f.Id AND dm.EventType=(SELECT Type FROM→˓EventType WHERE Name='Fair') JOIN City c on c.Id=f.CityId;";

Connection connection = null;ResultSet resultSet = null;Statement statement = null;

try {connection = ConnectionDB.conn;statement = connection.createStatement();resultSet = statement.executeQuery(query);while (resultSet.next()) {

SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");String sdate = resultSet.getString("StartDate");String edate = resultSet.getString("EndDate");Fair f = new Fair();f.Id = resultSet.getInt("Id");f.Name = resultSet.getString("Name");f.FairType = resultSet.getString("FairType");f.Place = resultSet.getString("Place");f.Capacity = resultSet.getInt("Capacity");f.AvailableCapacity = resultSet.getInt("AvailableCapacity");f.StartDate = formatter.parse(sdate);f.EndDate = formatter.parse(edate);f.Deleted = resultSet.getBoolean("Deleted");f.City = resultSet.getString("City_Name");Fairs.add(f);

}return Fairs;

} catch (Exception e) {e.printStackTrace();

}return null;

}

public static List<Fair> GetFairsWithDate(Date startDate, Date endDate) {List<Fair> Fairs = new ArrayList<Fair>();

String query = "SELECT f.*,dm.StartDate,dm.EndDate,c.Name as City_Name FROM→˓Fair f JOIN Date_Match dm on dm.EventId=f.Id AND dm.EventType=(SELECT Type FROM→˓EventType WHERE Name='Fair') JOIN City c on c.Id=f.CityId;";

Connection connection = null;ResultSet resultSet = null;Statement statement = null;

try {connection = ConnectionDB.conn;statement = connection.createStatement();resultSet = statement.executeQuery(query);while (resultSet.next()) {

SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");Date sdate = formatter.parse(resultSet.getString("StartDate"));Date edate = formatter.parse(resultSet.getString("EndDate"));

2.2. Code 63

Page 68: Event Reservation System Documentation

Event Reservation System Documentation, Release 1.0

if (sdate.after(endDate) || edate.before(startDate))continue;

Fair f = new Fair();f.Id = resultSet.getInt("Id");f.Name = resultSet.getString("Name");f.FairType = resultSet.getString("FairType");f.Place = resultSet.getString("Place");f.Capacity = resultSet.getInt("Capacity");f.AvailableCapacity = resultSet.getInt("AvailableCapacity");f.StartDate = sdate;f.EndDate = edate;f.Deleted = resultSet.getBoolean("Deleted");f.City = resultSet.getString("City_Name");Fairs.add(f);

}return Fairs;

} catch (Exception e) {e.printStackTrace();

}return null;

}

public static void AddFair(Fair newFair) {Connection connection = null;Statement statement = null;ResultSet resultSet = null;PreparedStatement preStatement = null;

int cityID = -1;String query = "SELECT Id FROM City WHERE Name='" + newFair.City + "'";try {

statement = ConnectionDB.conn.createStatement();resultSet = statement.executeQuery(query);if (resultSet.next())

cityID = resultSet.getInt("Id");} catch (Exception e) {

e.printStackTrace();}

int insertedID = -1;query = "INSERT INTO Fair (Name,FairType,Place,Capacity,CityId,

→˓AvailableCapacity) "+ "VALUES ('"+ newFair.Name+ "','"+ newFair.FairType+ "','"+ newFair.Place+ "','"+ newFair.Capacity+ "','"+ cityID+ "','" + newFair.AvailableCapacity + "')";

try {connection = ConnectionDB.conn;preStatement = connection.prepareStatement(query,

Statement.RETURN_GENERATED_KEYS);preStatement.executeUpdate();ResultSet rset = preStatement.getGeneratedKeys();if (rset.next())

insertedID = rset.getInt(1);} catch (Exception e) {

e.printStackTrace();

64 Chapter 2. Developer Guide

Page 69: Event Reservation System Documentation

Event Reservation System Documentation, Release 1.0

}

Calendar cal = Calendar.getInstance();cal.setTime(newFair.StartDate);int Syear = cal.get(Calendar.YEAR);int Smonth = cal.get(Calendar.MONTH) + 1;int Sday = cal.get(Calendar.DAY_OF_MONTH);cal.setTime(newFair.EndDate);int Eyear = cal.get(Calendar.YEAR);int Emonth = cal.get(Calendar.MONTH) + 1;int Eday = cal.get(Calendar.DAY_OF_MONTH);

query = "INSERT INTO Date_Match VALUES (" + insertedID+ ",(SELECT Type FROM EventType WHERE Name='Fair'),'" + Syear+ "-" + ((Smonth < 10) ? ("0" + Smonth) : Smonth) + "-"+ ((Sday < 10) ? ("0" + Sday) : Sday) + "','" + Eyear + "-"+ ((Emonth < 10) ? ("0" + Emonth) : Emonth) + "-"+ ((Eday < 10) ? ("0" + Eday) : Eday) + "');";

try {statement = ConnectionDB.conn.createStatement();statement.executeUpdate(query);

} catch (Exception e) {e.printStackTrace();

}}

public static Fair getFair(int id) {Connection connection = null;ResultSet resultSet = null;Statement statement = null;

try {connection = ConnectionDB.conn;statement = connection.createStatement();resultSet = statement

.executeQuery("SELECT f.*,dm.StartDate,dm.EndDate,c.Name as City_→˓Name FROM Fair f JOIN Date_Match dm on dm.EventId=f.Id AND dm.EventType=(SELECT→˓Type FROM EventType WHERE Name='Fair') JOIN City c on c.Id=f.CityId WHERE f.Id="

+ id);if (resultSet.next()) {

Fair f = new Fair();f.Id = resultSet.getInt("Id");f.Name = resultSet.getString("Name");f.FairType = resultSet.getString("FairType");f.Place = resultSet.getString("Place");f.Capacity = resultSet.getInt("Capacity");f.AvailableCapacity = resultSet.getInt("AvailableCapacity");f.Deleted = resultSet.getBoolean("Deleted");f.StartDate = resultSet.getDate("StartDate");f.EndDate = resultSet.getDate("EndDate");f.City = resultSet.getString("City_Name");return f;

}} catch (Exception e) {

e.printStackTrace();}return null;

}

public static void DeleteFair(int FairID) {String query = "DELETE FROM Fair WHERE Id=" + FairID;try {

ConnectionDB.conn.createStatement().executeUpdate(query);

2.2. Code 65

Page 70: Event Reservation System Documentation

Event Reservation System Documentation, Release 1.0

} catch (Exception e) {e.printStackTrace();

}

query = "DELETE FROM Date_Match WHERE EventId="+ FairID+ " AND EventType=(SELECT Type FROM EventType WHERE Name='Fair')";

try {ConnectionDB.conn.createStatement().executeUpdate(query);

} catch (Exception e) {e.printStackTrace();

}}

public static void UpdateFair(Fair newFair) {

int cityID = -1;ResultSet resultSet = null;String query = "SELECT Id FROM City WHERE Name='" + newFair.City + "'";try {

resultSet = ConnectionDB.conn.createStatement().executeQuery(query);if (resultSet.next())

cityID = resultSet.getInt("Id");} catch (Exception e) {

e.printStackTrace();}

if (newFair.Capacity < newFair.AvailableCapacity)newFair.AvailableCapacity = newFair.Capacity;

query = "UPDATE Fair SET Name='" + newFair.Name + "', FairType='"+ newFair.FairType + "', Place='" + newFair.Place+ "', Capacity=" + newFair.Capacity + ", AvailableCapacity="+ newFair.AvailableCapacity + ",CityId=" + cityID+ " WHERE Id=" + newFair.Id;

try {ConnectionDB.conn.createStatement().executeUpdate(query);

} catch (Exception e) {e.printStackTrace();

}

Calendar cal = Calendar.getInstance();cal.setTime(newFair.StartDate);int Syear = cal.get(Calendar.YEAR);int Smonth = cal.get(Calendar.MONTH) + 1;int Sday = cal.get(Calendar.DAY_OF_MONTH);cal.setTime(newFair.EndDate);int Eyear = cal.get(Calendar.YEAR);int Emonth = cal.get(Calendar.MONTH) + 1;int Eday = cal.get(Calendar.DAY_OF_MONTH);

query = "UPDATE Date_Match SET StartDate='"+ Syear+ "-"+ ((Smonth < 10) ? ("0" + Smonth) : Smonth)+ "-"+ ((Sday < 10) ? ("0" + Sday) : Sday)+ "', EndDate='"+ Eyear+ "-"+ ((Emonth < 10) ? ("0" + Emonth) : Emonth)+ "-"+ ((Eday < 10) ? ("0" + Eday) : Eday)

66 Chapter 2. Developer Guide

Page 71: Event Reservation System Documentation

Event Reservation System Documentation, Release 1.0

+ "' WHERE EventId="+ newFair.Id+ " AND EventType=(SELECT Type FROM EventType WHERE Name='Fair')";

try {ConnectionDB.conn.createStatement().executeUpdate(query);

} catch (Exception e) {e.printStackTrace();

}}

}

FairDetailsPage shows the selected fair and makes it possible to delete and update the event. Also, there is a formto update the events. We used Ajax to show the available tickets without refreshing the page.

public class FairDetailsPage extends BasePage {public FairDetailsPage(final Fair fair) {

SimpleDateFormat format = new SimpleDateFormat("dd MMMM yyyy EEEE");

final Label label = new Label("availableTicket",(fair.AvailableCapacity != 0 ? (fair.AvailableCapacity < 20 ? "Son "

: "")+ fair.AvailableCapacity + " bilet kaldı.": "Biletler tükenmistir."));

label.setOutputMarkupId(true);this.add(new Label("place", fair.Place));this.add(new Label("capacity", fair.Capacity.toString()));this.add(new Label("startDate", format.format(fair.StartDate)));this.add(new Label("endDate", format.format(fair.EndDate)));this.add(new Label("fairName", fair.Name));this.add(new Label("cityName", " - " + fair.City));this.add(new Label("fairType", fair.FairType));this.add(label);this.add(new Image("image", new ContextRelativeResource("/images/fair/"

+ fair.Id + ".jpg")));

// Start of the Edit FormSimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");

final IModel<String> fairType = new Model<String>(fair.FairType);final DropDownChoice<String> listTypes = new DropDownChoice<String>(

"typeInputEdit", fairType, FairTypes);listTypes.setRequired(true);final IModel<String> City = new Model<String>(fair.City);final DropDownChoice<String> listCities = new DropDownChoice<String>(

"cityInputEdit", City, Cities);listCities.setRequired(true);final TextField<String> nameInput = new TextField<String>(

"nameInputEdit", Model.of(fair.Name));nameInput.setRequired(true);final TextField<String> placeInput = new TextField<String>(

"placeInputEdit", Model.of(fair.Place));placeInput.setRequired(true);final NumberTextField<Integer> capacityInput = new NumberTextField<Integer>(

"capacityInputEdit", Model.of(fair.Capacity));capacityInput.add(RangeValidator.minimum(0));capacityInput.setRequired(true);final NumberTextField<Integer> availableTicketInput = new NumberTextField

→˓<Integer>("availableTicketInputEdit", Model.of(fair.AvailableCapacity));

availableTicketInput.add(RangeValidator.minimum(0));availableTicketInput.setRequired(true);

2.2. Code 67

Page 72: Event Reservation System Documentation

Event Reservation System Documentation, Release 1.0

availableTicketInput.setOutputMarkupId(true);final TextField<String> SdateInput = new TextField<String>(

"startDateInputEdit",Model.of(formatter.format(fair.StartDate)));

SdateInput.setRequired(true);final TextField<String> EdateInput = new TextField<String>(

"endDateInputEdit", Model.of(formatter.format(fair.EndDate)));EdateInput.setRequired(true);Form<?> editFairForm = new Form<Void>("editFairForm") {

private static final long serialVersionUID = 1L;

@Overrideprotected void onSubmit() {

SimpleDateFormat formatter1 = new SimpleDateFormat("dd/MM/yyyy");String selectedTye = listTypes.getModelObject();String selectedCity = listCities.getModelObject();String newName = nameInput.getModelObject();String newPlace = placeInput.getModelObject();int newCapacity = capacityInput.getModelObject();int newAvailableTicket = availableTicketInput.getModelObject();String SnewDate = SdateInput.getModelObject();String EnewDate = EdateInput.getModelObject();fair.FairType = selectedTye;fair.Name = newName;fair.Place = newPlace;fair.Capacity = newCapacity;fair.AvailableCapacity = newAvailableTicket;fair.City = selectedCity;try {

fair.StartDate = formatter1.parse(SnewDate);fair.EndDate = formatter1.parse(EnewDate);

} catch (ParseException e) {// TODO Auto-generated catch blockfair.StartDate = null;fair.EndDate = null;

}FairCollection.UpdateFair(fair);setResponsePage(new FairDetailsPage(fair));

}};add(editFairForm);editFairForm.add(listTypes);editFairForm.add(listCities);editFairForm.add(nameInput);editFairForm.add(placeInput);editFairForm.add(capacityInput);editFairForm.add(availableTicketInput);editFairForm.add(SdateInput);editFairForm.add(EdateInput);// End of the Edit Form

add(new AjaxLink("ajaxLink") {@Overridepublic void onClick(AjaxRequestTarget target) {

if (fair.AvailableCapacity == 0) {target.appendJavaScript(";$('#hiddensnackbarfail').snackbar('show

→˓');");return;

}String query = "update Fair SET AvailableCapacity="

+ --fair.AvailableCapacity + " where id="+ fair.Id.toString();

try {

68 Chapter 2. Developer Guide

Page 73: Event Reservation System Documentation

Event Reservation System Documentation, Release 1.0

ConnectionDB.conn.prepareStatement(query).executeUpdate();label.setDefaultModelObject(fair.AvailableCapacity != 0 ? (fair.

→˓AvailableCapacity < 20 ? "Son ": "")+ fair.AvailableCapacity + " bilet kaldı.": "Biletler tükenmistir.");

availableTicketInput.setDefaultModelObject(fair.AvailableCapacity);

target.add(availableTicketInput);target.add(label);

} catch (SQLException e) {// TODO Auto-generated catch blocke.printStackTrace();

}target.appendJavaScript(";$('#hiddensnackbar').snackbar('show');");

}});add(new AjaxLink("ajaxDelete") {

@Overridepublic void onClick(AjaxRequestTarget target) {

FairCollection.DeleteFair(fair.Id);target.appendJavaScript(";window.location='../Fair';");

}});

}}

FairDetailsPageLink connects the pages FairBasePage and FairDetailsPage.

public class FairDetailsPageLink extends Link {private Fair _fair;

public FairDetailsPageLink(String id, Fair fair) {super(id);_fair = fair;

}

@Overridepublic void onClick() {

this.setResponsePage(new FairDetailsPage(this._fair));}

}

Concert Page

Concert Database Design

Concert Table

Concert table keep data of a concert which are id, musician id, place, capacity, available ticket, city id and deletedstatus.

Creating table like this;

Some tuples of concert;

Code

Concert class consists of Id, MusicianId, MusicianName, date, Place, Capacity, AvailableTicket, City andDeleted.:

2.2. Code 69

Page 74: Event Reservation System Documentation

Event Reservation System Documentation, Release 1.0

Fig. 2.15: Concert Table

Fig. 2.16: There is a concert of Metallica (Musician Id = 100) in Istanbul (City id =34) that has the capacity 100and 100 available tickets.

70 Chapter 2. Developer Guide

Page 75: Event Reservation System Documentation

Event Reservation System Documentation, Release 1.0

public class Concert {public Integer Id = null;public Integer MusicianId = null;public String MusicianName = null;public Date date = null;public String Place = null;public Integer Capacity = null;public Integer AvailableTicket = null;public String City = null;public Boolean Deleted = null;

public Concert() {}

}

ConcertBasePage shows all fairs without filtering and makes it possible to filter the fair events. It provides to addnew concerts to database.

public class ConcertBasePage extends BasePage {public ConcertBasePage(final PageParameters parameters) {

final DropDownChoice<String> listCities = new DropDownChoice<String>("cityInput", defaultCity, Cities);

listCities.setRequired(true);final TextField<String> nameInput = new TextField<String>("nameInput",

Model.of(""));nameInput.setRequired(true);final TextField<String> placeInput = new TextField<String>(

"placeInput", Model.of(""));placeInput.setRequired(true);final NumberTextField<Integer> capacityInput = new NumberTextField<Integer>(

"capacityInput", new Model(), Integer.class);capacityInput.add(RangeValidator.minimum(0));capacityInput.setRequired(true);final TextField<String> SDateInput = new TextField<String>(

"startDateInput", Model.of(""));SDateInput.setRequired(true);Form<?> addConcertForm = new Form<Void>("addConcertForm") {

private static final long serialVersionUID = 1L;

@Overrideprotected void onSubmit() {

String selectedCity = listCities.getModelObject();String newName = nameInput.getModelObject();String newPlace = placeInput.getModelObject();int newCapacity = capacityInput.getModelObject();String SnewDate = SDateInput.getModelObject();SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");Concert newConcert = new Concert();newConcert.MusicianName = newName;newConcert.Place = newPlace;newConcert.Capacity = newCapacity;newConcert.AvailableTicket = newCapacity;newConcert.City = selectedCity;try {

newConcert.date = formatter.parse(SnewDate);} catch (ParseException e) {

// TODO Auto-generated catch blocknewConcert.date = null;

}ConcertCollection.addConcert(newConcert);setResponsePage(ConcertBasePage.class, getPageParameters());

2.2. Code 71

Page 76: Event Reservation System Documentation

Event Reservation System Documentation, Release 1.0

}};add(addConcertForm);addConcertForm.add(listCities);addConcertForm.add(nameInput);addConcertForm.add(placeInput);addConcertForm.add(capacityInput);addConcertForm.add(SDateInput);

final TextField<String> baslangic = new TextField<String>("inpbaslangic", Model.of(""));

final TextField<String> bitis = new TextField<String>("inpbitis",Model.of(""));

Form<?> form = new Form<Void>("tarihForm") {@Overrideprotected void onSubmit() {

PageParameters pageParameters = new PageParameters();pageParameters.add("inpbaslangic", baslangic.getModelObject());pageParameters.add("inpbitis", bitis.getModelObject());setResponsePage(ConcertBasePage.class, pageParameters);

}};add(form);form.add(baslangic);form.add(bitis);String tarihbaslangic = null;String tarihbitis = null;if (parameters.getNamedKeys().contains("inpbaslangic")) {

tarihbaslangic = parameters.get("inpbaslangic").toString();

}if (parameters.getNamedKeys().contains("inpbitis")) {

tarihbitis = parameters.get("inpbitis").toString();}

ConcertCollection collection = new ConcertCollection();String query = "";PreparedStatement statement;List<Concert> concerts;try {

if (parameters.getNamedKeys().contains("inpbitis")&& parameters.getNamedKeys().contains("inpbaslangic")) {

query = "SELECT cp.*,dm.StartDate as Startdate from ((SELECT c.*,p.→˓Name as MusicianName FROM Concert as c join Person as p on p.Id=c.MusicianId) as→˓cp join Date_Match as dm on cp.id=dm.EventId AND EventType=5) where Startdate→˓between ? and ?";

statement = ConnectionDB.conn.prepareStatement(query);statement.setString(

1,tarihbaslangic.split("/")[2] + "-"

+ tarihbaslangic.split("/")[1] + "-"+ tarihbaslangic.split("/")[0]);

statement.setString(2,tarihbitis.split("/")[2] + "-"

+ tarihbitis.split("/")[1] + "-"+ tarihbitis.split("/")[0]);

concerts = collection.getConcertsWithQuery(statement);} else {

concerts = collection.getConcerts();}final SimpleDateFormat formatter = new SimpleDateFormat(

"dd MMMM yyyy \n EEEE");

72 Chapter 2. Developer Guide

Page 77: Event Reservation System Documentation

Event Reservation System Documentation, Release 1.0

PropertyListView concertListView = new PropertyListView("concert_list", concerts) {

@Overrideprotected void populateItem(ListItem item) {

Concert concert = (Concert) item.getModelObject();ConcertDetailsPageLink concertLink = new ConcertDetailsPageLink(

"concert_link", concert);concertLink.add(new Label("musicianName",

concert.MusicianName));concertLink.add(new Label("place", concert.Place));concertLink.add(new Label("date", formatter

.format(concert.date)));concertLink.add(new Label("capacity", concert.Capacity));concertLink.add(new Image("image",

new ContextRelativeResource("/images/concert/"+ concert.Id + ".jpg")));

item.add(concertLink);}

};this.add(concertListView);parameters.clearNamed();

} catch (SQLException e) {e.printStackTrace();

}

}}

ConcertCollection provides us to add, delete, update, search movies according to their start date.

public class ConcertCollection {private static List<Concert> _concerts;

public ConcertCollection() {String selectSQL = "select wd.*, cty.Name as CityName from City as cty join

→˓(SELECT cp.*,dm.StartDate as Startdate from (SELECT c.*,p.Name as MusicianName→˓FROM Concert as c join Person as p on p.Id=c.MusicianId) as cp join Date_Match→˓as dm on cp.id=dm.EventId AND EventType=5) as wd on wd.CityId=cty.Id";

PreparedStatement statement;try {

statement = ConnectionDB.conn.prepareStatement(selectSQL);_concerts = getConcertsWithQuery(statement);

} catch (SQLException e) {e.printStackTrace();

}}

public List<Concert> getConcerts() {return _concerts;

}

public static void addConcert(Concert concert) {int cityID = -1;int musicianId = -1;Statement statement = null;ResultSet resultSet = null;PreparedStatement preparedStatement;String query = "SELECT Id FROM City WHERE Name='" + concert.City + "'";try {

statement = ConnectionDB.conn.createStatement();resultSet = statement.executeQuery(query);if (resultSet.next())

cityID = resultSet.getInt("Id");

2.2. Code 73

Page 78: Event Reservation System Documentation

Event Reservation System Documentation, Release 1.0

query = "SELECT Id FROM Person WHERE Name='" + concert.MusicianName+ "'";

resultSet = statement.executeQuery(query);if (resultSet.next())

musicianId = resultSet.getInt("Id");if (musicianId == -1) {

query = "insert into Person(Name) values('"+ concert.MusicianName + "');";

preparedStatement = ConnectionDB.conn.prepareStatement(query,Statement.RETURN_GENERATED_KEYS);

preparedStatement.executeUpdate();ResultSet rset = preparedStatement.getGeneratedKeys();if (rset.next())

concert.MusicianId = rset.getInt(1);} else

concert.MusicianId = musicianId;} catch (Exception e) {

e.printStackTrace();}

int insertedID = -1;try {

preparedStatement = ConnectionDB.conn.prepareStatement(

"insert into Concert(MusicianId,Place,Capacity,→˓AvailableTicket,CityId) values(?,?,?,?,?)",

PreparedStatement.RETURN_GENERATED_KEYS);preparedStatement.setInt(1, concert.MusicianId);preparedStatement.setString(2, concert.Place);preparedStatement.setInt(3, concert.Capacity);preparedStatement.setInt(4, concert.Capacity);preparedStatement.setInt(5, cityID);preparedStatement.executeUpdate();ResultSet rset = preparedStatement.getGeneratedKeys();if (rset.next())

insertedID = rset.getInt(1);} catch (Exception e) {

// TODO Auto-generated catch blocke.printStackTrace();

}Calendar cal = Calendar.getInstance();cal.setTime(concert.date);int Syear = cal.get(Calendar.YEAR);int Smonth = cal.get(Calendar.MONTH) + 1;int Sday = cal.get(Calendar.DAY_OF_MONTH);

query = "INSERT INTO Date_Match VALUES (" + insertedID + ",5,'" + Syear+ "-" + ((Smonth < 10) ? ("0" + Smonth) : Smonth) + "-"+ ((Sday < 10) ? ("0" + Sday) : Sday) + "','" + Syear + "-"+ ((Smonth < 10) ? ("0" + Smonth) : Smonth) + "-"+ ((Sday < 10) ? ("0" + Sday) : Sday) + "');";

try {statement = ConnectionDB.conn.createStatement();statement.executeUpdate(query);

} catch (Exception e) {e.printStackTrace();

}_concerts.add(concert);

}

public static void deleteConcert(int Id) {PreparedStatement preparedStatement;try {

74 Chapter 2. Developer Guide

Page 79: Event Reservation System Documentation

Event Reservation System Documentation, Release 1.0

preparedStatement = ConnectionDB.conn.prepareStatement("delete from Concert where Id=?");

preparedStatement.setInt(1, Id);preparedStatement.executeUpdate();

} catch (Exception e) {e.printStackTrace();

}try {

preparedStatement = ConnectionDB.conn.prepareStatement("DELETE FROM Date_Match WHERE EventId=? AND

→˓EventType=5");preparedStatement.setInt(1, Id);preparedStatement.executeUpdate();

} catch (Exception e) {e.printStackTrace();

}}

public static void updateConcert(Concert concert) {PreparedStatement preparedStatement;Statement statement = null;ResultSet resultSet = null;int cityID = -1;int musicianId = -1;try {

// CityString query = "SELECT Id FROM City WHERE Name='" + concert.City

+ "'";statement = ConnectionDB.conn.createStatement();resultSet = statement.executeQuery(query);if (resultSet.next())

cityID = resultSet.getInt("Id");// ////////////////////// Musician From Personquery = "SELECT Id FROM Person WHERE Name='" + concert.MusicianName

+ "'";resultSet = statement.executeQuery(query);if (resultSet.next())

musicianId = resultSet.getInt("Id");if (musicianId == -1) {

query = "insert into Person(Name) values('"+ concert.MusicianName + "');";

preparedStatement = ConnectionDB.conn.prepareStatement(query,Statement.RETURN_GENERATED_KEYS);

preparedStatement.executeUpdate();ResultSet rset = preparedStatement.getGeneratedKeys();if (rset.next())

concert.MusicianId = rset.getInt(1);} else

concert.MusicianId = musicianId;// /////////////////////////preparedStatement = ConnectionDB.conn

.prepareStatement("update Concert Set MusicianId=?, Place=?,→˓Capacity=?, AvailableTicket=?,CityId=? where Id=?");

preparedStatement.setInt(1, concert.MusicianId);preparedStatement.setString(2, concert.Place);preparedStatement.setInt(3, concert.Capacity);preparedStatement.setInt(4, concert.AvailableTicket);preparedStatement.setInt(5, cityID);preparedStatement.setInt(6, concert.Id);preparedStatement.executeUpdate();

Calendar cal = Calendar.getInstance();

2.2. Code 75

Page 80: Event Reservation System Documentation

Event Reservation System Documentation, Release 1.0

cal.setTime(concert.date);int year = cal.get(Calendar.YEAR);int month = cal.get(Calendar.MONTH) + 1;int day = cal.get(Calendar.DAY_OF_MONTH);String dateSubQueryString = year + "-"

+ ((month < 10) ? ("0" + month) : month) + "-"+ ((day < 10) ? ("0" + day) : day);

preparedStatement = ConnectionDB.conn.prepareStatement("update Date_Match Set StartDate=?, EndDate=?

→˓where EventType=5 AND EventId=?");preparedStatement.setString(1, dateSubQueryString);preparedStatement.setString(2, dateSubQueryString);preparedStatement.setInt(3, concert.Id);preparedStatement.executeUpdate();

} catch (Exception e) {e.printStackTrace();

}}

public List<Concert> getConcertsWithQuery(PreparedStatement preparedStatement) {

_concerts = new ArrayList();Concert cc = new Concert();try {

System.out.println(preparedStatement.toString());ResultSet rs = preparedStatement.executeQuery();while (rs.next()) {

cc = new Concert();cc.Id = rs.getInt("Id");cc.MusicianId = rs.getInt("MusicianId");cc.MusicianName = rs.getString("MusicianName");DateFormat formatter1 = new SimpleDateFormat("yyyy-MM-dd");String dt = rs.getString("Startdate");cc.City = rs.getString("CityName");cc.date = formatter1.parse(dt);cc.Place = rs.getString("Place");cc.Capacity = rs.getInt("Capacity");cc.AvailableTicket = rs.getInt("AvailableTicket");cc.Deleted = rs.getBoolean("Deleted");_concerts.add(cc);

}return _concerts;

} catch (Exception e) {// TODO Auto-generated catch blocke.printStackTrace();return null;

}}

}

ConcertDetailsPage shows the selected concert and makes it possible to delete and update the event. Also, thereis a form to update the events. We used Ajax to show the available tickets without refreshing the page.

public class ConcertDetailsPage extends BasePage {

public ConcertDetailsPage(final Concert concert) {

// Start of the Page ComponentsSimpleDateFormat formatter2 = new SimpleDateFormat("dd MMMM yyyy EEEE");final Label label = new Label("availableTicket",

(concert.AvailableTicket != 0 ? "Yalnızca "

76 Chapter 2. Developer Guide

Page 81: Event Reservation System Documentation

Event Reservation System Documentation, Release 1.0

+ concert.AvailableTicket + " bilet kaldı.": "Biletler tükenmistir."));

label.setOutputMarkupId(true);this.add(new Label("city", concert.City));this.add(new Label("place", concert.Place));this.add(new Label("capacity", concert.Capacity.toString()));this.add(new Label("date", formatter2.format(concert.date)));this.add(label);this.add(new Label("musicianName", concert.MusicianName.toUpperCase()));this.add(new Image("image", new ContextRelativeResource(

"/images/concert/" + concert.Id + ".jpg")));

// End of the Page Components

// Start of the Edit Form

SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");final IModel<String> City = new Model<String>(concert.City);final DropDownChoice<String> listCities = new DropDownChoice<String>(

"cityInputEdit", City, Cities);listCities.setRequired(true);final TextField<String> nameInput = new TextField<String>(

"nameInputEdit", Model.of(concert.MusicianName));nameInput.setRequired(true);final TextField<String> placeInput = new TextField<String>(

"placeInputEdit", Model.of(concert.Place));placeInput.setRequired(true);final NumberTextField<Integer> capacityInput = new NumberTextField<Integer>(

"capacityInputEdit", Model.of(concert.Capacity));capacityInput.add(RangeValidator.minimum(0));capacityInput.setRequired(true);final NumberTextField<Integer> availableTicketInput = new NumberTextField

→˓<Integer>("availableTicketInputEdit", Model.of(concert.AvailableTicket));

availableTicketInput.add(RangeValidator.minimum(0));availableTicketInput.setRequired(true);availableTicketInput.setOutputMarkupId(true);final TextField<String> dateInput = new TextField<String>(

"dateInputEdit", Model.of(formatter.format(concert.date)));dateInput.setRequired(true);Form<?> editConcertForm = new Form<Void>("editConcertForm") {

private static final long serialVersionUID = 1L;

@Overrideprotected void onSubmit() {

SimpleDateFormat formatter1 = new SimpleDateFormat("dd/MM/yyyy");String selectedCity = listCities.getModelObject();String newName = nameInput.getModelObject();String newPlace = placeInput.getModelObject();int newCapacity = capacityInput.getModelObject();int newAvailableTicket = availableTicketInput.getModelObject();String newDate = dateInput.getModelObject();concert.MusicianName = newName;concert.Place = newPlace;concert.Capacity = newCapacity;concert.AvailableTicket = newAvailableTicket;concert.City = selectedCity;try {

concert.date = formatter1.parse(newDate);} catch (ParseException e) {

// TODO Auto-generated catch blockconcert.date = null;

}

2.2. Code 77

Page 82: Event Reservation System Documentation

Event Reservation System Documentation, Release 1.0

ConcertCollection.updateConcert(concert);setResponsePage(new ConcertDetailsPage(concert));

}};add(editConcertForm);editConcertForm.add(listCities);editConcertForm.add(nameInput);editConcertForm.add(placeInput);editConcertForm.add(capacityInput);editConcertForm.add(availableTicketInput);editConcertForm.add(dateInput);

// End of the Edit Form

// Start of the decreasing Available Ticket with AJAXadd(new AjaxLink("ajaxLink") {

@Overridepublic void onClick(AjaxRequestTarget target) {

if (concert.AvailableTicket == 0) {target.appendJavaScript(";$('#hiddensnackbarfail').snackbar('show

→˓');");return;

}String query = "update Concert SET AvailableTicket="

+ --concert.AvailableTicket + " where id="+ concert.Id.toString();

try {ConnectionDB.conn.prepareStatement(query).executeUpdate();label.setDefaultModelObject(concert.AvailableTicket != 0 ?

→˓"Yalnızca "+ concert.AvailableTicket + " bilet kaldı.": "Biletler tükenmistir.");

availableTicketInput.setDefaultModelObject(concert.AvailableTicket);

target.add(availableTicketInput);target.add(label);

} catch (SQLException e) {// TODO Auto-generated catch blocke.printStackTrace();

}target.appendJavaScript(";$('#hiddensnackbar').snackbar('show');");

}});

// Start of the decreasing Available Ticket with AJAX

// Start of the Delete with AJAX

add(new AjaxLink("ajaxDelete") {@Overridepublic void onClick(AjaxRequestTarget target) {

ConcertCollection.deleteConcert(concert.Id);target.appendJavaScript(";window.location='../Concert';");

}});

// End of the Delete with AJAX

}}

ConcertDetailsPageLink connects the pages ConcertBasePage and ConcertDetailsPage.

78 Chapter 2. Developer Guide

Page 83: Event Reservation System Documentation

Event Reservation System Documentation, Release 1.0

public class ConcertDetailsPageLink extends Link {private Concert _concert;

public ConcertDetailsPageLink(String id, Concert concert) {super(id);_concert = concert;

}

@Overridepublic void onClick() {

this.setResponsePage(new ConcertDetailsPage(this._concert));}

}

2.2. Code 79