-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStudent.py
More file actions
50 lines (45 loc) · 2.07 KB
/
Student.py
File metadata and controls
50 lines (45 loc) · 2.07 KB
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
from tkinter.constants import NONE
from pymysql import NULL
from Object import Student
from Object import User,ConntectDB
from Select import GetIDByNameAndAuthor,GetBookNumByID,GetBookTimeByID, GetStuNumByID,GetBookNumByID,GetAllBorrowbookByStuID,GetAllBorrowInfoByStuid
import datetime
def BorrowBook(stuID,bookName,bookAuthor):
conn = ConntectDB()
cur = conn.cursor()
id = GetIDByNameAndAuthor(bookName,bookAuthor)
if id == None:
return 2
allBookID = GetAllBorrowbookByStuID(stuID)
bookNum = GetBookNumByID(id)
ti = GetBookTimeByID(id)
stuNum = GetStuNumByID(stuID)
if id in allBookID:
return 1
elif bookNum > 0 and stuNum[0]>stuNum[1]:
str1 = datetime.datetime.now().strftime("%Y-%m-%d")
str2 = (datetime.datetime.now()+datetime.timedelta(days=+ti)).strftime("%Y-%m-%d")
cur.execute("insert into borrow (bookID,stuID,addTime,lastTime) values ('%s','%s','%s','%s')" % (id,stuID,str1,str2))
cur.execute("update book set bookNum = bookNum-1 where id = %s" % id)
cur.execute("update student set nowNum = nowNum+1 where id = %s" % stuID)
conn.commit()
return 5
else:
return 0
def ReturnBook(BorrowInfo,stuID,num):
conn = ConntectDB()
cur = conn.cursor()
bookid = BorrowInfo[num][0]
cur.execute("delete from borrow where bookID = %s and stuID = %s " % (bookid,stuID))
str1 = datetime.datetime.now().strftime("%Y-%m-%d")
if BorrowInfo[num][3]<str1:
cur.execute("update student set nowNum = nowNum-1,maxNum =maxNum-1 where id = %s" % stuID)
else:
cur.execute("update student set nowNum = nowNum-1 where id = %s" % stuID)
cur.execute("update book set bookNum = bookNum+1 where id = %s" % bookid)
conn.commit()
def AddExanime(stu,type,bookName,bookAuthor,bookPrice,bookType):
conn = ConntectDB()
cur = conn.cursor()
cur.execute("insert into examine (stuID,stuName,type,bookName,bookAuthor,bookPrice,bookType) values ('%s','%s','%s','%s','%s','%s','%s')" % (stu.id,stu.name,type,bookName,bookAuthor,bookPrice,bookType))
conn.commit()