KEMBAR78
Library Management System Final Report | PDF | Microsoft Sql Server | Software Development Process
0% found this document useful (0 votes)
11 views113 pages

Library Management System Final Report

different approach for library management system

Uploaded by

Prashant Shah
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views113 pages

Library Management System Final Report

different approach for library management system

Uploaded by

Prashant Shah
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 113

A First Project Final Report On

Desktop-based
Library Management System Application
using C# and MS-SQL Server Database

Submitted in Partial Fulfillment of the Requirements for


the Degree of ​Computer Engineering
under Pokhara University

Submitted by:
Sumit Ratna Tamakar, 171337
Prabin Sahani, 171342

Under the supervision of


Dr. Roshan Chitrakar

Date:
12/09/2019

Department of Computer Engineering


NEPAL COLLEGE OF
INFORMATION TECHNOLOGY

Balkumari, Lalitpur, Nepal


Acknowledgement
First of all, we would like to extend our heartfelt gratitude to our project supervisor, Dr.
Roshan Chitrakar for providing us with the opportunity to undertake this project and complete it.
Doing this has offered us valuable experience working with team members in the project to
achieve a common goal.

The success and final outcome of this project required a lot of guidance and assistance
from many sources and we are extremely privileged to have got all this support along with the
completion of the project. All that we have done is only due to such supervision and assistance
and we would not forget to thank them.

We would also like to thank Er. Madan Kadariya, head of the Department of Information
and Technology along with every other individual who has contributed to making this project
successful for taking out the time from their busy schedules to help us with our problems.

This acknowledgement section wouldn’t be complete without mentioning our families


who have supported us throughout the entirety of this project.

Finally, we would like to thank Pokhara University - School of Engineering for providing
us with the opportunity to endeavour into this project.

Thanking You,

Sumit Ratna Tamrakar

Prabin Sahani

I
Abstract

The main theme of this project is a Library Management System which is an application
program used by librarians in academic institutions. It is used to manage and handle basic library
operations like student record-keeping, book circulation, book searching and inventory keeping.
The system is digitized using a database enhancing the operation speed as well as storage space
management. This project significantly improves efficiency and makes working simple, easy and
fast using the graphical user interface.

Disorganization of information, a requirement of larger storage space, high time


consumption, data duplication, lack of security, difficulty in searching records, etc. were some of
the problems we discovered in a library which utilized manual conventional means of the
management system. Thus, digitizing record-keeping procedure, easily storing a large number of
records, providing security, automating library management, reducing management cost are
some of the important objectives of this project.

However, some of the limitations of our project are- no internet integration for online
access/service, data vulnerability due to lack of proper backup mechanism, lack of bar code
hardware integration, prone to hacking attempts. Basic understanding of computer operations
might be needed for library personnel to use this system. These setbacks may be addressed in
future updates.

With this system, users and admins will be able to access it by logging in; then browse,
search available books. Admins can add, read, update, delete details of books and students. In
addition, admins can keep records of lent and return books and can also notify students regarding
their books.

We used C# as the programming language, with Visual Studio 2019 as Integrated


Development Environment (IDE) and it’s built-in MS-SQL component to create our
desktop-based application.

Keywords: Desktop-based application, Library Management System, digitized library


management system, C#, MS-SQL, Visual Studio 2019

II
Table Of Contents

Acknowledgment I
Abstract II
Table Of Contents III
List of Figures IV
List of Tables VI

Introduction 7
Problem Statement 7
Objectives 10
Significance of the Study 11

Literature Review 12

Methodology 15

Conclusion: 56

Further Works/Recommendations 57

Bibliography/References 59

Appendix 60

III
List of Figures
Fig. 1: Library Management System 12
Fig. 2: iCampusHub 13
Fig. 3 : Visual Studio Logo 13
Fig. 4 : C# Logo 13
Fig. 5 : MS-SQL Server 14
Fig 6. Iterative Model 15
Fig. 7 : E-R Diagram of Library Management System 17
Fig. 8: System Flowchart of Library Management System 19
Fig. 9 : Use Case Diagram of Library Management System 20
Fig. 10:Login form 21
Fig. 11: Student Sign Up Form 23
Fig. 12: Login Page with fields filled 24
Fig. 13: Successful Student Login 26
Fig. 14: Student Menu 27
Fig.15: Student Menu - ‘Available’ Filter Selected 28
Fig.16: Student Menu - ‘Not available’ Filter Selected 29
Fig. 17: Student Menu - ‘Searching’ 30
Fig. 18: Successful Admin Menu 31
Fig.19: Admin Main Menu 32
Fig 20: Add Admin Form 33
Fig. 21: Admin - Students Menu 34
Fig. 22: Admin - Student Menu ‘Searching’ 35
Fig. 23: Admin - Student Menu - ‘Add Students Info’ Form 36
Fig. 24: Select Student Record Prompt - Message Box 37
Fig. 25: Admin - Student Menu - Edit Student Info Form 38
Fig. 26: Edit Student Record Successful - Message 39
Fig.27 : Admin - Student Menu - Record Deletion Confirmation Prompt 40
Fig. 28: Admin - Student Menu - Student Record Deletion Successful - Message 41
Fig.29 : Admin - Student Menu - Menu refreshed after student record deletion 42
Fig. 30: Admin - Books Menu 43
Fig. 31: Admin - Books Menu - Search 44
Fig. 32: Admin - Books Menu - Add Books Form 45
Fig. 33: Admin - Books Menu - Edit Books 46
Fig. 34: Admin - Books Menu - Deletion - Record Selection Prompt 47

IV
Fig. 35: Admin - Books Menu - Deletion - Deletion Confirmation 48
Fig. 36: Admin - Books Menu - Deletion - Successful Deletion - Message 49
Fig. 37: Admin - Issue Books Menu 50
Fig. 38: Admin - Return Books Menu 51
Fig. 39: Admin - Books Stock Menu 52
Fig. 40: Admin - Books Stock Menu - Search 53
Fig. 41: Admin - Book Stocks - Sending Email 54
Fig. 42: Admin - Books Stock - Checking Mail 55

V
List of Tables
Table 1: Tables used in Library Management System 18

VI
Introduction
Problem Statement
There are various problems that one might face if he/she does not have access to a digital
library management system. Both the book borrower as well as the book-lending institution may
face some inconveniences which could have been easily avoided if a digital system such as one
modelled in our project was in place. Some of the problems that one might encounter are listed in
our problem statement as follows:

- Duplication of data:
When there are a lot of books in an institution, it can be become hard to keep track of
exactly which books are available in the inventory. If there are, say over a thousand books in the
library, one might have a hard time maintaining a proper list of individual books. One or more of
the books may be overlooked in the existing inventory record and duplicate entries may be
entered into the inventory list. This causes the same book to be listed multiple times in the library
catalogue.

- Security issues:
A single hardcopy document consisting of all the important information kept in a library
may not be as secure as a digital database which may be backed up at multiple remote locations
and encrypted to protect from unauthorized access. Physical documents are more prone to theft,
unauthorized manipulation and unintended destruction. These security risks may be significantly
lessened by the use of a digital library management system.

- Lack of storage:
As we know the library consists of a large amount of old and new books, magazines,
bookmarks, newspapers, music, etc and managing them requires a large volume of storages. In a
traditional library management system, cabinets were used for this purpose and resulted in high
cost for the maintenance. The digital library management system provides large storage capacity
at a very low cost. USB drives, hard disks, optical disks, cloud services, etc are some of the
storage devices used in a digital library management system.

7
- Slower retrieval of data
Searching and retrieving data such as the name of a book or its author or information
regarding a student can become tedious if there is a vast amount of information to be searched.
Searching through all the data can be quite time-consuming and lead to poor management. On
the other hand, searching for a particular piece of information is quick and simple in the case of a
digital system
.
- Time-consuming:
In the traditional library management system, searching for books based on an index,
adding books, editing book records and removing the trivial files were time-consuming
processes. Similarly, an increase in the number of users made the issuing, returning, updating of
the records made the system more sluggish. But digital library management system can perform
all above-mentioned tasks in a few clicks in a few minutes.

- Lack of organization of information


Information may not be properly organized when stored in physical files. On addition,
deletion or update of a record, the organization of information may be disrupted. Whereas,
information can be instantly sorted and organized while using a digital system regardless of the
modification to the database,

- The inability of concurrent retrieval of data


If only one copy of the information is stored in the library then it can be accessed by only
a single user at a time. In stark comparison, many instances of an application system can be run
at the same time and data as well as information can be retrieved concurrently by multiple users.

- Prone to human errors


Manual Library Management Systems are vulnerable to human error. For
example, a librarian may misfile a borrower’s records or index a book incorrectly, thus slowing
down the library operations and leading to wastage of time. Humans can more prone to make
mistakes. The use of a computer significantly reduces the chances of errors and provides a high
degree of precision.

8
- Difficult to search records
Searching if a particular book is available or not maybe laborious if the library contains a
large catalogue while using manual services. The library personnel may have to shift through
tons of log files to check for the related information. The use of a digital system reduces the
whole process down to the press of a few keys.

9
Objectives
The main objective of this project is to provide a simple, efficient, reliable and secure
means of managing library operations. Our objective of undertaking this project is to address and
hopefully eliminate the many problems that arise during the manual management of a library. To
accomplish this, we have endeavoured into creating a brand new model of application software
which we hope can fulfil the needs of librarians in various institutes. Our project objectives are:
- To eliminate the problems mentioned in the problem statement of this report.
- To provide a simple and seamless user interface for the user to interact with.
- To provide simplicity, security and efficiency to the management process.
- To digitize the record-keeping procedure.
- To minimize management costs.
- To automate the management of the library.
- To provide an easy and quick way to store and view a large amount of information.
- To remove the inconveniences in library management.
- To enable smooth processing and management of library affairs.

10
Significance of the Study
The library is one of the oldest and most important institutions in our society. From long
ago in the past, it has been the source of knowledge for scholars who seek to gain insights on
various domains. With the changes in time, there has been a need for change in the old systems
of library management in which all the process were performed manually and papers and cards
were used to store information on all things related to the library including inventory list,
circulation information and indexing structures.

In the modern-day, it has become necessary to transition from the primitive system
mentioned above to a new and more efficient system in which the limitations of the previous
system can be overcome. The new system should encompass all the functionalities its
predecessor while introducing original and innovative features and facilities. This system should
reduce the time required for the operation of usual transactions and encourage smooth
functioning of management processes. It should enable a higher degree of effectiveness and
efficiency allowing more time for library personnel to devote more time in serving the customers
and maintaining the existing catalogue of books and information held in the library.

The intent of this study is to pinpoint the weaknesses and drawbacks of the existing
manual systems and hopefully replace them in the future with our model of a digital management
system. Our aim is to create a system while will enable anyone to get information about any
books, it’s authors as well as publishers. The speed of book circulation can be significantly
increased through this project.

We aim to provide a simple graphical user-friendly interface which is simple and easy to
use providing access to its resources. The same resources may be used concurrently by multiple
users. It also aims to provide improved security and organization of data and information.
Comparing the large space required to store information and records in traditional libraries,
digital library management systems possess the ability to store a large amount of information
taking up only a small space.

11
Literature Review

With the advancement of technology, almost every sector has interchanged from the
manual-based systems to the computer-based systems with the objective to increase efficiency
and perform various tasks in a short interval of time. So some effort has also been done in the
library management system so as to facilitate the users. Some of the programs which have
similar functionality as our project has been listed below:
● Library Management System:
Library Management System is a windows-based software that is used in university for
students. It can also be used in the home libraries for management. It supports adding google
books information and cover images of the book.

Fig. 1: Library Management System

● iCampusHUB:
iCampusHUB is a software which is used for the management of students, teachers,
books, courses, employees and all other processes for the smooth functioning of the institute.

12
Fig. 2: iCampusHub

Tools / Technology Used:


We used some of the tools so as to convert our vision into an actual program. The tools
used in our projects are mentioned below:
● Visual Studio:
Visual Studio is an Integrated Development Environment(IDE) which is
used for the development of apps for android, mac, ios, windows, web, etc. It
makes code writing faster and debugging and diagnosing easier. It is not a
language-specific IDE as we can write code in C#, C++, Visual Basic(VB),
Python, JavaScript and many more languages. It supports 36 different
languages. Fig. 3 : Visual

Studio Logo

● C#:
​ # is a simple, modern, general-purpose, object-oriented programming
C
language developed by Microsoft within its .NET initiative. It uses​ XML​-based​ Web
services​ on the​ .NET​ platform and is designed for improving productivity in ​Fig. 4 : C# Logo

