You are on page 1of 8

import sqlite3

sql_connect = sqlite3.connect('automobile.db')

cursor = sql_connect.cursor()

t=0

try:

query = 'SELECT * FROM customerdetails'

cursor.execute(query).fetchone

except:

createCust = "CREATE TABLE customerdetails (c_id int NOT NULL PRIMARY KEY,c_name
varchar(255) NOT NULL,c_address varchar(255), c_phone varchar(10), no_vehicle int NOT NULL)"

cursor.execute(createCust)

try:

query2 = 'SELECT * FROM showroomdetails'

cursor.execute(query2).fetchone

except:

createShow = "CREATE TABLE showroomdetails (s_id int NOT NULL PRIMARY KEY,s_name
varchar(255) NOT NULL,s_address varchar(255), s_phone varchar(10))"

cursor.execute(createShow)

try:

query3 = 'SELECT * FROM vehicledetails'

cursor.execute(query2).fetchone

except:

createCust = "CREATE TABLE vehicledetails (v_id varchar(10) NOT NULL PRIMARY KEY,c_id int NOT
NULL,s_id int NOT NULL, service_date DATE NOT NULL"

cursor.execute(createCust)

while(t!=1):

print("Main Menu")

print("1.) Service Center Menu")

print("2.) Customer Details menu")

print("3.) List of vehicles")

print("4.) exit")
ch = int(input(" Enter your choice "))

if(ch==1):

print("Service center Menu")

print("1.) Add a service center")

print("2.) veiw all service centers")

print("3.) remove a service center")

print("4.) exit")

c = int(input(" Enter your Choice "))

if(c==1):

s_id= int(input('Enter the Service center ID\t'))

s_name= input('Enter Name of the service center\t')

address = input('Enter the Adrress\t')

phone = int(input('Enter the phone number'))

cursor.execute("""INSERT INTO showroomdetails (s_id,s_name,s_address,s_phone) VALUES


(?,?,?,?)""",(s_id,s_name,address,phone,))

sql_connect.commit()

elif(c==2):

#display all showroom's details

results = cursor.execute(query2).fetchall()

print("\tShowroom I.D.",end=" ")

print("\tShowroom Name",end=" ")

print("\tShowroom Address",end=" ")

print("\tShowroom Phone no.")

print("="*140)

for row in results:

print("\t",row[0],end=" ")

print("\t",row[1],end=" ")

print("\t",row[2],end=" ")

print("\t",row[3])

elif(c==3):

check_id= input('Enter the id of the Service center')


cursor.execute("""DELETE FROM showroomdetails WHERE s_id = ? """, (check_id,))

sql_connect.commit()

elif(c==4):

t=1

break

elif(ch==2):

print("Customer Menu")

print("1.) Add a customer")

print("2.) Display all Customers")

print("3.) Remove a Customer")

print("4.) Search Customers")

print("5.) Update Customer")

print("6.) exit")

c= int(input(' Enter your choice '))

if(c==1):

c_id= int(input('Enter the customer ID\t'))

c_name= input('Enter Name of the customer\t')

address = input('Enter the Adrress\t')

phone = input('Enter the phone number\t')

no_vehicle= int(input('enter number of vehicles owned\t'))

cursor.execute("""INSERT INTO customerdetails (c_id,c_name,c_address,c_phone,no_vehicle)


VALUES (?,?,?,?)""",(c_id,c_name,address,phone,no_vehicle,))

sql_connect.commit()

elif(c==2):

#display all customer's details

results = cursor.execute(query).fetchall()

print("\tCustomer I.D.",end=" ")

print("\tCustomer Name",end=" ")

print("\tCustomer Address",end=" ")

print("\tCustomer Phone no.",end=" ")

print("\tNo. Vehicles",end=" ")


print("="*140)

for row in results:

print("\t",row[0],end=" ")

print("\t",row[1],end=" ")

print("\t",row[2],end=" ")

print("\t",row[3],end=" ")

print("\t",row[4])

elif(c==3):

check_id= input('Enter the id of the Customer')

cursor.execute("""DELETE FROM customerdetails WHERE c_id = ? """, (check_id,))

sql_connect.commit()

elif(c==4):

