Você está na página 1de 42

Imports System.

Data
002 Public Class Loan
003 Dim inc As Integer
004 Dim MaxRows AsInteger
005 Dim ds As NewDataSet
006 Dim da AsOleDb.OleDbDataAdapter
007 Dim sql As String
008 ' Dim cb As New OleDb.OleDbCommandBuilder(da)
009
01 Private Subbtnload_Click(ByValsender As System.Object, ByVal e AsSystem.
0 EventArgs) Handles btnload.Click
011 Dim con As NewOleDb.OleDbConnection
012
013
con.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data
014
Source = C:\Documents and Settings\Family\Desktop\K_S.mdb"
015 con.Open()
016 sql = "SELECT * FROM tblLoan"
017 da = NewOleDb.OleDbDataAdapter(sql, con)
018 da.Fill(ds, "k_S")
019
020
021 con.Close()
022
023
024 MaxRows = ds.Tables("K_S").Rows.Count
025 inc = -1
026
027 End Sub
028 Private SubNavigateRecords()
029
030 txtisbn.Text = ds.Tables("K_S").Rows(inc).Item(1)
031 txtloancardnumber.Text = ds.Tables("K_S").Rows(inc).Item(2)
032 txtloandate.Text = ds.Tables("K_S").Rows(inc).Item(3)
033 txtreturndate.Text = ds.Tables("K_S").Rows(inc).Item(4)
034 chkonloan.Text = ds.Tables("K_S").Rows(inc).Item(5)
035 End Sub
036
037
03 Private SubbtnNext_Click(ByValsender As System.Object, ByVal e AsSystem.
8 EventArgs) Handles btnNext.Click
039 If inc <> MaxRows - 1 Then
040 inc = inc + 1
041 NavigateRecords()
042 Else
043 MsgBox("No More Rows")
044 End If
045 End Sub
046
04 Private SubbtnPrevious_Click(ByValsender As System.Object, ByVal e AsSys
7 tem.EventArgs) HandlesbtnPrevious.Click
048 If inc > 0 Then
049 inc = inc - 1
050 NavigateRecords()
051 ElseIf inc = -1 Then
052 MsgBox("No Records Yet")
053 ElseIf inc = 0 Then
054 MsgBox("First Record")
055 End If
056 End Sub
057
05 Private SubbtnFirst_Click(ByValsender As System.Object, ByVal e AsSystem
8 .EventArgs) Handles btnFirst.Click
059 If inc <> 0 Then
060 inc = 0
061 NavigateRecords()
062 End If
063 End Sub
064
06 Private SubbtnLast_Click(ByValsender As System.Object, ByVal e AsSystem.
5 EventArgs) Handles btnLast.Click
066 If inc <> MaxRows - 1 Then
067 inc = MaxRows - 1
068 NavigateRecords()
069 End If
070 End Sub
071
07 Private Subbtnadd_Click(ByValsender As System.Object, ByVal e AsSystem.E
2 ventArgs) Handles btnaddnew.Click
073 btnCommit.Enabled = True
074 btnAddNew.Enabled = False
075 btnUpdate.Enabled = False
076 btndelete.Enabled = False
077
078 txtisbn.Clear()
079 txtloancardnumber.Clear()
080 txtloandate.Clear()
081 txtreturndate.Clear()
082 End Sub
083
08 Private SubbtnClaear_Click(ByValsender As System.Object, ByVal e AsSyste
4 m.EventArgs) Handles btnClear.Click
085 btnCommit.Enabled = False
086 btnaddnew.Enabled = True
087 btnUpdate.Enabled = True
088 btndelete.Enabled = True
089
090 inc = 0
091 NavigateRecords()
092 End Sub
093
09 Private SubbtnCommit_Click(ByValsender As System.Object, ByVal e AsSyste
4 m.EventArgs) Handles btnCommit.Click
095 If inc <> -1 Then
096
097 Dim cb As NewOleDb.OleDbCommandBuilder(da)
098 Dim dsNewRow As DataRow
099
100 dsNewRow = ds.Tables("AddressBook").NewRow()
101
102 dsNewRow.Item("ISBN") = txtisbn.Text
103 dsNewRow.Item("Loan Card Number") = txtloancardnumber.Text
104 dsNewRow.Item("Loan Date") = txtloandate.Text
105 dsNewRow.Item("REturn Date") = txtreturndate.Text
106
107
108 ds.Tables("K_S").Rows.Add(dsNewRow)
109
110 da.Update(ds, "K_S")
111
112 MsgBox("New Record added to the Database")
113
114 btnCommit.Enabled = False
115 btnaddnew.Enabled = True
116 btnUpdate.Enabled = True
117 btndelete.Enabled = True
118
119 End If
120 End Sub
121
12 Private SubbtnUpdate_Click(ByValsender As System.Object, ByVal e AsSyste
2 m.EventArgs) Handles btnUpdate.Click
123 Dim cb As NewOleDb.OleDbCommandBuilder(da)
124 ds.Tables("K_S").Rows(inc).Item(1) = txtisbn.Text
125 ds.Tables("K_Sk").Rows(inc).Item(2) = txtloancardnumber.Text
126 ds.Tables("K_S").Rows(inc).Item(3) = txtloandate.Text
127 ds.Tables("K_S").Rows(inc).Item(4) = txtreturndate.Text
128 ' da.Update(ds, "AddressBook")
129 MsgBox("Data updated")
130 End Sub
131
13 Private Subbtndelete_Click(ByValsender As System.Object, ByVal e AsSyste
2 m.EventArgs) Handles btndelete.Click
IfMessageBox.Show("Do you really want to Delete this
133
Record?", "Delete", MessageBoxButtons.YesNo, _
134 MessageBoxIcon.Warning) = DialogResult.No Then
135
136
137 MsgBox("Operation Cancelled")
138 Exit Sub
139
140 End If
141 Dim cb As NewOleDb.OleDbCommandBuilder(da)
142
143 ds.Tables("K_S").Rows(inc).Delete()
144 MaxRows = MaxRows - 1
145
146 inc = 0
147 NavigateRecords()
148 da.Update(ds, "K_S")
149 End Sub
150 End Class
Library Management System using VB 6 with MS Access
Database
posted by Girish Sundaram on December 25, 2016
In this post, we want to develop a Library Management System in Visual Basic 6.