13
the development of Web applications as well as desktop-based applications. C# boasts
type-safety, garbage collection, simplified type declarations, versioning and scalability support,
and other features that make developing solutions faster and easier, especially for
COM+ and Web services.

● Microsoft SQL Server Express:


Microsoft SQL Server is a Relational Database Management System
(RDBMS) ​developed by Microsoft. It is a highly scalable product that
can be run on anything from a single laptop, to a network of high- Fig. 5 : MS-SQL Server
Powered cloud servers, and anything in between. As a ​database server​, it is a ​software product
with the primary function of storing and retrieving data as requested by other ​software
applications​. ​In addition, it ensures the safety of the information stored, despite system crashes or
attempts at unauthorized access.

14
Methodology

Software Development Life Cycle


The software development cycle model we have used for the development of our project
is the Iterative Model. Initially, we had planned to use the Waterfall Model but during the course
of our software development life cycle, we came across moments where we had to repeat
previous iterations after moving forward through a certain phase which was not compliant with
the Waterfall Model but which was similar to the Iterative Model.

Fig 6. Iterative Model

We completed a cycle consisting of the following phases:


● Analysing of software requirements

15
In this phase, we determined the prerequisites for the development of the library
management system. For this, we used Visual Studio as an IDE and programmed the software
using the C# language. For the database, we chose Microsoft SQL Server.
● Design
In this phase, we designed the overall look, algorithm of the software and used the visual
programming feature of the Visual Studio to design our project. The Visual Studio provided
simple and easy to use interfaces for designing and coding the program.
● Coding and Development
In this phase, we coded all the Graphical User Components and provided their
functionality. Also, we integrated the Microsoft SQL Server to the software. Finally, we
were able to develop a prototype of our software.
● Testing and Debugging
In this phase, we performed different tests by providing various data and checked
whether the result was as per our expectations. The debugging process was carried out
when the program showed any errors or the result was not in the form as we expected it
to be.
● Implementation
Finally, we were able to develop a working library management system software that
could add, delete, edit and search books as well as student and issue books to the student
and check if they returned the books. It can be used to manage libraries in universities or
manage a home library.

After completion of each functionality, we repeated the above cycle from the analyzing
phase to its implementation. We performed many iterations of such cycles. With each cycle, we
made modifications to our design and added more functional capabilities. Thus, enhancing and
evolving our application software with each iteration.

16
Fig. 7 : E-R Diagram of Library Management System

17
Structure of Tables used in Library Management System

Table 1: Tables used in Library Management System

18
Fig. 8: System Flowchart of Library Management System

19
Fig. 9 : Use Case Diagram of Library Management System

20
Project Screenshots With Descriptions and Working Code

Login Form

Fig. 10:Login form

21
This is the first page/form which is loaded when the application is run. It is a simple login
page in which the user can choose the account type with which the user wishes to login. The user
must then enter the Username and Password associated with the chosen account type which
exists in the database. When the user clicks the ‘Login’ button, the application checks the
database whether there is a record in which the Username and Password match that of the
database. If there is a match, the user is logged into his/her account. If not, a message is
displayed stating - ‘Username and Password not found’.

The ‘radio_check’ value is set to 1 if ‘Admin’ radio button is selected. And its value is set to 2 if
‘Student’ radio button is selected. This variable is used to check whether we have to validate the
username and password from either ‘Student’ table in the database or to validate the fields from
‘Admin’ table in the database.

22
Student Sign Up Form

Fig. 11: Student Sign Up Form


Student Sign Up Form provides a mechanism by which students can use this system. The
student simply has to fill the information required in this form. No student can use this system if
he has not signed up for this system. After successfully signing up to the system, the student can
return to the ‘Login’ by clicking ‘LOG IN HERE’ button. All the information provided is saved
in the database table.

23
Fig. 12: Login Page with fields filled

The text in the Password field is hidden to make the password secure while entering so that the
nearby people cannot easily view the password while entering.
Code snippet for hiding text in Password field:

private void LoginPassword_Enter(object sender, EventArgs e)


