-
Notifications
You must be signed in to change notification settings - Fork 0
/
comment.py
153 lines (138 loc) · 6 KB
/
comment.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
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'comment.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 psycopg2
import sys
import datetime
import time
import writecomment
user_id = ""
class Ui_comment(object):
def setupUi(self, comment):
self.window = comment
comment.setObjectName("comment")
comment.resize(1000, 680)
comment.setMinimumSize(QtCore.QSize(1000, 680))
comment.setMaximumSize(QtCore.QSize(1000, 680))
self.COMMENT = QtWidgets.QLabel(comment)
self.COMMENT.setGeometry(QtCore.QRect(430, 20, 351, 81))
font = QtGui.QFont()
font.setPointSize(24)
self.COMMENT.setFont(font)
self.COMMENT.setObjectName("COMMENT")
self.CommentTable = QtWidgets.QTableWidget(comment)
self.CommentTable.setGeometry(QtCore.QRect(60, 130, 881, 441))
self.CommentTable.setObjectName("CommentTable")
self.CommentTable.setColumnCount(8)
self.CommentTable.setRowCount(0)
item = QtWidgets.QTableWidgetItem()
self.CommentTable.setHorizontalHeaderItem(0, item)
item = QtWidgets.QTableWidgetItem()
self.CommentTable.setHorizontalHeaderItem(1, item)
item = QtWidgets.QTableWidgetItem()
self.CommentTable.setHorizontalHeaderItem(2, item)
item = QtWidgets.QTableWidgetItem()
self.CommentTable.setHorizontalHeaderItem(3, item)
item = QtWidgets.QTableWidgetItem()
self.CommentTable.setHorizontalHeaderItem(4, item)
item = QtWidgets.QTableWidgetItem()
self.CommentTable.setHorizontalHeaderItem(5, item)
item = QtWidgets.QTableWidgetItem()
self.CommentTable.setHorizontalHeaderItem(6, item)
item = QtWidgets.QTableWidgetItem()
self.CommentTable.setHorizontalHeaderItem(7, item)
self.CommentButton = QtWidgets.QPushButton(comment)
self.CommentButton.setGeometry(QtCore.QRect(90, 590, 93, 28))
self.CommentButton.setObjectName("CommentButton")
self.FlushButton = QtWidgets.QPushButton(comment)
self.FlushButton.setGeometry(QtCore.QRect(760, 590, 93, 28))
self.FlushButton.setObjectName("FlushButton")
self.retranslateUi(comment)
QtCore.QMetaObject.connectSlotsByName(comment)
self.CommentButton.clicked.connect(self.OnComment)
self.FlushButton.clicked.connect(self.FlushTable)
def retranslateUi(self, comment):
_translate = QtCore.QCoreApplication.translate
comment.setWindowTitle(_translate("comment", "Form"))
self.COMMENT.setText(_translate("comment", "评论天地"))
item = self.CommentTable.horizontalHeaderItem(0)
item.setText(_translate("comment", "活动ID"))
item = self.CommentTable.horizontalHeaderItem(1)
item.setText(_translate("comment", "评论人ID"))
item = self.CommentTable.horizontalHeaderItem(2)
item.setText(_translate("comment", "评论内容"))
item = self.CommentTable.horizontalHeaderItem(3)
item.setText(_translate("comment", "评论时间"))
self.CommentButton.setText(_translate("comment", "评论"))
self.FlushButton.setText(_translate("comment", "刷新"))
def OnComment(self):
form1 = QtWidgets.QDialog()
ui = writecomment.Ui_com()
ui.setupUi(form1)
form1.show()
form1.exec_()
# time.sleep(2)
res = writecomment.cur1
try:
print("into try")
conn = psycopg2.connect(
user='postgres',
password='patrick+',
host='127.0.0.1',
database='postgres',
port=5432
)
cursor = conn.cursor()
query2 = "INSERT INTO COMMENTPLATFORM (ACT_ID, STU_ID, COM_CONTENT, COM_TIME) VALUES (%s, %s, %s, %s)"
strtime = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
cursor.execute(query2, (res.s1, user_id, res.s2, strtime))
conn.commit()
self.FlushTable()
except psycopg2.Error as err:
print("We have a problem")
print(err)
else:
conn.close()
def FlushTable(self):
try:
conn = psycopg2.connect(
user = 'postgres',
password = 'patrick+',
host = '127.0.0.1',
database = 'postgres',
port = 5432
)
cursor = conn.cursor()
query = "SELECT * FROM COMMENTPLATFORM"
cursor.execute(query)
rows = cursor.fetchall()
row = cursor.rowcount
self.CommentTable.setRowCount(row)
if row == 0:
return
vol = len(rows[0])
for i in range(row):
temp_data1 = rows[i][1] # 临时记录,不能直接插入表格
data1 = QTableWidgetItem(str(temp_data1)) # 转换后可插入表格
temp_data2 = rows[i][2] # 临时记录,不能直接插入表格
data2 = QTableWidgetItem(str(temp_data2)) # 转换后可插入表格
temp_data3 = rows[i][3] # 临时记录,不能直接插入表格
data3 = QTableWidgetItem(str(temp_data3)) # 转换后可插入表格
temp_data4 = rows[i][4] # 临时记录,不能直接插入表格
data4 = QTableWidgetItem(str(temp_data4)) # 转换后可插入表格
self.CommentTable.setItem(i, 0, data1)
self.CommentTable.setItem(i, 1, data2)
self.CommentTable.setItem(i, 2, data3)
self.CommentTable.setItem(i, 3, data4)
except psycopg2.Error as err:
print(err)
else:
conn.close()