Você está na página 1de 6

5/4/2017 HotelReservationSystemCodeProject

12,905,528 members 50,232 online Sign in

Searchforarticles,questions,tips
articles Q&A forums lounge

Hotel Reservation System


Jomar Pabuaya, 29 Mar 2009 GPL3 Rate this:
4.82 14 votes

An explanation of the useful code within Hotel Reservation System

Download Hotel_Management_System_VB 708.69 KB

Introduction
In this article I will explain the important procedure or function that I used in Hotel Reservation System. I wrote this article in the purpose that you will be able to use some of the useful code
here in my application. May it be a payroll system, inventory system, or any application that have the same concept like filling a Listview or Combobox.

Background
Ive posted an article before for my Hotel Reservation System here using Visual Basic 6.0. That time, I was thinking that this website is just like www.planetsourcecode.com. So I did not
bother to explain very well the importance of the program. As a result, that article has been deleted by the moderator of CodeProject.com.
In the past, I received a bad comment for I am using an obsolete version of visual basic. So I made an upgrade with my Hotel Reservation System from VB 6.0 to VB.NET. Just a note though
for VB 6.0 programmer kindly continue with what you are doing right now if you feel you are more productive in version 6.0. But if you want to upgrade your knowledge, then I recommend
using the new version which is VB.Net.

Using the Software


My Hotel Reservation System will help you manage a collection of data in your hotel. Moreover, you can record a reservation, check in, check out, payments, etc.
Since the purpose of this article is to teach you the importance of source code within this program, I attached here a link where you can read simple tutorial from my website at
http://www.sourcecodester.com/blog/freehotelmanagementsystemmanual.html.

https://www.codeproject.com/Articles/34533/HotelReservationSystem 1/6
5/4/2017 HotelReservationSystemCodeProject

Using the Code


May be this code isnt new to all of you but I do believe there are still programmer out there who needs this. I have three important code snippets to share which I used in this program
Hotel Reservation System.

Filling a ListView Control


Overview

The Windows Forms ListView control displays a list of items with icons. You can use a list view to create a user interface like the right pane of Windows Explorer. The control has four view
modes: LargeIcon, SmallIcon, List, and Details. Source: Microsoft Visual Studio 2008 Documentation

In the previous paragraph, listview is used to display a list of items. So, in my application I used it to display a list of records from a table with a customize column.
To fill a listview in my program you call it like:

Hide Copy Code


FillListView(lvList,GetData(sSql))

Where lvList in the first parameter is a ListView control in the FillListView procedure. The second parameter GetDatasSql will first call the GetData function and returns a data using
OleDbDataReader.

Before we call the FillListView procedure, we will call first the procedure named FillList. In this procedure you can customize the number of columns that you want to show in a listview.

Heres the code for FillList procedure:

Hide Copy Code


PublicSubFillList()
WithlvList
.Clear()

.View=View.Details
.FullRowSelect=True
.GridLines=True
.Columns.Add("RoomNumber",90)
.Columns.Add("RoomType",120)
.Columns.Add("Status",90)

FillListView(lvList,GetData(sSql))
EndWith
EndSub

This procedure can be found in any form that has a listview control to list all records from a table. The only difference is that you can set the properties for every column in your listview. Of
course, FillList procedure is being called at the form load event. So it will load the data from a table into the listview control before the form is displayed totally.

The following is the code for FillListView procedure:

Hide Copy Code


PublicSubFillListView(ByReflvListAsListView,ByRefmyDataAsOleDbDataReader)
DimitmListItemAsListViewItem

DimstrValueAsString

DoWhilemyData.Read
itmListItem=NewListViewItem()
strValue=IIf(myData.IsDBNull(0),"",myData.GetValue(0))
itmListItem.Text=strValue

ForshtCntr=1TomyData.FieldCount()1
IfmyData.IsDBNull(shtCntr)Then
itmListItem.SubItems.Add("")
Else
itmListItem.SubItems.Add(myData.GetValue(shtCntr))
EndIf
NextshtCntr

