I would appreciate a little advice on the most appropriate method for managing bookings.
I am adding to an existing program, written in VB with an MSSql DB.
I am currently using win forms as the GUI, utilising a DataGridView to display the data with a Month control.
My current DB schema is:
bikeDetail (bikeID (PK), bikeName, bikeColour, bikeStyle, bikeNotes)
bikeMovements (bikeMovementID (PK), bikeID, customerID, bikeMovementType, bikeMovementDate, bikeMovementAMPM, bikeMovementNotes).
customer (customerID, ..., ...)
The idea is that each time a bike is taken in or out, a record is made in the bikeMovements database. This may not be the easiest way of saving this data, but it should hopefully mean the database won't get bloated with lots of repeated data.
My problem is that I am struggling to work out the best way to search through the bikeMovements table in order to find out if bikes are in or out, and are hence available to book out. Using the calendar tool I am able to select a range of dates.
So far, I have been able to work out if a bike is available on a certain date by using a sql query, but not for the range of dates.
Current sql query:
SELECT * FROM tb_bikeMovements as bm, tb_bikeDetail as bd
WHERE bm.bikeMovementDate < '" + startDate + "'
and bm.bikeID = bd.bikeID
and bm.bikeMovementType = 1
This returns the bikes that are available from that day onward. (bikeMovementType 1 is the bike coming back in, and hence is available).
I would appreciate any advice on either a better sql query for bringing back availability, or a better way to setup the DB that would make querying it simpler.
Example dates:
bike 1 goes out on 22 April, and is booked back in for 24 April (available from 25 April)
bike 2 goes out on 22 April, and is booked back in for 28 April (available from 29 April)
bike 3 goes out on 26 April, and is booked back in for 27 April (available from 28 April)
bike 4 is available from 22 April onward.
What bikes are available for 25 - 29 April? (should be bike 1 and 4. Catching bike 1 is easy, bike 3 is the fly in the ointment as it goes out and back in within the selected date range!).
I am thinking that the easiest way would be to change my DB schema so that a record is created for every day that a bike is booked out for. This will make it a lot easier to search for availability, but will make the table way more bloated (2 records for each bike hire currently, in and out), with a record for every day the bike is out. To be fair though, we are not yet sure how many days these bikes will be rented for, and this would have an impact on my decision.
Any advice will be gratefully received!