0% found this document useful (0 votes)
22 views47 pages

CSC Activity

The document outlines a computer science project focused on a Car Service Management system named Precision Car Zone, intended for the AISSCE 2024-25 examination. It includes sections on Python and SQL introductions, hardware/software requirements, and detailed functionalities of the car service management system, such as booking appointments and managing customer data. Additionally, it features source code for database connectivity and operations related to user and service management.

Uploaded by

kandikattuvalasu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views47 pages

CSC Activity

The document outlines a computer science project focused on a Car Service Management system named Precision Car Zone, intended for the AISSCE 2024-25 examination. It includes sections on Python and SQL introductions, hardware/software requirements, and detailed functionalities of the car service management system, such as booking appointments and managing customer data. Additionally, it features source code for database connectivity and operations related to user and service management.

Uploaded by

kandikattuvalasu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 47

COMPUTER SCIENCE PROJECT

ON

Car Service Management


Precision Car Zone
FOR AISSCE 2024-25 EXAMINATION

[AS A PART OF THE COMPUTER COURSE (083)]

SUBMITTED BY

Name:

Roll Number:

Class: XII-S3

Session: 2024-2025
BONAFIDE CERTIFICATE

This is to certify that the project

in Computer science (083) has been submitted by the candidate

of class XII as per the requirements for

the CBSE Board Examination for the academic year 2024-2025.

SUBJECT:

REGISTER NO:

DATE:

PRINCIPAL SIGNATURE TEACHER SIGNATURE

SCHOOL STAMP EXAMINER SIGNATURE


Acknowledgment

Apart from the effort of me, the success of any project depends largely on
the encouragement and guidelines of many others. I take this opportunity to
express my gratitude to the people who have been instrumental in successful
completion of this project.

I express deep sense of gratitude to almighty God for giving me strength


for the successful completion of the project.

I express deep sense of gratitude to my Principal Ms. Dolly Mohan, who


has been continuously motivating and extending her helping hand to us. She
also appreciated and recognized my efforts and achievements in this project.

I would like to express my sincere gratitude to my computer science


teacher, Mr. Kingsley.D, for his guidance, support, and encouragement
throughout this project. I am truly grateful for the time and effort they dedicated
to answering my questions and helping me improve my work. His
encouragement kept me motivated and focused, ensuring that I was able to
complete the project to the best of my ability.

I would like to extend my heartfelt thanks to my parents for their constant


encouragement, understanding and help. Their unwavering support gave me the
strength to work diligently on this project.

Lastly, I would like to thank all my friends and classmates for their help,
suggestions, and cooperation. Their collective enthusiasm and advice were
crucial in completing this project.
Index

S.No Topic Pg.No

1 Python Introduction 1

2 SQL Introduction 4

3 Python SQL Connectivity 6

4 Hardware/Software 7
Requirements

5 Precision Car Zone 8

6 Source Code 10

7 Sample Output 33

8 References and 43
Bibliography
PYTHON INTRODUCTION

1.1 What is python?


Python is an open source, object-oriented high-level programming language
developed by Guido Van Rossum in 1991 at the National Research Institute for
Mathematics, Netherlands.
1.2 Features of Python:
● It is an interactive, interpreted language.
● It is a loosely typed object –oriented language.
● It is a free open –source and portable language,
● It takes less time to develop programs.
● It is extensible / extendable and highly efficient.
● It supports GUI.
● It can be easily compatible with other languages like C, C++ etc.
● It is used for both scientific and non-scientific programming.

Fig. 1.1 Python logo

1
1.3 Installing Python:
It can be installed by using website:
https://www.python.org/downloads/

Fig. 1.2 python.org

1.4 Interacting with Python:


Python programs can be run in two ways:
● Using Command line window

Fig. 1.3 Command line window

2
● Using IDLE

Fig. 1.4 Python Interactive Mode

1.5 Python Script Mode:

Fig. 1.5 Python Script Mode

3
SQL INTRODUCTION

2.1 What is SQL?


SQL is a domain-specific language designed for managing data held in
relational database management systems (RDBMS). It provides a way to
interact with databases using queries and commands. SQL is widely used due to
its ability to handle complex queries and its standardization across different
RDBMSs like MySQL, PostgreSQL, SQL Server, and SQLite.

