Sunteți pe pagina 1din 217

Library Management System

OOAD Project On
“Library Management System ”

Submitted by:
Singh Kuldeep Omprakash
T.Y.B.Sc (COMPUTER SCIENCE)

Project Guide:
Prof. Ms. Danila Pahuja

SMT. CHANDIBAI HIMATHMAL MANSUKHANI


COLLEGE, Ulhasnagar-421003

AFFILLIATED TO:
UNIVERSITY OF MUMBAI
2016-2017

Project by: Kuldeep Singh | 1053 Page 1


Library Management System

Library
Management
System
Project by,

- Kuldeep Singh

Project by: Kuldeep Singh | 1053 Page 2


Library Management System
Sr. No Topic Page
No.
A. System Documentation
1. College Certificate --
2. Acknowledgement 5
3. Organizational Overview 6
4. Description of Present System 7
5. Limitations of Present System 8
6. Proposed System and Its Advantages 9
7. Gantt Chart 11
8. Event List 12
9. Event Table 13
10. Entity Relationship Diagram(ER Diagram) 16
11. Use Case Diagram 23
12. Activity Data Matrix (CRUD Table) 28
13. Activity Diagram 29
14. Class Diagram 32
15. Object Diagram 34
16. Sequence/Collaboration Diagram 36
17. State Diagram 38
18. Component Diagram 41
19. Structured Diagram 42
20. Deployment Diagram 43
21. Package Diagram 45
22. Menu Tree 47
23. System Coding and Conventions 49
24. System Control and Standards 49
25. Form Listing 50
26. Report Listing 51
27. Database and List of tables with Description 52

B. Project Documentation
1. Program Source Code 56
2. Data Entry Screens 201

C. Validations
1. Test Case 207
2. Test Data 210
3. Test Results 212

D. Report Layouts 213


E. References And Bibliography 216

Project by: Kuldeep Singh | 1053 Page 3


Library Management System

System
Documentation

Project by: Kuldeep Singh | 1053 Page 4


Library Management System

ACKNOWLEDGEMENT
It gives me great pleasure in presenting this project report. Its
justification will never sound good if I do not express my vote of thanks
to our C.H.M. College and respective Principal. I would also like to
thank our coordinator Mrs.RitikaSachdev for her timely support in this
completion of this project.

I thank our internal project guide Mrs. Danila Pahuja, who has
done a lot to keep this project systematically and on schedule. I am
thankful for their valuable guidance to every stage of the project. Finally,
I would thank to all others, who give there extended support to complete
this project.

Project by: Kuldeep Singh | 1053 Page 5


Library Management System

SYNOPSIS

Organizational Overview:

The Library Management System is an application for assisting a


librarian in managing a book library in a college. The system would
provide basic set of features to add/update users, add/update books, and
manage book issue and book return function.

 Objectives
The project aims and objectives that will be achieved after
completion of this project are discussed in this subchapter. The aims
and objectives are as follows:

 Develop a system that can replace the manual library managing


system.
 Develop a database which stores user details & book details.
 A search column to search availability of books
 Create an easy to understand user friendly environment.
 Attractive user interfaces to navigate through the system for the
users.
 To design a system that will lessen the time and effort of the
student intheir transaction
 To print out reports immediately

Project by: Kuldeep Singh | 1053 Page 6


Library Management System

Description of Present System

It is manual system where librarian have to process


everything manually from organizing the books and place them in
the right place write shelf to retrieve them for the library visitors
and that is overwhelming consuming process.

In Manual system librarian has to store every details of


books in an register. So it is very difficult to locate

Project by: Kuldeep Singh | 1053 Page 7


Library Management System

Limitations of Present System

In our existing system all the transaction of book are done manually,
so taking more time for transaction like borrowing a book or returning a
book and also for searching a book.
Another major disadvantage is that preparing a list of borrowed and
available books in the library will take more time, currently it is doing as
one day process for verifying all records so after conducting the
feasibility study we decides to make manual library computerized

Some of the problem being face in manual library system is as follows


1. Fast report generation is not possible
2. Tracing a book is difficult
3. Information about book issue/return is not properly maintain
4. No central database can be created as information is not
available in database

Project by: Kuldeep Singh | 1053 Page 8


Library Management System

Proposed System and its advantages

Library management system provides a simple GUI (Graphical


User Interface) for the Library staff to manage the functions of the library
effectively. The Library Management system is designed and developed
for the receipt and Issuance of books in the library.
In a non computerized Library management system, when a book
isissued or returned, it is noted down in a register after which data entryis
done to update the status of the books. This process takes some time and
proper update of this information cannot be guaranteed. Anomalies in the
update process can cause loss of books.
so a more user friendlyinterface which could update the database
instantly has a greatd emand in libraries, hence the need for this project.

 The proposed system has two types of access:


 The Administrator.
 The User.

Project by: Kuldeep Singh | 1053 Page 9


Library Management System

 Advantages
 GUI: It does provide better GUI.
 Search: details become comparatively easy.
 Increase Work Speed: Due to Automation of some part of System
work speed will increase and it is time saving.
 Time Saving: It takes less time to store new Information and
Retrieve require information from database System. In this system
all details of Information placed separately. It reduce the lot of
paper work and maintains all details computerized.
 Facility: It is very easy to access and retain the information about
books,students etc.
 Flexibility: The database is flexible and can be easily modified
when some changes in the system require.
 Security: The system informs the administrator every login and
logout any authorized person is given access it keeps all records
safely or save from any accident like burning and water damage.
 Accuracy: Computerized system will be accurate enough to
provide minimum errors to perform any number of calculation and
also this provide to remove the problem which may present in the
system.
 User-Friendly: The system s user friendly software will create a
flexible and can for table environment and it leads to make
everything more and beneficial.
 Reduce-Error: Due to computerized there is less possibility of
error.
 Loss Of Data: Tampering or loss of data is avoided.
 Economical: Due to minimal error and work delay proposed
system can be economically helpful.
 User-friendly: The system should be user-friendly .The software
will create a flexible and can for table environment and it leads to
make everything more whole some and beneficial.

Project by: Kuldeep Singh | 1053 Page 10


Library Management System

Project by: Kuldeep Singh | 1053 Page 11


Library Management System

Event List
 An occurrence at specific time of place that can be described and is worth
remembering is known as event.
 It is used in system analysis and designing.

 Types Of Event
There are three types of events to consider when using decomposition technique to
identify some event.

 External:
 Outside the system.
 Initiated by external agent or Actor.
 Temporal:
 Occurs as a result of reaching point in name.
 Based on system deadlines.
 State:
 Something inside the system triggers the
processing end.

Project by: Kuldeep Singh | 1053 Page 12


Library Management System

Event List
1. Admin logs into System
2. Admin adds details of books
3. Admin update details of books
4. Admin deletes details of books
5. Users search for books.
6. Users checks book details
7. Users adds student details
8. Users update student details
9. Users delete student details
10. Student issues the book
11. Student returns the book
12. Users checks if books are returned in the given return date
13. Users take fine if book return date is expire
14. Admin places the orders for book stock
15. Supplier supplies the book stock
16. Admin generates reports

Project by: Kuldeep Singh | 1053 Page 13


Library Management System

 Event List Table:

Sr. No. Event Type


1 Admin logs into System External
2 Admin add /update/delete Staff External
3 Admin add /update/delete Supplier External
4 Holds the details of Library Management system External
5 Users creating / Log In External
6 Users add /update /delete Student External
7 User search for book External
8 User select and issue the book External
9 User returns the book External
10 User collects the fine External
10 Users updates book status External
11 Collect the book return details External
12 Holds the detail of Book returns External
13 Admin places the order for books Temporal
14 Supplier delivers books Temporal
15 Admin review reports Temporal
16 Admin generate report External

Project by: Kuldeep Singh | 1053 Page 14


Library Management System

Event Table
A table that lists events in tabular format that is in rows and key pieces of
information about each event in columns.

 Designing Of Event Table:-


1) While developing the list of events the analyst should note additional
information about each event for later use.
2) This information is entered in an event table.
3) An event table compares of rows and columns.
4) Each row in the event table records information about one event.
5) And row in the event table records information about one event.

 Event table should consist of the following:-


Event: Occurrence happening at a determinable time & place with/without
human agents.

Trigger: An occurrence that tells the system about the event.


 Source: An external agent or actor that supplies information.
Activity: Behavior that the system provides.
Response: An output produced by the system that gives information.
Destination: An external agent or actor that receives data from the system.

Project by: Kuldeep Singh | 1053 Page 15


Library Management System

Sr. Event Trigger Source Activity Response Destin


No. ation
1 Admin creating New Admin Admin New Admin New Entry Admin
login entry Logged In

2 Admin add Delete, add Admin Changes in New staff add Staff
/update/delete & modify staffs details delete update
Staff the staff by admin
details
3 Admin add Delete, add Admin Changes in New student Student
/update/delete & modify students add delete
Student the student details update by
details admin
4 Admin add Delete, add, Admin Changing in New customer Supplier
/Update /delete & modify supplier add delete
supplier the supplier details update by
details admin
5 User creating New User User New user New Entry User
login entry Logged In

6 User search for Search User Searching for Book searched User
books books the book

7 User select and Select and User Issuing the Book Issued Student
issue book issue book book

8 User return Return the Student Returning the Book User


book book book Returned

9 User collects Collect the Student Collecting the Fine Collected User
the fine fine fine

10 User updates Update book User Updating Book status User


book status status book status updated

11 Admin places Order the Admin Ordering the Books ordered Supplie
the order for book books r
books

Project by: Kuldeep Singh | 1053 Page 16


Library Management System

12 Supplier deliver Supply the Supplier Delivering Books Admin


the books book the book Delivered

13 Holds the User holds User Holding the Details User


details of books the details of details of recorded
books books

14 Admin logs in Login Admin Login Login System


successful

15 Admin Review Review Admin Reviewing Reports System


Reports Reports Reports Reviewed

16 Admin generate Generate Admin ----- ------ Admin


report report

Project by: Kuldeep Singh | 1053 Page 17


Library Management System

Entity Relationship Diagram:

 ER Diagrams are simple and clear.


 Entity relationship diagram can express overall logical
structure of database logically
 ER Diagrams represents entities and tables and their
relationship with one another.

Project by: Kuldeep Singh | 1053 Page 18


Library Management System

1. LogIn

2. Student_Details

3. Supplier_Details

Project by: Kuldeep Singh | 1053 Page 19


Library Management System

4. Book_Details

5. User_Details

Project by: Kuldeep Singh | 1053 Page 20


Library Management System

7. Staff_Details

8. Order_Details

Project by: Kuldeep Singh | 1053 Page 21


Library Management System

 Entity relationship diagram

Project by: Kuldeep Singh | 1053 Page 22


Library Management System

Use Case Diagram

A use case diagram is a set of scenarios that describing an interaction between


user and system. A use case diagram displays the relationship among actors & use
cases.

The 2 main components of use case diagram are use case and actor.
Diagrams:-

Actor Use case

Actor:-
An actor represents a user or another system will interact with the system that you are
modeling.

Use Case:-
A use case is an external view of the system that represents some action that might
perform in order to complete a task.

System Boundary:-
A System boundary defines a scope of what system will be. A system cannot have
infinite functionality a system boundary defines the limitation of system.

Project by: Kuldeep Singh | 1053 Page 23


Library Management System

Use case Diagram:


 Book:

 Admin

Project by: Kuldeep Singh | 1053 Page 24


Library Management System

 User

 Book

 Reports

Project by: Kuldeep Singh | 1053 Page 25


Library Management System

USE CASE DESCRIPTION


The above figure shows the UML(Unified Modeline Language) symbols for actor
(The stick figure) and (The ellipse) description

 Admin Subsystem:-
a) Admin creates the new account and logins into the account.
b) Admin can add staff details.
c) Admin can update staff details.
d) Admin can delete staff details.
e) Admin can check staff details.
f) Admin can display staff details.
g) Admin can generate reports.

 Student Subsystem:-
a) When a new student turns up for inquiry or for issuing book, admin adds
his/her details, if required.
b) If an existing student has made changes in personal details then admin
update his/her record.
c) If a student ‘s record not required and has not places any order, then admin
deletes his/her records.
d) If admin want to check for the detail of a student, he can do so by selecting
the id or Name of the student.

 Supplier Subsystem:-
a) When admin order book from a new supplier, then admin add his/her
details.
b) If an existing supplier has made changes in contact detail, then admin
updates in existing control.
c) If supplier no longer exists nor admin has purchased any product from
him, admin deletes his record.
d) If admin wants to check for the details of a supplier he can do so by
selecting the ID or name of the supplier.

 Issue Subsystem:-
a) When student comes for issuing book, his/her record is searched.
b) If a new student comes then the new record is created.
c) Admin selects the appropriate book name and book details then select
book id from the available book id.
d) Issue date is generated and book is given to customer.
e) Book status and details are stored in database.

Project by: Kuldeep Singh | 1053 Page 26


Library Management System

 Return Subsystem:-
a) When student comes for returning book, his/her record is searched.
b) If student is returning book on given return date, then book is returned.
c) If student is not returning book on given return date, then fine is collected
then book is returned.
d) Book status and details are stored in database

Project by: Kuldeep Singh | 1053 Page 27


Library Management System

Activity Data Matrix (CRUD Table)

 CRUD Table (Activity Data Matrix)


A table that describes data entities the location from which they are
accessed and the nature of access is called as CRUD.
C: Create new Data.
R: Read existing Data.
U: Update existing Data.
D: Delete Existing File.

Sr No Activity Entities
1 2 3 4 5 6 7
1 Admin account is C
created
2 Admin logs into R
system
3 Admin adds book C
details
4 Admin adds supplier C
details
5 User account is C
created
6 User logs into system R
7 User adds student C
details
8 User searches books R
9 User select books R
10 User issues books U
11 User update book U
details
12 User collects books RU
13 User collects fine R
14 Student pays fine R

Entities:
1) Account
2) Book
3) Services
4) Transaction

Project by: Kuldeep Singh | 1053 Page 28


Library Management System

Activity Diagram

a) Activity diagram describes the workflow behavior of the system.


b) Activity diagram are similar to state diagram because activities are the state of
doing something.
c) The diagram describes the state of activities by showing the sequence of
activities performed.
d) Activity diagram can resolve activities that are conditional or parallel.
e) Activity diagram should be used in conjunction with other modeling
techniques such as interaction diagram & state diagram.
f) Main reason to use the activity diagram is to model workflow behind the
system being designed.

Components of Activity Diagram:-

Represents the activity.


1

Merge
2

3 Fork and Join


4  Initial Activity

Project by: Kuldeep Singh | 1053 Page 29


Library Management System

 Activity diagram for book issue

Project by: Kuldeep Singh | 1053 Page 30


Library Management System

 Activity diagram for book return

Project by: Kuldeep Singh | 1053 Page 31


Library Management System

Class Diagram

Class diagrams are widely used to describe the types of objects used in
system and their relationship. Class diagrams models class structure and contents
using design elements such as classes & packages and objects.

Class diagram describes 3 different perspectives when designing a system. These


perspectives become evident as the diagram is created & help solidify the design.
Classes are composed of 3 things:
Class name
Attributes and
Operations.

Project by: Kuldeep Singh | 1053 Page 32


Library Management System

For Example Diagram:-

Project by: Kuldeep Singh | 1053 Page 33


Library Management System

Object Diagram

Object diagram are same as that of class diagram. Instead they contain the values in
place of data types.

The object diagram describes 3 different perspectives when designing a system. This
perspective becomes evident as the system is created & helps solidify the design.

They are composed of 2 things:


Class name
Attributes and

Project by: Kuldeep Singh | 1053 Page 34


Library Management System

Project by: Kuldeep Singh | 1053 Page 35


Library Management System

Sequence/Collaboration Diagram
Sequence diagram demonstrates the behavior of the objects in a use- case
by describing the objects and the messages they pass. The diagrams are read left to
right & descending.

Components of Sequence Diagram:-

Represents objects
activation.

Represents the objects of


2 case study.

--------- Represents life of objects.


3

Represents end of objects.


4

Project by: Kuldeep Singh | 1053 Page 36


Library Management System

Project by: Kuldeep Singh | 1053 Page 37


Library Management System

State Diagram

a) State diagram are used to describe the behavior of the system.

b) State diagram describe all of the possible state of an object as an event


occurs.

c) Each diagram usually represents objects of single class and track the
different state of its object through the system.

d) We use the state diagram to demonstrate the behavior of an object


through many use cases of the system.

e) We use the state diagram for classes where it is necessary to


understand the behavior of the object through the entire system.

Diagram:-

State Diagram

Activity

Transitions

Project by: Kuldeep Singh | 1053 Page 38


Library Management System

Admin

Project by: Kuldeep Singh | 1053 Page 39


Library Management System

Student

Project by: Kuldeep Singh | 1053 Page 40


Library Management System

Component Diagram

a) The component diagram contains component & dependencies.

b) Component represents the physical packaging of the module of the code.

c) The dependencies between the components show how changes made to one
component may affect each other components in the system.

d) Dependencies in a component system are represented by dashed lines between


2 or more components.

e) Component diagram can also show the interface used by the component to
communicate with each other.

Diagram:-

Project by: Kuldeep Singh | 1053 Page 41


Library Management System

Project by: Kuldeep Singh | 1053 Page 42


Library Management System

Deployment Diagram

a) The deployment diagram contains nodes & connections.

b) A node usually represents a piece of hardware in the system.

c) A connection depicts the communication path used by the hardware to


communicate & usually indicates a method such as TCP/IP.

Diagram:-

Project by: Kuldeep Singh | 1053 Page 43


Library Management System

Project by: Kuldeep Singh | 1053 Page 44


Library Management System

Package Diagram

In addition to standard UML dependency relationship there are two special types
dependcies defined between packages:
 Package Import
 Package Merge
A package imports a relationship between an import namespace and a package
indicating that importing namespace adds the names of members an unlabeled
dependency between two packages an interpreted as a package import
relationship. In this relationship elements within the target package will be
imported in source package.

A package merge is a directed relationship between two packages that


indicates that the contents of two packages that are to be combined. It is very
similar to generalization.

 Elements of package Diagram:-

1) Package: It is a general purpose mechanism for organizing model contains


elements is designed diagrams into groups. It provides an encapsulated
namespace within which all names must be unique.

2) Class: It is representation of objects that reflects their structure and


behavior of system.

3) Interface:It is specification of behavior. By implementing interface classes


are required to support the behavior

4) Object: It is instance of class. It often used in analysis to represent


numerous artifacts and item that exist.

5) Table: It is stereotyped class.

Project by: Kuldeep Singh | 1053 Page 45


Library Management System

Project by: Kuldeep Singh | 1053 Page 46


Library Management System

Menu Tree

 Login:
 Forgot Password
 Create new account
 Change password
 Main:
 Add and Manage
 Supplier
 Staff
 Book
 Others

 Activities:
 Book issue and return
 Generate fine if applicable
 Pays fine
 Administrative:
 Book issue/return report
 Supplier report
 Book Report
 Search:
 Supplier
 Book Details

 Student:
 Register
 Issue
 Return

Project by: Kuldeep Singh | 1053 Page 47


Library Management System

Project by: Kuldeep Singh | 1053 Page 48


Library Management System

System Coding & Conventions


Label: lbl
Textbox: txt
ImageButton: img
Radio Button: rdb
Hyperlink :hyp
CrystalReportViewer
Form: frm
Command Button: cmd
Menu: mnu
DropDownList: ddl

System Coding & Standards


Function :
1. Public Shared Function GetUniqueKey(ByVal maxSize As Integer) As String

Project by: Kuldeep Singh | 1053 Page 49


Library Management System

Form Listing:

 About :-This Form show about the shop and developer name & warnig.

 Staff:-This form is used to add the details of Staff

 Student:- This Form is used to add the details of Student.

 Change Password:- This Form is used to change the password.

 Book issue:- This Form is used to add the book issue details.

 Book return:- This Form is used to add the book return details.

 LogIn:- This Form is used for login into the system.

 Registration: -This Form is used for new User

 Suppliers: This Form is used for new supplier

 Staff:- This Form is used for new staff

 Book:-This form is used for new book

 Newspaper:- This form is used for new newspaper

 Magazines:- This form is used for new magazines

Project by: Kuldeep Singh | 1053 Page 50


Library Management System

Report Listing

 BookIssueStaff_Report: This form is used to display the book issue report of


staff.
 BookIssueStudent_Report: This form is used to display the book issue report
of student.
 BookReturnStaff_Report: This form is used to display the book return report
of staff.
 BookReturnStudent_Report: This form is used to display the book return
report of student.
 Book_Report: This form is used to display the books report.
 Student_Report: This form is used to display the student report.
 Staff_Report: This form is used to display the staff report.

Project by: Kuldeep Singh | 1053 Page 51


Library Management System

Database and List of Tables With description

Name Of Database: LibraryDatasbase

1. Book

Fields Datatypes Constraints


AccessionNo varchar(50) Primary Key
BookTitle Varchar(50) Not null
Author Varchar(50) Not null
JointAuthors Varchar(50) -
Subject Varchar(20) Not null
Department Varchar(50) -
Barcode Varchar(50) -
ISBN Varchar(50) -
Volume Varchar(50) -
Edition Varchar(20) Not null
Publisher Varchar(50) Not null
PlaceOfPublisher varchar(50) -
CD varchar(50) -
NoOfBooks varchar(50) Not null
AlmiraPosition varchar(50) -
Price varchar(50) Not null
BillDate varchar(50) -
Remarks varchar(50) -
SupplierName varchar(50) -

2. Staff

Fields Datatypes Constraints


staffname varchar(50) Not null
staffid varchar(50) Primary Key
Dateofjoining Date Not null
Phoneno numeric -
fatherName varchar(50) -
Email varchar(50) Not null
address varchar(50) Not null
Department varchar(50) -
DOB Date Not null
MobileNo numeric Not null
Gender varchar(50) Not null
Photo image -

3. Registration

Project by: Kuldeep Singh | 1053 Page 52


Library Management System

Fields Datatypes Constraints


UserName varchar(50) Primary Key
UserType varchar(50) Not null
Password varchar(50) Not null
Name varchar(50) Not null
Email varchar(50) Not null
phone Numeric Not null
RegisteredDate datetime Not null

4. Supplier

Fields Datatypes Constraints


SupplierName varchar(50) Primary Key
S_books varchar(50) -
S_newspaper varchar(50) -
S_magazines varchar(50) -
Email varchar(50) Not null
Phone Numeric Not null
Address varchar(50) Not null

5. Student

Fields Datatypes Constraints


Studentname varchar(50) Not null
studentid varchar(50) Primary Key
course varchar(50) Not null
Phoneno numeric -
fatherName varchar(50) -
Email varchar(50) Not null
address varchar(50) Not null
Department varchar(50) -
DOB Date Not null
MobileNo numeric Not null
Gender varchar(50) Not null
Photo image -
stu_Session Varchar(50) Not null
ClassRollNo numeric -
CautionMoneyReceiptNo varchar(50) -

6. Newspaper

Fields Datatypes Constraints


ID varchar(50) Primary Key
PaperName varchar(50) Not Null
N_Date date Not Null
Status varchar(50) Not Null
Remarks varchar(50) Not Null

7. BookIssueStaff
Project by: Kuldeep Singh | 1053 Page 53
Library Management System

Fields Datatypes Constraints


TransactionID varchar(50) Primary Key
IssueDate date Not Null
DueDate date Not Null
AccessionNo numeric Not Null
StaffID varchar(50) Not Null
Status varchar(50) Not Null

8. BookIssueStaff

Fields Datatypes Constraints


TransactionID varchar(50) Primary Key
IssueDate date Not Null
DueDate date Not Null
AccessionNo numeric Not Null
StudentID varchar(50) Not Null
Status varchar(50) Not Null

9. Course
Fields Datatypes Constraints
CourseName varchar(50) Primary Key

10. Course
Fields Datatypes Constraints
DepartmentName varchar(50) Primary Key

11. Return_staff
Fields Datatypes Constraints
TransactionID varchar(50) Primary Key
ReturnID varchar(50) Not Null
ReturnDate date Not Null
Fine numeric Not Null

12. Return_staff
Fields Datatypes Constraints
TransactionID varchar(50) Primary Key
ReturnID varchar(50) Not Null
ReturnDate date Not Null
Fine numeric Not Null

13. JournalAndMagazines
Fields Datatypes Constraints
ID varchar(50) Primary Key
JM_Name Varchar(50) Not null

Project by: Kuldeep Singh | 1053 Page 54


Library Management System

SubscriptionNo Varchar(50) Not null


SubscriptionDate Varchar(50) -
Subscription Varchar(20) Not null
SubscriptionDateFrom Varchar(50) -
SubscriptionDateTo Varchar(50) -
BillNo Varchar(50) -
BillDate Varchar(50) -
Amount Varchar(20) Not null
PaidOn Varchar(50) Not null
IssueNo varchar(50) -
IssueDate varchar(50) -
Months varchar(50) Not null
JM_Year varchar(50) -
Volume varchar(50) Not null
V_num varchar(50) -
DateOfReceipt varchar(50) -
SupplierName varchar(50) -
Department varchar(50) Not null
Remarks varchar(50) -

Project by: Kuldeep Singh | 1053 Page 55


Library Management System

Project
Source code

Project by: Kuldeep Singh | 1053 Page 56


Library Management System

frmLogin.vb

