图书管理系统
登录(加密)
import xlrd
from xlutils.copy import copy
impot hashlib
def login(username,password):
#读取excel信息
book = xlrd.open_workbook("book.xls")
sheet = book.sheet_by_name("user")
r = sheet.nrows
c = sheet.ncols
flag = False
'''
m--username的列下标
p--password的列下标
q--state的列下标
'''
m = 0
p = 0
q = 0
for j in range(c):
if sheet.cell(0,j).value == "username":
m = j
elif sheet.cell(0,j).value == "password":
p = j
elif sheet.cell(0,j).value == "state"
q = j
password = hashlib.md5(password.encode("utf-8")).hexdigest()
for i in range(1,r):
if sheet.cell(i,q).value == "0" and sheet.cell(i,m).value == username and sheet.cell(i,p).value == "password"
flag = True
break
return flag
信息查看
def showBooks():
book = xlrd.open_workbook("book.xls")
sheet = book.sheet_by_name("book")
r = sheet.nrows
c = sheet.ncols
q = 0
for j in range(c):
if sheet.cell(0,j).value == "state"
q = j
for i in range(1,r):
if sheet.cell(i,q).value == "1":
continue
for k in range(c):
if k=q:
continue
print(sheet.cell(i,k).value,end=" ")
print()
添加
def addBook(a):
book = xlrd.open_workbook("book.xls")
sheet = book.sheet_by_name("book")
r = sheet.nrows
c = sheet.ncols
book_copy = copy(book)
sheet_copy = book_copy.get_sheet(1)
for i in range(c)
try:
sheet_copy.right(r,i,a[i])
except:
break
book_copy.save("book.xls")
修改
def updateBook(a):
book = xlrd.open_workbook("book.xls")
sheet = book,sheet_by_name("book")
r = sheet.nrows
c = sheet.ncols
book_copy = copy(book)
sheet_copy = book_copy.get_sheet(1)
cr = 0
for i in range(r):
if sheet.cell(i,0).value==a[0]:
cr = i
break
for i in range(r):
try:
sheet_copy.write(cr,i,a[i])
except:
break
book_copy.save("book.xls")
删除
def deleteBook(id):
book = xlrd.open_workbook("book.xls")
sheet = book.sheet_yb_name("book")
r = sheet.nrows
c = sheet.ncols
book_copy = copy(book)
sheet_copy = book_copy.get_sheet(1)
cr = 0
for i in range(r):
if sheet.cell(i,0).value == id:
cr = i
break
sheet_copy.write(cr,c-1,"1")
book_copy.save("book.xls")
附录asd(secert)
import hashlib
password = hashlib.md5("password".encode("utf-8")).hexdigest()
print(password)
test.py 单开一个文件
import five as book
import hashlib
import xlrd
from xlutils import copy
print("======欢迎登陆图书管理系统========")
count = 0
while count < 3
username = input("请输入用户名")
password = input("请输入密码")
result = book.login(username,password)
if result:
#显示增删改查操作
print("1--查看图书信息")
print("2--添加图书信息")
print("3--修改图书信息")
print("4--删除图书信息")
op = input("请输入操作编号")
if op=="1":
book.showBooks()
break
elif op=="2":
a = input("请输入图书编号:")
b= input("请输入图书名字:")
c = input("请输入图书出版社:")
d= input("请输入图书价格:")
e = input("请输入图书作者:")
book_ = [a,b,c,d,e,"0"]
book.addBook(book_)
break
elif op=="3":
a = input("请输入图书编号:")
b= input("请输入图书名字:")
c = input("请输入图书出版社:")
d= input("请输入图书价格:")
e = input("请输入图书作者:")
book_ = [a,b,c,d,e,"0"]
book.addBook(book_)
break
elif op=="4"
id = input("请输入图书编号")
book.deleteBook(id)
break
else:
print("请输入正确编号")
print("===============%s==========="%"end")
else:
print("用户名或密码错误")
count += 1
if count ==3:
book = xlrd.open_workbook("book.xls")
sheet = book.sheet_by_name("user")
r = sheet.nrows
c = sheet.ncols
book_copy = .copy(book)
sheet_copy = book_copy.get_sheet(0)
for i in range(r):
if sheet.cell(i,1).value==username:
sheet_copy.write(i,3,"1")
break
book_copy.save("book.xls")