-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdisplay.py
484 lines (430 loc) · 20.7 KB
/
display.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
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'display.ui'
#
# Created by: PyQt5 UI code generator 5.15.0
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again. Do not edit this file unless you know what you are doing.
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from PyQt5.QtGui import *
import sys
import login
import apply
import psycopg2
import datetime
display_signal = "abc"
class Ui_display(object):
def setupUi(self, display):
self.window = display
display.setObjectName("display")
display.resize(1000, 680)
display.setMinimumSize(QtCore.QSize(1000, 680))
display.setMaximumSize(QtCore.QSize(1000, 680))
self.AllWESALON = QtWidgets.QLabel(display)
self.AllWESALON.setGeometry(QtCore.QRect(50, 10, 311, 81))
font = QtGui.QFont()
font.setPointSize(20)
self.AllWESALON.setFont(font)
self.AllWESALON.setObjectName("AllWESALON")
self.WESALONTable = QtWidgets.QTableWidget(display)
self.WESALONTable.setGeometry(QtCore.QRect(50, 100, 901, 461))
self.WESALONTable.setObjectName("WESALONTable")
self.WESALONTable.setColumnCount(10)
self.WESALONTable.setRowCount(0)
item = QtWidgets.QTableWidgetItem()
self.WESALONTable.setHorizontalHeaderItem(0, item)
item = QtWidgets.QTableWidgetItem()
self.WESALONTable.setHorizontalHeaderItem(1, item)
item = QtWidgets.QTableWidgetItem()
self.WESALONTable.setHorizontalHeaderItem(2, item)
item = QtWidgets.QTableWidgetItem()
self.WESALONTable.setHorizontalHeaderItem(3, item)
item = QtWidgets.QTableWidgetItem()
self.WESALONTable.setHorizontalHeaderItem(4, item)
item = QtWidgets.QTableWidgetItem()
self.WESALONTable.setHorizontalHeaderItem(5, item)
item = QtWidgets.QTableWidgetItem()
self.WESALONTable.setHorizontalHeaderItem(6, item)
item = QtWidgets.QTableWidgetItem()
self.WESALONTable.setHorizontalHeaderItem(7, item)
item = QtWidgets.QTableWidgetItem()
self.WESALONTable.setHorizontalHeaderItem(8, item)
item = QtWidgets.QTableWidgetItem()
self.WESALONTable.setHorizontalHeaderItem(9, item)
self.WESALONTable.horizontalHeader().setSortIndicatorShown(False)
self.WESALONTable.horizontalHeader().setStretchLastSection(False)
self.WESALONTable.setEditTriggers(QAbstractItemView.NoEditTriggers)
self.WESALONTable.setSelectionBehavior(QAbstractItemView.SelectRows)
self.ApplyWESALON = QtWidgets.QPushButton(display)
self.ApplyWESALON.setGeometry(QtCore.QRect(50, 580, 151, 51))
self.ApplyWESALON.setObjectName("ApplyWESALON")
self.SortEdit = QtWidgets.QComboBox(display)
self.SortEdit.setGeometry(QtCore.QRect(540, 580, 241, 41))
self.SortEdit.setObjectName("SortEdit")
self.SortEdit.addItem("")
self.SortEdit.addItem("")
self.SortEdit.addItem("")
self.SortEdit.addItem("")
self.SortEdit.addItem("")
self.SortEdit.addItem("")
self.SortEdit.addItem("")
self.SortEdit.addItem("")
self.SortEdit.addItem("")
self.SortEdit.addItem("")
self.SortEdit.addItem("")
self.SortEdit.addItem("")
self.SortEdit.addItem("")
self.SortEdit.addItem("")
self.SortEdit.addItem("")
self.SortEdit.addItem("")
self.SortEdit.addItem("")
self.SortEdit.addItem("")
self.SortEdit.addItem("")
self.SortEdit.setItemText(18, "")
self.SortLabel = QtWidgets.QLabel(display)
self.SortLabel.setGeometry(QtCore.QRect(450, 590, 72, 15))
self.SortLabel.setObjectName("SortLabel")
self.FlushButton = QtWidgets.QPushButton(display)
self.FlushButton.setGeometry(QtCore.QRect(860, 580, 93, 28))
self.FlushButton.setObjectName("FlushButton")
self.IDMessage = QtWidgets.QLabel(display)
self.IDMessage.setGeometry(QtCore.QRect(280, 40, 101, 21))
self.IDMessage.setObjectName("IDMessage")
self.FilterLabel = QtWidgets.QLabel(display)
self.FilterLabel.setGeometry(QtCore.QRect(431, 50, 141, 20))
self.FilterLabel.setObjectName("FilterLabel")
self.FilterWord = QtWidgets.QLineEdit(display)
self.FilterWord.setGeometry(QtCore.QRect(530, 40, 221, 41))
self.FilterWord.setObjectName("FilterWord")
self.SearchButton = QtWidgets.QPushButton(display)
self.SearchButton.setGeometry(QtCore.QRect(790, 50, 93, 28))
self.SearchButton.setObjectName("SearchButton")
self.SortButton = QtWidgets.QPushButton(display)
self.SortButton.setGeometry(QtCore.QRect(610, 630, 93, 28))
self.SortButton.setObjectName("SortButton")
self.JoinButton = QtWidgets.QPushButton(display)
self.JoinButton.setGeometry(QtCore.QRect(230, 580, 141, 51))
self.JoinButton.setObjectName("JoinButton")
self.retranslateUi(display)
QtCore.QMetaObject.connectSlotsByName(display)
# 改变左上角Label的名字
_translate = QtCore.QCoreApplication.translate
self.IDMessage.setText(_translate("display", display_signal))
# 添加申请活动按钮信号和槽
self.ApplyWESALON.clicked.connect(self.GoToApply)
# 添加刷新按钮信号和槽
self.FlushButton.clicked.connect(lambda:self.LoadTable())
# 添加排序按钮信号和槽
self.SortButton.clicked.connect(lambda:self.SortTable())
# 添加筛选按钮信号和槽
self.SearchButton.clicked.connect(lambda:self.LoadTableSearch())
# 添加筛选按钮信号和槽
self.JoinButton.clicked.connect(lambda: self.JoinAct())
def SortTable(self):
sortindex = self.SortEdit.currentText()
if sortindex == "按活动ID(ASC)":
self.WESALONTable.sortItems(1, Qt.AscendingOrder)
return
elif sortindex == "按活动ID(DESC)":
self.WESALONTable.sortItems(1, Qt.DescendingOrder)
return
elif sortindex == "按活动名字(ASC)":
self.WESALONTable.sortItems(2, Qt.AscendingOrder)
return
elif sortindex == "按活动名字(DESC)":
self.WESALONTable.sortItems(2, Qt.DescendingOrder)
return
elif sortindex == "按举办人(ASC)":
self.WESALONTable.sortItems(3, Qt.AscendingOrder)
return
elif sortindex == "按举办人(DESC)":
self.WESALONTable.sortItems(3, Qt.DescendingOrder)
return
elif sortindex == "按开始时间(ASC)":
self.WESALONTable.sortItems(4, Qt.AscendingOrder)
return
elif sortindex == "按开始时间(DESC)":
self.WESALONTable.sortItems(4, Qt.DescendingOrder)
return
elif sortindex == "按结束时间(ASC)":
self.WESALONTable.sortItems(5, Qt.AscendingOrder)
return
elif sortindex == "按结束时间(DESC)":
self.WESALONTable.sortItems(5, Qt.DescendingOrder)
return
elif sortindex == "按活动地点(ASC)":
self.WESALONTable.sortItems(6, Qt.AscendingOrder)
return
elif sortindex == "按活动地点(DESC)":
self.WESALONTable.sortItems(6, Qt.DescendingOrder)
return
elif sortindex == "按活动容量(ASC)":
self.WESALONTable.sortItems(7, Qt.AscendingOrder)
return
elif sortindex == "按活动容量(DESC)":
self.WESALONTable.sortItems(7, Qt.DescendingOrder)
return
elif sortindex == "按已加入人数(ASC)":
self.WESALONTable.sortItems(8, Qt.AscendingOrder)
return
elif sortindex == "按已加入人数(DESC)":
self.WESALONTable.sortItems(8, Qt.DescendingOrder)
return
elif sortindex == "按活动状态(ASC)":
self.WESALONTable.sortItems(9, Qt.AscendingOrder)
return
elif sortindex == "按活动状态(DESC)":
self.WESALONTable.sortItems(9, Qt.DescendingOrder)
return
def LoadTable(self):
nowtime1 = datetime.datetime.now()
try:
conn = psycopg2.connect(
user = 'postgres',
password = 'patrick+',
host = '127.0.0.1',
database = 'postgres',
port = 5432
)
cursor = conn.cursor()
query = "SELECT * FROM ACTIVITY"
cursor.execute(query)
rows = cursor.fetchall()
row = cursor.rowcount # 取得记录个数,用于设置表格的行数
if row == 0:
return
vol = len(rows[0]) # 取得字段数,用于设置表格的列数
query1 = "SELECT ACT_ID, STU_ID FROM PARTICIPATE"
cursor.execute(query1)
partable = cursor.fetchall()
parrow = cursor.rowcount # 取得记录个数,用于设置表格的行数
self.WESALONTable.setRowCount(row)
for i in range(row):
for j in range(vol):
temp_data = rows[i][j] # 临时记录,不能直接插入表格
data = QTableWidgetItem(str(temp_data)) # 转换后可插入表格
self.WESALONTable.setItem(i, j, data)
if rows[i][3] > nowtime1:
self.WESALONTable.setItem(i, 8, QTableWidgetItem(str("reserved")))
elif rows[i][4] < nowtime1:
self.WESALONTable.setItem(i, 8, QTableWidgetItem(str("finished")))
else:
self.WESALONTable.setItem(i, 8, QTableWidgetItem(str("ongoing")))
if self.IDMessage.text() == rows[i][2]:
self.WESALONTable.setItem(i, 9, QTableWidgetItem(str("我是举办人")))
elif rows[i][6] == rows[i][7] or nowtime1 >= rows[i][3]:
self.WESALONTable.setItem(i, 9, QTableWidgetItem(str("无法加入")))
else:
for k in range(parrow):
if partable[k][0] == rows[i][0] and partable[k][1] == self.IDMessage.text():
self.WESALONTable.setItem(i, 9, QTableWidgetItem(str("已参加")))
return
self.WESALONTable.setItem(i, 9, QTableWidgetItem(str("未参加")))
'''
if rows[i][2] != self.IDMessage.text() and rows[i][6] > rows[i][7] and rows[i][3] > nowtime1:
self.JoinButton = QPushButton('加入活动')
self.JoinButton.setDown(True)
self.JoinButton.setStyleSheet('QPushButton{margin:3px}')
self.WESALONTable.setCellWidget(i, 9, self.JoinButton)
#self.JoinButton.clicked.connect(print("qq"))
#lambda: self.JoinActivity(row[i][0], row[i][2])
'''
except psycopg2.Error as err:
print(err)
else:
conn.close()
def LoadTableSearch(self):
nowtime1 = datetime.datetime.now()
try:
conn = psycopg2.connect(
user = 'postgres',
password = 'patrick+',
host = '127.0.0.1',
database = 'postgres',
port = 5432
)
cursor = conn.cursor()
query = "SELECT * FROM ACTIVITY WHERE ACT_NAME LIKE '%%%s%%'" % self.FilterWord.text()
cursor.execute(query)
rows = cursor.fetchall()
row = cursor.rowcount # 取得记录个数,用于设置表格的行数
if row == 0:
return
vol = len(rows[0]) # 取得字段数,用于设置表格的列数
self.WESALONTable.setRowCount(row)
for i in range(row):
for j in range(vol):
temp_data = rows[i][j] # 临时记录,不能直接插入表格
data = QTableWidgetItem(str(temp_data)) # 转换后可插入表格
self.WESALONTable.setItem(i, j, data)
if rows[i][3] > nowtime1:
self.WESALONTable.setItem(i, 8, QTableWidgetItem(str("reserved")))
elif rows[i][4] < nowtime1:
self.WESALONTable.setItem(i, 8, QTableWidgetItem(str("finished")))
else:
self.WESALONTable.setItem(i, 8, QTableWidgetItem(str("ongoing")))
if self.IDMessage.text() == rows[i][2]:
self.WESALONTable.setItem(i, 9, QTableWidgetItem(str("我是举办人")))
elif rows[i][6] == rows[i][7] or nowtime1 >= rows[i][3]:
self.WESALONTable.setItem(i, 9, QTableWidgetItem(str("无法加入")))
else:
for k in range(parrow):
if partable[k][0] == rows[i][0] and partable[k][1] == self.IDMessage.text():
self.WESALONTable.setItem(i, 9, QTableWidgetItem(str("已参加")))
return
self.WESALONTable.setItem(i, 9, QTableWidgetItem(str("未参加")))
'''
if rows[i][2] != self.IDMessage.text() and rows[i][6] > rows[i][7] and rows[i][3] > nowtime1:
self.JoinButton = QPushButton('加入活动')
self.JoinButton.setDown(True)
self.JoinButton.setStyleSheet('QPushButton{margin:3px}')
self.WESALONTable.setCellWidget(i, 9, self.JoinButton)
#self.JoinButton.clicked.connect(print("qq"))
#lambda: self.JoinActivity(row[i][0], row[i][2])
'''
except psycopg2.Error as err:
print(err)
else:
conn.close()
def JoinAct(self):
nowtime1 = datetime.datetime.now()
row = self.WESALONTable.currentRow()
newstu = self.IDMessage.text()
newact = self.WESALONTable.item(row, 0).text()
newstart = self.WESALONTable.item(row, 3).text()
newend = self.WESALONTable.item(row, 4).text()
oldcurrent = self.WESALONTable.item(row, 7).text()
newcurrent1 = int(oldcurrent) + 1
newcurrent2 = str(newcurrent1)
temp = self.WESALONTable.item(row, 9).text()
print("qq")
try:
print("into try")
conn = psycopg2.connect(
user='postgres',
password='patrick+',
host='127.0.0.1',
database='postgres',
port=5432
)
cursor = conn.cursor()
print("qq1")
query = "SELECT ACT_ID, ACT_STARTTIME, ACT_ENDTIME FROM ACTIVITY WHERE ACT_ID IN (SELECT ACT_ID FROM PARTICIPATE WHERE STU_ID = %s)"
cursor.execute(query, (newstu,))
temprows = cursor.fetchall()
temprow = cursor.rowcount
print("qq2")
# b = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
for i in range(temprow):
print(temprows[i][1], newstart, temprows[i][2], newend)
if (temprows[i][1].strftime('%Y-%m-%d %H:%M:%S') <= newstart and newstart <= temprows[i][2].strftime('%Y-%m-%d %H:%M:%S')) or (temprows[i][1].strftime('%Y-%m-%d %H:%M:%S') <= newend and newend <= temprows[i][2].strftime('%Y-%m-%d %H:%M:%S')):
QMessageBox.information(self.window, '错误', '时间冲突', QMessageBox.Yes)
return
print("qq3")
if temp == "未参加":
query2 = "INSERT INTO PARTICIPATE (ACT_ID, STU_ID, PAR_TIME) VALUES (%s, %s, %s)"
cursor.execute(query2, (newact, newstu, nowtime1))
conn.commit()
print("qq4")
query3 = "UPDATE ACTIVITY SET CURRENTNUM = %s WHERE ACT_ID = %s"
print("pp")
cursor.execute(query3, (newcurrent1, newact))
print("oo")
conn.commit()
print("qq5")
self.LoadTable()
print("qq6")
else:
return
except psycopg2.Error as err:
print("We have a problem")
print(err)
else:
conn.close()
'''
def JoinActivity(self, newact, newstu):
print("love")
try:
conn = psycopg2.connect(
user='postgres',
password='sniperwwz',
host='127.0.0.1',
database='postgres',
port=5433
)
cursor = conn.cursor()
query2 = "INSERT INTO PARTICIPATE (ACT_ID, STU_ID, PAR_TIME) VALUES (%s, %s, %s)"
cursor.execute(query2, (newact, newstu, nowtime1))
conn.commit()
self.JoinButton.setEnabeld(False)
return
except psycopg2.Error as err:
print(err)
else:
conn.close()
'''
def GoToApply(self):
form1 = QtWidgets.QDialog()
self.ui = apply.Ui_apply()
self.ui.setupUi(form1)
form1.show()
form1.exec_()
def retranslateUi(self, display):
_translate = QtCore.QCoreApplication.translate
display.setWindowTitle(_translate("display", "所有WESALON"))
self.AllWESALON.setText(_translate("display", "所有WESALON"))
item = self.WESALONTable.horizontalHeaderItem(0)
item.setText(_translate("display", "活动ID"))
item = self.WESALONTable.horizontalHeaderItem(1)
item.setText(_translate("display", "活动名字"))
item = self.WESALONTable.horizontalHeaderItem(2)
item.setText(_translate("display", "举办人"))
item = self.WESALONTable.horizontalHeaderItem(3)
item.setText(_translate("display", "开始时间"))
item = self.WESALONTable.horizontalHeaderItem(4)
item.setText(_translate("display", "结束时间"))
item = self.WESALONTable.horizontalHeaderItem(5)
item.setText(_translate("display", "活动地点"))
item = self.WESALONTable.horizontalHeaderItem(6)
item.setText(_translate("display", "活动容量"))
item = self.WESALONTable.horizontalHeaderItem(7)
item.setText(_translate("display", "已加入人数"))
item = self.WESALONTable.horizontalHeaderItem(8)
item.setText(_translate("display", "活动状态"))
item = self.WESALONTable.horizontalHeaderItem(9)
item.setText(_translate("display", "是否已加入"))
self.ApplyWESALON.setText(_translate("display", "申请活动"))
self.SortEdit.setItemText(0, _translate("display", "按活动ID(ASC)"))
self.SortEdit.setItemText(1, _translate("display", "按活动ID(DESC)"))
self.SortEdit.setItemText(2, _translate("display", "按活动名字(ASC)"))
self.SortEdit.setItemText(3, _translate("display", "按活动名字(DESC)"))
self.SortEdit.setItemText(4, _translate("display", "按举办人(ASC)"))
self.SortEdit.setItemText(5, _translate("display", "按举办人(DESC)"))
self.SortEdit.setItemText(6, _translate("display", "按开始时间(ASC)"))
self.SortEdit.setItemText(7, _translate("display", "按开始时间(DESC)"))
self.SortEdit.setItemText(8, _translate("display", "按结束时间(ASC)"))
self.SortEdit.setItemText(9, _translate("display", "按结束时间(DESC)"))
self.SortEdit.setItemText(10, _translate("display", "按活动状态(ASC)"))
self.SortEdit.setItemText(11, _translate("display", "按活动状态(DESC)"))
self.SortEdit.setItemText(12, _translate("display", "按活动地点(ASC)"))
self.SortEdit.setItemText(13, _translate("display", "按活动地点(DESC)"))
self.SortEdit.setItemText(14, _translate("display", "按活动容量(ASC)"))
self.SortEdit.setItemText(15, _translate("display", "按活动容量(DESC)"))
self.SortEdit.setItemText(16, _translate("display", "按已加入人数(ASC)"))
self.SortEdit.setItemText(17, _translate("display", "按已加入人数(DESC)"))
self.SortLabel.setText(_translate("display", "排序条件"))
self.FlushButton.setText(_translate("display", "刷新"))
self.IDMessage.setText(_translate("display", "ID"))
self.FilterLabel.setText(_translate("display", "筛选关键词"))
self.SearchButton.setText(_translate("display", "查询"))
self.SortButton.setText(_translate("display", "排序"))
self.JoinButton.setText(_translate("display", "加入活动"))
if __name__ == "__main__":
app = QApplication(sys.argv)
form = QtWidgets.QWidget()
window = Ui_display()
window.setupUi(form)
form.show()
sys.exit(app.exec_())