first commit

main
library 9 months ago
parent 2c920f7302
commit 00d37404ff

@ -0,0 +1,6 @@
<component name="InspectionProjectProfileManager">
<settings>
<option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" />
</settings>
</component>

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="JavaScriptSettings">
<option name="languageLevel" value="ES6" />
</component>
</project>

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/source.iml" filepath="$PROJECT_DIR$/.idea/source.iml" />
</modules>
</component>
</project>

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

@ -0,0 +1,90 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="AutoImportSettings">
<option name="autoReloadType" value="SELECTIVE" />
</component>
<component name="ChangeListManager">
<list default="true" id="524e6a15-350a-49b7-b484-2e720c0b95ac" name="默认更改列表" comment="" />
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
<option name="LAST_RESOLUTION" value="IGNORE" />
</component>
<component name="ProjectColorInfo">{
&quot;associatedIndex&quot;: 5
}</component>
<component name="ProjectId" id="2Hr89HCpuuDcasMOCjPqzTt5XdN" />
<component name="ProjectViewState">
<option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" />
<option name="showMembers" value="true" />
</component>
<component name="PropertiesComponent">{
&quot;keyToString&quot;: {
&quot;Python.Gui.executor&quot;: &quot;Run&quot;,
&quot;RunOnceActivity.ShowReadmeOnStart&quot;: &quot;true&quot;
}
}</component>
<component name="RecentsManager">
<key name="CopyFile.RECENT_KEYS">
<recent name="D:\新的U盘文件备份\U盘文件--备份--专升本\专升本大三(下)用这个\Python\项目-疫苗管理系统+图书管理系统\python-mysql-book-management-system-master\source" />
</key>
</component>
<component name="RunManager">
<configuration name="Gui" type="PythonConfigurationType" factoryName="Python" nameIsGenerated="true">
<module name="source" />
<option name="ENV_FILES" value="" />
<option name="INTERPRETER_OPTIONS" value="" />
<option name="PARENT_ENVS" value="true" />
<envs>
<env name="PYTHONUNBUFFERED" value="1" />
</envs>
<option name="SDK_HOME" value="E:\Python installation package\python-3.7.2\python.exe" />
<option name="SDK_NAME" value="Python 3.11 (aa)" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$" />
<option name="IS_MODULE_SDK" value="false" />
<option name="ADD_CONTENT_ROOTS" value="true" />
<option name="ADD_SOURCE_ROOTS" value="true" />
<EXTENSION ID="PythonCoverageRunConfigurationExtension" runner="coverage.py" />
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/Gui.py" />
<option name="PARAMETERS" value="" />
<option name="SHOW_COMMAND_LINE" value="false" />
<option name="EMULATE_TERMINAL" value="false" />
<option name="MODULE_MODE" value="false" />
<option name="REDIRECT_INPUT" value="false" />
<option name="INPUT_FILE" value="" />
<method v="2" />
</configuration>
</component>
<component name="SharedIndexes">
<attachedChunks>
<set>
<option value="bundled-python-sdk-0509580d9d50-746f403e7f0c-com.jetbrains.pycharm.community.sharedIndexes.bundled-PC-241.14494.241" />
</set>
</attachedChunks>
</component>
<component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="应用程序级" UseSingleDictionary="true" transferred="true" />
<component name="SvnConfiguration">
<configuration />
</component>
<component name="TaskManager">
<task active="true" id="Default" summary="Default task">
<changelist id="524e6a15-350a-49b7-b484-2e720c0b95ac" name="默认更改列表" comment="" />
<created>1669031689251</created>
<option name="number" value="Default" />
<option name="presentableId" value="Default" />
<updated>1669031689251</updated>
<workItem from="1669031692615" duration="61000" />
<workItem from="1670304357003" duration="2021000" />
<workItem from="1684138334196" duration="340000" />
</task>
<servers />
</component>
<component name="TypeScriptGeneratedFilesManager">
<option name="version" value="1" />
</component>
<component name="com.intellij.coverage.CoverageDataManagerImpl">
<SUITE FILE_PATH="coverage/source$Gui.coverage" NAME="Gui Coverage Results" MODIFIED="1670306212008" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$" />
<SUITE FILE_PATH="coverage/book_management_system$Gui.coverage" NAME="Gui Coverage Results" MODIFIED="1684138443310" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$" />
</component>
</project>

@ -0,0 +1,123 @@
import pymysql
import logging
def AddOne(conn,BookNum,ClassOfBook,BookName,Publisher,Year,Author,Price,flag,num):
cursor=conn.cursor()
try:
#获取total
sql="select total from book"
if(BookNum=="" or ClassOfBook=="" or BookName=="" or Publisher=="" or Year=="" or Author=="" or Price==""):
return "不能有空项"
Year=int(Year)
Price=float(Price)
cursor.execute(sql)
total=cursor.fetchone()
if total is None:#目前还没有书total为0
total=0
else:
total=total[0]
#获取collection
sql="select collection from book where bnum=%s"
cursor.execute(sql,BookNum)
collection=cursor.fetchone()
except Exception as e:
conn.rollback()
logging.exception(e)
return e
if collection is None:#书不存在,新增添一条记录
if(flag==1):#试图在书不存在的情况下直接修改信息,操作失败
return "此书尚未被收录,修改失败"
collection=num
total+=num
sql="insert into book values(%s,%s,%s,%s,%s,%s,%s,%s,%s)"
try:
cursor.execute(sql,(BookNum,ClassOfBook,BookName,Publisher,Year,Author,Price,total,collection))
sql="update book set total=%s"
cursor.execute(sql,(total))
conn.commit()
return (total,collection)
except Exception as e:
logging.exception(e)
conn.rollback()
return e
else: #书已经存在根据flag修改信息或者是增加一本
collection=collection[0]
try:
old_sql="select bnum,bclass,bname,publisher,year,author,price from book where bnum=%s"
cursor.execute(old_sql,BookNum)
old_record=cursor.fetchone() #取出原记录
sql="update book set bclass=%s,bname=%s,publisher=%s,year=%s,author=%s,price=%s where bnum=%s"#在事务内更新记录,然后再读取出来
cursor.execute(sql ,(ClassOfBook,BookName,Publisher,Year,Author,Price,BookNum))
new_sql="select bnum,bclass,bname,publisher,year,author,price from book where bnum=%s"
cursor.execute(new_sql ,BookNum)
new_record=cursor.fetchone() #取出新记录
if flag==0:#不修改,只添加
#比对新老两条记录,如果一样则把数量加一,不一样则报错
if old_record==new_record:
total+=num
collection+=num
sql="update book set total=%s,collection=%s where bnum=%s"
cursor.execute(sql ,(total,collection,BookNum))
sql="update book set total=%s"
cursor.execute(sql ,(total))
conn.commit()
return (total,collection)
else:
#应该会报错
conn.rollback()
return "与记录中信息不一致!"
else:
#要修改信息了
conn.commit()
return "修改成功"
except Exception as e:
logging.exception(e)
conn.rollback()
return e
def AddBatch(conn,file_addr):
success_cnt=0
fail_cnt=0
succeed_list=[]
fail_list=[]
try:
with open(file_addr,"r",encoding="utf8") as f:
for line in f.readlines():
str1=line.strip('\n')#用来添加到列表里,保持原始格式
str2=line.strip('()\n').split(',')#用来取出各个属性值
if len(str2)!=8:
fail_list.append(str1)
break
BookNum=str2[0].strip()
ClassOfBook=str2[1].strip()
BookName=str2[2].strip()
Publisher=str2[3].strip()
Year=int(str2[4].strip())
Author=str2[5].strip()
Price=float(str2[6].strip())
num=int(str2[7].strip())
result=AddOne(conn,BookNum,ClassOfBook,BookName,Publisher,Year,Author,Price,0,num)
if type(result)==type(()):
succeed_list.append(str1)
success_cnt+=num
else:
fail_list.append(str1)
fail_cnt+=num
with open("succeed_log.txt","a") as s_f:
for line in succeed_list:
s_f.write(line)
s_f.write("\n")
return (len(succeed_list),success_cnt,len(fail_list),fail_cnt,fail_list)
except Exception as e:
logging.exception(e)
return e

