self.query1_window = QueryResultWindow() self.query2_window = QueryResultWindow() self.query3_window = QueryResultWindow() self.query4_window = QueryResultWindow() def show_query1_result(self): # 查询数据 db = pymysql.connect(host='39.99.214.172', user='root', password='Solotion.123', db='jj_tset') cursor = db.cursor() db_sql = """ """ cursor.execute(db_sql) result = cursor.fetchall() db.close() if len(result) == 0: QMessageBox.information(self, "提示", "今日无员工工资记录") return # 清空表格 self.query1_window.table_widget.setRowCount(0) self.query1_window.table_widget.setColumnCount(len(result[0])) self.query1_window.table_widget.setHorizontalHeaderLabels( ["员工ID", "员工姓名", "日期", "领取鸡爪重量(KG)", "效率(每小时KG)", "出成率", "基础工资", "重量奖励", "当日总工资"]) # 添加数据到表格 for row_num, row_data in enumerate(result): self.query1_window.table_widget.insertRow(row_num) for col_num, col_data in enumerate(row_data): self.query1_window.table_widget.setItem(row_num, col_num, QTableWidgetItem(str(col_data))) # 显示窗口 self.query1_window.show()显示窗口 self.query1_window.show()数据展示页面怎么设置筛选器按ID筛选结果并展示
时间: 2023-11-22 20:53:52 浏览: 43
你可以在查询数据时添加筛选条件,例如:
```python
db_sql = """SELECT * FROM table_name WHERE employee_id = 'your_id'"""
```
其中,`table_name` 为你的表名,`employee_id` 为你的员工ID列名,`your_id` 为你的员工ID。
然后,你需要将查询结果展示到表格中,你可以添加一个文本框和一个按钮,让用户输入ID并点击按钮进行筛选。具体实现可以参考以下代码:
```python
class MyWindow(QWidget):
def __init__(self):
super().__init__()
self.query1_window = QueryResultWindow()
# 添加文本框和按钮
self.id_edit = QLineEdit()
self.filter_btn = QPushButton("筛选")
self.filter_btn.clicked.connect(self.show_filtered_result)
# 布局
layout = QVBoxLayout()
layout.addWidget(QLabel("请输入员工ID:"))
layout.addWidget(self.id_edit)
layout.addWidget(self.filter_btn)
self.setLayout(layout)
def show_filtered_result(self):
# 获取输入的ID
employee_id = self.id_edit.text()
if not employee_id:
QMessageBox.warning(self, "提示", "请输入员工ID")
return
# 查询数据
db = pymysql.connect(host='39.99.214.172', user='root', password='Solotion.123', db='jj_tset')
cursor = db.cursor()
db_sql = """SELECT * FROM table_name WHERE employee_id = '{}'""".format(employee_id)
cursor.execute(db_sql)
result = cursor.fetchall()
db.close()
# 判断结果是否为空
if len(result) == 0:
QMessageBox.information(self, "提示", "无该员工工资记录")
return
# 清空表格
self.query1_window.table_widget.setRowCount(0)
self.query1_window.table_widget.setColumnCount(len(result[0]))
self.query1_window.table_widget.setHorizontalHeaderLabels(
["员工ID", "员工姓名", "日期", "领取鸡爪重量(KG)", "效率(每小时KG)", "出成率", "基础工资", "重量奖励", "当日总工资"])
# 添加数据到表格
for row_num, row_data in enumerate(result):
self.query1_window.table_widget.insertRow(row_num)
for col_num, col_data in enumerate(row_data):
self.query1_window.table_widget.setItem(row_num, col_num, QTableWidgetItem(str(col_data)))
# 显示窗口
self.query1_window.show()
```
其中,`MyWindow` 是你的主窗口,`QueryResultWindow` 是你的数据展示窗口。在 `__init__` 方法中添加了一个文本框和一个按钮,然后在 `show_filtered_result` 方法中获取输入的ID并拼接查询语句,最后将查询结果展示到表格中。请根据你的实际情况进行修改。
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![application/x-zip](https://img-home.csdnimg.cn/images/20210720083736.png)