-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathview.py
372 lines (326 loc) · 14.5 KB
/
view.py
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
from struct import pack
from tkinter import *
from tkinter.messagebox import *
from tkinter import ttk
from sql import Books, Identity
from Loginstate import *
import hashlib
import LoginPage
#insert a book
class InputFrame(Frame): # 继承Frame类
def __init__(self, master=None):
Frame.__init__(self, master)
self.root = master #定义内部变量root
self.bno = StringVar()
self.category = StringVar()
self.title = StringVar()
self.press= StringVar()
self.year = StringVar()
self.author = StringVar()
self.price = StringVar()
self.total= StringVar()
self.stock= StringVar()
self.minprice = StringVar()
self.maxprice = StringVar()
self.createPage()
def createPage(self):
self.configure(bg="#fffaf4")
Label(self, text='查询图书', font=("华文行楷", 20), justify = CENTER , fg="#86967e",bg="#fffaf4").pack(side = TOP, expand = NO, fill = Y)
column = ['bno', 'category', 'title', 'press', 'year', 'author', 'price', 'total', 'stock']
text_arr = ['编号','类型','书名','出版社','出版日期','作者','价格','总量','在库']
self.tree = ttk.Treeview(self, show="headings", columns=column)
#print the heading of book lists
for i in range(len(column)):
self.tree.heading(column[i], text=text_arr[i])
self.tree.column(column[i],width=80,anchor='center')
#self.tree.place(x=200,y=200,width=600,height=1000)
self.tree.pack(side = RIGHT, expand = YES, fill=Y)#一定要加这个pack,才能让表格显示出来
Label(self, text=" ",bg="#fffaf4").pack(side=BOTTOM)
Button(self ,text='借阅图书',command=self.lendbook).pack(side=BOTTOM)
Label(self, text=" ",bg="#fffaf4").pack(side=BOTTOM)
Button(self, text='满足任一条件查询', command=self.checkBook).pack(side=BOTTOM)
Label(self, text=" ",bg="#fffaf4").pack(side=BOTTOM)
Button(self, text='满足全部条件查询', command=self.check1Book).pack(side=BOTTOM)
Label(self, text=" ",bg="#fffaf4").pack(side=BOTTOM)
Label(self, text = '书籍类型: ',bg="#fffaf4").pack(side = TOP)
Entry(self, textvariable=self.category).pack(side = TOP)
Label(self, text = '书籍名称: ',bg="#fffaf4").pack(side = TOP)
Entry(self, textvariable=self.title).pack(side = TOP)
Label(self, text = '出版社: ',bg="#fffaf4").pack(side=TOP)
Entry(self, textvariable=self.press).pack(side=TOP)
Label(self, text = '作者: ',bg="#fffaf4").pack(side=TOP)
Entry(self, textvariable=self.author).pack(side=TOP)
Label(self, text = '出版年份: ',bg="#fffaf4").pack(side=TOP)
Entry(self, textvariable=self.year).pack(side=TOP)
Label(self, text = '价格区间: ',bg="#fffaf4").pack(side=TOP)
Label(self, text=" ",bg="#fffaf4").pack(side=LEFT)
Entry(self, textvariable=self.minprice).pack(side=LEFT)
Label(self, text = '~',bg="#fffaf4").pack(side=LEFT)
Entry(self, textvariable=self.maxprice).pack(side=LEFT)
Label(self, text=" ",bg="#fffaf4").pack(side=BOTTOM)
def addResult(self,book_arr):
try:
for book in book_arr:
values=[]
print(book)
values.append(book['bno'])
values.append(book["category"])
values.append(book["title"])
values.append(book["press"])
values.append(book["year"])
values.append(book["author"])
values.append(book["price"])
values.append(book["total"])
values.append(book["stock"])
self.tree.insert('','end',values=values)
except:
showinfo('警告!','获取图书数据失败!')
def lendbook(self):
bno = 0
curitem = self.tree.focus()
card = self.tree.item(curitem,option='values')
if(card != ''): bno = card[0]
print(card[-1])
newstock = int(card[-1])
newstock = newstock-1
print(newstock)
if bno == 0:
showinfo('警告!',"请点击图书信息再借阅")
else:
res = Books().lendBook(Loginstate().search(),bno)
if res==1:
showinfo('提示',"借阅图书成功!")
card = list(card)
card[8]=newstock
card = tuple(card)
print(card)
#self.tree.delete(curitem)
self.tree.item(curitem,values=card)
else:
showinfo('提示','库存不够了,请等待还书!')
def checkBook(self):
x=self.tree.get_children()
for item in x:
self.tree.delete(item)
bno = self.bno.get()
category = self.category.get()
title = self.title.get()
press = self.press.get()
year = self.year.get()
author = self.author.get()
minprice = self.minprice.get()
maxprice = self.maxprice.get()
total = self.total.get()
stock = self.stock.get()
if(title != ''):
res=[]
res = Books().queryBookbyName(title)
self.addResult(res)
if(press != ''):
res=[]
res = Books().queryBookbyPress(press)
self.addResult(res)
if(year != ''):
res=[]
res = Books().queryBookbyYear(year)
self.addResult(res)
if(author != ''):
res=[]
res = Books().queryBookbyAuthor(author)
self.addResult(res)
if(category != ''):
res=[]
res = Books().queryBookbyCategory(category)
self.addResult(res)
if(minprice != '' or maxprice != ''):
res=[]
res = Books().queryBookbyPrice(minprice,maxprice)
self.addResult(res)
print("Insert successful")
def check1Book(self):
x=self.tree.get_children()
for item in x:
self.tree.delete(item)
bno = self.bno.get()
category = self.category.get()
title = self.title.get()
press = self.press.get()
year = self.year.get()
author = self.author.get()
minprice = self.minprice.get()
maxprice = self.maxprice.get()
total = self.total.get()
stock = self.stock.get()
if(title=='' or press=='' or author=='' or category=='' or minprice=='' or maxprice==''):
showinfo('警告!',"请完成全部条件再查询")
else:
res=[]
res = Books().queryBookbyAll(title, press, author, category, minprice, maxprice)
self.addResult(res)
print("Insert successful")
#show all the lend record
class QueryFrame(Frame): # 继承Frame类
def __init__(self, master=None):
Frame.__init__(self, master)
self.root = master #定义内部变量root
self.itemName = StringVar()
self.createPage()
def createPage(self):
self.configure(bg="#fffaf4")
Label(self, text='归还图书', font=("华文行楷", 20), fg="#86967e",bg="#fffaf4").pack()
column = ['id', 'bno', 'title', 'cardID', 'username', 'lendDate', 'backDate']
text_arr = ['编号','书籍编号','书名','借书证号','借阅人','借出时间','归还时间']
self.tree = ttk.Treeview(self, show="headings", columns=column)
#print the heading of book lists
for i in range(len(column)):
self.tree.heading(column[i], text=text_arr[i])
self.tree.column(column[i],width=100,anchor='center')
self.tree.place(x=200,y=20,width=900,height=900)
self.tree.pack()#一定要加这个pack,才能让表格显示出来
userid = Loginstate().search()
print(userid)
record_arr = Books().queryRecordbyId(userid)
try:
for record in record_arr:
values=[]
values.append(record['id'])
values.append(record["bno"])
values.append(record["title"])
values.append(record["cardID"])
values.append(record["username"])
values.append(record["lendDate"])
values.append(record["backDate"])
#print(values)
self.tree.insert('','end',values=values)
except:
showinfo('警告!','获取借阅数据失败!')
Button(self ,text='归还图书',command=self.returnbook).pack()
def returnbook(self):
id = 0
curitem = self.tree.focus()
card = self.tree.item(curitem,option='values')
if(card != ''): id = card[0]
if id == 0:
showinfo('警告!',"请点击借阅信息再归还")
else:
Books().returnBook(id)
self.tree.delete(curitem)
showinfo('提示',"归还图书成功!")
#show all users
class CountFrame(Frame): # 继承Frame类
def __init__(self, master=None):
Frame.__init__(self, master)
self.root = master #定义内部变量root
self.createPage()
def createPage(self):
self.configure(bg="#fffaf4")
Label(self, text='借阅图书', font=("华文行楷", 20), fg="#86967e",bg="#fffaf4").pack()
column = ['bno', 'category', 'title', 'press', 'year', 'author', 'price', 'total', 'stock']
text_arr = ['编号','类型','书名','出版社','出版日期','作者','价格','总量','在库']
self.tree = ttk.Treeview(self, show="headings", columns=column)
#print the heading of book lists
for i in range(len(column)):
self.tree.heading(column[i], text=text_arr[i])
self.tree.column(column[i],width=100,anchor='center')
self.tree.place(x=200,y=20,width=900,height=1900)
self.tree.pack()#一定要加这个pack,才能让表格显示出来
book_arr = Books().allBook()
try:
for book in book_arr:
values=[]
values.append(book['bno'])
values.append(book["category"])
values.append(book["title"])
values.append(book["press"])
values.append(book["year"])
values.append(book["author"])
values.append(book["price"])
values.append(book["total"])
values.append(book["stock"])
self.tree.insert('','end',values=values)
except:
showinfo('警告!','获取图书数据失败!')
Button(self ,text='借阅图书',command=self.lendbook).pack()
def lendbook(self):
bno = 0
curitem = self.tree.focus()
card = self.tree.item(curitem,option='values')
if(card != ''): bno = card[0]
print(card[-1])
newstock = int(card[-1])
newstock = newstock-1
print(newstock)
if bno == 0:
showinfo('警告!',"请点击图书信息再借阅")
else:
res = Books().lendBook(Loginstate().search(),bno)
if res==1:
showinfo('提示',"借阅图书成功!")
card = list(card)
card[8]=newstock
card = tuple(card)
print(card)
#self.tree.delete(curitem)
self.tree.item(curitem,values=card)
elif res==2:
showinfo('警告!',"您已经借阅此图书,请归还再借阅!")
else:
showinfo('警告','库存不够,请等待还书!')
#Show all the books
class AboutFrame(Frame): # 继承Frame类
def __init__(self, master=None):
Frame.__init__(self, master)
self.root = master #定义内部变量root
self.password = StringVar()
self.createPage()
def createPage(self):
self.configure(bg="#fffaf4")
Label(self, text='个人信息', font=("华文行楷", 20), fg="#86967e",bg="#fffaf4").pack()
cardid = Loginstate().search()
print("view")
print(cardid)
userInf = Identity().userIdentity(cardid)
Label(self, text=('卡号: '+str(userInf[0]["cardID"])),bg="#fffaf4").pack()
Label(self, text=('姓名: '+userInf[0]["username"]),bg="#fffaf4").pack()
Label(self, text=('工作: '+userInf[0]["userwork"]),bg="#fffaf4").pack()
Label(self, text=('用户名: '+userInf[0]["userid"]),bg="#fffaf4").pack()
Label(self, text=('密码: 保密 '),bg="#fffaf4").pack()
Entry(self, textvariable=self.password).pack()
Button(self, text='更改密码', command=self.changepwd).pack()
Label(self, text='全部借阅记录', font=("华文行楷", 14), fg="#86967e",bg="#fffaf4").pack()
column = ['id', 'bno', 'title', 'cardID', 'username', 'lendDate', 'backDate']
text_arr = ['编号','书籍编号','书名','借书证号','借阅人','借出时间','归还时间']
self.tree = ttk.Treeview(self, show="headings", columns=column)
#print the heading of book lists
for i in range(len(column)):
self.tree.heading(column[i], text=text_arr[i])
self.tree.column(column[i],width=100,anchor='center')
self.tree.place(x=200,y=20,width=900,height=900)
self.tree.pack()#一定要加这个pack,才能让表格显示出来
userid = Loginstate().search()
print(userid)
record_arr = Books().queryAllRecordbyId(userid)
try:
for record in record_arr:
values=[]
values.append(record['id'])
values.append(record["bno"])
values.append(record["title"])
values.append(record["cardID"])
values.append(record["username"])
values.append(record["lendDate"])
if record["backDate"]==None:
values.append("待归还")
else: values.append(record["backDate"])
#print(values)
self.tree.insert('','end',values=values)
except:
showinfo('警告!','获取借阅数据失败!')
def changepwd(self):
secret = self.password.get()
if secret=='':
showinfo('警告!','请输入新密码!')
else:
encrypt=hashlib.md5(secret.encode()).hexdigest()
Identity().changepwd(Loginstate().search() ,encrypt)
showinfo('提示','密码更改成功')