@ -0,0 +1,92 @@
import pymysql
import logging
import datetime
def ShowList(conn,CardNum):
if(CardNum==""):
return "借书证号不能为空"
try:
cursor=conn.cursor()
sql="select * from card where cnum=%s"
cursor.execute(sql,CardNum)
result=cursor.fetchone()
#要看输入的卡号是不是有效的
if result is None:
return "无效的借书证号"
sql="select bnum,bname,btime,rtime,times from book natural join borrow where cnum=%s"
cursor.execute(sql,CardNum)
result=cursor.fetchall()
return result
except Exception as e:
logging.exception(e)
return e
def Borrow(conn,CardNum,BookNum):
if(CardNum=="" or BookNum==""):
return "不能为空"
try:
cursor=conn.cursor()
sql="select times,rtime from borrow where cnum=%s and bnum=%s"
cursor.execute(sql,(CardNum,BookNum))
times=cursor.fetchone()
if times is None:
pass
elif times[0]==1:
r_time=times[1]
r_time=r_time+datetime.timedelta(days=30)
r_time=r_time.strftime("%Y-%m-%d %H:%M:%S")
sql="update borrow set times=0,rtime=%s where cnum=%s and bnum=%s"
cursor.execute(sql,(r_time,CardNum,BookNum))
conn.commit()
return (1,r_time)
elif times[0]==0:
return "续借次数已达上限"
#前面要判断是否是续借,允许续借一次
#判断完不是续借之后,还要判断是否借书数量已经达到上限
sql="select numbers from card where cnum=%s"
cursor.execute(sql,CardNum)
result=cursor.fetchone()
if result[0]>=10:
return "借书数量超出上限"
else:
numbers=result[0]+1
#
sql="select bname,collection from book where bnum=%s"
cursor.execute(sql,BookNum)
result=cursor.fetchone()
#此处的判断逻辑其实不是很好。。。先判断了是否超出上限,再判断的书是否存在。可能会导致用户为了借一本不存在的书,先去还书,回来才发现根本没有这本书
if result is None:
return "借书失败,书号不存在"
if result[1]!=0:
#借书成功
bname=result[0]
collection=result[1]-1
sql="update book set collection=%s where bnum=%s"
cursor.execute(sql,(collection,BookNum))
b_time= datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
r_time=(datetime.datetime.now()+datetime.timedelta(days=30)).strftime("%Y-%m-%d %H:%M:%S")
sql="insert into borrow values(%s,%s,%s,%s,1)"
cursor.execute(sql,(CardNum,BookNum,b_time,r_time))
sql="update card set numbers=%s where cnum=%s"
cursor.execute(sql,(numbers,CardNum))
conn.commit()
return (0,r_time,bname)
else:
#借书失败,因为库存不足
#关于如何返回最早的还书时间这一点明天再说
#查到的方法中最起码可以把两个表join然后比较
#但是我比较想用聚合函数来做因为简单datatime类型的数据不知道能不能用聚合函数答案是能
sql="select min(rtime) from borrow where bnum=%s"
cursor.execute(sql,BookNum)
result=cursor.fetchone()
r_time=result[0]
r_time=r_time.strftime('%Y-%m-%d %H:%M:%S')
return (2,r_time)
except Exception as e:
logging.exception(e)
conn.rollback()
return e

@ -0,0 +1,54 @@
import pymysql
import logging
def AddCard(conn,CardNum,Name,Dept,Type,flag):
#既可以增加借书证,也可以修改原借书证信息
#具体可以参考图书入库部分
#flag=0代表增加flag=1代表修改
#修改功能是为了考虑到可能会更改单位之类的(比如转专业?)
if CardNum=="" or Name=="" or Dept=="" or Type=="":
return "不能有空项"
try:
cursor=conn.cursor()
sql="select * from card where cnum=%s"
cursor.execute(sql,CardNum)
result=cursor.fetchone()
#首先排除两个特殊情况:增加一个已经存在的证,或者是修改一个不存在的证
if result is None :
if flag==1:
return "借书证不存在,修改失败"
elif flag==0:
return "此借书证已存在,增加失败"
if flag==0:
sql="insert into card values(%s,%s,%s,%s,0)"
cursor.execute(sql,(CardNum,Name,Dept,Type))
conn.commit()
return 1
else:
sql="update card set name=%s,department=%s,type=%s where cnum=%s"
cursor.execute(sql,(Name,Dept,Type,CardNum))
conn.commit()
return 2
except Exception as e:
conn.rollback()
return e
def DeleteCard(conn,CardNum):
if CardNum=="":
return "卡号不能为空"
try:
cursor=conn.cursor()
sql="select * from card where cnum=%s"
cursor.execute(sql,CardNum)
result=cursor.fetchone()
if result is None:
return "借书证不存在"
sql="delete from card where cnum=%s"
cursor.execute(sql,CardNum)
conn.commit()
return 1
except Exception as e:
conn.rollback()
return e