Imports System.Data.SqlClient
Public Class Frmlogin

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button1.Click
If Len(Trim(cmbUserType.Text)) = 0 Then
MessageBox.Show("Please select user type", "Input Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
cmbUserType.Focus()
Exit Sub
End If
If Len(Trim(txtUsername.Text)) = 0 Then
MessageBox.Show("Please enter user name", "Input Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
txtUsername.Focus()
Exit Sub
End If
If Len(Trim(txtPassword.Text)) = 0 Then
MessageBox.Show("Please enter password", "Input Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
txtPassword.Focus()
Exit Sub
End If
Try
Dim myConnection As SqlConnection
myConnection = New SqlConnection("Data Source=.\SQLEXPRESS;Initial
Catalog=LibraryDatabase;Integrated Security=True")
Dim myCommand As SqlCommand
myCommand = New SqlCommand("SELECT UserName,password FROM
Registration where UserName = @Username and Password = @UserPassword",
myConnection)

Dim uName As New SqlParameter("@Username", SqlDbType.VarChar)


Dim uPassword As New SqlParameter("@UserPassword",
SqlDbType.VarChar)
uName.Value = txtUsername.Text
uPassword.Value = txtPassword.Text
myCommand.Parameters.Add(uName)
myCommand.Parameters.Add(uPassword)
myCommand.Connection.Open()
Dim myReader As SqlDataReader =
myCommand.ExecuteReader(CommandBehavior.CloseConnection)
Dim Login As Object = 0
If myReader.HasRows Then
myReader.Read()

Project by: Kuldeep Singh | 1053 Page 57


Library Management System

Login = myReader(Login)
End If
If Login = Nothing Then
MsgBox("Login is Failed...Try again !", MsgBoxStyle.Critical, "Login Denied")
txtUsername.Clear()
txtPassword.Clear()
txtUsername.Focus()
Else
ProgressBar1.Visible = True
ProgressBar1.Maximum = 5000
ProgressBar1.Minimum = 0
ProgressBar1.Value = 4
ProgressBar1.Step = 1
For i = 0 To 5000
ProgressBar1.PerformStep()
Next
Me.Hide()
frmMain.lblUser.Text = txtUsername.Text
frmMain.Show()
End If
myCommand.Dispose()
myConnection.Close()
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
End Try
End Sub
Private Sub Frmlogin_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
End
End Sub
Private Sub linkLabel1_LinkClicked(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles
linkLabel1.LinkClicked
Me.Hide()
frmChangePassword.Show()
frmChangePassword.cmbUserType.Text = ""
frmChangePassword.UserName.Text = ""
frmChangePassword.OldPassword.Text = ""
frmChangePassword.NewPassword.Text = ""
frmChangePassword.ConfirmPassword.Text = ""
frmChangePassword.cmbUserType.Focus()
End Sub
Private Sub linkLabel3_LinkClicked(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles
linkLabel3.LinkClicked
Me.Hide()

Project by: Kuldeep Singh | 1053 Page 58


Library Management System

frmPasswordRecovery.Show()
End Sub

Private Sub Frmlogin_FormClosing(ByVal sender As System.Object, ByVal e As


System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing
End
End Sub
End Class

frmSplash.vb
Public Class frmSplash
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Timer1.Tick
ProgressBar1.Visible = True
ProgressBar1.Value = ProgressBar1.Value + 2
If (ProgressBar1.Value = 10) Then
Label3.Text = "Reading modules.."
ElseIf (ProgressBar1.Value = 20) Then
Label3.Text = "Turning on modules."
ElseIf (ProgressBar1.Value = 40) Then
Label3.Text = "Starting modules.."
ElseIf (ProgressBar1.Value = 60) Then
Label3.Text = "Loading modules.."
ElseIf (ProgressBar1.Value = 80) Then
Label3.Text = "Done Loading modules.."
ElseIf (ProgressBar1.Value = 100) Then
frmLogin.Show()
Timer1.Enabled = False
Me.Hide()
End If
End Sub
End Class

frmPasswordRecovery.vb

imports System.Net.Mail
Imports System.Data.SqlClient
Public Class frmPasswordRecovery

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button1.Click
Try
Cursor = Cursors.WaitCursor
Timer1.Enabled = True
Dim ds As New DataSet()
Dim con As New SqlConnection("Data Source=.\SQLEXPRESS;Initial
Catalog=LibraryDatabase;Integrated Security=True")
con.Open()

Project by: Kuldeep Singh | 1053 Page 59


Library Management System

Dim cmd As New SqlCommand("SELECT Password FROM


Registration,Users where Users.UserName=Registration.UserName and
Registration.usertype = 'admin'", con)
Dim da As New SqlDataAdapter(cmd)
da.Fill(ds)
con.Close()
If ds.Tables(0).Rows.Count > 0 Then
Dim Msg As New MailMessage()
' Sender e-mail address.
Msg.From = New MailAddress("kuldeepsingh29996@gmail.com")
' Recipient e-mail address.
Msg.[To].Add("kuldeepkulfi7@gmail.com")
Msg.Subject = "Your Password Details"
Msg.Body = "Your Password: " &
Convert.ToString(ds.Tables(0).Rows(0)("Password")) & ""
Msg.IsBodyHtml = True
' your remote SMTP server IP.
Dim smtp As New SmtpClient()
smtp.Host = "smtp.gmail.com"
smtp.Port = 587
smtp.Credentials = New
Net.NetworkCredential("Kuldeepsingh29996@gmail.com", "28282828285")
smtp.EnableSsl = True
smtp.Send(Msg)
MessageBox.Show("Password Successfully sent " & vbCrLf & "Please
check your mail", "Thank you", MessageBoxButtons.OK,
MessageBoxIcon.Information)
Me.Hide()
frmlogin.Show()
Frmlogin.txtUsername.Text = ""
Frmlogin.txtPassword.Text = ""
Frmlogin.cmbUserType.Text = ""
Frmlogin.cmbUserType.Focus()
End If
Catch ex As Exception
MsgBox(ex.ToString())
End Try
End Sub

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Timer1.Tick
Cursor = Cursors.Default
Timer1.Enabled = False
End Sub

Private Sub frmPasswordRecovery_FormClosing(ByVal sender As Object, ByVal


e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
Me.Hide()
Frmlogin.Show()
Frmlogin.txtUsername.Text = ""

Project by: Kuldeep Singh | 1053 Page 60


Library Management System

Frmlogin.txtPassword.Text = ""
Frmlogin.cmbUserType.Text = ""
Frmlogin.cmbUserType.Focus()
End Sub

Private Sub frmPasswordRecovery_Load(ByVal sender As System.Object, ByVal


e As System.EventArgs) Handles MyBase.Load

End Sub
End Class

frmPasswordRecovery.vb
Imports System.Data.SqlClient
Public Class frmChangePassword
Dim rdr As SqlDataReader = Nothing
Dim con As SqlConnection = Nothing
Dim cmd As SqlCommand = Nothing
Dim ck As String = "Data Source=.\SQLEXPRESS;Initial
Catalog=LibraryDatabase;Integrated Security=True"

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button1.Click
Try
Dim RowsAffected As Integer = 0
If Len(Trim(cmbUserType.Text)) = 0 Then
MessageBox.Show("Please select user type", "Input Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
cmbUserType.Focus()
Exit Sub
End If
If Len(Trim(UserName.Text)) = 0 Then
MessageBox.Show("Please enter user name", "Input Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
UserName.Focus()
Exit Sub
End If
If Len(Trim(OldPassword.Text)) = 0 Then
MessageBox.Show("Please enter old password", "Input Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
OldPassword.Focus()
Exit Sub
End If
If Len(Trim(NewPassword.Text)) = 0 Then
MessageBox.Show("Please enter new password", "Input Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
NewPassword.Focus()
Exit Sub
End If

Project by: Kuldeep Singh | 1053 Page 61


Library Management System

If Len(Trim(ConfirmPassword.Text)) = 0 Then
MessageBox.Show("Please confirm new password", "Input Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
ConfirmPassword.Focus()
Exit Sub
End If
If NewPassword.TextLength < 5 Then
MessageBox.Show("The New Password Should be of Atleast 5 Characters",
"Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
NewPassword.Text = ""
ConfirmPassword.Text = ""
NewPassword.Focus()
Exit Sub
ElseIf NewPassword.Text <> ConfirmPassword.Text Then
MessageBox.Show("Password do not match", "Input error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
NewPassword.Text = ""
OldPassword.Text = ""
ConfirmPassword.Text = ""
OldPassword.Focus()
Exit Sub
ElseIf OldPassword.Text = NewPassword.Text Then
MessageBox.Show("Password is same..Re-enter new password", "Input
error", MessageBoxButtons.OK, MessageBoxIcon.Error)
NewPassword.Text = ""
ConfirmPassword.Text = ""
NewPassword.Focus()
Exit Sub
End If
con = New SqlConnection(ck)
con.Open()
Dim co As String = "update Registration set password = '" &
NewPassword.Text & "'where username='" & UserName.Text & "' and password = '"
& OldPassword.Text & "' and usertype='" & cmbUserType.Text & "'"
cmd = New SqlCommand(co)
cmd.Connection = con
RowsAffected = cmd.ExecuteNonQuery()
If RowsAffected > 0 Then
MessageBox.Show("Successfully changed", "Password",
MessageBoxButtons.OK, MessageBoxIcon.Information)
Me.Hide()
Frmlogin.Show()
Frmlogin.cmbUserType.Text = ""
Frmlogin.txtUsername.Text = ""
Frmlogin.txtPassword.Text = ""
Frmlogin.cmbUserType.Focus()
Else
MessageBox.Show("invalid user name or password", "input error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
UserName.Text = ""

Project by: Kuldeep Singh | 1053 Page 62


Library Management System

NewPassword.Text = ""
OldPassword.Text = ""
ConfirmPassword.Text = ""
UserName.Focus()
End If
con.Close()
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
End Try
End Sub
Private Sub ChangePassword_FormClosing(ByVal sender As Object, ByVal e As
System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
Me.Hide()
Frmlogin.Show()
Frmlogin.cmbUserType.Text = ""
frmLogin.txtUsername.Text = ""
frmLogin.txtPassword.Text = ""
Frmlogin.cmbUserType.Focus()
End Sub
End Class

frmMain.vb
Public Class frmMain
Private Sub RegistrationToolStripMenuItem_Click(sender As Object, e As
EventArgs) Handles RegistrationToolStripMenuItem.Click
frmRegistration.Show()
End Sub

Private Sub AboutToolStripMenuItem_Click(sender As Object, e As EventArgs)


Handles AboutToolStripMenuItem.Click
frmAbout.Show()
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Timer1.Tick
lblDateTime.Text = Now
End Sub
Private Sub CalculatorToolStripMenuItem_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles CalculatorToolStripMenuItem.Click
System.Diagnostics.Process.Start("Calc.exe")
End Sub
Private Sub NotepadToolStripMenuItem_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles NotepadToolStripMenuItem.Click
System.Diagnostics.Process.Start("Notepad.exe")
End Sub
Private Sub TaskManagerToolStripMenuItem_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
TaskManagerToolStripMenuItem.Click
System.Diagnostics.Process.Start("TaskMgr.exe")
End Sub

Project by: Kuldeep Singh | 1053 Page 63


Library Management System

Private Sub MSWordToolStripMenuItem_Click(ByVal sender As System.Object,


ByVal e As System.EventArgs) Handles MSWordToolStripMenuItem.Click
System.Diagnostics.Process.Start("WinWord.exe")
End Sub
Private Sub WordpadToolStripMenuItem_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles WordpadToolStripMenuItem.Click
System.Diagnostics.Process.Start("Wordpad.exe")
End Sub
Private Sub SystemInfoToolStripMenuItem_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
SystemInfoToolStripMenuItem.Click
frmSystemInfo.Show()
End Sub
Private Sub StudentsToolStripMenuItem_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles StudentsToolStripMenuItem.Click
frmStudent.Show()
End Sub
Private Sub BooksToolStripMenuItem_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles BooksToolStripMenuItem.Click
frmBookEntry.Show()
End Sub
Private Sub FacultiesToolStripMenuItem_Click(sender As Object, e As EventArgs)
Handles FacultiesToolStripMenuItem.Click
frmStaff.Show()
End Sub
Private Sub IssueToolStripMenuItem_Click(sender As Object, e As EventArgs)
Handles IssueToolStripMenuItem.Click
frmBookIssue.Show()
End Sub
Private Sub LogoutToolStripMenuItem_Click(sender As Object, e As EventArgs)
Handles LogoutToolStripMenuItem.Click
Me.Hide()
frmAbout.Hide()
frmSystemInfo.Hide()
frmStudent.Hide()
frmBookIssue.Hide()
frmBookReturn.Hide()
frmBookEntry.Hide()
frmStudent.Hide()
frmBookReturn.Hide()
frmCourse.Hide()
frmStaff.Hide()
frmSupplier.Hide()
frmRegistration.Hide()
frmLoginDetails.Hide()
frmBookRecord.Hide()
frmDepartment.Hide()
frmYears.Hide()
frmStudentRecord1.Hide()
frmStaffRecord1.Hide()

Project by: Kuldeep Singh | 1053 Page 64


Library Management System

frmNewsPaper.Hide()
frmBookIssueRecord1.Hide()
frmBookIssueRecord_Staff1.Hide()
frmSupplierRecord.Hide()
frmBookIssueRecord1.Hide()
frmBookIssueRecord_Staff1.Hide()
frmBookReturnRecord_Student1.Hide()
frmBookReturnRecord_Staff1.Hide()
Frmlogin.Show()
Frmlogin.cmbUserType.Text = ""
Frmlogin.txtUsername.Text = ""
Frmlogin.txtPassword.Text = ""
Frmlogin.ProgressBar1.Visible = False
Frmlogin.cmbUserType.Focus()
End Sub
Private Sub BookReturnToolStripMenuItem_Click(sender As Object, e As
EventArgs) Handles BookReturnToolStripMenuItem.Click
frmBookReturn.Show()
End Sub
Private Sub SearchToolStripMenuItem1_Click(sender As Object, e As EventArgs)
Handles SearchToolStripMenuItem1.Click
frmBookRecord.Show()
End Sub
Private Sub CourseToolStripMenuItem_Click(sender As Object, e As EventArgs)
Handles CourseToolStripMenuItem.Click
frmCourse.Show()
End Sub
Private Sub DepartmentToolStripMenuItem_Click(sender As Object, e As
EventArgs) Handles DepartmentToolStripMenuItem.Click
frmDepartment.Show()
End Sub
Private Sub BooksToolStripMenuItem1_Click(sender As Object, e As EventArgs)
Handles BooksToolStripMenuItem1.Click
frmBookEntry.Show()
End Sub
Private Sub StudentsToolStripMenuItem1_Click(sender As Object, e As
EventArgs) Handles StudentsToolStripMenuItem1.Click
frmStudent.Show()
End Sub
Private Sub FacultiesToolStripMenuItem1_Click(sender As Object, e As
EventArgs) Handles FacultiesToolStripMenuItem1.Click
frmStaff.Show()
End Sub
Private Sub SuppliersToolStripMenuItem_Click(sender As Object, e As
EventArgs) Handles SuppliersToolStripMenuItem.Click
frmSupplier.Show()
End Sub
Private Sub RegistrationToolStripMenuItem1_Click(sender As Object, e As
EventArgs) Handles RegistrationToolStripMenuItem1.Click
frmRegistration.Show()

Project by: Kuldeep Singh | 1053 Page 65


Library Management System

End Sub
Private Sub LoginDetailsToolStripMenuItem_Click(sender As Object, e As
EventArgs) Handles LoginDetailsToolStripMenuItem.Click
frmLoginDetails.Show()
End Sub
Private Sub JournalsToolStripMenuItem_Click(sender As Object, e As EventArgs)
Handles JournalsToolStripMenuItem.Click
frmJournalsAndMagzines.Show()
End Sub
Private Sub NewPapersToolStripMenuItem_Click(sender As Object, e As
EventArgs) Handles NewPapersToolStripMenuItem.Click
frmNewsPaper.Show()
End Sub
Private Sub BooksIssueToolStripMenuItem_Click(sender As Object, e As
EventArgs) Handles BooksIssueToolStripMenuItem.Click
frmBookIssue.Show()
End Sub
Private Sub BooksReturnToolStripMenuItem_Click(sender As Object, e As
EventArgs) Handles BooksReturnToolStripMenuItem.Click
frmBookReturn.Show()
End Sub
Private Sub MasterEntryToolStripMenuItem2_Click(sender As Object, e As
EventArgs) Handles MasterEntryToolStripMenuItem2.Click
frmBookRecord.Show()
End Sub
Private Sub StudentsToolStripMenuItem5_Click(sender As Object, e As
EventArgs) Handles StudentsToolStripMenuItem5.Click
frmBookIssueRecord1.Show()
frmBookIssueRecord1.Reset()
End Sub
Private Sub StaffsToolStripMenuItem_Click(sender As Object, e As EventArgs)
Handles StaffsToolStripMenuItem.Click
frmBookIssueRecord_Staff1.Show()
frmBookIssueRecord_Staff1.Reset()
End Sub
Private Sub StudentsToolStripMenuItem6_Click(sender As Object, e As
EventArgs) Handles StudentsToolStripMenuItem6.Click
frmBookReturnRecord_Student1.Show()
frmBookReturnRecord_Student1.Reset()
End Sub
Private Sub StaffsToolStripMenuItem1_Click(sender As Object, e As EventArgs)
Handles StaffsToolStripMenuItem1.Click
frmBookReturnRecord_Staff1.Show()
frmBookReturnRecord_Staff1.Reset()
End Sub
Private Sub StudentsToolStripMenuItem3_Click(sender As Object, e As
EventArgs) Handles StudentsToolStripMenuItem3.Click
frmStudentRecord1.Show()
End Sub

Project by: Kuldeep Singh | 1053 Page 66


Library Management System

Private Sub FacultiesToolStripMenuItem3_Click(sender As Object, e As


EventArgs) Handles FacultiesToolStripMenuItem3.Click
frmStaffRecord1.Show()
End Sub
Private Sub SuppliersToolStripMenuItem1_Click(sender As Object, e As
EventArgs) Handles SuppliersToolStripMenuItem1.Click
frmSupplierRecord.Show()
End Sub
Private Sub JournalsAndMagzinesToolStripMenuItem_Click(sender As Object, e
As EventArgs) Handles JournalsAndMagzinesToolStripMenuItem.Click
frmJournalsMagzinesRecord1.Show()
End Sub
Private Sub BooksToolStripMenuItem4_Click(sender As Object, e As EventArgs)
Handles BooksToolStripMenuItem4.Click
frmNewsPaperRecord1.Show()
frmNewsPaperRecord1.Reset()
End Sub
Private Sub BookListToolStripMenuItem_Click(sender As Object, e As
EventArgs) Handles BookListToolStripMenuItem.Click
frmBookReport.Show()
End Sub
Private Sub StudentListToolStripMenuItem_Click(sender As Object, e As
EventArgs) Handles StudentListToolStripMenuItem.Click
frmStudentReport.Show()
End Sub
Private Sub StaffListToolStripMenuItem_Click(sender As Object, e As EventArgs)
Handles StaffListToolStripMenuItem.Click
frmStaffReport.Show()
End Sub

Private Sub StudentToolStripMenuItem_Click(sender As Object, e As EventArgs)


Handles StudentToolStripMenuItem.Click
frmBookIssueReport_Student.Show()
End Sub
Private Sub StaffToolStripMenuItem_Click(sender As Object, e As EventArgs)
Handles StaffToolStripMenuItem.Click
frmBookIssueReport_Staff.Show()
End Sub
Private Sub StudentToolStripMenuItem1_Click(sender As Object, e As EventArgs)
Handles StudentToolStripMenuItem1.Click
frmBookReturnReport_Student.Show()
End Sub
Private Sub StaffToolStripMenuItem1_Click(sender As Object, e As EventArgs)
Handles StaffToolStripMenuItem1.Click
frmBookReturnReport_Staff.show()
End Sub
End Class

frmRegistration.vb
Imports System.Data

Project by: Kuldeep Singh | 1053 Page 67


Library Management System

Imports System.Data.SqlClient
Public Class frmRegistration
Dim con As New SqlConnection
Dim cmd As New SqlCommand
Dim reader As SqlDataReader = Nothing
Dim table As DataTable
Dim adaptar As SqlDataAdapter
Dim dt As New DataTable
Dim str As String = "Data Source=.\SQLEXPRESS;Initial
Catalog=LibraryDatabase;Integrated Security=True"
Sub Reset()
If con.State = ConnectionState.Open Then
con.Close()
End If
txtContactNo.Text = ""
txtEmailID.Text = ""
txtName.Text = ""
txtPassword.Text = ""
txtUsername.Text = ""
cmbUserType.Text = ""
txtUsername.Focus()
btnSave.Enabled = True
btnUpdate_record.Enabled = False
btnDelete.Enabled = False
If con.State = ConnectionState.Open Then
con.Close()
End If
End Sub
Private Sub frmRegistration_Load(sender As Object, e As EventArgs) Handles
MyBase.Load
Getdata()
End Sub

Public Sub Getdata()


Try
con.ConnectionString = str
con.Open()
cmd.Connection = con
cmd.CommandText = "select * from Registration order by RegisteredDate"
reader = cmd.ExecuteReader(CommandBehavior.CloseConnection)
DataGridView1.Rows.Clear()
While (reader.Read() = True)
DataGridView1.Rows.Add(reader(0), reader(1), reader(2), reader(3),
reader(4), reader(5), reader(6))
End While
con.Close()
If con.State = ConnectionState.Open Then
con.Close()
End If
Catch ex As Exception

Project by: Kuldeep Singh | 1053 Page 68


Library Management System

MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,


MessageBoxIcon.Error)
End Try
End Sub
Private Sub btnNewRecord_Click(sender As Object, e As EventArgs) Handles
btnNewRecord.Click
Reset()
End Sub
Private Sub DataGridView1_RowHeaderMouseClick(ByVal sender As Object,
ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles
DataGridView1.RowHeaderMouseClick
Try
Dim dr As DataGridViewRow = DataGridView1.SelectedRows(0)
txtUsername.Text = dr.Cells(0).Value.ToString()
txtUName.Text = dr.Cells(0).Value.ToString()
cmbUserType.Text = dr.Cells(1).Value.ToString()
txtPassword.Text = dr.Cells(2).Value.ToString()
txtName.Text = dr.Cells(3).Value.ToString()
txtContactNo.Text = dr.Cells(4).Value.ToString()
txtEmailID.Text = dr.Cells(5).Value.ToString()
btnUpdate_record.Enabled = True
btnDelete.Enabled = True
btnSave.Enabled = False
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
End Try
End Sub

Private Sub DataGridView1_RowPostPaint(ByVal sender As Object, ByVal e As


System.Windows.Forms.DataGridViewRowPostPaintEventArgs) Handles
DataGridView1.RowPostPaint
Dim strRowNumber As String = (e.RowIndex + 1).ToString()
Dim size As SizeF = e.Graphics.MeasureString(strRowNumber, Me.Font)
If DataGridView1.RowHeadersWidth < Convert.ToInt32((size.Width + 20))
Then
DataGridView1.RowHeadersWidth = Convert.ToInt32((size.Width + 20))
End If
Dim b As Brush = SystemBrushes.ControlText
e.Graphics.DrawString(strRowNumber, Me.Font, b, e.RowBounds.Location.X +
15, e.RowBounds.Location.Y + ((e.RowBounds.Height - size.Height) / 2))
End Sub

Private Sub btnSave_Click(sender As Object, e As EventArgs) Handles


btnSave.Click
If txtUsername.Text = "" Then
MessageBox.Show("Please enter username", "Error",
MessageBoxButtons.OK, MessageBoxIcon.[Error])
txtUsername.Focus()
Return

Project by: Kuldeep Singh | 1053 Page 69


Library Management System

End If
If cmbUserType.Text = "" Then
MessageBox.Show("Please select user type", "Error",
MessageBoxButtons.OK, MessageBoxIcon.[Error])
cmbUserType.Focus()
Return
End If
If txtPassword.Text = "" Then
MessageBox.Show("Please enter password", "Error",
MessageBoxButtons.OK, MessageBoxIcon.[Error])
txtPassword.Focus()
Return
End If
If txtName.Text = "" Then
MessageBox.Show("Please enter name", "Error", MessageBoxButtons.OK,
MessageBoxIcon.[Error])
txtName.Focus()
Return
End If
If txtContactNo.Text = "" Then
MessageBox.Show("Please enter contact no.", "Error",
MessageBoxButtons.OK, MessageBoxIcon.[Error])
txtContactNo.Focus()
Return
End If

If txtEmailID.Text = "" Then


MessageBox.Show("Please enter email id", "Error", MessageBoxButtons.OK,
MessageBoxIcon.[Error])
txtEmailID.Focus()
Return
End If
Try
con = New SqlConnection(str)
con.Open()
Dim ct As String = "select * from Registration where UserName=@find "
cmd = New SqlCommand(ct)
cmd.Connection = con
cmd.Parameters.Add(New SqlParameter("@find",
System.Data.SqlDbType.VarChar, 30, "UserName"))
cmd.Parameters("@find").Value = txtUsername.Text
reader = cmd.ExecuteReader()
If reader.Read() Then
MessageBox.Show("Username Already Exists", "Error",
MessageBoxButtons.OK, MessageBoxIcon.[Error])
txtUsername.Text = ""
txtUsername.Focus()
If (reader IsNot Nothing) Then
reader.Close()
End If

Project by: Kuldeep Singh | 1053 Page 70


Library Management System

Return
End If
con = New SqlConnection(str)
con.Open()
Dim cb As String = "insert into Registration VALUES ('" & txtUsername.Text
& "','" & cmbUserType.Text & "','" & txtPassword.Text & "','" & txtName.Text &
"','" & CInt(txtContactNo.Text) & "','" & txtEmailID.Text & "','" & Date.Now & "')"
cmd = New SqlCommand(cb)
cmd.Connection = con
cmd.ExecuteReader()
con.Close()
con.Open()
Dim cb1 As String = "insert into Users(Username) VALUES ('" &
txtUsername.Text & "')"
cmd = New SqlCommand(cb1)
cmd.Connection = con
cmd.ExecuteReader()
con.Close()
MessageBox.Show("Successfully Registered", "User",
MessageBoxButtons.OK, MessageBoxIcon.Information)
btnSave.Enabled = False
Getdata()
Catch ex As Exception
MessageBox.Show("Error while inserting record on table..." & ex.Message,
"Insert Records")

End Try
End Sub

Private Sub btnDelete_Click(sender As Object, e As EventArgs) Handles


btnDelete.Click
Try
If MessageBox.Show("Do you really want to delete this record?",
"Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) =
System.Windows.Forms.DialogResult.Yes Then
DeleteRecord()
End If

Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
End Try
End Sub
Private Sub DeleteRecord()
Try
If cmbUserType.Text = "admin" Or cmbUserType.Text = "Admin" Then
MessageBox.Show("Admin account can not be deleted", "Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
Exit Sub
End If

Project by: Kuldeep Singh | 1053 Page 71


Library Management System

Dim RowsAffected As Integer = 0


con = New SqlConnection(str)
con.Open()
Dim ct As String = "delete from Users Where UserName = '" &
txtUsername.Text & "'"
cmd = New SqlCommand(ct)
cmd.Connection = con
RowsAffected = cmd.ExecuteNonQuery()
If con.State = ConnectionState.Open Then
con.Close()
End If
con = New SqlConnection(str)
con.Open()
Dim ct1 As String = "delete from Registration Where UserName = '" &
txtUsername.Text & "'"
cmd = New SqlCommand(ct1)
cmd.Connection = con
RowsAffected = cmd.ExecuteNonQuery()

If RowsAffected > 0 Then


MessageBox.Show("Successfully deleted", "Record",
MessageBoxButtons.OK, MessageBoxIcon.Information)
If con.State = ConnectionState.Open Then
con.Close()
End If
Getdata()
Reset()
If con.State = ConnectionState.Open Then
con.Close()
End If
Else
MessageBox.Show("No Record found", "Sorry", MessageBoxButtons.OK,
MessageBoxIcon.Information)
Reset()
If con.State = ConnectionState.Open Then
con.Close()
End If
End If
If con.State = ConnectionState.Open Then
con.Close()
End If
Catch ex As Exception
MessageBox.Show("Error while deleting record on table..." & ex.Message,
"Insert Records")
End Try
End Sub

Private Sub txtContactNo_Validating(ByVal sender As System.Object, ByVal e As


System.ComponentModel.CancelEventArgs) Handles txtContactNo.Validating
If (txtContactNo.TextLength > 10) Then

Project by: Kuldeep Singh | 1053 Page 72


Library Management System

MessageBox.Show("Only 10 digits are allowed", "Input Error",


MessageBoxButtons.OK, MessageBoxIcon.Error)
txtContactNo.Focus()
ElseIf (txtContactNo.TextLength < 10) Then
MessageBox.Show("Contact No should be 10 Numbers", "Input Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
txtContactNo.Focus()
End If
End Sub
Private Sub txtContactNo_KeyPress(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles txtContactNo.KeyPress
If (e.KeyChar < Chr(48) Or e.KeyChar > Chr(57)) And e.KeyChar <> Chr(8)
Then
e.Handled = True
End If
End Sub

Private Sub txtEmailID_Validating(ByVal sender As System.Object, ByVal e As


System.ComponentModel.CancelEventArgs) Handles txtEmailID.Validating
Dim rEMail As New System.Text.RegularExpressions.Regex("^[a-zA-Z][\w\.-
]{2,28}[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-
Z]$")
If txtEmailID.Text.Length > 0 Then
If Not rEMail.IsMatch(txtEmailID.Text) Then
MessageBox.Show("invalid email address", "Error",
MessageBoxButtons.OK, MessageBoxIcon.[Error])
txtEmailID.SelectAll()
e.Cancel = True
End If
End If
End Sub

Private Sub btnUpdate_record_Click(sender As Object, e As EventArgs) Handles


btnUpdate_record.Click
Try
If txtUsername.Text = "" Then
MessageBox.Show("Please enter username", "Error",
MessageBoxButtons.OK, MessageBoxIcon.[Error])
txtUsername.Focus()
Return
End If
If cmbUserType.Text = "" Then
MessageBox.Show("Please select user type", "Error",
MessageBoxButtons.OK, MessageBoxIcon.[Error])
cmbUserType.Focus()
Return
End If
If txtPassword.Text = "" Then
MessageBox.Show("Please enter password", "Error",
MessageBoxButtons.OK, MessageBoxIcon.[Error])

Project by: Kuldeep Singh | 1053 Page 73


Library Management System

txtPassword.Focus()
Return
End If
If txtName.Text = "" Then
MessageBox.Show("Please enter name", "Error", MessageBoxButtons.OK,
MessageBoxIcon.[Error])
txtName.Focus()
Return
End If
If txtContactNo.Text = "" Then
MessageBox.Show("Please enter contact no.", "Error",
MessageBoxButtons.OK, MessageBoxIcon.[Error])
txtContactNo.Focus()
Return
End If
If txtEmailID.Text = "" Then
MessageBox.Show("Please enter email id", "Error",
MessageBoxButtons.OK, MessageBoxIcon.[Error])
txtEmailID.Focus()
Return
End If
con.ConnectionString = str
con.Open()
cmd.Connection = con
cmd.CommandText = "update registration set username='" &
txtUsername.Text & "', usertype='" & cmbUserType.Text & "',password='" &
txtPassword.Text & "',contactno='" & txtContactNo.Text & "',email='" &
txtEmailID.Text & "',name='" & txtName.Text & "' where username='" &
txtUName.Text & "'"
cmd.ExecuteNonQuery()
cmd.ExecuteReader()
con.Close()
MessageBox.Show("Successfully updated", "User Info",
MessageBoxButtons.OK, MessageBoxIcon.Information)
btnUpdate_record.Enabled = False
Getdata()
Catch ex As Exception
MessageBox.Show("Error while inserting record on table..." & ex.Message,
"Insert Records")
End Try
End Sub
End Class

frmBookEntry.vb
Option Strict On
Imports System.Data.SqlClient
Public Class frmBookEntry
Dim rdr As SqlDataReader
Dim dtable As DataTable
Dim con As SqlConnection

Project by: Kuldeep Singh | 1053 Page 74


Library Management System

Dim adp As SqlDataAdapter


Dim ds As DataSet
Dim cmd As SqlCommand
Dim dt As New DataTable
Dim gender As String
Dim cs As String = "Data Source=.\SQLEXPRESS;Initial
Catalog=LibraryDatabase;Integrated Security=True"
Sub fillSupplier()
Try
Dim CN As New SqlConnection(cs)
CN.Open()
adp = New SqlDataAdapter()
adp.SelectCommand = New SqlCommand("SELECT distinct
RTRIM(SupplierName) FROM Supplier", CN)
ds = New DataSet("ds")
adp.Fill(ds)
dtable = ds.Tables(0)
cmbSupplierName.Items.Clear()
For Each drow As DataRow In dtable.Rows
cmbSupplierName.Items.Add(drow(0).ToString())
Next
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
End Try
End Sub
Sub fillDepartment()
Try
Dim CN As New SqlConnection(cs)
CN.Open()
adp = New SqlDataAdapter()
adp.SelectCommand = New SqlCommand("SELECT distinct
RTRIM(Departmentname) FROM Department", CN)
ds = New DataSet("ds")
adp.Fill(ds)
dtable = ds.Tables(0)
cmbDepartment.Items.Clear()
For Each drow As DataRow In dtable.Rows
cmbDepartment.Items.Add(drow(0).ToString())
Next
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
End Try
End Sub
Sub fillSubject()
Try
Dim CN As New SqlConnection(cs)
CN.Open()
adp = New SqlDataAdapter()

Project by: Kuldeep Singh | 1053 Page 75


Library Management System

adp.SelectCommand = New SqlCommand("SELECT distinct


RTRIM(Subject) FROM Book", CN)
ds = New DataSet("ds")
adp.Fill(ds)
dtable = ds.Tables(0)
cmbSubject.Items.Clear()
For Each drow As DataRow In dtable.Rows
cmbSubject.Items.Add(drow(0).ToString())
Next
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
End Try
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs)
'frmBookRecord1.Show()
End Sub
Sub Reset()
txtAccessionNo.Text = ""
txtAlmiraPosition.Text = ""
txtAuthor.Text = ""
txtBarcode.Text = ""
txtBookTitle.Text = ""
txtCD.Text = ""
txtClassNo.Text = ""
txtEdition.Text = ""
txtISBN.Text = ""
txtJointAuthor.Text = ""
txtNoOfBooks.Text = ""
txtPlaceOfPublisher.Text = ""
txtPrice.Text = ""
txtPublisherName.Text = ""
txtPublishingYear.Text = ""
txtReference.Text = ""
txtRemarks.Text = ""
txtVolume.Text = ""
cmbDepartment.SelectedIndex = -1
cmbSubject.Text = ""
cmbSupplierName.Text = ""
dtpBillDate.Text = CType(Today, String)
btnDelete.Enabled = False
btnUpdate_record.Enabled = False
btnSave.Enabled = True
txtAccessionNo.Focus()
End Sub
Sub AutocompleteBookTitle()
Try
con = New SqlConnection(cs)
con.Open()

Project by: Kuldeep Singh | 1053 Page 76


Library Management System

Dim cmd As New SqlCommand("SELECT distinct BookTitle FROM Book",


con)
Dim ds As New DataSet()
Dim da As New SqlDataAdapter(cmd)
da.Fill(ds, "ds")
Dim col As New AutoCompleteStringCollection()
Dim i As Integer = 0
For i = 0 To ds.Tables(0).Rows.Count - 1
col.Add(ds.Tables(0).Rows(i)("BookTitle").ToString())
Next
txtBookTitle.AutoCompleteSource = AutoCompleteSource.CustomSource
txtBookTitle.AutoCompleteCustomSource = col
txtBookTitle.AutoCompleteMode = AutoCompleteMode.Suggest
con.Close()
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
End Try
End Sub

Sub AutocompleteJointAuthors()
Try
con = New SqlConnection(cs)
con.Open()
Dim cmd As New SqlCommand("SELECT distinct JointAuthors FROM
Book", con)
Dim ds As New DataSet()
Dim da As New SqlDataAdapter(cmd)
da.Fill(ds, "ds")
Dim col As New AutoCompleteStringCollection()
Dim i As Integer = 0
For i = 0 To ds.Tables(0).Rows.Count - 1
col.Add(ds.Tables(0).Rows(i)("JointAuthors").ToString())
Next
txtJointAuthor.AutoCompleteSource = AutoCompleteSource.CustomSource
txtJointAuthor.AutoCompleteCustomSource = col
txtJointAuthor.AutoCompleteMode = AutoCompleteMode.Suggest
con.Close()
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
End Try
End Sub
Sub AutocompleteAuthor()
Try
con = New SqlConnection(cs)
con.Open()
Dim cmd As New SqlCommand("SELECT distinct Author FROM Book",
con)
Dim ds As New DataSet()

Project by: Kuldeep Singh | 1053 Page 77


Library Management System

Dim da As New SqlDataAdapter(cmd)


da.Fill(ds, "ds")
Dim col As New AutoCompleteStringCollection()
Dim i As Integer = 0
For i = 0 To ds.Tables(0).Rows.Count - 1
col.Add(ds.Tables(0).Rows(i)("Author").ToString())
Next
txtAuthor.AutoCompleteSource = AutoCompleteSource.CustomSource
txtAuthor.AutoCompleteCustomSource = col
txtAuthor.AutoCompleteMode = AutoCompleteMode.Suggest
con.Close()
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
End Try
End Sub
Sub AutocompletePublisher()
Try
con = New SqlConnection(cs)
con.Open()
Dim cmd As New SqlCommand("SELECT distinct Publisher FROM Book",
con)
Dim ds As New DataSet()
Dim da As New SqlDataAdapter(cmd)
da.Fill(ds, "ds")
Dim col As New AutoCompleteStringCollection()
Dim i As Integer = 0
For i = 0 To ds.Tables(0).Rows.Count - 1
col.Add(ds.Tables(0).Rows(i)("Publisher").ToString())
Next
txtPublisherName.AutoCompleteSource =
AutoCompleteSource.CustomSource
txtPublisherName.AutoCompleteCustomSource = col
txtPublisherName.AutoCompleteMode = AutoCompleteMode.Suggest
con.Close()
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
End Try
End Sub
Sub AutocompletePlaceOfPublisher()
Try
con = New SqlConnection(cs)
con.Open()
Dim cmd As New SqlCommand("SELECT distinct PlaceOfPublisher FROM
Book", con)
Dim ds As New DataSet()
Dim da As New SqlDataAdapter(cmd)
da.Fill(ds, "ds")
Dim col As New AutoCompleteStringCollection()

Project by: Kuldeep Singh | 1053 Page 78


Library Management System

Dim i As Integer = 0
For i = 0 To ds.Tables(0).Rows.Count - 1
col.Add(ds.Tables(0).Rows(i)("PlaceOfPublisher").ToString())
Next
txtPlaceOfPublisher.AutoCompleteSource =
AutoCompleteSource.CustomSource
txtPlaceOfPublisher.AutoCompleteCustomSource = col
txtPlaceOfPublisher.AutoCompleteMode = AutoCompleteMode.Suggest
con.Close()
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
End Try
End Sub
Sub AutocompleteAccessionNo()
Try
con = New SqlConnection(cs)
con.Open()
Dim cmd As New SqlCommand("SELECT distinct AccessionNo FROM
Book", con)
Dim ds As New DataSet()
Dim da As New SqlDataAdapter(cmd)
da.Fill(ds, "ds")
Dim col As New AutoCompleteStringCollection()
Dim i As Integer = 0
For i = 0 To ds.Tables(0).Rows.Count - 1
col.Add(ds.Tables(0).Rows(i)("AccessionNo").ToString())
Next
txtAccessionNo.AutoCompleteSource = AutoCompleteSource.CustomSource
txtAccessionNo.AutoCompleteCustomSource = col
txtAccessionNo.AutoCompleteMode = AutoCompleteMode.Suggest
con.Close()
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
End Try
End Sub
Private Sub frmBookEntry_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
fillDepartment()
fillSubject()
fillSupplier()
AutocompleteAccessionNo()
AutocompleteBookTitle()
AutocompleteJointAuthors()
AutocompletePlaceOfPublisher()
AutocompletePublisher()
AutocompleteAuthor()
End Sub

Project by: Kuldeep Singh | 1053 Page 79


Library Management System

Private Sub btnNewRecord_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles btnNewRecord.Click
Reset()
End Sub

Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles btnSave.Click
Try
If Len(Trim(txtAccessionNo.Text)) = 0 Then
MessageBox.Show("Please enter Accession no.", "Input Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
txtAccessionNo.Focus()
Exit Sub
End If
If Len(Trim(txtBookTitle.Text)) = 0 Then
MessageBox.Show("Please enter book title", "Input Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
txtBookTitle.Focus()
Exit Sub
End If
If Len(Trim(txtAuthor.Text)) = 0 Then
MessageBox.Show("Please enter author name", "Input Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
txtAuthor.Focus()
Exit Sub
End If
If Len(Trim(cmbSubject.Text)) = 0 Then
MessageBox.Show("Please enetr/select subject", "Input Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
cmbSubject.Focus()
Exit Sub
End If
If Len(Trim(cmbDepartment.Text)) = 0 Then
MessageBox.Show("Please select department", "Input Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
cmbDepartment.Focus()
Exit Sub
End If
If Len(Trim(txtEdition.Text)) = 0 Then
MessageBox.Show("Please enter edition", "Input Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
txtEdition.Focus()
Exit Sub
End If
If Len(Trim(txtPublisherName.Text)) = 0 Then
MessageBox.Show("Please enter publisher name", "Input Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
txtPublisherName.Focus()
Exit Sub
End If

Project by: Kuldeep Singh | 1053 Page 80


Library Management System

If Len(Trim(txtPlaceOfPublisher.Text)) = 0 Then
MessageBox.Show("Please enter place of publisher", "Input Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
txtPlaceOfPublisher.Focus()
Exit Sub
End If
If Len(Trim(txtNoOfBooks.Text)) = 0 Then
MessageBox.Show("Please enter no. of books", "Input Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
txtNoOfBooks.Focus()
Exit Sub
End If
If Len(Trim(txtAlmiraPosition.Text)) = 0 Then
MessageBox.Show("Please enter almira position", "Input Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
txtAlmiraPosition.Focus()
Exit Sub
End If
If Len(Trim(txtPrice.Text)) = 0 Then
MessageBox.Show("Please enter price", "Input Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
txtPrice.Focus()
Exit Sub
End If
If (txtReference.Text = "") Then
txtReference.Text = CType(0, String)
End If
If Len(Trim(cmbSupplierName.Text)) = 0 Then
MessageBox.Show("Please select supplier", "Input Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
cmbSupplierName.Focus()
Exit Sub
End If
con = New SqlConnection(cs)
con.Open()
Dim ct As String = "select AccessionNo from Book where AccessionNo='" &
txtAccessionNo.Text & "'"
cmd = New SqlCommand(ct)
cmd.Connection = con
rdr = cmd.ExecuteReader()
If rdr.Read Then
MessageBox.Show("Accession no. already exists", "Input Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
txtAccessionNo.Text = ""
txtAccessionNo.Focus()
If Not rdr Is Nothing Then
rdr.Close()
End If
Exit Sub
End If

Project by: Kuldeep Singh | 1053 Page 81


Library Management System

con = New SqlConnection(cs)


con.Open()
Dim cb As String = "insert into Book(AccessionNo, BookTitle, Author,
JointAuthors, Subject, Department, Barcode, ISBN, Volume, Edition, ClassNo,
Publisher, PlaceOfPublisher, CD,PublishingYear, Reference, NoOfBooks,
AlmiraPosition, Price, BillDate, Remarks,SupplierName) VALUES('" &
txtAccessionNo.Text & "','" & txtBookTitle.Text & "','" & txtAuthor.Text & "','" &
txtJointAuthor.Text & "','" & cmbSubject.Text & "','" & cmbDepartment.Text & "','"
& txtBarcode.Text & "','" & txtISBN.Text & "','" & txtVolume.Text & "','" &
txtEdition.Text & "','" & txtClassNo.Text & "','" & txtPublisherName.Text & "','" &
txtPlaceOfPublisher.Text & "','" & txtCD.Text & "','" & txtPublishingYear.Text &
"','" & txtReference.Text & "','" & txtNoOfBooks.Text & "','" &
txtAlmiraPosition.Text & "','" & txtPrice.Text & "','" & dtpBillDate.Text & "','" &
txtRemarks.Text & "','" & cmbSupplierName.Text & "')"
cmd = New SqlCommand(cb)
cmd.Connection = con
cmd.ExecuteNonQuery()
con.Close()
MessageBox.Show("Successfully saved", "Book Record",
MessageBoxButtons.OK, MessageBoxIcon.Information)
fillSubject()
AutocompleteAccessionNo()
AutocompleteBookTitle()
AutocompleteJointAuthors()
AutocompletePlaceOfPublisher()
AutocompletePublisher()
AutocompleteAuthor()
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
End Try
End Sub

Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles btnDelete.Click
Try
If MessageBox.Show("Do you really want to delete this record?",
"Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) =
System.Windows.Forms.DialogResult.Yes Then
DeleteRecord()
End If
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
End Try
End Sub
Public Sub DeleteRecord()
Try
Dim RowsAffected As Integer = 0
con = New SqlConnection(cs)

Project by: Kuldeep Singh | 1053 Page 82


Library Management System

con.Open()
Dim cq As String = "delete from Book where AccessionNo= '" &
txtAccessionNo.Text & "'"
cmd = New SqlCommand(cq)
cmd.Connection = con
RowsAffected = cmd.ExecuteNonQuery()
If RowsAffected > 0 Then
MessageBox.Show("Successfully deleted", "Record",
MessageBoxButtons.OK, MessageBoxIcon.Information)
fillSubject()
Reset()
Else
MessageBox.Show("No record found", "Sorry", MessageBoxButtons.OK,
MessageBoxIcon.Information)
fillSubject()
AutocompleteAccessionNo()
AutocompleteBookTitle()
AutocompleteJointAuthors()
AutocompletePlaceOfPublisher()
AutocompletePublisher()
AutocompleteAuthor()
Reset()
If con.State = ConnectionState.Open Then
con.Close()
End If
con.Close()
End If
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
End Try
End Sub

Private Sub btnUpdate_record_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles btnUpdate_record.Click
Try
If Len(Trim(txtAccessionNo.Text)) = 0 Then
MessageBox.Show("Please enter Accession no.", "Input Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
txtAccessionNo.Focus()
Exit Sub
End If
If Len(Trim(txtBookTitle.Text)) = 0 Then
MessageBox.Show("Please enter book title", "Input Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
txtBookTitle.Focus()
Exit Sub
End If
If Len(Trim(txtAuthor.Text)) = 0 Then

Project by: Kuldeep Singh | 1053 Page 83


Library Management System

MessageBox.Show("Please enter author name", "Input Error",


MessageBoxButtons.OK, MessageBoxIcon.Error)
txtAuthor.Focus()
Exit Sub
End If
If Len(Trim(cmbSubject.Text)) = 0 Then
MessageBox.Show("Please enetr/select subject", "Input Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
cmbSubject.Focus()
Exit Sub
End If
If Len(Trim(cmbDepartment.Text)) = 0 Then
MessageBox.Show("Please select department", "Input Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
cmbDepartment.Focus()
Exit Sub
End If
If Len(Trim(txtEdition.Text)) = 0 Then
MessageBox.Show("Please enter edition", "Input Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
txtEdition.Focus()
Exit Sub
End If
If Len(Trim(txtPublisherName.Text)) = 0 Then
MessageBox.Show("Please enter publisher name", "Input Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
txtPublisherName.Focus()
Exit Sub
End If
If Len(Trim(txtNoOfBooks.Text)) = 0 Then
MessageBox.Show("Please enter no. of books", "Input Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
txtNoOfBooks.Focus()
Exit Sub
End If
If Len(Trim(txtAlmiraPosition.Text)) = 0 Then
MessageBox.Show("Please enter almira position", "Input Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
txtAlmiraPosition.Focus()
Exit Sub
End If
If Len(Trim(txtPrice.Text)) = 0 Then
MessageBox.Show("Please enter price", "Input Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
txtPrice.Focus()
Exit Sub
End If
If (txtReference.Text = "") Then
txtReference.Text = CType(0, String)
End If

Project by: Kuldeep Singh | 1053 Page 84


Library Management System

If Len(Trim(cmbSupplierName.Text)) = 0 Then
MessageBox.Show("Please select supplier", "Input Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
cmbSupplierName.Focus()
Exit Sub
End If
con = New SqlConnection(cs)
con.Open()
Dim cb As String = "update Book set AccessionNo='" & txtAccessionNo.Text
& "', BookTitle='" & txtBookTitle.Text & "',Author='" & txtAuthor.Text &
"',JointAuthors='" & txtJointAuthor.Text & "',Subject='" & cmbSubject.Text &
"',Department='" & cmbDepartment.Text & "',Barcode='" & txtBarcode.Text &
"',ISBN='" & txtISBN.Text & "',Volume='" & txtVolume.Text & "',Edition='" &
txtEdition.Text & "',ClassNo='" & txtClassNo.Text & "',Publisher='" &
txtPublisherName.Text & "',PlaceOfPublisher='" & txtPlaceOfPublisher.Text &
"',CD='" & txtCD.Text & "',PublishingYear='" & txtPublishingYear.Text &
"',Reference=" & txtReference.Text & ",NoOfBooks=" & txtNoOfBooks.Text &
",AlmiraPosition='" & txtAlmiraPosition.Text & "',Price=" & txtPrice.Text &
",BillDate='" & dtpBillDate.Text & "',Remarks='" & txtRemarks.Text &
"',SupplierName='" & cmbSupplierName.Text & "' where AccessionNo='" &
TextBox1.Text & "'"
cmd = New SqlCommand(cb)
cmd.Connection = con
cmd.ExecuteNonQuery()
con.Close()
MessageBox.Show("Successfully updated", "Book Record",
MessageBoxButtons.OK, MessageBoxIcon.Information)
btnUpdate_record.Enabled = False
fillSubject()
AutocompleteAccessionNo()
AutocompleteBookTitle()
AutocompleteJointAuthors()
AutocompletePlaceOfPublisher()
AutocompletePublisher()
AutocompleteAuthor()
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
End Try
End Sub

Private Sub txtPublishingYear_KeyPress(ByVal sender As System.Object, ByVal e


As System.Windows.Forms.KeyPressEventArgs) Handles
txtPublishingYear.KeyPress
If (e.KeyChar < Chr(48) Or e.KeyChar > Chr(57)) And e.KeyChar <> Chr(8)
Then
e.Handled = True
End If
End Sub

Project by: Kuldeep Singh | 1053 Page 85


Library Management System

Private Sub txtCD_KeyPress(ByVal sender As System.Object, ByVal e As


System.Windows.Forms.KeyPressEventArgs) Handles txtCD.KeyPress
If (e.KeyChar < Chr(48) Or e.KeyChar > Chr(57)) And e.KeyChar <> Chr(8)
Then
e.Handled = True
End If
End Sub

Private Sub txtReference_KeyPress(ByVal sender As System.Object, ByVal e As


System.Windows.Forms.KeyPressEventArgs) Handles txtReference.KeyPress
If (e.KeyChar < Chr(48) Or e.KeyChar > Chr(57)) And e.KeyChar <> Chr(8)
Then
e.Handled = True
End If
End Sub

Private Sub txtNoOfBooks_KeyPress(ByVal sender As System.Object, ByVal e As


System.Windows.Forms.KeyPressEventArgs) Handles txtNoOfBooks.KeyPress
If (e.KeyChar < Chr(48) Or e.KeyChar > Chr(57)) And e.KeyChar <> Chr(8)
Then
e.Handled = True
End If
End Sub

Private Sub txtPrice_KeyPress(ByVal sender As System.Object, ByVal e As


System.Windows.Forms.KeyPressEventArgs) Handles txtPrice.KeyPress
If (e.KeyChar < Chr(48) Or e.KeyChar > Chr(57)) And e.KeyChar <> Chr(8)
Then
e.Handled = True
End If
End Sub

Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button1.Click
frmBookRecord1.Show()
frmBookRecord1.Clear()
frmBookRecord1.fillAccessionNo()
frmBookRecord1.fillAuthor()
frmBookRecord1.fillDepartment()
frmBookRecord1.fillBookTitle()
frmBookRecord1.fillPOP()
frmBookRecord1.fillSubject()
frmBookRecord1.fillReferenceBook()
End Sub
End Class

frmBookRecord1.vb
Imports System.Data.SqlClient
Imports Excel = Microsoft.Office.Interop.Excel
Public Class frmBookIssueRecord1

Project by: Kuldeep Singh | 1053 Page 86


Library Management System

Dim rdr As SqlDataReader = Nothing


Dim dtable As DataTable
Dim con As SqlConnection = Nothing
Dim adp As SqlDataAdapter
Dim ds As DataSet
Dim cmd As SqlCommand = Nothing
Dim dt As New DataTable
Dim gender As String
Dim cs As String = "Data Source=.\SQLEXPRESS;Initial
Catalog=LibraryDatabase;Integrated Security=True"

Sub Reset()
txtBookName.Text = ""
txtBookName1.Text = ""
txtStudentName.Text = ""
cmbStudentName.Text = ""
cmbStudentName1.Text = ""
dtpDateFrom.Text = Today
dtpDateTo.Text = Today
DateTimePicker1.Text = Today
DateTimePicker2.Text = Today
DateTimePicker3.Text = Today
DateTimePicker4.Text = Today
DateTimePicker5.Text = Today
DateTimePicker6.Text = Today
DateTimePicker7.Text = Today
DateTimePicker8.Text = Today
DataGridView1.DataSource = Nothing
End Sub
Sub fillStudentName()
Try
cmbStudentName.DataSource = Nothing
cmbStudentName1.DataSource = Nothing
Dim CN As New SqlConnection(cs)
CN.Open()
adp = New SqlDataAdapter()
adp.SelectCommand = New SqlCommand("SELECT distinct Studentname
FROM Student,BookIssue_Student where
Student.StudentID=BookIssue_Student.StudentID", CN)
ds = New DataSet("ds")
adp.Fill(ds)
dtable = ds.Tables(0)
cmbStudentName.DisplayMember = "StudentName"
cmbStudentName.DataSource = dtable
cmbStudentName.SelectedIndex = -1
cmbStudentName1.DisplayMember = "StudentName"
cmbStudentName1.DataSource = dtable
cmbStudentName1.SelectedIndex = -1
Catch ex As Exception

Project by: Kuldeep Singh | 1053 Page 87


Library Management System

MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,


MessageBoxIcon.Error)
End Try
End Sub
Private Sub frmBookIssueRecord_Load(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles MyBase.Load
fillStudentName()
Reset()
End Sub

Private Sub txtBookName_TextChanged(ByVal sender As System.Object, ByVal e


As System.EventArgs) Handles txtBookName.TextChanged
Try
con = New SqlConnection(cs)
con.Open()
cmd = New SqlCommand("SELECT TransactionID as [Transaction ID],
IssueDate as [Issue Date], DueDate as [Due Date], Book.AccessionNo as [Accession
No],BookTitle as [Book Title],Author,Subject,ISBN,Edition,Student.StudentID as
[Student ID],StudentName as [Student Name],Course,Student.Department, Status
from Book,BookIssue_Student,Student where
Book.AccessionNo=BookIssue_Student.AccessionNo and
BookIssue_Student.StudentID=Student.StudentID and Issuedate Between '" &
dtpDateFrom.Text & "' and '" & dtpDateTo.Text & "' and BookTitle like '" &
txtBookName.Text & "%' order by Issuedate desc ", con)
Dim myDA As SqlDataAdapter = New SqlDataAdapter(cmd)
Dim myDataSet As DataSet = New DataSet()
myDA.Fill(myDataSet, "BookIssue_Student")
myDA.Fill(myDataSet, "Book")
myDA.Fill(myDataSet, "Student")
DataGridView1.DataSource =
myDataSet.Tables("BookIssue_Student").DefaultView
DataGridView1.DataSource = myDataSet.Tables("Book").DefaultView
DataGridView1.DataSource = myDataSet.Tables("Student").DefaultView
con.Close()
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
End Try
End Sub

Private Sub btnReset_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles btnReset.Click
Reset()
End Sub

Private Sub btnExportExcel_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles btnExportExcel.Click
If DataGridView1.RowCount = Nothing Then

Project by: Kuldeep Singh | 1053 Page 88


Library Management System

MessageBox.Show("Sorry nothing to export into excel sheet.." & vbCrLf &


"Please retrieve data in datagridview", "", MessageBoxButtons.OK,
MessageBoxIcon.Error)
Exit Sub
End If
Dim rowsTotal, colsTotal As Short
Dim I, j, iC As Short
System.Windows.Forms.Cursor.Current =
System.Windows.Forms.Cursors.WaitCursor
Dim xlApp As New Excel.Application
Try
Dim excelBook As Excel.Workbook = xlApp.Workbooks.Add
Dim excelWorksheet As Excel.Worksheet =
CType(excelBook.Worksheets(1), Excel.Worksheet)
xlApp.Visible = True

rowsTotal = DataGridView1.RowCount - 1
colsTotal = DataGridView1.Columns.Count - 1
With excelWorksheet
.Cells.Select()
.Cells.Delete()
For iC = 0 To colsTotal
.Cells(1, iC + 1).Value = DataGridView1.Columns(iC).HeaderText
Next
For I = 0 To rowsTotal - 1
For j = 0 To colsTotal
.Cells(I + 2, j + 1).value = DataGridView1.Rows(I).Cells(j).Value
Next j
Next I
.Rows("1:1").Font.FontStyle = "Bold"
.Rows("1:1").Font.Size = 12

.Cells.Columns.AutoFit()
.Cells.Select()
.Cells.EntireColumn.AutoFit()
.Cells(1, 1).Select()
End With
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
Finally
'RELEASE ALLOACTED RESOURCES
System.Windows.Forms.Cursor.Current =
System.Windows.Forms.Cursors.Default
xlApp = Nothing
End Try
End Sub

Private Sub txtBookName1_TextChanged(ByVal sender As System.Object, ByVal


e As System.EventArgs) Handles txtBookName1.TextChanged

Project by: Kuldeep Singh | 1053 Page 89


Library Management System

Try
con = New SqlConnection(cs)
con.Open()
cmd = New SqlCommand("SELECT TransactionID as [Transaction ID],
IssueDate as [Issue Date], DueDate as [Due Date], Book.AccessionNo as [Accession
No],BookTitle as [Book Title],Author,Subject,ISBN,Edition,Student.StudentID as
[Student ID],StudentName as [Student Name],Course,Student.Department, Status
from Book,BookIssue_Student,Student where
Book.AccessionNo=BookIssue_Student.AccessionNo and
BookIssue_Student.StudentID=Student.StudentID and DueDate Between '" &
DateTimePicker2.Text & "' and '" & DateTimePicker1.Text & "' and BookTitle like '"
& txtBookName1.Text & "%' order by DueDate desc ", con)
Dim myDA As SqlDataAdapter = New SqlDataAdapter(cmd)
Dim myDataSet As DataSet = New DataSet()
myDA.Fill(myDataSet, "BookIssue_Student")
myDA.Fill(myDataSet, "Book")
myDA.Fill(myDataSet, "Student")
DataGridView1.DataSource =
myDataSet.Tables("BookIssue_Student").DefaultView
DataGridView1.DataSource = myDataSet.Tables("Book").DefaultView
DataGridView1.DataSource = myDataSet.Tables("Student").DefaultView
con.Close()
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
End Try
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button1.Click
Try
con = New SqlConnection(cs)
con.Open()
cmd = New SqlCommand("SELECT TransactionID as [Transaction ID],
IssueDate as [Issue Date], DueDate as [Due Date], Book.AccessionNo as [Accession
No],BookTitle as [Book Title],Author,Subject,ISBN,Edition,Student.StudentID as
[Student ID],StudentName as [Student Name],Course,Student.Department, Status
from Book,BookIssue_Student,Student where
Book.AccessionNo=BookIssue_Student.AccessionNo and
BookIssue_Student.StudentID=Student.StudentID and IssueDate Between '" &
DateTimePicker8.Text & "' and '" & DateTimePicker7.Text & "' order by IssueDate
desc ", con)
Dim myDA As SqlDataAdapter = New SqlDataAdapter(cmd)
Dim myDataSet As DataSet = New DataSet()
myDA.Fill(myDataSet, "BookIssue_Student")
myDA.Fill(myDataSet, "Book")
myDA.Fill(myDataSet, "Student")
DataGridView1.DataSource =
myDataSet.Tables("BookIssue_Student").DefaultView
DataGridView1.DataSource = myDataSet.Tables("Book").DefaultView

Project by: Kuldeep Singh | 1053 Page 90


Library Management System

DataGridView1.DataSource = myDataSet.Tables("Student").DefaultView
con.Close()
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
End Try
End Sub

Private Sub cmbStudentName_SelectedIndexChanged(ByVal sender As


System.Object, ByVal e As System.EventArgs) Handles
cmbStudentName.SelectedIndexChanged
Try
con = New SqlConnection(cs)
con.Open()
cmd = New SqlCommand("SELECT TransactionID as [Transaction ID],
IssueDate as [Issue Date], DueDate as [Due Date], Book.AccessionNo as [Accession
No],BookTitle as [Book Title],Author,Subject,ISBN,Edition,Student.StudentID as
[Student ID],StudentName as [Student Name],Course,Student.Department, Status
from Book,BookIssue_Student,Student where
Book.AccessionNo=BookIssue_Student.AccessionNo and
BookIssue_Student.StudentID=Student.StudentID and IssueDate Between '" &
DateTimePicker4.Text & "' and '" & DateTimePicker3.Text & "' and StudentName= '"
& cmbStudentName.Text & "' order by IssueDate desc ", con)
Dim myDA As SqlDataAdapter = New SqlDataAdapter(cmd)
Dim myDataSet As DataSet = New DataSet()
myDA.Fill(myDataSet, "BookIssue_Student")
myDA.Fill(myDataSet, "Book")
myDA.Fill(myDataSet, "Student")
DataGridView1.DataSource =
myDataSet.Tables("BookIssue_Student").DefaultView
DataGridView1.DataSource = myDataSet.Tables("Book").DefaultView
DataGridView1.DataSource = myDataSet.Tables("Student").DefaultView
con.Close()
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
End Try
End Sub

Private Sub cmbStudentName1_SelectedIndexChanged(ByVal sender As


System.Object, ByVal e As System.EventArgs) Handles
cmbStudentName1.SelectedIndexChanged
Try
con = New SqlConnection(cs)
con.Open()
cmd = New SqlCommand("SELECT TransactionID as [Transaction ID],
IssueDate as [Issue Date], DueDate as [Due Date], Book.AccessionNo as [Accession
No],BookTitle as [Book Title],Author,Subject,ISBN,Edition,Student.StudentID as
[Student ID],StudentName as [Student Name],Course,Student.Department, Status

Project by: Kuldeep Singh | 1053 Page 91


Library Management System

from Book,BookIssue_Student,Student where


Book.AccessionNo=BookIssue_Student.AccessionNo and
BookIssue_Student.StudentID=Student.StudentID and DueDate Between '" &
DateTimePicker6.Text & "' and '" & DateTimePicker5.Text & "' and StudentName= '"
& cmbStudentName1.Text & "' order by DueDate desc ", con)
Dim myDA As SqlDataAdapter = New SqlDataAdapter(cmd)
Dim myDataSet As DataSet = New DataSet()
myDA.Fill(myDataSet, "BookIssue_Student")
myDA.Fill(myDataSet, "Book")
myDA.Fill(myDataSet, "Student")
DataGridView1.DataSource =
myDataSet.Tables("BookIssue_Student").DefaultView
DataGridView1.DataSource = myDataSet.Tables("Book").DefaultView
DataGridView1.DataSource = myDataSet.Tables("Student").DefaultView
con.Close()
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
End Try
End Sub

Private Sub txtStudentName_TextChanged(ByVal sender As System.Object,


ByVal e As System.EventArgs) Handles txtStudentName.TextChanged
Try
con = New SqlConnection(cs)
con.Open()
cmd = New SqlCommand("SELECT TransactionID as [Transaction ID],
IssueDate as [Issue Date], DueDate as [Due Date], Book.AccessionNo as [Accession
No],BookTitle as [Book Title],Author,Subject,ISBN,Edition,Student.StudentID as
[Student ID],StudentName as [Student Name],Course,Student.Department, Status
from Book,BookIssue_Student,Student where
Book.AccessionNo=BookIssue_Student.AccessionNo and
BookIssue_Student.StudentID=Student.StudentID and StudentName like '" &
txtStudentName.Text & "%' order by Studentname ", con)
Dim myDA As SqlDataAdapter = New SqlDataAdapter(cmd)
Dim myDataSet As DataSet = New DataSet()
myDA.Fill(myDataSet, "BookIssue_Student")
myDA.Fill(myDataSet, "Book")
myDA.Fill(myDataSet, "Student")
DataGridView1.DataSource =
myDataSet.Tables("BookIssue_Student").DefaultView
DataGridView1.DataSource = myDataSet.Tables("Book").DefaultView
DataGridView1.DataSource = myDataSet.Tables("Student").DefaultView
con.Close()
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
End Try
End Sub

Project by: Kuldeep Singh | 1053 Page 92


Library Management System

Private Sub DataGridView1_RowPostPaint(ByVal sender As Object, ByVal e As


System.Windows.Forms.DataGridViewRowPostPaintEventArgs) Handles
DataGridView1.RowPostPaint
Dim strRowNumber As String = (e.RowIndex + 1).ToString()
Dim size As SizeF = e.Graphics.MeasureString(strRowNumber, Me.Font)
If DataGridView1.RowHeadersWidth < Convert.ToInt32((size.Width + 20))
Then
DataGridView1.RowHeadersWidth = Convert.ToInt32((size.Width + 20))
End If
Dim b As Brush = SystemBrushes.ControlText
e.Graphics.DrawString(strRowNumber, Me.Font, b, e.RowBounds.Location.X +
15, e.RowBounds.Location.Y + ((e.RowBounds.Height - size.Height) / 2))

End Sub

Private Sub dtpDateTo_Validating(ByVal sender As System.Object, ByVal e As


System.ComponentModel.CancelEventArgs) Handles dtpDateTo.Validating
If (dtpDateFrom.Value.Date) > (dtpDateTo.Value.Date) Then
MessageBox.Show("Invalid Selection", "Input Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
dtpDateTo.Focus()
End If
End Sub

Private Sub DateTimePicker1_Validating(ByVal sender As System.Object, ByVal


e As System.ComponentModel.CancelEventArgs) Handles
DateTimePicker1.Validating
If (DateTimePicker2.Value.Date) > (DateTimePicker1.Value.Date) Then
MessageBox.Show("Invalid Selection", "Input Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
DateTimePicker1.Focus()
End If
End Sub

Private Sub DateTimePicker7_Validating(ByVal sender As System.Object, ByVal


e As System.ComponentModel.CancelEventArgs) Handles
DateTimePicker7.Validating
If (DateTimePicker8.Value.Date) > (DateTimePicker7.Value.Date) Then
MessageBox.Show("Invalid Selection", "Input Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
DateTimePicker7.Focus()
End If
End Sub

Private Sub DateTimePicker3_Validating(ByVal sender As System.Object, ByVal


e As System.ComponentModel.CancelEventArgs) Handles
DateTimePicker3.Validating
If (DateTimePicker4.Value.Date) > (DateTimePicker3.Value.Date) Then

Project by: Kuldeep Singh | 1053 Page 93


Library Management System

MessageBox.Show("Invalid Selection", "Input Error",


MessageBoxButtons.OK, MessageBoxIcon.Error)
DateTimePicker3.Focus()
End If
End Sub

Private Sub DateTimePicker5_Validating(ByVal sender As System.Object, ByVal


e As System.ComponentModel.CancelEventArgs) Handles
DateTimePicker5.Validating
If (DateTimePicker6.Value.Date) > (DateTimePicker5.Value.Date) Then
MessageBox.Show("Invalid Selection", "Input Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
DateTimePicker5.Focus()
End If
End Sub
End Class

frmStudent.vb
Option Strict On
Imports System.Data.SqlClient
Imports System.IO
Imports System.Security.Cryptography
Imports System.Text

Public Class frmStudent


Dim rdr As SqlDataReader = Nothing
Dim dtable As DataTable
Dim con As SqlConnection = Nothing
Dim adp As SqlDataAdapter
Dim ds As DataSet
Dim cmd As SqlCommand = Nothing
Dim dt As New DataTable
Dim gender As String
Dim cs As String = "Data Source=.\SQLEXPRESS;Initial
Catalog=LibraryDatabase;Integrated Security=True"
Public Shared Function GetUniqueKey(ByVal maxSize As Integer) As String
Dim chars As Char() = New Char(61) {}
chars = "123456789".ToCharArray()
Dim data As Byte() = New Byte(0) {}
Dim crypto As New RNGCryptoServiceProvider()
crypto.GetNonZeroBytes(data)
data = New Byte(maxSize - 1) {}
crypto.GetNonZeroBytes(data)
Dim result As New StringBuilder(maxSize)
For Each b As Byte In data
result.Append(chars(b Mod (chars.Length)))
Next
Return result.ToString()
End Function
Sub fillCourse()

Project by: Kuldeep Singh | 1053 Page 94


Library Management System

Try
Dim CN As New SqlConnection(cs)
CN.Open()
adp = New SqlDataAdapter()
adp.SelectCommand = New SqlCommand("SELECT distinct
RTRIM(Coursename) FROM Course", CN)
ds = New DataSet("ds")
adp.Fill(ds)
dtable = ds.Tables(0)
cmbCourse.Items.Clear()
For Each drow As DataRow In dtable.Rows
cmbCourse.Items.Add(drow(0).ToString())
Next
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
End Try
End Sub
Sub fillDepartment()
Try
Dim CN As New SqlConnection(cs)
CN.Open()
adp = New SqlDataAdapter()
adp.SelectCommand = New SqlCommand("SELECT distinct
RTRIM(Departmentname) FROM Department", CN)
ds = New DataSet("ds")
adp.Fill(ds)
dtable = ds.Tables(0)
cmbDepartment.Items.Clear()
For Each drow As DataRow In dtable.Rows
cmbDepartment.Items.Add(drow(0).ToString())
Next
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
End Try
End Sub
Private Sub frmStudent_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
fillCourse()
fillDepartment()
End Sub

Private Sub Browse_Click_1(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Browse.Click
Try
With OpenFileDialog1
.Filter = ("Images |*.png; *.bmp; *.jpg;*.jpeg; *.gif;")
.FilterIndex = 4
End With

Project by: Kuldeep Singh | 1053 Page 95


Library Management System

'Clear the file name


OpenFileDialog1.FileName = ""
If OpenFileDialog1.ShowDialog() = DialogResult.OK Then
Picture.Image = Image.FromFile(OpenFileDialog1.FileName)
End If
Catch ex As Exception
MsgBox(ex.ToString())
End Try
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button1.Click
frmStudentRecord.Show()
frmStudentRecord.GetData()
frmStudentRecord.txtStudentName.Text = ""
frmStudentRecord.cmbCourse.Text = ""
frmStudentRecord.cmbCourse1.Text = ""
frmStudentRecord.cmbDepartment.Text = ""
frmStudentRecord.cmbDepartment1.Text = ""
frmStudentRecord.cmbSession.Text = ""
End Sub

Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles btnSave.Click
Try
If Len(Trim(txtStudentName.Text)) = 0 Then
MessageBox.Show("Please enter student name", "Input Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
txtStudentName.Focus()
Exit Sub
End If
If rbMale.Checked = False And rbFemale.Checked = False Then
MessageBox.Show("Please select gender", "Input Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
Exit Sub
End If
If Len(Trim(txtLastName.Text)) = 0 Then
MessageBox.Show("Please enter last name", "Input Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
txtLastName.Focus()
Exit Sub
End If
If Len(Trim(cmbCourse.Text)) = 0 Then
MessageBox.Show("Please select course", "Input Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
cmbCourse.Focus()
Exit Sub
End If
If Len(Trim(cmbDepartment.Text)) = 0 Then

Project by: Kuldeep Singh | 1053 Page 96


Library Management System

MessageBox.Show("Please select department", "Input Error",


MessageBoxButtons.OK, MessageBoxIcon.Error)
cmbDepartment.Focus()
Exit Sub
End If
If Len(Trim(txtRollNo.Text)) = 0 Then
MessageBox.Show("Please enter class roll no.", "Input Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
txtRollNo.Focus()
Exit Sub
End If
If Len(Trim(txtReceiptNo.Text)) = 0 Then
MessageBox.Show("Please enter receipt no.", "Input Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
txtReceiptNo.Focus()
Exit Sub
End If
If Len(Trim(txtTempAddress.Text)) = 0 Then
MessageBox.Show("Please enter temporary address", "Input Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
txtTempAddress.Focus()
Exit Sub
End If
If Len(Trim(txtPermanentAddress.Text)) = 0 Then
MessageBox.Show("Please enter permanent address", "Input Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
txtPermanentAddress.Focus()
Exit Sub
End If
If Len(Trim(txtMobileNo.Text)) = 0 Then
MessageBox.Show("Please enter mobile no.", "Input Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
txtMobileNo.Focus()
Exit Sub
End If
If rbMale.Checked = True Then
gender = rbMale.Text
End If
If rbFemale.Checked = True Then
gender = rbFemale.Text
End If
txtStudentID.Text = "S-" & GetUniqueKey(6)
con = New SqlConnection(cs)
con.Open()
Dim cb As String = "insert into Student(StudentID, StudentName, LastName,
Course, Department,stu_Session, ClassRollNo, CautionMoneyReceiptNo,
TemporaryAddress, PermanentAddress, DOB, PhoneNo, MobileNo, Email,
Photo,gender) VALUES('" & txtStudentID.Text & "','" & txtStudentName.Text & "','"
& txtLastName.Text & "','" & cmbCourse.Text & "','" & cmbDepartment.Text & "','"
& txtSession.Text & "','" & txtRollNo.Text & "','" & txtReceiptNo.Text & "','" &

Project by: Kuldeep Singh | 1053 Page 97


Library Management System

txtTempAddress.Text & "','" & txtPermanentAddress.Text & "','" & dtpDOB.Text &
"','" & txtPhoneNo.Text & "','" & txtMobileNo.Text & "','" & txtEmail.Text &
"',@image,'" & gender & "')"
cmd = New SqlCommand(cb)
cmd.Connection = con
Dim ms As New MemoryStream()
Dim bmpImage As New Bitmap(Picture.Image)
bmpImage.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg)
Dim data As Byte() = ms.GetBuffer()
Dim p As New SqlParameter("@image", SqlDbType.VarBinary)
p.Value = data
cmd.Parameters.Add(p)
cmd.ExecuteNonQuery()
con.Close()
con = New SqlConnection(cs)
con.Open()
Dim cb1 As String = "insert into StudentList(StudentID) VALUES('" &
txtStudentID.Text & "')"
cmd = New SqlCommand(cb1)
cmd.Connection = con
cmd.ExecuteNonQuery()
con.Close()
con = New SqlConnection(cs)
con.Open()
Dim cb2 As String = "insert into Cards_student(StudentID,Status) VALUES('"
& txtStudentID.Text & "','No')"
cmd = New SqlCommand(cb2)
cmd.Connection = con
cmd.ExecuteNonQuery()
con.Close()
con = New SqlConnection(cs)
con.Open()
Dim cb3 As String = "insert into NoDues_Student(StudentID,Status)
VALUES('" & txtStudentID.Text & "','No')"
cmd = New SqlCommand(cb3)
cmd.Connection = con
cmd.ExecuteNonQuery()
con.Close()
MessageBox.Show("Successfully saved", " Student Record",
MessageBoxButtons.OK, MessageBoxIcon.Information)
btnSave.Enabled = False
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
End Try
End Sub

Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles btnDelete.Click
Try

Project by: Kuldeep Singh | 1053 Page 98


Library Management System

If MessageBox.Show("Do you really want to delete this record?",


"Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) =
System.Windows.Forms.DialogResult.Yes Then
DeleteRecord()
End If
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
End Try
End Sub
Public Sub DeleteRecord()
Try
Dim RowsAffected As Integer = 0
con = New SqlConnection(cs)
con.Open()
Dim cq As String = "delete from Student where StudentID = '" &
txtStudentID.Text & "'"
cmd = New SqlCommand(cq)
cmd.Connection = con
RowsAffected = cmd.ExecuteNonQuery()
If RowsAffected > 0 Then
MessageBox.Show("Successfully deleted", "Record",
MessageBoxButtons.OK, MessageBoxIcon.Information)
Reset()
Else
MessageBox.Show("No record found", "Sorry", MessageBoxButtons.OK,
MessageBoxIcon.Information)
Reset()
If con.State = ConnectionState.Open Then
con.Close()
End If
con.Close()
End If
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
End Try
End Sub
Sub Reset()
txtStudentID.Text = ""
txtContactNo.Text = ""
txtEmail.Text = ""
txtLastName.Text = ""
txtMobileNo.Text = ""
txtPermanentAddress.Text = ""
txtPhoneNo.Text = ""
txtReceiptNo.Text = ""
txtRollNo.Text = ""
txtSession.Text = ""
txtStudentName.Text = ""

Project by: Kuldeep Singh | 1053 Page 99


Library Management System

txtTempAddress.Text = ""
txtPermanentAddress.Text = ""
cmbCourse.Text = ""
dtpDOB.Text = CType(Today, String)
cmbDepartment.Text = ""
Picture.Image = My.Resources.photo
rbMale.Checked = False
rbFemale.Checked = False
btnSave.Enabled = True
btnDelete.Enabled = False
btnUpdate_record.Enabled = False
txtStudentName.Focus()
End Sub

Private Sub btnNewRecord_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles btnNewRecord.Click
Reset()
End Sub

Private Sub btnUpdate_record_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles btnUpdate_record.Click
Try
If Len(Trim(txtStudentName.Text)) = 0 Then
MessageBox.Show("Please enter student name", "Input Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
txtStudentName.Focus()
Exit Sub
End If
If rbMale.Checked = False And rbFemale.Checked = False Then
MessageBox.Show("Please select gender", "Input Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
Exit Sub
End If
If Len(Trim(txtLastName.Text)) = 0 Then
MessageBox.Show("Please enter last name", "Input Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
txtLastName.Focus()
Exit Sub
End If
If Len(Trim(cmbCourse.Text)) = 0 Then
MessageBox.Show("Please select course", "Input Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
cmbCourse.Focus()
Exit Sub
End If
If Len(Trim(cmbDepartment.Text)) = 0 Then
MessageBox.Show("Please select department", "Input Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
cmbDepartment.Focus()
Exit Sub

Project by: Kuldeep Singh | 1053 Page 100


Library Management System

End If
If Len(Trim(txtRollNo.Text)) = 0 Then
MessageBox.Show("Please enter class roll no.", "Input Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
txtRollNo.Focus()
Exit Sub
End If
If Len(Trim(txtReceiptNo.Text)) = 0 Then
MessageBox.Show("Please enter receipt no.", "Input Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
txtReceiptNo.Focus()
Exit Sub
End If
If Len(Trim(txtTempAddress.Text)) = 0 Then
MessageBox.Show("Please enter temporary address", "Input Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
txtTempAddress.Focus()
Exit Sub
End If
If Len(Trim(txtPermanentAddress.Text)) = 0 Then
MessageBox.Show("Please enter permanent address", "Input Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
txtPermanentAddress.Focus()
Exit Sub
End If
If Len(Trim(txtMobileNo.Text)) = 0 Then
MessageBox.Show("Please enter mobile no.", "Input Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
txtMobileNo.Focus()
Exit Sub
End If

If rbMale.Checked = True Then


gender = rbMale.Text
End If
If rbFemale.Checked = True Then
gender = rbFemale.Text
End If
con = New SqlConnection(cs)
con.Open()
Dim cb As String = "update Student set Studentname='" &
txtStudentName.Text & "',Lastname='" & txtLastName.Text & "',Course='" &
cmbCourse.Text & "',Department='" & cmbDepartment.Text & "',Stu_Session='" &
txtSession.Text & "',ClassRollNo='" & txtRollNo.Text &
"',CautionMoneyReceiptNo='" & txtReceiptNo.Text & "',TemporaryAddress='" &
txtTempAddress.Text & "',PermanentAddress='" & txtPermanentAddress.Text &
"',DOB='" & dtpDOB.Text & "',PhoneNo='" & txtPhoneNo.Text & "',MobileNo='" &
txtMobileNo.Text & "',Email='" & txtEmail.Text & "',Photo=@image,Gender='" &
gender & "' where StudentID= '" & txtStudentID.Text & "'"
cmd = New SqlCommand(cb)

Project by: Kuldeep Singh | 1053 Page 101


Library Management System

cmd.Connection = con
Dim ms As New MemoryStream()
Dim bmpImage As New Bitmap(Picture.Image)
bmpImage.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg)
Dim data As Byte() = ms.GetBuffer()
Dim p As New SqlParameter("@image", SqlDbType.VarBinary)
p.Value = data
cmd.Parameters.Add(p)
cmd.ExecuteNonQuery()
con.Close()
MessageBox.Show("Successfully updated", " Student Record",
MessageBoxButtons.OK, MessageBoxIcon.Information)
btnUpdate_record.Enabled = False
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
End Try
End Sub

Private Sub txtEmail_Validating(ByVal sender As System.Object, ByVal e As


System.ComponentModel.CancelEventArgs) Handles txtEmail.Validating
Dim rEMail As New System.Text.RegularExpressions.Regex("^[a-zA-Z][\w\.-
]{2,28}[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-
Z]$")
If txtEmail.Text.Length > 0 Then
If Not rEMail.IsMatch(txtEmail.Text) Then
MessageBox.Show("invalid email address", "Error",
MessageBoxButtons.OK, MessageBoxIcon.[Error])
txtEmail.SelectAll()
e.Cancel = True
End If
End If
End Sub

Private Sub txtMobileNo_Validating(ByVal sender As System.Object, ByVal e As


System.ComponentModel.CancelEventArgs) Handles txtMobileNo.Validating
If (txtMobileNo.TextLength > 10) Then
MessageBox.Show("Only 10 digits are allowed", "Input Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
txtMobileNo.Focus()
ElseIf (txtMobileNo.TextLength < 10) Then
MessageBox.Show("Contact No should be 10 Numbers", "Input Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
txtMboileNo.Focus()
End Sub

Private Sub txtMobileNo_KeyPress(ByVal sender As System.Object, ByVal e As


System.Windows.Forms.KeyPressEventArgs) Handles txtMobileNo.KeyPress
If (e.KeyChar < Chr(48) Or e.KeyChar > Chr(57)) And e.KeyChar <> Chr(8)
Then

Project by: Kuldeep Singh | 1053 Page 102


Library Management System

e.Handled = True
End If
End Sub

Private Sub txtPhoneNo_KeyPress(ByVal sender As System.Object, ByVal e As


System.Windows.Forms.KeyPressEventArgs) Handles txtPhoneNo.KeyPress
If (e.KeyChar < Chr(48) Or e.KeyChar > Chr(57)) And e.KeyChar <> Chr(8)
Then
e.Handled = True
End If
End Sub
End Class

frmStudentRecord.vb
Imports System.Data.SqlClient
Imports System.IO
Imports Excel = Microsoft.Office.Interop.Excel

Public Class frmStudentRecord


Dim rdr As SqlDataReader
Dim dtable As DataTable
Dim con As SqlConnection
Dim adp As SqlDataAdapter
Dim ds As DataSet
Dim cmd As SqlCommand
Dim dt As New DataTable
Dim cs As String = "Data Source=.\SQLEXPRESS;Initial
Catalog=LibraryDatabase;Integrated Security=True"

Private Sub frmStudentRecord_Load(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles MyBase.Load
fillCourse()
fillDepartment()
fillSession()
GetData()
End Sub
Sub fillSession()
Try
Dim CN As New SqlConnection(cs)
CN.Open()
adp = New SqlDataAdapter()
adp.SelectCommand = New SqlCommand("SELECT distinct (stu_session)
FROM Student", CN)
ds = New DataSet("ds")
adp.Fill(ds)
dtable = ds.Tables(0)
cmbSession.Items.Clear()
For Each drow As DataRow In dtable.Rows
cmbSession.Items.Add(drow(0).ToString())

Project by: Kuldeep Singh | 1053 Page 103


Library Management System

Next
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
End Try
End Sub
Sub fillCourse()
Try
Dim CN As New SqlConnection(cs)
CN.Open()
adp = New SqlDataAdapter()
adp.SelectCommand = New SqlCommand("SELECT distinct RTRIM(Course)
FROM Student", CN)
ds = New DataSet("ds")
adp.Fill(ds)
dtable = ds.Tables(0)
cmbCourse.Items.Clear()
cmbCourse1.Items.Clear()
For Each drow As DataRow In dtable.Rows
cmbCourse.Items.Add(drow(0).ToString())
cmbCourse1.Items.Add(drow(0).ToString())
Next
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
End Try
End Sub
Sub fillDepartment()
Try
Dim CN As New SqlConnection(cs)
CN.Open()
adp = New SqlDataAdapter()
adp.SelectCommand = New SqlCommand("SELECT distinct
RTRIM(Department) FROM Student", CN)
ds = New DataSet("ds")
adp.Fill(ds)
dtable = ds.Tables(0)
cmbDepartment.Items.Clear()
cmbDepartment1.Items.Clear()
For Each drow As DataRow In dtable.Rows
cmbDepartment.Items.Add(drow(0).ToString())
cmbDepartment1.Items.Add(drow(0).ToString())
Next
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
End Try
End Sub

Project by: Kuldeep Singh | 1053 Page 104


Library Management System

Private Sub DataGridView1_RowHeaderMouseClick(ByVal sender As Object,


ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles
DataGridView1.RowHeaderMouseClick
Try
Dim dr As DataGridViewRow = DataGridView1.SelectedRows(0)
Me.Hide()
frmStudent.Show()
frmStudent.txtStudentID.Text = dr.Cells(0).Value.ToString()
frmStudent.txtStudentName.Text = dr.Cells(1).Value.ToString()
If (dr.Cells(2).Value.ToString() = "Male") Then
frmStudent.rbMale.Checked = True
End If
If (dr.Cells(2).Value.ToString() = "Female") Then
frmStudent.rbFemale.Checked = True
End If
frmStudent.txtLastName.Text = dr.Cells(3).Value.ToString()
frmStudent.cmbCourse.Text = dr.Cells(4).Value.ToString()
frmStudent.cmbDepartment.Text = dr.Cells(5).Value.ToString()
frmStudent.txtSession.Text = dr.Cells(6).Value.ToString()
frmStudent.txtRollNo.Text = dr.Cells(7).Value.ToString()
frmStudent.txtReceiptNo.Text = dr.Cells(8).Value.ToString()
frmStudent.txtTempAddress.Text = dr.Cells(9).Value.ToString()
frmStudent.txtPermanentAddress.Text = dr.Cells(10).Value.ToString()
frmStudent.dtpDOB.Text = dr.Cells(11).Value.ToString()
frmStudent.txtPhoneNo.Text = dr.Cells(12).Value.ToString()
frmStudent.txtMobileNo.Text = dr.Cells(13).Value.ToString()
frmStudent.txtEmail.Text = dr.Cells(14).Value.ToString()
Dim data As Byte() = DirectCast(dr.Cells(15).Value, Byte())
Dim ms As New MemoryStream(data)
frmStudent.Picture.Image = Image.FromStream(ms)
frmStudent.btnUpdate_record.Enabled = True
frmStudent.btnDelete.Enabled = True
frmStudent.btnSave.Enabled = False
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
End Try
End Sub

Private Sub DataGridView1_RowPostPaint(ByVal sender As Object, ByVal e As


System.Windows.Forms.DataGridViewRowPostPaintEventArgs) Handles
DataGridView1.RowPostPaint
Dim strRowNumber As String = (e.RowIndex + 1).ToString()
Dim size As SizeF = e.Graphics.MeasureString(strRowNumber, Me.Font)
If DataGridView1.RowHeadersWidth < Convert.ToInt32((size.Width + 20))
Then
DataGridView1.RowHeadersWidth = Convert.ToInt32((size.Width + 20))
End If
Dim b As Brush = SystemBrushes.ControlText

Project by: Kuldeep Singh | 1053 Page 105


Library Management System

e.Graphics.DrawString(strRowNumber, Me.Font, b, e.RowBounds.Location.X +


15, e.RowBounds.Location.Y + ((e.RowBounds.Height - size.Height) / 2))
End Sub
Public Sub GetData()
Try
con = New SqlConnection(cs)
con.Open()
cmd = New SqlCommand("SELECT StudentID as [Student ID], StudentName
as [Student Name],Gender, LastName as [Last Name], Course, Department,
Stu_Session as [Session], ClassRollNo as [Class Roll No], CautionMoneyReceiptNo
as [Caution Money Receipt No], TemporaryAddress as [Temporary Address],
PermanentAddress as [Permanent Address], DOB, PhoneNo as [Phone No],
MobileNo as [Mobile No], Email as [Email ID], Photo from Student order by
StudentName", con)
Dim myDA As SqlDataAdapter = New SqlDataAdapter(cmd)
Dim myDataSet As DataSet = New DataSet()
myDA.Fill(myDataSet, "Student")
DataGridView1.DataSource = myDataSet.Tables("Student").DefaultView
con.Close()
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
End Try
End Sub

Private Sub txtStudentName_TextChanged(ByVal sender As System.Object,


ByVal e As System.EventArgs) Handles txtStudentName.TextChanged
Try
con = New SqlConnection(cs)
con.Open()
cmd = New SqlCommand("SELECT StudentID as [Student ID], StudentName
as [Student Name],Gender, LastName as [Last Name], Course, Department,
Stu_Session as [Session], ClassRollNo as [Class Roll No], CautionMoneyReceiptNo
as [Caution Money Receipt No], TemporaryAddress as [Temporary Address],
PermanentAddress as [Permanent Address], DOB, PhoneNo as [Phone No],
MobileNo as [Mobile No], Email as [Email ID], Photo from Student where
studentname like '" & txtStudentName.Text & "%' order by StudentName", con)
Dim myDA As SqlDataAdapter = New SqlDataAdapter(cmd)
Dim myDataSet As DataSet = New DataSet()
myDA.Fill(myDataSet, "Student")
DataGridView1.DataSource = myDataSet.Tables("Student").DefaultView
con.Close()
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
End Try
End Sub

Private Sub cmbCourse_SelectedIndexChanged(ByVal sender As System.Object,


ByVal e As System.EventArgs) Handles cmbCourse.SelectedIndexChanged

Project by: Kuldeep Singh | 1053 Page 106


Library Management System

Try
con = New SqlConnection(cs)
con.Open()
cmd = New SqlCommand("SELECT StudentID as [Student ID], StudentName
as [Student Name],Gender, LastName as [Last Name], Course, Department,
Stu_Session as [Session], ClassRollNo as [Class Roll No], CautionMoneyReceiptNo
as [Caution Money Receipt No], TemporaryAddress as [Temporary Address],
PermanentAddress as [Permanent Address], DOB, PhoneNo as [Phone No],
MobileNo as [Mobile No], Email as [Email ID], Photo from Student where Course= '"
& cmbCourse.Text & "' order by StudentName", con)
Dim myDA As SqlDataAdapter = New SqlDataAdapter(cmd)
Dim myDataSet As DataSet = New DataSet()
myDA.Fill(myDataSet, "Student")
DataGridView1.DataSource = myDataSet.Tables("Student").DefaultView
con.Close()
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
End Try
End Sub

Private Sub cmbDepartment_SelectedIndexChanged(ByVal sender As


System.Object, ByVal e As System.EventArgs) Handles
cmbDepartment.SelectedIndexChanged
Try
con = New SqlConnection(cs)
con.Open()
cmd = New SqlCommand("SELECT StudentID as [Student ID], StudentName
as [Student Name],Gender, LastName as [Last Name], Course, Department,
Stu_Session as [Session], ClassRollNo as [Class Roll No], CautionMoneyReceiptNo
as [Caution Money Receipt No], TemporaryAddress as [Temporary Address],
PermanentAddress as [Permanent Address], DOB, PhoneNo as [Phone No],
MobileNo as [Mobile No], Email as [Email ID], Photo from Student where
department= '" & cmbDepartment.Text & "' order by StudentName", con)
Dim myDA As SqlDataAdapter = New SqlDataAdapter(cmd)
Dim myDataSet As DataSet = New DataSet()
myDA.Fill(myDataSet, "Student")
DataGridView1.DataSource = myDataSet.Tables("Student").DefaultView
con.Close()
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
End Try
End Sub

Private Sub btnReset_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles btnReset.Click
txtStudentName.Text = ""
cmbCourse.Text = ""
cmbDepartment.Text = ""

Project by: Kuldeep Singh | 1053 Page 107


Library Management System

cmbCourse1.Text = ""
cmbDepartment1.Text = ""
cmbSession.Text = ""
GetData()
End Sub

Private Sub btnExportExcel_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles btnExportExcel.Click
If DataGridView1.RowCount = Nothing Then
MessageBox.Show("Sorry nothing to export into excel sheet.." & vbCrLf &
"Please retrieve data in datagridview", "", MessageBoxButtons.OK,
MessageBoxIcon.Error)
Exit Sub
End If
Dim rowsTotal, colsTotal As Short
Dim I, j, iC As Short
System.Windows.Forms.Cursor.Current =
System.Windows.Forms.Cursors.WaitCursor
Dim xlApp As New Excel.Application
Try
Dim excelBook As Excel.Workbook = xlApp.Workbooks.Add
Dim excelWorksheet As Excel.Worksheet =
CType(excelBook.Worksheets(1), Excel.Worksheet)
xlApp.Visible = True

rowsTotal = DataGridView1.RowCount - 1
colsTotal = DataGridView1.Columns.Count - 1
With excelWorksheet
.Cells.Select()
.Cells.Delete()
For iC = 0 To colsTotal - 1
.Cells(1, iC + 1).Value = DataGridView1.Columns(iC).HeaderText
Next
For I = 0 To rowsTotal - 1
For j = 0 To colsTotal - 1
.Cells(I + 2, j + 1).value = DataGridView1.Rows(I).Cells(j).Value
Next j
Next I
.Rows("1:1").Font.FontStyle = "Bold"
.Rows("1:1").Font.Size = 12

.Cells.Columns.AutoFit()
.Cells.Select()
.Cells.EntireColumn.AutoFit()
.Cells(1, 1).Select()
End With
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
Finally

Project by: Kuldeep Singh | 1053 Page 108


Library Management System

'RELEASE ALLOACTED RESOURCES


System.Windows.Forms.Cursor.Current =
System.Windows.Forms.Cursors.Default
xlApp = Nothing
End Try
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button1.Click
Try
If Len(Trim(cmbSession.Text)) = 0 Then
MessageBox.Show("Please select session", "Input Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
cmbSession.Focus()
Exit Sub
End If
If Len(Trim(cmbCourse1.Text)) = 0 Then
MessageBox.Show("Please select course", "Input Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
cmbCourse1.Focus()
Exit Sub
End If
If Len(Trim(cmbDepartment1.Text)) = 0 Then
MessageBox.Show("Please select department", "Input Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
cmbDepartment1.Focus()
Exit Sub
End If
con = New SqlConnection(cs)
con.Open()
cmd = New SqlCommand("SELECT StudentID as [Student ID], StudentName
as [Student Name],Gender, LastName as [Last Name], Course, Department,
Stu_Session as [Session], ClassRollNo as [Class Roll No], CautionMoneyReceiptNo
as [Caution Money Receipt No], TemporaryAddress as [Temporary Address],
PermanentAddress as [Permanent Address], DOB, PhoneNo as [Phone No],
MobileNo as [Mobile No], Email as [Email ID], Photo from Student where
department= '" & cmbDepartment1.Text & "' and Course='" & cmbCourse1.Text & "'
and Stu_Session='" & cmbSession.Text & "' order by StudentName", con)
Dim myDA As SqlDataAdapter = New SqlDataAdapter(cmd)
Dim myDataSet As DataSet = New DataSet()
myDA.Fill(myDataSet, "Student")
DataGridView1.DataSource = myDataSet.Tables("Student").DefaultView
con.Close()
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
End Try
End Sub
End Class

Project by: Kuldeep Singh | 1053 Page 109


Library Management System

frmStaff.vb
Option Strict On
Imports System.Data.SqlClient
Imports System.IO
Imports System.Security.Cryptography
Imports System.Text

Public Class frmStaff


Dim rdr As SqlDataReader = Nothing
Dim dtable As DataTable
Dim con As SqlConnection = Nothing
Dim adp As SqlDataAdapter
Dim ds As DataSet
Dim cmd As SqlCommand = Nothing
Dim dt As New DataTable
Dim gender As String
Dim cs As String = "Data Source=.\SQLEXPRESS;Initial
Catalog=LibraryDatabase;Integrated Security=True"
Public Shared Function GetUniqueKey(ByVal maxSize As Integer) As String
Dim chars As Char() = New Char(61) {}
chars = "123456789".ToCharArray()
Dim data As Byte() = New Byte(0) {}
Dim crypto As New RNGCryptoServiceProvider()
crypto.GetNonZeroBytes(data)
data = New Byte(maxSize - 1) {}
crypto.GetNonZeroBytes(data)
Dim result As New StringBuilder(maxSize)
For Each b As Byte In data
result.Append(chars(b Mod (chars.Length)))
Next
Return result.ToString()
End Function
Sub fillDepartment()
Try
Dim CN As New SqlConnection(cs)
CN.Open()
adp = New SqlDataAdapter()
adp.SelectCommand = New SqlCommand("SELECT distinct
RTRIM(Departmentname) FROM Department", CN)
ds = New DataSet("ds")
adp.Fill(ds)
dtable = ds.Tables(0)
cmbDepartment.Items.Clear()
For Each drow As DataRow In dtable.Rows
cmbDepartment.Items.Add(drow(0).ToString())
Next
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
End Try

Project by: Kuldeep Singh | 1053 Page 110


Library Management System

End Sub
Private Sub frmStudent_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
fillDepartment()
End Sub

Private Sub Browse_Click_1(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Browse.Click
Try
With OpenFileDialog1
.Filter = ("Images |*.png; *.bmp; *.jpg;*.jpeg; *.gif;")
.FilterIndex = 4
End With
'Clear the file name
OpenFileDialog1.FileName = ""
If OpenFileDialog1.ShowDialog() = DialogResult.OK Then
Picture.Image = Image.FromFile(OpenFileDialog1.FileName)
End If
Catch ex As Exception
MsgBox(ex.ToString())
End Try
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button1.Click
frmStaffRecord.Show()
frmStaffRecord.GetData()
frmStaffRecord.txtStaffName.Text = ""
frmStaffRecord.cmbDepartment.Text = ""
frmStaffRecord.dtpDateFrom.Text = CType(Today, String)
frmStaffRecord.dtpDateTo.Text = CType(Today, String)
End Sub

Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles btnSave.Click
Try
If Len(Trim(txtStaffName.Text)) = 0 Then
MessageBox.Show("Please enter staff name", "Input Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
txtStaffName.Focus()
Exit Sub
End If
If rbMale.Checked = False And rbFemale.Checked = False Then
MessageBox.Show("Please select gender", "Input Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
Exit Sub
Exit Sub
End If
If Len(Trim(txtLastName.Text)) = 0 Then

Project by: Kuldeep Singh | 1053 Page 111


Library Management System

MessageBox.Show("Please enter Last name", "Input Error",


MessageBoxButtons.OK, MessageBoxIcon.Error)
txtLastName.Focus()
Exit Sub
End If
If Len(Trim(cmbDepartment.Text)) = 0 Then
MessageBox.Show("Please select department", "Input Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
cmbDepartment.Focus()
Exit Sub
End If
If Len(Trim(txtTempAddress.Text)) = 0 Then
MessageBox.Show("Please enter temporary address", "Input Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
txtTempAddress.Focus()
Exit Sub
End If
If Len(Trim(txtPermanentAddress.Text)) = 0 Then
MessageBox.Show("Please enter permanent address", "Input Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
txtPermanentAddress.Focus()
Exit Sub
End If
If Len(Trim(txtMobileNo.Text)) = 0 Then
MessageBox.Show("Please enter mobile no.", "Input Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
txtMobileNo.Focus()
Exit Sub
End If
If rbMale.Checked = True Then
gender = rbMale.Text
End If
If rbFemale.Checked = True Then
gender = rbFemale.Text
End If
txtStaffID.Text = "F-" & GetUniqueKey(6)
con = New SqlConnection(cs)
con.Open()
Dim cb As String = "insert into Staff(StaffID, StaffName, LastName,
dateofjoining, Department, TemporaryAddress, PermanentAddress, DOB, PhoneNo,
MobileNo, Email, Photo,Gender) VALUES('" & txtStaffID.Text & "','" &
txtStaffName.Text & "','" & txtLastName.Text & "','" & dtpDateOfJoining.Text &
"','" & cmbDepartment.Text & "','" & txtTempAddress.Text & "','" &
txtPermanentAddress.Text & "','" & dtpDOB.Text & "','" & txtPhoneNo.Text & "','"
& txtMobileNo.Text & "','" & txtEmail.Text & "',@image,'" & gender & "')"
cmd = New SqlCommand(cb)
cmd.Connection = con
Dim ms As New MemoryStream()
Dim bmpImage As New Bitmap(Picture.Image)
bmpImage.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg)

Project by: Kuldeep Singh | 1053 Page 112


Library Management System

Dim data As Byte() = ms.GetBuffer()


Dim p As New SqlParameter("@image", SqlDbType.VarBinary)
p.Value = data
cmd.Parameters.Add(p)
cmd.ExecuteNonQuery()
con.Close()
con = New SqlConnection(cs)
con.Open()
Dim cb2 As String = "insert into Cards_staff(StaffID,Status) VALUES('" &
txtStaffID.Text & "','No')"
cmd = New SqlCommand(cb2)
cmd.Connection = con
cmd.ExecuteNonQuery()
con.Close()
con = New SqlConnection(cs)
con.Open()
Dim cb3 As String = "insert into NoDues_staff(StaffID,Status) VALUES('" &
txtStaffID.Text & "','No')"
cmd = New SqlCommand(cb3)
cmd.Connection = con
cmd.ExecuteNonQuery()
con.Close()
MessageBox.Show("Successfully saved", " Staff Record",
MessageBoxButtons.OK, MessageBoxIcon.Information)
btnSave.Enabled = False
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
End Try
End Sub

Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles btnDelete.Click
Try
If MessageBox.Show("Do you really want to delete this record?",
"Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) =
System.Windows.Forms.DialogResult.Yes Then
DeleteRecord()
End If
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
End Try
End Sub
Public Sub DeleteRecord()
Try
Dim RowsAffected As Integer = 0
con = New SqlConnection(cs)
con.Open()

Project by: Kuldeep Singh | 1053 Page 113


Library Management System

Dim cq As String = "delete from Staff where StaffID = '" & txtStaffID.Text &
"'"
cmd = New SqlCommand(cq)
cmd.Connection = con
RowsAffected = cmd.ExecuteNonQuery()
If RowsAffected > 0 Then
MessageBox.Show("Successfully deleted", "Record",
MessageBoxButtons.OK, MessageBoxIcon.Information)
Reset()
Else
MessageBox.Show("No record found", "Sorry", MessageBoxButtons.OK,
MessageBoxIcon.Information)
Reset()
If con.State = ConnectionState.Open Then
con.Close()
End If
con.Close()
End If
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
End Try
End Sub
Sub Reset()
txtStaffID.Text = ""
txtContactNo.Text = ""
txtEmail.Text = ""
txtLastName.Text = ""
txtMobileNo.Text = ""
txtPermanentAddress.Text = ""
txtPhoneNo.Text = ""
txtStaffName.Text = ""
txtTempAddress.Text = ""
txtPermanentAddress.Text = ""
dtpDateOfJoining.Text = CType(Today, String)
dtpDOB.Text = CType(Today, String)
cmbDepartment.Text = ""
Picture.Image = My.Resources.photo
rbMale.Checked = False
rbFemale.Checked = False
btnSave.Enabled = True
btnDelete.Enabled = False
btnUpdate_record.Enabled = False
txtStaffName.Focus()
End Sub

Private Sub btnNewRecord_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles btnNewRecord.Click
Reset()
End Sub

Project by: Kuldeep Singh | 1053 Page 114


Library Management System

Private Sub btnUpdate_record_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles btnUpdate_record.Click
Try
If Len(Trim(txtStaffName.Text)) = 0 Then
MessageBox.Show("Please enter staff name", "Input Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
txtStaffName.Focus()
Exit Sub
End If
If rbMale.Checked = False And rbFemale.Checked = False Then
MessageBox.Show("Please select gender", "Input Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
Exit Sub
End If
If Len(Trim(txtLastName.Text)) = 0 Then
MessageBox.Show("Please enter Last name", "Input Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
txtLastName.Focus()
Exit Sub
End If
If Len(Trim(cmbDepartment.Text)) = 0 Then
MessageBox.Show("Please select department", "Input Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
cmbDepartment.Focus()
Exit Sub
End If
If Len(Trim(txtTempAddress.Text)) = 0 Then
MessageBox.Show("Please enter temporary address", "Input Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
txtTempAddress.Focus()
Exit Sub
End If
If Len(Trim(txtPermanentAddress.Text)) = 0 Then
MessageBox.Show("Please enter permanent address", "Input Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
txtPermanentAddress.Focus()
Exit Sub
End If
If Len(Trim(txtMobileNo.Text)) = 0 Then
MessageBox.Show("Please enter mobile no.", "Input Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
txtMobileNo.Focus()
Exit Sub
End If

If rbMale.Checked = True Then


gender = rbMale.Text
End If
If rbFemale.Checked = True Then

Project by: Kuldeep Singh | 1053 Page 115


Library Management System

gender = rbFemale.Text
End If
con = New SqlConnection(cs)
con.Open()
Dim cb As String = "update Staff set Staffname='" & txtStaffName.Text &
"',LastName='" & txtLastName.Text & "',DateOfJoining='" & dtpDateOfJoining.Text
& "',Department='" & cmbDepartment.Text & "',TemporaryAddress='" &
txtTempAddress.Text & "',PermanentAddress='" & txtPermanentAddress.Text &
"',DOB='" & dtpDOB.Text & "',PhoneNo='" & txtPhoneNo.Text & "',MobileNo='" &
txtMobileNo.Text & "',Email='" & txtEmail.Text & "',Photo=@image,Gender='" &
gender & "' where StaffID= '" & txtStaffID.Text & "'"
cmd = New SqlCommand(cb)
cmd.Connection = con
Dim ms As New MemoryStream()
Dim bmpImage As New Bitmap(Picture.Image)
bmpImage.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg)
Dim data As Byte() = ms.GetBuffer()
Dim p As New SqlParameter("@image", SqlDbType.VarBinary)
p.Value = data
cmd.Parameters.Add(p)
cmd.ExecuteNonQuery()
con.Close()
MessageBox.Show("Successfully updated", " Staff Record",
MessageBoxButtons.OK, MessageBoxIcon.Information)
btnUpdate_record.Enabled = False
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
End Try
End Sub

Private Sub txtEmail_Validating(ByVal sender As System.Object, ByVal e As


System.ComponentModel.CancelEventArgs) Handles txtEmail.Validating
Dim rEMail As New System.Text.RegularExpressions.Regex("^[a-zA-Z][\w\.-
]{2,28}[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-
Z]$")
If txtEmail.Text.Length > 0 Then
If Not rEMail.IsMatch(txtEmail.Text) Then
MessageBox.Show("invalid email address", "Error",
MessageBoxButtons.OK, MessageBoxIcon.[Error])
txtEmail.SelectAll()
e.Cancel = True
End If
End If
End Sub

Private Sub txtMobileNo_Validating(ByVal sender As System.Object, ByVal e As


System.ComponentModel.CancelEventArgs) Handles txtMobileNo.Validating
If (txtMobileNo.TextLength > 10) Then

Project by: Kuldeep Singh | 1053 Page 116


Library Management System

MessageBox.Show("Only 10 digits are allowed", "Input Error",


MessageBoxButtons.OK, MessageBoxIcon.Error)
txtMobileNo.Focus()
ElseIf (txtMobileNo.TextLength < 10) Then
MessageBox.Show("Contact No should be 10 Numbers", "Input Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
txtMobileNo.Focus()
End If
End Sub

Private Sub txtMobileNo_KeyPress(ByVal sender As System.Object, ByVal e As


System.Windows.Forms.KeyPressEventArgs) Handles txtMobileNo.KeyPress
If (e.KeyChar < Chr(48) Or e.KeyChar > Chr(57)) And e.KeyChar <> Chr(8)
Then
e.Handled = True
End If
End Sub

Private Sub txtPhoneNo_KeyPress(ByVal sender As System.Object, ByVal e As


System.Windows.Forms.KeyPressEventArgs) Handles txtPhoneNo.KeyPress
If (e.KeyChar < Chr(48) Or e.KeyChar > Chr(57)) And e.KeyChar <> Chr(8)
Then
e.Handled = True
End If
End Sub
End Class

frmStaffRecord.vb
Imports System.Data.SqlClient
Imports System.IO
Imports Excel = Microsoft.Office.Interop.Excel

Public Class frmStaffRecord


Dim rdr As SqlDataReader = Nothing
Dim dtable As DataTable
Dim con As SqlConnection = Nothing
Dim adp As SqlDataAdapter
Dim ds As DataSet
Dim cmd As SqlCommand = Nothing
Dim dt As New DataTable
Dim cs As String = "Data Source=.\SQLEXPRESS;Initial
Catalog=LibraryDatabase;Integrated Security=True"

Sub fillDepartment()
Try
Dim CN As New SqlConnection(cs)
CN.Open()
adp = New SqlDataAdapter()

Project by: Kuldeep Singh | 1053 Page 117


Library Management System

adp.SelectCommand = New SqlCommand("SELECT distinct


RTRIM(Department) FROM Staff", CN)
ds = New DataSet("ds")
adp.Fill(ds)
dtable = ds.Tables(0)
cmbDepartment.Items.Clear()
For Each drow As DataRow In dtable.Rows
cmbDepartment.Items.Add(drow(0).ToString())
Next
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
End Try
End Sub

Private Sub DataGridView1_RowHeaderMouseClick(ByVal sender As Object,


ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles
DataGridView1.RowHeaderMouseClick
Try
Dim dr As DataGridViewRow = DataGridView1.SelectedRows(0)
Me.Hide()
frmStaff.Show()
frmStaff.txtStaffID.Text = dr.Cells(0).Value.ToString()
frmStaff.txtStaffName.Text = dr.Cells(1).Value.ToString()
If (dr.Cells(2).Value.ToString() = "Male") Then
frmStaff.rbMale.Checked = True
End If
If (dr.Cells(2).Value.ToString() = "Female") Then
frmStaff.rbFemale.Checked = True
End If
frmStaff.txtLastName.Text = dr.Cells(3).Value.ToString()
frmStaff.dtpDateOfJoining.Text = dr.Cells(4).Value.ToString()
frmStaff.cmbDepartment.Text = dr.Cells(5).Value.ToString()
frmStaff.txtTempAddress.Text = dr.Cells(6).Value.ToString()
frmStaff.txtPermanentAddress.Text = dr.Cells(7).Value.ToString()
frmStaff.dtpDOB.Text = dr.Cells(8).Value.ToString()
frmStaff.txtPhoneNo.Text = dr.Cells(9).Value.ToString()
frmStaff.txtMobileNo.Text = dr.Cells(10).Value.ToString()
frmStaff.txtEmail.Text = dr.Cells(11).Value.ToString()
Dim data As Byte() = DirectCast(dr.Cells(12).Value, Byte())
Dim ms As New MemoryStream(data)
frmStaff.Picture.Image = Image.FromStream(ms)
frmStaff.btnUpdate_record.Enabled = True
frmStaff.btnDelete.Enabled = True
frmStaff.btnSave.Enabled = False
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
End Try

Project by: Kuldeep Singh | 1053 Page 118


Library Management System

End Sub

Private Sub DataGridView1_RowPostPaint(ByVal sender As Object, ByVal e As


System.Windows.Forms.DataGridViewRowPostPaintEventArgs) Handles
DataGridView1.RowPostPaint
Dim strRowNumber As String = (e.RowIndex + 1).ToString()
Dim size As SizeF = e.Graphics.MeasureString(strRowNumber, Me.Font)
If DataGridView1.RowHeadersWidth < Convert.ToInt32((size.Width + 20))
Then
DataGridView1.RowHeadersWidth = Convert.ToInt32((size.Width + 20))
End If
Dim b As Brush = SystemBrushes.ControlText
e.Graphics.DrawString(strRowNumber, Me.Font, b, e.RowBounds.Location.X +
15, e.RowBounds.Location.Y + ((e.RowBounds.Height - size.Height) / 2))
End Sub
Public Sub GetData()
Try
con = New SqlConnection(cs)
con.Open()
cmd = New SqlCommand("SELECT StaffID as [Staff ID], StaffName as
[Staff Name],Gender, LastName as [Last Name],DateOfJoining as [Date Of Joining],
Department, TemporaryAddress as [Temporary Address], PermanentAddress as
[Permanent Address], DOB, PhoneNo as [Phone No], MobileNo as [Mobile No],
Email as [Email ID], Photo from Staff order by Staffname", con)
Dim myDA As SqlDataAdapter = New SqlDataAdapter(cmd)
Dim myDataSet As DataSet = New DataSet()
myDA.Fill(myDataSet, "Staff")
DataGridView1.DataSource = myDataSet.Tables("Staff").DefaultView
con.Close()
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
End Try
End Sub

Private Sub cmbDepartment_SelectedIndexChanged(ByVal sender As


System.Object, ByVal e As System.EventArgs) Handles
cmbDepartment.SelectedIndexChanged
Try
con = New SqlConnection(cs)
con.Open()
cmd = New SqlCommand("SELECT StaffID as [Staff ID], StaffName as
[Staff Name],Gender, LastName as [Last Name],DateOfJoining as [DateOfJoining],
Department, TemporaryAddress as [Temporary Address], PermanentAddress as
[Permanent Address], DOB, PhoneNo as [Phone No], MobileNo as [Mobile No],
Email as [Email ID], Photo from Staff where department='" & cmbDepartment.Text
& "' order by Staffname", con)
Dim myDA As SqlDataAdapter = New SqlDataAdapter(cmd)

Project by: Kuldeep Singh | 1053 Page 119


Library Management System

Dim myDataSet As DataSet = New DataSet()


myDA.Fill(myDataSet, "Staff")
DataGridView1.DataSource = myDataSet.Tables("Staff").DefaultView
con.Close()
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
End Try
End Sub

Private Sub btnReset_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles btnReset.Click
txtStaffName.Text = ""
dtpDateFrom.Text = Today
cmbDepartment.Text = ""
dtpDateTo.Text = Today
GetData()
End Sub

Private Sub btnExportExcel_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles btnExportExcel.Click
Dim rowsTotal, colsTotal As Short
Dim I, j, iC As Short
System.Windows.Forms.Cursor.Current =
System.Windows.Forms.Cursors.WaitCursor
Dim xlApp As New Excel.Application
Try
Dim excelBook As Excel.Workbook = xlApp.Workbooks.Add
Dim excelWorksheet As Excel.Worksheet =
CType(excelBook.Worksheets(1), Excel.Worksheet)
xlApp.Visible = True

rowsTotal = DataGridView1.RowCount - 1
colsTotal = DataGridView1.Columns.Count - 1
With excelWorksheet
.Cells.Select()
.Cells.Delete()
For iC = 0 To colsTotal - 1
.Cells(1, iC + 1).Value = DataGridView1.Columns(iC).HeaderText
Next
For I = 0 To rowsTotal - 1
For j = 0 To colsTotal - 1
.Cells(I + 2, j + 1).value = DataGridView1.Rows(I).Cells(j).Value
Next j
Next I
.Rows("1:1").Font.FontStyle = "Bold"
.Rows("1:1").Font.Size = 12

.Cells.Columns.AutoFit()
.Cells.Select()

Project by: Kuldeep Singh | 1053 Page 120


Library Management System

.Cells.EntireColumn.AutoFit()
.Cells(1, 1).Select()
End With
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
Finally
'RELEASE ALLOACTED RESOURCES
System.Windows.Forms.Cursor.Current =
System.Windows.Forms.Cursors.Default
xlApp = Nothing
End Try
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button1.Click
Try
con = New SqlConnection(cs)
con.Open()
cmd = New SqlCommand("SELECT StaffID as [Staff ID], StaffName as
[Staff Name],Gender, LastName as [Last Name],DateOfJoining as [Date Of Joining],
Department, TemporaryAddress as [Temporary Address], PermanentAddress as
[Permanent Address], DOB, PhoneNo as [Phone No], MobileNo as [Mobile No],
Email as [Email ID], Photo from Staff where DateOfJoining between #" &
dtpDateFrom.Text & "# and #" & dtpDateTo.Text & "# order by Staffname", con)
Dim myDA As SqlDataAdapter = New SqlDataAdapter(cmd)
Dim myDataSet As DataSet = New DataSet()
myDA.Fill(myDataSet, "Staff")
DataGridView1.DataSource = myDataSet.Tables("Staff").DefaultView
con.Close()
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
End Try
End Sub

Private Sub txtStaffName_TextChanged(ByVal sender As System.Object, ByVal e


As System.EventArgs) Handles txtStaffName.TextChanged
Try
con = New SqlConnection(cs)
con.Open()
cmd = New SqlCommand("SELECT StaffID as [Staff ID], StaffName as
[Staff Name],Gender, LastName as [Last Name],DateOfJoining as [Date Of Joining],
Department, TemporaryAddress as [Temporary Address], PermanentAddress as
[Permanent Address], DOB, PhoneNo as [Phone No], MobileNo as [Mobile No],
Email as [Email ID], Photo from Staff where staffname like '" & txtStaffName.Text &
"%' order by Staffname", con)
Dim myDA As SqlDataAdapter = New SqlDataAdapter(cmd)
Dim myDataSet As DataSet = New DataSet()
myDA.Fill(myDataSet, "Staff")

Project by: Kuldeep Singh | 1053 Page 121


Library Management System

DataGridView1.DataSource = myDataSet.Tables("Staff").DefaultView
con.Close()
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
End Try
End Sub

Private Sub frmStaffRecord_Load(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles MyBase.Load
fillDepartment()
GetData()
End Sub

Private Sub dtpDateTo_Validating(ByVal sender As System.Object, ByVal e As


System.ComponentModel.CancelEventArgs) Handles dtpDateTo.Validating
If (dtpDateFrom.Value.Date) > (dtpDateTo.Value.Date) Then
MessageBox.Show("Invalid Selection", "Input Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
dtpDateTo.Focus()
End If
End Sub
End Class

frmBookIssue.vb
Imports System.Data.SqlClient
Imports System.Security.Cryptography
Imports System.Text
Public Class frmBookIssue

Dim rdr As SqlDataReader = Nothing


Dim dtable As DataTable
Dim con As SqlConnection = Nothing
Dim adp As SqlDataAdapter
Dim ds As DataSet
Dim cmd As SqlCommand = Nothing
Dim dt As New DataTable
Dim gender As String
Dim cs As String = "Data Source=.\SQLEXPRESS;Initial
Catalog=LibraryDatabase;Integrated Security=True"
Public Shared Function GetUniqueKey(ByVal maxSize As Integer) As String
Dim chars As Char() = New Char(61) {}
chars = "123456789".ToCharArray()
Dim data As Byte() = New Byte(0) {}
Dim crypto As New RNGCryptoServiceProvider()
crypto.GetNonZeroBytes(data)
data = New Byte(maxSize - 1) {}
crypto.GetNonZeroBytes(data)
Dim result As New StringBuilder(maxSize)
For Each b As Byte In data

Project by: Kuldeep Singh | 1053 Page 122


Library Management System

result.Append(chars(b Mod (chars.Length)))


Next
Return result.ToString()
End Function
Sub Reset()
cmbStudentID.Text = ""
txtTransactionID.Text = ""
txtAuthor.Text = ""
txtBookTitle.Text = ""
txtCategory.Text = ""
txtDepartment.Text = ""
txtEdition.Text = ""
txtISBN.Text = ""
txtCourse.Text = ""
txtStudentName.Text = ""
cmbAccessionNo.Text = ""
dtpDueDate.Text = ""
dtpIssueDate.Text = ""
btnSave.Enabled = True
btnDelete.Enabled = False
btnUpdate_record.Enabled = False
End Sub
Sub Reset1()
cmbStaffID.Text = ""
txtTransactionID1.Text = ""
txtAuthor1.Text = ""
txtBookTitle1.Text = ""
txtCategory1.Text = ""
txtDepartment1.Text = ""
txtEdition1.Text = ""
txtISBN1.Text = ""
txtStaffName.Text = ""
cmbAccessionNo1.Text = ""
dtpDueDate1.Text = ""
dtpIssueDate1.Text = ""
btnSave1.Enabled = True
btnDelete1.Enabled = False
btnUpdate1.Enabled = False
End Sub
Private Sub frmBookIssue_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
fillANo()
fillANo1()
fillStudentID()
fillStaffID()
Reset()
Reset1()
End Sub

Public Sub DeleteRecord()

Project by: Kuldeep Singh | 1053 Page 123


Library Management System

Try
Dim RowsAffected As Integer = 0
con = New SqlConnection(cs)
con.Open()
Dim cq As String = "delete from BookIssue_Student where TransactionID = '"
& txtTransactionID.Text & "'"
cmd = New SqlCommand(cq)
cmd.Connection = con
RowsAffected = cmd.ExecuteNonQuery()
If RowsAffected > 0 Then
MessageBox.Show("Successfully deleted", "Record",
MessageBoxButtons.OK, MessageBoxIcon.Information)
Reset()
Else
MessageBox.Show("No record found", "Sorry", MessageBoxButtons.OK,
MessageBoxIcon.Information)
Reset()
If con.State = ConnectionState.Open Then
con.Close()
End If
con.Close()
End If
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
End Try
End Sub
Public Sub DeleteRecord1()
Try
Dim RowsAffected As Integer = 0
con = New SqlConnection(cs)
con.Open()
Dim cq As String = "delete from BookIssue_Staff where TransactionID = '" &
txtTransactionID1.Text & "'"
cmd = New SqlCommand(cq)
cmd.Connection = con
RowsAffected = cmd.ExecuteNonQuery()
If RowsAffected > 0 Then
MessageBox.Show("Successfully deleted", "Record",
MessageBoxButtons.OK, MessageBoxIcon.Information)
Reset1()
Else
MessageBox.Show("No record found", "Sorry", MessageBoxButtons.OK,
MessageBoxIcon.Information)
Reset1()
If con.State = ConnectionState.Open Then
con.Close()
End If
con.Close()
End If

Project by: Kuldeep Singh | 1053 Page 124


Library Management System

Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
End Try
End Sub
Sub fillANo()
Try
cmbAccessionNo.DataSource = Nothing
Dim CN As New SqlConnection(cs)
CN.Open()
adp = New SqlDataAdapter()
adp.SelectCommand = New SqlCommand("SELECT distinct AccessionNo
FROM Book", CN)
ds = New DataSet("ds")
adp.Fill(ds)
dtable = ds.Tables(0)
cmbAccessionNo.DisplayMember = "AccessionNo"
cmbAccessionNo.DataSource = dtable
cmbAccessionNo.SelectedIndex = -1
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
End Try
End Sub
Sub fillANo1()
Try
cmbAccessionNo1.DataSource = Nothing
Dim CN As New SqlConnection(cs)
CN.Open()
adp = New SqlDataAdapter()
adp.SelectCommand = New SqlCommand("SELECT distinct AccessionNo
FROM Book ", CN)
ds = New DataSet("ds")
adp.Fill(ds)
dtable = ds.Tables(0)
cmbAccessionNo1.DisplayMember = "AccessionNo"
cmbAccessionNo1.DataSource = dtable
cmbAccessionNo1.SelectedIndex = -1
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
End Try
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
frmStudentRecord3.Show()
frmStudentRecord3.txtStudentName.Text = ""
frmStudentRecord3.cmbCourse.Text = ""
frmStudentRecord3.cmbDepartment.Text = ""
frmStudentRecord3.cmbCourse1.Text = ""

Project by: Kuldeep Singh | 1053 Page 125


Library Management System

frmStudentRecord3.cmbDepartment1.Text = ""
frmStudentRecord3.cmbSession.Text = ""
frmStudentRecord3.GetData()
End Sub

Private Sub cmbAccessionNo_SelectedIndexChanged(ByVal sender As


System.Object, ByVal e As System.EventArgs) Handles
cmbAccessionNo.SelectedIndexChanged
Try
con = New SqlConnection(cs)
con.Open()
Dim ct As String = "select BookTitle,Author,Subject,ISBN,Edition from book
where AccessionNo='" & cmbAccessionNo.Text & "'"
cmd = New SqlCommand(ct)
cmd.Connection = con
rdr = cmd.ExecuteReader()
If rdr.Read Then
txtBookTitle.Text = rdr("BookTitle").ToString()
txtAuthor.Text = rdr("Author").ToString()
txtCategory.Text = rdr("Subject").ToString()
txtISBN.Text = rdr("ISBN").ToString()
txtEdition.Text = rdr("Edition").ToString()
End If
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
End Try
End Sub

Private Sub dtpIssueDate_ValueChanged(ByVal sender As System.Object, ByVal


e As System.EventArgs) Handles dtpIssueDate.ValueChanged
dtpDueDate.Text = dtpIssueDate.Value.Date.AddDays(4)
End Sub

Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles btnDelete.Click
Try
If MessageBox.Show("Do you really want to delete this record?",
"Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) =
Windows.Forms.DialogResult.Yes Then
DeleteRecord()
End If
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
End Try
End Sub

Private Sub btnUpdate_record_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles btnUpdate_record.Click

Project by: Kuldeep Singh | 1053 Page 126


Library Management System

Try
If (cmbStudentID.Text = "") Then
MessageBox.Show("Please retrieve student id", "Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
cmbStudentID.Focus()
Exit Sub
End If
If (txtStudentName.Text = "") Then
MessageBox.Show("Please retrieve student name", "Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
txtStudentName.Focus()
Exit Sub
End If
If Len(Trim(cmbAccessionNo.Text)) = 0 Then
MessageBox.Show("Please select accession no.", "Input Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
cmbAccessionNo.Focus()
Exit Sub
End If
If Len(Trim(txtBookTitle.Text)) = 0 Then
MessageBox.Show("Please retrieve book title", "Input Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
txtBookTitle.Focus()
Exit Sub
End If
con = New SqlConnection(cs)
con.Open()
Dim ct As String = "select NoOfBooks from Book where AccessionNo='" &
cmbAccessionNo.Text & "' and NoOfBooks <=0"
cmd = New SqlCommand(ct)
cmd.Connection = con
rdr = cmd.ExecuteReader()
If rdr.Read Then
MessageBox.Show("Book is not available for issue", "Input Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
Reset()
If Not rdr Is Nothing Then
rdr.Close()
End If
Exit Sub
End If
con = New SqlConnection(cs)
con.Open()
Dim cb As String = "update Bookissue_student set IssueDate=#" &
dtpIssueDate.Text & "#,DueDate=#" & dtpDueDate.Text & "#,AccessionNo='" &
cmbAccessionNo.Text & "',StudentID= '" & cmbStudentID.Text & "' where
TransactionID='" & txtTransactionID.Text & "'"
cmd = New SqlCommand(cb)
cmd.Connection = con
cmd.ExecuteNonQuery()

Project by: Kuldeep Singh | 1053 Page 127


Library Management System

con.Close()
If (cmbAccessionNo.Text <> TextBox1.Text) And (txtStatus.Text = "Issued")
Then
con = New SqlConnection(cs)
con.Open()
Dim cb1 As String = "Update book set NoOfBooks = NoOfBooks + 1
where AccessionNo='" & TextBox1.Text & "'"
cmd = New SqlCommand(cb1)
cmd.Connection = con
cmd.ExecuteNonQuery()
con.Close()
con = New SqlConnection(cs)
con.Open()
Dim cb2 As String = "Update book set NoOfBooks = NoOfBooks - 1 where
AccessionNo='" & cmbAccessionNo.Text & "'"
cmd = New SqlCommand(cb2)
cmd.Connection = con
cmd.ExecuteNonQuery()
con.Close()
End If
MessageBox.Show("Successfully updated", "Record",
MessageBoxButtons.OK, MessageBoxIcon.Information)
btnUpdate_record.Enabled = False
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
End Try
End Sub

Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles btnSave.Click
Try
If (cmbStudentID.Text = "") Then
MessageBox.Show("Please retrieve student id", "Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
cmbStudentID.Focus()
Exit Sub
End If
If (txtStudentName.Text = "") Then
MessageBox.Show("Please retrieve student name", "Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
txtStudentName.Focus()
Exit Sub
End If
If Len(Trim(cmbAccessionNo.Text)) = 0 Then
MessageBox.Show("Please select accession no.", "Input Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
cmbAccessionNo.Focus()
Exit Sub
End If

Project by: Kuldeep Singh | 1053 Page 128


Library Management System

If Len(Trim(txtBookTitle.Text)) = 0 Then
MessageBox.Show("Please retrieve book title", "Input Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
txtBookTitle.Focus()
Exit Sub
End If
con = New SqlConnection(cs)
con.Open()
Dim ct As String = "select NoOfBooks from Book where AccessionNo='" &
cmbAccessionNo.Text & "' and NoOfBooks <=0"
cmd = New SqlCommand(ct)
cmd.Connection = con
rdr = cmd.ExecuteReader()
If rdr.Read Then
MessageBox.Show("Book is not available for issue", "Input Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
Reset()
If Not rdr Is Nothing Then
rdr.Close()
End If
Exit Sub
End If
dtpDueDate.Text = dtpIssueDate.Value.Date.AddDays(4)
txtTransactionID.Text = "T-" & GetUniqueKey(6)
con = New SqlConnection(cs)
con.Open()
Dim cb As String = "insert into Bookissue_Student(TransactionID, IssueDate,
DueDate, AccessionNo, StudentID, Status) VALUES('" & txtTransactionID.Text &
"','" & dtpIssueDate.Text & "','" & dtpDueDate.Text & "','" & cmbAccessionNo.Text
& "','" & cmbStudentID.Text & "','Issued')"
cmd = New SqlCommand(cb)
cmd.Connection = con
cmd.ExecuteNonQuery()
con.Close()
con = New SqlConnection(cs)
con.Open()
Dim cb1 As String = "Update book set NoOfBooks = NoOfBooks-1 where
AccessionNo='" & cmbAccessionNo.Text & "'"
cmd = New SqlCommand(cb1)
cmd.Connection = con
cmd.ExecuteNonQuery()
con.Close()
MessageBox.Show("Successfully issued", "Book", MessageBoxButtons.OK,
MessageBoxIcon.Information)
txtTransactionID.Text = ""
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
End Try
End Sub

Project by: Kuldeep Singh | 1053 Page 129


Library Management System

Private Sub btnNewRecord_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles btnNewRecord.Click
Reset()
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button1.Click
frmBookRecord2.Show()
frmBookRecord2.Clear()
End Sub

Private Sub cmbStudentID_SelectedIndexChanged(ByVal sender As


System.Object, ByVal e As System.EventArgs) Handles
cmbStudentID.SelectedIndexChanged
Try
con = New SqlConnection(cs)
con.Open()
Dim ct As String = "select StudentName,Course,Department from Student
where StudentID='" & cmbStudentID.Text & "'"
cmd = New SqlCommand(ct)
cmd.Connection = con
rdr = cmd.ExecuteReader()
If rdr.Read Then
txtStudentName.Text = rdr("StudentName").ToString()
txtCourse.Text = rdr("Course").ToString()
txtDepartment.Text = rdr("Department").ToString()
End If
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
End Try
End Sub

Sub fillStudentID()
Try
cmbStudentID.DataSource = Nothing
Dim CN As New SqlConnection(cs)
CN.Open()
adp = New SqlDataAdapter()
adp.SelectCommand = New SqlCommand("SELECT distinct StudentID
FROM Student ", CN)
ds = New DataSet("ds")
adp.Fill(ds)
dtable = ds.Tables(0)
cmbStudentID.DisplayMember = "StudentID"
cmbStudentID.DataSource = dtable
cmbStudentID.SelectedIndex = -1
Catch ex As Exception

Project by: Kuldeep Singh | 1053 Page 130


Library Management System

MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,


MessageBoxIcon.Error)
End Try
End Sub
Sub fillStaffID()
Try
cmbStaffID.DataSource = Nothing
Dim CN As New SqlConnection(cs)
CN.Open()
adp = New SqlDataAdapter()
adp.SelectCommand = New SqlCommand("SELECT distinct StaffID FROM
Staff ", CN)
ds = New DataSet("ds")
adp.Fill(ds)
dtable = ds.Tables(0)
cmbStaffID.DisplayMember = "StaffID"
cmbStaffID.DataSource = dtable
cmbStaffID.SelectedIndex = -1
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
End Try
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button3.Click
frmBookIssueRecord.Show()
frmBookIssueRecord.Reset()
End Sub

Private Sub btnNewRecord1_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles btnNewRecord1.Click
Reset1()
End Sub

Private Sub btnSave1_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles btnSave1.Click
Try
If (cmbStaffID.Text = "") Then
MessageBox.Show("Please retrieve staff id", "Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
cmbStaffID.Focus()
Exit Sub
End If
If (txtStaffName.Text = "") Then
MessageBox.Show("Please retrieve staff name", "Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
txtStaffName.Focus()
Exit Sub
End If

Project by: Kuldeep Singh | 1053 Page 131


Library Management System

If Len(Trim(cmbAccessionNo1.Text)) = 0 Then
MessageBox.Show("Please select accession no.", "Input Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
cmbAccessionNo1.Focus()
Exit Sub
End If
If Len(Trim(txtBookTitle1.Text)) = 0 Then
MessageBox.Show("Please retrieve book title", "Input Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
txtBookTitle1.Focus()
Exit Sub
End If
con = New SqlConnection(cs)
con.Open()
Dim ct As String = "select NoOfBooks from Book where AccessionNo='" &
cmbAccessionNo1.Text & "' and NoOfBooks <=0"
cmd = New SqlCommand(ct)
cmd.Connection = con
rdr = cmd.ExecuteReader()
If rdr.Read Then
MessageBox.Show("Book is not available for issue", "Input Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
Reset()
If Not rdr Is Nothing Then
rdr.Close()
End If
Exit Sub
End If
dtpDueDate1.Text = dtpIssueDate1.Value.Date.AddDays(4)
txtTransactionID1.Text = "T-" & GetUniqueKey(6)
con = New SqlConnection(cs)
con.Open()
Dim cb As String = "insert into Bookissue_Staff(TransactionID, IssueDate,
DueDate, AccessionNo, StaffID, Status) VALUES('" & txtTransactionID1.Text &
"','" & dtpIssueDate1.Text & "','" & dtpDueDate1.Text & "','" &
cmbAccessionNo1.Text & "','" & cmbStaffID.Text & "','Issued')"
cmd = New SqlCommand(cb)
cmd.Connection = con
cmd.ExecuteNonQuery()
con.Close()
con = New SqlConnection(cs)
con.Open()
Dim cb1 As String = "Update book set NoOfBooks = NoOfBooks-1 where
AccessionNo='" & cmbAccessionNo1.Text & "'"
cmd = New SqlCommand(cb1)
cmd.Connection = con
cmd.ExecuteNonQuery()
con.Close()
MessageBox.Show("Successfully issued", "Book", MessageBoxButtons.OK,
MessageBoxIcon.Information)

Project by: Kuldeep Singh | 1053 Page 132


Library Management System

txtTransactionID.Text = ""
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
End Try
End Sub

Private Sub btnUpdate1_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles btnUpdate1.Click
Try
If (cmbStaffID.Text = "") Then
MessageBox.Show("Please retrieve staff id", "Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
cmbStaffID.Focus()
Exit Sub
End If
If (txtStaffName.Text = "") Then
MessageBox.Show("Please retrieve staff name", "Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
txtStaffName.Focus()
Exit Sub
End If
If Len(Trim(cmbAccessionNo1.Text)) = 0 Then
MessageBox.Show("Please select accession no.", "Input Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
cmbAccessionNo1.Focus()
Exit Sub
End If
If Len(Trim(txtBookTitle1.Text)) = 0 Then
MessageBox.Show("Please retrieve book title", "Input Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
txtBookTitle1.Focus()
Exit Sub
End If
con = New SqlConnection(cs)
con.Open()
Dim ct As String = "select NoOfBooks from Book where AccessionNo='" &
cmbAccessionNo1.Text & "' and NoOfBooks <=0"
cmd = New SqlCommand(ct)
cmd.Connection = con
rdr = cmd.ExecuteReader()
If rdr.Read Then
MessageBox.Show("Book is not available for issue", "Input Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
Reset()
If Not rdr Is Nothing Then
rdr.Close()
End If
Exit Sub
End If

Project by: Kuldeep Singh | 1053 Page 133


Library Management System

con = New SqlConnection(cs)


con.Open()
Dim cb As String = "update Bookissue_staff set IssueDate='" &
dtpIssueDate1.Text & "',DueDate='" & dtpDueDate1.Text & "',AccessionNo='" &
cmbAccessionNo1.Text & "',StaffID= '" & cmbStaffID.Text & "' where
TransactionID='" & txtTransactionID1.Text & "'"
cmd = New SqlCommand(cb)
cmd.Connection = con
cmd.ExecuteNonQuery()
con.Close()
If (cmbAccessionNo1.Text <> TextBox2.Text) And (txtStatus1.Text =
"Issued") Then
con = New SqlConnection(cs)
con.Open()
Dim cb1 As String = "Update book set NoOfBooks = NoOfBooks + 1
where AccessionNo='" & TextBox2.Text & "'"
cmd = New SqlCommand(cb1)
cmd.Connection = con
cmd.ExecuteNonQuery()
con.Close()
con = New SqlConnection(cs)
con.Open()
Dim cb2 As String = "Update book set NoOfBooks = NoOfBooks - 1 where
AccessionNo='" & cmbAccessionNo1.Text & "'"
cmd = New SqlCommand(cb2)
cmd.Connection = con
cmd.ExecuteNonQuery()
con.Close()
End If
MessageBox.Show("Successfully updated", "Record",
MessageBoxButtons.OK, MessageBoxIcon.Information)
btnUpdate1.Enabled = False
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
End Try
End Sub

Private Sub btnDelete1_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles btnDelete1.Click
Try
If MessageBox.Show("Do you really want to delete this record?",
"Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) =
Windows.Forms.DialogResult.Yes Then
DeleteRecord1()
End If
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
End Try

Project by: Kuldeep Singh | 1053 Page 134


Library Management System

End Sub

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button4.Click
frmBookIssueRecord_Staff.Show()
frmBookIssueRecord_Staff.Reset()
End Sub

Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button5.Click
frmStaffRecord2.Show()
frmStaffRecord2.txtStaffName.Text = ""
frmStaffRecord2.dtpDateFrom.Text = Today
frmStaffRecord2.cmbDepartment.Text = ""
frmStaffRecord2.dtpDateTo.Text = Today
frmStaffRecord2.GetData()
End Sub

Private Sub cmbAccessionNo1_SelectedIndexChanged(ByVal sender As


System.Object, ByVal e As System.EventArgs) Handles
cmbAccessionNo1.SelectedIndexChanged
Try
con = New SqlConnection(cs)
con.Open()
Dim ct As String = "select BookTitle,Author,Subject,ISBN,Edition from book
where AccessionNo='" & cmbAccessionNo1.Text & "'"
cmd = New SqlCommand(ct)
cmd.Connection = con
rdr = cmd.ExecuteReader()
If rdr.Read Then
txtBookTitle1.Text = rdr("BookTitle").ToString()
txtAuthor1.Text = rdr("Author").ToString()
txtCategory1.Text = rdr("Subject").ToString()
txtISBN1.Text = rdr("ISBN").ToString()
txtEdition1.Text = rdr("Edition").ToString()
End If
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
End Try
End Sub

Private Sub cmbStaffID_SelectedIndexChanged(ByVal sender As System.Object,


ByVal e As System.EventArgs) Handles cmbStaffID.SelectedIndexChanged
Try
con = New SqlConnection(cs)
con.Open()
Dim ct As String = "select Staffname,Department from Staff where StaffID='"
& cmbStaffID.Text & "'"
cmd = New SqlCommand(ct)

Project by: Kuldeep Singh | 1053 Page 135


Library Management System

cmd.Connection = con
rdr = cmd.ExecuteReader()
If rdr.Read Then
txtStaffName.Text = rdr("StaffName").ToString()
txtDepartment1.Text = rdr("Department").ToString()
End If
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
End Try
End Sub

Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button6.Click
frmBookRecord3.Show()
frmBookRecord3.Clear()
End Sub

Private Sub dtpIssueDate1_ValueChanged(ByVal sender As System.Object, ByVal


e As System.EventArgs) Handles dtpIssueDate1.ValueChanged
dtpDueDate1.Text = dtpIssueDate1.Value.Date.AddDays(4)
End Sub
End Class
frmBookReturn.vb
Imports System.Data.SqlClient
Imports System.Security.Cryptography
Imports System.Text
Public Class frmBookReturn

Dim rdr As SqlDataReader = Nothing


Dim dtable As DataTable
Dim con As SqlConnection = Nothing
Dim adp As SqlDataAdapter
Dim ds As DataSet
Dim cmd As SqlCommand = Nothing
Dim dt As New DataTable
Dim gender As String
Dim cs As String = "Data Source=.\SQLEXPRESS;Initial
Catalog=LibraryDatabase;Integrated Security=True"
Public Shared Function GetUniqueKey(ByVal maxSize As Integer) As String
Dim chars As Char() = New Char(61) {}
chars = "123456789".ToCharArray()
Dim data As Byte() = New Byte(0) {}
Dim crypto As New RNGCryptoServiceProvider()
crypto.GetNonZeroBytes(data)
data = New Byte(maxSize - 1) {}
crypto.GetNonZeroBytes(data)
Dim result As New StringBuilder(maxSize)
For Each b As Byte In data
result.Append(chars(b Mod (chars.Length)))

Project by: Kuldeep Singh | 1053 Page 136


Library Management System

Next
Return result.ToString()
End Function
Sub Reset()
txtStudentID.Text = ""
dtpReturnDate.Text = Today
txtTransactionID.Text = ""
txtAuthor.Text = ""
txtBookTitle.Text = ""
txtCategory.Text = ""
txtDepartment.Text = ""
txtEdition.Text = ""
txtISBN.Text = ""
txtCourse.Text = ""
txtStudentName.Text = ""
txtAccessionNo.Text = ""
dtpDueDate.Text = ""
dtpIssueDate.Text = ""
txtFine.Text = ""
btnSave.Enabled = True
btnDelete.Enabled = False
btnUpdate_record.Enabled = False
End Sub
Sub Reset1()
txtStaffID.Text = ""
txtTransactionID1.Text = ""
dtpReturnDate1.Text = Today
txtAuthor1.Text = ""
txtBookTitle1.Text = ""
txtCategory1.Text = ""
txtDepartment1.Text = ""
txtEdition1.Text = ""
txtISBN1.Text = ""
txtStaffName.Text = ""
txtAccessionNo1.Text = ""
dtpDueDate1.Text = ""
dtpIssueDate1.Text = ""
txtFine1.Text = ""
btnSave1.Enabled = True
btnDelete1.Enabled = False
btnUpdate1.Enabled = False
End Sub
Private Sub btnNewRecord1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnNewRecord1.Click
Reset1()
End Sub
Private Sub btnNewRecord_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnNewRecord.Click
Reset()
End Sub

Project by: Kuldeep Singh | 1053 Page 137


Library Management System

Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles btnSave.Click
Try
If Len(Trim(txtTransactionID.Text)) = 0 Then
MessageBox.Show("Please retrieve transaction id", "Input Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
txtTransactionID.Focus()
Exit Sub
End If
If (dtpReturnDate.Value.Date < dtpDueDate.Value.Date) Then
MessageBox.Show("Return date can not be less than due date", "Input
Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
dtpReturnDate.Focus()
Exit Sub
End If
If txtFine.Text = "" Then
txtFine.Text = 0
End If
txtReturnID.Text = "R-" & GetUniqueKey(6)
con = New SqlConnection(cs)
con.Open()
Dim cb As String = "insert into return_Student(ReturnID, TransactionID,
ReturnDate, Fine) VALUES('" & txtReturnID.Text & "','" & txtTransactionID.Text &
"','" & dtpReturnDate.Text & "'," & txtFine.Text & ")"
cmd = New SqlCommand(cb)
cmd.Connection = con
cmd.ExecuteNonQuery()
con.Close()
con = New SqlConnection(cs)
con.Open()
Dim cb1 As String = "Update book set NoOfBooks = NoOfBooks+1 where
AccessionNo='" & txtAccessionNo.Text & "'"
cmd = New SqlCommand(cb1)
cmd.Connection = con
cmd.ExecuteNonQuery()
con.Close()
con = New SqlConnection(cs)
con.Open()
Dim cb2 As String = "Update bookIssue_student set Status = 'Returned' where
AccessionNo='" & txtAccessionNo.Text & "'"
cmd = New SqlCommand(cb2)
cmd.Connection = con
cmd.ExecuteNonQuery()
con.Close()
MessageBox.Show("Successfully returned", "Book",
MessageBoxButtons.OK, MessageBoxIcon.Information)
btnSave.Enabled = False
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)

Project by: Kuldeep Singh | 1053 Page 138


Library Management System

End Try
End Sub

Private Sub dtpReturnDate_ValueChanged(ByVal sender As System.Object, ByVal


e As System.EventArgs) Handles dtpReturnDate.ValueChanged
Dim st As Integer =
dtpReturnDate.Value.Date.Subtract(dtpDueDate.Value.Date).Days
If (st > 0) Then
txtFine.Text = (st * 5).ToString()
Else
txtFine.Text = 0
End If
End Sub

Private Sub dtpReturnDate_Validating(ByVal sender As System.Object, ByVal e


As System.ComponentModel.CancelEventArgs) Handles dtpReturnDate.Validating
If (dtpDueDate.Value.Date) > (dtpReturnDate.Value.Date) Then
MessageBox.Show("Invalid Selection", "Input Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
dtpReturnDate.Focus()
End If
End Sub

Private Sub dtpReturnDate1_Validating(ByVal sender As System.Object, ByVal e


As System.ComponentModel.CancelEventArgs) Handles dtpReturnDate1.Validating
If (dtpDueDate1.Value.Date) > (dtpReturnDate1.Value.Date) Then
MessageBox.Show("Invalid Selection", "Input Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
dtpReturnDate1.Focus()
End If
End Sub

Private Sub dtpReturnDate1_ValueChanged(ByVal sender As System.Object,


ByVal e As System.EventArgs) Handles dtpReturnDate1.ValueChanged
Dim st As Integer =
dtpReturnDate1.Value.Date.Subtract(dtpDueDate1.Value.Date).Days
If (st > 0) Then
txtFine1.Text = (st * 5).ToString()

Else
txtFine1.Text = 0
End If
End Sub

Private Sub btnSave1_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles btnSave1.Click
Try
If Len(Trim(txtTransactionID1.Text)) = 0 Then
MessageBox.Show("Please retrieve transaction id", "Input Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)

Project by: Kuldeep Singh | 1053 Page 139


Library Management System

txtTransactionID1.Focus()
Exit Sub
End If
If (dtpReturnDate1.Value.Date < dtpDueDate1.Value.Date) Then
MessageBox.Show("Return date can not be less than due date", "Input
Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
dtpReturnDate1.Focus()
Exit Sub
End If
If txtFine1.Text = "" Then
txtFine1.Text = 0
End If
txtReturnID1.Text = "R-" & GetUniqueKey(6)
con = New SqlConnection(cs)
con.Open()
Dim cb As String = "insert into return_Staff(ReturnID, TransactionID,
ReturnDate, Fine) VALUES('" & txtReturnID1.Text & "','" & txtTransactionID1.Text
& "','" & dtpReturnDate1.Text & "'," & txtFine1.Text & ")"
cmd = New SqlCommand(cb)
cmd.Connection = con
cmd.ExecuteNonQuery()
con.Close()
con = New SqlConnection(cs)
con.Open()
Dim cb1 As String = "Update book set NoOfBooks = NoOfBooks+1 where
AccessionNo='" & txtAccessionNo1.Text & "'"
cmd = New SqlCommand(cb1)
cmd.Connection = con
cmd.ExecuteNonQuery()
con.Close()
con = New SqlConnection(cs)
con.Open()
Dim cb2 As String = "Update bookIssue_staff set Status = 'Returned' where
AccessionNo='" & txtAccessionNo1.Text & "'"
cmd = New SqlCommand(cb2)
cmd.Connection = con
cmd.ExecuteNonQuery()
con.Close()
MessageBox.Show("Successfully returned", "Book",
MessageBoxButtons.OK, MessageBoxIcon.Information)
btnSave1.Enabled = False

Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
End Try
End Sub

Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles btnDelete.Click

Project by: Kuldeep Singh | 1053 Page 140


Library Management System

Try
If MessageBox.Show("Do you really want to delete this record?",
"Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) =
Windows.Forms.DialogResult.Yes Then
DeleteRecord()
End If
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
End Try
End Sub

Private Sub btnDelete1_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles btnDelete1.Click
Try
If MessageBox.Show("Do you really want to delete this record?",
"Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) =
Windows.Forms.DialogResult.Yes Then
DeleteRecord1()
End If
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
End Try
End Sub
Public Sub DeleteRecord()
Try
Dim RowsAffected As Integer = 0
con = New SqlConnection(cs)
con.Open()
Dim cq As String = "delete from Return_Student where ReturnID = '" &
txtReturnID.Text & "'"
cmd = New SqlCommand(cq)
cmd.Connection = con
RowsAffected = cmd.ExecuteNonQuery()
If RowsAffected > 0 Then
MessageBox.Show("Successfully deleted", "Record",
MessageBoxButtons.OK, MessageBoxIcon.Information)
Reset()
Else
MessageBox.Show("No record found", "Sorry", MessageBoxButtons.OK,
MessageBoxIcon.Information)
Reset()
If con.State = ConnectionState.Open Then
con.Close()
End If
con.Close()
End If
Catch ex As Exception

Project by: Kuldeep Singh | 1053 Page 141


Library Management System

MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,


MessageBoxIcon.Error)
End Try
End Sub
Public Sub DeleteRecord1()
Try
Dim RowsAffected As Integer = 0
con = New SqlConnection(cs)
con.Open()
Dim cq As String = "delete from Return_Staff where ReturnID = '" &
txtReturnID1.Text & "'"
cmd = New SqlCommand(cq)
cmd.Connection = con
RowsAffected = cmd.ExecuteNonQuery()
If RowsAffected > 0 Then
MessageBox.Show("Successfully deleted", "Record",
MessageBoxButtons.OK, MessageBoxIcon.Information)
Reset1()
Else
MessageBox.Show("No record found", "Sorry", MessageBoxButtons.OK,
MessageBoxIcon.Information)
Reset1()
If con.State = ConnectionState.Open Then
con.Close()
End If
con.Close()
End If
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
End Try
End Sub

Private Sub btnUpdate_record_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles btnUpdate_record.Click
Try
If Len(Trim(txtTransactionID.Text)) = 0 Then
MessageBox.Show("Please retrieve transaction id", "Input Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
txtTransactionID.Focus()
Exit Sub
End If
If (dtpReturnDate.Value.Date < dtpDueDate.Value.Date) Then
MessageBox.Show("Return date can not be less than due date", "Input
Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
dtpReturnDate.Focus()
Exit Sub
End If
If txtFine.Text = "" Then
txtFine.Text = 0

Project by: Kuldeep Singh | 1053 Page 142


Library Management System

End If
con = New SqlConnection(cs)
con.Open()
Dim cb As String = "update Return_student set TransactionID='" &
txtTransactionID.Text & "',ReturnDate='" & dtpReturnDate.Text & "',Fine='" &
txtFine.Text & "' where ReturnID='" & txtReturnID.Text & "'"
cmd = New SqlCommand(cb)
cmd.Connection = con
cmd.ExecuteNonQuery()
con.Close()
If (txtAccessionNo.Text <> TextBox1.Text) Then
con = New SqlConnection(cs)
con.Open()
Dim cb1 As String = "Update book set NoOfBooks = NoOfBooks - 1 where
AccessionNo='" & TextBox1.Text & "'"
cmd = New SqlCommand(cb1)
cmd.Connection = con
cmd.ExecuteNonQuery()
con.Close()
con = New SqlConnection(cs)
con.Open()
Dim cb2 As String = "Update book set NoOfBooks = NoOfBooks + 1
where AccessionNo='" & txtAccessionNo.Text & "'"
cmd = New SqlCommand(cb2)
cmd.Connection = con
cmd.ExecuteNonQuery()
con.Close()
con = New SqlConnection(cs)
con.Open()
Dim cb3 As String = "Update bookIssue_student set Status = 'Returned'
where AccessionNo='" & txtAccessionNo.Text & "'"
cmd = New SqlCommand(cb3)
cmd.Connection = con
cmd.ExecuteNonQuery()
con.Close()
con = New SqlConnection(cs)
con.Open()
Dim cb4 As String = "Update bookIssue_student set Status = 'Issued' where
AccessionNo='" & TextBox1.Text & "'"
cmd = New SqlCommand(cb4)
cmd.Connection = con
cmd.ExecuteNonQuery()
con.Close()
End If
MessageBox.Show("Successfully updated", "Record",
MessageBoxButtons.OK, MessageBoxIcon.Information)
btnUpdate_record.Enabled = False
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)

Project by: Kuldeep Singh | 1053 Page 143


Library Management System

End Try
End Sub

Private Sub btnUpdate1_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles btnUpdate1.Click
Try
If Len(Trim(txtTransactionID1.Text)) = 0 Then
MessageBox.Show("Please retrieve transaction id", "Input Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
txtTransactionID1.Focus()
Exit Sub
End If
If (dtpReturnDate1.Value.Date < dtpDueDate1.Value.Date) Then
MessageBox.Show("Return date can not be less than due date", "Input
Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
dtpReturnDate1.Focus()
Exit Sub
End If
If txtFine1.Text = "" Then
txtFine1.Text = 0
End If
con = New SqlConnection(cs)
con.Open()
Dim cb As String = "update Return_staff set TransactionID='" &
txtTransactionID1.Text & "',ReturnDate='" & dtpReturnDate1.Text & "',Fine='" &
txtFine1.Text & "' where ReturnID='" & txtReturnID1.Text & "'"
cmd = New SqlCommand(cb)
cmd.Connection = con
cmd.ExecuteNonQuery()
con.Close()
If (txtAccessionNo1.Text <> TextBox2.Text) Then
con = New SqlConnection(cs)
con.Open()
Dim cb1 As String = "Update book set NoOfBooks = NoOfBooks - 1 where
AccessionNo='" & TextBox2.Text & "'"
cmd = New SqlCommand(cb1)
cmd.Connection = con
cmd.ExecuteNonQuery()
con.Close()
con = New SqlConnection(cs)
con.Open()
Dim cb2 As String = "Update book set NoOfBooks = NoOfBooks + 1
where AccessionNo='" & txtAccessionNo1.Text & "'"
cmd = New SqlCommand(cb2)
cmd.Connection = con
cmd.ExecuteNonQuery()
con.Close()
con = New SqlConnection(cs)
con.Open()

Project by: Kuldeep Singh | 1053 Page 144


Library Management System

Dim cb3 As String = "Update bookIssue_staff set Status = 'Returned' where


AccessionNo='" & txtAccessionNo1.Text & "'"
cmd = New SqlCommand(cb3)
cmd.Connection = con
cmd.ExecuteNonQuery()
con.Close()
con = New SqlConnection(cs)
con.Open()
Dim cb4 As String = "Update bookIssue_staff set Status = 'Issued' where
AccessionNo='" & TextBox2.Text & "'"
cmd = New SqlCommand(cb4)
cmd.Connection = con
cmd.ExecuteNonQuery()
con.Close()
End If
MessageBox.Show("Successfully updated", "Record",
MessageBoxButtons.OK, MessageBoxIcon.Information)
btnUpdate1.Enabled = False
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
End Try
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button1.Click
frmBookIssueRecord_Staff2.Show()
frmBookIssueRecord_Staff2.Reset()
End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button3.Click
frmBookIssueRecord2.Show()
frmBookIssueRecord2.Reset()
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button2.Click
frmBookReturnRecord_Student.Show()
frmBookReturnRecord_Student.Reset()
End Sub

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button4.Click
frmBookReturnRecord_Staff.Show()
frmBookReturnRecord_Staff.Reset()
End Sub
End Class

frmBookRecord.vb
Project by: Kuldeep Singh | 1053 Page 145
Library Management System

Imports System.Data.SqlClient
Imports Excel = Microsoft.Office.Interop.Excel
Public Class frmBookRecord
Dim rdr As SqlDataReader = Nothing
Dim dtable As DataTable
Dim con As SqlConnection = Nothing
Dim adp As SqlDataAdapter
Dim ds As DataSet
Dim cmd As SqlCommand = Nothing
Dim dt As New DataTable
Dim gender As String
Dim cs As String = "Data Source=.\SQLEXPRESS;Initial
Catalog=LibraryDatabase;Integrated Security=True"

Private Sub ExportExcel_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles ExportExcel.Click
If dataGridView1.RowCount = Nothing Then
MessageBox.Show("Sorry nothing to export into excel sheet.." & vbCrLf &
"Please retrieve data in datagridview", "", MessageBoxButtons.OK,
MessageBoxIcon.Error)
Exit Sub
End If
Dim rowsTotal, colsTotal As Short
Dim I, j, iC As Short
System.Windows.Forms.Cursor.Current =
System.Windows.Forms.Cursors.WaitCursor
Dim xlApp As New Excel.Application
Try
Dim excelBook As Excel.Workbook = xlApp.Workbooks.Add
Dim excelWorksheet As Excel.Worksheet =
CType(excelBook.Worksheets(1), Excel.Worksheet)
xlApp.Visible = True

rowsTotal = dataGridView1.RowCount - 1
colsTotal = dataGridView1.Columns.Count - 1
With excelWorksheet
.Cells.Select()
.Cells.Delete()
For iC = 0 To colsTotal
.Cells(1, iC + 1).Value = dataGridView1.Columns(iC).HeaderText
Next
For I = 0 To rowsTotal - 1
For j = 0 To colsTotal
.Cells(I + 2, j + 1).value = dataGridView1.Rows(I).Cells(j).Value
Next j
Next I
.Rows("1:1").Font.FontStyle = "Bold"
.Rows("1:1").Font.Size = 12

.Cells.Columns.AutoFit()

Project by: Kuldeep Singh | 1053 Page 146


Library Management System

.Cells.Select()
.Cells.EntireColumn.AutoFit()
.Cells(1, 1).Select()
End With
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
Finally
'RELEASE ALLOACTED RESOURCES
System.Windows.Forms.Cursor.Current =
System.Windows.Forms.Cursors.Default
xlApp = Nothing
End Try
End Sub

Private Sub button7_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles button7.Click
If dataGridView2.RowCount = Nothing Then
MessageBox.Show("Sorry nothing to export into excel sheet.." & vbCrLf &
"Please retrieve data in datagridview", "", MessageBoxButtons.OK,
MessageBoxIcon.Error)
Exit Sub
End If
Dim rowsTotal, colsTotal As Short
Dim I, j, iC As Short
System.Windows.Forms.Cursor.Current =
System.Windows.Forms.Cursors.WaitCursor
Dim xlApp As New Excel.Application
Try
Dim excelBook As Excel.Workbook = xlApp.Workbooks.Add
Dim excelWorksheet As Excel.Worksheet =
CType(excelBook.Worksheets(1), Excel.Worksheet)
xlApp.Visible = True

rowsTotal = dataGridView2.RowCount - 1
colsTotal = dataGridView2.Columns.Count - 1
With excelWorksheet
.Cells.Select()
.Cells.Delete()
For iC = 0 To colsTotal
.Cells(1, iC + 1).Value = dataGridView2.Columns(iC).HeaderText
Next
For I = 0 To rowsTotal - 1
For j = 0 To colsTotal
.Cells(I + 2, j + 1).value = dataGridView2.Rows(I).Cells(j).Value
Next j
Next I
.Rows("1:1").Font.FontStyle = "Bold"
.Rows("1:1").Font.Size = 12

Project by: Kuldeep Singh | 1053 Page 147


Library Management System

.Cells.Columns.AutoFit()
.Cells.Select()
.Cells.EntireColumn.AutoFit()
.Cells(1, 1).Select()
End With
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
Finally
'RELEASE ALLOACTED RESOURCES
System.Windows.Forms.Cursor.Current =
System.Windows.Forms.Cursors.Default
xlApp = Nothing
End Try
End Sub

Private Sub button1_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles button1.Click
If dataGridView3.RowCount = Nothing Then
MessageBox.Show("Sorry nothing to export into excel sheet.." & vbCrLf &
"Please retrieve data in datagridview", "", MessageBoxButtons.OK,
MessageBoxIcon.Error)
Exit Sub
End If
Dim rowsTotal, colsTotal As Short
Dim I, j, iC As Short
System.Windows.Forms.Cursor.Current =
System.Windows.Forms.Cursors.WaitCursor
Dim xlApp As New Excel.Application
Try
Dim excelBook As Excel.Workbook = xlApp.Workbooks.Add
Dim excelWorksheet As Excel.Worksheet =
CType(excelBook.Worksheets(1), Excel.Worksheet)
xlApp.Visible = True

rowsTotal = dataGridView3.RowCount - 1
colsTotal = dataGridView3.Columns.Count - 1
With excelWorksheet
.Cells.Select()
.Cells.Delete()
For iC = 0 To colsTotal
.Cells(1, iC + 1).Value = dataGridView3.Columns(iC).HeaderText
Next
For I = 0 To rowsTotal - 1
For j = 0 To colsTotal
.Cells(I + 2, j + 1).value = dataGridView3.Rows(I).Cells(j).Value
Next j
Next I
.Rows("1:1").Font.FontStyle = "Bold"
.Rows("1:1").Font.Size = 12

Project by: Kuldeep Singh | 1053 Page 148


Library Management System

.Cells.Columns.AutoFit()
.Cells.Select()
.Cells.EntireColumn.AutoFit()
.Cells(1, 1).Select()
End With
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
Finally
'RELEASE ALLOACTED RESOURCES
System.Windows.Forms.Cursor.Current =
System.Windows.Forms.Cursors.Default
xlApp = Nothing
End Try
End Sub

Private Sub button3_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles button3.Click
If dataGridView4.RowCount = Nothing Then
MessageBox.Show("Sorry nothing to export into excel sheet.." & vbCrLf &
"Please retrieve data in datagridview", "", MessageBoxButtons.OK,
MessageBoxIcon.Error)
Exit Sub
End If
Dim rowsTotal, colsTotal As Short
Dim I, j, iC As Short
System.Windows.Forms.Cursor.Current =
System.Windows.Forms.Cursors.WaitCursor
Dim xlApp As New Excel.Application
Try
Dim excelBook As Excel.Workbook = xlApp.Workbooks.Add
Dim excelWorksheet As Excel.Worksheet =
CType(excelBook.Worksheets(1), Excel.Worksheet)
xlApp.Visible = True

rowsTotal = dataGridView4.RowCount - 1
colsTotal = dataGridView4.Columns.Count - 1
With excelWorksheet
.Cells.Select()
.Cells.Delete()
For iC = 0 To colsTotal
.Cells(1, iC + 1).Value = dataGridView4.Columns(iC).HeaderText
Next
For I = 0 To rowsTotal - 1
For j = 0 To colsTotal
.Cells(I + 2, j + 1).value = dataGridView4.Rows(I).Cells(j).Value
Next j
Next I
.Rows("1:1").Font.FontStyle = "Bold"

Project by: Kuldeep Singh | 1053 Page 149


Library Management System

.Rows("1:1").Font.Size = 12

.Cells.Columns.AutoFit()
.Cells.Select()
.Cells.EntireColumn.AutoFit()
.Cells(1, 1).Select()
End With
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
Finally
'RELEASE ALLOACTED RESOURCES
System.Windows.Forms.Cursor.Current =
System.Windows.Forms.Cursors.Default
xlApp = Nothing
End Try
End Sub

Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button10.Click
If DataGridView5.RowCount = Nothing Then
MessageBox.Show("Sorry nothing to export into excel sheet.." & vbCrLf &
"Please retrieve data in datagridview", "", MessageBoxButtons.OK,
MessageBoxIcon.Error)
Exit Sub
End If
Dim rowsTotal, colsTotal As Short
Dim I, j, iC As Short
System.Windows.Forms.Cursor.Current =
System.Windows.Forms.Cursors.WaitCursor
Dim xlApp As New Excel.Application
Try
Dim excelBook As Excel.Workbook = xlApp.Workbooks.Add
Dim excelWorksheet As Excel.Worksheet =
CType(excelBook.Worksheets(1), Excel.Worksheet)
xlApp.Visible = True

rowsTotal = DataGridView5.RowCount - 1
colsTotal = DataGridView5.Columns.Count - 1
With excelWorksheet
.Cells.Select()
.Cells.Delete()
For iC = 0 To colsTotal
.Cells(1, iC + 1).Value = DataGridView5.Columns(iC).HeaderText
Next
For I = 0 To rowsTotal - 1
For j = 0 To colsTotal
.Cells(I + 2, j + 1).value = DataGridView5.Rows(I).Cells(j).Value
Next j
Next I

Project by: Kuldeep Singh | 1053 Page 150


Library Management System

.Rows("1:1").Font.FontStyle = "Bold"
.Rows("1:1").Font.Size = 12

.Cells.Columns.AutoFit()
.Cells.Select()
.Cells.EntireColumn.AutoFit()
.Cells(1, 1).Select()
End With
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
Finally
'RELEASE ALLOACTED RESOURCES
System.Windows.Forms.Cursor.Current =
System.Windows.Forms.Cursors.Default
xlApp = Nothing
End Try
End Sub

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button4.Click
If DataGridView6.RowCount = Nothing Then
MessageBox.Show("Sorry nothing to export into excel sheet.." & vbCrLf &
"Please retrieve data in datagridview", "", MessageBoxButtons.OK,
MessageBoxIcon.Error)
Exit Sub
End If
Dim rowsTotal, colsTotal As Short
Dim I, j, iC As Short
System.Windows.Forms.Cursor.Current =
System.Windows.Forms.Cursors.WaitCursor
Dim xlApp As New Excel.Application
Try
Dim excelBook As Excel.Workbook = xlApp.Workbooks.Add
Dim excelWorksheet As Excel.Worksheet =
CType(excelBook.Worksheets(1), Excel.Worksheet)
xlApp.Visible = True

rowsTotal = DataGridView6.RowCount - 1
colsTotal = DataGridView6.Columns.Count - 1
With excelWorksheet
.Cells.Select()
.Cells.Delete()
For iC = 0 To colsTotal
.Cells(1, iC + 1).Value = DataGridView6.Columns(iC).HeaderText
Next
For I = 0 To rowsTotal - 1
For j = 0 To colsTotal
.Cells(I + 2, j + 1).value = DataGridView6.Rows(I).Cells(j).Value
Next j

Project by: Kuldeep Singh | 1053 Page 151


Library Management System

Next I
.Rows("1:1").Font.FontStyle = "Bold"
.Rows("1:1").Font.Size = 12

.Cells.Columns.AutoFit()
.Cells.Select()
.Cells.EntireColumn.AutoFit()
.Cells(1, 1).Select()
End With
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
Finally
'RELEASE ALLOACTED RESOURCES
System.Windows.Forms.Cursor.Current =
System.Windows.Forms.Cursors.Default
xlApp = Nothing
End Try
End Sub

Private Sub cmbBookTitle_SelectedIndexChanged(ByVal sender As


System.Object, ByVal e As System.EventArgs) Handles
cmbBookTitle.SelectedIndexChanged
Try
con = New SqlConnection(cs)
con.Open()
cmd = New SqlCommand("SELECT AccessionNo as [Accession No],
BookTitle as [Book Title], Author, JointAuthors as [Joint Authors], Subject,
Department, Barcode, ISBN, Volume, Edition, ClassNo as [Class No], Publisher,
PlaceOfPublisher as [Place Of Publisher], CD,PublishingYear as [Publishing Year],
Reference, NoOfBooks, AlmiraPosition as [Almira Position], Price, BillDate as [Bill
Date],SupplierName,Remarks from book where bookTitle='" & cmbBookTitle.Text
& "' order by BookTitle", con)
Dim myDA As SqlDataAdapter = New SqlDataAdapter(cmd)
Dim myDataSet As DataSet = New DataSet()
myDA.Fill(myDataSet, "Book")
dataGridView1.DataSource = myDataSet.Tables("Book").DefaultView
con.Close()
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
End Try
End Sub

Private Sub txtBookTitle_TextChanged(ByVal sender As System.Object, ByVal e


As System.EventArgs) Handles txtBookTitle.TextChanged
Try
con = New SqlConnection(cs)
con.Open()

Project by: Kuldeep Singh | 1053 Page 152


Library Management System

cmd = New SqlCommand("SELECT AccessionNo as [Accession No],


BookTitle as [Book Title], Author, JointAuthors as [Joint Authors], Subject,
Department, Barcode, ISBN, Volume, Edition, ClassNo as [Class No], Publisher,
PlaceOfPublisher as [Place Of Publisher], CD,PublishingYear as [Publishing Year],
Reference, NoOfBooks, AlmiraPosition as [Almira Position], Price, BillDate as [Bill
Date],SupplierName,Remarks from book where bookTitle like '" &
txtBookTitle.Text & "%' order by BookTitle", con)
Dim myDA As SqlDataAdapter = New SqlDataAdapter(cmd)
Dim myDataSet As DataSet = New DataSet()
myDA.Fill(myDataSet, "Book")
dataGridView1.DataSource = myDataSet.Tables("Book").DefaultView
con.Close()
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
End Try
End Sub

Private Sub button6_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles button6.Click
cmbBookTitle.Text = ""
txtBookTitle.Text = ""
dataGridView1.DataSource = Nothing
End Sub

Private Sub cmbAuthor_SelectedIndexChanged(ByVal sender As System.Object,


ByVal e As System.EventArgs) Handles cmbAuthor.SelectedIndexChanged
Try
con = New SqlConnection(cs)
con.Open()
cmd = New SqlCommand("SELECT AccessionNo as [Accession No],
BookTitle as [Book Title], Author, JointAuthors as [Joint Authors], Subject,
Department, Barcode, ISBN, Volume, Edition, ClassNo as [Class No], Publisher,
PlaceOfPublisher as [Place Of Publisher], CD,PublishingYear as [Publishing Year],
Reference, NoOfBooks, AlmiraPosition as [Almira Position], Price, BillDate as [Bill
Date],SupplierName,Remarks from book where Author='" & cmbAuthor.Text & "'
order by BookTitle", con)
Dim myDA As SqlDataAdapter = New SqlDataAdapter(cmd)
Dim myDataSet As DataSet = New DataSet()
myDA.Fill(myDataSet, "Book")
dataGridView2.DataSource = myDataSet.Tables("Book").DefaultView
con.Close()
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
End Try
End Sub

Private Sub txtAuthor_TextChanged(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles txtAuthor.TextChanged

Project by: Kuldeep Singh | 1053 Page 153


Library Management System

Try
con = New SqlConnection(cs)
con.Open()
cmd = New SqlCommand("SELECT AccessionNo as [Accession No],
BookTitle as [Book Title], Author, JointAuthors as [Joint Authors], Subject,
Department, Barcode, ISBN, Volume, Edition, ClassNo as [Class No], Publisher,
PlaceOfPublisher as [Place Of Publisher], CD,PublishingYear as [Publishing Year],
Reference, NoOfBooks, AlmiraPosition as [Almira Position], Price, BillDate as [Bill
Date],SupplierName,Remarks from book where Author like '" & txtAuthor.Text &
"%' order by BookTitle", con)
Dim myDA As SqlDataAdapter = New SqlDataAdapter(cmd)
Dim myDataSet As DataSet = New DataSet()
myDA.Fill(myDataSet, "Book")
dataGridView2.DataSource = myDataSet.Tables("Book").DefaultView
con.Close()
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
End Try
End Sub

Private Sub button9_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles button9.Click
txtAuthor.Text = ""
txtJointAuthors.Text = ""
cmbAuthor.Text = ""
dataGridView2.DataSource = Nothing
End Sub

Private Sub cmbAccessionNo_SelectedIndexChanged(ByVal sender As


System.Object, ByVal e As System.EventArgs) Handles
cmbAccessionNo.SelectedIndexChanged
Try
con = New SqlConnection(cs)
con.Open()
cmd = New SqlCommand("SELECT AccessionNo as [Accession No],
BookTitle as [Book Title], Author, JointAuthors as [Joint Authors], Subject,
Department, Barcode, ISBN, Volume, Edition, ClassNo as [Class No], Publisher,
PlaceOfPublisher as [Place Of Publisher], CD,PublishingYear as [Publishing Year],
Reference, NoOfBooks, AlmiraPosition as [Almira Position], Price, BillDate as [Bill
Date],SupplierName,Remarks from book where AccessionNo='" &
cmbAccessionNo.Text & "' order by BookTitle", con)
Dim myDA As SqlDataAdapter = New SqlDataAdapter(cmd)
Dim myDataSet As DataSet = New DataSet()
myDA.Fill(myDataSet, "Book")
dataGridView3.DataSource = myDataSet.Tables("Book").DefaultView
con.Close()
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)

Project by: Kuldeep Singh | 1053 Page 154


Library Management System

End Try
End Sub

Private Sub txtAccessionNo_TextChanged(ByVal sender As System.Object, ByVal


e As System.EventArgs) Handles txtAccessionNo.TextChanged
Try
con = New SqlConnection(cs)
con.Open()
cmd = New SqlCommand("SELECT AccessionNo as [Accession No],
BookTitle as [Book Title], Author, JointAuthors as [Joint Authors], Subject,
Department, Barcode, ISBN, Volume, Edition, ClassNo as [Class No], Publisher,
PlaceOfPublisher as [Place Of Publisher], CD,PublishingYear as [Publishing Year],
Reference, NoOfBooks, AlmiraPosition as [Almira Position], Price, BillDate as [Bill
Date],SupplierName,Remarks from book where AccessionNo like '" &
txtAccessionNo.Text & "%' order by BookTitle", con)
Dim myDA As SqlDataAdapter = New SqlDataAdapter(cmd)
Dim myDataSet As DataSet = New DataSet()
myDA.Fill(myDataSet, "Book")
dataGridView3.DataSource = myDataSet.Tables("Book").DefaultView
con.Close()
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
End Try
End Sub

Private Sub button2_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles button2.Click
txtAccessionNo.Text = ""
cmbAccessionNo.Text = ""
dataGridView3.DataSource = Nothing
End Sub

Private Sub cmbSubject_SelectedIndexChanged(ByVal sender As System.Object,


ByVal e As System.EventArgs) Handles cmbSubject.SelectedIndexChanged
Try
con = New SqlConnection(cs)
con.Open()
cmd = New SqlCommand("SELECT AccessionNo as [Accession No],
BookTitle as [Book Title], Author, JointAuthors as [Joint Authors], Subject,
Department, Barcode, ISBN, Volume, Edition, ClassNo as [Class No], Publisher,
PlaceOfPublisher as [Place Of Publisher], CD,PublishingYear as [Publishing Year],
Reference, NoOfBooks, AlmiraPosition as [Almira Position], Price, BillDate as [Bill
Date],SupplierName,Remarks from book where Subject='" & cmbSubject.Text & "'
order by BookTitle", con)
Dim myDA As SqlDataAdapter = New SqlDataAdapter(cmd)
Dim myDataSet As DataSet = New DataSet()
myDA.Fill(myDataSet, "Book")
dataGridView4.DataSource = myDataSet.Tables("Book").DefaultView
con.Close()

Project by: Kuldeep Singh | 1053 Page 155


Library Management System

Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
End Try
End Sub

Private Sub txtSubject_TextChanged(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles txtSubject.TextChanged
Try
con = New SqlConnection(cs)
con.Open()
cmd = New SqlCommand("SELECT AccessionNo as [Accession No],
BookTitle as [Book Title], Author, JointAuthors as [Joint Authors], Subject,
Department, Barcode, ISBN, Volume, Edition, ClassNo as [Class No], Publisher,
PlaceOfPublisher as [Place Of Publisher], CD,PublishingYear as [Publishing Year],
Reference, NoOfBooks, AlmiraPosition as [Almira Position], Price, BillDate as [Bill
Date],SupplierName,Remarks from book where Subject like '" & txtSubject.Text &
"%' order by BookTitle", con)
Dim myDA As SqlDataAdapter = New SqlDataAdapter(cmd)
Dim myDataSet As DataSet = New DataSet()
myDA.Fill(myDataSet, "Book")
dataGridView4.DataSource = myDataSet.Tables("Book").DefaultView
con.Close()
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
End Try
End Sub

Private Sub button8_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles button8.Click
txtSubject.Text = ""
cmbSubject.Text = ""
dataGridView4.DataSource = Nothing
End Sub

Private Sub Button12_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button12.Click
txtPOP.Text = ""
cmbPOP.Text = ""
DataGridView5.DataSource = Nothing
End Sub

Private Sub Button11_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button11.Click
txtDepartment.Text = ""
cmbDepartment.Text = ""
DataGridView6.DataSource = Nothing
End Sub

Project by: Kuldeep Singh | 1053 Page 156


Library Management System

Private Sub tabControl1_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles tabControl1.Click
Clear()
End Sub
Sub Clear()
DataGridView8.DataSource = Nothing
cmbRfBook.Text = ""
txtRFBooks.Text = ""
DataGridView7.DataSource = Nothing
txtPOP.Text = ""
cmbPOP.Text = ""
DataGridView5.DataSource = Nothing
txtDepartment.Text = ""
cmbDepartment.Text = ""
DataGridView6.DataSource = Nothing
txtSubject.Text = ""
cmbSubject.Text = ""
dataGridView4.DataSource = Nothing
txtAccessionNo.Text = ""
cmbAccessionNo.Text = ""
dataGridView3.DataSource = Nothing
txtAuthor.Text = ""
txtJointAuthors.Text = ""
cmbAuthor.Text = ""
dataGridView2.DataSource = Nothing
cmbBookTitle.Text = ""
txtBookTitle.Text = ""
dataGridView1.DataSource = Nothing
End Sub

Private Sub cmbPOP_SelectedIndexChanged(ByVal sender As System.Object,


ByVal e As System.EventArgs) Handles cmbPOP.SelectedIndexChanged
Try
con = New SqlConnection(cs)
con.Open()
cmd = New SqlCommand("SELECT AccessionNo as [Accession No],
BookTitle as [Book Title], Author, JointAuthors as [Joint Authors], Subject,
Department, Barcode, ISBN, Volume, Edition, ClassNo as [Class No], Publisher,
PlaceOfPublisher as [Place Of Publisher], CD,PublishingYear as [Publishing Year],
Reference, NoOfBooks as [No Of Books], AlmiraPosition as [Almira Position], Price,
BillDate as [Bill Date], Remarks from book where PlaceOfPublisher= '" &
cmbPOP.Text & "' order by BookTitle", con)
Dim myDA As SqlDataAdapter = New SqlDataAdapter(cmd)
Dim myDataSet As DataSet = New DataSet()
myDA.Fill(myDataSet, "Book")
DataGridView5.DataSource = myDataSet.Tables("Book").DefaultView
con.Close()
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)

Project by: Kuldeep Singh | 1053 Page 157


Library Management System

End Try
End Sub

Private Sub txtPOP_TextChanged(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles txtPOP.TextChanged
Try
con = New SqlConnection(cs)
con.Open()
cmd = New SqlCommand("SELECT AccessionNo as [Accession No],
BookTitle as [Book Title], Author, JointAuthors as [Joint Authors], Subject,
Department, Barcode, ISBN, Volume, Edition, ClassNo as [Class No], Publisher,
PlaceOfPublisher as [Place Of Publisher], CD,PublishingYear as [Publishing Year],
Reference, NoOfBooks, AlmiraPosition as [Almira Position], Price, BillDate as [Bill
Date],SupplierName,Remarks from book where PlaceOfPublisher like '" &
txtPOP.Text & "%' order by BookTitle", con)
Dim myDA As SqlDataAdapter = New SqlDataAdapter(cmd)
Dim myDataSet As DataSet = New DataSet()
myDA.Fill(myDataSet, "Book")
DataGridView5.DataSource = myDataSet.Tables("Book").DefaultView
con.Close()
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
End Try
End Sub

Private Sub txtDepartment_TextChanged(ByVal sender As System.Object, ByVal


e As System.EventArgs) Handles txtDepartment.TextChanged
Try
con = New SqlConnection(cs)
con.Open()
cmd = New SqlCommand("SELECT AccessionNo as [Accession No],
BookTitle as [Book Title], Author, JointAuthors as [Joint Authors], Subject,
Department, Barcode, ISBN, Volume, Edition, ClassNo as [Class No], Publisher,
PlaceOfPublisher as [Place Of Publisher], CD,PublishingYear as [Publishing Year],
Reference, NoOfBooks, AlmiraPosition as [Almira Position], Price, BillDate as [Bill
Date],SupplierName,Remarks from book where Department like '" &
txtDepartment.Text & "%' order by BookTitle", con)
Dim myDA As SqlDataAdapter = New SqlDataAdapter(cmd)
Dim myDataSet As DataSet = New DataSet()
myDA.Fill(myDataSet, "Book")
DataGridView6.DataSource = myDataSet.Tables("Book").DefaultView
con.Close()
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
End Try
End Sub

Project by: Kuldeep Singh | 1053 Page 158


Library Management System

Private Sub cmbDepartment_SelectedIndexChanged(ByVal sender As


System.Object, ByVal e As System.EventArgs) Handles
cmbDepartment.SelectedIndexChanged
Try
con = New SqlConnection(cs)
con.Open()
cmd = New SqlCommand("SELECT AccessionNo as [Accession No],
BookTitle as [Book Title], Author, JointAuthors as [Joint Authors], Subject,
Department, Barcode, ISBN, Volume, Edition, ClassNo as [Class No], Publisher,
PlaceOfPublisher as [Place Of Publisher], CD,PublishingYear as [Publishing Year],
Reference, NoOfBooks, AlmiraPosition as [Almira Position], Price, BillDate as [Bill
Date],SupplierName,Remarks from book where Department= '" &
cmbDepartment.Text & "' order by BookTitle", con)
Dim myDA As SqlDataAdapter = New SqlDataAdapter(cmd)
Dim myDataSet As DataSet = New DataSet()
myDA.Fill(myDataSet, "Book")
DataGridView6.DataSource = myDataSet.Tables("Book").DefaultView
con.Close()
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
End Try
End Sub
Sub fillSubject()
Try
cmbSubject.DataSource = Nothing
Dim CN As New SqlConnection(cs)
CN.Open()
adp = New SqlDataAdapter()
adp.SelectCommand = New SqlCommand("SELECT distinct Subject FROM
Book where subject is not null", CN)
ds = New DataSet("ds")
adp.Fill(ds)
dtable = ds.Tables(0)
cmbSubject.DisplayMember = "Subject"
cmbSubject.DataSource = dtable
cmbSubject.SelectedIndex = -1
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
End Try
End Sub
Sub fillBookTitle()
Try
cmbBookTitle.DataSource = Nothing
Dim CN As New SqlConnection(cs)
CN.Open()
adp = New SqlDataAdapter()
adp.SelectCommand = New SqlCommand("SELECT distinct BookTitle
FROM Book where BookTitle is not null", CN)

Project by: Kuldeep Singh | 1053 Page 159


Library Management System

ds = New DataSet("ds")
adp.Fill(ds)
dtable = ds.Tables(0)
cmbBookTitle.DisplayMember = "BookTitle"
cmbBookTitle.DataSource = dtable
cmbBookTitle.SelectedIndex = -1
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
End Try
End Sub
Sub fillAuthor()
Try
cmbAuthor.DataSource = Nothing
Dim CN As New SqlConnection(cs)
CN.Open()
adp = New SqlDataAdapter()
adp.SelectCommand = New SqlCommand("SELECT distinct Author FROM
Book where Author is not null", CN)
ds = New DataSet("ds")
adp.Fill(ds)
dtable = ds.Tables(0)
cmbAuthor.DisplayMember = "Author"
cmbAuthor.DataSource = dtable
cmbAuthor.SelectedIndex = -1
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
End Try
End Sub
Sub fillAccessionNo()
Try
cmbAccessionNo.DataSource = Nothing
Dim CN As New SqlConnection(cs)
CN.Open()
adp = New SqlDataAdapter()
adp.SelectCommand = New SqlCommand("SELECT distinct AccessionNo
FROM Book where AccessionNo is not null", CN)
ds = New DataSet("ds")
adp.Fill(ds)
dtable = ds.Tables(0)
cmbAccessionNo.DisplayMember = "AccessionNo"
cmbAccessionNo.DataSource = dtable
cmbAccessionNo.SelectedIndex = -1
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
End Try
End Sub
Sub fillPOP()

Project by: Kuldeep Singh | 1053 Page 160


Library Management System

Try
cmbPOP.DataSource = Nothing
Dim CN As New SqlConnection(cs)
CN.Open()
adp = New SqlDataAdapter()
adp.SelectCommand = New SqlCommand("SELECT distinct
PlaceOfPublisher FROM Book where PlaceOfPublisher is not null", CN)
ds = New DataSet("ds")
adp.Fill(ds)
dtable = ds.Tables(0)
cmbPOP.DisplayMember = "PlaceOfPublisher"
cmbPOP.DataSource = dtable
cmbPOP.SelectedIndex = -1
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
End Try
End Sub
Sub fillDepartment()
Try
cmbDepartment.DataSource = Nothing
Dim CN As New SqlConnection(cs)
CN.Open()
adp = New SqlDataAdapter()
adp.SelectCommand = New SqlCommand("SELECT distinct Department
FROM Book where Department is not null", CN)
ds = New DataSet("ds")
adp.Fill(ds)
dtable = ds.Tables(0)
cmbDepartment.DisplayMember = "Department"
cmbDepartment.DataSource = dtable
cmbDepartment.SelectedIndex = -1
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
End Try
End Sub
Private Sub frmBookRecord_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
fillAccessionNo()
fillAuthor()
fillBookTitle()
fillDepartment()
fillPOP()
fillSubject()
fillReferenceBook()
Clear()
End Sub

Project by: Kuldeep Singh | 1053 Page 161


Library Management System

Private Sub dataGridView1_RowPostPaint(ByVal sender As Object, ByVal e As


System.Windows.Forms.DataGridViewRowPostPaintEventArgs) Handles
dataGridView1.RowPostPaint
Dim strRowNumber As String = (e.RowIndex + 1).ToString()
Dim size As SizeF = e.Graphics.MeasureString(strRowNumber, Me.Font)
If dataGridView1.RowHeadersWidth < Convert.ToInt32((size.Width + 20))
Then
dataGridView1.RowHeadersWidth = Convert.ToInt32((size.Width + 20))
End If
Dim b As Brush = SystemBrushes.ControlText
e.Graphics.DrawString(strRowNumber, Me.Font, b, e.RowBounds.Location.X +
15, e.RowBounds.Location.Y + ((e.RowBounds.Height - size.Height) / 2))

End Sub

Private Sub dataGridView2_RowPostPaint(ByVal sender As Object, ByVal e As


System.Windows.Forms.DataGridViewRowPostPaintEventArgs) Handles
dataGridView2.RowPostPaint
Dim strRowNumber As String = (e.RowIndex + 1).ToString()
Dim size As SizeF = e.Graphics.MeasureString(strRowNumber, Me.Font)
If dataGridView2.RowHeadersWidth < Convert.ToInt32((size.Width + 20))
Then
dataGridView2.RowHeadersWidth = Convert.ToInt32((size.Width + 20))
End If
Dim b As Brush = SystemBrushes.ControlText
e.Graphics.DrawString(strRowNumber, Me.Font, b, e.RowBounds.Location.X +
15, e.RowBounds.Location.Y + ((e.RowBounds.Height - size.Height) / 2))

End Sub

Private Sub dataGridView3_RowPostPaint(ByVal sender As Object, ByVal e As


System.Windows.Forms.DataGridViewRowPostPaintEventArgs) Handles
dataGridView3.RowPostPaint
Dim strRowNumber As String = (e.RowIndex + 1).ToString()
Dim size As SizeF = e.Graphics.MeasureString(strRowNumber, Me.Font)
If dataGridView3.RowHeadersWidth < Convert.ToInt32((size.Width + 20))
Then
dataGridView3.RowHeadersWidth = Convert.ToInt32((size.Width + 20))
End If
Dim b As Brush = SystemBrushes.ControlText
e.Graphics.DrawString(strRowNumber, Me.Font, b, e.RowBounds.Location.X +
15, e.RowBounds.Location.Y + ((e.RowBounds.Height - size.Height) / 2))

End Sub

Private Sub dataGridView4_RowPostPaint(ByVal sender As Object, ByVal e As


System.Windows.Forms.DataGridViewRowPostPaintEventArgs) Handles
dataGridView4.RowPostPaint
Dim strRowNumber As String = (e.RowIndex + 1).ToString()

Project by: Kuldeep Singh | 1053 Page 162


Library Management System

Dim size As SizeF = e.Graphics.MeasureString(strRowNumber, Me.Font)


If dataGridView4.RowHeadersWidth < Convert.ToInt32((size.Width + 20))
Then
dataGridView4.RowHeadersWidth = Convert.ToInt32((size.Width + 20))
End If
Dim b As Brush = SystemBrushes.ControlText
e.Graphics.DrawString(strRowNumber, Me.Font, b, e.RowBounds.Location.X +
15, e.RowBounds.Location.Y + ((e.RowBounds.Height - size.Height) / 2))

End Sub

Private Sub DataGridView5_RowPostPaint(ByVal sender As Object, ByVal e As


System.Windows.Forms.DataGridViewRowPostPaintEventArgs) Handles
DataGridView5.RowPostPaint
Dim strRowNumber As String = (e.RowIndex + 1).ToString()
Dim size As SizeF = e.Graphics.MeasureString(strRowNumber, Me.Font)
If DataGridView5.RowHeadersWidth < Convert.ToInt32((size.Width + 20))
Then
DataGridView5.RowHeadersWidth = Convert.ToInt32((size.Width + 20))
End If
Dim b As Brush = SystemBrushes.ControlText
e.Graphics.DrawString(strRowNumber, Me.Font, b, e.RowBounds.Location.X +
15, e.RowBounds.Location.Y + ((e.RowBounds.Height - size.Height) / 2))

End Sub
Private Sub DataGridView6_RowPostPaint(ByVal sender As Object, ByVal e As
System.Windows.Forms.DataGridViewRowPostPaintEventArgs) Handles
DataGridView6.RowPostPaint
Dim strRowNumber As String = (e.RowIndex + 1).ToString()
Dim size As SizeF = e.Graphics.MeasureString(strRowNumber, Me.Font)
If DataGridView6.RowHeadersWidth < Convert.ToInt32((size.Width + 20))
Then
DataGridView6.RowHeadersWidth = Convert.ToInt32((size.Width + 20))
End If
Dim b As Brush = SystemBrushes.ControlText
e.Graphics.DrawString(strRowNumber, Me.Font, b, e.RowBounds.Location.X +
15, e.RowBounds.Location.Y + ((e.RowBounds.Height - size.Height) / 2))
End Sub

Private Sub txtJointAuthors_TextChanged(ByVal sender As System.Object, ByVal


e As System.EventArgs) Handles txtJointAuthors.TextChanged
Try
con = New SqlConnection(cs)
con.Open()
cmd = New SqlCommand("SELECT AccessionNo as [Accession No],
BookTitle as [Book Title], Author, JointAuthors as [Joint Authors], Subject,
Department, Barcode, ISBN, Volume, Edition, ClassNo as [Class No], Publisher,
PlaceOfPublisher as [Place Of Publisher], CD,PublishingYear as [Publishing Year],
Reference, NoOfBooks, AlmiraPosition as [Almira Position], Price, BillDate as [Bill

Project by: Kuldeep Singh | 1053 Page 163


Library Management System

Date],SupplierName,Remarks from book where JointAuthors like '%" &


txtJointAuthors.Text & "%' order by BookTitle", con)
Dim myDA As SqlDataAdapter = New SqlDataAdapter(cmd)
Dim myDataSet As DataSet = New DataSet()
myDA.Fill(myDataSet, "Book")
dataGridView2.DataSource = myDataSet.Tables("Book").DefaultView
con.Close()
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
End Try
End Sub

Private Sub DataGridView7_RowPostPaint(ByVal sender As Object, ByVal e As


System.Windows.Forms.DataGridViewRowPostPaintEventArgs) Handles
DataGridView7.RowPostPaint
Dim strRowNumber As String = (e.RowIndex + 1).ToString()
Dim size As SizeF = e.Graphics.MeasureString(strRowNumber, Me.Font)
If DataGridView7.RowHeadersWidth < Convert.ToInt32((size.Width + 20))
Then
DataGridView7.RowHeadersWidth = Convert.ToInt32((size.Width + 20))
End If
Dim b As Brush = SystemBrushes.ControlText
e.Graphics.DrawString(strRowNumber, Me.Font, b, e.RowBounds.Location.X +
15, e.RowBounds.Location.Y + ((e.RowBounds.Height - size.Height) / 2))

End Sub

Private Sub DataGridView8_RowPostPaint(ByVal sender As Object, ByVal e As


System.Windows.Forms.DataGridViewRowPostPaintEventArgs) Handles
DataGridView8.RowPostPaint
Dim strRowNumber As String = (e.RowIndex + 1).ToString()
Dim size As SizeF = e.Graphics.MeasureString(strRowNumber, Me.Font)
If DataGridView8.RowHeadersWidth < Convert.ToInt32((size.Width + 20))
Then
DataGridView8.RowHeadersWidth = Convert.ToInt32((size.Width + 20))
End If
Dim b As Brush = SystemBrushes.ControlText
e.Graphics.DrawString(strRowNumber, Me.Font, b, e.RowBounds.Location.X +
15, e.RowBounds.Location.Y + ((e.RowBounds.Height - size.Height) / 2))

End Sub

Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button5.Click
If DataGridView7.RowCount = Nothing Then
MessageBox.Show("Sorry nothing to export into excel sheet.." & vbCrLf &
"Please retrieve data in datagridview", "", MessageBoxButtons.OK,
MessageBoxIcon.Error)
Exit Sub

Project by: Kuldeep Singh | 1053 Page 164


Library Management System

End If
Dim rowsTotal, colsTotal As Short
Dim I, j, iC As Short
System.Windows.Forms.Cursor.Current =
System.Windows.Forms.Cursors.WaitCursor
Dim xlApp As New Excel.Application
Try
Dim excelBook As Excel.Workbook = xlApp.Workbooks.Add
Dim excelWorksheet As Excel.Worksheet =
CType(excelBook.Worksheets(1), Excel.Worksheet)
xlApp.Visible = True

rowsTotal = DataGridView7.RowCount - 1
colsTotal = DataGridView7.Columns.Count - 1
With excelWorksheet
.Cells.Select()
.Cells.Delete()
For iC = 0 To colsTotal
.Cells(1, iC + 1).Value = DataGridView7.Columns(iC).HeaderText
Next
For I = 0 To rowsTotal - 1
For j = 0 To colsTotal
.Cells(I + 2, j + 1).value = DataGridView7.Rows(I).Cells(j).Value
Next j
Next I
.Rows("1:1").Font.FontStyle = "Bold"
.Rows("1:1").Font.Size = 12

.Cells.Columns.AutoFit()
.Cells.Select()
.Cells.EntireColumn.AutoFit()
.Cells(1, 1).Select()
End With
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
Finally
'RELEASE ALLOACTED RESOURCES
System.Windows.Forms.Cursor.Current =
System.Windows.Forms.Cursors.Default
xlApp = Nothing
End Try
End Sub

Private Sub Button14_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button14.Click
If DataGridView8.RowCount = Nothing Then
MessageBox.Show("Sorry nothing to export into excel sheet.." & vbCrLf &
"Please retrieve data in datagridview", "", MessageBoxButtons.OK,
MessageBoxIcon.Error)

Project by: Kuldeep Singh | 1053 Page 165


Library Management System

Exit Sub
End If
Dim rowsTotal, colsTotal As Short
Dim I, j, iC As Short
System.Windows.Forms.Cursor.Current =
System.Windows.Forms.Cursors.WaitCursor
Dim xlApp As New Excel.Application
Try
Dim excelBook As Excel.Workbook = xlApp.Workbooks.Add
Dim excelWorksheet As Excel.Worksheet =
CType(excelBook.Worksheets(1), Excel.Worksheet)
xlApp.Visible = True

rowsTotal = DataGridView8.RowCount - 1
colsTotal = DataGridView8.Columns.Count - 1
With excelWorksheet
.Cells.Select()
.Cells.Delete()
For iC = 0 To colsTotal
.Cells(1, iC + 1).Value = DataGridView8.Columns(iC).HeaderText
Next
For I = 0 To rowsTotal - 1
For j = 0 To colsTotal
.Cells(I + 2, j + 1).value = DataGridView8.Rows(I).Cells(j).Value
Next j
Next I
.Rows("1:1").Font.FontStyle = "Bold"
.Rows("1:1").Font.Size = 12

.Cells.Columns.AutoFit()
.Cells.Select()
.Cells.EntireColumn.AutoFit()
.Cells(1, 1).Select()
End With
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
Finally
'RELEASE ALLOACTED RESOURCES
System.Windows.Forms.Cursor.Current =
System.Windows.Forms.Cursors.Default
xlApp = Nothing
End Try
End Sub

Private Sub Button16_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button16.Click
Try
con = New SqlConnection(cs)
con.Open()

Project by: Kuldeep Singh | 1053 Page 166


Library Management System

cmd = New SqlCommand("SELECT AccessionNo as [Accession No],


BookTitle as [Book Title], Author, JointAuthors as [Joint Authors], Subject,
Department, Barcode, ISBN, Volume, Edition, ClassNo as [Class No], Publisher,
PlaceOfPublisher as [Place Of Publisher], CD,PublishingYear as [Publishing Year],
Reference, NoOfBooks, AlmiraPosition as [Almira Position], Price, BillDate as [Bill
Date],SupplierName,Remarks from book order by BookTitle", con)
Dim myDA As SqlDataAdapter = New SqlDataAdapter(cmd)
Dim myDataSet As DataSet = New DataSet()
myDA.Fill(myDataSet, "Book")
DataGridView8.DataSource = myDataSet.Tables("Book").DefaultView
con.Close()
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
End Try
End Sub

Private Sub Button15_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button15.Click
DataGridView8.DataSource = Nothing
End Sub

Private Sub txtRFBooks_TextChanged(ByVal sender As System.Object, ByVal e


As System.EventArgs) Handles txtRFBooks.TextChanged
Try
con = New SqlConnection(cs)
con.Open()
cmd = New SqlCommand("SELECT AccessionNo as [Accession No],
BookTitle as [Book Title], Author, JointAuthors as [Joint Authors], Subject,
Department, Barcode, ISBN, Volume, Edition, ClassNo as [Class No], Publisher,
PlaceOfPublisher as [Place Of Publisher], CD,PublishingYear as [Publishing Year],
Reference, NoOfBooks, AlmiraPosition as [Almira Position], Price, BillDate as [Bill
Date],SupplierName,Remarks from book where reference > 0 and BookTitle like '" &
txtRFBooks.Text & "%' order by BookTitle", con)
Dim myDA As SqlDataAdapter = New SqlDataAdapter(cmd)
Dim myDataSet As DataSet = New DataSet()
myDA.Fill(myDataSet, "Book")
DataGridView7.DataSource = myDataSet.Tables("Book").DefaultView
con.Close()
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
End Try
End Sub

Private Sub cmbRfBook_SelectedIndexChanged(ByVal sender As System.Object,


ByVal e As System.EventArgs) Handles cmbRfBook.SelectedIndexChanged
Try
con = New SqlConnection(cs)
con.Open()

Project by: Kuldeep Singh | 1053 Page 167


Library Management System

cmd = New SqlCommand("SELECT AccessionNo as [Accession No],


BookTitle as [Book Title], Author, JointAuthors as [Joint Authors], Subject,
Department, Barcode, ISBN, Volume, Edition, ClassNo as [Class No], Publisher,
PlaceOfPublisher as [Place Of Publisher], CD,PublishingYear as [Publishing Year],
Reference, NoOfBooks, AlmiraPosition as [Almira Position], Price, BillDate as [Bill
Date],SupplierName,Remarks from book where reference > 0 and BookTitle = '" &
cmbRfBook.Text & "' order by BookTitle", con)
Dim myDA As SqlDataAdapter = New SqlDataAdapter(cmd)
Dim myDataSet As DataSet = New DataSet()
myDA.Fill(myDataSet, "Book")
DataGridView7.DataSource = myDataSet.Tables("Book").DefaultView
con.Close()
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
End Try
End Sub
Sub fillReferenceBook()
Try
cmbRfBook.DataSource = Nothing
Dim CN As New SqlConnection(cs)
CN.Open()
adp = New SqlDataAdapter()
adp.SelectCommand = New SqlCommand("SELECT distinct BookTitle
FROM Book where Reference > 0", CN)
ds = New DataSet("ds")
adp.Fill(ds)
dtable = ds.Tables(0)
cmbRfBook.DisplayMember = "BookTitle"
cmbRfBook.DataSource = dtable
cmbRfBook.SelectedIndex = -1
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
End Try
End Sub
Private Sub Button13_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button13.Click
cmbRfBook.Text = ""
txtRFBooks.Text = ""
DataGridView7.DataSource = Nothing
End Sub
End Class

frmLoginDetails.vb
Imports System.Data.SqlClient
Public Class frmLoginDetails
Dim rdr As SqlDataReader = Nothing
Dim con As SqlConnection = Nothing

Project by: Kuldeep Singh | 1053 Page 168


Library Management System

Dim cmd As SqlCommand = Nothing


Dim cs As String = "Data Source=.\SQLEXPRESS;Initial
Catalog=LibraryDatabase;Integrated Security=True"

Private Sub frmLoginDetails_Load(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles MyBase.Load
Try
con = New SqlConnection(cs)
con.Open()
cmd = New SqlCommand("SELECT Username,Usertype,password from
Registration order by RegisteredDate", con)
rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection)
DataGridView1.Rows.Clear()
While (rdr.Read() = True)
DataGridView1.Rows.Add(rdr(0), rdr(1), rdr(2))
End While
con.Close()
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
End Try
End Sub
End Class
frmBookIssueRecord_Staff.vb
Imports System.Data.SqlClient
Imports Excel = Microsoft.Office.Interop.Excel
Public Class frmBookIssueRecord_Staff
Dim rdr As SqlDataReader = Nothing
Dim dtable As DataTable
Dim con As SqlConnection = Nothing
Dim adp As SqlDataAdapter
Dim ds As DataSet
Dim cmd As SqlCommand = Nothing
Dim dt As New DataTable
Dim gender As String
Dim cs As String = "Data Source=.\SQLEXPRESS;Initial
Catalog=LibraryDatabase;Integrated Security=True"

Sub Reset()
txtBookName.Text = ""
txtBookName1.Text = ""
txtStaffName.Text = ""
cmbStaffName.Text = ""
cmbStaffName1.Text = ""
dtpDateFrom.Text = Today
dtpDateTo.Text = Today
DateTimePicker1.Text = Today
DateTimePicker2.Text = Today
DateTimePicker3.Text = Today

Project by: Kuldeep Singh | 1053 Page 169


Library Management System

DateTimePicker4.Text = Today
DateTimePicker5.Text = Today
DateTimePicker6.Text = Today
DateTimePicker7.Text = Today
DateTimePicker8.Text = Today
DataGridView1.DataSource = Nothing
End Sub
Sub fillStaffName()
Try
Dim CN As New SqlConnection(cs)
CN.Open()
adp = New SqlDataAdapter()
adp.SelectCommand = New SqlCommand("SELECT distinct
RTRIM(Staffname) FROM Staff,BookIssue_Staff where
Staff.StaffID=BookIssue_Staff.StaffID", CN)
ds = New DataSet("ds")
adp.Fill(ds)
dtable = ds.Tables(0)
cmbStaffName.Items.Clear()
cmbStaffName1.Items.Clear()
For Each drow As DataRow In dtable.Rows
cmbStaffName.Items.Add(drow(0).ToString())
cmbStaffName1.Items.Add(drow(0).ToString())
Next
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
End Try
End Sub
Private Sub frmBookIssueRecord_Load(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles MyBase.Load
fillStaffName()
End Sub

Private Sub txtBookName_TextChanged(ByVal sender As System.Object, ByVal e


As System.EventArgs) Handles txtBookName.TextChanged
Try
con = New SqlConnection(cs)
con.Open()
cmd = New SqlCommand("SELECT TransactionID as [Transaction ID],
IssueDate as [Issue Date], DueDate as [Due Date], Book.AccessionNo as [Accession
No],BookTitle as [Book Title],Author,Subject,ISBN,Edition,Staff.StaffID as [Staff
ID],StaffName as [Staff Name],Staff.Department, Status from
Book,BookIssue_Staff,Staff where
Book.AccessionNo=BookIssue_Staff.AccessionNo and
BookIssue_Staff.StaffID=Staff.StaffID and Issuedate Between '" &
dtpDateFrom.Text & "' and '" & dtpDateTo.Text & "' and BookTitle like '" &
txtBookName.Text & "%' order by Issuedate desc ", con)
Dim myDA As SqlDataAdapter = New SqlDataAdapter(cmd)
Dim myDataSet As DataSet = New DataSet()

Project by: Kuldeep Singh | 1053 Page 170


Library Management System

myDA.Fill(myDataSet, "BookIssue_Staff")
myDA.Fill(myDataSet, "Book")
myDA.Fill(myDataSet, "Staff")
DataGridView1.DataSource =
myDataSet.Tables("BookIssue_Staff").DefaultView
DataGridView1.DataSource = myDataSet.Tables("Book").DefaultView
DataGridView1.DataSource = myDataSet.Tables("Staff").DefaultView
con.Close()
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
End Try
End Sub

Private Sub btnReset_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles btnReset.Click
Reset()
End Sub

Private Sub btnExportExcel_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles btnExportExcel.Click
If DataGridView1.RowCount = Nothing Then
MessageBox.Show("Sorry nothing to export into excel sheet.." & vbCrLf &
"Please retrieve data in datagridview", "", MessageBoxButtons.OK,
MessageBoxIcon.Error)
Exit Sub
End If
Dim rowsTotal, colsTotal As Short
Dim I, j, iC As Short
System.Windows.Forms.Cursor.Current =
System.Windows.Forms.Cursors.WaitCursor
Dim xlApp As New Excel.Application
Try
Dim excelBook As Excel.Workbook = xlApp.Workbooks.Add
Dim excelWorksheet As Excel.Worksheet =
CType(excelBook.Worksheets(1), Excel.Worksheet)
xlApp.Visible = True

rowsTotal = DataGridView1.RowCount - 1
colsTotal = DataGridView1.Columns.Count - 1
With excelWorksheet
.Cells.Select()
.Cells.Delete()
For iC = 0 To colsTotal
.Cells(1, iC + 1).Value = DataGridView1.Columns(iC).HeaderText
Next
For I = 0 To rowsTotal - 1
For j = 0 To colsTotal
.Cells(I + 2, j + 1).value = DataGridView1.Rows(I).Cells(j).Value
Next j

Project by: Kuldeep Singh | 1053 Page 171


Library Management System

Next I
.Rows("1:1").Font.FontStyle = "Bold"
.Rows("1:1").Font.Size = 12

.Cells.Columns.AutoFit()
.Cells.Select()
.Cells.EntireColumn.AutoFit()
.Cells(1, 1).Select()
End With
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
Finally
'RELEASE ALLOACTED RESOURCES
System.Windows.Forms.Cursor.Current =
System.Windows.Forms.Cursors.Default
xlApp = Nothing
End Try
End Sub

Private Sub txtBookName1_TextChanged(ByVal sender As System.Object, ByVal


e As System.EventArgs) Handles txtBookName1.TextChanged
Try
con = New SqlConnection(cs)
con.Open()
cmd = New SqlCommand("SELECT TransactionID as [Transaction ID],
IssueDate as [Issue Date], DueDate as [Due Date], Book.AccessionNo as [Accession
No],BookTitle as [Book Title],Author,Subject,ISBN,Edition,Staff.StaffID as [Staff
ID],StaffName as [Staff Name],Staff.Department, Status from
Book,BookIssue_Staff,Staff where
Book.AccessionNo=BookIssue_Staff.AccessionNo and
BookIssue_Staff.StaffID=Staff.StaffID and DueDate Between '" &
DateTimePicker2.Text & "' and '" & DateTimePicker1.Text & "' and BookTitle like '"
& txtBookName1.Text & "%' order by DueDate desc ", con)
Dim myDA As SqlDataAdapter = New SqlDataAdapter(cmd)
Dim myDataSet As DataSet = New DataSet()
myDA.Fill(myDataSet, "BookIssue_Staff")
myDA.Fill(myDataSet, "Book")
myDA.Fill(myDataSet, "Staff")
DataGridView1.DataSource =
myDataSet.Tables("BookIssue_Staff").DefaultView
DataGridView1.DataSource = myDataSet.Tables("Book").DefaultView
DataGridView1.DataSource = myDataSet.Tables("Staff").DefaultView
con.Close()
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
End Try
End Sub

Project by: Kuldeep Singh | 1053 Page 172


Library Management System

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button1.Click
Try
con = New SqlConnection(cs)
con.Open()
cmd = New SqlCommand("SELECT TransactionID as [Transaction ID],
IssueDate as [Issue Date], DueDate as [Due Date], Book.AccessionNo as [Accession
No],BookTitle as [Book Title],Author,Subject,ISBN,Edition,Staff.StaffID as [Staff
ID],StaffName as [Staff Name],Staff.Department, Status from
Book,BookIssue_Staff,Staff where
Book.AccessionNo=BookIssue_Staff.AccessionNo and
BookIssue_Staff.StaffID=Staff.StaffID and IssueDate Between '" &
DateTimePicker8.Text & "' and '" & DateTimePicker7.Text & "' order by IssueDate
desc ", con)
Dim myDA As SqlDataAdapter = New SqlDataAdapter(cmd)
Dim myDataSet As DataSet = New DataSet()
myDA.Fill(myDataSet, "BookIssue_Staff")
myDA.Fill(myDataSet, "Book")
myDA.Fill(myDataSet, "Staff")
DataGridView1.DataSource =
myDataSet.Tables("BookIssue_Staff").DefaultView
DataGridView1.DataSource = myDataSet.Tables("Book").DefaultView
DataGridView1.DataSource = myDataSet.Tables("Staff").DefaultView
con.Close()
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
End Try
End Sub

Private Sub cmbStaffName_SelectedIndexChanged(ByVal sender As


System.Object, ByVal e As System.EventArgs) Handles
cmbStaffName.SelectedIndexChanged
Try
con = New SqlConnection(cs)
con.Open()
cmd = New SqlCommand("SELECT TransactionID as [Transaction ID],
IssueDate as [Issue Date], DueDate as [Due Date], Book.AccessionNo as [Accession
No],BookTitle as [Book Title],Author,Subject,ISBN,Edition,Staff.StaffID as [Staff
ID],StaffName as [Staff Name],Staff.Department, Status from
Book,BookIssue_Staff,Staff where
Book.AccessionNo=BookIssue_Staff.AccessionNo and
BookIssue_Staff.StaffID=Staff.StaffID and IssueDate Between '" &
DateTimePicker4.Text & "' and '" & DateTimePicker3.Text & "' and StaffName= '" &
cmbStaffName.Text & "' order by IssueDate desc ", con)
Dim myDA As SqlDataAdapter = New SqlDataAdapter(cmd)
Dim myDataSet As DataSet = New DataSet()
myDA.Fill(myDataSet, "BookIssue_Staff")
myDA.Fill(myDataSet, "Book")
myDA.Fill(myDataSet, "Staff")

Project by: Kuldeep Singh | 1053 Page 173


Library Management System

DataGridView1.DataSource =
myDataSet.Tables("BookIssue_Staff").DefaultView
DataGridView1.DataSource = myDataSet.Tables("Book").DefaultView
DataGridView1.DataSource = myDataSet.Tables("Staff").DefaultView
con.Close()
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
End Try
End Sub

Private Sub cmbStaffName1_SelectedIndexChanged(ByVal sender As


System.Object, ByVal e As System.EventArgs) Handles
cmbStaffName1.SelectedIndexChanged
Try
con = New SqlConnection(cs)
con.Open()
cmd = New SqlCommand("SELECT TransactionID as [Transaction ID],
IssueDate as [Issue Date], DueDate as [Due Date], Book.AccessionNo as [Accession
No],BookTitle as [Book Title],Author,Subject,ISBN,Edition,Staff.StaffID as [Staff
ID],StaffName as [Staff Name],Staff.Department, Status from
Book,BookIssue_Staff,Staff where
Book.AccessionNo=BookIssue_Staff.AccessionNo and
BookIssue_Staff.StaffID=Staff.StaffID and DueDate Between '" &
DateTimePicker6.Text & "' and '" & DateTimePicker5.Text & "' and StaffName= '" &
cmbStaffName1.Text & "' order by DueDate desc ", con)
Dim myDA As SqlDataAdapter = New SqlDataAdapter(cmd)
Dim myDataSet As DataSet = New DataSet()
myDA.Fill(myDataSet, "BookIssue_Staff")
myDA.Fill(myDataSet, "Book")
myDA.Fill(myDataSet, "Staff")
DataGridView1.DataSource =
myDataSet.Tables("BookIssue_Staff").DefaultView
DataGridView1.DataSource = myDataSet.Tables("Book").DefaultView
DataGridView1.DataSource = myDataSet.Tables("Staff").DefaultView
con.Close()
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
End Try
End Sub

Private Sub txtStaffName_TextChanged(ByVal sender As System.Object, ByVal e


As System.EventArgs) Handles txtStaffName.TextChanged
Try
con = New SqlConnection(cs)
con.Open()
cmd = New SqlCommand("SELECT TransactionID as [Transaction ID],
IssueDate as [Issue Date], DueDate as [Due Date], Book.AccessionNo as [Accession

Project by: Kuldeep Singh | 1053 Page 174


Library Management System

No],BookTitle as [Book Title],Author,Subject,ISBN,Edition,Staff.StaffID as [Staff


ID],StaffName as [Staff Name],Staff.Department, Status from
Book,BookIssue_Staff,Staff where
Book.AccessionNo=BookIssue_Staff.AccessionNo and
BookIssue_Staff.StaffID=Staff.StaffID and StaffName like '" & txtStaffName.Text &
"%' order by Staffname ", con)
Dim myDA As SqlDataAdapter = New SqlDataAdapter(cmd)
Dim myDataSet As DataSet = New DataSet()
myDA.Fill(myDataSet, "BookIssue_Staff")
myDA.Fill(myDataSet, "Book")
myDA.Fill(myDataSet, "Staff")
DataGridView1.DataSource =
myDataSet.Tables("BookIssue_Staff").DefaultView
DataGridView1.DataSource = myDataSet.Tables("Book").DefaultView
DataGridView1.DataSource = myDataSet.Tables("Staff").DefaultView
con.Close()
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
End Try
End Sub

Private Sub DataGridView1_RowHeaderMouseClick(ByVal sender As Object,


ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles
DataGridView1.RowHeaderMouseClick
Try
Dim dr As DataGridViewRow = DataGridView1.SelectedRows(0)
Me.Hide()
frmBookIssue.Show()
frmBookIssue.txtTransactionID1.Text = dr.Cells(0).Value.ToString()
frmBookIssue.dtpIssueDate1.Text = dr.Cells(1).Value.ToString()
frmBookIssue.dtpDueDate1.Text = dr.Cells(2).Value.ToString()
frmBookIssue.cmbAccessionNo1.Text = dr.Cells(3).Value.ToString()
frmBookIssue.TextBox2.Text = dr.Cells(3).Value.ToString()
frmBookIssue.txtBookTitle1.Text = dr.Cells(4).Value.ToString()
frmBookIssue.txtAuthor1.Text = dr.Cells(5).Value.ToString()
frmBookIssue.txtCategory1.Text = dr.Cells(6).Value.ToString()
frmBookIssue.txtISBN1.Text = dr.Cells(7).Value.ToString()
frmBookIssue.txtEdition1.Text = dr.Cells(8).Value.ToString()
frmBookIssue.cmbStaffID.Text = dr.Cells(9).Value.ToString()
frmBookIssue.txtStaffName.Text = dr.Cells(10).Value.ToString()
frmBookIssue.txtDepartment1.Text = dr.Cells(11).Value.ToString()
frmBookIssue.txtStatus1.Text = dr.Cells(12).Value.ToString()
frmBookIssue.btnUpdate1.Enabled = True
frmBookIssue.btnDelete1.Enabled = True
frmBookIssue.btnSave1.Enabled = False
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
End Try

Project by: Kuldeep Singh | 1053 Page 175


Library Management System

End Sub

Private Sub DataGridView1_RowPostPaint(ByVal sender As Object, ByVal e As


System.Windows.Forms.DataGridViewRowPostPaintEventArgs) Handles
DataGridView1.RowPostPaint
Dim strRowNumber As String = (e.RowIndex + 1).ToString()
Dim size As SizeF = e.Graphics.MeasureString(strRowNumber, Me.Font)
If DataGridView1.RowHeadersWidth < Convert.ToInt32((size.Width + 20))
Then
DataGridView1.RowHeadersWidth = Convert.ToInt32((size.Width + 20))
End If
Dim b As Brush = SystemBrushes.ControlText
e.Graphics.DrawString(strRowNumber, Me.Font, b, e.RowBounds.Location.X +
15, e.RowBounds.Location.Y + ((e.RowBounds.Height - size.Height) / 2))

End Sub

Private Sub dtpDateTo_Validating(ByVal sender As System.Object, ByVal e As


System.ComponentModel.CancelEventArgs) Handles dtpDateTo.Validating
If (dtpDateFrom.Value.Date) > (dtpDateTo.Value.Date) Then
MessageBox.Show("Invalid Selection", "Input Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
dtpDateTo.Focus()
End If
End Sub

Private Sub DateTimePicker1_Validating(ByVal sender As System.Object, ByVal


e As System.ComponentModel.CancelEventArgs) Handles
DateTimePicker1.Validating
If (DateTimePicker2.Value.Date) > (DateTimePicker1.Value.Date) Then
MessageBox.Show("Invalid Selection", "Input Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
DateTimePicker1.Focus()
End If
End Sub

Private Sub DateTimePicker7_Validating(ByVal sender As System.Object, ByVal


e As System.ComponentModel.CancelEventArgs) Handles
DateTimePicker7.Validating
If (DateTimePicker8.Value.Date) > (DateTimePicker7.Value.Date) Then
MessageBox.Show("Invalid Selection", "Input Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
DateTimePicker7.Focus()
End If
End Sub

Private Sub DateTimePicker3_Validating(ByVal sender As System.Object, ByVal


e As System.ComponentModel.CancelEventArgs) Handles
DateTimePicker3.Validating
If (DateTimePicker4.Value.Date) > (DateTimePicker3.Value.Date) Then

Project by: Kuldeep Singh | 1053 Page 176


Library Management System

MessageBox.Show("Invalid Selection", "Input Error",


MessageBoxButtons.OK, MessageBoxIcon.Error)
DateTimePicker3.Focus()
End If
End Sub

Private Sub DateTimePicker5_Validating(ByVal sender As System.Object, ByVal


e As System.ComponentModel.CancelEventArgs) Handles
DateTimePicker5.Validating
If (DateTimePicker6.Value.Date) > (DateTimePicker5.Value.Date) Then
MessageBox.Show("Invalid Selection", "Input Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
DateTimePicker5.Focus()
End If
End Sub
End Class

frmBookReturnRecord_Staff.vb
Imports System.Data.SqlClient
Imports Excel = Microsoft.Office.Interop.Excel
Public Class frmBookReturnRecord_Staff
Dim rdr As SqlDataReader = Nothing
Dim dtable As DataTable
Dim con As SqlConnection = Nothing
Dim adp As SqlDataAdapter
Dim ds As DataSet
Dim cmd As SqlCommand = Nothing
Dim dt As New DataTable
Dim gender As String
Dim cs As String = "Data Source=.\SQLEXPRESS;Initial
Catalog=LibraryDatabase;Integrated Security=True"
Sub Reset()
txtBookName.Text = ""
txtStaffName.Text = ""
cmbStaffName.Text = ""
DateTimePicker1.Text = Today
DateTimePicker2.Text = Today
dtpDateFrom.Text = Today
dtpDateTo.Text = Today
DateTimePicker3.Text = Today
DateTimePicker4.Text = Today
DateTimePicker7.Text = Today
DateTimePicker8.Text = Today
DataGridView1.DataSource = Nothing
End Sub
Sub fillStaffName()
Try
Dim CN As New SqlConnection(cs)
CN.Open()
adp = New SqlDataAdapter()

Project by: Kuldeep Singh | 1053 Page 177


Library Management System

adp.SelectCommand = New SqlCommand("SELECT distinct


RTRIM(Staffname) FROM Staff,BookIssue_Staff,Return_Staff where
Staff.StaffID=BookIssue_Staff.StaffID and
BookIssue_Staff.TransactionID=Return_Staff.TransactionID", CN)
ds = New DataSet("ds")
adp.Fill(ds)
dtable = ds.Tables(0)
cmbStaffName.Items.Clear()
For Each drow As DataRow In dtable.Rows
cmbStaffName.Items.Add(drow(0).ToString())
Next
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
End Try
End Sub
Private Sub frmBookIssueRecord_Load(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles MyBase.Load
fillStaffName()
End Sub

Private Sub txtBookName_TextChanged(ByVal sender As System.Object, ByVal e


As System.EventArgs) Handles txtBookName.TextChanged
Try
con = New SqlConnection(cs)
con.Open()
cmd = New SqlCommand("SELECT ReturnID as [Return ID],ReturnDate as
[Return Date],Fine, BookIssue_Staff.TransactionID as [Transaction ID], IssueDate as
[Issue Date], DueDate as [Due Date], Book.AccessionNo as [Accession
No],BookTitle as [Book Title],Author,Subject,ISBN,Edition,Staff.StaffID as [Staff
ID],StaffName as [Staff Name],Staff.Department from
Book,BookIssue_Staff,Staff,Return_Staff where
Book.AccessionNo=BookIssue_Staff.AccessionNo and
BookIssue_Staff.StaffID=Staff.StaffID and
BookIssue_Staff.TransactionID=Return_Staff.TransactionID and Returndate Between
'" & dtpDateFrom.Text & "' and '" & dtpDateTo.Text & "' and BookTitle like '" &
txtBookName.Text & "%' order by Returndate desc ", con)
Dim myDA As SqlDataAdapter = New SqlDataAdapter(cmd)
Dim myDataSet As DataSet = New DataSet()

myDA.Fill(myDataSet, "Return_Staff")

DataGridView1.DataSource =
myDataSet.Tables("Return_Staff").DefaultView
con.Close()
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
End Try
End Sub

Project by: Kuldeep Singh | 1053 Page 178


Library Management System

Private Sub btnReset_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles btnReset.Click
Reset()
End Sub

Private Sub btnExportExcel_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles btnExportExcel.Click
If DataGridView1.RowCount = Nothing Then
MessageBox.Show("Sorry nothing to export into excel sheet.." & vbCrLf &
"Please retrieve data in datagridview", "", MessageBoxButtons.OK,
MessageBoxIcon.Error)
Exit Sub
End If
Dim rowsTotal, colsTotal As Short
Dim I, j, iC As Short
System.Windows.Forms.Cursor.Current =
System.Windows.Forms.Cursors.WaitCursor
Dim xlApp As New Excel.Application
Try
Dim excelBook As Excel.Workbook = xlApp.Workbooks.Add
Dim excelWorksheet As Excel.Worksheet =
CType(excelBook.Worksheets(1), Excel.Worksheet)
xlApp.Visible = True

rowsTotal = DataGridView1.RowCount - 1
colsTotal = DataGridView1.Columns.Count - 1
With excelWorksheet
.Cells.Select()
.Cells.Delete()
For iC = 0 To colsTotal
.Cells(1, iC + 1).Value = DataGridView1.Columns(iC).HeaderText
Next
For I = 0 To rowsTotal - 1
For j = 0 To colsTotal
.Cells(I + 2, j + 1).value = DataGridView1.Rows(I).Cells(j).Value
Next j
Next I
.Rows("1:1").Font.FontStyle = "Bold"
.Rows("1:1").Font.Size = 12

.Cells.Columns.AutoFit()
.Cells.Select()
.Cells.EntireColumn.AutoFit()
.Cells(1, 1).Select()
End With
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
Finally

Project by: Kuldeep Singh | 1053 Page 179


Library Management System

'RELEASE ALLOACTED RESOURCES


System.Windows.Forms.Cursor.Current =
System.Windows.Forms.Cursors.Default
xlApp = Nothing
End Try
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button1.Click
Try
con = New SqlConnection(cs)
con.Open()
cmd = New SqlCommand("SELECT ReturnID as [Return ID],ReturnDate as
[Return Date],Fine, BookIssue_Staff.TransactionID as [Transaction ID], IssueDate as
[Issue Date], DueDate as [Due Date], Book.AccessionNo as [Accession
No],BookTitle as [Book Title],Author,Subject,ISBN,Edition,Staff.StaffID as [Staff
ID],StaffName as [Staff Name],Staff.Department from
Book,BookIssue_Staff,Staff,Return_Staff where
Book.AccessionNo=BookIssue_Staff.AccessionNo and
BookIssue_Staff.StaffID=Staff.StaffID and
BookIssue_Staff.TransactionID=Return_Staff.TransactionID and Returndate Between
'" & DateTimePicker8.Text & "' and '" & DateTimePicker7.Text & "' order by
Returndate desc ", con)
Dim myDA As SqlDataAdapter = New SqlDataAdapter(cmd)
Dim myDataSet As DataSet = New DataSet()
myDA.Fill(myDataSet, "BookIssue_Staff")
myDA.Fill(myDataSet, "Book")
myDA.Fill(myDataSet, "Staff")
myDA.Fill(myDataSet, "Return_Staff")
DataGridView1.DataSource =
myDataSet.Tables("BookIssue_Staff").DefaultView
DataGridView1.DataSource = myDataSet.Tables("Book").DefaultView
DataGridView1.DataSource = myDataSet.Tables("Staff").DefaultView
DataGridView1.DataSource =
myDataSet.Tables("Return_Staff").DefaultView
con.Close()
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
End Try
End Sub

Private Sub cmbStaffName_SelectedIndexChanged(ByVal sender As


System.Object, ByVal e As System.EventArgs) Handles
cmbStaffName.SelectedIndexChanged
Try
con = New SqlConnection(cs)
con.Open()

Project by: Kuldeep Singh | 1053 Page 180


Library Management System

cmd = New SqlCommand("SELECT ReturnID as [Return ID],ReturnDate as


[Return Date],Fine, BookIssue_Staff.TransactionID as [Transaction ID], IssueDate as
[Issue Date], DueDate as [Due Date], Book.AccessionNo as [Accession
No],BookTitle as [Book Title],Author,Subject,ISBN,Edition,Staff.StaffID as [Staff
ID],StaffName as [Staff Name],Staff.Department from
Book,BookIssue_Staff,Staff,Return_Staff where
Book.AccessionNo=BookIssue_Staff.AccessionNo and
BookIssue_Staff.StaffID=Staff.StaffID and
BookIssue_Staff.TransactionID=Return_Staff.TransactionID and ReturnDate
Between '" & DateTimePicker4.Text & "' and '" & DateTimePicker3.Text & "' and
StaffName= '" & cmbStaffName.Text & "' order by ReturnDate desc ", con)
Dim myDA As SqlDataAdapter = New SqlDataAdapter(cmd)
Dim myDataSet As DataSet = New DataSet()
myDA.Fill(myDataSet, "BookIssue_Staff")
myDA.Fill(myDataSet, "Book")
myDA.Fill(myDataSet, "Staff")
myDA.Fill(myDataSet, "Return_Staff")
DataGridView1.DataSource =
myDataSet.Tables("BookIssue_Staff").DefaultView
DataGridView1.DataSource = myDataSet.Tables("Book").DefaultView
DataGridView1.DataSource = myDataSet.Tables("Staff").DefaultView
DataGridView1.DataSource =
myDataSet.Tables("Return_Staff").DefaultView
con.Close()
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
End Try
End Sub

Private Sub txtStaffName_TextChanged(ByVal sender As System.Object, ByVal e


As System.EventArgs) Handles txtStaffName.TextChanged
Try
con = New SqlConnection(cs)
con.Open()
cmd = New SqlCommand("SELECT ReturnID as [Return ID],ReturnDate as
[Return Date],Fine, BookIssue_Staff.TransactionID as [Transaction ID], IssueDate as
[Issue Date], DueDate as [Due Date], Book.AccessionNo as [Accession
No],BookTitle as [Book Title],Author,Subject,ISBN,Edition,Staff.StaffID as [Staff
ID],StaffName as [Staff Name],Staff.Department from
Book,BookIssue_Staff,Staff,Return_Staff where
Book.AccessionNo=BookIssue_Staff.AccessionNo and
BookIssue_Staff.StaffID=Staff.StaffID and
BookIssue_Staff.TransactionID=Return_Staff.TransactionID and StaffName like '" &
txtStaffName.Text & "%' order by Staffname ", con)
Dim myDA As SqlDataAdapter = New SqlDataAdapter(cmd)
Dim myDataSet As DataSet = New DataSet()
myDA.Fill(myDataSet, "BookIssue_Staff")
myDA.Fill(myDataSet, "Book")

Project by: Kuldeep Singh | 1053 Page 181


Library Management System

myDA.Fill(myDataSet, "Staff")
myDA.Fill(myDataSet, "Return_Staff")
DataGridView1.DataSource =
myDataSet.Tables("BookIssue_Staff").DefaultView
DataGridView1.DataSource = myDataSet.Tables("Book").DefaultView
DataGridView1.DataSource = myDataSet.Tables("Staff").DefaultView
DataGridView1.DataSource =
myDataSet.Tables("Return_Staff").DefaultView
con.Close()
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
End Try
End Sub

Private Sub DataGridView1_RowHeaderMouseClick(ByVal sender As Object,


ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles
DataGridView1.RowHeaderMouseClick
Try
Dim dr As DataGridViewRow = DataGridView1.SelectedRows(0)
Me.Hide()
frmBookReturn.Show()
frmBookReturn.txtReturnID1.Text = dr.Cells(0).Value.ToString()
frmBookReturn.dtpReturnDate1.Text = dr.Cells(1).Value.ToString()
frmBookReturn.txtFine1.Text = dr.Cells(2).Value.ToString()
frmBookReturn.txtTransactionID1.Text = dr.Cells(3).Value.ToString()
frmBookReturn.dtpIssueDate1.Text = dr.Cells(4).Value.ToString()
frmBookReturn.dtpDueDate1.Text = dr.Cells(5).Value.ToString()
frmBookReturn.txtAccessionNo1.Text = dr.Cells(6).Value.ToString()
frmBookReturn.TextBox2.Text = dr.Cells(6).Value.ToString()
frmBookReturn.txtBookTitle1.Text = dr.Cells(7).Value.ToString()
frmBookReturn.txtAuthor1.Text = dr.Cells(8).Value.ToString()
frmBookReturn.txtCategory1.Text = dr.Cells(9).Value.ToString()
frmBookReturn.txtISBN1.Text = dr.Cells(10).Value.ToString()
frmBookReturn.txtEdition1.Text = dr.Cells(11).Value.ToString()
frmBookReturn.txtStaffID.Text = dr.Cells(12).Value.ToString()
frmBookReturn.txtStaffName.Text = dr.Cells(13).Value.ToString()
frmBookReturn.txtDepartment1.Text = dr.Cells(14).Value.ToString()
frmBookReturn.btnUpdate1.Enabled = True
frmBookReturn.btnDelete1.Enabled = True
frmBookReturn.btnSave1.Enabled = False
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
End Try
End Sub

Private Sub DataGridView1_RowPostPaint(ByVal sender As Object, ByVal e As


System.Windows.Forms.DataGridViewRowPostPaintEventArgs) Handles
DataGridView1.RowPostPaint

Project by: Kuldeep Singh | 1053 Page 182


Library Management System

Dim strRowNumber As String = (e.RowIndex + 1).ToString()


Dim size As SizeF = e.Graphics.MeasureString(strRowNumber, Me.Font)
If DataGridView1.RowHeadersWidth < Convert.ToInt32((size.Width + 20))
Then
DataGridView1.RowHeadersWidth = Convert.ToInt32((size.Width + 20))
End If
Dim b As Brush = SystemBrushes.ControlText
e.Graphics.DrawString(strRowNumber, Me.Font, b, e.RowBounds.Location.X +
15, e.RowBounds.Location.Y + ((e.RowBounds.Height - size.Height) / 2))

End Sub

Private Sub dtpDateTo_Validating(ByVal sender As System.Object, ByVal e As


System.ComponentModel.CancelEventArgs) Handles dtpDateTo.Validating
If (dtpDateFrom.Value.Date) > (dtpDateTo.Value.Date) Then
MessageBox.Show("Invalid Selection", "Input Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
dtpDateTo.Focus()
End If
End Sub

Private Sub DateTimePicker7_Validating(ByVal sender As System.Object, ByVal


e As System.ComponentModel.CancelEventArgs) Handles
DateTimePicker7.Validating
If (DateTimePicker8.Value.Date) > (DateTimePicker7.Value.Date) Then
MessageBox.Show("Invalid Selection", "Input Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
DateTimePicker7.Focus()
End If
End Sub

Private Sub DateTimePicker3_Validating(ByVal sender As System.Object, ByVal


e As System.ComponentModel.CancelEventArgs) Handles
DateTimePicker3.Validating
If (DateTimePicker4.Value.Date) > (DateTimePicker3.Value.Date) Then
MessageBox.Show("Invalid Selection", "Input Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
DateTimePicker3.Focus()
End If
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button2.Click
Try
con = New SqlConnection(cs)
con.Open()
cmd = New SqlCommand("SELECT ReturnID as [Return ID],ReturnDate as
[Return Date],Fine, BookIssue_Staff.TransactionID as [Transaction ID], IssueDate as
[Issue Date], DueDate as [Due Date], Book.AccessionNo as [Accession
No],BookTitle as [Book Title],Author,Subject,ISBN,Edition,Staff.StaffID as [Staff

Project by: Kuldeep Singh | 1053 Page 183


Library Management System

ID],StaffName as [Staff Name],Staff.Department from


Book,BookIssue_Staff,Staff,Return_Staff where
Book.AccessionNo=BookIssue_Staff.AccessionNo and
BookIssue_Staff.StaffID=Staff.StaffID and
BookIssue_Staff.TransactionID=Return_Staff.TransactionID and Returndate Between
'" & DateTimePicker2.Text & "' and '" & DateTimePicker1.Text & "' and Fine > 0
order by Returndate desc ", con)
Dim myDA As SqlDataAdapter = New SqlDataAdapter(cmd)
Dim myDataSet As DataSet = New DataSet()
myDA.Fill(myDataSet, "BookIssue_Staff")
myDA.Fill(myDataSet, "Book")
myDA.Fill(myDataSet, "Staff")
myDA.Fill(myDataSet, "Return_Staff")
DataGridView1.DataSource =
myDataSet.Tables("BookIssue_Staff").DefaultView
DataGridView1.DataSource = myDataSet.Tables("Book").DefaultView
DataGridView1.DataSource = myDataSet.Tables("Staff").DefaultView
DataGridView1.DataSource =
myDataSet.Tables("Return_Staff").DefaultView
con.Close()
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
End Try
End Sub

Private Sub DateTimePicker1_Validating(ByVal sender As System.Object, ByVal


e As System.ComponentModel.CancelEventArgs) Handles
DateTimePicker1.Validating
If (DateTimePicker2.Value.Date) > (DateTimePicker1.Value.Date) Then
MessageBox.Show("Invalid Selection", "Input Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
DateTimePicker1.Focus()
End If
End Sub
End Class

frmBookReturnRecord_Student.vb
Imports System.Data.SqlClient
Imports Excel = Microsoft.Office.Interop.Excel
Public Class frmBookReturnRecord_Student
Dim rdr As SqlDataReader = Nothing
Dim dtable As DataTable
Dim con As SqlConnection = Nothing
Dim adp As SqlDataAdapter
Dim ds As DataSet
Dim cmd As SqlCommand = Nothing
Dim dt As New DataTable
Dim gender As String

Project by: Kuldeep Singh | 1053 Page 184


Library Management System

Dim cs As String = "Data Source=.\SQLEXPRESS;Initial


Catalog=LibraryDatabase;Integrated Security=True"

Sub Reset()
txtBookName.Text = ""
txtStudentName.Text = ""
cmbStudentName.Text = ""
DateTimePicker1.Text = Today
DateTimePicker2.Text = Today
dtpDateFrom.Text = Today
dtpDateTo.Text = Today
DateTimePicker3.Text = Today
DateTimePicker4.Text = Today
DateTimePicker7.Text = Today
DateTimePicker8.Text = Today
DataGridView1.DataSource = Nothing
End Sub
Sub fillStudentName()
Try
cmbStudentName.DataSource = Nothing
Dim CN As New SqlConnection(cs)
CN.Open()
adp = New SqlDataAdapter()
adp.SelectCommand = New SqlCommand("SELECT distinct Studentname
FROM Student,BookIssue_Student,Return_Student where
Student.StudentID=BookIssue_Student.StudentID and
BookIssue_Student.TransactionID=Return_Student.TransactionID", CN)
ds = New DataSet("ds")
adp.Fill(ds)
dtable = ds.Tables(0)
cmbStudentName.DisplayMember = "StudentName"
cmbStudentName.DataSource = dtable
cmbStudentName.SelectedIndex = -1
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
End Try
End Sub
Private Sub frmBookIssueRecord_Load(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles MyBase.Load
fillStudentName()
End Sub

Private Sub txtBookName_TextChanged(ByVal sender As System.Object, ByVal e


As System.EventArgs) Handles txtBookName.TextChanged
Try

cmd = New SqlCommand("SELECT TransactionID as [Transaction ID],


IssueDate as [Issue Date], DueDate as [Due Date], Book.AccessionNo as [Accession
No],BookTitle as [Book Title],Author,Subject,ISBN,Edition,Student.StudentID as

Project by: Kuldeep Singh | 1053 Page 185


Library Management System

[Student ID],StudentName as [Student Name],Course,Student.Department, Status


from Book,BookIssue_Student,Student where
Book.AccessionNo=BookIssue_Student.AccessionNo and
BookIssue_Student.StudentID=Student.StudentID and Issuedate Between '" &
dtpDateFrom.Text & "' and '" & dtpDateTo.Text & "' and BookTitle like '" &
txtBookName.Text & "%' order by Issuedate desc ", con)
Try
con = New SqlConnection(cs)
con.Open()
cmd = New SqlCommand("SELECT ReturnID as [Return ID],ReturnDate
as [Return Date],Fine, BookIssue_Student.TransactionID as [Transaction ID],
IssueDate as [Issue Date], DueDate as [Due Date], Book.AccessionNo as [Accession
No],BookTitle as [Book Title],Author,Subject,ISBN,Edition,Student.StudentID as
[Student ID],StudentName as [Student Name],Course,Student.Department from
Book,BookIssue_Student,Student,Return_Student where
Book.AccessionNo=BookIssue_Student.AccessionNo and
BookIssue_Student.StudentID=Student.StudentID and
BookIssue_Student.TransactionID=Return_Student.TransactionID and Returndate
Between '" & dtpDateFrom.Text & "' and '" & dtpDateTo.Text & "' and BookTitle
like '" & txtBookName.Text & "%' order by Returndate desc ", con)
Dim myDA As SqlDataAdapter = New SqlDataAdapter(cmd)
Dim myDataSet As DataSet = New DataSet()
myDA.Fill(myDataSet, "BookIssue_Student")
myDA.Fill(myDataSet, "Book")
myDA.Fill(myDataSet, "Student")
myDA.Fill(myDataSet, "Return_Student")
DataGridView1.DataSource =
myDataSet.Tables("BookIssue_Student").DefaultView
DataGridView1.DataSource = myDataSet.Tables("Book").DefaultView
DataGridView1.DataSource = myDataSet.Tables("Student").DefaultView
DataGridView1.DataSource =
myDataSet.Tables("Return_Student").DefaultView
con.Close()
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
End Try
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
End Try
End Sub

Private Sub btnReset_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles btnReset.Click
Reset()
End Sub

Private Sub btnExportExcel_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles btnExportExcel.Click

Project by: Kuldeep Singh | 1053 Page 186


Library Management System

If DataGridView1.RowCount = Nothing Then


MessageBox.Show("Sorry nothing to export into excel sheet.." & vbCrLf &
"Please retrieve data in datagridview", "", MessageBoxButtons.OK,
MessageBoxIcon.Error)
Exit Sub
End If
Dim rowsTotal, colsTotal As Short
Dim I, j, iC As Short
System.Windows.Forms.Cursor.Current =
System.Windows.Forms.Cursors.WaitCursor
Dim xlApp As New Excel.Application
Try
Dim excelBook As Excel.Workbook = xlApp.Workbooks.Add
Dim excelWorksheet As Excel.Worksheet =
CType(excelBook.Worksheets(1), Excel.Worksheet)
xlApp.Visible = True

rowsTotal = DataGridView1.RowCount - 1
colsTotal = DataGridView1.Columns.Count - 1
With excelWorksheet
.Cells.Select()
.Cells.Delete()
For iC = 0 To colsTotal
.Cells(1, iC + 1).Value = DataGridView1.Columns(iC).HeaderText
Next
For I = 0 To rowsTotal - 1
For j = 0 To colsTotal
.Cells(I + 2, j + 1).value = DataGridView1.Rows(I).Cells(j).Value
Next j
Next I
.Rows("1:1").Font.FontStyle = "Bold"
.Rows("1:1").Font.Size = 12

.Cells.Columns.AutoFit()
.Cells.Select()
.Cells.EntireColumn.AutoFit()
.Cells(1, 1).Select()
End With
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
Finally
'RELEASE ALLOACTED RESOURCES
System.Windows.Forms.Cursor.Current =
System.Windows.Forms.Cursors.Default
xlApp = Nothing
End Try
End Sub

Project by: Kuldeep Singh | 1053 Page 187


Library Management System

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button1.Click
Try
con = New SqlConnection(cs)
con.Open()
cmd = New SqlCommand("SELECT ReturnID as [Return ID],ReturnDate as
[Return Date],Fine, BookIssue_Student.TransactionID as [Transaction ID], IssueDate
as [Issue Date], DueDate as [Due Date], Book.AccessionNo as [Accession
No],BookTitle as [Book Title],Author,Subject,ISBN,Edition,Student.StudentID as
[Student ID],StudentName as [Student Name],Course,Student.Department from
Book,BookIssue_Student,Student,Return_Student where
Book.AccessionNo=BookIssue_Student.AccessionNo and
BookIssue_Student.StudentID=Student.StudentID and
BookIssue_Student.TransactionID=Return_Student.TransactionID and Returndate
Between '" & DateTimePicker8.Text & "' and '" & DateTimePicker7.Text & "' order
by Returndate desc ", con)
Dim myDA As SqlDataAdapter = New SqlDataAdapter(cmd)
Dim myDataSet As DataSet = New DataSet()
myDA.Fill(myDataSet, "BookIssue_Student")
myDA.Fill(myDataSet, "Book")
myDA.Fill(myDataSet, "Student")
myDA.Fill(myDataSet, "Return_Student")
DataGridView1.DataSource =
myDataSet.Tables("BookIssue_Student").DefaultView
DataGridView1.DataSource = myDataSet.Tables("Book").DefaultView
DataGridView1.DataSource = myDataSet.Tables("Student").DefaultView
DataGridView1.DataSource =
myDataSet.Tables("Return_Student").DefaultView
con.Close()
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
End Try
End Sub

Private Sub cmbStudentName_SelectedIndexChanged(ByVal sender As


System.Object, ByVal e As System.EventArgs) Handles
cmbStudentName.SelectedIndexChanged
Try
con = New SqlConnection(cs)
con.Open()
cmd = New SqlCommand("SELECT ReturnID as [Return ID],ReturnDate as
[Return Date],Fine, BookIssue_Student.TransactionID as [Transaction ID], IssueDate
as [Issue Date], DueDate as [Due Date], Book.AccessionNo as [Accession
No],BookTitle as [Book Title],Author,Subject,ISBN,Edition,Student.StudentID as
[Student ID],StudentName as [Student Name],Course,Student.Department from
Book,BookIssue_Student,Student,Return_Student where
Book.AccessionNo=BookIssue_Student.AccessionNo and
BookIssue_Student.StudentID=Student.StudentID and
BookIssue_Student.TransactionID=Return_Student.TransactionID and ReturnDate

Project by: Kuldeep Singh | 1053 Page 188


Library Management System

Between '" & DateTimePicker4.Text & "' and '" & DateTimePicker3.Text & "' and
StudentName= '" & cmbStudentName.Text & "' order by ReturnDate desc ", con)
Dim myDA As SqlDataAdapter = New SqlDataAdapter(cmd)
Dim myDataSet As DataSet = New DataSet()
myDA.Fill(myDataSet, "BookIssue_Student")
myDA.Fill(myDataSet, "Book")
myDA.Fill(myDataSet, "Student")
myDA.Fill(myDataSet, "Return_Student")
DataGridView1.DataSource =
myDataSet.Tables("BookIssue_Student").DefaultView
DataGridView1.DataSource = myDataSet.Tables("Book").DefaultView
DataGridView1.DataSource = myDataSet.Tables("Student").DefaultView
DataGridView1.DataSource =
myDataSet.Tables("Return_Student").DefaultView
con.Close()
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
End Try
End Sub

Private Sub txtStudentName_TextChanged(ByVal sender As System.Object,


ByVal e As System.EventArgs) Handles txtStudentName.TextChanged
Try
con = New SqlConnection(cs)
con.Open()
cmd = New SqlCommand("SELECT ReturnID as [Return ID],ReturnDate as
[Return Date],Fine, BookIssue_Student.TransactionID as [Transaction ID], IssueDate
as [Issue Date], DueDate as [Due Date], Book.AccessionNo as [Accession
No],BookTitle as [Book Title],Author,Subject,ISBN,Edition,Student.StudentID as
[Student ID],StudentName as [Student Name],Course,Student.Department from
Book,BookIssue_Student,Student,Return_Student where
Book.AccessionNo=BookIssue_Student.AccessionNo and
BookIssue_Student.StudentID=Student.StudentID and
BookIssue_Student.TransactionID=Return_Student.TransactionID and StudentName
like '" & txtStudentName.Text & "%' order by Studentname ", con)
Dim myDA As SqlDataAdapter = New SqlDataAdapter(cmd)
Dim myDataSet As DataSet = New DataSet()
myDA.Fill(myDataSet, "BookIssue_Student")
myDA.Fill(myDataSet, "Book")
myDA.Fill(myDataSet, "Student")
myDA.Fill(myDataSet, "Return_Student")
DataGridView1.DataSource =
myDataSet.Tables("BookIssue_Student").DefaultView
DataGridView1.DataSource = myDataSet.Tables("Book").DefaultView
DataGridView1.DataSource = myDataSet.Tables("Student").DefaultView
DataGridView1.DataSource =
myDataSet.Tables("Return_Student").DefaultView
con.Close()

Project by: Kuldeep Singh | 1053 Page 189


Library Management System

Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
End Try
End Sub

Private Sub DataGridView1_RowHeaderMouseClick(ByVal sender As Object,


ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles
DataGridView1.RowHeaderMouseClick
Try
Dim dr As DataGridViewRow = DataGridView1.SelectedRows(0)
Me.Hide()
frmBookReturn.Show()
frmBookReturn.txtReturnID.Text = dr.Cells(0).Value.ToString()
frmBookReturn.dtpReturnDate.Text = dr.Cells(1).Value.ToString()
frmBookReturn.txtFine.Text = dr.Cells(2).Value.ToString()
frmBookReturn.txtTransactionID.Text = dr.Cells(3).Value.ToString()
frmBookReturn.dtpIssueDate.Text = dr.Cells(4).Value.ToString()
frmBookReturn.dtpDueDate.Text = dr.Cells(5).Value.ToString()
frmBookReturn.txtAccessionNo.Text = dr.Cells(6).Value.ToString()
frmBookReturn.TextBox1.Text = dr.Cells(6).Value.ToString()
frmBookReturn.txtBookTitle.Text = dr.Cells(7).Value.ToString()
frmBookReturn.txtAuthor.Text = dr.Cells(8).Value.ToString()
frmBookReturn.txtCategory.Text = dr.Cells(9).Value.ToString()
frmBookReturn.txtISBN.Text = dr.Cells(10).Value.ToString()
frmBookReturn.txtEdition.Text = dr.Cells(11).Value.ToString()
frmBookReturn.txtStudentID.Text = dr.Cells(12).Value.ToString()
frmBookReturn.txtStudentName.Text = dr.Cells(13).Value.ToString()
frmBookReturn.txtCourse.Text = dr.Cells(14).Value.ToString()
frmBookReturn.txtDepartment.Text = dr.Cells(15).Value.ToString()
frmBookReturn.btnUpdate_record.Enabled = True
frmBookReturn.btnDelete.Enabled = True
frmBookReturn.btnSave.Enabled = False
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
End Try
End Sub

Private Sub DataGridView1_RowPostPaint(ByVal sender As Object, ByVal e As


System.Windows.Forms.DataGridViewRowPostPaintEventArgs) Handles
DataGridView1.RowPostPaint
Dim strRowNumber As String = (e.RowIndex + 1).ToString()
Dim size As SizeF = e.Graphics.MeasureString(strRowNumber, Me.Font)
If DataGridView1.RowHeadersWidth < Convert.ToInt32((size.Width + 20))
Then
DataGridView1.RowHeadersWidth = Convert.ToInt32((size.Width + 20))
End If
Dim b As Brush = SystemBrushes.ControlText

Project by: Kuldeep Singh | 1053 Page 190


Library Management System

e.Graphics.DrawString(strRowNumber, Me.Font, b, e.RowBounds.Location.X +


15, e.RowBounds.Location.Y + ((e.RowBounds.Height - size.Height) / 2))

End Sub

Private Sub dtpDateTo_Validating(ByVal sender As System.Object, ByVal e As


System.ComponentModel.CancelEventArgs) Handles dtpDateTo.Validating
If (dtpDateFrom.Value.Date) > (dtpDateTo.Value.Date) Then
MessageBox.Show("Invalid Selection", "Input Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
dtpDateTo.Focus()
End If
End Sub

Private Sub DateTimePicker7_Validating(ByVal sender As System.Object, ByVal


e As System.ComponentModel.CancelEventArgs) Handles
DateTimePicker7.Validating
If (DateTimePicker8.Value.Date) > (DateTimePicker7.Value.Date) Then
MessageBox.Show("Invalid Selection", "Input Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
DateTimePicker7.Focus()
End If
End Sub

Private Sub DateTimePicker3_Validating(ByVal sender As System.Object, ByVal


e As System.ComponentModel.CancelEventArgs) Handles
DateTimePicker3.Validating
If (DateTimePicker4.Value.Date) > (DateTimePicker3.Value.Date) Then
MessageBox.Show("Invalid Selection", "Input Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
DateTimePicker3.Focus()
End If
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button2.Click
Try
con = New SqlConnection(cs)
con.Open()
cmd = New SqlCommand("SELECT ReturnID as [Return ID],ReturnDate as
[Return Date],Fine, BookIssue_Student.TransactionID as [Transaction ID], IssueDate
as [Issue Date], DueDate as [Due Date], Book.AccessionNo as [Accession
No],BookTitle as [Book Title],Author,Subject,ISBN,Edition,Student.StudentID as
[Student ID],StudentName as [Student Name],Course,Student.Department from
Book,BookIssue_Student,Student,Return_Student where
Book.AccessionNo=BookIssue_Student.AccessionNo and
BookIssue_Student.StudentID=Student.StudentID and
BookIssue_Student.TransactionID=Return_Student.TransactionID and Returndate
Between '" & DateTimePicker2.Text & "' and '" & DateTimePicker1.Text & "' and
Fine > 0 order by Returndate desc ", con)

Project by: Kuldeep Singh | 1053 Page 191


Library Management System

Dim myDA As SqlDataAdapter = New SqlDataAdapter(cmd)


Dim myDataSet As DataSet = New DataSet()
myDA.Fill(myDataSet, "BookIssue_Student")
myDA.Fill(myDataSet, "Book")
myDA.Fill(myDataSet, "Student")
myDA.Fill(myDataSet, "Return_Student")
DataGridView1.DataSource =
myDataSet.Tables("BookIssue_Student").DefaultView
DataGridView1.DataSource = myDataSet.Tables("Book").DefaultView
DataGridView1.DataSource = myDataSet.Tables("Student").DefaultView
DataGridView1.DataSource =
myDataSet.Tables("Return_Student").DefaultView
con.Close()
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
End Try
End Sub

Private Sub DateTimePicker1_Validating(ByVal sender As System.Object, ByVal


e As System.ComponentModel.CancelEventArgs) Handles
DateTimePicker1.Validating
If (DateTimePicker2.Value.Date) > (DateTimePicker1.Value.Date) Then
MessageBox.Show("Invalid Selection", "Input Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
DateTimePicker1.Focus()
End If
End Sub
End Class

frmCourse.vb
Option Strict On
Imports System.Data.SqlClient
Public Class frmCourse
Dim con As SqlConnection = Nothing
Dim cmd As SqlCommand = Nothing
Dim rdr As SqlDataReader
Dim cs As String = "Data Source=.\SQLEXPRESS;Initial
Catalog=LibraryDatabase;Integrated Security=True"

Sub Reset()
txtCourseName.Text = ""
btnSave.Enabled = True
btnUpdate_record.Enabled = False
btnDelete.Enabled = False
txtCourseName.Focus()
End Sub
Public Sub GetData()
Try

Project by: Kuldeep Singh | 1053 Page 192


Library Management System

con = New SqlConnection(cs)


con.Open()
cmd = New SqlCommand("SELECT CourseName from Course order by
Coursename", con)
rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection)
DataGridView1.Rows.Clear()
While (rdr.Read() = True)
DataGridView1.Rows.Add(rdr(0))
End While
con.Close()
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
End Try
End Sub
Private Sub frmCourse_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
GetData()
End Sub

Private Sub btnNewRecord_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles btnNewRecord.Click
Reset()
End Sub

Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles btnSave.Click
If Len(Trim(txtCourseName.Text)) = 0 Then
MessageBox.Show("Please enter course name", "Input Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
txtCourseName.Focus()
Exit Sub
End If
Try
con = New SqlConnection(cs)
con.Open()
Dim ct As String = "select Coursename from course where Coursename='" &
txtCourseName.Text & "'"
cmd = New SqlCommand(ct)
cmd.Connection = con
rdr = cmd.ExecuteReader()
If rdr.Read Then
MessageBox.Show("Course Name Already Exists", "Input Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
Reset()
If Not rdr Is Nothing Then
rdr.Close()
End If
Exit Sub
End If

Project by: Kuldeep Singh | 1053 Page 193


Library Management System

con = New SqlConnection(cs)


con.Open()
Dim cb As String = "insert into Course(Coursename) VALUES ('" &
txtCourseName.Text & "')"
cmd = New SqlCommand(cb)
cmd.Connection = con
cmd.ExecuteReader()
MessageBox.Show("Successfully saved", "Record", MessageBoxButtons.OK,
MessageBoxIcon.Information)
GetData()
btnSave.Enabled = False
con.Close()
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
End Try
End Sub

Private Sub DataGridView1_RowHeaderMouseClick(ByVal sender As Object,


ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles
DataGridView1.RowHeaderMouseClick
Try
Dim dr As DataGridViewRow = DataGridView1.SelectedRows(0)
txtCourseName.Text = dr.Cells(0).Value.ToString()
TextBox1.Text = dr.Cells(0).Value.ToString()
btnUpdate_record.Enabled = True
btnDelete.Enabled = True
btnSave.Enabled = False
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
End Try
End Sub

Private Sub DataGridView1_RowPostPaint(ByVal sender As Object, ByVal e As


System.Windows.Forms.DataGridViewRowPostPaintEventArgs) Handles
DataGridView1.RowPostPaint
Dim strRowNumber As String = (e.RowIndex + 1).ToString()
Dim size As SizeF = e.Graphics.MeasureString(strRowNumber, Me.Font)
If DataGridView1.RowHeadersWidth < Convert.ToInt32((size.Width + 20))
Then
DataGridView1.RowHeadersWidth = Convert.ToInt32((size.Width + 20))
End If
Dim b As Brush = SystemBrushes.ControlText
e.Graphics.DrawString(strRowNumber, Me.Font, b, e.RowBounds.Location.X +
15, e.RowBounds.Location.Y + ((e.RowBounds.Height - size.Height) / 2))
End Sub

Public Sub DeleteRecord()


Try

Project by: Kuldeep Singh | 1053 Page 194


Library Management System

Dim RowsAffected As Integer = 0


con = New SqlConnection(cs)
con.Open()
Dim cq As String = "delete from Course where CourseName='" &
txtCourseName.Text & "'"
cmd = New SqlCommand(cq)
cmd.Connection = con
RowsAffected = cmd.ExecuteNonQuery()
If RowsAffected > 0 Then
MessageBox.Show("Successfully deleted", "Record",
MessageBoxButtons.OK, MessageBoxIcon.Information)
GetData()
Reset()
Else
MessageBox.Show("No record found", "Sorry", MessageBoxButtons.OK,
MessageBoxIcon.Information)
Reset()
If con.State = ConnectionState.Open Then
con.Close()
End If
con.Close()
End If
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
End Try
End Sub
Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnDelete.Click
Try
If MessageBox.Show("Do you really want to delete this record?",
"Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) =
System.Windows.Forms.DialogResult.Yes Then
DeleteRecord()
End If
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
End Try
End Sub

Private Sub btnUpdate_record_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles btnUpdate_record.Click
If Len(Trim(txtCourseName.Text)) = 0 Then
MessageBox.Show("Please enter course name", "Input Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
txtCourseName.Focus()
Exit Sub
End If

Project by: Kuldeep Singh | 1053 Page 195


Library Management System

Try
con = New SqlConnection(cs)
con.Open()
Dim cb As String = "update Course set Coursename='" &
txtCourseName.Text & "' where Coursename='" & TextBox1.Text & "'"
cmd = New SqlCommand(cb)
cmd.Connection = con
cmd.ExecuteReader()
MessageBox.Show("Successfully updated", "Record",
MessageBoxButtons.OK, MessageBoxIcon.Information)
GetData()
btnUpdate_record.Enabled = False
con.Close()
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
End Try
End Sub
End Class

frmCourse.vb
Option Strict On
Imports System.Data.SqlClient
Public Class frmCourse
Dim con As SqlConnection = Nothing
Dim cmd As SqlCommand = Nothing
Dim rdr As SqlDataReader
Dim cs As String = "Data Source=.\SQLEXPRESS;Initial
Catalog=LibraryDatabase;Integrated Security=True"

Sub Reset()
txtCourseName.Text = ""
btnSave.Enabled = True
btnUpdate_record.Enabled = False
btnDelete.Enabled = False
txtCourseName.Focus()
End Sub
Public Sub GetData()
Try
con = New SqlConnection(cs)
con.Open()
cmd = New SqlCommand("SELECT CourseName from Course order by
Coursename", con)
rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection)
DataGridView1.Rows.Clear()
While (rdr.Read() = True)
DataGridView1.Rows.Add(rdr(0))
End While
con.Close()
Catch ex As Exception

Project by: Kuldeep Singh | 1053 Page 196


Library Management System

MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,


MessageBoxIcon.Error)
End Try
End Sub
Private Sub frmCourse_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
GetData()
End Sub

Private Sub btnNewRecord_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles btnNewRecord.Click
Reset()
End Sub

Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles btnSave.Click
If Len(Trim(txtCourseName.Text)) = 0 Then
MessageBox.Show("Please enter course name", "Input Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
txtCourseName.Focus()
Exit Sub
End If

Try
con = New SqlConnection(cs)
con.Open()
Dim ct As String = "select Coursename from course where Coursename='" &
txtCourseName.Text & "'"
cmd = New SqlCommand(ct)
cmd.Connection = con
rdr = cmd.ExecuteReader()
If rdr.Read Then
MessageBox.Show("Course Name Already Exists", "Input Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
Reset()
If Not rdr Is Nothing Then
rdr.Close()
End If
Exit Sub
End If
con = New SqlConnection(cs)
con.Open()
Dim cb As String = "insert into Course(Coursename) VALUES ('" &
txtCourseName.Text & "')"
cmd = New SqlCommand(cb)
cmd.Connection = con
cmd.ExecuteReader()
MessageBox.Show("Successfully saved", "Record", MessageBoxButtons.OK,
MessageBoxIcon.Information)
GetData()

Project by: Kuldeep Singh | 1053 Page 197


Library Management System

btnSave.Enabled = False
con.Close()
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
End Try
End Sub

Private Sub DataGridView1_RowHeaderMouseClick(ByVal sender As Object,


ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles
DataGridView1.RowHeaderMouseClick
Try
Dim dr As DataGridViewRow = DataGridView1.SelectedRows(0)
txtCourseName.Text = dr.Cells(0).Value.ToString()
TextBox1.Text = dr.Cells(0).Value.ToString()
btnUpdate_record.Enabled = True
btnDelete.Enabled = True
btnSave.Enabled = False
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
End Try
End Sub

Private Sub DataGridView1_RowPostPaint(ByVal sender As Object, ByVal e As


System.Windows.Forms.DataGridViewRowPostPaintEventArgs) Handles
DataGridView1.RowPostPaint
Dim strRowNumber As String = (e.RowIndex + 1).ToString()
Dim size As SizeF = e.Graphics.MeasureString(strRowNumber, Me.Font)
If DataGridView1.RowHeadersWidth < Convert.ToInt32((size.Width + 20))
Then
DataGridView1.RowHeadersWidth = Convert.ToInt32((size.Width + 20))
End If
Dim b As Brush = SystemBrushes.ControlText
e.Graphics.DrawString(strRowNumber, Me.Font, b, e.RowBounds.Location.X +
15, e.RowBounds.Location.Y + ((e.RowBounds.Height - size.Height) / 2))
End Sub

Public Sub DeleteRecord()


Try
Dim RowsAffected As Integer = 0
con = New SqlConnection(cs)
con.Open()
Dim cq As String = "delete from Course where CourseName='" &
txtCourseName.Text & "'"
cmd = New SqlCommand(cq)
cmd.Connection = con
RowsAffected = cmd.ExecuteNonQuery()
If RowsAffected > 0 Then

Project by: Kuldeep Singh | 1053 Page 198


Library Management System

MessageBox.Show("Successfully deleted", "Record",


MessageBoxButtons.OK, MessageBoxIcon.Information)
GetData()
Reset()
Else
MessageBox.Show("No record found", "Sorry", MessageBoxButtons.OK,
MessageBoxIcon.Information)
Reset()
If con.State = ConnectionState.Open Then
con.Close()
End If
con.Close()
End If
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
End Try
End Sub
Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnDelete.Click
Try
If MessageBox.Show("Do you really want to delete this record?",
"Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) =
System.Windows.Forms.DialogResult.Yes Then
DeleteRecord()
End If
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
End Try
End Sub

Private Sub btnUpdate_record_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles btnUpdate_record.Click
If Len(Trim(txtCourseName.Text)) = 0 Then
MessageBox.Show("Please enter course name", "Input Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
txtCourseName.Focus()
Exit Sub
End If

Try
con = New SqlConnection(cs)
con.Open()
Dim cb As String = "update Course set Coursename='" &
txtCourseName.Text & "' where Coursename='" & TextBox1.Text & "'"
cmd = New SqlCommand(cb)
cmd.Connection = con
cmd.ExecuteReader()

Project by: Kuldeep Singh | 1053 Page 199


Library Management System

MessageBox.Show("Successfully updated", "Record",


MessageBoxButtons.OK, MessageBoxIcon.Information)
GetData()
btnUpdate_record.Enabled = False
con.Close()
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
End Try
End Sub
End Class

Project by: Kuldeep Singh | 1053 Page 200


Library Management System

Data Entry
Screens

Project by: Kuldeep Singh | 1053 Page 201


Library Management System

Login Forms :

Home Form :

Data Entry Forms :

Project by: Kuldeep Singh | 1053 Page 202


Library Management System

Book Issue Form :

Project by: Kuldeep Singh | 1053 Page 203


Library Management System

Book Return Form :

Course and Department Forms :

Supplier Form :

Project by: Kuldeep Singh | 1053 Page 204


Library Management System

Data Entry Forms :

Book Search Form :

Project by: Kuldeep Singh | 1053 Page 205


Library Management System

Error validations from forms :

Project by: Kuldeep Singh | 1053 Page 206


Library Management System

Test Cases,
Test Results
And
Test Data

Project by: Kuldeep Singh | 1053 Page 207


Library Management System

What is Test Case?


“A Test Case has a component that describe an input, action or event expected
response, to determine if a feature of an application is working correctly.”

Software testing can be stated as the process of validating and verifying that a
computer program/application/product:

 Meets the requirements that guided its design and


development.
 Works as expected
 Can be implemented with the same characters.
 And satisfies the needs of Stakeholders.
Why we Write Test Case?

A Test Case in Software Engineering is a set of conditions or variables under which a


tester will determine whether an application , software system or one of its feature is
working as it was originally established for it to do.

The basic objective to write test case is to validate testing coverage for the
application.

Test Cases bring some sort of standardization and minimize the ad-hoc approach in
testing.

Project by: Kuldeep Singh | 1053 Page 208


Library Management System

Test Cases
Expected Valid username and valid password
Results :

Project by: Kuldeep Singh | 1053 Page 209


Library Management System

Actual Test Data:


Results : Empty username and empty password

Invalid username and password

Project by: Kuldeep Singh | 1053 Page 210


Library Management System

Expected Valid Data


Result :

Project by: Kuldeep Singh | 1053 Page 211


Library Management System

Actual Test Data :


Results : Test Data : Empty Entry

Test Data: Invalid mobile number

Project by: Kuldeep Singh | 1053 Page 212


Library Management System

Reports
Layout

Project by: Kuldeep Singh | 1053 Page 213


Library Management System

Book Reports :

Student Reports :

Staff Reports :

Project by: Kuldeep Singh | 1053 Page 214


Library Management System

Book Issue Reports :

Book Return Reports :

Project by: Kuldeep Singh | 1053 Page 215


Library Management System

References
&
Bibliography

Project by: Kuldeep Singh | 1053 Page 216


Library Management System

References
 College Practical
 Integrated Approach to Software Engineering

URLs
http://stackoverflow.com/

https://www.codeproject.com

https://msdn.microsoft.com/

Project by: Kuldeep Singh | 1053 Page 217

S-ar putea să vă placă și