check_id= input('Enter the id of the Customer')

cursor.execute("""SELECT * FROM customerdetails WHERE c_id = ? """, (check_id,))

sql_connect.commit()

elif(c==5):

print("Update Menu")

print("="*20)

print("1.) Update Name")

print("2.) update no. of vehicles")

print("3.) Update Adress")

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

if(s==1):

check_id= input('Enter the id of the Service center')

name_new = input('Enter the rectified Name')

cursor.execute("""UPDATE bookdetails SET c_name = ? WHERE c_id =? """,


(name_new,check_id,))

sql_connect.commit()

elif(s==2):

check_id= input('Enter the id of the Service center')

no_new = int(input('Enter the no. of vehicles'))


cursor.execute("""UPDATE bookdetails SET no_vehicle = ? WHERE c_id =? """,
(no_new,check_id,))

sql_connect.commit()

elif(s==3):

check_id= input('Enter the id of the Service center')

no_new = int(input('Enter the rectified address'))

cursor.execute("""UPDATE bookdetails SET c_address = ? WHERE c_id =? """,


(no_new,check_id,))

sql_connect.commit()

elif(c==6):

t=1

break

else:

print('Wrong choice')

elif(ch==3):

print("Vehicle Menu")

print("1.) Add a vehicle detail")

print('2.) Remove a vehicle detail')

print('3.) Search a vehicle')

print('4.) rectify a mistake')

print('5.) exit')

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

if(c==1):

v_id= input('Enter the customer ID\t')

c_id= int(input('Enter customer ID'))

s_id= int(input('Enter Service center ID'))

date = input('Enter the Date of next servicing')

cursor.execute("""INSERT INTO vehicledetails (v_id,c_id,s_id,service_date) VALUES


(?,?,?,?)""",(v_id,c_id,s_id,date,))

sql_connect.commit()

elif(c==2):

check_id= input('Enter the id of the Customer')


cursor.execute("""DELETE FROM vehicledetails WHERE v_id = ? """, (check_id,))

sql_connect.commit()

elif(c==3):

print('Search menu')

print("="*20)

print("1.) Search by vehicle number")

print("2.) Search by Customer ID")

print("3.) Search by Service center ID")

print("4.) Exit")

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

if(s==1):

check_id= input('Enter the vehicle number')

cursor.execute("""SELECT * FROM vehicledetails WHERE v_id = ? """, (check_id,))

sql_connect.commit()

elif(s==2):

check_id= input('Enter the customer ID')

cursor.execute("""SELECT * FROM vehicledetails WHERE c_id = ? """, (check_id,))

sql_connect.commit()

elif(s==3):

check_id= input('Enter the Service center ID')

cursor.execute("""SELECT * FROM vehicledetails WHERE s_id = ? """, (check_id,))

sql_connect.commit()

elif(s==4):

t=1

break

else:

print('Wrong choice')

elif(c==4):

print("Update Menu")

print("="*20)

print("1.) Rectify Vehicle Number")


print("2.) Rectify Customer's ID")

print("3.) Rectify service center's ID")

print("4.) Exit")

s= int(input("Enter your Choice"))

if(s==1):

check_id= input('Enter the Vehicle Number')

name_new = input('Enter the rectified Vehicle Number')

cursor.execute("""UPDATE vehicledetails SET v_id = ? WHERE v_id =? """,


(name_new,check_id,))

sql_connect.commit()

elif(s==2):

check_id= input('Enter the Vehicle Number')

name_new = input('Enter the rectified customer ID')

cursor.execute("""UPDATE vehicledetails SET c_id = ? WHERE v_id =? """,


(name_new,check_id,))

sql_connect.commit()

elif(s==3):

check_id= input('Enter the Vehicle Number')

name_new = input('Enter the rectified Service center ID')

cursor.execute("""UPDATE vehicledetails SET s_id = ? WHERE c_id =? """,


(name_new,check_id,))

sql_connect.commit()

elif(s==4):

t=1

break

else:

print('Wrong Choice')

elif(c==5):

t=1

break

else:

print(" Wrong choice ")


elif(ch==4):

break

else:

print(" Sorry Wrong choice ")

You might also like