@ -0,0 +1,825 @@
class basedesk():
def __init__(self,master):
self.root=master
self.root.title('图书管理系统')
self.root.geometry('1000x700')
initwin(self.root)
class initwin(): #主窗口
def __init__(self,master):
global im
global image
self.master=master
self.master.config(bg='Magenta')
self.initwin=tk.Frame(self.master,)
self.initwin.pack()
self.canvas = tk.Canvas(self.initwin,
width = 1000,
height = 700,
bg = 'green')
image=Image.open('bg.jpg')
im=ImageTk.PhotoImage(image)
self.canvas.create_image(0,0,anchor='nw',image = im) # 使用create_image将图片添加到Canvas组件中
self.canvas.pack() # 将Canvas添加到主窗口
btn_add=ttk.Button(self.initwin,text="图书入库或修改信息",command=self.add)
btn_query=ttk.Button(self.initwin,text="查询图书信息",command=self.query)
btn_card=ttk.Button(self.initwin,text="借书证管理",command=self.card)
btn_borrow=ttk.Button(self.initwin,text="借书",command=self.borrow)
btn_return=ttk.Button(self.initwin,text="还书",command=self.returnbook)#return是保留字。。。
self.canvas.create_window(100,50,width=200,height=40,window=btn_add)
self.canvas.create_window(100,100,width=200,height=40,window=btn_query)
self.canvas.create_window(100,250,width=200,height=40,window=btn_card)
self.canvas.create_window(100,150,width=200,height=40,window=btn_borrow)
self.canvas.create_window(100,200,width=200,height=40,window=btn_return)
self.title=tk.Label(self.initwin,text="图书管理系统",font=("宋体",30))
self.canvas.create_window(400,150,anchor="nw",width=300,height=70,window=self.title)
def add(self,): #add窗口实现的功能选择批量入库或者单本入库添加或是修改
self.initwin.destroy()
addwin(self.master)
def query(self):
self.initwin.destroy()
querywin(self.master)
def card(self):
self.initwin.destroy()
cardwin(self.master)
def borrow(self):
self.initwin.destroy()
borrowwin(self.master)
def returnbook(self):
self.initwin.destroy()
returnwin(self.master)
class addwin():
def __init__(self,master):
global im
global image
self.master=master
self.master.config(bg='GhostWhite')
self.str="此处输出状态信息"
self.addwin=tk.Frame(self.master,)
self.addwin.pack()
self.canvas = tk.Canvas(self.addwin,
width = 1000,
height = 700,
bg = 'white')
image=Image.open('bg.jpg')
im=ImageTk.PhotoImage(image)
self.canvas.create_image(0,0,anchor='nw',image = im) # 使用create_image将图片添加到Canvas组件中
self.canvas.pack() # 将Canvas添加到窗口
self.btn_back=ttk.Button(self.addwin,text="返回主菜单",command=self.back)
#btn_back.pack()
self.canvas.create_window(100,50,width=200,height=40,window=self.btn_back)
self.mode=tk.IntVar() #选择入库模式(单本或者批量)
self.style_radio=ttk.Style()
self.style_radio.configure("radio.TRadiobutton",font=("微软雅黑",12),background="Aqua")
self.r1=ttk.Radiobutton(self.addwin,text="单本入库(或修改信息)",variable=self.mode,value=1,command=self.display1,style="radio.TRadiobutton")
self.r2=ttk.Radiobutton(self.addwin,text="批量入库",variable=self.mode,value=2,command=self.display2,style="radio.TRadiobutton")
self.canvas.create_window(400,50,window=self.r1)
self.canvas.create_window(400,100,window=self.r2)
self.style_label=ttk.Style()
self.style_label.configure("label.TLabel",font=("微软雅黑",14))
self.s_title=ttk.Label(self.addwin,text="状态栏",style="label.TLabel", width=30,anchor="center")
self.state=tk.Message(self.addwin,text=self.str,width=300,font=("微软雅黑",12))
self.canvas.create_window(800,100,height=50,window=self.s_title)
self.canvas.create_window(650,150,anchor="nw",width=300,window=self.state)
self.flag1=0#标记“批量入库”的控件是否存在的flag
self.flag2=0#标记“单本入库”的控件是否存在的flag
self.cflag=0#change flag,用来区分是添加一本书还是修改书的信息.为1时代表修改
def display2(self,):
if(self.flag2==1):
self.bnum_prom.destroy()
self.cob_prom.destroy()
self.bname_prom.destroy()
self.pub_prom.destroy()
self.y_prom.destroy()
self.auth_prom.destroy()
self.pri_prom.destroy()
self.btn_conf2.destroy()
self.btn_conf3.destroy()
self.bnum_input.destroy()
self.cob_input.destroy()
self.bname_input.destroy()
self.pub_input.destroy()
self.y_input.destroy()
self.auth_input.destroy()
self.pri_input.destroy()
self.flag2=0
if(self.flag1==1):
return
self.f_prom=ttk.Label(self.addwin,text="请输入文件名字:",font=('微软雅黑', 12), width=70, style="label.TLabel",anchor="center")
self.f_input=tk.Entry(self.addwin,show=None,font=("微软雅黑",14))
self.btn_conf1=ttk.Button(self.addwin,text="确认",command=self.onclick1)####此处不输入直接点击会有bug
self.flag1=1#(用来记录是否创建f_input)
self.canvas.create_window(400,150,height=50,width=300,window=self.f_input)
self.canvas.create_window(400,250,height=50,window=self.btn_conf1)
self.canvas.create_window(150,150,height=50,width=150,window=self.f_prom)
def display1(self,):
if(self.flag1==1):
self.f_input.destroy()
self.btn_conf1.destroy()
self.f_prom.destroy()
self.flag1=0
if(self.flag2==1):
return
self.bnum_prom=ttk.Label(self.addwin,text="书号:",anchor="center",style="label.TLabel", width=50)
self.cob_prom=ttk.Label(self.addwin,text="类别:",anchor="center",style="label.TLabel",width=50)
self.bname_prom=ttk.Label(self.addwin,text="书名:",anchor="center",style="label.TLabel", width=50)
self.pub_prom=ttk.Label(self.addwin,text="出版社:",anchor="center",style="label.TLabel", width=50)
self.y_prom=ttk.Label(self.addwin,text="年份:",anchor="center",style="label.TLabel", width=50)
self.auth_prom=ttk.Label(self.addwin,text="作者:",anchor="center",style="label.TLabel", width=50)
self.pri_prom=ttk.Label(self.addwin,text="价格:",anchor="center",style="label.TLabel", width=50)
self.btn_conf2=ttk.Button(self.addwin,text="入库",command=self.onclick2)
self.btn_conf3=ttk.Button(self.addwin,text="修改",command=self.onclick3)
self.bnum_input=tk.Entry(self.addwin,show=None,font=("微软雅黑",14),width=20)
self.cob_input=tk.Entry(self.addwin,show=None,font=("微软雅黑",14),width=20)
self.bname_input=tk.Entry(self.addwin,show=None,font=("微软雅黑",14),width=20)
self.pub_input=tk.Entry(self.addwin,show=None,font=("微软雅黑",14),width=20)
self.y_input=tk.Entry(self.addwin,show=None,font=("微软雅黑",14),width=20)
self.auth_input=tk.Entry(self.addwin,show=None,font=("微软雅黑",14),width=20)
self.pri_input=tk.Entry(self.addwin,show=None,font=("微软雅黑",14),width=20)
self.flag2=1#标记一下上面的东西都被创立了,下面要把它们放在画布上
self.canvas.create_window(250,150,width=70,window=self.bnum_prom)
self.canvas.create_window(410,150,height=30,window=self.bnum_input)
self.canvas.create_window(250,200,width=70,window=self.cob_prom)
self.canvas.create_window(410,200,height=30,window=self.cob_input)
self.canvas.create_window(250,250,width=70,window=self.bname_prom)
self.canvas.create_window(410,250,height=30,window=self.bname_input)
self.canvas.create_window(250,300,width=70,window=self.pub_prom)
self.canvas.create_window(410,300,height=30,window=self.pub_input)
self.canvas.create_window(250,350,width=70,window=self.y_prom)
self.canvas.create_window(410,350,height=30,window=self.y_input)
self.canvas.create_window(250,400,width=70,window=self.auth_prom)
self.canvas.create_window(410,400,height=30,window=self.auth_input)
self.canvas.create_window(250,450,width=70,window=self.pri_prom)
self.canvas.create_window(410,450,height=30,window=self.pri_input)
self.canvas.create_window(300,500,window=self.btn_conf2)
self.canvas.create_window(420,500,window=self.btn_conf3)
def onclick1(self,):
#基本完成,批量入库的部分
file_addr=self.f_input.get()
result=AddPart.AddBatch(conn,file_addr)
self.state.destroy()
if type(result)==type(()):
self.str="导入完毕\n成功导入 %d 条记录,共 %d\n导入记录存至succeed_log.txt中\n导入失败 %d 条记录,共 %d\n详见屏幕下方"%(result[0],result[1],result[2],result[3])
self.f_list=scrolledtext.ScrolledText(self.addwin,width=700,height=300,font=("微软雅黑",12))
self.f_str="以下是导入失败的书的名单\n"
self.f_list.insert(END,self.f_str)
for _ in result[4]:
self.f_list.insert(END,_+"\n")
self.f_list.config(state='disabled')
self.canvas.create_window(100,280,width=700,height=300,anchor="nw",window=self.f_list)
self.btn_list=ttk.Button(self.addwin,text="确认导入失败名单",command=self.destroy_flist)
self.canvas.create_window(400,600,anchor="nw",window=self.btn_list)
self.r1.config(state="disabled")
self.r2.config(state="disabled")
else:
self.str=result
self.state=tk.Message(self.addwin,text=self.str,width=300,font=("微软雅黑",12))
self.canvas.create_window(650,150,anchor="nw",width=300,window=self.state)
def destroy_flist(self):
self.addwin.destroy()
addwin(self.master)
def onclick2(self,):
bnum=self.bnum_input.get()
cob=self.cob_input.get()
bname=self.bname_input.get()
pub=self.pub_input.get()
y=self.y_input.get()
auth=self.auth_input.get()
pri=self.pri_input.get()
result=AddPart.AddOne(conn,bnum,cob,bname,pub,y,auth,pri,self.cflag,1)
if type(result)==type(()):
self.str="添加成功\n图书馆现有此书%d\n共有藏书%d"%(result[1],result[0])
elif result!="修改成功":
self.str=result
else:
self.str=result
self.state.destroy()
self.state=tk.Message(self.addwin,text=self.str,width=300,font=("微软雅黑",12))
self.canvas.create_window(650,150,anchor="nw",width=300,window=self.state)
self.cflag=0
def onclick3(self,):
self.cflag=1
self.onclick2()
def back(self,):
self.addwin.destroy()
initwin(self.master)
class querywin():
def __init__(self,master):
global im
global image
self.master=master
self.querywin=tk.Frame(self.master,)
self.querywin.pack()
self.canvas=tk.Canvas(self.querywin,
width=1000,
height=700,
bg='white')
image=Image.open('bg.jpg')
im=ImageTk.PhotoImage(image)
self.canvas.create_image(0,0,anchor="nw",image=im)
self.canvas.pack()
self.btn_back=ttk.Button(self.querywin,text="返回主菜单",command=self.back)
self.canvas.create_window(100,50,width=200,height=40,window=self.btn_back)
self.style_l=ttk.Style()
self.style_l.configure("l.TLabel",font=("微软雅黑",14))
self.style_e=ttk.Style()
self.style_e.configure("e.TLabel",font=("微软雅黑",14))
self.sel_title=ttk.Label(self.querywin,text="请选择您的查询方式,并点击确认",width=30,style="l.TLabel",anchor="center")
self.canvas.create_window(310,90,height=50,anchor="nw",window=self.sel_title)
self.btn_sel=ttk.Button(self.querywin,text="确认",command=self.judge)
self.canvas.create_window(435,420,anchor="nw",height=40,window=self.btn_sel)
self.list=tk.Listbox(self.querywin)
for i in ["类别","书名","出版社","年份(区间)","作者","价格(区间)"]:
self.list.insert(END,i)
self.list.config(font=("微软雅黑",16),height=6)
self.canvas.create_window(310,200,width=340,anchor="nw",window=self.list)
def judge(self):
self.sel_index=self.list.curselection()
if self.sel_index==():
pass
else:
self.query(self.sel_index[0])
def query(self,index):
self.index=index
self.search_str=self.list.get(index)
self.sel_title.destroy()
self.btn_sel.destroy()
self.list.destroy()
#首先把之前的控件都destroy掉然后根据index的值来生成不同的控件
#如果是单值查询,则只有一个输入框
#如果是区间查询则要两个输入框index为3或5
if index!=3 and index !=5:
self.search_prom1=ttk.Label(self.querywin,text="请输入 "+self.search_str+":",style="l.TLabel",width=20,anchor="center")
self.search_input1=tk.Entry(self.querywin,show=None,font=("微软雅黑",14))
self.btn_search1=ttk.Button(self.querywin,text="查询",command=self.onclick1)
self.canvas.create_window(150,150,anchor="nw",height=50,window=self.search_prom1)
self.canvas.create_window(400,150,anchor="nw",height=50,width=300,window=self.search_input1)
self.canvas.create_window(780,150,anchor="nw",height=50,window=self.btn_search1)
else:
#pass
self.search_prom2=ttk.Label(self.querywin,text="请输入 "+self.search_str+':',style="l.TLabel",anchor="center",width=20)
self.search_input2=tk.Entry(self.querywin,show=None,font=("微软雅黑",14))
self.search_link=ttk.Label(self.querywin,text="————")
self.search_input3=tk.Entry(self.querywin,show=None,font=("微软雅黑",14))
self.btn_search2=ttk.Button(self.querywin,text="查询",command=self.onclick2)
self.canvas.create_window(150,150,anchor="nw",height=50,window=self.search_prom2)
self.canvas.create_window(400,155,anchor="nw",width=100,height=40,window=self.search_input2)
self.canvas.create_window(550,165,anchor="nw",window=self.search_link)
self.canvas.create_window(650,155,anchor="nw",width=100,height=40,window=self.search_input3)
self.canvas.create_window(800,150,anchor="nw",height=50,window=self.btn_search2)
def onclick1(self):
result=QueryPart.QueryBook(conn,self.search_input1.get(),0,self.index)
#针对单值查询,把参数传到查询部分中,然后调用show函数显示结果
self.show(result)
def onclick2(self):
result=QueryPart.QueryBook(conn,self.search_input2.get(),self.search_input3.get(),self.index)
#针对区间查询,把参数传到查询部分中然后调用show函数显示结果
self.show(result)
def show(self,result):
#美观方面的问题还需要改进。。。现在先大体实现功能
#重构此部分由label改为ttk的Treeview
self.query_list=ttk.Treeview(self.querywin,columns=["书号","类别","书名","出版社","年份","作者","价格","库存数"],show="headings")#show设为headings可以隐藏首列
self.query_list.column("书号",width=100)
self.query_list.column("类别",width=150)
self.query_list.column("书名",width=200)
self.query_list.column("出版社",width=150)
self.query_list.column("年份",width=50)
self.query_list.column("作者",width=100)
self.query_list.column("价格",width=80)
self.query_list.column("库存数",width=80)
self.query_list.heading("书号",text="书号",)
self.query_list.heading("类别",text="类别",)
self.query_list.heading("书名",text="书名",)
self.query_list.heading("出版社",text="出版社")
self.query_list.heading("年份",text="年份")
self.query_list.heading("作者",text="作者")
self.query_list.heading("价格",text="价格")
self.query_list.heading("库存数",text="库存数")
self.canvas.create_window(50,250,height=300,anchor="nw",window=self.query_list)
self.query_bar=ttk.Scrollbar(self.querywin,orient='vertical',command=self.query_list.yview)
self.query_list.configure(yscrollcommand=self.query_bar.set)
self.canvas.create_window(960,250,height=300,anchor="nw",window=self.query_bar)
self.btn_list=ttk.Button(self.querywin,text="返回",command=self.destroy_search)
self.canvas.create_window(480,580,height=30,width=50,window=self.btn_list)
if type(result)!=type(()):
return
i=0#临时变量
for item in result:
self.bnum_str=item[0]
self.class_str=item[1]
self.bname_str=item[2]
self.pub_str=item[3]
self.year_str=item[4]
self.auth_str=item[5]
self.pri_str=item[6]
self.coll_str=item[7]
self.query_list.insert("",i,values=(item[0],item[1],item[2],item[3],item[4],item[5],item[6],item[7]))
i+=1
#print(result)
#把传过来的结果显示出来,参数没定下来。。。
def destroy_search(self):
self.querywin.destroy()
querywin(self.master)
def back(self):
self.querywin.destroy()
initwin(self.master)
class cardwin():
def __init__(self,master):
global im
global image
self.master=master
self.cardwin=tk.Frame(self.master)
self.cardwin.pack()
self.canvas=tk.Canvas(self.cardwin,
width=1000,
height=700,
bg='white')
image=Image.open('bg.jpg')
im=ImageTk.PhotoImage(image)
self.canvas.create_image(0, 0, anchor="nw", image=im)
self.canvas.pack()
self.btn_back=ttk.Button(self.cardwin,text="返回主菜单",command=self.back)
self.canvas.create_window(100,50,width=200,height=40,window=self.btn_back)
self.mode=tk.IntVar()
self.style_r=ttk.Style()
self.style_r.configure("r.TRadiobutton",font=("微软雅黑",10),background="Aqua")
self.r1=ttk.Radiobutton(self.cardwin,text="增添或修改",variable=self.mode,value=1,command=self.Add,style="r.TRadiobutton")
self.r2=ttk.Radiobutton(self.cardwin,text="删除借书证",variable=self.mode,value=2,command=self.Delete,style="r.TRadiobutton")
self.canvas.create_window(400,50,window=self.r1)
self.canvas.create_window(400,100,window=self.r2)
self.flag_add=0
self.flag_del=0
self.cflag=0
self.type="S"
self.str="状态信息"
self.style_l=ttk.Style()
self.style_l.configure("l.TLabel",font=("微软雅黑",14))
self.s_title=ttk.Label(self.cardwin,text="状态栏",width=30,style="l.TLabel",anchor="center")
self.state=tk.Message(self.cardwin,text=self.str,width=300,font=("微软雅黑",12))
self.canvas.create_window(800,100,height=50,window=self.s_title)
self.canvas.create_window(650,150,anchor="nw",width=300,window=self.state)
def Add(self):
if self.flag_del==1:
self.cnum_input.destroy()
self.cnum_prom.destroy()
self.btn_del.destroy()
self.flag_del=0
if self.flag_add==1:
return
self.cnum_prom=ttk.Label(self.cardwin,text="借书证号:",style="l.TLabel",width=50,anchor="center")
self.name_prom=ttk.Label(self.cardwin,text="姓名:",style="l.TLabel",width=50,anchor="center")
self.dept_prom=ttk.Label(self.cardwin,text="所属单位(学院):",style="l.TLabel",width=50,anchor="center")
self.type_prom=ttk.Label(self.cardwin,text="身份类别:",style="l.TLabel",width=50,anchor="center")
self.canvas.create_window(150,150,anchor="nw",width=150,height=40,window=self.cnum_prom)
self.canvas.create_window(150,200,anchor="nw",width=150,height=40,window=self.name_prom)
self.canvas.create_window(150,250,anchor="nw",width=150,height=40,window=self.dept_prom)
self.canvas.create_window(150,300,anchor="nw",width=150,height=40,window=self.type_prom)
self.cnum_input=tk.Entry(self.cardwin,show=None,font=("微软雅黑",14))
self.name_input=tk.Entry(self.cardwin,show=None,font=("微软雅黑",14))
self.dept_input=tk.Entry(self.cardwin,show=None,font=("微软雅黑",14))
self.style_r1=ttk.Style()
self.style_r1.configure("r1.TRadiobutton",font=("微软雅黑",14))
self.type_input=tk.IntVar()
self.type_input1=ttk.Radiobutton(self.cardwin,text="老师",variable=self.type_input,value=1,command=self.T_type,style="r1.TRadiobutton")
self.type_input2=ttk.Radiobutton(self.cardwin,text="学生",variable=self.type_input,value=2,command=self.S_type,style="r1.TRadiobutton")
self.canvas.create_window(350,150,anchor="nw",height=40,window=self.cnum_input)
self.canvas.create_window(350,200,anchor="nw",height=40,window=self.name_input)
self.canvas.create_window(350,250,anchor="nw",height=40,window=self.dept_input)
self.canvas.create_window(380,305,anchor="nw",window=self.type_input1)
self.canvas.create_window(480,305,anchor="nw",window=self.type_input2)
self.btn_add=ttk.Button(self.cardwin,text="增添",command=self.add)
self.btn_change=ttk.Button(self.cardwin,text="修改",command=self.change)
self.canvas.create_window(250,400,anchor="nw",window=self.btn_add)
self.canvas.create_window(400,400,anchor="nw",window=self.btn_change)
self.flag_add=1
def add(self):
cnum=self.cnum_input.get()
name=self.name_input.get()
dept=self.dept_input.get()
Type=self.type
result=CardPart.AddCard(conn,cnum,name,dept,Type,self.cflag)
if result==1:
self.str="添加成功"
elif result==2:
self.str="修改成功"
else :
self.str=result
self.state.destroy()
self.state=tk.Message(self.cardwin,text=self.str,width=300,font=("微软雅黑",12))
self.canvas.create_window(650,150,anchor="nw",width=300,window=self.state)
self.cflag=0
def change(self):
self.cflag=1
self.add()
def T_type(self):
self.type="T"
def S_type(self):
self.type="S"
def Delete(self):
if self.flag_add==1:
#destroy
self.cnum_prom.destroy()
self.cnum_input.destroy()
self.name_prom.destroy()
self.name_input.destroy()
self.dept_prom.destroy()
self.dept_input.destroy()
self.type_prom.destroy()
self.type_input1.destroy()
self.type_input2.destroy()
self.btn_add.destroy()
self.btn_change.destroy()
self.flag_add=0
if self.flag_del==1:
return
self.cnum_prom=ttk.Label(self.cardwin,text="请输入借书证号:",style="l.TLabel",width=70,anchor="center")
self.cnum_input=tk.Entry(self.cardwin,show=None,font=("微软雅黑",14))
self.btn_del=ttk.Button(self.cardwin,text="删除",command=self.dele)
self.canvas.create_window(150,200,width=150,height=50,anchor="nw",window=self.cnum_prom)
self.canvas.create_window(350,205,width=250,height=40,anchor="nw",window=self.cnum_input)
self.canvas.create_window(430,300,width=70,height=40,anchor="nw",window=self.btn_del)
self.flag_del=1
def dele(self):
cnum=self.cnum_input.get()
result=CardPart.DeleteCard(conn,cnum)
if(result==1):
self.str="删除成功"
else:
self.str=result
self.state.destroy()
self.state=tk.Message(self.cardwin,text=self.str,width=300,font=("微软雅黑",12))
self.canvas.create_window(650,150,anchor="nw",width=300,window=self.state)
def back(self):
self.cardwin.destroy()
initwin(self.master)
class borrowwin():
def __init__(self,master):
global im
global image
self.master=master
self.borrowwin=tk.Frame(self.master)
self.borrowwin.pack()
self.canvas=tk.Canvas(self.borrowwin,
width=1000,
height=700,
bg='white')
image=Image.open('bg.jpg')
im=ImageTk.PhotoImage(image)
self.canvas.create_image(0,0,anchor="nw",image=im)
self.canvas.pack()
self.btn_back=ttk.Button(self.borrowwin,text="返回主菜单",command=self.back)
self.canvas.create_window(100,50,width=200,height=40,window=self.btn_back)
self.style_l=ttk.Style()
self.style_l.configure("l.TLabel",font=("微软雅黑",14))
self.cnum_prom=ttk.Label(self.borrowwin,text="请输入借书证号:",style="l.TLabel",anchor="center")
self.cnum_input=tk.Entry(self.borrowwin,show=None,font=("微软雅黑",14))
self.btn_cnum=ttk.Button(self.borrowwin,text="确认",command=self.confirm)
self.canvas.create_window(100,100,height=40,width=200,anchor="nw",window=self.cnum_prom)
self.canvas.create_window(350,100,height=40,width=300,anchor="nw",window=self.cnum_input)
self.canvas.create_window(700,100,height=40,width=70,anchor="nw",window=self.btn_cnum)
def confirm(self):
CardNum=self.cnum_input.get()
self.cnum=CardNum
borrow_list=BorrowPart.ShowList(conn,CardNum)
self.borrow_list=borrow_list
self.btn_next=ttk.Button(self.borrowwin,text="下一步",command=self.next)
self.canvas.create_window(430,550,width=100,height=40,anchor="nw",window=self.btn_next)
self.btn_cnum['state']='disabled'
if type(borrow_list)!=type(()):
self.error=ttk.Label(self.borrowwin,text=borrow_list,style="l.TLabel",anchor="center")
self.canvas.create_window(400,300,width=200,height=50,anchor="nw",window=self.error)
if type(borrow_list)==type(()):
self.query_list=ttk.Treeview(self.borrowwin,columns=["书号","书名","借书时间","归还期限","是否可以续借"],show="headings")#show设为headings可以隐藏首列
self.query_list.column("书号",width=100)
self.query_list.column("书名",width=200)
self.query_list.column("借书时间",width=200)
self.query_list.column("归还期限",width=200)
self.query_list.column("是否可以续借",width=80)
self.query_list.heading("书号",text="书号",)
self.query_list.heading("书名",text="书名",)
self.query_list.heading("借书时间",text="借书时间")
self.query_list.heading("归还期限",text="归还期限")
self.query_list.heading("是否可以续借",text="是否可以续借")
self.canvas.create_window(100,250,height=230,anchor="nw",window=self.query_list)
#下面这个滚动条做的不是很成功。。。但是我发现不用滚动条也可以用鼠标滚轮去上下翻滚。那我何必非得弄个滚动条呢。。。
#但我还是弄了.jpg
# self.query_bar=ttk.Scrollbar(self.borrowwin,orient='vertical',command=self.query_list.yview)
# self.query_list.configure(yscrollcommand=self.query_bar.set)
# self.canvas.create_window(880,250,height=300,anchor="nw",window=self.query_bar)
i=0#临时变量
for item in borrow_list:
if item[4]==0:
self.plus="不可以"
else:
self.plus="可以"
self.query_list.insert("",i,values=(item[0],item[1],item[2],item[3],self.plus))
i+=1
def next(self):
if type(self.borrow_list)==type(()):
self.query_list.destroy()
#self.query_bar.destroy()
self.cnum_prom.destroy()
self.cnum_input.destroy()
self.btn_cnum.destroy()
self.btn_next.destroy()
self.bnum_prom=ttk.Label(self.borrowwin,text="请输入书号:",style="l.TLabel",anchor="center")
self.bnum_input=tk.Entry(self.borrowwin,show=None,font=("微软雅黑",14))
self.btn_bnum=ttk.Button(self.borrowwin,text="借书",command=self.borrow)
self.canvas.create_window(250,150,height=40,anchor="nw",window=self.bnum_prom)
self.canvas.create_window(400,150,anchor="nw",height=40,window=self.bnum_input)
self.canvas.create_window(650,150,anchor="nw",height=40,window=self.btn_bnum)
else:
self.borrowwin.destroy()
borrowwin(self.master)
def borrow(self):
self.bnum=self.bnum_input.get()
result=BorrowPart.Borrow(conn,self.cnum,self.bnum)
if type(result)==type(()):
if result[0]==0:
self.borrow_str="%s借书成功,请在%s前归还"%(result[2],result[1])
elif result[0]==1:
self.borrow_str="续借成功,请在%s前归还"%(result[1])
elif result[0]==2:
self.borrow_str="尚无库存,最早归还日期为%s"%result[1]
else:
self.borrow_str=result
self.borrow_success=ttk.Label(self.borrowwin,text=self.borrow_str,style="l.TLabel",anchor="center")
self.btn_borrow_over=tk.Button(self.borrowwin,text="返回上一级菜单",command=self.return_last)
self.canvas.create_window(170,300,width=700,anchor="nw",height=50,window=self.borrow_success)
self.canvas.create_window(450,400,anchor="nw",width=100,height=40,window=self.btn_borrow_over)
def return_last(self):
self.borrowwin.destroy()
borrowwin(self.master)
def back(self):
self.borrowwin.destroy()
initwin(self.master)
class returnwin():
def __init__(self,master):
global im
global image
self.master=master
self.returnwin=tk.Frame(self.master)
self.returnwin.pack()
self.canvas=tk.Canvas(self.returnwin,
width=1000,
height=700,
bg='white')
image=Image.open('bg.jpg')
im=ImageTk.PhotoImage(image)
self.canvas.create_image(0,0,anchor="nw",image=im)
self.canvas.pack()
self.btn_back=ttk.Button(self.returnwin,text="返回主菜单",command=self.back)
self.canvas.create_window(100,50,width=200,height=40,window=self.btn_back)
self.style_l=ttk.Style()
self.style_l.configure("l.TLabel",font=("微软雅黑",14))
self.cnum_prom=ttk.Label(self.returnwin,text="请输入借书证号:",style="l.TLabel",anchor="center")
self.cnum_input=tk.Entry(self.returnwin,show=None,font=("微软雅黑",14))
self.btn_cnum=ttk.Button(self.returnwin,text="确认",command=self.confirm)
self.canvas.create_window(100,100,height=40,width=200,anchor="nw",window=self.cnum_prom)
self.canvas.create_window(350,100,height=40,width=300,anchor="nw",window=self.cnum_input)
self.canvas.create_window(700,100,height=40,width=70,anchor="nw",window=self.btn_cnum)
def confirm(self):
CardNum=self.cnum_input.get()
self.cnum=CardNum
borrow_list=BorrowPart.ShowList(conn,CardNum)
self.borrow_list=borrow_list
self.btn_next=ttk.Button(self.returnwin,text="下一步",command=self.next)
self.canvas.create_window(430,550,width=100,height=40,anchor="nw",window=self.btn_next)
self.btn_cnum['state']='disabled'
if type(borrow_list)!=type(()):
self.error=ttk.Label(self.returnwin,text=borrow_list,style="l.TLabel",anchor="center")
self.canvas.create_window(400,300,width=200,height=50,anchor="nw",window=self.error)
if type(borrow_list)==type(()):
self.query_list=ttk.Treeview(self.returnwin,columns=["书号","书名","借书时间","归还期限","是否可以续借"],show="headings")#show设为headings可以隐藏首列
self.query_list.column("书号",width=100)
self.query_list.column("书名",width=200)
self.query_list.column("借书时间",width=200)
self.query_list.column("归还期限",width=200)
self.query_list.column("是否可以续借",width=80)
self.query_list.heading("书号",text="书号",)
self.query_list.heading("书名",text="书名",)
self.query_list.heading("借书时间",text="借书时间")
self.query_list.heading("归还期限",text="归还期限")
self.query_list.heading("是否可以续借",text="是否可以续借")
self.canvas.create_window(100,250,height=230,anchor="nw",window=self.query_list)
# #下面这个滚动条做的不是很成功。。。但是我发现不用滚动条也可以用鼠标滚轮去上下翻滚。那我何必非得弄个滚动条呢。。。
# #但我还是弄了.jpg
# self.query_bar=ttk.Scrollbar(self.returnwin,orient='vertical',command=self.query_list.yview)
# self.query_list.configure(yscrollcommand=self.query_bar.set)
# self.canvas.create_window(880,250,height=230,anchor="nw",window=self.query_bar)
i=0#临时变量
for item in borrow_list:
if item[4]==0:
self.plus="可以"
else:
self.plus="不可以"
self.query_list.insert("",i,values=(item[0],item[1],item[2],item[3],self.plus))
i+=1
def next(self):
if type(self.borrow_list)==type(()):
self.query_list.destroy()
#self.query_bar.destroy()
self.cnum_prom.destroy()
self.cnum_input.destroy()
self.btn_cnum.destroy()
self.btn_next.destroy()
self.bnum_prom=ttk.Label(self.returnwin,text="请输入书号:",style="l.TLabel",anchor="center")
self.bnum_input=tk.Entry(self.returnwin,show=None,font=("微软雅黑",14))
self.btn_bnum=ttk.Button(self.returnwin,text="还书",command=self.return_book)
self.canvas.create_window(250,150,height=40,anchor="nw",window=self.bnum_prom)
self.canvas.create_window(400,150,anchor="nw",height=40,window=self.bnum_input)
self.canvas.create_window(650,150,anchor="nw",height=40,window=self.btn_bnum)
else:
self.returnwin.destroy()
returnwin(self.master)
def return_book(self):
self.bnum=self.bnum_input.get()
result=ReturnPart.Return(conn,self.cnum,self.bnum)
if type(result)==type(()):
name=result[0]
if result[1]==0:
late=",没有超期"
else:
late=",超出还书期限"#此处可以为超出还书期限的增加惩罚措施。。。不过由于精力实在有限。。。
self.return_str="%s还书成功"%name
self.return_str=self.return_str+late
else:
self.return_str=result
self.borrow_success=ttk.Label(self.returnwin,text=self.return_str,style="l.TLabel",anchor="center")
self.btn_borrow_over=tk.Button(self.returnwin,text="返回上一级菜单",command=self.return_last)
self.canvas.create_window(170,300,width=700,anchor="nw",height=50,window=self.borrow_success)
self.canvas.create_window(450,400,anchor="nw",width=100,height=40,window=self.btn_borrow_over)
def return_last(self):
self.returnwin.destroy()
returnwin(self.master)
def back(self):
self.returnwin.destroy()
initwin(self.master)
def StartGui():
root = tk.Tk()
basedesk(root)
root.mainloop()
if __name__ == "__main__":
import tkinter as tk
from tkinter import scrolledtext,END
from tkinter import ttk
from PIL import Image, ImageTk
import AddPart
import QueryPart
import CardPart
import BorrowPart
import ReturnPart
import logging
import pymysql
image = None
im = None
with open("config.txt","r") as config:
user=config.readline().split(":")[1].strip(" \n")
pw=config.readline().split(":")[1].strip(" \n")
try:
conn = pymysql.connect(
host='localhost',
port=3306,
user=user,
password=pw,
database='library',
charset='utf8'
)
except Exception as e:
logging.exception(e)
StartGui()

