Library Management System Final Report
Library Management System Final Report
Desktop-based
Library Management System Application
using C# and MS-SQL Server Database
Submitted by:
Sumit Ratna Tamakar, 171337
Prabin Sahani, 171342
Date:
12/09/2019
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.
Finally, we would like to thank Pokhara University - School of Engineering for providing
us with the opportunity to endeavour into this project.
Thanking You,
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.
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.
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.
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.
● 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
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.
14
Methodology
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
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
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
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:
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:
25
Successful Student Account 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
27
Student Menu with ‘Available’ Filter selected
28
Student Menu with ‘Not Available’ Filter selected
29
Student Menu - ‘Searching’ with ‘Both’ Filter (Search Key Word ‘Th’)
30
Successful Admin Account Login
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
32
Admin - ‘Add Admin’ Form
33
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’)
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
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
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
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
Record edited successfully-message box appears when the new information is successfully added
to the system.
39
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
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’
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
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
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
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
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
Record deleted successfully Message-box appears when the record of the book is successfully
deleted from the database.
49
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
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
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’)
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
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.
54
Admin - Books Stock - Checking Mail on Receiver’s Side
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.
55
Conclusion:
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.
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
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:
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;
wanted_path =
Path.GetDirectoryName(Path.GetDirectoryName(System.IO.Directory.GetCurrentDirectory()));
result = Add_Student_Info_openFileDialog.ShowDialog();
}
}
60
Add_Student_Info.ActiveForm.Close();
}
connection.Open();
SqlCommand cmd = connection.CreateCommand();
cmd.CommandType = CommandType.Text;
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();
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();
}
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();
}
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);
}
}
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);
}
}
try
{
i = Convert.ToInt32(dataGridView1.SelectedCells[0].Value.ToString());
SqlCommand cmd = con.CreateCommand();
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
}
}
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);
}
67
SqlCommand cmd = con.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.ExecuteNonQuery();
Display_Books();
update_panel.Visible = false;
j++;
}
else
{
this.Show();
}
if (j > 0)
{
MessageBox.Show("Record deleted successfully");
}
con.Close();
}
}
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");
int select_check = 0;
public Admin_Student_MainMenu()
{
InitializeComponent();
if (connection.State == ConnectionState.Open)
{
connection.Close();
}
connection.Open();
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);
Admin_Student_MainMenu_dataGridView.Rows[i].Cells[9].Value = img;
Admin_Student_MainMenu_dataGridView.Rows[i].Height = 100;
i = i + 1;
}
int i = 0;
if (connection.State == ConnectionState.Open)
{
connection.Close();
}
connection.Open();
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);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString());
}
71
Edit_Student_Info Edit_Student_Info_page = new Edit_Student_Info();
Edit_Student_Info_page.Show();
}
}
int i = 0;
if (connection.State == ConnectionState.Open)
{
connection.Close();
}
connection.Open();
Bitmap img;
DataGridViewImageColumn imageCol = new DataGridViewImageColumn();
imageCol.HeaderText = "Student Image";
imageCol.ImageLayout = DataGridViewImageCellLayout.Zoom;
imageCol.Width = 100;
Admin_Student_MainMenu_dataGridView.Columns.Add(imageCol);
Admin_Student_MainMenu_dataGridView.Rows[i].Cells[9].Value = img;
Admin_Student_MainMenu_dataGridView.Rows[i].Height = 100;
i = i + 1;
}
}
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();
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();
}
Fill_Books_Info();
}
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;
}
Book_Stock_Email_Textbox.Text = Student_email_var;
75
}
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
{
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;
public Edit_Student_Info()
{
InitializeComponent();
}
if (connection.State == ConnectionState.Open)
{
connection.Close();
}
connection.Open();
select_record_cmd.ExecuteNonQuery();
78
DataTable dt = new DataTable();
SqlDataAdapter da = new SqlDataAdapter(select_record_cmd);
da.Fill(dt);
Bitmap img;
connection.Close();
}
}
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";
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");
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();
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
{
public Issue_books()
{
InitializeComponent();
}
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();
}
}
int count = 0;
if (e.KeyCode != Keys.Enter)
{
Issue_Books_Book_Name_listBox.Items.Clear();
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());
}
}
}
}
Issue_Books_Book_Name_listBox.SelectedIndex = 0;
}
int book_available_quantity_check = 0;
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();
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();
cmd_update.Parameters.AddWithValue("@Book_name", Issue_Books_Book_Name_Textbox.Text);
cmd_update.ExecuteNonQuery();
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();
if (book_available_quantity_check == 0)
{
SqlCommand cmd_update_status = connection.CreateCommand();
cmd_update_status.CommandType = CommandType.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";
int count = 0;
public Login()
{
InitializeComponent();
}
87
if (LoginUsername.Text == "Username")
{
LoginUsername.Text = "";
LoginUsername.ForeColor = Color.Black;
}
LoginUsername.ForeColor = Color.Silver;
}
LoginPassword.ForeColor = Color.Black;
LoginPassword.PasswordChar = '•';
}
LoginPassword.ForeColor = Color.Silver;
LoginPassword.PasswordChar = '\0';
}
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.Parameters.AddWithValue("@Username", LoginUsername.Text);
cmd.Parameters.AddWithValue("@Password", LoginPassword.Text);
cmd.ExecuteNonQuery();
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.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;
}
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();
}
92
private void Mainmenu_return_books_button_Click(object sender, EventArgs e)
{
Return_books Return_Books_Page = new Return_books();
Return_Books_Page.Show();
}
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;
int result_User = 0;
menu_total_users_label.Text = result_User.ToString();
con.Close();
}
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
{
public Return_books()
{
InitializeComponent();
}
Fill_Grid(Return_Books_Search_Student_Roll_no_Textbox.Text);
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;
int i;
i = Convert.ToInt32(Return_Books_dataGridView.SelectedCells[0].Value.ToString());
cmd.Parameters.AddWithValue("@id", i);
cmd.ExecuteNonQuery();
DataTable dt = new DataTable();
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(dt);
int book_available_quantity_check = 0;
96
cmd.Parameters.AddWithValue("@Books_return_date",
Return_Books_Return_Date_dateTimePicker.Value.ToString());
cmd.Parameters.AddWithValue("@id", i);
cmd.ExecuteNonQuery();
cmd2.Parameters.AddWithValue("@Book_name", Return_Books_Book_Name_Label_Display.Text);
cmd2.ExecuteNonQuery();
cmd_book_available_check.Parameters.AddWithValue("@Book_name",
Return_Books_Book_Name_Label_Display.Text);
cmd_book_available_check.ExecuteNonQuery();
if (book_available_quantity_check == 1)
{
SqlCommand cmd_update_status = con.CreateCommand();
cmd_update_status.CommandType = CommandType.Text;
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();
}
99
{
SignUp.ActiveForm.Close();
}
SignUp_Username_Textbox.ForeColor = Color.Black;
}
}
SignUp_Username_Textbox.ForeColor = Color.Silver;
}
}
SignUp_First_Name_Textbox.ForeColor = Color.Black;
}
}
SignUp_First_Name_Textbox.ForeColor = Color.Silver;
}
}
100
SignUp_Password_Textbox.ForeColor = Color.Black;
SignUp_Password_Textbox.PasswordChar = '•';
}
}
SignUp_Password_Textbox.ForeColor = Color.Silver;
SignUp_Password_Textbox.PasswordChar = '\0';
}
}
SignUp_Re_Password_Textbox.ForeColor = Color.Black;
SignUp_Re_Password_Textbox.PasswordChar = '•';
}
}
SignUp_Re_Password_Textbox.ForeColor = Color.Silver;
SignUp_Re_Password_Textbox.PasswordChar = '\0';
}
}
SignUp_Email_Textbox.ForeColor = Color.Black;
}
}
101
if (SignUp_Email_Textbox.Text == "")
{
SignUp_Email_Textbox.Text = "someone@example.com";
SignUp_Email_Textbox.ForeColor = Color.Silver;
}
}
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");
}
}
}
}
SignUp_Last_Name_Textbox.ForeColor = Color.Black;
}
}
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();
}
106
{
SignUp.ActiveForm.Close();
}
SignUp_Username_Textbox.ForeColor = Color.Black;
}
}
SignUp_Username_Textbox.ForeColor = Color.Silver;
}
}
SignUp_First_Name_Textbox.ForeColor = Color.Black;
}
}
SignUp_First_Name_Textbox.ForeColor = Color.Silver;
}
}
107
SignUp_Password_Textbox.ForeColor = Color.Black;
SignUp_Password_Textbox.PasswordChar = '•';
}
}
SignUp_Password_Textbox.ForeColor = Color.Silver;
SignUp_Password_Textbox.PasswordChar = '\0';
}
}
SignUp_Re_Password_Textbox.ForeColor = Color.Black;
SignUp_Re_Password_Textbox.PasswordChar = '•';
}
}
SignUp_Re_Password_Textbox.ForeColor = Color.Silver;
SignUp_Re_Password_Textbox.PasswordChar = '\0';
}
}
SignUp_Email_Textbox.ForeColor = Color.Black;
}
}
108
if (SignUp_Email_Textbox.Text == "")
{
SignUp_Email_Textbox.Text = "someone@example.com";
SignUp_Email_Textbox.ForeColor = Color.Silver;
}
}
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");
}
}
}
}
SignUp_Last_Name_Textbox.ForeColor = Color.Black;
}
}
SignUp_Last_Name_Textbox.ForeColor = Color.Silver;
}
}
}
}
112