lvList.Items.Add(itmListItem)
Loop
EndSub

Because ListView from the calling procedure is being referenced in this procedure, you do not need to call the name of a form anymore, say form1.lvList. Instead you fill the listview with:

Hide Copy Code


lvList.Items.Add(itmListItem)

Points of interest

Since I am using a listview to retrieve the data from the table especially in my masterfiles, I dont need to create the same code once again to fill the listview. All you need is to pass the name
of a listview in the first parameter and the SQL string returned by OleDbDataReader to fill the listview control.

Filling a Combobox Control


Overview

https://www.codeproject.com/Articles/34533/HotelReservationSystem 2/6
5/4/2017 HotelReservationSystemCodeProject
The Windows Forms ComboBox control is used to display data in a dropdown combo box. By default, the ComboBox control appears in two parts: the top part is a text box that allows the
user to type a list item. The second part is a list box that displays a list of items from which the user can select one. Source: Microsoft Visual Studio 2008 Documentation

ComboBox is again another control that needs not to be filled with data using a redundant code. In this code snippet, we can fill the combobox with just one procedure by passing
parameters from the calling form.

The procedure is called using this syntax:

Hide Copy Code


FillCombobox(cboCountry,"SELECT*FROMCountries","Countries","Country","CountryID")

Notice that there are 5 parameters that will be passed to the FillCombobox procedure. The first parameter which is cboCountry is the name of a combobox in your form that will be filled with
data from Countries table in the second parameter, the third is just a dummy, which is actually the name of the table to be used in the datasource in the FillCombobox procedure, the fourth
Country is the name of a field that has an actual data. The fifth parameter CountryID will be used to tag the actual data in Country field.

The FillCombobox Procedure:

Hide Copy Code


PublicSubFillCombobox(ByValcboComboAsComboBox,ByValsSQLAsString,ByValstrTableAsString,ByValstrDisplayMemberAsString,ByVal
strValueMemberAsString)
DimcnHotelAsOleDbConnection
cnHotel=NewOleDbConnection

Try
WithcnHotel
If.State=ConnectionState.OpenThen.Close()

.ConnectionString=cnString
.Open()
EndWith

DimdaAsOleDbDataAdapter=NewOleDbDataAdapter(sSQL,cnHotel)
DimdtAsNewDataSet

da.Fill(dt,strTable)

cboCombo.DataSource=dt.Tables(strTable).DefaultView
cboCombo.DisplayMember=strDisplayMember
cboCombo.ValueMember=strValueMember
CatchexAsException
MessageBox.Show(ex.Message)
Finally
cnHotel.Close()
EndTry
EndSub

As you can see in this code:

Hide Copy Code


cboCombo.DataSource=dt.Tables(strTable).DefaultView
cboCombo.DisplayMember=strDisplayMember
cboCombo.ValueMember=strValueMember

The 3 properties of cboCombo will use the parameter that is being passed from the calling procedure. The best part here is the DisplayMember and ValueMember which actually holds the
data. I remember that filling a combobox with data in version 6.0 of visual basic will certainly takes a lot of code. But now its a lot easier with vb.net.

DisplayMember is actually the dummy field for this combobox because the actual data that is saved in the database is the value from ValueMember.

Example:

Hide Copy Code


ValueMember(CountyID)DisplayMember(Country)
1UnitedStates
2India
3Canada

This means that only the value of the CountryID will be saved in the table and not the Country.

Counting the Number of Records in a Table


In visual basic 6.0, if you are going to determine the number of records in a recordset, all you have to do is add a code like rs.recordcount, where rs is the name of a variable that holds the
data.

However, in VB.NET this functionality has been removed. So, how can we figure out the number of recordset then?

The following is an example again from hotel reservation system.

Hide Copy Code


