Imports System.Collections.Generic
Imports System.Linq
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Collections
Imports System.Data
Partial Class CheckRoom
Inherits System.Web.UI.Page
Private Connect As New Connect()
Private sql As String
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
sql = "select * from event_tb"
End Sub
Private Function check_event() As ArrayList
Dim room_name As New DataTable()
Connect.[Select]("SELECT * FROM room_tb", room_name)
Dim room As Integer = room_name.Rows.Count
Dim list As New ArrayList()
Dim i As Integer
Dim start_date As DateTime = DateTime.Parse(txt_start.Text)
Dim ent_date As DateTime = DateTime.Parse(txt_end.Text)
For i = 0 To room - 1
'sql = "SELECT * FROM event_tb WHERE (start_date BETWEEN '" + start_date.ToString("yyyy/MM/dd") + "' AND '" + ent_date.ToString("yyyy/MM/dd") + "') OR (end_date BETWEEN '" + start_date.ToString("yyyy/MM/dd") + "' AND '" + ent_date.ToString("yyyy/MM/dd") + "') AND room_id ='" + i.ToString() + "'";
sql = "SELECT * FROM event_tb WHERE (start_date BETWEEN '" & start_date.ToString("yyyy/MM/dd") & "' AND '" & ent_date.ToString("yyyy/MM/dd") & "') AND room_id ='" & Convert.ToString(room_name.Rows(i)("room_id")) & "'"
If Connect.[Select](sql).Rows.Count > 0 Then
list.Add(New roomCheck("ห้อง " & Convert.ToString(room_name.Rows(i)("room_name")), "ไม่ว่าง"))
Else
list.Add(New roomCheck("ห้อง " & Convert.ToString(room_name.Rows(i)("room_name")), "ว่าง"))
End If
Next
Return list
End Function
Public Class roomCheck
Private m_room_name As String
Private m_room_status As String
Public Sub New(ByVal room_name__1 As String, ByVal room_status__2 As String)
Room_name = room_name__1
Room_status = room_status__2
End Sub
Public Property Room_name() As String
Get
Return m_room_name
End Get
Set(ByVal value As String)
m_room_name = value
End Set
End Property
Public Property Room_status() As String
Get
Return m_room_status
End Get
Set(ByVal value As String)
m_room_status = value
End Set
End Property
End Class
Protected Sub btn_check_Click(ByVal sender As Object, ByVal e As EventArgs)
g_check.DataSource = Nothing
Dim list As ArrayList = check_event()
g_check.DataSource = list
g_check.DataBind()
End Sub
End Class
ใน event_tb มีฟิลด์เอาไว้เก็บ room status ไหมครับ ว่าตอนนี้ room status = booked แล้วหรือยัง
Code (VB.NET)
sql = "SELECT * FROM event_tb WHERE (start_date BETWEEN '" & start_date.ToString("yyyy/MM/dd") & "' AND '" & ent_date.ToString("yyyy/MM/dd") & "') AND room_status !='booked'"