2.2 Getting Started:


1. Install a Database System: Choose an RDBMS like MySQL,
PostgreSQL, or SQLite and install it on your machine.
2. Access the Database: Use a client tool or command line interface
provided by the RDBMS to interact with the database.
3. Practice SQL Commands: Write and execute SQL queries to familiarize
yourself with the syntax and functionality.

Fig. 2.1 Types of SQL commands

4
2.3 Installing MySQL:
Step 1: In Google search bar type Mysql download
Step 2: scroll down and click GPL link https://dev.mysql.com/downloads/
Step 3: select MySQL installer for windows
Step 4: Download MSI installer of 296MB file
Step 5: Once the file is downloaded go to your Downloads folder and start your
installation process
Step 6: Start the installation
Step 7: set the password as ‘root’
Step 8: click finish and don’t change the default settings
Step 9: close the MYSQL JS terminal
Step 10: Go to start - all programs – Mysql - MySQL 8.0 command line client
Step 11: enter the password (root) and press enter

Fig. 2.2 MySQL Command Line Client

5
PYTHON SQL CONNECTIVITY

Connecting Python to a SQL database involves using a database connector


library or module that allows Python code to execute SQL queries and interact
with the database.

3.1 Common Python SQL Libraries:


1. SQLite: A lightweight, file-based database.
2. MySQL: A popular open-source database server.
3. PostgreSQL: An advanced open-source database system.
4. SQL Server: A relational database system developed by Microsoft

3.2 Key Points:


 Connection: Establish a connection using the appropriate library and
credentials.
 Cursor: Create a cursor object to execute SQL commands.
 Execute: Use the cursor to run queries and commands.
 Commit: Save changes to the database (except for read-only queries).
 Close: Always close the connection to release resources.

Fig. 3.1 Steps to connect Python and MySQL

6
HARDWARE /SOFTWARE REQUIREMENTS

4.1 Hardware Requirements:


 PC, laptop, keyboard, mouse, printer

 Processor 12th Gen Intel(R) Core (TM) i7-1260P 2.10 GHz

 Installed RAM 16.0 GB (15.7 GB usable)

4.2 Software Requirements:


 Windows 11 Home Single Language Version - 23H2
 Python 3.11.4 as Front-end Development environment
 MySQL 8.0 Command Line Client as Back-end Development environment
 MS-Word for documentation

7
PRECISION CAR ZONE

 This platform is designed to make car maintenance and repair work easy
and stress-free. This enables you to book an appointment for a car to
repair or make any services online.
 It adds and views customer details, including name, phone number,
email, and address.
 Maintain a database of vehicles associated with customers, including
details like model, year, and license plate.
 It records and views vehicle service details, including service type, cost,
and service date.
 This system ensures efficient management of all service-related activities,
making it easier for car service businesses to keep track of their
operations and provide better customer service.
 This would also generate the invoice of the repaired or serviced details
according to the service and repair works done.
 The project not only focuses on storing and managing data but also
ensures data integrity and user-friendly interaction through a
command- line interface.

Fig. 5.1

8
5.1 Benefits of booking a car service appointment through online:

1. Convenience: Book an appointment from anywhere, at any time, without


having to call or visit the service center.
2. Time-saving: Quickly fill out a booking form and receive instant
confirmation, saving time and effort.
3. Easy scheduling: Choose a date and time that suits you, with real-time
availability checks.
4. Reduced wait times: Book in advance to minimize waiting time at the
service center.
5. Access to discounts and promotions: Receive exclusive online offers and
discounts.
6. Reminders and notifications: Get automated reminders and updates on your
appointment.
7. Paperless documentation: Access your service history and records digitally.
8. Increased transparency: Clearly see the services and costs involved.
9. Improved customer experience: Online booking systems often include
customer feedback and review options.
10. Environmentally friendly: Reduce paper waste and minimize carbon
footprint.

Booking a car service appointment online offers a seamless, efficient, and


convenient experience!

9
Source Code

import mysql.connector
import datetime

con = mysql.connector.connect(host='localhost',user='root',password='root')
cursor=con.cursor()

