The Library Management System is a desktop application developed using C# and Windows Forms for the graphical user interface (GUI). It uses ADO.NET for database connectivity to manage library operations such as adding books, borrowing and returning books, managing members, and handling fines. The system is designed to streamline library operations and provide an efficient way to manage books, members, and staff.
This project was developed as part of my Database Final Project for the Computer Science program at Alexandria University. My name is Makrious Ayman.
- Book Management: Add, update, and delete books.
- Member Management: Add, update, and delete members.
- Staff Management: Add, update, and delete staff members.
- Borrowing and Returning Books: Track book borrowings and returns.
- Fines Management: Record fines for overdue books.
- Authentication: Secure login system for staff and administrators.
The database for the Library Management System is designed using SQL Server. Below is a detailed description of the database schema, including tables, relationships, and constraints.
- Description: Stores information about books in the library.
- Attributes:
id(Primary Key, INT): Unique identifier for each book.Name(VARCHAR): Title of the book.Date(DATE): Publication date.OLB(VARCHAR): Old library barcode.Publisher(VARCHAR): Publisher of the book.ISBN(VARCHAR): International Standard Book Number.AuthorName(VARCHAR): Author of the book.Category(VARCHAR): Genre or category of the book.Location(VARCHAR): Physical location of the book in the library.Amount(INT): Number of copies available.Price(FLOAT): Price of the book.
- Constraints:
ISBNmust be unique.Amountmust be a non-negative integer.
- Description: Stores information about library members.
- Attributes:
id(Primary Key, INT): Unique identifier for each member.Name(VARCHAR): Full name of the member.SSN(VARCHAR): Social Security Number (unique identifier).Address(VARCHAR): Address of the member.Phone1(VARCHAR): Primary phone number.Phone2(VARCHAR): Secondary phone number.Email(VARCHAR): Email address of the member.BirthDate(DATE): Date of birth.MembershipStatus(BIT): Indicates if the membership is active (1) or inactive (0).BorrowState(BIT): Indicates if the member is allowed to borrow books (1) or not (0).
- Constraints:
SSNmust be unique.Emailmust be unique.
- Description: Tracks book borrowings by members.
- Attributes:
BorrowId(Primary Key, INT): Unique identifier for each borrowing record.MemberId(Foreign Key, INT): ReferencesMembers(id).BookId(Foreign Key, INT): ReferencesBooks(id).BorrowDate(DATETIME): Date the book was borrowed.DueDate(DATETIME): Due date for returning the book.
- Constraints:
- A member cannot borrow more books than the allowed limit (enforced by application logic).
- A book cannot be borrowed if
Amountin theBookstable is 0.
- Description: Records book purchases by customers.
- Attributes:
Purchaseld(Primary Key, INT): Unique identifier for each purchase record.BookId(Foreign Key, INT): ReferencesBooks(id).CustomerName(VARCHAR): Name of the customer.CustomerContact(VARCHAR): Contact information of the customer.PurchaseDate(DATETIME): Date of purchase.TotalPrice(FLOAT): Total price of the purchase.
- Constraints:
BookIdmust reference an existing book.
- Description: Records fines for overdue books.
- Attributes:
FineId(Primary Key, INT): Unique identifier for each fine record.MemberId(Foreign Key, INT): ReferencesMembers(id).FineAmount(FLOAT): Amount of the fine.FineType(VARCHAR): Type of fine (e.g., overdue, lost).ReturnDate(DATETIME): Date the book was returned.BookId(Foreign Key, INT): ReferencesBooks(id).ReturnId(Foreign Key, INT): ReferencesReturning(ReturnId).
- Constraints:
FineAmountmust be a non-negative value.
- Description: Tracks book returns.
- Attributes:
ReturnId(Primary Key, INT): Unique identifier for each return record.StaffId(Foreign Key, INT): ReferencesStaff(id).MemberId(Foreign Key, INT): ReferencesMembers(id).BookId(Foreign Key, INT): ReferencesBooks(id).ReturnDate(DATETIME): Date the book was returned.BorrowId(Foreign Key, INT): ReferencesBorrow(BorrowId).
- Constraints:
ReturnDatemust be greater than or equal toBorrowDate.
- Description: Stores information about library staff.
- Attributes:
id(Primary Key, INT): Unique identifier for each staff member.Name(VARCHAR): Full name of the staff member.SSN(VARCHAR): Social Security Number (unique identifier).Address(VARCHAR): Address of the staff member.Phone1(VARCHAR): Primary phone number.Phone2(VARCHAR): Secondary phone number.BirthDate(DATE): Date of birth.WorkType(VARCHAR): Type of work (e.g., librarian, admin).HireDate(DATE): Date the staff member was hired.Email(VARCHAR): Email address of the staff member.
- Constraints:
SSNmust be unique.Emailmust be unique.
- Description: Stores login credentials for staff and administrators.
- Attributes:
id(Primary Key, INT): Unique identifier for each user.Username(VARCHAR): Username for login.Password(VARCHAR): Password for login.
- Constraints:
Usernamemust be unique.
-
Books and Borrow:
- Relationship: A book can be borrowed multiple times.
- Cardinality: One-to-Many (1 book can be borrowed by many members).
-
Members and Borrow:
- Relationship: A member can borrow multiple books.
- Cardinality: One-to-Many (1 member can borrow many books).
-
Borrow and Returning:
- Relationship: A borrowing record corresponds to one return record.
- Cardinality: One-to-One (1 borrowing record corresponds to 1 return record).
-
Staff and Returning:
- Relationship: A staff member can handle multiple returns.
- Cardinality: One-to-Many (1 staff member can handle many returns).
-
Books and Buy:
- Relationship: A book can be purchased multiple times.
- Cardinality: One-to-Many (1 book can be purchased by many customers).
-
Members and Fines:
- Relationship: A member can have multiple fines.
- Cardinality: One-to-Many (1 member can have many fines).
-
Adding a Book:
- The
ISBNmust be unique. - The
Amountof copies must be a non-negative integer.
- The
-
Borrowing a Book:
- A member cannot borrow a book if their
BorrowStateis 0 (not allowed to borrow). - A book cannot be borrowed if the
Amountin theBookstable is 0 (no copies available).
- A member cannot borrow a book if their
-
Returning a Book:
- The
ReturnDatemust be greater than or equal to theBorrowDate. - If the book is returned late, a fine is automatically calculated and recorded in the
Finestable.
- The
The database includes several stored procedures to automate common tasks:
- SP_addStaff: Adds a new staff member.
- SP_authenticate: Authenticates users during login.
- SP_addMember: Adds a new member.
- SP_editStaff: Updates staff information.
- SP_editMember: Updates member information.
- SP_searchStaff: Searches for a staff member by ID.
- SP_searchMember: Searches for a member by ID.
- SP_delStaff: Deletes a staff member.
- SP_delMember: Deletes a member.
Constraints are essential for maintaining data integrity and ensuring that the database operates correctly. Below are the key constraints used in the Library Management System:
- Every table has a primary key (
idor similar) to uniquely identify each record. - Examples:
Books(id)Members(id)Borrow(BorrowId)
- Ensures no duplicate records exist in the table.
- Foreign keys are used to establish relationships between tables.
- Examples:
Borrow(MemberId)referencesMembers(id).Borrow(BookId)referencesBooks(id).Returning(StaffId)referencesStaff(id).
- Ensures that related records exist in the referenced tables.
- Certain fields must be unique to avoid duplication.
- Examples:
Books(ISBN): Ensures no two books have the same ISBN.Members(SSN): Ensures no two members have the same Social Security Number.User_Pass(Username): Ensures no duplicate usernames for login.
- Ensures that data meets specific conditions before being inserted or updated.
- Examples:
Books(Amount): Must be a non-negative integer (ensures no negative copies).Fines(FineAmount): Must be a non-negative value (ensures no negative fines).Borrow(DueDate): Must be greater than or equal toBorrowDate.
- Ensures that certain fields cannot be left empty.
- Examples:
Books(Name): A book must have a title.Members(Name): A member must have a name.Borrow(BorrowDate): A borrowing record must have a borrow date.
The system handles borrowing and returning of books through the Borrow and Returning tables, with additional logic to enforce rules and constraints.
-
Steps:
- A member requests to borrow a book.
- The system checks:
- If the member’s
BorrowStateis1(allowed to borrow). - If the book’s
Amountis greater than0(copies available).
- If the member’s
- If both conditions are met:
- A new record is created in the
Borrowtable with:MemberId: The member borrowing the book.BookId: The book being borrowed.BorrowDate: The current date.DueDate: Calculated based on library policies (e.g., 14 days fromBorrowDate).
- The
Amountof the book in theBookstable is decremented by1.
- A new record is created in the
-
Constraints:
- A member cannot borrow more books than the allowed limit (enforced by application logic).
- A book cannot be borrowed if
Amountis0.
-
Steps:
- A member returns a book.
- The system checks:
- If the
ReturnDateis greater than or equal to theBorrowDate. - If the book was borrowed by the same member (via
BorrowId).
- If the
- If the book is returned late:
- A fine is calculated based on the number of days overdue.
- A new record is created in the
Finestable with:MemberId: The member returning the book.BookId: The book being returned.FineAmount: The calculated fine.FineType: Set to "Overdue".ReturnDate: The current date.
- The
Amountof the book in theBookstable is incremented by1.
-
Constraints:
- The
ReturnDatemust be greater than or equal to theBorrowDate. - A book cannot be returned if it was not borrowed (enforced by foreign key constraints).
- The
- Run the SQL scripts provided in the
Library_Management_System(Creating Tables SQL).sqlfile to create the database and tables. - Execute the stored procedures from
Library_Management_System(Some Stored Procedures).sql.
- Open the project in Visual Studio.
- Build and run the application.
- Makrious Ayman
- Andrew Gerges
- Bishoy Effat