0% found this document useful (0 votes)
12 views7 pages

Source Code

Uploaded by

jasoncva20
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)
12 views7 pages

Source Code

Uploaded by

jasoncva20
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/ 7

TABLES AND FIELDS

FOR DATABSASES
SOURCE CODE
1. # Importing MySQL
2. import mysql.connector as mysql
3.
4. print("\t Welcome to Royal Enfield Showroom")
5.
6. # Establishing Connection
7. db = mysql.connect(host = "localhost", user = "root", password = "JasonJoe20",
database = "RE_Showroom")
8. if db.is_connected():
9. print("Connection established successfully")
10. cb = db.cursor()
11.
12. # Function to order a bike
13. def Order():
14. print("Welcome to the Order Tab!")
15. print("Here are our models and its details: ")
16. # Displaying Models
17. print("\tModelID \t SNo\t Model \t Sold\tStock Price")
18. cb.execute("select * from Bikes;")
19. Bikes = cb.fetchall()
20. for Bike in Bikes:
21. for field in Bike:
22. print("\t", field, end = " ")
23. print()
24. # Entering details of Customer
25. CName = input("Enter Customer Name: ")
26. CPhone = int(input("Enter Customer Phone Number: "))
27. CEmail = input("Enter Customer E-Mail ID: ")
28. CID = int(input("Enter Customer ID (given by employee): "))
29. cb.execute("insert into CUSTOMER(ID, Name, PhoneNo, Email) values ({}, '{}', {},
'{}')".format(CID, CName, CPhone, CEmail))
30. db.commit()
31. # entereing details of Model
32. sno = int(input("Enter SNo of the model you would like to purchase: "))
33. cb.execute("select * from Bikes")
34. Data = cb.fetchall()
35. for i in Data:
36. if i[1] == sno:
37. MID = i[0]
38. MName = i[2]
39. cb.execute("insert into ORDERS(CustomerID, CustomerName, ModelID, ModelName)
values ({}, '{}', '{}', '{}')".format(CID, CName, MID, MName))
40. db.commit()
41. print("Order Placed succesfully! ")
42. print("Thank you for shopping with Royal Enfield! ")
43. print("For delivery queries contact 768906")
44. print()
45.
46.
47. # Fucntion to order accessories
48. def Accessories():
49. print("Here are the list of accessories: ")
50. # Displaying Equipments
51. print("\tID \tSNo\tEquipments \t Sold\tStock\tPrice")
52. cb.execute("select *from accessories;")
53. Equipments = cb.fetchall()
54. for Equipment in Equipments:
55. for field in Equipment:
56. print("\t", field, end = " ")
57. print()
58. # Entereing details of Customer
59. CName = input("Enter Customer Name: ")
60. CPhone = int(input("Enter Customer Phone Number: "))
61. CEmail = input("Enter Customer E-Mail ID: ")
62. CID = int(input("Enter Customer ID (given by employee): "))
63. cb.execute("insert into CUSTOMER(ID, Name, PhoneNo, Email) values ({}, '{}', {},
'{}')".format(CID, CName, CPhone, CEmail))
64. db.commit()
65. # Enetering details of Equipment
66. sno = int(input("Enter SNo of the equipment you would like to purchase: "))
67. cb.execute("select * from Accessories")
68. Data = cb.fetchall()
69. for i in Data:
70. if i[1] == sno:
71. EID = i[0]
72. EName = i[2]
73.
74. cb.execute("insert into ORDERS(CustomerID, CustomerName, EquipmentID,
EquipmentName) values ({}, '{}', '{}', '{}')".format(CID, CName, EID, EName))
75. db.commit()
76. print("Order Placed succesfully! ")
77. print("Thank you for shopping with Royal Enfield! ")
78. print("For delivery queries contact 768906")
79. print()
80.
81. # Menu for Customers
82. while True:
83. print("How can we help you? ")
84. print("1. Order a bike")
85. print("2. Buy some accessories")
86. print("3. Exit")
87. Ans = int(input("Enter number of choice: "))
88. if Ans == 1:
89. Order()
90. elif Ans == 2:
91. Accessories()
92. elif Ans == 3: # Exiting the loop
93. break
94. else:
95. print("Invalid choice. ") # Invalid Condition
96.
OUTPUT

1. Ordering a Bike

2. Buying an Accessory
3. Exiting

DATABASE
1. After ordering a Bike
2. After Buying an Accessory

You might also like