@ -0,0 +1,43 @@
import pymysql
import logging
def QueryBook(conn,para1,para2,index):
if para1=="" or para2=="":
return "输入不能为空"
cursor=conn.cursor()
##目前进度单值查询已做完区间查询没有做。并且最后return的是一个比较乱的tuple。在show()函数中应该要一层一层的处理
try:
if index==0:
sql="select bnum,bclass,bname,publisher,year,author,price,collection from book where bclass=%s"
elif index==1:
sql="select bnum,bclass,bname,publisher,year,author,price,collection from book where bname=%s"
elif index==2:
sql="select bnum,bclass,bname,publisher,year,author,price,collection from book where publisher=%s"
elif index==4:
sql="select bnum,bclass,bname,publisher,year,author,price,collection from book where author=%s"
elif index==3:
y1=int(para1)
y2=int(para2)
sql="select bnum,bclass,bname,publisher,year,author,price,collection from book where year>%s and year<%s"
elif index==5:
p1=float(para1)
p2=float(para2)
sql="select bnum,bclass,bname,publisher,year,author,price,collection from book where price>%s and price<%s"
try:
if index==0 or index==1 or index==2 or index==4:
cursor.execute(sql,para1)
elif index==5:
cursor.execute(sql,(p1,p2))
else:
cursor.execute(sql,(y1,y2))
conn.commit()
result=cursor.fetchall()
return result
except Exception as e:
conn.rollback()
return e
except Exception as e:
return e

@ -0,0 +1,40 @@
import pymysql
import logging
import datetime
def Return(conn,CardNum,BookNum):
if(CardNum=="" or BookNum==""):
return "不能为空"
try:
cursor=conn.cursor()
sql="select numbers from card where cnum=%s"
cursor.execute(sql,CardNum)
num_=cursor.fetchone()
num=num_[0]-1
sql="select bname,collection,rtime from book natural join borrow where bnum=%s and cnum=%s"
cursor.execute(sql,(BookNum,CardNum))
result=cursor.fetchone()
if result is None:
return "您尚未借阅此书,因此无法还书"
else:
name=result[0]
collection=result[1]
r_time=result[2]
collection+=1
n_time=datetime.datetime.now()
if(n_time>r_time):
late=1
else:
late=0
sql="update book set collection=%s where bnum=%s"
cursor.execute(sql,(collection,BookNum))
sql="delete from borrow where bnum=%s and cnum=%s"
cursor.execute(sql,(BookNum,CardNum))
sql="update card set numbers=%s where cnum=%s"
cursor.execute(sql,(num,CardNum))
conn.commit()
return (name,late)
except Exception as e:
logging.exception(e)
conn.rollback()
return e

Binary file not shown.

After

Width:  |  Height:  |  Size: 55 KiB

