0% found this document useful (0 votes)
31 views18 pages

C.S Project Presentation

The document is a Computer Science project by P. Pranav from Delhi Public School Bangalore East, focusing on a bakery management system using MySQL and Python. It includes acknowledgments, objectives, source code for database management, and functionalities for product, customer, and order management. The project aims to demonstrate real-world applications of technology in managing a bakery's operations.

Uploaded by

achu140211
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)
31 views18 pages

C.S Project Presentation

The document is a Computer Science project by P. Pranav from Delhi Public School Bangalore East, focusing on a bakery management system using MySQL and Python. It includes acknowledgments, objectives, source code for database management, and functionalities for product, customer, and order management. The project aims to demonstrate real-world applications of technology in managing a bakery's operations.

Uploaded by

achu140211
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/ 18

DELHI PUBLIC SCHOOL

BANGLORE EAST

COMPUTER SCIENCE PROJECT


2024-2025

NAME : P.PRANAV
CLASS : XII – K
ROLL NO : 23
1
INDEX

3
ACKNOWLEDGEMENT

This project would not be complete


without mentioning the names of who have
made it possible.

I would like to extend my sincere gratitude to


our principal Dr. Manilla Carvalho, who has
always been a constant pillar of support.

I would like to thank my Computer Science


Mrs. Vikranti , for her valuable guidance and
supervision without whom the project
wouldn’t have come forth.

I would also like to thank my family and


fellow classmates for their constant support
and encouragement throughout the course of
this project

4
OBJECTIVE

Hardware Requirements:
1.) Computer
2.) Storage

Software Requirements:
1.) MY SQL Database
2.) Python
3.) Python MY SQL connector module
4.) Datetime module
5.) IDLE
6.) Windows OS

Applications in the Real World:


Having bakery in a community provides
numerous benefits! It provides a
delicious variety of freshly baked goods,
like bread , pastries and cakes that can
satisfy our taste buds. A good bakery is
a sign that the place has developed a bit
further than just surviving.

5
SOURCE CODE

MYSQL:

create table products( product_id int


primary key auto_increment,
product_name varchar(20),
category varchar(30), price
float(10,2), stock int)

create table customers(customer_id int


primary key auto_increment
NOT NULL, customer_name
varchar(20),phone
varchar(15),email varchar(20))

6
create table orders(order_id int
primary key
auto_increment NOT NULL,
customer_id int, order_date
timestamp default
current_timestamp,
product_id int, quantity int,
total_price float(10,2)

foreign key(customer_id)
references
customes(customer_id)

foreign key(product_id)
references
products(product_id))

7
PYTHON:
# C.S PROJECT
import mysql.connector
from datetime import datetime

# Connect to the MySQL database


db = mysql.connector.connect(
host="localhost",
user="root", # Replace with your MySQL username
password="Cactus12!", # Replace with your MySQL password
database="bakery_db"
)

cursor = db.cursor()

# -------------------- PRODUCTS MANAGEMENT ----------------------

# Function to add a product

def add_product():
product_name = input("Enter product name: ")
category = input("Enter product category: ")
price = float(input("Enter product price: "))
stock = int(input("Enter product stock: "))

query = "INSERT INTO products (product_name, category, price,


stock) VALUES (%s, %s, %s, %s)"
values = (product_name, category, price, stock)
cursor.execute(query, values)
db.commit()
print("Product added successfully!")

8
# Function to update a product
def update_product():
product_id = int(input("Enter the product ID to update: "))
cursor.execute("SELECT * FROM products WHERE product_id = %s",
(product_id,))
product = cursor.fetchone()
if product:
print(f"Current Product: {product}")
product_name = input(f"Enter new product name ({product[1]}): ") or
product[1]
category = input(f"Enter new category ({product[2]}): ") or product[2]
price = input(f"Enter new price ({product[3]}): ") or product[3]
stock = input(f"Enter new stock ({product[4]}): ") or product[4]

query = "UPDATE products SET product_name = %s, category = %s, price


= %s, stock = %s WHERE product_id = %s"
cursor.execute(query, (product_name, category, price, stock,
product_id))
db.commit()
print("Product updated successfully!")
else:
print("Product not found!")
# Function to delete a product
def delete_product():
product_id = int(input("Enter the product ID to delete: "))
cursor.execute("SELECT * FROM products WHERE product_id = %s",
(product_id,))
product = cursor.fetchone()
if product:
cursor.execute("DELETE FROM products WHERE product_id = %s",
(product_id,))
db.commit()
print(f"Product ID {product_id} deleted successfully!")
else:
print("Product not found!")
# Function to view products
def view_products():
cursor.execute("SELECT * FROM products")
products = cursor.fetchall()
print("\nProducts:")
for product in products:
print(f"ID: {product[0]}, Name: {product[1]}, Category: {product[2]},
Price: {product[3]}, Stock: {product[4]}")
print()

9
# -------------------- CUSTOMER MANAGEMENT ----------------------

# Function to add a customer


def add_customer():
customer_name = input("Enter customer name: ")
phone = input("Enter customer phone number: ")
email = input("Enter customer email: ")

query = "INSERT INTO customers (customer_name, phone,


email) VALUES (%s, %s, %s)"
values = (customer_name, phone, email)
cursor.execute(query, values)
db.commit()
print("Customer added successfully!")

# Function to update a customer


