cs prj final 11
cs prj final 11
INVESTIGATORY PROJECT
Computer Science
2024 -2025
_______________ _______________
_______________________
Mrs. Sukanya M
Principal School Seal
2
ACKNOWLEDGMENT
My sincere thanks go to Mrs.Sukanya M, Our Principal Ma'am, for
her coordination in extending every possible support for the
completion of this project. I would like to express a deep sense of
thanks and gratitude to my project guide Mrs. Thushantha Ma'am
for guiding me immensely through the course of the project. She
always evinced keen interest in my work. Her constructive advice and
constant motivation have been responsible for the successful
completion of this project. I would also like to convey my gratitude to
Jayalakshmi Ma’am, Our Lab Assistant who has helped us
throughout the completion of our project.
3
CONTENTS:
6
2 Objectives
3 Technical Specifications 8
4 Database Used 9
10 Bibliography 42
4
CASE STUDY
1)The ARM Dairy Store Inventory and Sales (Stock)
Management System software is a program which makes it easy
to maintain a record of dairy products available in the list and
track orders issued to suppliers in The Dairy Store
4) It’s used to store, update, delete, and display the user’s data
among other functions
5
OBJECTIVES
Inventory Management: The system will efficiently
spoilage.
6
TECHNICAL
SPECIFICATIONS
SOFTWARE
SPECIFICATIONS:
Pycharm community
SQL 5.
OS-Windows
7
TABLES USED
DATABASE USED:
TABLES:
8
TABLE PRODUCT :
DESCRIBING PRODUCT:
DESCRIBING SALES:
9
DESCRIBING USER :
TABLE SALES:
TABLE USER:
10
Modules and User-Defined
Functions
Modules Used
1. mysql.connector:
o A Python library to connect and interact with MySQL databases.
o Functions like connect(), cursor(), and execute() are used to
interact with the database.
2. mysql.connector.Error:
o Used to handle database connection and query execution errors.
12
Main Functionality (main)
1. Connects to the database using connect_to_db().
1. Modules:
o mysql.connector handles all database interactions, such as
connecting to MySQL, executing queries, and committing
changes.
2. User-Defined Functions:
o connect_to_db(): Establishes the connection for all database
operations.
13
o create_tables(): Prepares the database structure.
3. Integration:
o The main() function orchestrates all operations, ensuring the
database connection is established, and user inputs are processed
effectively.
14
CODE
import mysql.connector
from mysql.connector import Error
def connect_to_db():
try:
connection = mysql.connector.connect(
host='localhost',
user='root',
password='sample'
database='diary_shop'
)
if connection.is_connected(
print("Connected to the database")
return connection
except Error as e:
print(f"Error connecting to MySQL: {e}")
return None
15
def create_tables(connection):
cursor = connection.cursor()
try:
cursor.execute("""
CREATE TABLE IF NOT EXISTS Product (
product_id INT AUTO_INCREMENT PRIMARY KEY,
product_name VARCHAR(255),
product_company VARCHAR(255),
product_description TEXT,
unit_price FLOAT,
quantity INT
);
""")
cursor.execute("""
CREATE TABLE IF NOT EXISTS Sales (
sale_id INT AUTO_INCREMENT PRIMARY KEY,
16
product_id INT,
sale_quantity INT,
sale_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (product_id) REFERENCES Product(product_id)
);
""")
cursor.execute("""
CREATE TABLE IF NOT EXISTS User (
user_id INT AUTO_INCREMENT PRIMARY KEY,
username VARCHAR(255) UNIQUE,
role ENUM('admin', 'staff')
);
""")
print("Tables created successfully.")
except Error as e:
print(f"Error creating tables: {e}")
finally:
cursor.close()
17
def add_product(connection):
cursor = connection.cursor()
product_name = input("Enter product name: ")
product_company = input("Enter product company: ")
product_description = input("Enter product description: ")
unit_price = float(input("Enter unit price: "))
quantity = int(input("Enter quantity: "))
try:
cursor.execute("""
INSERT INTO Product (product_name, product_company,
def view_products(connection):
cursor = connection.cursor()
try:
cursor.execute("SELECT * FROM Product")
products = cursor.fetchall()
print("Products:")
for product in products:
print(product)
except Error as e:
print(f"Error fetching products: {e}")
finally:
cursor.close()
def modify_product(connection):
cursor = connection.cursor()
product_id = int(input("Enter product ID to modify: "))
print("What do you want to modify?")
print("1. Name\n2. Company\n3. Description\n4. Unit Price\n5. Quantity")
choice = int(input("Enter choice: "))
field = {1: "product_name", 2: "product_company", 3:
19
"product_description", 4: "unit_price", 5: "quantity"}[choice]
new_value = input(f"Enter new value for {field}: ")
try:
if choice in [4, 5]:
cursor.execute(f"UPDATE Product SET {field} = %s WHERE product_id
= %s", (float(new_value) if choice == 4 else int(new_value), product_id))
else:
cursor.execute(f"UPDATE Product SET {field} = %s WHERE product_id
= %s", (new_value, product_id))
connection.commit()
print("Product updated successfully.")
except Error as e:
def make_sale(connection):
cursor = connection.cursor()
product_id = int(input("Enter product ID: "))
20
sale_quantity = int(input("Enter sale quantity: "))
try:
cursor.execute("""
UPDATE Product
SET quantity = quantity - %s
WHERE product_id = %s
""", (sale_quantity, product_id))
connection.commit()
print("Sale recorded successfully.")
except Error as e:
21
print(f"Error making sale: {e}")
finally:
cursor.close()
def view_sales(connection):
cursor = connection.cursor()
try:
cursor.execute("""
SELECT Sales.sale_id, Product.product_name, Sales.sale_quantity,
Sales.sale_date
FROM Sales
JOIN Product ON Sales.product_id = Product.product_id
""")
sales = cursor.fetchall()
print("Sales:")
for sale in sales:
print(sale)
except Error as e:
print(f"Error fetching sales: {e}")
22
finally:
cursor.close()
def add_user(connection):
cursor = connection.cursor()
username = input("Enter username: ")
role = input("Enter role (admin/staff): ").lower()
try:
cursor.execute("""
INSERT INTO User (username, role)
VALUES (%s, %s)
""", (username, role))
connection.commit()
print("User added successfully.")
except Error as e:
print(f"Error adding user: {e}")
finally:
23
cursor.close()
def main():
connection = connect_to_db()
if connection is None:
return
create_tables(connection)
24
while True:
print("\nARM Diary Shop Management System")
print("1. Add Product")
print("2. View Products")
print("3. Modify Product")
print("4. Make Sale")
print("5. View Sales")
print("6. Add User")
print("7. Exit")
choice = int(input("Enter your choice: "))
if choice == 1:
add_product(connection)
elif choice == 2:
view_products(connection)
elif choice == 3:
modify_product(connection)
elif choice == 4:
make_sale(connection)
elif choice == 5:
view_sales(connection)
elif choice == 6:
add_user(connection)
25
elif choice == 7:
connection.close()
print("Goodbye!")
break
else:
print("Invalid choice! Try again.")
if __name__ == "__main__":
main()
26
OUTPUT
27
28
29
30
31
32
33
34
35
36
37
FUTURE
ENHANCEMENTS
Future Enhancements for Diary Management System
avoid shortages.
decision-making.
editing).
transactions seamlessly.
6. AI-Powered Features:
interfaces.
7. Enhanced Security:
40
BIBLIOGRAPHY
• Computer Science with Python - Class XII by Preeti Arora
• Python Programming Projects & Practical for CBSE Class XI & XII:
GUI Based Projects & Practical -By Reema Thareja and Vedant Bahel
• https://www.geeksforgeeks.org/python/default.com
•https://www.w3schools.com/python/default.asp
• https://realpython.com
41
42