{
if (LoginPassword.Text == "Password")
{
LoginPassword.Text = "";
LoginPassword.ForeColor = Color.Black;

24
LoginPassword.PasswordChar = '•';
}

While checking if the username and password are valid or not, we have made the checking
procedure to be case-sensitive by using the following code:

cmd.CommandText = "SELECT Username,Password FROM Admin WHERE Username = @Username COLLATE


SQL_Latin1_General_Cp1_CS_AS AND Password = @Password COLLATE SQL_Latin1_General_Cp1_CS_AS
";

25
Successful Student Account Login

Fig. 13: Successful Student Login

If account type - Student is chosen, all fields are filled and there is a match in the database, a
message box is displayed to signal that the login has been successful and the user is taken to next
page, Student Menu.

26
Student Menu

Fig. 14: Student Menu


Student Menu is designed for the student to get the details of book information such as book
name, book publication, book author and to check whether the book is available or not. The
search feature and search filters help the student find their desired books in a short time. If the
student wishes to leave the menu, he/she can do so using the logout button.

27
Student Menu with ‘Available’ Filter selected

Fig.15: Student Menu - ‘Available’ Filter Selected


If Available Filter is selected, the Datagrid displays the results in which the status of the book is
‘Available’. If the user wishes to search for only those books which are available, he/she can
enter text in the search textbox while the ‘Available’ filter is selected and then click on the
Search button. Then, only those books will be searched, which are available.

28
Student Menu with ‘Not Available’ Filter selected

Fig.16: Student Menu - ‘Not available’ Filter Selected


If Not Available Filter is selected, the Datagrid displays the results in which the status of the
book is ‘Not Available’. The search function searches books based on the selected filter similar
to the above case. In this case, only those books will be searched which are not available.

29
Student Menu - ‘Searching’ with ‘Both’ Filter (Search Key Word ‘Th’)

Fig. 17: Student Menu - ‘Searching’


If ‘Both’ Filter is selected, the Datagrid displays the results in which the status of the book is
both ‘Available’ and ‘Not Available’.The search function searches books based on the selected
filter similar to the above cases. In this case, all the books will be searched.

30
Successful Admin Account Login

Fig. 18: Successful Admin Menu

If account type - Admin is chosen, all fields are filled and there is a match in the database, a
message box is displayed to signal that the login has been successful and the user is taken to next
page, Main Menu.

31
Admin Main Menu

Fig.19: Admin Main Menu


Main Menu can be accessed by admins only and consists of various features. The ‘Total Books’
displays the number of varieties of books present in the system. Similarly, the ‘Total Books
Issued’ displays the number of books issued by the students. The ‘Total Users' exhibits the total
number of students and admin using the system. If the admin wishes to add other admin, it can
be easily done by clicking the ‘Add Admin’ button and providing required sign up details.
Clicking the ‘Student’ and ‘Books’ button provides a new window consisting of the details of
students and books respectively. The ‘View Book Stock’ provides a new window which gives
information about the books in stock of the system. Clicking ‘Issue Books’ button provides a
window through which books can be issued. Finally, ‘Return Books’ button provides a window
from which returned books can be registered.

32
Admin - ‘Add Admin’ Form

Fig 20: Add Admin Form


Admin Sign Up Form/Add Admin Form - provides a mechanism by which the main admin can
add other admins to the system. This can be done by the main admin only. The admin can simply
provide the details of the person in this form. Unlike Student Sign Up Form, it does not contain
the Login option in this form.

33
Admin - Students Menu

Fig. 21: Admin - Students Menu

Students Menu is used by the admin to get the information about the students who are using the
system. It consists of a Datagrid which displays the information about a student which includes
name, roll number, department, contact, email, address, date of birth along with their images.
The search button makes easier to search a particular student. Clicking ‘Add Student’ button
gives a form which can be used to add new students’ information. The existing details can be
easily edited by clicking ‘Edit Student’ button and providing new information in respective
fields. The existing records can be deleted using the ‘Delete Record’ button.

34
Admin - Student Menu ‘Searching’ (Search Key Word ‘Tam’)

Fig. 22: Admin - Student Menu ‘Searching’

The student records may be searched to find the desired record. The parameters it searches are -
Student name, Student roll number, Student department, Student contact, Student email, Student
date of birth and Student Address. The user may search for any value in the aforementioned
columns. Furthermore, the search box is programmed using the KeyUp Event which runs the
search query every time a new character is entered. This removes the need for clicking the
‘Search’ button. As there is no need for pressing a ‘Search’ button in this context, the ‘Search’
button is omitted.

35
Admin - Students ‘Add Students Info’ Form

Fig. 23: Admin - Student Menu - ‘Add Students Info’ Form

Add Student Info form is used to add information of new students using the system. For this, the
admin fills the details of the student in respective fields. It also supports the addition of an image
of the student. It can be done by clicking the ‘Select’ button and supports the following image
filters.

Filters: JPEG Files (*.jpeg)|*.jpeg| PNG Files (*.png)| *png| JPG Files (*.jpg)| *.jpg|All files
(*.*)|*.*

36
Admin - Student Menu - Editing and Deleting Student Records - Record Selection Prompt

Fig. 24: Select Student Record Prompt - Message Box

A Select Student Record Prompt - Message Box appears when the admin tries to edit or delete
student records without clicking any cell of the Datagrid. The edit and delete can only be
performed when any cell of the Datagrid is selected.

37
Admin - Student Menu - Edit Student Info Form

Fig. 25: Admin - Student Menu - Edit Student Info Form

Edit Student Info Form can be used to update or modify the existing information of the student.
For this, all the fields must be provided with correct information. It also supports the
modification of the image of the student.

38
Admin - Student Menu - Edit Student Record Successful

Fig. 26: Edit Student Record Successful - Message

Record edited successfully-message box appears when the new information is successfully added
to the system.

39
Admin - Student Menu - Record Deletion Confirmation Prompt

Fig.27 : Admin - Student Menu - Record Deletion Confirmation Prompt

When the ‘Delete Record’ button is clicked, a Record Deletion Confirmation Prompt appears so
as to confirm if the admin truly wants to delete the record. This avoids the loss of data if the
admin had mistakenly clicked the button.

40
Admin - Student Menu - Student Record Deletion Successful - Message

Fig. 28: Admin - Student Menu - Student Record Deletion Successful - Message

Record deleted successfully Message-box appears when the record is successfully deleted from
the database.

41
Admin - Student Menu - Menu refreshed after student record deletion

Fig.29 : Admin - Student Menu - Menu refreshed after student record deletion

As you can see, after getting the ‘Record deleted successfully’ message and refreshing the menu,
record no. 12 - Record with Student Name -Sample Record from the page before has been
deleted and is no longer stored in database. The record has been removed from Datagrid and
deleted from the database table.

42
Admin - Books Menu

Fig. 30: Admin - Books Menu

Books consist of the Datagrid which gives information about the name, author, publication,
price, quantity, purchase date and available quantity of the books stored in the database. The
records can be searched by clicking the ‘Search’ button. The content of the Datagrid is refreshed
when the ‘refresh’ button is clicked. Clicking the ‘Add’ button provides a new form which can
be used to store information about the new books. Clicking the cells of Datagrid shows the field
to update the book information. The information stored in the database can be easily deleted by
clicking the ‘Delete’ button.

43
Admin - Books Menu - Search - KeyWord ‘Comp’

Fig. 31: Admin - Books Menu - Search

When ‘Comp’ is typed in the textbox followed by the clicking of ‘Search’ button, the
information of the records which consist of Comp substring is displayed in the Datagrid.

44
Admin - Books Menu - Add Books Form

Fig. 32: Admin - Books Menu - Add Books Form

Add Books Info is used to add information on new books into the database. For this, the correct
data must be provided in the corresponding fields. Clicking on ‘Save’ button after entering
values of correct data types in the fields will insert the information into the ‘Books’ table of the
database.

45
Admin - Books Menu - Edit Books

Fig. 33: Admin - Books Menu - Edit Books

When any cell of the Datagrid is clicked, then the values are automatically entered in the
corresponding field. After changing the required values, the ‘Update’ button is clicked so as to
update values in the database.

46
Admin - Books Menu - Deletion - Record Selection Prompt

Fig. 34: Admin - Books Menu - Deletion - Record Selection Prompt

A Deletion-Record Message Box appears when the admin tries to delete book records without
clicking any cell of the Datagrid. The delete can only be performed when any cell of the Datagrid
is selected.

47
Admin - Books Menu - Deletion - Deletion Confirmation

Fig. 35: Admin - Books Menu - Deletion - Deletion Confirmation

When the ‘Delete’ button is clicked, a Record Deletion Confirmation Prompt appears so as to
confirm if the admin truly wants to delete the records of book. This avoids the loss of data if the
admin had mistakenly clicked the ‘Delete’ button.

48
Admin - Books Menu - Deletion - Successful Deletion - Message

Fig. 36: Admin - Books Menu - Deletion - Successful Deletion - Message

Record deleted successfully Message-box appears when the record of the book is successfully
deleted from the database.

49
Admin - Issue Books Menu

Fig. 37: Admin - Issue Books Menu

The user is required to enter the student roll number in the student roll no. field and click on
‘Search’. If the student roll number matches that of one of the records of the database, the
student’s record details are filled in automatically in the right-hand-side fields. Then, we search
for the name of the book which we require. The names of the books which match the text in the
‘Book Name’ field appear in a list box. We can toggle and choose one of the books in the list by
either pressing the down arrow then pressing enter or by clicking on the book name. Then, the
user must choose the Issue Date. After all the fields have been completed (filled), the user clicks
the ‘Issue Book’ button. If the book to be lent is available, then the above message ‘Book issued
successfully’ is shown. Otherwise, the message - ‘Book not available’ is displayed.

50
Admin - Return Books Menu

Fig. 38: Admin - Return Books Menu

The user is required to enter the roll number of the student who is going to return the book. Then,
he/she clicks ‘Search Books’ and if the roll number is valid, all of the books borrowed by the
student associated with the roll number are displayed. After clicking on one of the books in the
Datagrid, the book name and issue date fields are automatically filled. The user can then choose
the return date and then click on ‘Return Book’.

The message ‘Book returned successfully’ will be displayed which signals that the book-return
operation has been successful.

51
Admin - Books Stock Menu

Fig. 39: Admin - Books Stock Menu

The Book Stock Menu shows a list of the books that are stored in the library. The total quantity
of books owned by the library (be it available or currently lent) and the total number of available
books are displayed on the upper datagrid. We can choose one of the listed books by clicking on
the desired cell. If one or more books of the selected kind are currently being lent out to students,
then the information of students who have borrowed the book will be displayed in the lower
datagrid.

52
Admin - Books Stock Menu - Search (Key Word ‘Co’)

Fig. 40: Admin - Books Stock Menu - Search

The books in the upper datagrid may be searched for a particular book by typing in the ‘Search’
box. The procedure after the selection of a certain cell or row or book is the same as above (the
case without the use of search function in the Book Stock menu.

53
Admin - Book Stocks - Sending Email - Mail Sent - Message

Fig. 41: Admin - Book Stocks - Sending Email

After completing the above steps of selecting a book, if we wish to contact a student and inform
him of the upcoming due date or ask him/her to return the book soon, we can do so by clicking
on the related student information in the lower datagrid which will fill up the Email field beside
it on the left. Then, we can type out our message contents in the ‘Content’ section just below.

After we have finished composing our email, we can send it by clicking the ‘Send’ button below.

If the transmission of the message was successful, the message ‘Mail Sent’ will be dispayed as
shown above.

In our program, the mailing capability is restricted to Gmail only.

In the above screenshot, a mail has been sent to : library.test.ps@gmail.com

54
Admin - Books Stock - Checking Mail on Receiver’s Side

Fig. 42: Admin - Books Stock - Checking Mail

As we can see above in the inbox of the email address - library.test.ps@gmail.com , the mail
which we had previously sent has been received.

Hence, our email system is successful.

55
Conclusion:

As we know, managing a library manually is tiresome, difficult, is less secure,


time-consuming, costly and is very difficult to search the records. So, digitizing the library
management system is an effective method for increasing productivity and smooth functioning of
the library as a library is an integral part of any university or educational institution.

So with the help of this project, we are sure that it will help librarians to manage the
library. Using this software, a librarian can easily search the database information with few
clicks. It will simplify the work of the librarians as Graphical User Interfaces are used to simplify
the user interaction with the software. The security of the data stored can be ensured in this
software. All the processes like adding, deleting, updating and searching of books and student
can be done promptly. The maintenance cost of the software will be very less compared to that
done manually.

We have learnt a great deal on how to create and manage a project through working on
this project in a team. Our confidence and skills in programming have received a significant
boost by completing this project. We have more ideas to improve this application software in the
future. We hope to release better versions of this application and software of much higher quality
in the coming days.

56
Further Works/Recommendations

We understand that our project is not perfect and that there are many things which we must
improve upon. We hope to re-model our system and enhance the existing features in the
upcoming versions. Here, we include some of the features which we hope to add to our existing
project in our future updates:
● Additional features in Student account:
Currently, users who have logged in through their ‘Student’ Account can only view the
books and filter them using three filters: Available, Not available and Both.
Our plan is to add the feature such that the user will have the ability to search for available books
and then reserve their desired book through the system so that it will be ensured that they are
able to obtain a copy of the book.

● Online Connectivity:
Our application is totally desktop-based with the only use of online capabilities being the
ability to send emails to the book borrowers. We wish to create an online system in the future
which can be integrated with our existing system to allow online access and manipulation of
remote desktop data and information.

● Backup and printable format production:


Our plans include adding the ability to create multiple backup files of data and produce
printable file formats to print the information. This will add ease of use to the system to even the
novice users.

● Connection to Cloud Services:


We wish to integrate our systems to cloud services such as Amazon Web Services or
Google Cloud Services to create real-time backups of the information and add a further layer of
security.

57
Some recommendations to our system users are:
We have tried our best to make the user interface simple and understandable to the average
person. But it is recommended that users have basic knowledge on how to use a computer system
and how to interact with its system components.
It is also recommended that users have experience in working in a library or at least understand
the basic principles at work.

58
Bibliography/References

1. Programmer, Social. “[Part-1] - Designing a Library Management System (C# Windows


Form)”, Video, 18 Aug. 2018,
https://www.youtube.com/watch?v=sKX1UIq5CxE&t=332s
2. C# Ui Academy. “Designing a Modern Signup Form in Winform App Visual C#”, Video,
19 Oct. 2017”, ​https://www.youtube.com/watch?v=iVzZyerZh48&t=281s
3. Gravelle, Rob. “A Guide to MySQL Prepared Statements and Parameterized Queries.”
Database Journal, DatabaseJournal, 5 Nov. 2018,
www.databasejournal.com/features/mysql/a-guide-to-mysql-prepared-statements-and-par
ameterized-queries.html.
4. Jain Ashish, “​How to do a case sensitive search in WHERE clause (I'm using SQL
Server)?​”, 2 Dec. 2009,
https://stackoverflow.com/questions/1831105/how-to-do-a-case-sensitive-search-in-wher
e-clause-im-using-sql-server
5. Adnipara Amit, 17 Nov. 2017, “​library management system project in c#.net​”, Video
Playlist,
https://www.youtube.com/playlist?list=PLsdZGHZMYvk0WF1Q8NkWtrz4Jh-thMp2E
6. Paweł Żelazny​ ,“​How to make a parameterized SELECT query in C#?​” Question Forum,
1 Apr. 2019,
https://stackoverflow.com/questions/55978404/how-to-make-a-parameterized-select-quer
y-in-c
7. Dinesh, “​How to open a new form from another form​”, Question Forum, Nov. 2011,
https://stackoverflow.com/questions/3965043/how-to-open-a-new-form-from-another-for
m

59
Appendix

In the appendix section for the this project, we have included the source code used in the various
forms used in this project. The various forms along with their source codes are as follows:

Form 1: Add_Student_Info Form:

using System;
using System.Data;
using System.Data.SqlClient;
using System.IO;
using System.Windows.Forms;

namespace Library_Management_System
{
public partial class Add_Student_Info : Form
{
string password;
string wanted_path;
DialogResult result;

SqlConnection connection = new SqlConnection(@"Data


Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=D:\College\Project\NEW\Library Management
System\Library Management System\Library_Management_System.mdf;Integrated Security=True");
public Add_Student_Info()
{
InitializeComponent();
}

private void Add_Student_Info_SelectImage_Button_Click(object sender, EventArgs e)


{
password = Class1.GetRandomPassword(20);

wanted_path =
Path.GetDirectoryName(Path.GetDirectoryName(System.IO.Directory.GetCurrentDirectory()));
result = Add_Student_Info_openFileDialog.ShowDialog();

if (result == DialogResult.OK) // Test result


{
Add_Student_Info_Name_PictureBox.ImageLocation = Add_Student_Info_openFileDialog.FileName;
Add_Student_Info_Name_PictureBox.SizeMode = PictureBoxSizeMode.StretchImage;

}
}

private void Add_Student_Info_Name_Exit_Click(object sender, EventArgs e)


{

60
Add_Student_Info.ActiveForm.Close();
}

public void Add_Student_Info_Save_Button_Click(object sender, EventArgs e)


{
try
{
string img_path;
File.Copy(Add_Student_Info_openFileDialog.FileName, wanted_path + "\\Student_images\\" + password
+ ".jpg");

img_path = "Student_images\\" + password + ".jpg";

connection.Open();
SqlCommand cmd = connection.CreateCommand();
cmd.CommandType = CommandType.Text;

cmd.CommandText = "INSERT INTO Student_info VALUES (@Student_name , @Student_image


,@Student_roll_no , @Student_department , @Student_contact, @Student_email, @Student_date_of_birth,
@Student_address)";

cmd.Parameters.AddWithValue("@Student_name", Add_Student_Info_Name_Textbox.Text);
cmd.Parameters.AddWithValue("@Student_image", img_path.ToString());
cmd.Parameters.AddWithValue("@Student_roll_no", Add_Student_Info_Roll_No_Textbox.Text);
cmd.Parameters.AddWithValue("@Student_department", Add_Student_Info_Department_Textbox.Text);
cmd.Parameters.AddWithValue("@Student_contact", Add_Student_Info_Contact_Textbox.Text);
cmd.Parameters.AddWithValue("@Student_email", Add_Student_Info_Email_Textbox.Text);
cmd.Parameters.AddWithValue("@Student_date_of_birth",
Add_Student_Info_DOB_dateTimePicker.Value);
cmd.Parameters.AddWithValue("@Student_address", Add_Student_Info_Address_Textbox.Text);

cmd.ExecuteNonQuery();
connection.Close();

Add_Student_Info_Name_Textbox.Clear();
Add_Student_Info_Roll_No_Textbox.Clear();
Add_Student_Info_Department_Textbox.Clear();
Add_Student_Info_Contact_Textbox.Clear();
Add_Student_Info_Email_Textbox.Clear();
Add_Student_Info_Address_Textbox.Clear();

MessageBox.Show("Record inserted successfully");

Admin_Student_MainMenu Admin_Student_MainMenu_page = new Admin_Student_MainMenu();


}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString());
}
}
}
}