def start():
cursor.execute("CREATE DATABASE IF NOT EXISTS car_service")
cursor.execute("USE car_service")
cursor.execute("""

CREATE TABLE IF NOT EXISTS Roles(


role_id INT PRIMARY KEY,

role_name VARCHAR(50) NOT NULL UNIQUE


);
""")
cursor.execute("""
CREATE TABLE IF NOT EXISTS users(

user_id INT PRIMARY KEY,


username VARCHAR(50) NOT NULL UNIQUE,
password VARCHAR(50) NOT NULL,
role_id INT,

FOREIGN KEY(role_id) REFERENCES Roles(role_id)


);
""")
cursor.execute("""
CREATE TABLE IF NOT EXISTS services(

service_id INT PRIMARY KEY,

10
service_name VARCHAR(50) NOT NULL,
price INT NOT NULL

);
""")
cursor.execute("""
CREATE TABLE IF NOT EXISTS tasks(

task_id INT PRIMARY KEY,


task_name VARCHAR(100),
assigned_to INT,
status VARCHAR(30),

FOREIGN KEY(assigned_to) REFERENCES users(user_id)


);
""")
cursor.execute("""
CREATE TABLE IF NOT EXISTS booking(

booking_id INT PRIMARY KEY,


user_id INT NOT NULL,
service_id INT NOT NULL,
date DATE NOT NULL,

status VARCHAR(50) NOT NULL,


FOREIGN KEY(user_id) REFERENCES users(user_id),
FOREIGN KEY(service_id) REFERENCES services(service_id)
);
""")
cursor.execute("""
CREATE TABLE IF NOT EXISTS feedback(

feedback_id INT AUTO_INCREMENT PRIMARY KEY,


booking_id INT NOT NULL,
user_id INT NOT NULL,

11
feedback_text TEXT,
rating INT,
FOREIGN KEY (booking_id) REFERENCES booking(booking_id),
FOREIGN KEY (user_id) REFERENCES users(user_id)

);
""")
cursor.execute("""
CREATE TABLE IF NOT EXISTS payments(

payment_id INT AUTO_INCREMENT PRIMARY KEY,


booking_id INT NOT NULL,
user_id INT NOT NULL,
amount_paid INT NOT NULL,
payment_date DATE NOT NULL,
payment_status VARCHAR(50) NOT NULL,
FOREIGN KEY (booking_id) REFERENCES booking(booking_id),
FOREIGN KEY (user_id) REFERENCES users(user_id)
);
""")
cursor.execute("""
INSERT IGNORE INTO Roles (role_id, role_name)
VALUES (1, 'admin'), (2, 'tech'), (3, 'user');
""")
cursor.execute("""
INSERT INTO Roles (role_id, role_name)
VALUES (1, 'admin'), (2, 'tech'), (3, 'user')
ON DUPLICATE KEY UPDATE role_name=VALUES(role_name);
""")
cursor.execute("""
INSERT INTO users (user_id, username, password, role_id)

12
VALUES
(1, 'admin_user', 'admin_pass', 1),

(2, 'tech_user1', 'tech_pass1', 2),


(3, 'tech_user2', 'tech_pass2', 2),

(4, 'regular_user1', 'user_pass1', 3),


(5, 'regular_user2', 'user_pass2', 3)

ON DUPLICATE KEY UPDATE username=VALUES(username),


password=VALUES(password), role_id=VALUES(role_id);
""")

cursor.execute("""
INSERT INTO services (service_id, service_name, price)
VALUES
(1, 'Oil Change', 50),

(2, 'Tire Rotation', 30),


(3, 'Brake Inspection', 75),
(4, 'Battery Replacement', 100)

ON DUPLICATE KEY UPDATE service_name=VALUES(service_name),


price=VALUES(price);
""")
cursor.execute("""
INSERT INTO tasks (task_id, task_name, assigned_to, status)
VALUES
(1, 'Oil Change for Car1', 2, 'In Progress'),
(2, 'Tire Rotation for Car2', 3, 'Completed'),
(3, 'Brake Inspection for Car3', 2, 'Pending')
ON DUPLICATE KEY UPDATE task_name=VALUES(task_name),
assigned_to=VALUES(assigned_to), status=VALUES(status);
""")

