This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
importpymysql
importlogging
defAddCard(conn,CardNum,Name,Dept,Type,flag):
#既可以增加借书证,也可以修改原借书证信息
#具体可以参考图书入库部分
#flag=0代表增加,flag=1代表修改
#修改功能是为了考虑到可能会更改单位之类的(比如转专业?)
ifCardNum==""orName==""orDept==""orType=="":
return"不能有空项"
try:
cursor=conn.cursor()
sql="select * from card where cnum=%s"
cursor.execute(sql,CardNum)
result=cursor.fetchone()
#首先排除两个特殊情况:增加一个已经存在的证,或者是修改一个不存在的证
ifresultisNone:
ifflag==1:
return"借书证不存在,修改失败"
elifflag==0:
return"此借书证已存在,增加失败"
ifflag==0:
sql="insert into card values(%s,%s,%s,%s,0)"
cursor.execute(sql,(CardNum,Name,Dept,Type))
conn.commit()
return1
else:
sql="update card set name=%s,department=%s,type=%s where cnum=%s"