(读者可打开【光盘】|【源文件】|【实例 96 】|【 96.4.txt 】文件,直接复制) [page_break] ( 4 )定义“ Roomcheck ”函数。该函数首先检测用户有没有选择预订客房类型,如果没有选择,则该函数返回“ False ”,接着在用户选择预订客房类型的情况下,检测所选择的客房类型在预订的时间段中是否已预订满,如果是,则返回“ False ”,否则将返回“ True ”,该函数的代码如下所述。 Function Roomcheck() As Boolean Dim Hotelada1, Hotelada2 As OleDbDataAdapter Dim HotelDataSet1, HotelDataSet2 As System.Data.DataSet Dim Hoteldt1, Hoteldt2 As DataTable Dim i, RoomI As Integer If RoomRadio.SelectedItem.Value <> Nothing Then Hotelstring = "Select * From UserOrder Where RoomID=" & RoomRadio.SelectedItem.Value Hotelada1 = New OleDbDataAdapter(Hotelstring, conn) HotelDataSet1 = New System.Data.DataSet Hotelada1.Fill(HotelDataSet1, "UserOrder") Hoteldt1 = HotelDataSet1.Tables("UserOrder") Dim Date1, Date2 As Date Date1 = StartTime.Text Date2 = LastTime.Text For i = 0 To Hoteldt1.Rows.Count - 1 Dim roomdate1, roomdate2 As Date roomdate1 = Hoteldt1.Rows(i)("StartTime") roomdate2 = Hoteldt1.Rows(i)("LastTime") If (System.DateTime.Compare(Date1, roomdate1) And System.DateTime.Compare(roomdate2, Date1)) _ Or (System.DateTime.Compare(Date2, roomdate1) And System.DateTime.Compare(roomdate2, Date2)) _ Or (System.DateTime.Compare(roomdate1, Date1) And System.DateTime.Compare(Date2, roomdate2)) Then RoomI += 1 End If Next Hotelstring = "select RoomNum From tbRoom where RoomID=" & RoomRadio.SelectedItem.Value Hotelada2 = New OleDbDataAdapter(Hotelstring, conn) HotelDataSet2 = New System.Data.DataSet Hotelada1.Fill(HotelDataSet2, "tbRoom") Hoteldt2 = HotelDataSet2.Tables("tbRoom") If RoomI +CInt(OrderNum.Text) > Hoteldt2.Rows(0)("RoomNum") Then Roomcheck = False Exit Function End If Else Roomcheck = False Exit Function End If Roomcheck = True End Function | |