简体   繁体   English

检查两个日期时间选择器之间的冲突

[英]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. 您有一个包含DateFromDateTo列的reservations表。

  • If this query returns 0, then allow the second user to save. 如果此查询返回0,则允许第二个用户保存。
  • If it returns a number > 0, then don't allow the second user to save. 如果返回的数字> 0,则不允许第二个用户保存。

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.

相关问题 无法在两个日期时间选择器之间过滤数据网格视图 - Can't filter datagridview between two datetimepicker 在访问数据库中的两个日期时间选择器之间搜索 - Searching between two datetimepicker in access database 显示两个日期时间选择器之间的数据。“条件表达式中的数据类型不匹配” - Displaying the data between two datetimepicker,.“Data type mismatch in criteria expression” 检查是否为datetimepicker输入了值? - check if value is entered for datetimepicker? Datetimepicker和文本框之间的计算 - Calculation Between Datetimepicker and Textbox 为什么同一控件上的两个StaticResource之间存在冲突? - Why am I having a conflict between two StaticResource on the same control? 两个库(LiveChart 和 HandyControl)之间的 WPF 冲突创建图形偏移 - WPF Conflict between two librairies (LiveChart & HandyControl) create a graph offset 检查字符串是否在两个字母之间 - Check if string is between two letters 检查两个IEnumerable之间的存在 - check existense between two IEnumerable C# 在 Datagridview 中显示两个日期之间的数据。 来自 DatetimePicker 或文本框的日期 - C# show data between two dates in Datagridview. Dates from DatetimePicker or Textbox
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM