Dreamweaver room reservation business is characterized by a large customer mobility, the user registration method is more flexible, in addition to the usual verification of booking business, but also to prevent the reservation full of the situation to continue to book rooms. This example will provide readers with an introduction to how to make room reservation business.
Effect description
Figure 96-1 shows the basic interface of the booking business, where users can log in or register and book rooms directly.
Creative Ideas
Through the program to detect whether the user successfully logged in, the login error can be registered successfully, and add the user's booking information. Use the "Compare" under the "Datatime" class to compare the time that a user subscribes to a time that other users have subscribed to to detect whether the subscription is full.
Operation Steps
Step one to set the environment for your application
(1) Copy the contents of instance 96 in the CD. Copy all files under the CD \ Source file \ Instance 96 directory to the C:\ Inetpub\wwwroot\ "directory. Set the home directory for the default Web site as "C:\" in the IIS server Inetpub\wwwroot\hotel "(refer to the related method in instance 1). New site "Hotel" in Dreamweaver, whose site directory is "C:\ Inetpub\wwwroot\hotel, the method of establishing a site can refer to instance 2.
(2) "HOTEL.MDB" structure. Run Access, open the C:\ Inetpub\wwwroot\adweb\data\hotel.mdb ", you can see the database" Hotel.mdb "in the" Tboder "," Tbuser "and" tbroom "3 data tables. The "Tboder" table is used to store information about the user's reservation, as shown in Figure 96-2 of the table's data structure. The "tbuser" table is used to store user registration information, as shown in Figure 96-3 of the table's data structure. The "tbroom" table is used to store the price of various rooms and the corresponding number of rooms in the hotel, and the data structure of the table is shown in Figure 96-4. There is also a query table "Userorder" in the Database "Hotel.mdb", and the query table is set in Design view as shown in Figure 96-5.
(3) Establish the database link "adconn", Link the database "C:\ Inetpub\wwwroot\adweb \data\hotel.mdb ", the method can refer to instance 75.
Step TwoDesign Basic Page
(1) "index.aspx" page structure. Open "Index.aspx", which is provided directly by the material and is initially opened as shown in Figure 96-6. ① and ② in the figure are images rather than image buttons, the image in the rounded box ① the action is to add an "OnClick" action to display the "Layer1" layer in which a calendar control is added with the ID "MyCalendar1", and the image shown in the Fillet box ② is added " OnClick action to display the "Layer2" layer in which a calendar control is added with the ID "MyCalendar2".
Tip: The settings for other controls on the "index.aspx" initial page are shown in table 96-1.
Table 96-1 settings for other controls on the "index.aspx" initial page
Control corresponding text |
control type |
Control ID |
Check-in time |
asp: Text Box |
StartTime |
Check-out time |
asp: Text Box |
Lasttime |
Number of bookings |
asp: Text Box |
Ordernum |
Member ID |
asp: Text Box |
UserID1 |
Member password |
asp: Text Box |
UserPass1 |
Registration ID |
asp: Text Box |
Userid |
real name |
asp: Text Box |
Usename |
Login Password |
asp: Text Box |
Userpass |
Duplicate password |
asp: Text Box |
UserPass2 |
Email |
asp: Text Box |
UserEmail |
Contact phone |
asp: Text Box |
Usertel |
"Subscribe Now" button |
asp: Button |
Orderbt |
Reset All button |
form Buttons |
Submit (its action resets the form) |
(2) Add the DataSet "Roomdata". Add the DataSet "Roomdata" in the server behaviors panel, which is set in the DataSet dialog box as shown in Figure 96-7.
(3) Modify the SQL command. Click the Advanced button in the DataSet dialog box to switch to the DataSet Advanced dialog box and change the SQL command from select Pice,roomid to Roomnum,roomtype from Tbroom to select Pice,roomid, Roomnu M, Trim (roomtype) +chr +cstr (pice) as Roomtype from Tbroom, as shown in Figure 96-8.
(4) Add a list of data. Click ASP: Radio button list on the ASP.net shortcut menu, as shown in Figure 96-9.
(5) Add "System.Data", "System.Data.OleDb", "System.Globalization" and "System.Threading" 4 namespaces to the page, as shown in the rounded box in Figure 96-10.
(6) Define the page load process "Page_Load", which is described in the following code.
Sub Page_Load (ByVal Src as Object, ByVal E as EventArgs)
Dim I as Integer
If not Page.IsPostBack Then
For i = 0 to Roomdata.recordcount-1
Dim str1, str2 as String
STR1 = Roomdata.defaultview (i). Row ("Roomtype")
str2 = CStr (Roomdata.defaultview (i). Row ("Roomid"))
ROOMRADIO.ITEMS.ADD (New ListItem (str1, str2))
Next
End If
End Sub
(Reader can open "CD" | "Source file" | "Instance 96" | "96.1.txt" file, copy directly)
Program Description:
The "Page_Load" procedure is to add a list item to the radio button list "Roomradio" when the page is first loaded, and the label value of the Add List item equals the field "Roomtype" under the "Roomdata" DataSet, and the selected value is equal to the field "Roomid".
Hint: Maybe someone will ask why not use the data binding of the radio button list directly? This is due to data binding through Dreamweaver, where errors that cannot get a radio button list selection are frequently found in the program.
(7) Define the "mycalendar1_selectionchanged" procedure to respond to the "selectionchanged" event of the Calendar control "MyCalendar1", which is described in the following code.
Protected Sub mycalendar1_selectionchanged (ByVal sender as Object, ByVal e as System.EventArgs) Handles Mycalendar1.selectionchanged
Starttime.text = MyCalendar1.SelectedDate.ToShortDateString
End Sub
(Reader can open "CD" | "Source file" | "Instance 96" | "96.2.txt" file, copy directly)
(8) Define the "mycalendar2_selectionchanged" procedure to respond to the "selectionchanged" event of the Calendar control "MyCalendar2", which is described in the following code.
Protected Sub mycalendar2_selectionchanged (ByVal sender as Object, ByVal e as System.EventArgs) Handles Mycalendar2.selectionchanged
lasttime.text= MyCalendar2.SelectedDate.ToShortDateString
End Sub
step three to achieve customer reservation business
(1) The process of implementing the customer reservation business is shown in Figure 96-11.
(2) Add 4 global variables to the page, as shown in the rounded box in Figure 96-12.
(3) define the "Usercheck" function. This function is used to detect whether a user is logged on correctly, if the login is incorrect, if the user is logged on correctly or if the registration succeeds, the function returns "True", otherwise it returns "False", which is described in the following code.
Function Usercheck () as Boolean
Dim Hotelada1, Hotelada2 as OleDbDataAdapter
Dim HotelDataSet1, HotelDataSet2 as System.Data.DataSet
Dim Hoteldt1, Hoteldt2 as DataTable
Dim Tbrow as DataRow
Dim yy as OleDbCommandBuilder
hotelstring = "SELECT * from Tbuser Where userid= '" & Userid1.text & "' and Userpass= '" & Userpass1.text & "'"
HOTELADA1 = New OleDbDataAdapter (hotelstring, conn)
HotelDataSet1 = New System.Data.DataSet
Hotelada1.fill (HotelDataSet1, "Tbuser")
HOTELDT1 = Hoteldataset1.tables ("Tbuser")
If Hoteldt1.Rows.Count > 0 Then
StrName = hoteldt1.rows (0) ("UserId")
Else
If (Trim (userid.text) <> Nothing) and (Trim (userpass.text) <> Nothing) _
and (Trim (username.text) <> Nothing) and (Trim (useremail.text) <> Nothing) _
and (Trim (Usertel.text) <> Nothing) Then
hotelstring = "SELECT * FROM Tbuser"
Hotelada2 = New OleDbDataAdapter (hotelstring, conn)
yy = New OleDbCommandBuilder (Hotelada2)
HotelDataSet2 = New System.Data.DataSet
Hotelada2.fill (HotelDataSet2, "Tbuser")
HOTELDT2 = Hoteldataset2.tables ("Tbuser")
Tbrow = Hoteldt2.newrow
Tbrow ("UserId") = Userid.text
Tbrow ("userpass") = Userpass.text
Tbrow ("UserName") = Username.text
Tbrow ("useremail") = Useremail.text
Tbrow ("Usertel") = Usertel.text
HOTELDT2.ROWS.ADD (Tbrow)
Hotelada2.update (HotelDataSet2, "Tbuser")
StrName = Userid.text
Else
Usercheck = False
Exit Function
End If
End If
Usercheck = True
End Function
(4) Define the "Roomcheck" function. This function first detects whether the user has chosen to book a room type, if no selection is made, the function returns "false" and then, if the user chooses to book the room type, detects whether the selected room type has been booked full for the time period of the subscription, and returns "false" if it is, otherwise returns "True ", the code for the function is described below.
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
(Reader can open "CD" | "Source file" | "Instance 96" | "96.5.txt" file, copy directly)
Tip: In the program, use the "Compare" method under the "Datatime" class to compare time to find orders that appear to be duplicated over time. The following 3 cases are time duplicates: The ① user chooses a check-in time smaller than the "StartTime" field value in the order, the check-out time is greater than the "lasttime" field value, and ② the user's choice of check-in time is greater than the "starttime" field value in the order, and the check-out time is less than Sttime field value, ③ the user's chosen check-in time is less than the "starttime" field value in the order, and the Check-out time selected is less than the "lasttime" field value. Find the number of duplicates if the maximum number of customers in the type of room is equal to that, then the type of room in that time period is booked full.
(5) Define the "Orderinser" process to add information about the user's booking room to the "tborder" table, which is described in the following code.
sub Orderinser ()
Dim Hotelada2 As OleDbDataAdapter
Dim HotelDataSet2 As System.Data.DataSet
Dim Hoteldt2 As DataTable
Dim tbrow As DataRow
Dim yy As OleDbCommandBuilder
hotelstring = "SELECT * FROM Tbor Der "
Hotelada2 = new OleDbDataAdapter (hotelstring, conn)
HotelDataSet2 = new System.Data.DataSet
yy = new OleD Bcommandbuilder (Hotelada2)
Hotelada2.fill (HotelDataSet2, "Tborder")
Hoteldt2 = Hoteldataset2.tables (" Tborder ")
Tbrow = Hoteldt2.newrow
Tbrow (" UserID ") = StrName
Tbrow (" roomid ") = CInt ( RoomRadio.SelectedItem.Value)
Tbrow ("ordernum") = CInt (Ordernum.text)
Tbrow ("starttime") = Starttime.text
Tbrow ("lasttime") = Lasttime.text
Hoteldataset2.tables ("Tborder"). Rows.Add (Tbrow)
Hotelada2.update (HotelDataSet2, Tborder)
End Sub
(6) Define procedure "Errinfo" When used for an error, the procedure is called to display an error message, as described in the following code.
Sub Errinfo (ByVal errmess as String)
Dim Strscript as String
Strscript = "<script language=javascript>"
Strscript + + "alert" (' + errmess + '); "
Strscript = "<"
Strscript = "/"
Strscript = "Script>"
RegisterClientScriptBlock ("Showsavemessage", Strscript)
End Sub
(Reader can open "CD" | "Source file" | "Instance 96" | "96.7.txt" file, copy directly)
(7) Define the OnClick event response procedure for the "Subscribe now" button to "Orderbt_click" and bind the procedure to the OnClick event of the Subscribe now button. The source code for the "Orderbt_click" process is described below.
Protected Sub Orderbt_click (ByVal sender as Object, ByVal e as System.EventArgs)
Dim Errstr as String
Hotelconn = "Provider=Microsoft.Jet.OLEDB.4.0;Data source=" & Server.MapPath ("Data/hotel.mdb")
conn = New OleDbConnection (hotelconn)
If usercheck () = False Then
ERRSTR = "Please log in correctly or enter your registration information correctly!" "
Errinfo (ERRSTR)
Exit Sub
End If
If Roomcheck () = False Then
ERRSTR = "Your reservation room has been booked up for the time period of your reservation!" "
Errinfo (ERRSTR)
Exit Sub
End If
Orderinser ()
End Sub
(8) Preview effect. Save "INDEX.APSX" to preview the effect in IE, as shown in Figure 96-1.
This example explains the simplest process in the room reservation business: User registration, login, verify that the user is booked full to complete the room reservation business. This example does not validate the server control, nor does it validate the uniqueness of the registration name, and interested readers can add the relevant features by reference to instance 76 and instance 77. When the reservation information is submitted, the room booking business will send the reservation information to the reservation room by e-mail, this example also does not explain this knowledge, interested readers can refer to example 84 "Step three establish order mail automatic reply" in the relevant content. When the booking information is submitted, the room booking business will also send the information to the hotel's main station, so as to update the estimated database of the main station, as this knowledge is beyond the scope of Dreamweaver application, so this is no longer described in detail. At this point, the example operation is complete.