1 Star 0 Fork 0

fanyangchu/PythonCode

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
bookstore_manangement_system.py 23.78 KB
一键复制 编辑 原始数据 按行查看 历史
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342
import os
import mysql.connector as mys
mycon=mys.connect(host='localhost',user='root',passwd='Yksrocks',database='book_store_management')
if mycon.is_connected():
print()
print('successfully connected')
mycur=mycon.cursor()
def DBZ():
# IF NO. OF BOOKS IS ZERO(0) THAN DELETE IT AUTOMATICALLY
display="select * from books"
mycur.execute(display)
data2=mycur.fetchall()
for y in data2:
if y[6]<=0:
delete="delete from books where Numbers_of_book<=0"
mycur.execute(delete)
mycon.commit()
def separator():
print()
print("\t\t========================================")
print()
def end_separator():
print()
print()
def login():
user_name=input(" USER NAME --- ")
passw=input(" PASSWORD --- ")
display='select * from login'
mycur.execute(display)
data2=mycur.fetchall()
for y in data2:
if y[1]==user_name and y[2]==passw:
pass
else:
separator()
print(" Username or Password is Incorrect Try Again")
separator()
user_name=input(" USER NAME --- ")
passw=input(" PASSWORD --- ")
if y[1]==user_name and y[2]==passw:
pass
else:
separator()
print(" Username or Password is Again Incorrect")
exit()
def ViewAll():
print("\u0332".join("BOOK NAMES~~"))
print("------------------------------------")
display='select * from books'
mycur.execute(display)
data2=mycur.fetchall()
c=0
for y in data2:
c=c+1
print(c,"-->",y[1])
def CNB1():
if y[6]==0:
separator()
print(" NOW THIS BOOK IS NOT AVAILABLE ")
elif y[6]>0 and y[6]<=8:
separator()
print("WARNING!!!!!!!!!!!!!!!!!!!!!!!")
print("NO. OF THIS BOOK IS LOW","\tONLY",y[6]-1,"LEFT")
print()
print()
elif y[6]>8:
separator()
print("NO. OF BOOKS LEFT IS ",y[6]-1)
print()
print()
def CNB2():
if y[6]<=8:
separator()
print("WARNING!!!!!!!!!!!!!!!!!!!!!!!")
print("NO. OF THIS BOOK IS LOW","\tONLY",y[6],"LEFT")
else:
separator()
print("NO. OF BOOKS LEFT IS ",y[6])
separator()
# LOGIN
display12='select * from visit'
mycur.execute(display12)
data2222=mycur.fetchall()
for m in data2222:
if m[0]==0:
c=m[0]
display11='select * from login'
mycur.execute(display11)
data222=mycur.fetchall()
if c==0:
if c==0:
print("\t\t\t\t REGESTER ")
print("\t\t\t\t----------------------------")
print()
print()
user_name=input("ENTER USER NAME -- ")
passw=input("ENTER PASSWORD limit 8-20 -- ")
lenght=len(passw)
if lenght>=8 and lenght<=20:
c=c+1
insert55=(c,user_name,passw)
insert22="insert into login values(%s,%s,%s)"
mycur.execute(insert22,insert55)
mycon.commit()
separator()
login()
else:
if lenght<8:
separator()
print(" Password Is less than 8 Characters Enter Again")
separator()
user_name2=input("ENTER USER NAME -- ")
passw2=input("ENTER PASSWORD AGAIN (limit 8-20) -- ")
lenght1=len(passw2)
if lenght1>=8 and lenght1<=20:
c=c+1
insert555=(c,user_name2,passw2)
insert222="insert into login values(%s,%s,%s)"
mycur.execute(insert222,insert555)
mycon.commit()
separator()
login()
elif lenght>20:
separator()
print(" Password Is Greater than 20 Characters Enter Again")
separator()
user_name=input("ENTER USER NAME -- ")
passw=input("ENTER PASSWORD AGAIN (limit 8-20) -- ")
lenght=len(passw)
if lenght>=8 and lenght>=20:
c=c+1
insert55=(c,user_name,passw)
insert22="insert into login values(%s,%s,%s)"
mycur.execute(insert22,insert55)
mycon.commit()
separator()
login()
update33="update visit set visits=%s"%(c)
mycur.execute(update33)
mycon.commit()
elif m[0]==1:
if m[0]==1:
login()
separator()
DBZ()
# REPETITION
a=True
while a==True:
# PROGRAM STARTED
print(" *TO VIEW ALL ENTER 1")
print(" *TO SEARCH and BUY BOOK ENTER 2")
print(" *TO ADD BOOK ENTER 3")
print(" *TO UPDATE ENTER 4")
print(" *TO DELETE BOOK ENTER 5")
print(" *TO CLOSE ENTER 6")
print()
choice=int(input("ENTER YOUR CHOICE -- "))
separator()
#VIEW
if choice==1:
print()
ViewAll()
separator()
rep=input("Do You Want To Restart ?? yes / no -- ").lower()
if rep=="yes":
end_separator()
separator()
DBZ()
continue
else:
end_separator()
DBZ()
os._exit(0)
end_separator()
#SEARCH / BUY
if choice==2:
book_name=input("ENTER BOOK NAME ---- ")
separator()
display="select * from books where Name='%s'"%(book_name)
mycur.execute(display)
data2=mycur.fetchone()
if data2!=None:
print("BOOK IS AVAILABLE")
#BUY OR NOT
separator()
print("\t*WANT TO BUY PRESS 1")
print("\t*IF NOT PRESS 2")
print()
choice2=int(input("ENTER YOUR CHOICE -- "))
if choice2==1:
#BUY 1 OR MORE
separator()
print("\t*IF YOU WANT ONE BOOK PRESS 1")
print("\t*IF YOU WANT MORE THAN ONE BOOK PRESS 2")
print()
choice3=int(input("ENTER YOUR CHOICE -- "))
if choice3==1:
display='select * from books'
mycur.execute(display)
data2=mycur.fetchall()
for y in data2:
if y[1]==book_name:
if y[6]>0:
separator()
u="update books set Numbers_of_book=Numbers_of_book - 1 where name='%s';"%(book_name)
mycur.execute(u)
mycon.commit()
print("BOOK WAS BOUGHT")
separator()
print("THANKS FOR COMING")
CNB1()
separator()
rep=input("Do You Want To Restart ?? yes / no -- ").lower()
if rep=="yes":
end_separator()
separator()
DBZ()
continue
else:
end_separator()
DBZ()
os._exit(0)
if choice3==2:
separator()
wb=int(input("ENTER NO. OF BOOKS -- "))
separator()
display='select * from books'
mycur.execute(display)
data2=mycur.fetchall()
for y in data2:
if y[1]==book_name:
if wb>y[6]:
if y[6]>0:
print("YOU CAN'T BUT THAT MUCH BOOKS")
separator()
print("BUT YOU CAN BUY",y[6],"BOOKS MAX")
separator()
choice44=input("DO YOU WANT TO BUY BOOK ? Y/N -- ")
separator()
k=y[6]
if choice44=="y" or choice44=="Y":
u2="update books set numbers_of_book=numbers_of_book -%s where name='%s'"%(k,book_name)
mycur.execute(u2)
mycon.commit()
print("BOOK WAS BOUGHT")
separator()
print("THANKS FOR COMING")
separator()
display='select * from books'
mycur.execute(display)
data2=mycur.fetchall()
for y in data2:
if y[1]==book_name:
if y[6]<=8:
print("WARNING!!!!!!!!!!!!!!!!!!!!!!!")
print("NO. OF THIS BOOK IS LOW","\tONLY",y[6],"LEFT")
end_separator()
break
separator()
rep=input("Do You Want To Restart ?? yes / no -- ").lower()
if rep=="yes":
end_separator()
separator()
DBZ()
continue
else:
end_separator()
DBZ()
os._exit(0)
elif choice44=="n" or choice44=="N":
print("SORRY FOR INCONVENIENCE WE WILL TRY TO FULLFILL YOUR REQUIREMENT AS SOON AS POSSIBLE")
end_separator()
separator()
rep=input("Do You Want To Restart ?? yes / no -- ").lower()
if rep=="yes":
separator()
DBZ()
continue
else:
end_separator()
DBZ()
os._exit(0)
elif y[6]==0:
print("SORRY NO BOOK LEFT WE WILL TRY TO FULLFILL YOUR REQUIREMENT AS SOON AS POSSIBLE")
end_separator()
separator()
rep=input("Do You Want To Restart ?? yes / no -- ").lower()
if rep=="yes":
separator()
DBZ()
continue
else:
end_separator()
DBZ()
os._exit(0)
else:
u2="update books set numbers_of_book=numbers_of_book -%s where name='%s'"%(wb,book_name)
mycur.execute(u2)
mycon.commit()
print("BOOK WAS BOUGHT")
separator()
print("THANKS FOR COMING")
display='select * from books'
mycur.execute(display)
data2=mycur.fetchall()
for y in data2:
if y[1]==book_name:
CNB2()
separator()
rep=input("Do You Want To Restart ?? yes / no -- ").lower()
if rep=="yes":
separator()
DBZ()
continue
else:
end_separator()
DBZ()
os._exit(0)
else:
separator()
print("NO BOOK IS BOUGHT")
end_separator()
separator()
rep=input("Do You Want To Restart ?? yes / no -- ").lower()
if rep=="yes":
separator()
DBZ()
continue
else:
end_separator()
DBZ()
os._exit(0)
else:
separator()
print("SORRY NO BOOK WITH THIS NAME EXIST / NAME IS INCORRECT")
end_separator()
separator()
rep=input("Do You Want To Restart ?? yes / no -- ").lower()
if rep=="yes":
separator()
DBZ()
continue
else:
end_separator()
DBZ()
os._exit(0)
# ADDING BOOK
if choice==3:
q10=int(input("ENTER NO. OF BOOKS TO ADD -- "))
separator()
for k in range(q10):
SNo10=int(input("ENTER SNo OF BOOK -- "))
name10=input("ENTER NAME OF BOOK --- ")
author10=input("ENTER NAME OF AUTHOR -- ")
year10=int(input("ENTER YEAR OF PUBLISHING -- "))
ISBN10=input("ENTER ISBN OF BOOK -- ")
price10=int(input("ENTER PRICE OF BOOK -- "))
nob10=int(input("ENTER NO. OF BOOKS -- "))
display10="select * from books where ISBN='%s'"%(ISBN10)
mycur.execute(display10)
data20=mycur.fetchone()
if data20!=None:
print("This ISBN Already Exists")
os._exit(0)
else:
insert=(SNo10,name10,author10,year10,ISBN10,price10,nob10)
insert20="insert into books values(%s,%s,%s,%s,%s,%s,%s)"
mycur.execute(insert20,insert)
mycon.commit()
separator()
print("BOOK IS ADDED")
separator()
rep=input("Do You Want To Restart ?? yes / no -- ").lower()
if rep=="yes":
separator()
DBZ()
continue
else:
end_separator()
DBZ()
os._exit(0)
# UPDATING BOOK
if choice==4:
choice4=input("ENTER ISBN OF BOOK -- ")
separator()
display="select * from books where ISBN='%s'"%(choice4)
mycur.execute(display)
data2=mycur.fetchone()
if data2!=None:
SNo1=int(input("ENTER NEW SNo OF BOOK -- "))
name1=input("ENTER NEW NAME OF BOOK --- ")
author1=input("ENTER NEW NAME OF AUTHOR -- ")
year1=int(input("ENTER NEW YEAR OF PUBLISHING -- "))
ISBN1=input("ENTER NEW ISBN OF BOOK -- ")
price1=int(input("ENTER NEW PRICE OF BOOK -- "))
nob=int(input("ENTER NEW NO. OF BOOKS -- "))
insert=(SNo1,name1,author1,year1,ISBN1,price1,nob,choice4)
update="update books set SNo=%s,Name=%s,Author=%s,Year=%s,ISBN=%s,Price=%s,numbers_of_book=%s where ISBN=%s"
mycur.execute(update,insert)
mycon.commit()
separator()
print("BOOK IS UPDATED")
separator()
rep=input("Do You Want To Restart ?? yes / no -- ").lower()
if rep=="yes":
separator()
DBZ()
continue
else:
end_separator()
DBZ()
os._exit(0)
else:
print("SORRY NO BOOK WITH THIS ISBN IS EXIST / INCORRECT ISBN")
print()
print()
separator()
rep=input("Do You Want To Restart ?? yes / no -- ").lower()
if rep=="yes":
separator()
DBZ()
continue
else:
end_separator()
DBZ()
os._exit(0)
# DELETING A BOOK
if choice==5:
ISBN1=input("ENTER ISBN OF THAT BOOK THAT YOU WANT TO DELETE -- ")
display="select * from books where ISBN='%s'"%(ISBN1)
mycur.execute(display)
data2=mycur.fetchone()
if data2!=None:
separator()
choice5=input("ARE YOU SURE TO DELETE THIS BOOK ENTER Y/N -- ")
if choice5=='Y' or choice5=='y':
separator()
ISBN2=input("PLEASE ENTER ISBN AGAIN -- ")
delete="delete from books where ISBN='%s'"%(ISBN2)
mycur.execute(delete)
mycon.commit()
separator()
print("BOOK IS DELETED")
print()
print()
separator()
rep=input("Do You Want To Restart ?? yes / no -- ").lower()
if rep=="yes":
separator()
DBZ()
continue
else:
end_separator()
DBZ()
os._exit(0)
else:
separator()
print("NO BOOK IS DELETED")
print()
print()
separator()
rep=input("Do You Want To Restart ?? yes / no -- ").lower()
if rep=="yes":
separator()
DBZ()
continue
else:
end_separator()
DBZ()
os._exit(0)
else:
separator()
print("SORRY NO BOOK WITH THIS ISBN AVAILABLE / ISBN IS INCORRECT")
print()
print()
separator()
rep=input("Do You Want To Restart ?? yes / no -- ").lower()
if rep=="yes":
separator()
DBZ()
continue
else:
end_separator()
DBZ()
os._exit(0)
# CLOSE
if choice==6:
exit()
os._exit(0)
# IF NO. OF BOOKS IS ZERO( 0 ) THAN DELETE IT AUTOMATICALLY
display="select * from books"
mycur.execute(display)
data2=mycur.fetchall()
for y in data2:
if y[6]<=0:
delete="delete from books where Numbers_of_book<=0"
mycur.execute(delete)
mycon.commit()
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/fanych/pythoncode.git
git@gitee.com:fanych/pythoncode.git
fanych
pythoncode
PythonCode
master

搜索帮助