0% found this document useful (0 votes)
5 views14 pages

GRP PRJ OOP

The document outlines the development of a library management system using PYQT and SQLite, detailing the steps for creating the application and its functionalities. It includes a user manual for interacting with the application, such as searching, adding, updating, and deleting books. The conclusion emphasizes the educational value of the project in understanding Object Oriented Programming and application development.

Uploaded by

jojokamara2345
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)
5 views14 pages

GRP PRJ OOP

The document outlines the development of a library management system using PYQT and SQLite, detailing the steps for creating the application and its functionalities. It includes a user manual for interacting with the application, such as searching, adding, updating, and deleting books. The conclusion emphasizes the educational value of the project in understanding Object Oriented Programming and application development.

Uploaded by

jojokamara2345
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/ 14

INTRODUCTION

This project is about developing a user interface application that can manage a Library
system that help the user to add, remove, find and delete book from the library.

With the use PYQT design which you can drag and drop the different interface or you can
code it manual. Also make use of Sql lite to keep all data base

PROCEDURE FOR CREATING THE LIBRARY SYSTEM

Step 1: You have to import the library which is the PYQT by typing import pyqt

Step 2: you have to import the SQL Lite by typing import SQL lite

Step 3: you have to install pyqt on the terminal and make sure you are connected to
strong internet use (pip install pyqt5 to install)
Step 4: You have to install the SQL lite using (pip install SQL lite)

Step 5: You have to declare the class which is (class Name)

Step 6: You have to declare the attributes using the __init__ constructor

Step 7: You have to declare the methods or function

CASE STUDY

This is a library management system that keep track of books in an online library system.
The system help you to know book that are not available at the moment in the library or
books that are added or books that are just be updated in the library for easy running of
the library system. With the use of PYQT which is in different version but for this project
we are using the PYQT5. This help you to design an application system through the
Manuel code or drag and drop to design a perfect interface. The PYQT can be manually
install using line of code or you can download it from the browser. With the use of python
language you then code the functionality you want your application to perform after that
you have to run the code on you terminal and it straight away take you to the PYQT to
display you project. The PYQT has some functionality which help you to design your
application the way want it to be using color, text, image and videos. The use of the SQL
lite is to keep all the data that are and will be add to the application system.

USER MANUAL

How to play around the application

Step 1: Clicking on the application to open after that you go the screech to look for the
book you want to read or find. When screeching for the book you have to write the title,
author, ISBN and publish year and click screech.

Step 2: When you want to add a book you have to click on the add book. Enter the title
of the book you want to author, ISBN and the published year.
Step 3: If you want to delete a book you have to click on the title of the book you want
to delete and press delete. You can delete multiple book at a time by select the amount
you want to delete

Step 4: You can by clicking update and entering the book title, author, ISBN and year
and click update.

Step 5: If you have open a particular and want to exit from there you can press back to
go back.

import sys