DimsqlQRYAsString="SELECT*FROM[Room_Rates]WHERERoomNumber="&RoomNumber&"ANDRateTypeID="&cboRateType.SelectedValue
DimcmdAsOleDbCommand=NewOleDbCommand(sqlQRY,cnHotel)
DimRecordCountAsInteger

RecordCount=CountRows("SELECTCount(*)FROM[Room_Rates]")

This is very important if you want to determine first if the recordset contains a data to avoid errors later in your code.
This is just a few of the useful code which can be found in Hotel Reservation System.

The following are some of the common question which I found very useful.

https://www.codeproject.com/Articles/34533/HotelReservationSystem 3/6
5/4/2017 HotelReservationSystemCodeProject
1. How to subtract a date in DatePicker
dtpDateOut.Value.AddDays1
2. How to add days in a DatePicker

dtpDateOut.Value = dtpDateIn.Value.AddDays1

To Do List

1. Add Login Form


2. Add Toolbar
3. Fix Room Inventory
4. Reports

Folio Report
Reservation Report
Account Receivable Report
Check In Guest Report
Check Out Report
Guest List Report
Other Charges Report
Room History

License
This article, along with any associated source code and files, is licensed under The GNU General Public License GPLv3

Share
EMAIL TWITTER

About the Author


Jomar Pabuaya
Software Developer Senior
United States

Jomar Pabuaya is a computer programmer and currently working as an IT Head in the government. He is also a computer instructor teaching computer programming. You can visit his
website at www.sourcecodester.com

You may also be interested in...


ASP.NET MVC Hotel Booking System Using AngularJS Watering System in Python

SharePoint Reservations 10 Ways to Boost COBOL Application Development

Visual COBOL New Release: Small point. Big deal SAPrefs Netscapelike Preferences Dialog

Comments and Discussions


You must Sign In to use this message board.

https://www.codeproject.com/Articles/34533/HotelReservationSystem 4/6
5/4/2017 HotelReservationSystemCodeProject

Search Comments Go

First Prev Next

Hotel Management System


Member 12875066 28Nov16 6:42

Excellent work
Mustafa_ub2016 29Jan16 13:40

Data base password


Member 10953278 17Jul14 5:26

Re: Data base password


rashidnk 29Aug14 21:40

Re: Data base password


Member 11491843 2Mar15 5:01

Re: Data base password


Member 11698258 17May15 20:26

sending database password


Member 10760142 19Apr14 1:19

Re: sending database password


Member 12483981 2Sep16 10:50

password?
Member 10749980 14Apr14 22:27

Re: password?
Member 11788312 26Jun15 2:51

password
Member 10746759 13Apr14 18:58

Password
Member 10517068 10Jan14 17:59

database in this system


Quratul Ain Aini 23Apr13 23:15

request password
harishleon 27Feb13 4:19

vb.net Room Reserve Query


bhaveshkawade 9Dec12 20:47

java code
divu.kana 7Jun12 19:30

Re: java code


Member 10061035 17May13 22:13

Re: java code


Member 11574129 9Aug15 2:05

[My vote of 1] www.FreeHotelSoftware.com


Pratik Vakil 24Aug10 16:35

My vote of 1
psouza4micronet 30Mar09 2:46

Re: My vote of 1
Jomar Pabuaya 30Mar09 17:38

Re: My vote of 1
P. Ganesh Kumar 26Aug09 3:16

Refresh 1

General News Suggestion Question Bug Answer Joke Praise Rant Admin

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Layout: fixed | fluid

https://www.codeproject.com/Articles/34533/HotelReservationSystem 5/6
5/4/2017 HotelReservationSystemCodeProject
Permalink | Advertise | Privacy | Terms of Use | Mobile Article Copyright 2009 by Jomar Pabuaya
Web01 | 2.8.170424.1 | Last Updated 30 Mar 2009 Everything else Copyright CodeProject, 19992017

https://www.codeproject.com/Articles/34533/HotelReservationSystem 6/6

Você também pode gostar