-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
487 lines (444 loc) · 21.9 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
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
import os
import mysql.connector as sc
import datetime as dt
#Function to check availibity of a Book no.
def checkbook(bno):
try:
con=sc.connect(host='localhost',user=username,passwd=password,database='library')
cur=con.cursor()
cur.execute("Select count(*) from book where bno={} ".format(bno))
data=cur.fetchall()
d=data[0][0]
con.close()
return d
except:
return
#Function to check availibity of a Member no..
def checkmember(idd):
con=sc.connect(host='localhost',user=username,passwd=password,database='library')
cur=con.cursor()
cur.execute("Select count(*) from member where id={} ".format(idd))
data=cur.fetchall()
d=data[0][0]
con.close()
return d
#Function to check availibity of a issue no.
def checkissue(iss):
con=sc.connect(host='localhost',user=username,passwd=password,database='library')
cur=con.cursor()
cur.execute("Select count(*) from register where is_no={} ".format(iss))
data=cur.fetchall()
d=data[0][0]
con.close()
return d
#Function to check book with member.
def checki_book_member(iss):
con=sc.connect(host='localhost',user=username,passwd=password,database='library')
cur=con.cursor()
cur.execute("Select count(*) from register where id={} ".format(iss))
data=cur.fetchall()
d=data[0][0]
con.close()
return d
#Function to check availibity of a issue no.
def checkqty(bno):
con=sc.connect(host='localhost',user=username,passwd=password,database='library')
cur=con.cursor()
cur.execute("Select copy from book where bno={} ".format(bno))
data=cur.fetchone()
d=data[0]
con.close()
return d
#Function to register a book
def book():
os.system('cls')
ch='y'
while ch=='y' or ch=='Y':
con=sc.connect(host='localhost',database='library',user=username,password=password)
cur=con.cursor()
try:
os.system('cls')
print('************************************************************')
print('* Library Management System *')
print('************************************************************')
bno=int(input(" Enter Book No. \t\t\t: "))
bno=int("102"+str(bno))
while checkbook(bno):
print(" Entered Book No. already Exits ")
bno=int(input(" Enter Book No. \t\t\t: "))
bno=int("102"+str(bno))
bname=input(" Enter Book Name\t\t\t: ")
author=input(" Enter Author Name\t\t\t: ")
price=float(input(" Enter Book Price\t\t\t: "))
qty=int(input(" Enter Quantity \t\t\t: "))
cur.execute("insert into book(bno,bname,author,price,copy) values({},'{}','{}',{},{})".format(bno,bname,author,price,qty))
con.commit()
print('************************************************************')
print("\t\tBook Succesfully Registered")
print('************************************************************')
ch=input("\tDo you want to register another book?(y/n)")
con.close()
except:
print('************************************************************')
print("\t\tError!!!... during registering book.")
print('************************************************************')
ch=input("\tDo you want to try with another data?(y/n)")
#Function to register a member
def member():
os.system('cls')
ch='y'
while ch=='y' or ch=='Y':
con=sc.connect(host='localhost',database='library',user=username,password=password)
cur=con.cursor()
try:
os.system('cls')
print('************************************************************')
print('* Library Management System *')
print('************************************************************')
mno=int(input(" Enter Member No. \t\t\t: "))
mno=int("101"+str(mno))
while checkmember(mno):
print(" Entered Member No. already Exits ")
mno=int(input(" Enter Member No. \t\t\t: "))
mno=int("101"+str(mno))
name=input(" Enter Member Name\t\t\t: ")
mob=input(" Enter Mobile No. \t\t\t: ")
df=dt.date.today()
if df.month<10:
jdate=str(df.year)+"-0"+str(df.month)+"-"+str(df.day)
else:
jdate=str(df.year)+"-"+str(df.month)+"-"+str(df.day)
cur.execute("insert into member(id,name,join_date,mob) values({},'{}','{}','{}')".format(mno,name,jdate,mob))
con.commit()
print('************************************************************')
print("\t\tMember Registered Succesfully")
print('************************************************************')
ch=input("\tDo you want to register other member?(y/n)")
con.close()
except:
print('************************************************************')
print("\t\tError!!!... during Member Registration.")
print('************************************************************')
ch=input("\tDo you want to try with another data?(y/n)")
#Function to view issue a book
def register():
os.system('cls')
ch='y'
while ch=='y' or ch=='Y':
con=sc.connect(host='localhost',database='library',user=username,password=password)
cur=con.cursor()
try:
os.system('cls')
print('************************************************************')
print('* Library Management System *')
print('************************************************************')
ino=int(input(" Enter Issue No. \t\t\t: "))
ino=int("103"+str(ino))
while checkissue(ino):
print(" Entered Issue No. already Exits ")
ino=int(input(" Enter Issue No. \t\t\t: "))
ino=int("103"+str(ino))
bno=int(input(" Enter Book no.\t\t\t: "))
bno=int("102"+str(bno))
while checkbook(bno)==0 or checkqty(bno)==0:
print(" Entered Book no. not exits ")
bno=int(input(" Enter Book no.\t\t\t: "))
bno=int("102"+str(bno))
mno=int(input(" Enter Member No. \t\t\t: "))
mno=int("101"+str(mno))
while checkmember(mno)==0:
print(" Entered Member Not already Exits ")
mno=int(input(" Enter Member No. \t\t\t: "))
mno=int("101"+str(mno))
df=dt.date.today()
if df.month<10:
idate=str(df.year)+"-0"+str(df.month)+"-"+str(df.day)
else:
idate=str(df.year)+"-"+str(df.month)+"-"+str(df.day)
dew=input(" Enter Due date (yyyy-mm-dd) \t: ")
cur.execute("insert into register(is_no,bno,id,issue_date,dew_date) values({},{},{},'{}','{}')".format(ino,bno,mno,idate,dew))
con.commit()
cur.execute("update book set copy=copy-1 where bno={}".format(bno))
con.commit()
print('************************************************************')
print("\t\tBook Issued Succesfully")
print('************************************************************')
ch=input("\tDo you want to Issue more books?(y/n)")
con.close()
except:
print('************************************************************')
print("\t\tError!!!... during Issuing Book.")
print('************************************************************')
ch=input("\tDo you want to try with another data?(y/n)")
#Function to view member details
def view():
ch='y'
while ch=='y' or ch=='Y':
try:
con=sc.connect(host='localhost',database='library',user=username,password=password)
cur=con.cursor()
os.system('cls')
print('************************************************************')
print('* Library Management System *')
print('************************************************************')
mno=int(input(" Enter Member No. \t\t\t: "))
mno=int("101"+str(mno))
while checkmember(mno)==0:
print(" Entered Member Not Exits ")
mno=int(input(" Enter Member No. \t\t\t: "))
mno=int("101"+str(mno))
cur.execute("Select name,bname,issue_date,dew_date,return_date, mob from book b,register r,member m where b.bno=r.bno and m.id=r.id and m.id={}".format(mno))
data=cur.fetchone()
os.system('cls')
print('************************************************************')
print('* Member Details *')
print('************************************************************')
print(' Member No. : ',mno)
print(' Member Name : ',data[0])
print(' Book Name : ',data[1])
print(' Issue Date : ',data[2])
print(' Due Date : ',data[3])
print(' Return Date : ',data[4])
print(' Mobile : ',data[5])
print('************************************************************')
ch=input("\tDo you want to View another record?(y/n)")
con.close()
except:
print('************************************************************')
print("\t\tError!!!... during viewing.")
print('************************************************************')
ch=input("\tDo you want to try with another data?(y/n)")
#Function to view list of Book present in library
def list_all_book():
ch='y'
while ch=='y' or ch=='Y':
try:
con=sc.connect(host='localhost',database='library',user=username,password=password)
cur=con.cursor()
os.system('cls')
print('************************************************************')
print('* Library Management System *')
print('************************************************************')
cur.execute("Select bno,bname,copy from book ")
data=cur.fetchall()
os.system('cls')
print('************************************************************')
print('* List of Books *')
print('************************************************************')
print('\tBook No.\t Book Name\t\tQty')
print('------------------------------------------------------------')
print('\t',end="")
for row in data:
for d in row:
print(d,end='\t\t')
print()
if not row==data[-1]:
print('\t',end="")
print('************************************************************')
ch=input("Press any key to Continue...")
con.close()
except:
print('************************************************************')
print("\t\tError!!!... during Viewing.")
print('************************************************************')
ch=input("\tDo you want to try with another data?(y/n)")
#Function to view list of Registered members
def list_all_members():
ch='y'
while ch=='y' or ch=='Y':
try:
con=sc.connect(host='localhost',database='library',user=username,password=password)
cur=con.cursor()
os.system('cls')
print('************************************************************')
print('* Library Management System *')
print('************************************************************')
cur.execute("Select id,name,mob from member ")
data=cur.fetchall()
os.system('cls')
print('************************************************************')
print('* List of Members *')
print('************************************************************')
print('\tMember No.\t Member Name\t\tMobile')
print('------------------------------------------------------------')
print('\t',end="")
for row in data:
for d in row:
print(d,end='\t\t')
print()
if not row==data[-1]:
print('\t',end="")
print('************************************************************')
ch=input("Press any key to Continue...")
con.close()
except:
print('************************************************************')
print("\t\tError!!!... during Viewing.")
print('************************************************************')
ch=input("\tDo you want to try with another data?(y/n)")
#Function to view list of Book issued with member name
def list_all():
ch='y'
while ch=='y' or ch=='Y':
try:
con=sc.connect(host='localhost',database='library',user=username,password=password)
cur=con.cursor()
os.system('cls')
print('************************************************************')
print('* Library Management System *')
print('************************************************************')
cur.execute("Select is_no,name,bname,dew_date from book b,register r,member m where b.bno=r.bno and m.id=r.id")
data=cur.fetchall()
os.system('cls')
print('************************************************************')
print('* List of Books Issued *')
print('************************************************************')
print('\tIssue No. Member Name Book Name\tDue date')
print('------------------------------------------------------------')
print('\t',end="")
for row in data:
for d in row:
print(d,end='\t')
print()
if not row==data[-1]:
print('\t',end="")
print('************************************************************')
ch=input("Press any key to Continue...")
con.close()
except:
print('************************************************************')
print("\t\tError!!!... during Viewing.")
print('************************************************************')
ch=input("\tDo you want to try with another data?(y/n)")
#Function to Extend due Date
def extend():
ch='y'
while ch=='y' or ch=='Y':
try:
con=sc.connect(host='localhost',database='library',user=username,password=password)
cur=con.cursor()
os.system('cls')
print('************************************************************')
print('* Library Management System *')
print('************************************************************')
print('* *')
print('* 1. Extend Due date *')
print('* 2. Cancel Membership *')
print('* *')
print('************************************************************')
opt=int(input(' Enter Option :- '))
print('************************************************************')
if opt==1:
os.system('cls')
list_all()
ino=int(input(" Enter Issue No. \t\t\t: "))
ino=int("103"+str(ino))
while checkissue(ino)==0:
print(" Entered Issue No. not Exits ")
ino=int(input(" Enter Issue No. \t\t\t: "))
ino=int("103"+str(ino))
print('************************************************************')
dew=input("\t\tEnter new Due Date : ")
cur.execute("update register set dew_date='{}' where is_no={}".format(dew,ino))
con.commit()
print('************************************************************')
print("\t\tDue date Succesfully Extended")
print('************************************************************')
elif opt==2:
list_all_members()
mno=int(input(" Enter Member No. \t\t\t: "))
mno=int("101"+str(mno))
while checkmember(mno)==0:
print(" Entered Member Not Exits ")
mno=int(input(" Enter Member No. \t\t\t: "))
mno=int("101"+str(mno))
while checki_book_member(mno):
print('************************************************************')
print("\tBooks pending = ",checki_book_member(mno),"\n\tPlease Return all book First")
print('************************************************************')
input("Press any key to return books.")
ret_book()
cur.execute("delete from member where id={}".format(mno))
con.commit()
print('************************************************************')
print("\t\tMembership successfully cancelled")
print('************************************************************')
ch=input("\tDo you want to update anything else?(y/n)")
con.close()
except:
print('************************************************************')
print("\t\tError!!!... during updating.")
print('************************************************************')
ch=input("\tDo you want to try with another data?(y/n)")
#Function to Return a book
def ret_book():
ch='y'
while ch=='y' or ch=='Y':
try:
con=sc.connect(host='localhost',database='library',user=username,password=password)
cur=con.cursor()
os.system('cls')
list_all()
ino=int(input(" Enter Issue No. \t\t\t: "))
ino=int("103"+str(ino))
while checkissue(ino)==0:
print(" Entered Issue No. not Exits ")
ino=int(input(" Enter Issue No. \t\t\t: "))
ino=int("103"+str(ino))
cur.execute("update book set copy=copy+1 where bno in(select bno from register where is_no={})".format(ino))
con.commit()
cur.execute("delete from register where is_no={}".format(ino))
con.commit()
print('************************************************************')
print('* *')
print('* Book Returned Successfully *')
print('* *')
print('************************************************************')
ch=input("\tDo you want to return another book?(y/n)")
con.close()
except:
print('************************************************************')
print("\t\tError!!!... during returning book.")
print('************************************************************')
ch=input("\tDo you want to try with another data?(y/n)")
#Main
username = input("Enter your username: ")
password = input("Enter your password: ")
ch=1
while ch!=0 :
os.system('cls')
print('************************************************************')
print('* Library Management System *')
print('************************************************************')
print('* *')
print('* 1. Book Entry *')
print('* 2. Register Member *')
print('* 3. Issue Book *')
print('* 4. View Member issued Books *')
print('* 5. View All Books *')
print('* 6. View All Members *')
print('* 7. View All issued Books *')
print('* 8. Update details *')
print('* 9. Return Book *')
print('* 0. Exit *')
print('* *')
print('************************************************************')
ch=int(input(' Enter Option :- '))
if ch==1:
book()
elif ch==2:
member()
elif ch==3:
register()
elif ch==4:
view()
elif ch==5:
list_all_book()
elif ch==6:
list_all_members()
elif ch==7:
list_all()
elif ch==8:
extend()
elif ch==9:
ret_book()