[英]check conflict between two datetimepicker
So I'm making a simple reservation system ,C# and sql . 因此,我正在制作一个简单的预订系统C#和sql。 I have datetimepicker 1 and datetimepicker 2 .
我有datetimepicker 1和datetimepicker 2。 For ex.
对于前。 datetimepicker = aug 1 2009 and datetimepicker2 = aug 3 2009 saved in sql by the user .
datetimepicker = 2009年8月1日,datetimepicker2 = 2009年8月3日,由用户保存在sql中。
What to do with that so that the next customer that would try to get the date 1-3 would be forced to choose another date ? 该怎么办,以便下一个试图获取1-3日期的下一个客户将被迫选择另一个日期?
You can run a query like this one: 您可以运行如下查询:
select count(*) as cnt
from reservations t
where
not
(
(@dtTo <= t.DateFrom)
or
(@dtFrom >= t.DateTo)
)
assuming that @dtFrom, @dtTo are the dates the second user has chosen, and assuming 假设@ dtFrom,@ dtTo是第二个用户选择的日期,并假设
you have a reservations
table with DateFrom
and DateTo
columns. 您有一个包含
DateFrom
和DateTo
列的reservations
表。
What's the idea behind this: 这背后的想法是什么:
two segments of time [dateFrom1, dateTo1]
and [dateFrom2, dateTo2]
are not 时间
[dateFrom1, dateTo1]
和[dateFrom2, dateTo2]
两个时间段不是
conflicting (ie are not overlapping) for this reservation-based scenario if and only if: 仅在以下情况下,此基于预留的方案发生冲突(即不重叠):
dateTo1 <= dateFrom2 or dateFrom1 >= dateTo2
(draw it on a piece of paper and you'll see why). (将其画在一张纸上,您会明白为什么)。
So if the negation 所以如果否定
not ( dateTo1 <= dateFrom2 or dateFrom1 >= dateTo2 )
is true, the two segments are overlapping/conflicting. 是的,这两个部分是重叠/冲突的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.