Click here to learn developing other visual basic applications.


1. Manage member information

2. Each member must log in using password provided to them.

The Library Management System will have following modules.

1. frmLibraryManagement

2. frmLogin

3. frmBookdetails

4. frmMemberdetails

5. frmMenu

6. Module1.bas

System Design
LIBRARY MANAGEMENT SYSTEM

Data Model [ E-R Diagram ]


E-R DIAGRAM FOR LIBRARY DATABASE

Relational Model [ Tables ]

Now we need to convert the E-R Model to a Relational Model which means create table

for each entity in the E-R model.

BOOK TABLE

The book table in Access Design View is given below. One of the Field Name is "Primary

Key", in this case, Member ID.

BOOK TABLE

LOGIN TABLE

The login table in MS Access Design View is given below. The Field Name "User ID" is

the "Primary Key" for this table.

LOGIN TABLE

MEMBER TABLE
The third table in MS Access Design View is given below. The Field Name "Member ID"

is the "Primary Key" for the table.

Note: Primary Key is a field that uniquely


identifies each row in the table.

MEMBER TABLE

RELATIONSHIP

A Relationship in MS Access is similar to the E-R Diagram we created previously. We

can use E-R Diagram to create a relationships between table.

To view or create relationships among tables, go to Database Tool from the Toolbar

> [Click] Relationships under Show/Hide.

RELATIONSHIPS BETWEEN TABLE


The relationship between MEMBER and BOOK is called One-to-Many and the

relationship between MEMBER and LOGIN is One-to-One.

Components for frmLibraryManagement

You can design the interface for each of the forms in Visual Basic now. However, you