cursor.execute("""
INSERT INTO booking (booking_id, user_id, service_id, date, status)

13
VALUES
(1, 4, 1, '2025-01-01', 'Completed'),

(2, 4, 2, '2025-01-02', 'Pending'),


(3, 5, 3, '2025-01-03', 'In Progress')

ON DUPLICATE KEY UPDATE user_id=VALUES(user_id),


service_id=VALUES(service_id), date=VALUES(date), status=VALUES(status);
""")

cursor.execute("""
INSERT INTO feedback (feedback_id, booking_id, user_id, feedback_text, rating)
VALUES
(1, 1, 4, 'Great service!', 5),

(2, 2, 4, 'Quick and efficient.', 4)


ON DUPLICATE KEY UPDATE booking_id=VALUES(booking_id),
user_id=VALUES(user_id), feedback_text=VALUES(feedback_text),
rating=VALUES(rating);
""")
cursor.execute("""

INSERT INTO payments (payment_id, booking_id, user_id, amount_paid, payment_date,


payment_status)
VALUES

(1, 1, 4, 50, '2025-01-01', 'Paid')

ON DUPLICATE KEY UPDATE booking_id=VALUES(booking_id),


user_id=VALUES(user_id), amount_paid=VALUES(amount_paid),
payment_date=VALUES(payment_date), payment_status=VALUES(payment_status);
""")

con.commit()

start()

#for admin

14
def add_user():
username=input("Enter username:")
password=input("Enter password:")
role_id=input("Enter role ID (1 for Admin, 2 for Tech, 3 for User): ")

if not username or not password or not role_id:


print("Any one field is required.")
return

cursor.execute('select*from users where username=%s',(username,))


if cursor.fetchone():
print("Username already exists.")
return

cursor.execute('select max(user_id) from users')


max_id = cursor.fetchone()
next_id= (max_id[0]+1) if max_id[0] is not None else 1

cursor.execute('INSERT INTO users VALUES(%s,%s,%s,%s)',


(next_id,username,password,role_id))

con.commit()

print("User added succesfully.")

def view_users():
cursor.execute("SELECT*FROM users")
users = cursor.fetchall()
print("user_id username role_id")
for user in users:

15
print(user[0], ' ',user[1], ' ', '\t',user[3])