@ -0,0 +1,2 @@
user: root
password: 123456

@ -0,0 +1,17 @@
( book_no_1, Computer Science,《计算机网络自顶向下方法》, 机械工业出版社, 2018, 詹姆斯, 89.00, 3 )
( book_no_2, Computer Science, 《深入理解计算机系统》, 机械工业出版社, 2016, 兰德尔, 139.00, 2 )
( book_no_3, Computer Science, 《图解HTTP》, 人民邮电出版社, 2014, 上野宣, 49.00, 5)
( book_no_4, 青春小说, 《余生,请多指教》, 百花洲文艺出版社, 2016, 柏林石匠, 32.00, 1 )
( book_no_5, Computer Science, 《AI传奇人工智能通俗史》, 机械工业出版社, 2017, 陈宗周, 59.00, 6 )
( book_no_6, 青春小说, 《致我们单纯的小美好 上+下》, 江苏凤凰文艺出版社, 2015, 赵乾乾, 48.00, 4 )
( book_no_7, 文学, 《津轻》, 四川文艺出版社, 2017, 太宰治, 39.8, 2 )
( book_no_8, 外国名著, 《人间失格》, 浙江文艺出版社, 2016, 太宰治, 25.00, 2 )
( book_no_9, 文学,《追风筝的人》, 上海人民出版社, 2006, 卡勒德, 29.00, 2 )
( book_no_10, 外国名著, 《老人与海》, 延边人民出版社, 2000, 海明威, 90.00, 2 )
( book_no_11, Computer Science, 《Computer Architecture》, xxx, 2003, xxx, 90.00, 2 )
( book_no_12, Computer Science,《Computer Architecture》, xxx, 2003, xxx, 90.00, 2 )
( book_no_13, Computer Science, 《Computer Architecture》, xxx, 2003, xxx, 90.00, 2 )
( book_no_14, Computer Science, 《Computer Architecture》, xxx, 2003, xxx, 90.00, 2 )
( book_no_15, Computer Science, 《Computer Architecture》, xxx, 2003, xxx, 90.00, 2 )
( book_no_16, Computer Science, 《Computer Architecture》, xxx, 2003, xxx, 90.00, 2 )
( book_no_17, Computer Science, 《Computer Architecture》, xxx, 2003, xxx, 90.00, 2 )