must rename them properly for sake of coding.

Let's create components for frmLibraryMangement as follows and rename them.

FORM LIBRARY MANAGEMENT

Labels

Name : lblLibraryManagement

Caption : LIBRARY MANAGEMENT SYSTEM


Buttons

Name : cmdLogin

Caption : LOGIN

Code for frmLibraryManagement

Private Sub cmdLogin_Click()


frmLogin.Show
Unload Me

End Sub

Components for frmLogin

The log in screen is different because you want password to be hidden when you type

them. To create Log in dialog.

[Right-Click] Project1.vbp > Select Add > [Click] Form. The new form dialog

box will appear, select Log in Dialog.


LOG IN DIALOG
Now we must rename and change the code for frmLogin.

FORM LOG IN

Labels

Name : lblUserID

Caption: User Name:


Name : lblPassword

Caption: Password

Text-Boxes

Name : txtUserID

Text : 'leave blank'

Name : txtPassword

Text : 'leave blank'

Buttons

Name : cmdOK

Caption: Login

Name : cmdCancel

Caption: Cancel

Code for frmLogin

Option Explicit

Public LoginSucceeded As Boolean

Private Sub cmdCancel_Click()


'set the global var to false
'to denote a failed login
LoginSucceeded = False
Me.Hide
End Sub

Private Sub cmdOK_Click()

rs.Open "SELECT * FROM LOGIN ", con, adOpenDynamic,


adLockReadOnly

While Not rs.EOF

If rs!UserID = Val(txtUserID) Then

'check for correct password


If rs!Password = txtPassword Then
'place code to here to pass the
'success to the calling sub
'setting a global var is the easiest
LoginSucceeded = True
frmMENU.Show
Me.Hide
con.Close

Exit Sub

Else
MsgBox "Invalid Password, try again!", , "Login"
txtPassword.SetFocus
SendKeys "{Home}+{End}"

End If

End If
rs.MoveNext

Wend
End Sub

Private Sub Form_Load()

Call loadcon
MsgBox ("Connected")

End Sub

Components for frmMenu [ MDI form]

The frmMenu is a form with menu items and we can create a menu using Menu Editor.

To create a MDI form, [Right-Click] Project1.vbp > Select Add > [Click] MDI

Form.

Create following menu items using Menu Editor.

MDI FORM WITH MENU EDITOR

Code for frmMenu


When you click on any menu item it will open another form with in the parent MDI

form. The other form that must open within MDI form should have their MDI child

property set to True.

SET MDI CHILD PROPERTY TO TRUE

Components for frmBookDetails

The frmBookDetails store the book information and you can perform various operations

on the book database such as INSERT, DELETE and UPDATE, etc.


FORM FOR BOOK DETAILS

Labels

Name : lblBookDetails

Caption : BOOK DETAILS

Name : lblBookID

Caption : BOOK ID

Name : lblBookname

Caption : BOOK NAME


Name : lblAuthor

Caption : AUTHOR

Name : lblMID

Caption : MEMBER ID

Text-Boxes

Name : txtBookID

Text : 'leave blank'

Name : txtBookname

Text ; 'leave blank'

Name : txtAuthor

Text : 'leave blank'

Name : txtMID

Text : 'leave blank'

Buttons

Name : cmdAdd

Caption : &ADD
Name : cmdDel

Caption : &DELETE

Name : cmdUpdate

Caption : &UPDATE

Name : cmdDisplay

Caption : &DISPLAY

Name : cmdClear

Caption : &CLEAR

Name : cmdExit

Caption : &EXIT

Data Grids

Name : DataGrid1

Code for frmBookDetails

Private Sub cmdAdd_Click()