def add_services():
service_name=input("Enter service name:
") price = int(input("Enter service price: "))

cursor.execute('select max(service_id) from services')


max_id = cursor.fetchone()
next_id= (max_id[0]+1) if max_id[0] is not None else 1

cursor.execute("INSERT INTO services values(%s,%s,%s)",(next_id,service_name,price))


con.commit()
print("Service added succesfully.")

def view_services():
cursor.execute("SELECT*FROM services")
services = cursor.fetchall()

print("service id \tservice name \


tprice") for service in services:
print(service[0],'\t',service[1],"\t",service[2])

def view_user_bookings():
user_id = input("Enter the User ID to view their bookings: ")

cursor.execute("""
SELECT booking.booking_id, services.service_name, booking.date, booking.status
FROM booking
JOIN services ON booking.service_id = services.service_id
WHERE booking.user_id = %s

16
""", (user_id,))

bookings = cursor.fetchall()

if not bookings:
print(f"No bookings found for User ID
{user_id}.") return

print("\nUser's Bookings:")
print("Booking ID\tService Name\tDate\t\
tStatus") for booking in bookings:
print(f"{booking[0]}\t{booking[1]}\t{booking[2]}\t{booking[3]}")

def assign_task():
task_name=input("Enter task name: ")
assigned_to=input("Enter technician user ID: ")
status = 'pending'

cursor.execute("select user_id from users where user_id=%s",(assigned_to,))


if not cursor.fetchone():
print("User not found.")

cursor.execute('select max(task_id) from tasks')


max_id = cursor.fetchone()
next_id= (max_id[0]+1) if max_id[0] is not None else 1

cursor.execute("insert into tasks values(%s,%s,%s,%s)",


(next_id,task_name,assigned_to,status))
con.commit()

17
print("Task assigned succesfully")

def view_feedback():
cursor.execute("""
SELECT feedback.feedback_id, users.username, services.service_name,
feedback.rating, feedback.feedback_text
FROM feedback
JOIN booking ON feedback.booking_id = booking.booking_id
JOIN services ON booking.service_id = services.service_id
JOIN users ON feedback.user_id = users.user_id

""")
feedbacks = cursor.fetchall()

if not feedbacks:
print("No feedback available.")
return

print("\nFeedback Summary:")
print("Feedback ID\tUser\tService Name\tRating\tFeedback")
for feedback in feedbacks:
print(f"{feedback[0]}\t{feedback[1]}\t{feedback[2]}\t{feedback[3]}\t{feedback[4]}")

def view_payments():
cursor.execute("""
SELECT payments.payment_id, users.username, services.service_name,
payments.amount_paid, payments.payment_date, payments.payment_status
FROM payments
JOIN booking ON payments.booking_id = booking.booking_id
JOIN services ON booking.service_id = services.service_id

18
JOIN users ON payments.user_id = users.user_id
""")
payments = cursor.fetchall()

if not payments:
print("No payments found.")
return

print("\nPayments Summary:")
print("Payment ID\tUser\tService Name\tAmount Paid\tDate\t\tStatus")
for payment in payments:

print(f"{payment[0]}\t{payment[1]}\t{payment[2]}\t{payment[3]}\t{payment[4]}\t{payment
[5]}")

def admin_menu():
while True:
print("\nADMIN MENU")
print("1. Add User")
print("2. View Users")
print("3. Add Service")
print("4. View Services")
print("5. View bookings")
print("6. Assign Task")
print("7. View feedback.")
print("8. View payment")
print("9. Exit")

choice=input("choose an option: ")


if choice == '1':

19
add_user()
elif choice == '2':
view_users()
elif choice ==
'3':
add_services()
elif choice == '4':
view_services()
elif choice == '5':
view_user_bookings()
elif choice == '6':
assign_task()
elif choice == '7':
view_feedback()
elif choice == '8':
view_payments()
elif choice == '9':
break
else:
print("Invalid choice. Please try again.")

def view_assigned_tasks(user_id): print("\


nViewing Assigned Tasks")
status_filter = input("Filter by status (leave blank for all tasks): pending, in progress,
completed: ")

if status_filter:
cursor.execute('''SELECT task_id, task_name, status FROM tasks WHERE
assigned_to=%s AND status=%s''', (user_id, status_filter))
else:

20
cursor.execute('''SELECT task_id, task_name, status FROM tasks WHERE assigned_to=
%s''', (user_id,))

tasks = cursor.fetchall()

if tasks:
print("\nAssigned tasks:")
print("Task ID\tTask Name\tStatus")
for task in tasks:

print(f"{task[0]}\t{task[1]}\t{task[2]}")
else:

print("No tasks assigned.")

def view_task_details(task_id):
cursor.execute('''SELECT task_name, status, assigned_to FROM tasks WHERE task_id=
%s''', (task_id,))
task = cursor.fetchone()

if task:
print("\nTask Details:")
print(f"Task Name: {task[0]}")
print(f"Status: {task[1]}")
cursor.execute('''SELECT username FROM users WHERE user_id=%s''', (task[2],))
user = cursor.fetchone()
print(f"Assigned To: {user[0]}")
else:
print("Task not found.")

def update_task_status(user_id):
print("\nUpdate Task Status")

21
task_id = input("Enter task ID to update: ")

cursor.execute('''SELECT task_id, status FROM tasks WHERE task_id=%s AND


assigned_to=%s''', (task_id, user_id))
task = cursor.fetchone()

if task:

print(f"Current status of task {task_id}: {task[1]}")

if task[1] == 'completed':
print("Task is already completed. Status cannot be updated.")
return

new_status = input("Enter new status (pending, in progress, completed): ").lower()


if new_status not in ['pending', 'in progress', 'completed']:
print("Invalid status. Please try again.")
return

cursor.execute('''UPDATE tasks SET status=%s WHERE task_id=%s''', (new_status,


task_id))
con.commit()

print("Task status updated successfully.")


else:
print("Task not found or you are not assigned to this task.")

def tech_menu(user_id):
while True:
print("\nTECHNICIAN MENU")
print("1. View Assigned Tasks")

22
print("2. View Task Details")
print("3. Update Task Status")
print("4. Exit")

choice = input("Choose an option: ")


if choice == '1':
view_assigned_tasks(user_id)
elif choice == '2':
task_id = input("Enter task ID to view details: ")
view_task_details(task_id)
elif choice == '3':
update_task_status(user_id)
elif choice == '4':
break
else:

print("Invalid choice. Please try again.")

#for user

def book_service(user_id):
view_services()
service_id=input("Enter the service ID: ")

date = input("Enter the preferred date for the service(YYYY-MM-DD): ")

cursor.execute('select max(booking_id) from booking')


max_id = cursor.fetchone()
next_id= (max_id[0]+1) if max_id[0] is not None else 1

23
cursor.execute('insert into booking values(%s,%s,%s,%s,%s)',
(next_id,user_id,service_id,date,'pending'))
con.commit()

print("Service booked succesfully.")

def view_service_history(user_id):
cursor.execute('select
booking.booking_id,services.service_name,booking.date,booking.status from
booking,services where booking.service_id=services.service_id and booking.user_id=%s',
(user_id,))
history = cursor.fetchall()

if history:
print("\nYour service history.")

print("booking id \tservice name \tdate \tstatus")


for record in history:
print(record[0],'\t',record[1],"\t",record[2],'\t',record[3])

def cancel_booking(user_id):
booking_id = input("Enter the Booking ID you want to cancel: ")

cursor.execute("SELECT booking_id, status FROM booking WHERE booking_id = %s


AND user_id = %s",(booking_id,user_id))
booking=cursor.fetchone()
if booking:
if booking[1]!='completed':
cursor.execute("update booking set status='canceled' where booking_id=%s",
(booking_id,))

con.commit()

24
print('Booking canceled succesfully.')
else:
print("Cannot cancel a completed booking.")
else:

print("Booking not found.")

def leave_feedback(user_id):
cursor.execute("""
SELECT booking.booking_id, services.service_name, booking.date, booking.status
FROM booking
JOIN services ON booking.service_id = services.service_id
WHERE booking.user_id = %s
""", (user_id,))

bookings = cursor.fetchall()

if not bookings:
print("No bookings found to leave feedback.")
return

print("\nYour Bookings:")
print("Booking ID\tService Name\tDate\t\
tStatus") for booking in bookings:
print(f"{booking[0]}\t{booking[1]}\t{booking[2]}\t{booking[3]}")

booking_id = input("\nEnter the Booking ID to leave feedback: ")

cursor.execute("""
SELECT booking_id FROM booking
WHERE booking_id = %s AND user_id = %s

25
""", (booking_id, user_id))
if not cursor.fetchone():
print("Invalid booking ID.")
return

cursor.execute("""

SELECT feedback_id FROM feedback WHERE booking_id = %s AND user_id = %s


""", (booking_id, user_id))
if cursor.fetchone():
print("Feedback already provided for this booking.")
return

feedback_text = input("Enter your feedback: ")


rating = int(input("Enter your rating (1 to 5): "))
if rating < 1 or rating > 5:

print("Rating must be between 1 and 5.")


return

cursor.execute("""

INSERT INTO feedback (booking_id, user_id, feedback_text, rating)


VALUES (%s, %s, %s, %s)
""", (booking_id, user_id, feedback_text, rating))
con.commit()
print("Thank you for your feedback!")

def make_payment(user_id):

cursor.execute("""

SELECT booking.booking_id, services.service_name, services.price, booking.date

26
FROM booking
JOIN services ON booking.service_id = services.service_id
WHERE booking.user_id = %s AND booking.status = 'pending'
""", (user_id,))

bookings = cursor.fetchall()

if not bookings:
print("No pending bookings available for payment.")
return

print("\nPending Bookings for Payment:")


print("Booking ID\tService Name\tPrice\tDate")
for booking in bookings:
print(f"{booking[0]}\t{booking[1]}\t{booking[2]}\t{booking[3]}")

booking_id = input("\nEnter the Booking ID to make payment: ")

cursor.execute("""
SELECT booking_id, service_id FROM booking
WHERE booking_id = %s AND user_id = %s AND status = 'pending'
""", (booking_id, user_id))
booking = cursor.fetchone()

if not booking:

print("Invalid booking ID or already paid.")


return

service_id = booking[1]

cursor.execute("SELECT price FROM services WHERE service_id = %s", (service_id,))

27
price = cursor.fetchone()[0]

payment_status = 'paid'
payment_date =
datetime.date.today()

cursor.execute("""

INSERT INTO payments (booking_id, user_id, amount_paid, payment_date,


payment_status)
VALUES (%s, %s, %s, %s, %s)

""", (booking_id, user_id, price, payment_date, payment_status))


con.commit()
cursor.execute("UPDATE booking SET status = 'paid' WHERE booking_id = %s",
(booking_id,))
con.commit()

print("Payment successful! Thank you for your payment.")

def user_menu(user_id):
while True:
print("\nUSER MENU")
print("1. View Available Services")
print("2. Book a Service")
print("3. View Service History")
print("4. Leave feedback")
print("5. Cancel a Booking")
print("6. Make payment")
print("7. Exit")

choice = input("Choose an option: ")


if choice == '1':

28
view_services()
elif choice == '2':
book_service(user_id)
elif choice == '3':
view_service_history(user_id)
elif choice == '4':
leave_feedback(user_id)
elif choice == '5':
cancel_booking(user_id)
elif choice == '6':
make_payment(user_id)
elif choice == '7':
break
else:
print("Invalid choice. Try again.")

def login():

username=input("Enter username:")
password=input("Enter password:")

cursor.execute('SELECT user_id,password,role_id from users where username=%s',


(username,))
result = cursor.fetchone()

if result:
stored_password=result[1]
user_id=result[0]
role_id=result[2]

29
if password == stored_password:
print('Login successful.')

cursor.execute('SELECT role_name from roles where role_id=%s',(role_id,))


role_result=cursor.fetchone()

if role_result:
role_name=role_result[0]

if role_name=="admin":
print("Welcome Admin.")
admin_menu()

elif role_name=="tech":
print('Welcome
tech.')
tech_menu(user_id)

elif role_name=='user':
print('Welcome user.')
user_menu(user_id)

else:
print("Role not found.")
else:

print("Invalid password.")
else:

print("User not found.")

def sign_up():

30
username=input("Enter username:")
password=input("Enter password:")
role_id=input("Enter role id(1.admin,2.tech,3.user): ")

if not username or not password or not role_id:


print("At least one field is required.")
return

cursor.execute('select*from users where username=%s',(username,))


if cursor.fetchone():
print("Username already exists.")
return

cursor.execute('select max(user_id) from users')


max_id = cursor.fetchone()
next_id= (max_id[0]+1) if max_id[0] is not None else 1

cursor.execute('INSERT INTO users VALUES(%s,%s,%s,%s)',


(next_id,username,password,role_id))
con.commit()

print("Sign up succesful.")

a = input("Return to main page(yes or


no):") if a =='yes':
main()
elif a=='no':
print("Thank you for using car service managment.")
else:

31
print("Invalid option.")

def main():
while True:
print("WELCOME TO CAR SERVICE MANAGMMENT")
print("1. Login")
print("2. Sign up")
print("3. Exit")

choice = input("choose an option(1,2,3):")


if choice=="1":
login()
elif choice=="2":
sign_up()
elif choice=="3":
break
else:
print("Invalid option.")

main()

32
Sample Outputs
Python Outputs:

33
34
35
36
37
38
39
MySQL Outputs:

40
41
42
REFERENCES

 https://www.python.org/

 https://www.w3schools.com/sql/sql_intro.asp

 https://www.geeksforgeeks.org/how-to-connect-python-with-sql-
database/

BIBILIOGRAPHY

 Computer science with python by Sumita Arora

 Computer science with python by Preeti Arora

 Let us Python by Yashwant Kanetkar.

 MySQL connector/Python Revealed by Jesper Wisborg Krogh

 Computer Science NCERT textbook.

43

You might also like