避免预约冲突

发布于 2025-01-03 15:27:12 字数 317 浏览 0 评论 0原文

我有三个表:

Employee(Id,name etc)
Appointment(Id,date,time,employee id, clientid etc)
Client(Id,name etc) 

员工表与约会表是一对多,客户表也是如此。

然而,我想要实现的是允许系统防止重复或冲突的约会,但无法完全弄清楚如何解决这个问题。我是否需要一个额外的表,其中包含可用的时间段以及如何将它们连接在一起?或者例如员工可用性表?

或者我可以用我已经拥有的东西并且仅仅通过操作查询来实现我需要的东西吗?

非常感谢

I have three tables:

Employee(Id,name etc)
Appointment(Id,date,time,employee id, clientid etc)
Client(Id,name etc) 

The Employee table has a 1 to many with the Appointment table as does the Client table.

However what I'm trying to achieve is to allow for the system to prevent duplicate or conflicting appointments but cant quite get my head around how to go about this. Would I need an additional table with say available time slots and some how link it all together? Or for example an employee availability table in addition?

Or could I achieve what I need with what I already have and just by manipulation of queries?

Many thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

街角卖回忆 2025-01-10 15:27:12

我认为预约表是必要的。它将允许您仅包含可用的空档,并分析员工的工作量和可用性。该表将为每位员工每天提供 15 分钟的时间。您可能希望为假期/病假/通常在一段时间内不可用添加另一个表。

编辑

我曾设想过以下内容:

Timeslots:
EmployeeID ) Primary key
TimeSlot   ) 
JobID      - Foreign key
Status     ) And so forth
Notes      ) 

“我想与 E1 提前预约”

SELECT TimeSlots.EmployeeID, TimeSlots.TimeSlot, TimeSlots.JobID
FROM TimeSlots
WHERE TimeSlots.EmployeeID=1
AND TimeSlots.TimeSlot Between #2/9/2012 9:0:0# And #2/9/2012 11:30:0#

“我想在上午 9:00 预约”

SELECT TimeSlots.EmployeeID, TimeSlots.TimeSlot, TimeSlots.JobID
FROM TimeSlots
WHERE TimeSlots.TimeSlot Between #2/9/2012 9:0:0# And #2/9/2012 9:30:0#

I think an appointments table is going to be necessary. It will allow you to include only available slots and also to analyse employees workload and availability. The table would include 15 minute slots for each day for each employee. You may wish to add a further table for holidays / sick days / generally unavailable for a chunk of time.

EDIT

I had envisioned something on the lines of:

Timeslots:
EmployeeID ) Primary key
TimeSlot   ) 
JobID      - Foreign key
Status     ) And so forth
Notes      ) 

"I want an early appointment with E1"

SELECT TimeSlots.EmployeeID, TimeSlots.TimeSlot, TimeSlots.JobID
FROM TimeSlots
WHERE TimeSlots.EmployeeID=1
AND TimeSlots.TimeSlot Between #2/9/2012 9:0:0# And #2/9/2012 11:30:0#

"I want an appointment at 9:00am"

SELECT TimeSlots.EmployeeID, TimeSlots.TimeSlot, TimeSlots.JobID
FROM TimeSlots
WHERE TimeSlots.TimeSlot Between #2/9/2012 9:0:0# And #2/9/2012 9:30:0#
一抹淡然 2025-01-10 15:27:12

为了防止冲突,这里的逻辑非常简单:

冲突发生在以下情况:

RequestStartDate <= EndDate 
and 
RequestEndDate >= StartDate 

因此,上面是一个相当简单的查询。如果发生任何碰撞,
上面将返回记录,而您只是不允许预订。

当然,上述内容可以很容易地延长时间,甚至是特定的房间。

例如:

RequestStartTime <= EndTime 
and 
RequestEndTime >= StartTime 
And
RequestDate = BookingDate

事实上,在访问中,由于您可以存储日期+时间列,那么我们就回到了上面的第一个示例(因此,如果您这样做,预订可能会跨越多天)。如前所述,如果这是针对特定房间的,则只需在上面添加房间条件即可。

Access 2010 确实有表触发器和存储过程,但是由于您需要用户的 UI,因此这样的代码通常可以达到目的:

dim strWhere                 as string 
dim dtRequeestStartDate      as date 
dim dtRequestEndDate         as date 

dtRequestStartDate = inputbox("Enter start Date") 
dtRequestEndDate = inputbox("Enter end date") 

strWhere="#" & format(dtRequestStartDate,"mm/dd/yyyy") & "# <= EndDate" & _ 
     " and #" & format(dtRequestEndDate,"mm/dd/yyyy") & "#  >= StartDate" 


if dcount("*","tableBooking",strWhere) > 0 then 
    msgbox "sorry, you cant book 
...bla bla bla.... 

上面只是一个示例,我相信您会构建一个很好的表单
提示用户预订日期。

因此,上述简单条件确实会返回任何冲突。并且编写了这么多预订系统,我强烈建议您不要提前创建空白记录,而是使用上述正确的逻辑,从而仅将记录添加到预订系统,而不必编写大量代码来创建一堆空白记录带有时隙等的记录。

上面的简单查询将防止冲突。

To prevent collisions, the logic here is quite simple:

A collision occurs when:

RequestStartDate <= EndDate 
and 
RequestEndDate >= StartDate 

The above is thus a rather simply query. If any collision occurs, the
above will return records and you simply don't allow the booking.

The above of course can EASY be extended for time, and even a particular room.

Eg:

RequestStartTime <= EndTime 
and 
RequestEndTime >= StartTime 
And
RequestDate = BookingDate

And in fact in access since you can store a date + time column, then we are quite much back to the first example above (and as such a booking can span multiple days if you do this). And as noted, if this was for a particular room, then just add a room condition to the above.

Access 2010 does have table triggers and store procedures, but since you need a UI for the user, then code like this normally does the trick:

dim strWhere                 as string 
dim dtRequeestStartDate      as date 
dim dtRequestEndDate         as date 

dtRequestStartDate = inputbox("Enter start Date") 
dtRequestEndDate = inputbox("Enter end date") 

strWhere="#" & format(dtRequestStartDate,"mm/dd/yyyy") & "# <= EndDate" & _ 
     " and #" & format(dtRequestEndDate,"mm/dd/yyyy") & "#  >= StartDate" 


if dcount("*","tableBooking",strWhere) > 0 then 
    msgbox "sorry, you cant book 
...bla bla bla.... 

The above is just an example, and I am sure you would build a nice form that
prompts the user for the booking dates.

So the above simple conditions above does return ANY collisions. And having written so many reservation systmes, I strongly recommend you do NOT create blank records ahead of time, but use the above correct logic and thus ONLY add records to the booking system and not have to write tons of code to create a bunch of blank records with time slots etc.

The above simply query will prevent collisions.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文