con.Execute "INSERT INTO BOOK (BookID, BookName, Author,
MemberID) VALUES (" & txtBookID & ", '" & txtBookN & "','" &
txtAuthor & "', " & txtMID & ")"
MsgBox ("Record Inserted !!")
End Sub

Private Sub cmdClr_Click()


txtBookID.Text = " "
txtBooktitle.Text = " "
txtAuthor.Text = " "
End Sub

Private Sub cmdDel_Click()

con.Execute "DELETE * FROM BOOK WHERE BookID = " & txtBookID & ""
MsgBox ("Record Deleted !!")

End Sub

Private Sub cmdDisplay_Click()


rs.CursorLocation = adUseClient
rs.CursorType = adOpenStatic
rs.Open "SELECT * FROM BOOK", con, adOpenDynamic,
adLockPessimistic

Set DataGrid1.DataSource = rs

End Sub

Private Sub cmdExit_Click()


Unload Me
con.Close

End Sub

Private Sub cmdUpdate_Click()


con.Execute "UPDATE BOOK SET BookName = '" & txtBookname & "',
Author = '" & txtAuthor & "', MemberID = '" & txtMID & "' WHERE
BOOKID = " & txtBID & ""
MsgBox ("Record Updated")

End Sub

Private Sub Form_Load()


Call loadcon
MsgBox ("Connected")
End Sub

Private Sub lblBookDetails_Click()

End Sub

Components for frmMember

FORM LIBRARY MEMBER DETAILS

Labels

Name : lblMemberDetai

Caption : MEMBER DETAILS

Name : lblMID
Caption : MEMBER ID

Name : lblMembername

Caption : MEMBER NAME

Text-Boxes

Name : txtMemberID

Text : 'leave blank'

Name : txtMembername

Text ; 'leave blank'

Buttons

Name : cmdAdd

Caption : &ADD

Name : cmdDel

Caption : &DELETE

Name : cmdUpdate

Caption : &UPDATE

Name : cmdDisplay
Caption : &DISPLAY

Name : cmdClear

Caption : &CLEAR

Name : cmdExit

Caption : &EXIT

Data Grids

Name : DataGrid1

Code for frmMemberDetails

Private Sub cmdAdd_Click()


con.Execute "INSERT INTO MEMBER (MemberID, MemberName) VALUES ("
& Text1 & ", '" & Text2 & "')"
MsgBox ("Record Inserted")

End Sub

Private Sub cmdClr_Click()


Text1.Text = ""
Text2.Text = ""
End Sub

Private Sub cmdDel_Click()


con.Execute "DELETE * FROM MEMBER WHERE MemberID = " & Text1 & ""
MsgBox ("Record Deleted")

End Sub
Private Sub cmdDisplay_Click()

rs.CursorLocation = adUseClient
rs.CursorType = adOpenStatic

rs.Open "SELECT * FROM MEMBER", con, adOpenDynamic,


adLockPessimistic
Set DataGrid1.DataSource = rs

End Sub

Private Sub cmdExit_Click()


Unload Me
con.Close

End Sub

Private Sub cmdUbdate_Click()


con.Execute "UPDATE MEMBER SET MemberID = " & Text1 & ",
MemberName = '" & Text2 & "'"
MsgBox ("Record Updated")
End Sub

Private Sub Form_Load()


Call loadcon
MsgBox ("Connected")
End Sub

Module1.bas

All form need to connect to Microsoft Access Database but you may have to write the

code for connection in each form. It there is a large number of forms in the project, say

10, then these extra line of codes become redundant.


To save us from this trouble, create Module1.bas file

from Project1.vbp windows.The code for Module is given below.

Public con As New ADODB.Connection


Public rs As New ADODB.Recordset
Public constr As String

Public Sub loadcon()


constr = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=C:\Users\Girish\Documents\LIBRARY.mdb;Persist Security
Info=False"

con.Open constr

End Sub

Note: You cannot add the code for Module 1 because first you have to add the

components for Microsoft ADO Data Control 6.0 (OLEDB) and Microsoft Data

grid Control 6.0 (OLEDB).


Library Management System Using Access

For my project in IT419 Database Management System, I created the Library Management System
software. The software is implemented using Microsoft Access 2007 with Visual Basic for Application for
its User Interface and automation. This software can be used in a small school library. With a slight
modification, it can also be used in a book borrowing store. In my project, Ive chosen the University
Library of UP Diliman to be my fictitious software client mainly because of its nice logo which fits nicely on
my user interface design.

A. THE MAIN FORM

The first form that will display when using this program is the Main Form. From here, the user can select 7
menus:

Login - allows the user to access the program


Search - allows user to search for library items
Check-in - allows user to return borrowed Library items
Check-out - allows user to borrow Library items
Patron - allows user to view his/her personal records
Administration - allows user (the librarian) to add, edit, and delete Library items and user

accounts
Reports allows user (the librarian) to view the different Library reports.
B. THE LOGIN SYSTEM

Using the login menu, the user can access features of the software by providing username and password.
The user can access the software as either a Librarian or as a Patron.

Librarian - unlimited access to all features of the program


Patron can access only the Search and Patron menu
PROGRAM MODES

The program operates in 3 modes:

ANONYMOUS MODE This mode is activated during startup when users are not yet logged in.
PATRON MODE This mode is activated when a Library patron is logged in.
LIBRARIAN MODE This mode is activated when a Librarian is logged in.
C. SEARCH SYSTEM

In this menu, the user can search for a particular library item based on selected search criteria and search
text:

The search results will display every item that matched the search text. It also allows you to view the
specific details of the library item by clicking on the corresponding details button.
When the Details button is clicked, the Library Item Details Form will show, displaying the particular items
details.

D. BOOK BORROWING SYSTEM

CHECK-IN FORM

This form is accessible only by a Librarian account and is used when patrons return the borrowed books.
The returned items ID and copy number can be selected and any fines incurred will be automatically
calculated by the software.
CHECK-OUT FORM

This form is accessible only by a Librarian account and is used when patrons borrow books. In order for
the Library Item to be borrowed, the borrowers name and borrowed items ID and index number are
specified. The Due date is automatically calculated by the software based on the Circulation Type of the
borrowed item.
E. ADMINISTRATION SYSTEM

LIBRARY USER MANAGEMENT FORM

This form is accessible only by a Librarian account. In this form, the librarian can add, edit, and delete
librarian accounts and librarian groups. The librarian can also add, edit and delete patron accounts and
patron groups.
ITEM MANAGEMENT FORM

This form is accessible only by a Librarian account. In this form, the librarian can add, edit, and delete
item author, publisher, series, status, subject, media, location and library items.
ACQUISTION FORM

This form is accessible only by a Librarian account. The form is used when a new item is acquired.
Acquisition details of the item is inputted, such as the items cost, acquisition date, supplier, PO number
and the name of the person who received the item.
CIRCULATION FORM

This form is accessible only by a Librarian account. The form is used to view the circulation records which
allow the Librarian to modify or create new circulation records without the need to use the Check-in and
Check-out Forms.

CIRCULATION TYPE FORM

This form is accessible only by a Librarian account. The librarian can add, edit or remove Circulation
Types. The records specified here are used by the program when auto-calculating fines when returning
items late.
F. REPORTING SYSTEM

THE REPORTS MENU

The reports menu is accessible only by the librarian and is used to view the different program reports.
DAILY FINES SUMMARY REPORT displays the summary of fines received for the last 30 days.

LIST OF BORROWED ITEMS REPORT displays the list of borrowed/unreturned library items.
TOP TEN MOST BORROWED ITEMS REPORT displays the top ten most borrowed library items.

LIST OF LIBRARY ITEMS BY LOCATION displays the list of library items grouped by location.
LIST OF PATRONS BY GROUP displays the list of patrons by group.

LIST OF LIBRARIANS BY GROUP displays the list of librarians by group.


THE PATRON MENU

The patron menu is accessible only by the patrons and is used to view the Patron Record and Circulation
History.

THE PATRON RECORD FORM Used to display the currently logged on patrons record details.
THE CIRCULATION HISTORY FORM Used to display the currently logged on patrons circulation
history.

Você também pode gostar