As part of our “Software Engineering and Project Management” course assignment, we got to do a hotel management software. So fat it’s been going great, however, I do have issue with one of the features: How to visually represent all bookings and/or appointments in calendar…
At first my idea was to save all Bookings from DB in an arraylist, and then with use of JTable create a table where rows represent Rooms and columns represent Days. Then with the help of a loop I would check every column, and then ask from array where bookings are stored, if at that day some of the bookings begin. if so I would highlight the cell. However our tutor told me not to do so, because it’s just way too much unnecessary work and instead just use java calendar api to solve this.
The thing is, I’ve been googling but I haven’t found any helpful tutorials or topics which would help me figure out how to do what I want. Unfortunately due to my time capacity right now, I can’t afford to spend a whole day looking and testing something which usually end up not working as we want it.
In short, we need to visually represent active bookings/appointments in calendar and we’re looking for the fastest and simplest way to do so.
If you’re smart, you can get the db engine to do most of the work. Consider this untested MySQL query:
SELECT COUNT(*) AS cnt, DATEDIFF(booking_date, ‘2012-05-20’) AS col FROM bookings WHERE booking_date BETWEEN ‘2012-05-20’ AND ‘2012-05-27’ GROUP BY booking_date;
This will give you the column and the number of bookings on that day. From there you just have to loop through the results and complete the table.
Edit: If you don’t have db access you should store the data in a HashMap so you have O(1) lookup rather than O(n) each time.