Is it possible to make a booking system using delphi/lazarus? lazarus / 16-Databases ---------------------------------------------------------------------- BITW · 2014-03-30 16:15 I am programming a database(DB) in Lazarus as a project and for increased complexity have NOT downloaded any additional libraries. The software is intended to allow customers to check availability of hiring a villa and them make a booking if the villa is available. Declaring records and writing them to a file acts as a table for my DB. Reading/Writing/Deleting the records in my files has been achieved successfully and I now move on to the point where I use this data to make bookings. I have 3 tables; Clients Villas Bookings Now, my problem comes in with the bookings table. How do I make my application know that a villa has already been booked for the period in which a new booking wants to be made. (basically double booking shouldn't be allowed) So far as mentioned, I can only read/write and delete records in my tables and now move on to the booking stage. Please ask if further info is needed I'm thinking of using the Tcalendar but have no idea how to program with it or even if that is the simple way of doing it. Any tips please? ---------------------------------------------------------------------- howardpc · 2014-03-30 19:18 One approach would be to loop through all bookings looking for a potential clash (overlap) of dates with the proposed new booking. A simple-minded approach might elaborate on something like the following: Code: [Select] interface TDateRange = record     startDate: TDateTime;     endDate: TDateTime;   end;   function DatesClash(range1, range2: TDateRange): boolean; implementation function DatesClash(range1, range2: TDateRange): boolean;     // assumes startdate < endDate in data passed in ranges begin   if range1.startDate = range2.startDate then     Result:=True   else if range1.startDate < range2.startDate then     Result:=range1.endDate > range2.startDate   else                      // range1.startDate > range2.startDate;     Result:=range1.startDate < range2.endDate; end; ---------------------------------------------------------------------- marcov · 2014-03-30 19:23 Yes. See also http://stackoverflow.com/questions/22746326/is-it- possible-to-make-a-booking-system-using-delphi-lazarus In general one would write an SQL query to check if a certain period is free. (e.g. by searching in a table with an index on start date). What database are you planning to use? ---------------------------------------------------------------------- BITW · 2014-03-30 20:00 Quote from: marcov on March 30, 2014, 09:23:00 pmYes. See also http://stackoverflow.com/questions/22746326/is-it-possible-to-make-a- booking-system-using-delphi-lazarus In general one would write an SQL query to check if a certain period is free. (e.g. by searching in a table with an index on start date). What database are you planning to use? haha thats my question too Its fine, @howardpc explained it perfectly ---------------------------------------------------------------------- BITW · 2014-03-30 20:01 Quote from: howardpc on March 30, 2014, 09:18:16 pmOne approach would be to loop through all bookings looking for a potential clash (overlap) of dates with the proposed new booking. A simple-minded approach might elaborate on something like the following: Code: [Select] interface TDateRange = record     startDate: TDateTime;     endDate: TDateTime;   end;   function DatesClash(range1, range2: TDateRange): boolean; implementation function DatesClash(range1, range2: TDateRange): boolean;     // assumes startdate < endDate in data passed in ranges begin   if range1.startDate = range2.startDate then     Result:=True   else if range1.startDate < range2.startDate then     Result:=range1.endDate > range2.startDate   else                      // range1.startDate > range2.startDate;     Result:=range1.startDate < range2.endDate; end; Thanks, helped a lot and its cool to know we were on the same wavelength! (Y) ---------------------------------------------------------------------- BigChimp · 2014-03-31 08:59 You could also use TDBF which is part of FreePascal/Lazarus and use DBase tables to store your details. You can then filter the records you are interested in looking at: http://wiki.lazarus.freepascal.org/Lazarus_Tdbf_Tutorial#Index.2Ffilte r_on_TDateTimes Good luck with this homework assignment