酒店预订系统 - 房间供应情况(搜索) [英] Hotel booking system - room availability (search)

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

问题描述

我正在创建一个酒店预订系统。但是,因为我不是专家,所以它不能做我想做的事情。目前,这段代码没有运行,我不太确定它出错的地方。我希望它像普通的酒店预订系统一样运行,例如,如果房间被预订为21/02/17至23/02/17,那么按钮在该日期期间将保持红色。但是它仍然可以在23/02/17预订(因为退房)。正如我所说的那样,我很新,所以可能已经有了一些东西但是还没有完全理解它。



我也在想我的str1应该改变对于诸如

I am creating a hotel booking system. However since I am not an expert, it doesn't do what I want it to be able to do. At the moment, this code does not run and I am not quite sure where it's going wrong. I want it to run like a normal Hotel booking system where for example, if a room was booked 21/02/17 to 23/02/17 then the button would remain red in that date period. However it would be able to still be able to be booked on the 23/02/17 (because of checking out). As I said I'm quite new so there may be something that exists already but just haven't quite understood it.

Also I was thinking should my str1 be changed to something such as

Select * from BookingInformation where theDate between Date In and Date Out and Room Number = 'Something'







Private Sub ReadRecords()
Dim btn As Button = Nothing
MyConn = New OleDbConnection
MyConn.ConnectionString = connString
MyConn.Open()

str1 = ("SELECT * FROM [BookingInformation] WHERE [Date Out] = '" & dtpDateOut.Value.Date & "'") 'When searching this searches for the data that you are looking for'

Dim cmd1 As OleDbCommand = New OleDbCommand(str1, MyConn)
dr = cmd1.ExecuteReader
While dr.Read()
    strRoomBooking = dr("Room Booking").ToString
    strDateIn = dr("Date In").ToString
    strDateOut = dr("Date Out").ToString


    If strDateOut > DateTime.Today Then
        If strRoomBooking = btn.Text Then
            btn.BackColor = Color.Red
        End If
    End If
End While
MyConn.Close()
End Sub

Private Sub Room_Booking_Load(sender As Object, e As EventArgs) Handles MyBase.Load
ReadRecords()

End If





我的尝试:



我已经尝试了上面的代码并且也看了一下并且想一想



What I have tried:

Ii have tried the code above and also had a look into it and think

<pre>Select * from BookingInformation where theDate between Date In and Date Out and Room Number = 'Something'



可以正常工作


may work

推荐答案

首先查看你正在存储的日期输出 - 等式检查需要确切的值,所以如果您没有将其设置为精确的时间,直到微秒 - 我建议检查时间酒店往往会有 - 那么比较将不匹配。



但是不要这样做就是这样。我知道这只是功课,但它是重要的东西:永远不要连接字符串来构建SQL命令。它让您对意外或故意的SQL注入攻击持开放态度,这可能会破坏您的整个数据库。改为使用参数化查询。



我建议停下来思考你想要做什么:当你预订酒店房间时,你什么时候租用它对于?实际上,它从开始日的第一个可用时间预订到结束日的结账。大多数酒店在退房和可用时间之间会有一个小时左右的差距,让员工有机会检查和打扫房间。因此,要使DB值反映实际酒店,并在预订时,检查第一天到结账时间的可用时间是否与任何预订时间重叠。如果没有,用户可以预订。
Start by looking at exactly what you are storing as the Date Out - equality checks require exact values, so if you are not setting that as an exact time of day down to the microsecond - and I'd suggest "check out time" which hotels tend to have - then the comparison won't match.

But don't do it like that. I know it's only homework, but it's important stuff: Never concatenate strings to build a SQL command. It leaves you wide open to accidental or deliberate SQL Injection attack which can destroy your entire database. Use Parametrized queries instead.

What I'd suggest is stopping and thinking about what you are trying to do: when you book a hotel room, when do you rent it for? Effectively, it's booked from "first available time" on start day to "checkout" on end day. And most hotels will have an hour or so gap between the "check out" and "available" time to give the staff a chance to check and clean the room. So make the DB values reflect the actual hotel, and when a booking comes in, check if the available time on the first day to the checkout time on the last day overlaps any booked period. If it doesn't, the user can book it.


这篇关于酒店预订系统 - 房间供应情况(搜索)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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