-
Notifications
You must be signed in to change notification settings - Fork 0
/
admin.py
235 lines (192 loc) · 8.25 KB
/
admin.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
from threading import Thread
from PyQt5.QtCore import *
from adminWindow import Ui_adminWindow
from database import dataBase
from newAdmin import newAdmin
from PyQt5.QtWidgets import *
class admin(Ui_adminWindow, QMainWindow):
sig_cat = pyqtSignal(list)
sig_wit = pyqtSignal(list)
sig_feed = pyqtSignal(list)
def __init__(self, username):
super(admin, self).__init__()
self.setupUi(self)
self.activateButton()
self.setWindowTitle('校园猫管理平台(管理员端)')
self.fillBox()
self.sig_cat.connect(self.genCatTable)
self.sig_wit.connect(self.genWitTable)
self.sig_feed.connect(self.genFeedTable)
self.sizeTables()
self.showCat()
self.showWitness()
self.showFeed()
self.username = username
self.newAdminWindow = None
def activateButton(self):
self.catinfoBtn.clicked.connect(self.switch)
self.witnessBtn.clicked.connect(self.switch)
self.feedBtn.clicked.connect(self.switch)
self.newAdminBtn.clicked.connect(self.newAdmin)
self.addCatButton.clicked.connect(self.addCat)
self.addWitButton.clicked.connect(self.addWitness)
self.addFeedBtn.clicked.connect(self.addFeed)
def switch(self):
sender = self.sender()
if sender.text() == '猫猫花名册':
self.stackedWidget.setCurrentIndex(0)
if sender.text() == '猫猫位置打卡':
self.stackedWidget.setCurrentIndex(1)
if sender.text() == '记录我的投喂':
self.stackedWidget.setCurrentIndex(2)
def newAdmin(self):
self.newAdminWindow = newAdmin()
self.newAdminWindow.show()
def fillBox(self):
self.feedCatBox.clear()
self.witCatNameBox.clear()
database = dataBase()
cnt, cat = database.selectAll('cat')
self.witCatNameBox.addItems(a[4] for a in cat)
self.feedCatBox.addItems(a[4] for a in cat)
cnt, location = database.selectAll('location')
self.addLocBox.addItems(a[1] for a in location)
self.feedLocBox.addItems(a[1] for a in location)
self.witLocBox.addItems(a[1] for a in location)
cnt, food = database.selectAll('food')
self.feedFoodBox.addItems(a[1] for a in food)
cmt, vac = database.selectAll('vacinfo')
self.addCatVacBox.addItems(a[1] for a in vac)
def showCat(self):
thread = Thread(target=self.getCatView())
thread.start()
def getCatView(self):
database = dataBase()
cnt, res = database.getCatView()
self.sig_cat.emit([cnt, res])
def genCatTable(self, res):
catView = res[1] # res第0个是cnt,第1个是集合的集合
column = len(catView[0]) # 列数
row = 0
for info in catView:
if self.catTabel.rowCount() <= row:
self.catTabel.insertRow(row)
for i in range(column):
itemValue = info[i]
item = QTableWidgetItem(str(itemValue))
self.catTabel.setItem(row, i, item)
row = row + 1
for i in range(row):
for j in range(column):
item = self.catTabel.item(i, j)
item.setTextAlignment(Qt.AlignVCenter | Qt.AlignHCenter)
def addCat(self):
catName = self.addCatNameEdit.text()
catGender = self.addCatGenderBox.currentText()
catRace = self.AddCatRaceEdit.text()
catLoc = self.addLocBox.currentText()
catVac = self.addCatVacBox.currentText()
catOther = self.addOtherEdit.toPlainText()
if '' in [catName, catRace]:
QMessageBox.information(self, '提示', '除了备注都是必填~请检查表单', QMessageBox.Ok)
return
database = dataBase()
cnt, res = database.select('cat', 'catName', catName)
if cnt > 0:
QMessageBox.information(self, '提示', '该猫已存在,或与档案内的猫重名', QMessageBox.Ok)
cnt, res = database.select('catrace', 'raceName', catRace)
if cnt == 0:
database.addRace(catRace)
raceNum = database.getRaceNum(catRace)
locNum = database.getLocNum(catLoc)
vacNum = database.getVacNum(catVac)
database.addCat(vacNum, raceNum, locNum, catName, catGender, catOther)
database.update()
QMessageBox.information(self, '提示', '添加成功', QMessageBox.Ok)
self.addCatNameEdit.clear()
self.addOtherEdit.clear()
self.AddCatRaceEdit.clear()
self.fillBox()
self.showCat()
def showWitness(self):
thread = Thread(target=self.getWitView())
thread.start()
def getWitView(self):
database = dataBase()
cnt, res = database.getWitView()
self.sig_wit.emit([cnt, res])
def genWitTable(self, res):
witView = res[1] # res第0个是cnt,第1个是集合的集合
column = len(witView[0]) # 列数
row = 0
for info in witView:
if self.witnessTable.rowCount() <= row:
self.witnessTable.insertRow(row)
for i in range(column):
itemValue = info[i]
item = QTableWidgetItem(str(itemValue))
self.witnessTable.setItem(row, i, item)
row = row + 1
for i in range(row):
for j in range(column):
item = self.witnessTable.item(i, j)
item.setTextAlignment(Qt.AlignVCenter | Qt.AlignHCenter)
def showFeed(self):
thread = Thread(target=self.getFeedView())
thread.start()
def getFeedView(self):
database = dataBase()
cnt, res = database.getFeedView()
self.sig_feed.emit([cnt, res])
def genFeedTable(self, res):
FeedView = res[1] # res第0个是cnt,第1个是集合的集合
column = len(FeedView[0]) # 列数
row = 0
for info in FeedView:
if self.feedTable.rowCount() <= row:
self.feedTable.insertRow(row)
for i in range(column):
itemValue = info[i]
item = QTableWidgetItem(str(itemValue))
self.feedTable.setItem(row, i, item)
row = row + 1
for i in range(row):
for j in range(column):
item = self.feedTable.item(i, j)
item.setTextAlignment(Qt.AlignVCenter | Qt.AlignHCenter)
def addWitness(self):
userName = self.username
catName = self.witCatNameBox.currentText()
locName = self.witLocBox.currentText()
database = dataBase()
userNum = database.getUserNum(userName)
catNum = database.getCatNum(catName)
locNum = database.getLocNum(locName)
database.addWitness(userNum, locNum, catNum)
database.update()
QMessageBox.information(self, '提示', '添加成功', QMessageBox.Ok)
self.showWitness()
def addFeed(self):
userName = self.username
catName = self.feedCatBox.currentText()
locName = self.feedLocBox.currentText()
foodName = self.feedFoodBox.currentText()
database = dataBase()
userNum = database.getUserNum(userName)
catNum = database.getCatNum(catName)
locNum = database.getLocNum(locName)
foodNum = database.getFoodNum(foodName)
database.addFeed(foodNum, catNum, locNum, userNum)
database.update()
QMessageBox.information(self, '提示', '添加成功', QMessageBox.Ok)
self.showFeed()
def sizeTables(self):
self.catTabel.setEditTriggers(QAbstractItemView.NoEditTriggers)
self.catTabel.horizontalHeader().setSectionResizeMode(QHeaderView.ResizeToContents)
self.catTabel.verticalHeader().setSectionResizeMode(QHeaderView.ResizeToContents)
self.feedTable.setEditTriggers(QAbstractItemView.NoEditTriggers)
self.feedTable.horizontalHeader().setSectionResizeMode(QHeaderView.ResizeToContents)
self.feedTable.verticalHeader().setSectionResizeMode(QHeaderView.ResizeToContents)
self.witnessTable.setEditTriggers(QAbstractItemView.NoEditTriggers)
self.witnessTable.horizontalHeader().setSectionResizeMode(QHeaderView.ResizeToContents)
self.witnessTable.verticalHeader().setSectionResizeMode(QHeaderView.ResizeToContents)