-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
295 lines (281 loc) · 9.59 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
import mysql.connector as con
db=con.connect(user='root',host='localhost',password='0829')
if db.is_connected():
print("connected")
cur = db.cursor()
cur.execute("create database python")
cur.execute('use python')
db.close()
db = con.connect(user='root', host='localhost', password='0829', database='python')
cur = db.cursor()
cur.execute('create table music (MusicCode int(3) primary key,Name varchar(20)not null,Artist varchar(20),Releases varchar(20),Price int(3),Genre varchar(20)default "N/A",Quantity int(3))')
cur.execute('create table customer_details (Code int(3) primary key,CustomerName varchar(20),PhoneNo int(10),IssueDate date,ReturnDate date)')
print('created')
db.close()
else:
print('not connected')
exit()
#to add records in customdeets
def cadd():
db=con.connect(user='root',host='localhost',password='0829',database='python')
cur=db.cursor()
issdate=input('enter issue date')
rtdate=input("enter return date you want to add")
custname=input("enter name of customer date you want to add")
custph=int(input("enter phone no. of customer you want to add"))
custcode=int(input("enter customer code you want to add"))
sql='insert into customer_details values(%s,%s,%s,%s,%s)'
val=(custcode,custname,custph,issdate,rtdate)
cur.execute(sql,val)
db.commit()
db.close()
print('added')
#to search by code in customdeets
def searchbycode():
db=con.connect(user='root',host='localhost',password='0829',database='python')
cur=db.cursor()
c=int(input("enter customer code you want to search"))
sql='select * from customer_details where code=%s'
val=(c,)
cur.execute(sql,val)
r=cur.fetchone()
print(r)
db.commit()
db.close()
#to search by name in customdeets
def searchbyname():
db=con.connect(user='root',host='localhost',password='0829',database='python')
cur=db.cursor()
n=input("enter customer name you want to search")
sql='select * from customer_details where customername=%s'
val=(n,)
cur.execute(sql,val)
r=cur.fetchone()
print(r)
db.commit()
db.close()
#to search by phone in customdeets
def searchbyphone():
db=con.connect(user='root',host='localhost',password='0829',database='python')
cur=db.cursor()
c=int(input("enter customer phone number you want to search"))
sql='select * from customer_details where code=%s'
val=(c,)
cur.execute(sql,val)
r=cur.fetchone()
print(r)
db.commit()
db.close()
#to modify in customdeets
def modify():
db=con.connect(host='localhost',user='root',password='0829',database='python')
cur=db.cursor()
code=int(input("enter customer code you want to modify details of"))
ch=input("do you want to change name Y/N")
if ch=='y' or ch=='Y':
n2=input('enter new name')
sql='update CUSTOMER_details set customer ame=%s where code=%s'
val=(n2,code)
cur.execute(sql,val)
db.commit()
ch=input("do you want to change phone number? Y/N")
if ch=='y' or ch=='Y':
n2=int(input('enter new number'))
sql='update CUSTOMER_details set phoneno=%s where code=%s'
val=(n2,code)
cur.execute(sql,val)
db.commit()
ch=input("do you want to change date of issue? Y/N")
if ch=='y' or ch=='Y':
n2=input('enter new date of issue')
sql='update CUSTOMER_details set issuedate=%s where issuedate=%s'
val=(n2,code)
cur.execute(sql,val)
db.commit()
ch=input("do you want to change date of return? Y/N")
if ch=='y' or ch=='Y':
n2=input('enter new date of return')
sql='update CUSTOMER_details set returndate=%s where returndate=%s'
val=(n2,code)
cur.execute(sql,val)
db.commit()
else:
db.close()
#to delete customer from customdeets
def cdel():
e=int(input("enter no. of customer you want to delete"))
db=con.connect(user='root',host='localhost',password='granth',database='python')
cur=db.cursor()
sql='delete from customer_details where code=%s'
val=(e,)
cur.execute(sql,val)
db.commit()
db.close()
#to add records in music
def madd():
db=con.connect(user='root',host='localhost',password='0829',database='python')
cur=db.cursor()
mcode=int(input("enter music code:"))
mname=input("enter name of music:")
artist=input("enter name of artist: ")
genre=input("enter genre of music:")
ryear=int(input("Enter the year of release:"))
price=int(input("enter price of music rented:"))
qty=int(input("enter quantity:"))
sql='insert into MUSIC values(%s,%s,%s,%s,%s,%s,%s)'
val=(mcode,mname,artist,ryear,price,genre,qty)
cur.execute(sql,val)
db.commit()
db.close()
print('record inserted')
#to delete from music
def mdel():
e=int(input("enter no. of music name you want to delete"))
db=con.connect(user='root',host='localhost',password='0829',database='python')
cur=db.cursor()
sql='delete from MUSIC where musiccode=%s'
val=(e,)
cur.execute(sql,val)
db.commit()
db.close()
#search by code in music
def msearchbycode():
db=con.connect(host='localhost',user='root',password='0829',database='python')
cur=db.cursor()
mcode=int(input("enter music code you want to search"))
sql='select * from MUSIC where musiccode=%s'
val=(mcode,)
cur.execute(sql,val)
r=cur.fetchone()
print(r)
db.commit()
db.close()
#search by name in music
def msearchbyname():
db=con.connect(host='localhost',user='root',password='0829',database='python')
cur=db.cursor()
n=input("enter music name you want to search")
sql='select * from MUSIC where name=%s'
val=(n,)
cur.execute(sql,val)
r=cur.fetchone()
print(r)
db.commit()
db.close()
#search by artist in music
def searchbyartist():
b=con.connect(host='localhost',user='root',password='0829',database='python')
cur=db.cursor()
a=input("enter artist of songs you want to search")
sql='select * from MUSIC where artist=%s'
val=(a,)
cur.execute(sql,val)
r=cur.fetchall()
for i in r:
print(i)
db.commit()
db.close()
#to search by genre in music
def searchbygenre():
db=con.connect(host='localhost',user='root',password='0829',database='python')
cur=db.cursor()
a=input("enter genre of songs you want to search")
sql='select * from MUSIC where genre=%s'
val=(a,)
cur.execute(sql,val)
r=cur.fetchall()
for i in r:
print(i)
db.commit()
db.close()
#to modify in music
def mmodify():
db=con.connect(host='localhost',user='root',password='0829',database='python')
cur=db.cursor()
mcode=int(input("enter music code you want to modify details of"))
ch=input("do you want to change name Y/N")
if ch=='y' or ch=='Y':
n2=input('enter new name')
sql='update music set name=%s where musiccode=%s'
val=(n2,mcode)
cur.execute(sql,val)
db.commit()
ch=input("do you want to change artist Y/N")
if ch=='y' or ch=='Y':
n2=input('enter new artist')
sql='update music set artist=%s where musiccode=%s'
val=(n2,mcode)
cur.execute(sql,val)
db.commit()
ch=input("do you want to change price Y/N")
if ch=='y' or ch=='Y':
n2=int(input('enter new price'))
sql='update music set price=%s where price=%s'
val=(n2,mcode)
cur.execute(sql,val)
db.commit()
ch=input("do you want to change genre Y/N")
if ch=='y' or ch=='Y':
n2=input('enter new genre')
sql='update music set genre=%s where genre=%s'
val=(n2,mcode)
cur.execute(sql,val)
db.commit()
ch=input("do you want to change qty Y/N")
if ch=='y' or ch=='Y':
n2=int(input('enter new qty'))
sql='update music set quantity=%s where quantity=%s'
val=(n2,mcode)
cur.execute(sql,val)
db.commit()
ch=input("do you want to change year of release Y/N")
if ch=='y' or ch=='Y':
n2=int(input('enter new price'))
sql='update music set releases=%s where releases=%s'
val=(n2,mcode)
cur.execute(sql,val)
db.commit()
n='y'
while n in 'yY':
a=int(input('''Press 1 to add records in Customer table
Press 2 to search using code in Customer table
Press 3 to search using name in Customer table
Press 4 to search using phone number in Customer table
Press 5 to modify details in Customer table
Press 6 to delete details in Customer table
Press 7 to add records in music table
Press 8 to search using code in music table
Press 9 to search using name in music table
Press 10 to search using artist in music table
Press 11 to search using genre in music table
Press 12 to modify details in music table
Press 13 to delete records in Music table'''))
if a==1:
cadd()
elif a==2:
searchbycode()
elif a==3:
searchbyname()
elif a==4:
searchbyphone()
elif a==5:
modify()
elif a==6:
cdel()
elif a==7:
madd()
elif a==8:
msearchbycode()
elif a==9:
msearchbyname()
elif a==10:
searchbyartist()
elif a==11:
searchbygenre()
elif a==12:
mmodify()
elif a==13:
mdel()
else:
print('wrong choice, try again!')
n=input('Do you want to continue?(Y/N)?')