酒店预订系统(可预订客房,(按钮)) [英] Hotel Booking System (Room Available,(Buttons))

查看:54
本文介绍了酒店预订系统(可预订客房,(按钮))的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作酒店预订系统.我有15个按钮代表每个房间.选择日期之后,如果已经预订了房间,那么我需要带有数字的按钮变成红色,并且无法选择.但是,我还需要将按钮设置为红色,并且日期输入和输出日期之间必须要有时间.

I'm making a Hotel Booking System. I have 15 buttons representing each room. Once the date in has been selected, if a room has been booked, then I need the button with the number on it to turn red and cannot be selected. However, I also need the button to be red with the time in-between the date in and date out.

这是我到目前为止的代码.我不太确定从哪里开始.

This is the code I have so far. I'm not really sure where to start.

 Dim date1 As DateTime = dtpDateIn.Value.Date
    Dim date2 As DateTime = dtpDateOut.Value.Date
    Dim da As OleDbDataAdapter = New OleDbDataAdapter
    Dim BookingFound As String = False 
    MyConn = New OleDbConnection 

    MyConn.ConnectionString = connString 

    MyConn.Open() 

    str1 = ("Select * from BookingInformation where [Date In] >= '" & date1 & "' AND [Date Out] <= '" & date2 & "'") 

    '("SELECT * FROM [BookingInformation] WHERE [Date In] = #" & dtpDateIn.Value.Date & "#") 

    Dim cmd1 As OleDbCommand = New OleDbCommand(str1, MyConn) 
    dr = cmd1.ExecuteReader 

    While dr.Read() 
        BookingFound = True 

        strDateOut = dr("Date Out").ToString 
        strDateIn = dr("Date In").ToString 
        strRoomNumber = dr("Room Number").ToString 

        CmbRooms.Items.Remove(strRoomNumber)
    End While
    MyConn.Close() 
End Sub

推荐答案

首先,如果您将所有房间按钮收集到一个列表中并按房间号进行排序,将会稍微容易一些.理想情况下,按钮名称应类似于btnRoom01.如果您确保任何一位数字都以零开头,则示例中使用的排序方法将起作用.如果没有,则需要将其重写为您的要求.

First of all, it will be a little easier if you collect all your room buttons into a list and order them by the room number. Ideally, the button name will be something like btnRoom01. If you make sure that any single digit numbers start with a zero, the method of ordering used in my sample will work. If not, you'll need to re-write it to your requirements.

创建一个表单范围的列表-

create a form wide list -

Dim roomButtons As New List(Of Button)

这是收集按钮的代码

Private Sub AddButtonsToCollection()
    roomButtons.Clear()
    For Each ctl As Control In Me.Controls
        Dim btn As Button
        If ctl.GetType = GetType(Button) Then
            btn = CType(ctl, Button)
            If btn.Name.Contains("btnRoom") Then
                roomButtons.Add(btn)
                roomButtons = roomButtons.OrderBy(Function(x) x.Name).ToList
            End If
        End If
    Next
End Sub

您的while循环应该看起来像这样

And your while loop should look something like this

While dr.Read()
    Dim bookingDateIn, bookingDateOut As Date
    BookingFound = True
    Date.TryParse(dr("Date Out").ToString, bookingDateIn)
    Date.TryParse(dr("Date In").ToString, bookingDateIn)
    Dim RoomNumber As Integer = CInt(dr("Room Number").ToString)
    If (bookingDateIn <= date2) And (bookingDateOut >= date1) Then
        roomButtons(RoomNumber - 1).BackColor = Color.Red
        roomButtons(RoomNumber - 1).Text = RoomNumber.ToString & vbCrLf & bookingDateIn.ToShortDateString & vbCrLf & bookingDateOut.ToShortDateString
    End If
End While

这篇关于酒店预订系统(可预订客房,(按钮))的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