酒店客房预订声明 [英] Hotel Room Booking Statement

查看:169
本文介绍了酒店客房预订声明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上,我正在为我的计算一级课程做一个基本的酒店预订系统,并且打了一个绊脚石(也不帮助有偏头痛!)



我正在检查一个房间是否可用,然后用户预订(应用程序全部由工作人员运行和使用),但试图让我的头脑如何做到这一点。 p>

目前我在想,我可以搜索目前的预订数据库中的房间号码和日期,我想预订,如果一场比赛回来,这意味着某些房间是已预订这很好,很好,但是如何告诉他日期呢? (对不起,坏的问题)我正在考虑一个伪代码版本的sql语句:


如果已经在数据库中检查预订日期
之前检查新预订的日期 AND 预订结帐日期已经
在数据库'是在之后的新预订日期,然后房间已经
已预订。


基本上如果它返回一个记录,那么我知道房间已经预订。但是,我只需要弄清楚如何使用SQL根据我的入住/退出日期搜索记录。



但是这样可以双重预订,我疯了:/任何想法?

解决方案

起初可能看起来不是很明显,但实际上可以简化测试全部或部分日期重叠只有两个条件



假设您有 BOOKING 表与现有的预订和新的预订与检查日期 @NEW_CHECK_IN 和退房日期 @NEW_CHECK_OUT 。要找到与这些日期重叠的所有预订(假设终点是包容性的),您只需要这种where子句:

  - 选择重叠预订
- ...
WHERE BOOKING.CHECK_IN< = @NEW_CHECK_OUT
AND BOOKING.CHECK_OUT> = @NEW_CHECK_IN
- ...

我知道它看起来太简单了,但是尝试用drf说明的场景(加上三个错过,(1)新预订在现有预订后,(2)新预订严格在现有预订中,(3)新预订等于现有预订)。您会看到,这套简单的条件涵盖了所有这些情况。


Essentially i'm making a basic hotel booking system for my computing a-level coursework, and have hit a stumbling block (doesn't help having a migraine either!)

I'm in the process of checking if a room is available for then the user to book (the application is all run and used by staff by the way) but trying to get my head around how to do it.

At the moment I was thinking I could just search the current booking database for the room number and dates I want to book for and if a match came back that meant that certain room was booked. That's all fine and dandy, but how do I tell it the range of dates? (sorry bad question) I was thinking an pseudo code version of the sql statement on the lines of:

If 'check in date of booking already on the database' is before 'check in date of new booking' AND 'check out date of booking already on the database' is after 'check in date of new booking' then room is already booked.

Basically if it returns a record then I know that room is booked. But I just need to figure out how to use SQL to search for records based on my check in/out dates.

But that'll allow double bookings, agh it's driving me mad :/ Any ideas?

解决方案

It may not seem totally obvious at first, but you can actually simplify the testing of a full or partial date overlap with just two conditions.

Let's say you've got BOOKING table with existing bookings and a new booking with check in date @NEW_CHECK_IN and check out date @NEW_CHECK_OUT. To find all bookings that overlap these dates (assuming the end points are inclusive) you just need this kind of where clause:

--Select overlapping bookings
-- ...
WHERE BOOKING.CHECK_IN <= @NEW_CHECK_OUT
  AND BOOKING.CHECK_OUT >= @NEW_CHECK_IN
-- ...

I know it looks too simple, but try it out with the scenarios that drf illustrated (plus the three that were missed, (1) where the new booking is after the existing booking, (2) the new booking is strictly within the existing booking and (3) the new booking is equal to the existing booking). You'll see that this simple set of conditions covers all of these scenarios.

这篇关于酒店客房预订声明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