61
Form 2: Admin_Book_Add_Books Form

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace LMS_BookInfo
{
public partial class Admin_Book_Add_Books : Form
{
SqlConnection con = new SqlConnection(@"Data
Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=D:\College\Project\NEW\Library Management
System\Library Management System\Library_Management_System.mdf;Integrated Security=True");

public Admin_Book_Add_Books()
{
InitializeComponent();
}

private void add_books_LMS_form_Load(object sender, EventArgs e)


{

private void add_books_Exit_Click(object sender, EventArgs e)


{
this.Close();
}

private void addbooks_savebutton_Click(object sender, EventArgs e)


{
if (con.State == ConnectionState.Open)
{
con.Close();
}
con.Open();
try
{
SqlCommand cmd = con.CreateCommand();
cmd.CommandType = CommandType.Text;

cmd.CommandText = "INSERT INTO Books VALUES (@Book_name , @Book_author ,


@Book_publication , @Book_price , @Book_quantity , @Book_purchase_date , @Book_quantity,
@Book_status)";

62
cmd.Parameters.AddWithValue("@Book_name", addbooks_bookname_textbox.Text);
cmd.Parameters.AddWithValue("@Book_author", addbooks_bookauthor_textbox.Text);
cmd.Parameters.AddWithValue("@Book_publication", addbooks_bookpublication_textbox.Text);
cmd.Parameters.AddWithValue("@Book_price", addbooks_bookprice_textbox.Text);
cmd.Parameters.AddWithValue("@Book_quantity", addbooks_bookquantity_textbox.Text);
cmd.Parameters.AddWithValue("@Book_purchase_date", dateTimePicker1.Value);
cmd.Parameters.AddWithValue("@Book_status", "Available");

cmd.ExecuteNonQuery();

addbooks_bookname_textbox.Clear();
addbooks_bookauthor_textbox.Clear();
addbooks_bookpublication_textbox.Clear();
addbooks_bookprice_textbox.Clear();
addbooks_bookquantity_textbox.Clear();

con.Close();

MessageBox.Show("Added Successfully!");

}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
}

63
Form 3: Admin_Book_MainMenu Form

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace LMS_BookInfo
{ public partial class Admin_Book_MainMenu : Form
{
SqlConnection con = new SqlConnection(@"Data
Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=D:\College\Project\NEW\Library Management
System\Library Management System\Library_Management_System.mdf;Integrated Security = True");

int i= -1;
public Admin_Book_MainMenu()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)


{
Display_Books();

private void Books_Exit_Click(object sender, EventArgs e)


{
this.Close();
}

private void Books_LMS_add_button_Click(object sender, EventArgs e)


{
Admin_Book_Add_Books ab = new Admin_Book_Add_Books();
ab.Show();
}

private void Books_LMS_search_button_Click(object sender, EventArgs e)


{
int i = 0;

if (con.State == ConnectionState.Open)
{
con.Close();

64
}

con.Open();
try
{
SqlCommand cmd = con.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "SELECT * FROM Books WHERE Book_name LIKE('%" +
books_search_textbox.Text + "%') OR Book_author LIKE('%" + books_search_textbox.Text + "%') OR
Book_publication LIKE('%" + books_search_textbox.Text + "%')";
cmd.ExecuteNonQuery();
DataTable dt = new DataTable();
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(dt);
i = Convert.ToInt32(dt.Rows.Count.ToString());
dataGridView1.DataSource = dt;
con.Close();

if (i == 0)
{
MessageBox.Show("No books found for your search!");
}

}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}

private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)


{
update_panel.Visible = true;

if (con.State == ConnectionState.Open)
{
con.Close();
}
con.Open();

try

{
i = Convert.ToInt32(dataGridView1.SelectedCells[0].Value.ToString());
SqlCommand cmd = con.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "SELECT * FROM Books WHERE id="+ i +"";
cmd.ExecuteNonQuery();
DataTable dt = new DataTable();
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(dt);
foreach(DataRow dr in dt.Rows)
{
book_update_bookname.Text = dr["Book_name"].ToString();

65
book_update_bookauthor.Text = dr["Book_author"].ToString();
book_update_bookprice.Text = dr["Book_price"].ToString();
book_update_bookpublication.Text = dr["Book_publication"].ToString();
book_update_quantity.Text = dr["Book_quantity"].ToString();
book_update_bookpurchasedate.Value = Convert.ToDateTime(dr["Book_purchase_date"].ToString());

}
con.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}

private void Books_LMS_update_button_Click(object sender, EventArgs e)


{
if (con.State == ConnectionState.Open)
{
con.Close();
}
con.Open();

try

{
i = Convert.ToInt32(dataGridView1.SelectedCells[0].Value.ToString());
SqlCommand cmd = con.CreateCommand();

cmd.CommandText = "UPDATE Books SET Book_name = @Book_name , Book_author =


@Book_author, Book_publication = @Book_publication , Book_price = @Book_price ,Book_quantity =
@Book_quantity , Book_purchase_date = @Book_purchase_date WHERE id = @id";

cmd.Parameters.AddWithValue("@Book_name", book_update_bookname.Text);
cmd.Parameters.AddWithValue("@Book_author", book_update_bookauthor.Text);
cmd.Parameters.AddWithValue("@Book_publication", book_update_bookpublication.Text);
cmd.Parameters.AddWithValue("@Book_price", book_update_bookprice.Text);
cmd.Parameters.AddWithValue("@Book_quantity", book_update_quantity.Text);
cmd.Parameters.AddWithValue("@Book_purchase_date", book_update_bookpurchasedate.Value);

cmd.Parameters.AddWithValue("@id", i);

cmd.ExecuteNonQuery();
Display_Books();
MessageBox.Show("Updated Successfully");
update_panel.Visible = false;

}
catch (Exception ex)
{
MessageBox.Show(ex.Message);

66
}
}

public void Display_Books()


{

if (con.State == ConnectionState.Open)
{
con.Close();
}
con.Open();

try

{
SqlCommand cmd = con.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "SELECT * FROM Books";
cmd.ExecuteNonQuery();
DataTable dt = new DataTable();
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(dt);
dataGridView1.DataSource = dt;
con.Close();

}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}

private void Books_LMS_delete_button_Click(object sender, EventArgs e)


{
int j = 0;
if (i == -1)
{
MessageBox.Show("Please select a record");
}
else
{
DialogResult Del = MessageBox.Show("Are you sure you want to delete record no." +
dataGridView1.SelectedRows[0].Cells[0].Value.ToString(), "Delete", MessageBoxButtons.YesNo,
MessageBoxIcon.Question);
if (Del == DialogResult.Yes)
{
if (con.State == ConnectionState.Open)
{
con.Close();
}
con.Open();

67
SqlCommand cmd = con.CreateCommand();
cmd.CommandType = CommandType.Text;

cmd.CommandText = "DELETE FROM Books WHERE id = " + i + "";

cmd.ExecuteNonQuery();

Display_Books();

update_panel.Visible = false;

j++;

}
else
{
this.Show();
}

if (j > 0)
{
MessageBox.Show("Record deleted successfully");
}

con.Close();
}
}

private void refresh_button_Click(object sender, EventArgs e)


{
dataGridView1.Refresh();

Display_Books();
}

}
}

68
Form 4: Admin_Student_MainMenu Form

using System;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Windows.Forms;

namespace Library_Management_System
{
public partial class Admin_Student_MainMenu : Form
{
SqlConnection connection = new SqlConnection(@"Data
Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=D:\College\Project\NEW\Library Management
System\Library Management System\Library_Management_System.mdf;Integrated Security=True");

public static int cell_id_num;

int select_check = 0;
public Admin_Student_MainMenu()
{
InitializeComponent();

private void AdminStudent_MainMenu_Load(object sender, EventArgs e)


{
Fill_Grid();
}

public void Fill_Grid()


{
int i = 0;

if (connection.State == ConnectionState.Open)
{
connection.Close();
}
connection.Open();

SqlCommand cmd = connection.CreateCommand();


cmd.CommandType = CommandType.Text;
cmd.CommandText = "SELECT * FROM Student_info";
cmd.ExecuteNonQuery();
DataTable dt = new DataTable();
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(dt);
Admin_Student_MainMenu_dataGridView.DataSource = dt;

Bitmap img;
DataGridViewImageColumn imageCol = new DataGridViewImageColumn();

69
imageCol.HeaderText = "Student Image";
imageCol.ImageLayout = DataGridViewImageCellLayout.Zoom;
imageCol.Width = 100;
Admin_Student_MainMenu_dataGridView.Columns.Add(imageCol);

foreach (DataRow dr in dt.Rows)


{
img = new Bitmap(@"..\..\" + dr["Student_image"].ToString());

Admin_Student_MainMenu_dataGridView.Rows[i].Cells[9].Value = img;
Admin_Student_MainMenu_dataGridView.Rows[i].Height = 100;
i = i + 1;
}

private void Admin_Student_MainMenu_Exit_Click(object sender, EventArgs e)


{
MainMenu MainMenu_Page = new MainMenu();
this.Hide();
MainMenu_Page.Show();
}

private void Admin_Student_MainMenu_Add_Student_Button_Click(object sender, EventArgs e)


{
Add_Student_Info Add_Student_Info_Page = new Add_Student_Info();
Add_Student_Info_Page.Show();

private void Admin_Student_MainMenu_Add_Student_Search_Textbox_KeyUp(object sender, KeyEventArgs


e)
{
try
{
Admin_Student_MainMenu_dataGridView.Columns.Clear();
Admin_Student_MainMenu_dataGridView.Refresh();

int i = 0;

if (connection.State == ConnectionState.Open)
{
connection.Close();
}
connection.Open();

SqlCommand cmd = connection.CreateCommand();


cmd.CommandType = CommandType.Text;

cmd.CommandText = "SELECT * FROM Student_info WHERE ((Student_name LIKE ('%" +


Admin_Student_MainMenu_Add_Student_Search_Textbox.Text + "%')) OR (Student_roll_no LIKE ('%" +

70
Admin_Student_MainMenu_Add_Student_Search_Textbox.Text + "%' )) OR (Student_department LIKE ('%" +
Admin_Student_MainMenu_Add_Student_Search_Textbox.Text + "%')) OR (Student_contact LIKE ('%" +
Admin_Student_MainMenu_Add_Student_Search_Textbox.Text + "%')) OR (Student_email LIKE ('%" +
Admin_Student_MainMenu_Add_Student_Search_Textbox.Text + "%' )) OR (CONVERT(VARCHAR,
Student_date_of_birth, 120) LIKE ('%" + Admin_Student_MainMenu_Add_Student_Search_Textbox.Text + "%' ))
OR (Student_address LIKE ('%" + Admin_Student_MainMenu_Add_Student_Search_Textbox.Text + "%')))";

cmd.ExecuteNonQuery();
DataTable dt = new DataTable();
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(dt);
Admin_Student_MainMenu_dataGridView.DataSource = dt;

Bitmap img;
DataGridViewImageColumn imageCol = new DataGridViewImageColumn();
imageCol.HeaderText = "Student Image";
imageCol.ImageLayout = DataGridViewImageCellLayout.Zoom;
imageCol.Width = 100;
Admin_Student_MainMenu_dataGridView.Columns.Add(imageCol);

foreach (DataRow dr in dt.Rows)


{
img = new Bitmap(@"..\..\" + dr["Student_image"].ToString());
Admin_Student_MainMenu_dataGridView.Rows[i].Cells[9].Value = img;
Admin_Student_MainMenu_dataGridView.Rows[i].Height = 100;
i = i + 1;
}

}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString());
}

private void Admin_Student_MainMenu_dataGridView_CellClick(object sender, DataGridViewCellEventArgs


e)
{
select_check = 1;
cell_id_num =
Convert.ToInt32(Admin_Student_MainMenu_dataGridView.SelectedCells[0].Value.ToString());
}

private void Admin_Student_MainMenu_Add_Student_Edit_Button_Click(object sender, EventArgs e)


{
if (select_check == 0)
{
MessageBox.Show("Please select a record");
}
else
{

71
Edit_Student_Info Edit_Student_Info_page = new Edit_Student_Info();
Edit_Student_Info_page.Show();
}
}

private void Admin_Student_MainMenu_RefreshButton_Click(object sender, EventArgs e)


{
Admin_Student_MainMenu_dataGridView.Columns.Clear();
Admin_Student_MainMenu_dataGridView.Refresh();

int i = 0;

if (connection.State == ConnectionState.Open)
{
connection.Close();
}
connection.Open();

SqlCommand cmd = connection.CreateCommand();


cmd.CommandType = CommandType.Text;
cmd.CommandText = "SELECT * FROM Student_info";
cmd.ExecuteNonQuery();
DataTable dt = new DataTable();
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(dt);
Admin_Student_MainMenu_dataGridView.DataSource = dt;

Bitmap img;
DataGridViewImageColumn imageCol = new DataGridViewImageColumn();
imageCol.HeaderText = "Student Image";
imageCol.ImageLayout = DataGridViewImageCellLayout.Zoom;
imageCol.Width = 100;
Admin_Student_MainMenu_dataGridView.Columns.Add(imageCol);

foreach (DataRow dr in dt.Rows)


{
img = new Bitmap(@"..\..\" + dr["Student_image"].ToString());

Admin_Student_MainMenu_dataGridView.Rows[i].Cells[9].Value = img;
Admin_Student_MainMenu_dataGridView.Rows[i].Height = 100;
i = i + 1;
}
}

private void Admin_Student_MainMenu_Add_Student_Delete_Button_Click(object sender, EventArgs e)


{
int j = 0;
if (select_check == 0)
{
MessageBox.Show("Please select a record");
}
else
{

72
DialogResult Del = MessageBox.Show("Are you sure you want to delete record no. " +
Admin_Student_MainMenu_dataGridView.SelectedRows[0].Cells[0].Value.ToString(), "Delete",
MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (Del == DialogResult.Yes)
{
if (connection.State == ConnectionState.Open)
{
connection.Close();
}
connection.Open();

SqlCommand select_record_cmd = connection.CreateCommand();


select_record_cmd.CommandType = CommandType.Text;

select_record_cmd.CommandText = "DELETE FROM Student_info WHERE Id ='"+ cell_id_num +"'";

select_record_cmd.ExecuteNonQuery();

j++;
}
else
{
this.Show();
}

if (j > 0)
{
MessageBox.Show("Record deleted successfully");
}

connection.Close();
}

}
}
}

73
Form 5: Book_stock Form

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;

using System.ComponentModel.DataAnnotations;

using System.Net;
using System.Net.Mail;

namespace Library_Management_System
{
public partial class Book_stock : Form
{
SqlConnection connection = new SqlConnection(@"Data
Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=D:\College\Project\NEW\Library Management
System\Library Management System\Library_Management_System.mdf;Integrated Security=True");

public Book_stock()
{
InitializeComponent();
}

private void Book_Stock_Exit_Click(object sender, EventArgs e)


{
Book_stock.ActiveForm.Close();
}

private void Book_stock_Load(object sender, EventArgs e)


{
if (connection.State == ConnectionState.Open)
{
connection.Close();
}
connection.Open();

Fill_Books_Info();
}

public void Fill_Books_Info()


{
SqlCommand select_command = connection.CreateCommand();

74
select_command.CommandType = CommandType.Text;
select_command.CommandText = "SELECT Book_name, Book_author, Book_quantity,
Book_available_quantity FROM Books";
select_command.ExecuteNonQuery();
DataTable select_books_datatable = new DataTable();
SqlDataAdapter select_books_dataadapter = new SqlDataAdapter(select_command);
select_books_dataadapter.Fill(select_books_datatable);
Book_Stock_Books_dataGridView.DataSource = select_books_datatable;
}

private void Book_Stock_Books_dataGridView_CellClick(object sender, DataGridViewCellEventArgs e)


{
string Book_name_var;
Book_name_var = Book_Stock_Books_dataGridView.SelectedCells[0].Value.ToString();

SqlCommand select_students_command = connection.CreateCommand();


select_students_command.CommandType = CommandType.Text;
select_students_command.CommandText = "SELECT * FROM Issue_books WHERE Books_name =
@Books_name AND Books_return_date IS NULL";
select_students_command.Parameters.AddWithValue("@Books_name", Book_name_var);
select_students_command.ExecuteNonQuery();
DataTable select_students_datatable = new DataTable();
SqlDataAdapter select_students_dataadapter = new SqlDataAdapter(select_students_command);
select_students_dataadapter.Fill(select_students_datatable);
Book_Stock_Students_dataGridView.DataSource = select_students_datatable;
}

private void Book_Stock_Search_TextBox_KeyUp(object sender, KeyEventArgs e)


{
SqlCommand search_command = connection.CreateCommand();
search_command.CommandType = CommandType.Text;
search_command.CommandText = "SELECT Book_name, Book_author, Book_quantity,
Book_available_quantity FROM Books WHERE (Book_name LIKE '%"+ Book_Stock_Search_TextBox.Text +"%'
OR Book_author LIKE '%"+ Book_Stock_Search_TextBox.Text +"%')";
search_command.ExecuteNonQuery();
DataTable search_books_datatable = new DataTable();
SqlDataAdapter search_books_dataadapter = new SqlDataAdapter(search_command);
search_books_dataadapter.Fill(search_books_datatable);
Book_Stock_Books_dataGridView.DataSource = search_books_datatable;
Book_Stock_Books_dataGridView.Refresh();

private void Book_Stock_Students_dataGridView_CellClick(object sender, DataGridViewCellEventArgs e)


{
string Student_email_var;
Student_email_var = Book_Stock_Students_dataGridView.SelectedCells[4].Value.ToString();

Book_Stock_Email_Textbox.Text = Student_email_var;

75
}

private void Book_Stock_Send_Email_Button_Click(object sender, EventArgs e)


{
SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587);
smtp.EnableSsl = true;
smtp.UseDefaultCredentials = false;
//(Username, password)
smtp.Credentials = new NetworkCredential("library.personnel@gmail.com", "sumitprabin");
MailMessage mail = new MailMessage("library.personnel@gmail.com", Book_Stock_Email_Textbox.Text,
"Regarding Book Return", Book_Stock_Email_Content_Textbox.Text);
mail.Priority = MailPriority.High;
smtp.Send(mail);
MessageBox.Show("Mail Sent");
}
}
}

76
File 1: Class1.cs
using System;
using System.Data;
using System.Configuration;
using System.Web;

/// <summary>
/// Summary description for Class1
/// </summary>
public class Class1
{

public static string GetRandomPassword(int length)


{
char[] chars =
"abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ".ToCharArray();
string password = string.Empty;
Random random = new Random();

for (int i = 0; i < length; i++)


{
int x = random.Next(1, chars.Length);
//For avoiding Repetation of Characters
if (!password.Contains(chars.GetValue(x).ToString()))
password += chars.GetValue(x);
else
i=i-1;
}
return password;
}

77
Form 6: Edit_Student_Info Form

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.IO;

namespace Library_Management_System
{
public partial class Edit_Student_Info : Form
{

string password;
string wanted_path;

int wanted_path_check;

SqlConnection connection = new SqlConnection(@"Data


Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=D:\College\Project\NEW\Library Management
System\Library Management System\Library_Management_System.mdf;Integrated Security=True;Connect
Timeout=30");

public Edit_Student_Info()
{
InitializeComponent();
}

int cell_id_num = Admin_Student_MainMenu.cell_id_num;


private void Edit_Student_Info_Load(object sender, EventArgs e)
{

if (connection.State == ConnectionState.Open)
{
connection.Close();
}
connection.Open();

SqlCommand select_record_cmd = connection.CreateCommand();


select_record_cmd.CommandType = CommandType.Text;
select_record_cmd.CommandText = "SELECT * FROM Student_info WHERE Id = @Id";
select_record_cmd.Parameters.AddWithValue("@Id", cell_id_num);

select_record_cmd.ExecuteNonQuery();

78
DataTable dt = new DataTable();
SqlDataAdapter da = new SqlDataAdapter(select_record_cmd);
da.Fill(dt);

foreach (DataRow dr in dt.Rows)


{
Edit_Student_Info_Name_Textbox.Text = dr["Student_name"].ToString();
Edit_Student_Info_Roll_No_Textbox.Text = dr["Student_roll_no"].ToString();
Edit_Student_Info_Department_Textbox.Text = dr["Student_department"].ToString();
Edit_Student_Info_Contact_Textbox.Text = dr["Student_contact"].ToString();
Edit_Student_Info_Email_Textbox.Text = dr["Student_email"].ToString();
Edit_Student_Info_Contact_Textbox.Text = dr["Student_contact"].ToString();
Edit_Student_Info_Address_Textbox.Text = dr["Student_address"].ToString();

Bitmap img;

foreach (DataRow dr2 in dt.Rows)


{
img = new Bitmap(@"..\..\" + dr["Student_image"].ToString());
Edit_Student_Info_Name_PictureBox.Image = img;
}

connection.Close();
}
}

private void Edit_Student_Info_SelectImage_Button_Click(object sender, EventArgs e)


{
password = Class1.GetRandomPassword(20);

wanted_path =
Path.GetDirectoryName(Path.GetDirectoryName(System.IO.Directory.GetCurrentDirectory()));
DialogResult result = Edit_Student_Info_openFileDialog.ShowDialog();

Edit_Student_Info_openFileDialog.Filter = "JPEG Files (*.jpeg)|*.jpeg| PNG Files (*.png)| *png| JPG Files
(*.jpg)| *.jpg";

if (result == DialogResult.OK) // Test result


{
Edit_Student_Info_Name_PictureBox.ImageLocation = Edit_Student_Info_openFileDialog.FileName;
Edit_Student_Info_Name_PictureBox.SizeMode = PictureBoxSizeMode.StretchImage;
wanted_path_check = 1;
}

private void Edit_Student_Info_Name_Exit_Click(object sender, EventArgs e)


{
Edit_Student_Info.ActiveForm.Close();
}

protected void Edit_Student_Info_Save_Button_Click(object sender, EventArgs e)

79
{
if (connection.State == ConnectionState.Open)
{
connection.Close();
}
connection.Open();
try
{
string img_path;
SqlCommand cmd = connection.CreateCommand();
cmd.CommandType = CommandType.Text;
if (wanted_path_check != 1)
{
cmd.CommandText = "UPDATE Student_info SET Student_name = @Student_name, Student_roll_no
= @Student_roll_no, Student_department = @Student_department, Student_contact = @Student_contact,
Student_email = @Student_email, Student_date_of_birth = @Student_date_of_birth, Student_address =
@Student_address WHERE id = @id";

cmd.Parameters.AddWithValue("@Student_name", Edit_Student_Info_Name_Textbox.Text);
cmd.Parameters.AddWithValue("@Student_roll_no", Edit_Student_Info_Roll_No_Textbox.Text);
cmd.Parameters.AddWithValue("@Student_department",
Edit_Student_Info_Department_Textbox.Text);
cmd.Parameters.AddWithValue("@Student_contact", Edit_Student_Info_Contact_Textbox.Text);
cmd.Parameters.AddWithValue("@Student_email", Edit_Student_Info_Email_Textbox.Text);
cmd.Parameters.AddWithValue("@Student_date_of_birth",
Edit_Student_Info_DOB_dateTimePicker.Value);
cmd.Parameters.AddWithValue("@Student_address", Edit_Student_Info_Address_Textbox.Text);
cmd.Parameters.AddWithValue("@id", cell_id_num);

}
else
{
File.Copy(Edit_Student_Info_openFileDialog.FileName, wanted_path + "\\Student_images\\" +
password + ".jpg");

img_path = "Student_images\\" + password + ".jpg";

cmd.CommandText = "UPDATE Student_info SET Student_name = @Student_name, Student_image=


@Student_image, Student_roll_no = @Student_roll_no, Student_department = @Student_department,
Student_contact = @Student_contact, Student_email = @Student_email, Student_date_of_birth =
@Student_date_of_birth, Student_address = @Student_address WHERE id = @id";

cmd.Parameters.AddWithValue("@Student_name", Edit_Student_Info_Name_Textbox.Text);
cmd.Parameters.AddWithValue("@Student_roll_no", Edit_Student_Info_Roll_No_Textbox.Text);
cmd.Parameters.AddWithValue("@Student_image", img_path.ToString());
cmd.Parameters.AddWithValue("@Student_department",
Edit_Student_Info_Department_Textbox.Text);
cmd.Parameters.AddWithValue("@Student_contact", Edit_Student_Info_Contact_Textbox.Text);
cmd.Parameters.AddWithValue("@Student_email", Edit_Student_Info_Email_Textbox.Text);
cmd.Parameters.AddWithValue("@Student_date_of_birth",
Edit_Student_Info_DOB_dateTimePicker.Value);
cmd.Parameters.AddWithValue("@Student_address", Edit_Student_Info_Address_Textbox.Text);

80
cmd.Parameters.AddWithValue("@id", cell_id_num);

}
cmd.ExecuteNonQuery();
connection.Close();

MessageBox.Show("Record edited successfully");


}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString());
}
}

81
Form 7: Issue_books Form

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

using System.Data.SqlClient;

namespace Library_Management_System
{
public partial class Issue_books : Form
{

SqlConnection connection = new SqlConnection(@"Data


Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=D:\College\Project\NEW\Library Management
System\Library Management System\Library_Management_System.mdf;Integrated Security=True");

public Issue_books()
{
InitializeComponent();
}

private void Issue_books_Load(object sender, EventArgs e)


{
if (connection.State == ConnectionState.Open)
{
connection.Close();
}
connection.Open();

private void Issue_Books_Search_Student_Button_Click(object sender, EventArgs e)


{
int i = 0;

SqlCommand cmd = connection.CreateCommand();


cmd.CommandType = CommandType.Text;
cmd.CommandText = "SELECT * FROM Student_info WHERE Student_roll_no = '"+
Issue_Books_Search_Student_Roll_no_Textbox.Text +"'";
cmd.ExecuteNonQuery();
DataTable dt = new DataTable();
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(dt);

i = Convert.ToInt32(dt.Rows.Count.ToString());

82
if (i == 0)
{
MessageBox.Show("Student associated with this roll number not found");
}
else
{
foreach (DataRow dr in dt.Rows)
{
Issue_Books_Student_Name_Textbox.Text = dr["Student_name"].ToString();
Issue_Books_Student_Department_Textbox.Text = dr["Student_department"].ToString();
Issue_Books_Student_Contact_Textbox.Text = dr["Student_contact"].ToString();
Issue_Books_Student_Email_Textbox.Text = dr["Student_email"].ToString();
Issue_Books_Student_DOB_Textbox.Text = dr["Student_date_of_birth"].ToString();
Issue_Books_Student_Address_Textbox.Text = dr["Student_address"].ToString();

}
}

private void Issue_Books_Exit_Click(object sender, EventArgs e)


{
Issue_books.ActiveForm.Close();
}

private void Issue_Books_Book_Name_Textbox__KeyUp_Event(object sender, KeyEventArgs e)


{

int count = 0;

if (e.KeyCode != Keys.Enter)
{

Issue_Books_Book_Name_listBox.Items.Clear();

SqlCommand cmd = connection.CreateCommand();


cmd.CommandType = CommandType.Text;
cmd.CommandText = "SELECT * FROM Books WHERE Book_name LIKE ('%" +
Issue_Books_Book_Name_Textbox.Text + "%')";
cmd.ExecuteNonQuery();
DataTable dt = new DataTable();
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(dt);

count = Convert.ToInt32(dt.Rows.Count.ToString());

if (count > 0)

83
{
Issue_Books_Book_Name_listBox.Visible = true;
foreach (DataRow dr in dt.Rows)
{
Issue_Books_Book_Name_listBox.Items.Add(dr["Book_name"].ToString());
}
}

}
}

private void Issue_Books_Book_Name_Textbox_KeyDown_Event(object sender, KeyEventArgs e)


{
if (e.KeyCode == Keys.Down)
{
Issue_Books_Book_Name_listBox.Focus();

Issue_Books_Book_Name_listBox.SelectedIndex = 0;
}

private void Issue_Books_Book_Name_listBox_MouseClick_Event(object sender, MouseEventArgs e)


{
try
{
Issue_Books_Book_Name_Textbox.Text = Issue_Books_Book_Name_listBox.SelectedItem.ToString();
}
catch (Exception)
{
MessageBox.Show("Please click on one of the books");
}
Issue_Books_Book_Name_listBox.Visible = false;
}

private void Issue_Books_Book_Name_Listbox_KeyDown_Event(object sender, KeyEventArgs e)


{
if (e.KeyCode == Keys.Enter)
{
Issue_Books_Book_Name_Textbox.Text = Issue_Books_Book_Name_listBox.SelectedItem.ToString();
Issue_Books_Book_Name_listBox.Visible = false;
}
}

private void Issue_Books_Issue_Button_Click(object sender, EventArgs e)


{
int book_quantity = 0;

int book_available_quantity_check = 0;

SqlCommand cmd_check = connection.CreateCommand();


cmd_check.CommandType = CommandType.Text;

84
cmd_check.CommandText = "SELECT * FROM Books WHERE Book_name = @Book_name";

cmd_check.Parameters.AddWithValue("@Book_name", Issue_Books_Book_Name_Textbox.Text);

cmd_check.ExecuteNonQuery();

DataTable dt2 = new DataTable();


SqlDataAdapter da2 = new SqlDataAdapter(cmd_check);
da2.Fill(dt2);

foreach (DataRow dr2 in dt2.Rows)


{
book_quantity = Convert.ToInt32(dr2["Book_available_quantity"].ToString());
}

if (book_quantity > 0)
{
SqlCommand cmd = connection.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "INSERT INTO Issue_books VALUES (@Student_roll_no, @Student_department,
@Student_contact, @Student_email, @Student_date_of_birth, @Student_address, @Books_name,
@Books_issue_date, @Books_return_date)";

cmd.Parameters.AddWithValue("@Student_roll_no",
Issue_Books_Search_Student_Roll_no_Textbox.Text);
cmd.Parameters.AddWithValue("@Student_department",
Issue_Books_Student_Department_Textbox.Text);
cmd.Parameters.AddWithValue("@Student_contact", Issue_Books_Student_Contact_Textbox.Text);
cmd.Parameters.AddWithValue("@Student_email", Issue_Books_Student_Email_Textbox.Text);
cmd.Parameters.AddWithValue("@Student_date_of_birth", Issue_Books_Student_DOB_Textbox.Text);
cmd.Parameters.AddWithValue("@Student_address", Issue_Books_Student_Address_Textbox.Text);
cmd.Parameters.AddWithValue("@Books_name", Issue_Books_Book_Name_Textbox.Text);
cmd.Parameters.AddWithValue("@Books_issue_date",
Issue_Books_Issue_Date_dateTimePicker.Value.ToShortDateString());
cmd.Parameters.AddWithValue("@Books_return_date", DBNull.Value);

cmd.ExecuteNonQuery();

SqlCommand cmd_update = connection.CreateCommand();


cmd_update.CommandType = CommandType.Text;

cmd_update.CommandText = "UPDATE Books SET Book_available_quantity =


Book_available_quantity-1 WHERE Book_name = @Book_name";

cmd_update.Parameters.AddWithValue("@Book_name", Issue_Books_Book_Name_Textbox.Text);

cmd_update.ExecuteNonQuery();

MessageBox.Show("Book issued successfully");

SqlCommand cmd_book_available_check = connection.CreateCommand();


cmd_book_available_check.CommandType = CommandType.Text;

85
cmd_book_available_check.CommandText = "SELECT * FROM Books WHERE Book_name =
@Book_name";

cmd_book_available_check.Parameters.AddWithValue("@Book_name",
Issue_Books_Book_Name_Textbox.Text);

cmd_book_available_check.ExecuteNonQuery();

DataTable dt3 = new DataTable();


SqlDataAdapter da3 = new SqlDataAdapter(cmd_book_available_check);
da3.Fill(dt3);

foreach (DataRow dr3 in dt3.Rows)


{
book_available_quantity_check = Convert.ToInt32(dr3["Book_available_quantity"].ToString());
}

if (book_available_quantity_check == 0)
{
SqlCommand cmd_update_status = connection.CreateCommand();
cmd_update_status.CommandType = CommandType.Text;

cmd_update_status.CommandText = "UPDATE Books SET Book_status = @Book_Status WHERE


Book_name = @Book_name";

cmd_update_status.Parameters.AddWithValue("@Book_status", "Not available");


cmd_update_status.Parameters.AddWithValue("@Book_name",
Issue_Books_Book_Name_Textbox.Text);

cmd_update_status.ExecuteNonQuery();
}

}
else
{
MessageBox.Show("Book not available");
}
}
}
}

86
Form 8: Login Form

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

using System.Data.SqlClient;

using LMS_BookInfo;

namespace Library_Management_System
{
public partial class Login : Form
{
public static string username_id = "UsernameID";

SqlConnection con = new SqlConnection(@"Data


Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=D:\College\Project\NEW\Library Management
System\Library Management System\Library_Management_System.mdf;Integrated Security=True");

int count = 0;

public static int form_select = 0;


int radio_check = 0;

public Login()
{
InitializeComponent();
}

private void LoginExit_Click(object sender, EventArgs e)


{
Application.Exit();
}

private void Login_Load(object sender, EventArgs e)


{
if (con.State == ConnectionState.Open)
{
con.Close();
}
con.Open();
}

private void LoginUsername_Enter(object sender, EventArgs e)


{

87
if (LoginUsername.Text == "Username")
{
LoginUsername.Text = "";

LoginUsername.ForeColor = Color.Black;
}

private void LoginUsername_Leave(object sender, EventArgs e)


{
if (LoginUsername.Text == "")
{
LoginUsername.Text = "Username";

LoginUsername.ForeColor = Color.Silver;
}

private void LoginPassword_Enter(object sender, EventArgs e)


{
if (LoginPassword.Text == "Password")
{
LoginPassword.Text = "";

LoginPassword.ForeColor = Color.Black;

LoginPassword.PasswordChar = '•';
}

private void LoginPassword_Leave(object sender, EventArgs e)


{
if (LoginPassword.Text == "")
{
LoginPassword.Text = "Password";

LoginPassword.ForeColor = Color.Silver;

LoginPassword.PasswordChar = '\0';
}

private void LoginSignUp_Click(object sender, EventArgs e)


{
form_select = 1;
this.Hide();
SignUp SignUp_Page = new SignUp();
SignUp_Page.Show();

88
private void LoginLoginButton_Click(object sender, EventArgs e)
{
if (radio_check == 1)
{
try
{
if (con.State == ConnectionState.Open)
{
con.Close();
}
con.Open();
SqlCommand cmd = con.CreateCommand();
cmd.CommandType = CommandType.Text;

cmd.CommandText = "SELECT Username,Password FROM Admin WHERE Username = @Username


COLLATE SQL_Latin1_General_Cp1_CS_AS AND Password = @Password COLLATE
SQL_Latin1_General_Cp1_CS_AS ";

cmd.Parameters.AddWithValue("@Username", LoginUsername.Text);
cmd.Parameters.AddWithValue("@Password", LoginPassword.Text);

cmd.ExecuteNonQuery();

DataTable dt = new DataTable();


SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(dt);
count = Convert.ToInt32(dt.Rows.Count.ToString());
if (count == 0)
{
MessageBox.Show("Username and Password not found");
}
else
{
MessageBox.Show("Admin Welcome!");

MainMenu MainMenu_page = new MainMenu();


MainMenu_page.Show();

this.Hide();
}
con.Close();

}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}

else if (radio_check == 2)
{

89
try
{
if (con.State == ConnectionState.Open)
{
con.Close();
}

con.Open();
SqlCommand cmd = con.CreateCommand();
cmd.CommandType = CommandType.Text;

cmd.CommandText = "SELECT * FROM Student WHERE Username = @Username COLLATE


SQL_Latin1_General_Cp1_CS_AS AND Password = @Password COLLATE SQL_Latin1_General_Cp1_CS_AS
";

cmd.Parameters.AddWithValue("@Username", LoginUsername.Text);
cmd.Parameters.AddWithValue("@Password", LoginPassword.Text);

cmd.ExecuteNonQuery();
DataTable dt = new DataTable();
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(dt);
count = Convert.ToInt32(dt.Rows.Count.ToString());
if (count == 0)
{
MessageBox.Show("Username and Password not found");
}
else
{
username_id = LoginUsername.Text;

MessageBox.Show("Student Welcome!");
Student_Menu Student_Menu_page = new Student_Menu();
Student_Menu_page.Show();

this.Hide();
}
con.Close();

}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}

}
else
{
MessageBox.Show("Please select account type: Admin or Student");
}
}

90
private void admin_radiobutton_CheckedChanged(object sender, EventArgs e)
{
radio_check = 1;
}

private void student_radiobutton_CheckedChanged(object sender, EventArgs e)


{
radio_check = 2;
}
}
}

91
Form 9: MainMenu Form

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

using LMS_BookInfo;
using System.Data.SqlClient;

namespace Library_Management_System
{
public partial class MainMenu : Form
{
SqlConnection con = new SqlConnection(@"Data
Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=D:\College\Project\NEW\Library Management
System\Library Management System\Library_Management_System.mdf;Integrated Security=True");
public MainMenu()
{
InitializeComponent();
}

private void Mainmenu_students_button_Click(object sender, EventArgs e)


{
Admin_Student_MainMenu AdminStudent_MainMenuPage = new Admin_Student_MainMenu();
this.Hide();
AdminStudent_MainMenuPage.Show();
}

private void LoginExit_Click(object sender, EventArgs e)


{
Application.Exit();
}

private void Mainmenu_books_button_Click(object sender, EventArgs e)


{
LMS_BookInfo.Admin_Book_MainMenu Admin_Book_MainMenu_page = new
Admin_Book_MainMenu();
Admin_Book_MainMenu_page.Show();
}

private void Mainmenu_issue_books_button_Click(object sender, EventArgs e)


{
Issue_books Issue_books_page = new Issue_books();
Issue_books_page.Show();
}

92
private void Mainmenu_return_books_button_Click(object sender, EventArgs e)
{
Return_books Return_Books_Page = new Return_books();
Return_Books_Page.Show();
}

private void Mainmenu_view_book_stock_button_Click(object sender, EventArgs e)


{
Book_stock Book_stock_page = new Book_stock();
Book_stock_page.Show();
}

private void Mainmenu_add_admin_button_Click(object sender, EventArgs e)


{
Login.form_select = 2;
SignUp Sign_Up_page = new SignUp();
Sign_Up_page.Show();
}

private void Mainmenu_logout_button_Click(object sender, EventArgs e)


{
MainMenu.ActiveForm.Close();
Login Login_page = new Login();
Login_page.Show();
}
public void Update_Books_Number()
{
if (con.State == ConnectionState.Open)
{
con.Close();
}
con.Open();
SqlCommand cmd = con.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "SELECT count(id) FROM Books";
int result_books = (int)cmd.ExecuteScalar();
menu_total_books_label.Text = result_books.ToString();
con.Close();
}
public void Update_Issue_Books_Number()
{
if (con.State == ConnectionState.Open)
{
con.Close();
}
con.Open();
SqlCommand cmd = con.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "SELECT count(id) FROM Issue_books WHERE Books_return_date IS NULL";
int result_issue_books = (int)cmd.ExecuteScalar();
menu_total_books_issued_label.Text = result_issue_books.ToString();
con.Close();
}

93
public void Update_Users_Number()
{
if (con.State == ConnectionState.Open)
{
con.Close();
}
con.Open();

int result_Admin_User = 0;
int result_Student_User = 0;

SqlCommand cmd1 = con.CreateCommand();


cmd1.CommandType = CommandType.Text;
cmd1.CommandText = "Select count(Username) from Admin";
result_Admin_User = (int)cmd1.ExecuteScalar();

SqlCommand cmd2 = con.CreateCommand();


cmd2.CommandType = CommandType.Text;
cmd2.CommandText = "Select count(Username) from Student";
result_Student_User = (int)cmd2.ExecuteScalar();

int result_User = 0;

result_User = result_Admin_User + result_Student_User;

menu_total_users_label.Text = result_User.ToString();
con.Close();
}

private void MainMenu_Load(object sender, EventArgs e)


{
Update_Books_Number();
Update_Issue_Books_Number();
Update_Users_Number();
}

private void MainMenu_RefreshButton_Click(object sender, EventArgs e)


{
Update_Books_Number();
Update_Issue_Books_Number();
Update_Users_Number();
}
}
}

94
Form 10: Return_books Form

using System;
using System.Data;
using System.Data.SqlClient;
using System.Windows.Forms;

namespace Library_Management_System
{
public partial class Return_books : Form
{

SqlConnection con = new SqlConnection(@"Data


Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=D:\College\Project\NEW\Library Management
System\Library Management System\Library_Management_System.mdf;Integrated Security=True");

public Return_books()
{
InitializeComponent();
}

private void Return_Books_Search_Books_Button_Click(object sender, EventArgs e)


{
Return_Books_Menu_DataGrid_Panel.Visible = true;

Fill_Grid(Return_Books_Search_Student_Roll_no_Textbox.Text);

private void Return_books_Load(object sender, EventArgs e)


{
if (con.State == ConnectionState.Open)
{
con.Close();
}
con.Open();
}

public void Fill_Grid(string Student_roll_no) // String should be replaced with int


{
SqlCommand cmd = con.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "SELECT * FROM Issue_books WHERE Student_roll_no = @Student_roll_no AND
Books_return_date IS NULL";

95
cmd.Parameters.AddWithValue("Student_roll_no", Return_Books_Search_Student_Roll_no_Textbox.Text);

cmd.ExecuteNonQuery();
DataTable dt = new DataTable();
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(dt);
Return_Books_dataGridView.DataSource = dt;

private void Return_Books_Exit_Click(object sender, EventArgs e)


{
Return_books.ActiveForm.Close();
}

private void Return_Books_dataGridView_CellClick(object sender, DataGridViewCellEventArgs e)


{
Return_Books_Return_Book_Panel.Visible = true;

int i;
i = Convert.ToInt32(Return_Books_dataGridView.SelectedCells[0].Value.ToString());

SqlCommand cmd = con.CreateCommand();


cmd.CommandType = CommandType.Text;
cmd.CommandText = "SELECT * FROM Issue_books WHERE id = @id";

cmd.Parameters.AddWithValue("@id", i);

cmd.ExecuteNonQuery();
DataTable dt = new DataTable();
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(dt);

foreach (DataRow dr in dt.Rows)


{
Return_Books_Book_Name_Label_Display.Text = dr["Books_name"].ToString();
Return_Books_Issue_Date_Label_Display.Text = dr["Books_issue_date"].ToString();
}
}

private void Return_Books_Issue_Book_Button_Click(object sender, EventArgs e)


{
int i;
i = Convert.ToInt32(Return_Books_dataGridView.SelectedCells[0].Value.ToString());

int book_available_quantity_check = 0;

SqlCommand cmd = con.CreateCommand();


cmd.CommandType = CommandType.Text;
cmd.CommandText = "UPDATE Issue_books SET Books_return_date = @Books_return_date WHERE Id =
@Id";

96
cmd.Parameters.AddWithValue("@Books_return_date",
Return_Books_Return_Date_dateTimePicker.Value.ToString());
cmd.Parameters.AddWithValue("@id", i);

cmd.ExecuteNonQuery();

SqlCommand cmd2 = con.CreateCommand();


cmd2.CommandType = CommandType.Text;
cmd2.CommandText = "UPDATE Books SET Book_available_quantity = Book_available_quantity + 1
WHERE Book_name = @Book_name";

cmd2.Parameters.AddWithValue("@Book_name", Return_Books_Book_Name_Label_Display.Text);

cmd2.ExecuteNonQuery();

MessageBox.Show("Book returned successfully");

SqlCommand cmd_book_available_check = con.CreateCommand();


cmd_book_available_check.CommandType = CommandType.Text;

cmd_book_available_check.CommandText = "SELECT * FROM Books WHERE Book_name =


@Book_name";

cmd_book_available_check.Parameters.AddWithValue("@Book_name",
Return_Books_Book_Name_Label_Display.Text);

cmd_book_available_check.ExecuteNonQuery();

DataTable dt3 = new DataTable();


SqlDataAdapter da3 = new SqlDataAdapter(cmd_book_available_check);
da3.Fill(dt3);

foreach (DataRow dr3 in dt3.Rows)


{
book_available_quantity_check = Convert.ToInt32(dr3["Book_available_quantity"].ToString());
}

if (book_available_quantity_check == 1)
{
SqlCommand cmd_update_status = con.CreateCommand();
cmd_update_status.CommandType = CommandType.Text;

cmd_update_status.CommandText = "UPDATE Books SET Book_status = @Book_Status WHERE


Book_name = @Book_name";

cmd_update_status.Parameters.AddWithValue("@Book_status", "Available");
cmd_update_status.Parameters.AddWithValue("@Book_name",
Return_Books_Book_Name_Label_Display.Text);

cmd_update_status.ExecuteNonQuery();

97
}

Return_Books_Return_Book_Panel.Visible = false;

Fill_Grid(Return_Books_Search_Student_Roll_no_Textbox.Text);
}
}
}

98
Form 11: SignUp Form

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

using System.Data.SqlClient;

using System.ComponentModel.DataAnnotations;

namespace Library_Management_System
{
public partial class SignUp : Form
{
SqlConnection con = new SqlConnection(@"Data
Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=D:\College\Project\NEW\Library Management
System\Library Management System\Library_Management_System.mdf;Integrated Security=True");

int email_check = 0;
int form_select = Login.form_select;

public SignUp()
{
InitializeComponent();
}

private void SignUp_Load(object sender, EventArgs e)


{
if (form_select == 1)
{
SignUp_Login_Label.Visible = true;
}
else if (form_select == 2)
{
SignUp_Already_have_account_label.Visible = false;
SignUp_Login_Label.Visible = false;
}
}

private void SignUp_Exit_Click(object sender, EventArgs e)


{
if (form_select == 1)
{
Application.Exit();
}
else if (form_select == 2)

99
{
SignUp.ActiveForm.Close();
}

private void SignUp_Usename_Textbox_Enter(object sender, EventArgs e)


{
if (SignUp_Username_Textbox.Text == "Username")
{
SignUp_Username_Textbox.Text = "";

SignUp_Username_Textbox.ForeColor = Color.Black;
}
}

private void SignUp_Usename_Textbox_Leave(object sender, EventArgs e)


{
if (SignUp_Username_Textbox.Text == "")
{
SignUp_Username_Textbox.Text = "Username";

SignUp_Username_Textbox.ForeColor = Color.Silver;
}
}

private void SignUp_First_Name_Textbox_Enter(object sender, EventArgs e)


{
if (SignUp_First_Name_Textbox.Text == "John")
{
SignUp_First_Name_Textbox.Text = "";

SignUp_First_Name_Textbox.ForeColor = Color.Black;
}
}

private void SignUp_First_Name_Textbox_Leave(object sender, EventArgs e)


{
if (SignUp_First_Name_Textbox.Text == "")
{
SignUp_First_Name_Textbox.Text = "John";

SignUp_First_Name_Textbox.ForeColor = Color.Silver;
}
}

private void SignUp_Password_Textbox_Enter(object sender, EventArgs e)


{
if (SignUp_Password_Textbox.Text == "Password")
{
SignUp_Password_Textbox.Text = "";

100
SignUp_Password_Textbox.ForeColor = Color.Black;

SignUp_Password_Textbox.PasswordChar = '•';
}
}

private void SignUp_Password_Textbox_Leave(object sender, EventArgs e)


{
if (SignUp_Password_Textbox.Text == "")
{
SignUp_Password_Textbox.Text = "Password";

SignUp_Password_Textbox.ForeColor = Color.Silver;

SignUp_Password_Textbox.PasswordChar = '\0';
}
}

private void SignUp_Re_Password_Textbox_Enter(object sender, EventArgs e)


{
if (SignUp_Re_Password_Textbox.Text == "Password")
{
SignUp_Re_Password_Textbox.Text = "";

SignUp_Re_Password_Textbox.ForeColor = Color.Black;

SignUp_Re_Password_Textbox.PasswordChar = '•';
}
}

private void SignUp_Re_Password_Textbox_Leave(object sender, EventArgs e)


{
if (SignUp_Re_Password_Textbox.Text == "")
{
SignUp_Re_Password_Textbox.Text = "Password";

SignUp_Re_Password_Textbox.ForeColor = Color.Silver;

SignUp_Re_Password_Textbox.PasswordChar = '\0';
}
}

private void SignUp_Email_Textbox_Enter(object sender, EventArgs e)


{
if (SignUp_Email_Textbox.Text == "someone@example.com")
{
SignUp_Email_Textbox.Text = "";

SignUp_Email_Textbox.ForeColor = Color.Black;
}
}

private void SignUp_Email_Textbox_Leave(object sender, EventArgs e)


{

101
if (SignUp_Email_Textbox.Text == "")
{
SignUp_Email_Textbox.Text = "someone@example.com";

SignUp_Email_Textbox.ForeColor = Color.Silver;
}
}

private void SignUp_Login_Label_Click(object sender, EventArgs e)


{
Login Login_Page = new Login();
this.Hide();
Login_Page.Show();
}

private void SignUp_SignUp_Button_Click(object sender, EventArgs e)


{
string s = SignUp_Email_Textbox.Text;
var check_email_attribute = new EmailAddressAttribute();

if ((SignUp_Username_Textbox.ForeColor == Color.Silver) || (SignUp_First_Name_Textbox.ForeColor ==


Color.Silver) || (SignUp_Last_Name_Textbox.ForeColor == Color.Silver) || (SignUp_Password_Textbox.ForeColor
== Color.Silver) || (SignUp_Re_Password_Textbox.ForeColor == Color.Silver) ||
(SignUp_Email_Textbox.ForeColor == Color.Silver))
{
MessageBox.Show("Please fill all the fields");
}
else
{
if (check_email_attribute.IsValid(s))
{
email_check = 1;
}
else
{
email_check = 2;
}

if (SignUp_Password_Textbox.Text == SignUp_Re_Password_Textbox.Text && email_check == 1)


{
if (form_select == 1)
{
try
{
if (con.State == ConnectionState.Open)
{
con.Close();
}

con.Open();
SqlCommand cmd = con.CreateCommand();
cmd.CommandType = CommandType.Text;

102
cmd.CommandText = "INSERT INTO Student VALUES(@Username, @Password, @Firstname ,
@Lastname, @Email)";
string username = SignUp_Username_Textbox.Text.Length == 0 ? "ABC" :
SignUp_Username_Textbox.Text;
string password = SignUp_Password_Textbox.Text.Length == 0 ? null :
SignUp_Password_Textbox.Text;
string firstname = SignUp_First_Name_Textbox.Text.Length == 0 ? null :
SignUp_First_Name_Textbox.Text;
string lastname = SignUp_Last_Name_Textbox.Text.Length == 0 ? null :
SignUp_Last_Name_Textbox.Text;
string email = SignUp_Email_Textbox.Text.Length == 0 ? null : SignUp_Email_Textbox.Text;

cmd.Parameters.AddWithValue("@Username", username);
cmd.Parameters.AddWithValue("@Password", password);
cmd.Parameters.AddWithValue("@Firstname", firstname);
cmd.Parameters.AddWithValue("@Lastname", lastname);
cmd.Parameters.AddWithValue("@Email", email);

cmd.ExecuteNonQuery();

SignUp_First_Name_Textbox.Clear();
SignUp_Last_Name_Textbox.Clear();
SignUp_Password_Textbox.Clear();
SignUp_Re_Password_Textbox.Clear();
SignUp_Username_Textbox.Clear();
SignUp_Email_Textbox.Clear();

con.Close();

MessageBox.Show("Added Successfully!");

}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}

else if (form_select == 2)
{
try
{
if (con.State == ConnectionState.Open)
{
con.Close();
}

103
con.Open();
SqlCommand cmd = con.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "INSERT INTO Admin VALUES( @Username, @Password, @Firstname ,
@Lastname, @Email)";
string username = SignUp_Username_Textbox.Text.Length == 0 ? null :
SignUp_Username_Textbox.Text;
string password = SignUp_Password_Textbox.Text.Length == 0 ? null :
SignUp_Password_Textbox.Text;
string firstname = SignUp_First_Name_Textbox.Text.Length == 0 ? null :
SignUp_First_Name_Textbox.Text;
string lastname = SignUp_Last_Name_Textbox.Text.Length == 0 ? null :
SignUp_Last_Name_Textbox.Text;
string email = SignUp_Email_Textbox.Text.Length == 0 ? null : SignUp_Email_Textbox.Text;

cmd.Parameters.AddWithValue("@Username", username);
cmd.Parameters.AddWithValue("@Password", password);
cmd.Parameters.AddWithValue("@Firstname", firstname);
cmd.Parameters.AddWithValue("@Lastname", lastname);
cmd.Parameters.AddWithValue("@Email", email);

cmd.ExecuteNonQuery();

SignUp_First_Name_Textbox.Clear();
SignUp_Last_Name_Textbox.Clear();
SignUp_Password_Textbox.Clear();
SignUp_Re_Password_Textbox.Clear();
SignUp_Username_Textbox.Clear();
SignUp_Email_Textbox.Clear();

con.Close();

MessageBox.Show("Added Successfully!");

}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
else
{
if (SignUp_Password_Textbox.Text != SignUp_Re_Password_Textbox.Text)

104
{
MessageBox.Show("Passwords do not match");
}
if (email_check == 2)
{
MessageBox.Show("Email is not valid");
}

}
}
}

private void SignUp_Last_Name_Textbox_Enter(object sender, EventArgs e)


{
if (SignUp_Last_Name_Textbox.Text == "Doe")
{
SignUp_Last_Name_Textbox.Text = "";

SignUp_Last_Name_Textbox.ForeColor = Color.Black;
}
}

private void SignUp_Last_Name_Textbox_Leave(object sender, EventArgs e)


{
if (SignUp_Last_Name_Textbox.Text == "")
{
SignUp_Last_Name_Textbox.Text = "Doe";

SignUp_Last_Name_Textbox.ForeColor = Color.Silver;
}
}
}
}

105
Form 12: Student_Menu Form

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

using System.Data.SqlClient;

using System.ComponentModel.DataAnnotations;

namespace Library_Management_System
{
public partial class SignUp : Form
{
SqlConnection con = new SqlConnection(@"Data
Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=D:\College\Project\NEW\Library Management
System\Library Management System\Library_Management_System.mdf;Integrated Security=True");

int email_check = 0;
int form_select = Login.form_select;

public SignUp()
{
InitializeComponent();
}

private void SignUp_Load(object sender, EventArgs e)


{
if (form_select == 1)
{
SignUp_Login_Label.Visible = true;
}
else if (form_select == 2)
{
SignUp_Already_have_account_label.Visible = false;
SignUp_Login_Label.Visible = false;
}
}

private void SignUp_Exit_Click(object sender, EventArgs e)


{
if (form_select == 1)
{
Application.Exit();
}
else if (form_select == 2)

106
{
SignUp.ActiveForm.Close();
}

private void SignUp_Usename_Textbox_Enter(object sender, EventArgs e)


{
if (SignUp_Username_Textbox.Text == "Username")
{
SignUp_Username_Textbox.Text = "";

SignUp_Username_Textbox.ForeColor = Color.Black;
}
}

private void SignUp_Usename_Textbox_Leave(object sender, EventArgs e)


{
if (SignUp_Username_Textbox.Text == "")
{
SignUp_Username_Textbox.Text = "Username";

SignUp_Username_Textbox.ForeColor = Color.Silver;
}
}

private void SignUp_First_Name_Textbox_Enter(object sender, EventArgs e)


{
if (SignUp_First_Name_Textbox.Text == "John")
{
SignUp_First_Name_Textbox.Text = "";

SignUp_First_Name_Textbox.ForeColor = Color.Black;
}
}

private void SignUp_First_Name_Textbox_Leave(object sender, EventArgs e)


{
if (SignUp_First_Name_Textbox.Text == "")
{
SignUp_First_Name_Textbox.Text = "John";

SignUp_First_Name_Textbox.ForeColor = Color.Silver;
}
}

private void SignUp_Password_Textbox_Enter(object sender, EventArgs e)


{
if (SignUp_Password_Textbox.Text == "Password")
{
SignUp_Password_Textbox.Text = "";

107
SignUp_Password_Textbox.ForeColor = Color.Black;

SignUp_Password_Textbox.PasswordChar = '•';
}
}

private void SignUp_Password_Textbox_Leave(object sender, EventArgs e)


{
if (SignUp_Password_Textbox.Text == "")
{
SignUp_Password_Textbox.Text = "Password";

SignUp_Password_Textbox.ForeColor = Color.Silver;

SignUp_Password_Textbox.PasswordChar = '\0';
}
}

private void SignUp_Re_Password_Textbox_Enter(object sender, EventArgs e)


{
if (SignUp_Re_Password_Textbox.Text == "Password")
{
SignUp_Re_Password_Textbox.Text = "";

SignUp_Re_Password_Textbox.ForeColor = Color.Black;

SignUp_Re_Password_Textbox.PasswordChar = '•';
}
}

private void SignUp_Re_Password_Textbox_Leave(object sender, EventArgs e)


{
if (SignUp_Re_Password_Textbox.Text == "")
{
SignUp_Re_Password_Textbox.Text = "Password";

SignUp_Re_Password_Textbox.ForeColor = Color.Silver;

SignUp_Re_Password_Textbox.PasswordChar = '\0';
}
}

private void SignUp_Email_Textbox_Enter(object sender, EventArgs e)


{
if (SignUp_Email_Textbox.Text == "someone@example.com")
{
SignUp_Email_Textbox.Text = "";

SignUp_Email_Textbox.ForeColor = Color.Black;
}
}

private void SignUp_Email_Textbox_Leave(object sender, EventArgs e)


{

108
if (SignUp_Email_Textbox.Text == "")
{
SignUp_Email_Textbox.Text = "someone@example.com";

SignUp_Email_Textbox.ForeColor = Color.Silver;
}
}

private void SignUp_Login_Label_Click(object sender, EventArgs e)


{
Login Login_Page = new Login();
this.Hide();
Login_Page.Show();
}

private void SignUp_SignUp_Button_Click(object sender, EventArgs e)


{
string s = SignUp_Email_Textbox.Text;
var check_email_attribute = new EmailAddressAttribute();

if ((SignUp_Username_Textbox.ForeColor == Color.Silver) || (SignUp_First_Name_Textbox.ForeColor ==


Color.Silver) || (SignUp_Last_Name_Textbox.ForeColor == Color.Silver) || (SignUp_Password_Textbox.ForeColor
== Color.Silver) || (SignUp_Re_Password_Textbox.ForeColor == Color.Silver) ||
(SignUp_Email_Textbox.ForeColor == Color.Silver))
{
MessageBox.Show("Please fill all the fields");
}
else
{
if (check_email_attribute.IsValid(s))
{
email_check = 1;
}
else
{
email_check = 2;
}

if (SignUp_Password_Textbox.Text == SignUp_Re_Password_Textbox.Text && email_check == 1)


{
if (form_select == 1)
{
try
{
if (con.State == ConnectionState.Open)
{
con.Close();
}

con.Open();
SqlCommand cmd = con.CreateCommand();
cmd.CommandType = CommandType.Text;

109
cmd.CommandText = "INSERT INTO Student VALUES(@Username, @Password, @Firstname ,
@Lastname, @Email)";
string username = SignUp_Username_Textbox.Text.Length == 0 ? "ABC" :
SignUp_Username_Textbox.Text;
string password = SignUp_Password_Textbox.Text.Length == 0 ? null :
SignUp_Password_Textbox.Text;
string firstname = SignUp_First_Name_Textbox.Text.Length == 0 ? null :
SignUp_First_Name_Textbox.Text;
string lastname = SignUp_Last_Name_Textbox.Text.Length == 0 ? null :
SignUp_Last_Name_Textbox.Text;
string email = SignUp_Email_Textbox.Text.Length == 0 ? null : SignUp_Email_Textbox.Text;

cmd.Parameters.AddWithValue("@Username", username);
cmd.Parameters.AddWithValue("@Password", password);
cmd.Parameters.AddWithValue("@Firstname", firstname);
cmd.Parameters.AddWithValue("@Lastname", lastname);
cmd.Parameters.AddWithValue("@Email", email);

cmd.ExecuteNonQuery();

SignUp_First_Name_Textbox.Clear();
SignUp_Last_Name_Textbox.Clear();
SignUp_Password_Textbox.Clear();
SignUp_Re_Password_Textbox.Clear();
SignUp_Username_Textbox.Clear();
SignUp_Email_Textbox.Clear();

con.Close();

MessageBox.Show("Added Successfully!");

}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}

else if (form_select == 2)
{
try
{
if (con.State == ConnectionState.Open)
{
con.Close();
}

110
con.Open();
SqlCommand cmd = con.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "INSERT INTO Admin VALUES( @Username, @Password, @Firstname ,
@Lastname, @Email)";
string username = SignUp_Username_Textbox.Text.Length == 0 ? null :
SignUp_Username_Textbox.Text;
string password = SignUp_Password_Textbox.Text.Length == 0 ? null :
SignUp_Password_Textbox.Text;
string firstname = SignUp_First_Name_Textbox.Text.Length == 0 ? null :
SignUp_First_Name_Textbox.Text;
string lastname = SignUp_Last_Name_Textbox.Text.Length == 0 ? null :
SignUp_Last_Name_Textbox.Text;
string email = SignUp_Email_Textbox.Text.Length == 0 ? null : SignUp_Email_Textbox.Text;

cmd.Parameters.AddWithValue("@Username", username);
cmd.Parameters.AddWithValue("@Password", password);
cmd.Parameters.AddWithValue("@Firstname", firstname);
cmd.Parameters.AddWithValue("@Lastname", lastname);
cmd.Parameters.AddWithValue("@Email", email);

cmd.ExecuteNonQuery();

SignUp_First_Name_Textbox.Clear();
SignUp_Last_Name_Textbox.Clear();
SignUp_Password_Textbox.Clear();
SignUp_Re_Password_Textbox.Clear();
SignUp_Username_Textbox.Clear();
SignUp_Email_Textbox.Clear();

con.Close();

MessageBox.Show("Added Successfully!");

}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
else
{
if (SignUp_Password_Textbox.Text != SignUp_Re_Password_Textbox.Text)

111
{
MessageBox.Show("Passwords do not match");
}
if (email_check == 2)
{
MessageBox.Show("Email is not valid");
}

}
}
}

private void SignUp_Last_Name_Textbox_Enter(object sender, EventArgs e)


{
if (SignUp_Last_Name_Textbox.Text == "Doe")
{
SignUp_Last_Name_Textbox.Text = "";

SignUp_Last_Name_Textbox.ForeColor = Color.Black;
}
}

private void SignUp_Last_Name_Textbox_Leave(object sender, EventArgs e)


{
if (SignUp_Last_Name_Textbox.Text == "")
{
SignUp_Last_Name_Textbox.Text = "Doe";

SignUp_Last_Name_Textbox.ForeColor = Color.Silver;
}
}
}
}

112

You might also like