我正在尝试检查Events
每个事件中的 DateTime 重叠表。我已经编写了允许用户输入Module_code
. 这Module_code
将根据表中的条目进行检查Events
。如果Start_Date_Time
或对于任何事件与表中任何其他事件的或End_Date_Time
重叠,仅对于该模块,那么我想将事件行放入数组列表中,然后用结果填充网格视图。我有以下代码,我认为它可以实现我的大部分目标。但是,当我运行它时,gridview 中没有数据。调试显示没有发送任何内容。我认为这是我如何尝试将我的值传递给 arrayList 的问题。 Start_Date_Time
End_Date_Time
'return all relevant tables from the Modules database, based on the module code entered by the user.
Dim eventTime = (From mods In db.Modules
Join evnt In db.Events On mods.Module_code Equals evnt.Module_code
Join rm In db.Rooms On rm.Room_ID Equals evnt.Room_ID
Join build In db.Buildings On build.Building_code Equals rm.Building_code
Where ((mods.Module_code = initialModCode) And (evnt.Room_ID = rm.Room_ID))
Select evnt.Event_ID, evnt.Module_code, evnt.Event_type, evnt.Start_Date_Time, evnt.End_Date_Time, build.Building_code, rm.Room_Number)
Dim listClashes As New ArrayList()
For i As Integer = 0 To eventTime.Count - 1
For j As Integer = i + 1 To eventTime.Count - 1
If (eventTime.ToList(i).Start_Date_Time < eventTime.ToList(j).End_Date_Time) And (eventTime.ToList(i).End_Date_Time > eventTime.ToList(j).Start_Date_Time) Then
'MsgBox("Clash", MsgBoxStyle.MsgBoxSetForeground, "")
listClashes.Add(eventTime)
Else
'MsgBox("No Clash", MsgBoxStyle.MsgBoxSetForeground, "")
End If
Next
Next
gdvClashes.DataSource = listClashes
gdvClashes.DataBind()
编辑..代码更改为
If (eventTime(i).Start_Date_Time <= eventTime(j).End_Date_Time) And (eventTime(i).End_Date_Time >= eventTime(j).Start_Date_Time) Then
'MsgBox("Clash", MsgBoxStyle.MsgBoxSetForeground, "")
listClashes.Add(eventTime.ToList)
Else
此编辑无效。说是抛出异常The query operator 'ElementAtOrDefault' is not supported.
我在这里走错了方向吗?
编辑..
新代码建议
Dim listClashes = From e1 In eventTime
From e2 In eventTime
Where (e2.Start_Date_Time >= e1.Start_Date_Time) And (e2.Start_Date_Time <= e1.End_Date_Time)
Select eventTime
gdvClashes.DataSource = listClashes
gdvClashes.DataBind()
这应该包含在 for 循环中还是引用 arrayList 或其他东西?