def update_customer():
customer_id = int(input("Enter the customer ID to update: "))
cursor.execute("SELECT * FROM customers WHERE customer_id
= %s", (customer_id,))
customer = cursor.fetchone()
if customer:
print(f"Current Customer: {customer}")
customer_name = input(f"Enter new customer name
({customer[1]}): ") or customer[1]
phone = input(f"Enter new phone number ({customer[2]}): ")
or customer[2]
email = input(f"Enter new email ({customer[3]}): ") or
customer[3]

query = "UPDATE customers SET customer_name = %s, phone


= %s, email = %s WHERE customer_id = %s"
cursor.execute(query, (customer_name, phone, email,
customer_id))
db.commit()
print("Customer updated successfully!")
else:
print("Customer not found!")

10
# Function to delete a customer
def delete_customer():
customer_id = int(input("Enter the customer ID to delete: "))
cursor.execute("SELECT * FROM customers WHERE
customer_id = %s", (customer_id,))
customer = cursor.fetchone()
if customer:
cursor.execute("DELETE FROM customers WHERE
customer_id = %s", (customer_id,))
db.commit()
print(f"Customer ID {customer_id} deleted successfully!")
else:
print("Customer not found!")

# Function to view customers


def view_customers():
cursor.execute("SELECT * FROM customers")
customers = cursor.fetchall()
print("\nCustomers:")
for customer in customers:
print(f"ID: {customer[0]}, Name: {customer[1]}, Phone:
{customer[2]}, Email: {customer[3]}")
print()

# -------------------- ORDER MANAGEMENT ----------------------

# Function to find customer by phone number


def find_customer_by_phone():
phone = input("Enter customer phone number: ")
cursor.execute("SELECT * FROM customers WHERE phone =
%s", (phone,))
customer = cursor.fetchone()
return customer

11
# Function to create an order
def create_order():
customer = find_customer_by_phone()
if customer is None:
print("Customer not found. Please add the customer first.")
add_customer()
customer = find_customer_by_phone()

customer_id = customer[0]
print(f"Customer ID: {customer_id}, Name: {customer[1]}")

while True:
product_id = int(input("Enter product ID (0 to finish): "))
if product_id == 0:
break
cursor.execute("SELECT * FROM products WHERE product_id
= %s", (product_id,))
product = cursor.fetchone()
if product is None:
print("Product not found.")
continue

quantity = int(input("Enter quantity: "))


if quantity > product[4]:
print("Insufficient stock!")
continue
total_price = product[3] * quantity
# Insert order details into orders table
order_query = "INSERT INTO orders (customer_id,
product_id, quantity, total_price) VALUES (%s, %s, %s, %s)"
cursor.execute(order_query, (customer_id, product_id,
quantity, total_price))
# Update product stock
new_stock = product[4] - quantity
update_stock_query = "UPDATE products SET stock = %s
WHERE product_id = %s"
cursor.execute(update_stock_query, (new_stock,
product_id))
db.commit()
print("Order created successfully!")
12
# Function to view orders
def view_orders():
cursor.execute("""
SELECT o.order_id, o.order_date, c.customer_name,
c.phone, p.product_name, o.quantity, o.total_price
FROM orders o
JOIN customers c ON o.customer_id = c.customer_id
JOIN products p ON o.product_id = p.product_id
ORDER BY o.order_date DESC
""")
orders = cursor.fetchall()
print("\nOrders:")
for order in orders:
print(f"Order ID: {order[0]}, Date: {order[1]}, Customer:
{order[2]}, Phone: {order[3]}, Product: {order[4]}, Quantity:
{order[5]}, Total Price: {order[6]}")
print()
# Function to generate sales report
def sales_report():
cursor.execute("""
SELECT p.product_name, SUM(o.quantity) AS total_sold,
SUM(o.total_price) AS total_sales
FROM orders o
JOIN products p ON o.product_id = p.product_id
GROUP BY p.product_name
ORDER BY total_sales DESC
""")
report = cursor.fetchall()
print("\nSales Report:")
for row in report:
print(f"Product: {row[0]}, Total Sold: {row[1]}, Total Sales:
{row[2]}")
print

13
# -------------------- MAIN MENU ----------------------

def menu():
while True:
print("\n******************** WELCOME TO HEAVENLY
TREAT ********************")
print("\n PRODUCT MANAGEMENT....")
print("1. Add Product")
print("2. View Products")
print("3. Update Product")
print("4. Delete Product")
print("\n CUSTOMER MANAGEMENT....")
print("5. Add Customer")
print("6. View Customers")
print("7. Update Customer")
print("8. Delete Customer")
print("\n ORDER MANAGEMENT....")
print("9. Create Order")
print("10. View Orders")
print("11. Sales Report")
print("12. Exit")

choice = int(input("Enter your choice: "))

if choice == 1:
add_product()
elif choice == 2:
view_products()
elif choice == 3:
update_product()
elif choice == 4:
delete_product()
elif choice == 5:
add_customer()

14
elif choice == 6:
view_customers()
elif choice == 7:
update_customer()
elif choice == 8:
delete_customer()
elif choice == 9:
create_order()
elif choice == 10:
view_orders()
elif choice == 11:
sales_report()
elif choice == 12:
break
else:
print("Invalid choice. Try again.")

# Run the bakery management system


if __name__ == "__main__":
menu()

# Close the database connection when the program ends


cursor.close()
db.close()

15
OUTPUT:
17
18
BIBLIOGRAPHY

• www.scribd.com

• www.slideshare.net

• https://githum.com

• www.freeprojectz.com

• Sumita Arora Class 12


Computer Science
textbook

19

You might also like