@ -0,0 +1,7 @@
( book_no_1, Computer Science, Computer Architecture, xxx, 2003, xxx, 90.00, 2 )
( book_no_1, Computer Science, Computer Architecture, xxx, 2003, xxx, 90.00, 2 )
( book_no_1, Computer Science, Computer Architecture, xxx, 2003, xxx, 90.00, 2 )
( book_no_1, Computer Science, Computer Architecture, xxx, 2003, xxx, 90.00, 2 )
( book_no_1, Computer Science, Computer Architecture, xxx, 2003, xxx, 90.00, 2 )
( book_no_1, Computer Science, Computer Architecture, xxx, 2003, xxx, 90.00, 2 )
( book_no_1, Computer Science, Computer Architecture, xxx, 2003, xxx, 90.00, 2 )

@ -0,0 +1,102 @@
/*
Navicat Premium Data Transfer
Source Server : JDBC
Source Server Type : MySQL
Source Server Version : 80027
Source Host : localhost:3306
Source Schema : library
Target Server Type : MySQL
Target Server Version : 80027
File Encoding : 65001
Date: 25/05/2024 17:43:04
*/
SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;
-- ----------------------------
-- Table structure for book
-- ----------------------------
DROP TABLE IF EXISTS `book`;
CREATE TABLE `book` (
`bnum` char(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL,
`bclass` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL,
`bname` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL,
`publisher` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL,
`year` int(0) NULL DEFAULT NULL,
`author` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL,
`price` decimal(7, 2) NULL DEFAULT NULL,
`total` int(0) NULL DEFAULT NULL,
`collection` int(0) NULL DEFAULT NULL,
PRIMARY KEY (`bnum`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci ROW_FORMAT = Dynamic;
-- ----------------------------
-- Records of book
-- ----------------------------
INSERT INTO `book` VALUES (' 21401202727', '计算机', 'python基础', '长春出版社', 2021, '李四', 500.00, 49, 3);
INSERT INTO `book` VALUES ('1', '1', '1', '1', 1, '1', 1.00, 49, 1);
INSERT INTO `book` VALUES ('111', '卷心菜', 'python入门到精通', '工信出版社', 2022, '小白', 54.00, 49, 0);
INSERT INTO `book` VALUES ('21401202727', '计算机', 'python基础', '长春出版社', 2022, '张三', 50.00, 49, 1);
INSERT INTO `book` VALUES ('book_no_1', 'Computer Science', '《计算机网络自顶向下方法》', '机械工业出版社', 2018, '詹姆斯', 89.00, 49, 3);
INSERT INTO `book` VALUES ('book_no_10', '外国名著', '《老人与海》', '延边人民出版社', 2000, '海明威', 90.00, 49, 2);
INSERT INTO `book` VALUES ('book_no_11', 'Computer Science', '《Computer Architecture》', 'xxx', 2003, 'xxx', 90.00, 49, 2);
INSERT INTO `book` VALUES ('book_no_12', 'Computer Science', '《Computer Architecture》', 'xxx', 2003, 'xxx', 90.00, 49, 2);
INSERT INTO `book` VALUES ('book_no_13', 'Computer Science', '《Computer Architecture》', 'xxx', 2003, 'xxx', 90.00, 49, 2);
INSERT INTO `book` VALUES ('book_no_14', 'Computer Science', '《Computer Architecture》', 'xxx', 2003, 'xxx', 90.00, 49, 2);
INSERT INTO `book` VALUES ('book_no_15', 'Computer Science', '《Computer Architecture》', 'xxx', 2003, 'xxx', 90.00, 49, 2);
INSERT INTO `book` VALUES ('book_no_16', 'Computer Science', '《Computer Architecture》', 'xxx', 2003, 'xxx', 90.00, 49, 2);
INSERT INTO `book` VALUES ('book_no_17', 'Computer Science', '《Computer Architecture》', 'xxx', 2003, 'xxx', 90.00, 49, 2);
INSERT INTO `book` VALUES ('book_no_2', 'Computer Science', '《深入理解计算机系统》', '机械工业出版社', 2016, '兰德尔', 139.00, 49, 2);
INSERT INTO `book` VALUES ('book_no_3', 'Computer Science', '《图解HTTP》', '人民邮电出版社', 2014, '上野宣', 49.00, 49, 5);
INSERT INTO `book` VALUES ('book_no_4', '青春小说', '《余生,请多指教》', '百花洲文艺出版社', 2016, '柏林石匠', 32.00, 49, 1);
INSERT INTO `book` VALUES ('book_no_5', 'Computer Science', '《AI传奇人工智能通俗史》', '机械工业出版社', 2017, '陈宗周', 59.00, 49, 6);
INSERT INTO `book` VALUES ('book_no_6', '青春小说', '《致我们单纯的小美好 上+下》', '江苏凤凰文艺出版社', 2015, '赵乾乾', 48.00, 49, 4);
INSERT INTO `book` VALUES ('book_no_7', '文学', '《津轻》', '四川文艺出版社', 2017, '太宰治', 39.80, 49, 2);
INSERT INTO `book` VALUES ('book_no_8', '外国名著', '《人间失格》', '浙江文艺出版社', 2016, '太宰治', 25.00, 49, 2);
INSERT INTO `book` VALUES ('book_no_9', '文学', '《追风筝的人》', '上海人民出版社', 2006, '卡勒德', 29.00, 49, 2);
-- ----------------------------
-- Table structure for borrow
-- ----------------------------
DROP TABLE IF EXISTS `borrow`;
CREATE TABLE `borrow` (
`cnum` char(7) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL,
`bnum` char(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL,
`btime` datetime(0) NULL DEFAULT NULL,
`rtime` datetime(0) NULL DEFAULT NULL,
`times` int(0) NULL DEFAULT NULL,
PRIMARY KEY (`cnum`, `bnum`) USING BTREE,
INDEX `bnum`(`bnum`) USING BTREE,
CONSTRAINT `borrow_ibfk_1` FOREIGN KEY (`cnum`) REFERENCES `card` (`cnum`) ON DELETE RESTRICT ON UPDATE RESTRICT,
CONSTRAINT `borrow_ibfk_2` FOREIGN KEY (`bnum`) REFERENCES `book` (`bnum`) ON DELETE RESTRICT ON UPDATE RESTRICT
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci ROW_FORMAT = Dynamic;
-- ----------------------------
-- Records of borrow
-- ----------------------------
INSERT INTO `borrow` VALUES ('1231231', '111', '2024-05-20 19:07:24', '2024-05-27 19:07:24', 1);
-- ----------------------------
-- Table structure for card
-- ----------------------------
DROP TABLE IF EXISTS `card`;
CREATE TABLE `card` (
`cnum` char(7) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL,
`name` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL,
`department` varchar(40) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL,
`type` char(1) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL,
`numbers` int(0) NULL DEFAULT NULL,
PRIMARY KEY (`cnum`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci ROW_FORMAT = Dynamic;
-- ----------------------------
-- Records of card
-- ----------------------------
INSERT INTO `card` VALUES ('1231231', '试试', '计算机', 'T', 1);
INSERT INTO `card` VALUES ('1234567', '小白', '信息工程', 'S', 0);
SET FOREIGN_KEY_CHECKS = 1;
Loading…
Cancel
Save