from PyQt5.QtWidgets import (

QApplication, QMainWindow, QVBoxLayout, QHBoxLayout, QPushButton,

QLineEdit, QLabel, QTableWidget, QTableWidgetItem, QWidget, QInputDialog,


QMessageBox

import sqlite3

class LibraryManagementSystem(QMainWindow):

def go_back(self):

self.load_books() # Reload the books into the table

def __init__(self):

super().__init__()

self.setWindowTitle("Limkokwing Library Management System")


self.setGeometry(200, 200, 800, 600)

# Main Widget

self.main_widget = QWidget()

self.setCentralWidget(self.main_widget)

# Main Layout

self.layout = QVBoxLayout()

self.main_widget.setLayout(self.layout)

# Search Bar

self.search_layout = QHBoxLayout()

self.search_input = QLineEdit()

self.search_input.setPlaceholderText("Search by Title, Author, ISBN, or Genre")

self.search_button = QPushButton("Search")

self.search_button.clicked.connect(self.search_books)

self.search_layout.addWidget(self.search_input)

self.search_layout.addWidget(self.search_button)

self.layout.addLayout(self.search_layout)

# Table for displaying books

self.table = QTableWidget()
self.table.setColumnCount(5)

self.table.setHorizontalHeaderLabels(["Title", "Author", "ISBN", "Genre",


"Publication Year"])

self.layout.addWidget(self.table)

# CRUD Buttons

self.button_layout = QHBoxLayout()

# Back Button

self.back_button = QPushButton("Back")

self.back_button.clicked.connect(self.go_back)

self.add_button = QPushButton("Add Book")

self.add_button.clicked.connect(self.add_book)

self.update_button = QPushButton("Update Book")

self.update_button.clicked.connect(self.update_book)

self.delete_button = QPushButton("Delete Book")

self.delete_button.clicked.connect(self.delete_book)

self.button_layout.addWidget(self.add_button)
self.button_layout.addWidget(self.update_button)

self.button_layout.addWidget(self.delete_button)

self.button_layout.addWidget(self.back_button)

self.layout.addLayout(self.button_layout)

# Database Connection

self.conn = sqlite3.connect("library.db")

self.cursor = self.conn.cursor()

self.create_table()

self.add_initial_books()

self.load_books()

def create_table(self):

query = """

CREATE TABLE IF NOT EXISTS books (

id INTEGER PRIMARY KEY AUTOINCREMENT,

title TEXT NOT NULL,

author TEXT NOT NULL,

isbn TEXT UNIQUE NOT NULL,

genre TEXT,

publication_year INTEGER

)
"""

self.cursor.execute(query)

self.conn.commit()

def add_initial_books(self):

books = [

("The Millionaire Fastlane", "MJ DeMarco", "9780984358106", "Finance", 2011),

("Rich Dad Poor Dad", "Robert Kiyosaki", "9781612680194", "Finance", 1997),

("The Richest Man in Babylon", "George S. Clason", "9780451205360",


"Finance", 1926),

("The Parable of the Pipeline", "Burke Hedges", "9781891279059", "Business",


2000),

("Think and Grow Rich", "Napoleon Hill", "9781585424337", "Self-help", 1937),

("Cashflow Quadrant", "Robert Kiyosaki", "9781612680057", "Finance", 1998),

("Unscripted", "MJ DeMarco", "9781732659405", "Finance", 2017),

("Poor Charlie's Almanack", "Charlie Munger", "9781578645015", "Biography",


2005),

("The Almanack of Naval Ravikant", "Eric Jorgenson", "9781544514215", "Self-


help", 2020),

("Moonshots", "Naveen Jain", "9781732509717", "Entrepreneurship", 2018)

for book in books:


try:

query = """

INSERT INTO books (title, author, isbn, genre, publication_year)

VALUES (?, ?, ?, ?, ?)

"""

self.cursor.execute(query, book)

except sqlite3.IntegrityError:

continue # Skip duplicate entries

self.conn.commit()

def load_books(self):

query = "SELECT title, author, isbn, genre, publication_year FROM books"

self.cursor.execute(query)

books = self.cursor.fetchall()

self.table.setRowCount(len(books))

for row_idx, book in enumerate(books):

for col_idx, value in enumerate(book):

self.table.setItem(row_idx, col_idx, QTableWidgetItem(str(value)))

def search_books(self):
search_text = self.search_input.text()

query = """

SELECT title, author, isbn, genre, publication_year FROM books

WHERE title LIKE ? OR author LIKE ? OR isbn LIKE ? OR genre LIKE ?

"""

self.cursor.execute(query, (f"%{search_text}%",) * 4)

books = self.cursor.fetchall()

self.table.setRowCount(len(books))

for row_idx, book in enumerate(books):

for col_idx, value in enumerate(book):

self.table.setItem(row_idx, col_idx, QTableWidgetItem(str(value)))

def add_book(self):

title, ok = QInputDialog.getText(self, "Add Book", "Enter Title:")

if not ok or not title:

return

author, ok = QInputDialog.getText(self, "Add Book", "Enter Author:")

if not ok or not author:

return
isbn, ok = QInputDialog.getText(self, "Add Book", "Enter ISBN:")

if not ok or not isbn:

return

genre, ok = QInputDialog.getText(self, "Add Book", "Enter Genre:")

if not ok or not genre:

return

year, ok = QInputDialog.getInt(self, "Add Book", "Enter Publication Year:")

if not ok:

return

try:

query = """

INSERT INTO books (title, author, isbn, genre, publication_year)

VALUES (?, ?, ?, ?, ?)

"""

self.cursor.execute(query, (title, author, isbn, genre, year))

self.conn.commit()

self.load_books()

except sqlite3.IntegrityError:

QMessageBox.warning(self, "Error", "A book with this ISBN already exists.")


def update_book(self):

selected_row = self.table.currentRow()

if selected_row < 0:

QMessageBox.warning(self, "Error", "Please select a book to update.")

return

isbn = self.table.item(selected_row, 2).text()

title, ok = QInputDialog.getText(self, "Update Book", "Enter new Title:",


QLineEdit.Normal, self.table.item(selected_row, 0).text())

if not ok or not title:

return

author, ok = QInputDialog.getText(self, "Update Book", "Enter new Author:",


QLineEdit.Normal, self.table.item(selected_row, 1).text())

if not ok or not author:

return

genre, ok = QInputDialog.getText(self, "Update Book", "Enter new Genre:",


QLineEdit.Normal, self.table.item(selected_row, 3).text())

if not ok or not genre:

return
year, ok = QInputDialog.getInt(self, "Update Book", "Enter new Publication Year:",
int(self.table.item(selected_row, 4).text()))

if not ok:

return

query = """

UPDATE books

SET title = ?, author = ?, genre = ?, publication_year = ?

WHERE isbn = ?

"""

self.cursor.execute(query, (title, author, genre, year, isbn))

self.conn.commit()

self.load_books()

def delete_book(self):

selected_row = self.table.currentRow()

if selected_row < 0:

QMessageBox.warning(self, "Error", "Please select a book to delete.")

return

isbn = self.table.item(selected_row, 2).text()

query = "DELETE FROM books WHERE isbn = ?"


self.cursor.execute(query, (isbn,))

self.conn.commit()

self.load_books()

if __name__ == "__main__":

app = QApplication(sys.argv)

window = LibraryManagementSystem()

window.show()

sys.exit(app.exec_())
CONCLUSION

In a nut shell this assignment was a good means of learning as it make us understand
the Meaning and purpose of Object Oriented Programming Language. We get to know
the how to use PYQT and create our very own application system.

You might also like