169 lines
5.7 KiB
Python
169 lines
5.7 KiB
Python
|
|
from PySide6.QtWidgets import (
|
||
|
|
QDialog, QVBoxLayout, QHBoxLayout, QLabel,
|
||
|
|
QTableWidget, QTableWidgetItem, QHeaderView,
|
||
|
|
QPushButton, QComboBox, QFrame, QDateEdit
|
||
|
|
)
|
||
|
|
from PySide6.QtCore import Qt, QDate
|
||
|
|
from PySide6.QtGui import QFont
|
||
|
|
|
||
|
|
class ReportDialogUI(QDialog):
|
||
|
|
def __init__(self, parent=None):
|
||
|
|
super().__init__(parent)
|
||
|
|
self.setWindowTitle("统计报表")
|
||
|
|
self.resize(1000, 600)
|
||
|
|
self.init_ui()
|
||
|
|
|
||
|
|
def init_ui(self):
|
||
|
|
# 设置字体
|
||
|
|
self.title_font = QFont("微软雅黑", 14, QFont.Bold)
|
||
|
|
self.normal_font = QFont("微软雅黑", 12)
|
||
|
|
|
||
|
|
# 主布局
|
||
|
|
self.main_layout = QVBoxLayout(self)
|
||
|
|
self.main_layout.setContentsMargins(10, 10, 10, 10)
|
||
|
|
self.main_layout.setSpacing(10)
|
||
|
|
|
||
|
|
# 创建筛选条件区域
|
||
|
|
self.create_filter_section()
|
||
|
|
|
||
|
|
# 创建报表内容区域
|
||
|
|
self.create_report_section()
|
||
|
|
|
||
|
|
# 创建按钮区域
|
||
|
|
self.create_button_section()
|
||
|
|
|
||
|
|
def create_filter_section(self):
|
||
|
|
"""创建筛选条件区域"""
|
||
|
|
# 筛选条件容器
|
||
|
|
self.filter_frame = QFrame()
|
||
|
|
self.filter_frame.setFrameShape(QFrame.StyledPanel)
|
||
|
|
self.filter_layout = QHBoxLayout(self.filter_frame)
|
||
|
|
|
||
|
|
# 日期选择
|
||
|
|
self.date_label = QLabel("日期范围:")
|
||
|
|
self.date_label.setFont(self.normal_font)
|
||
|
|
self.start_date = QDateEdit()
|
||
|
|
self.start_date.setFont(self.normal_font)
|
||
|
|
self.start_date.setCalendarPopup(True)
|
||
|
|
self.start_date.setDate(QDate.currentDate())
|
||
|
|
self.date_separator = QLabel("-")
|
||
|
|
self.end_date = QDateEdit()
|
||
|
|
self.end_date.setFont(self.normal_font)
|
||
|
|
self.end_date.setCalendarPopup(True)
|
||
|
|
self.end_date.setDate(QDate.currentDate())
|
||
|
|
|
||
|
|
# 报表类型选择
|
||
|
|
self.type_label = QLabel("报表类型:")
|
||
|
|
self.type_label.setFont(self.normal_font)
|
||
|
|
self.type_combo = QComboBox()
|
||
|
|
self.type_combo.setFont(self.normal_font)
|
||
|
|
self.type_combo.addItems(["日报表", "月报表", "年报表"])
|
||
|
|
|
||
|
|
# 查询按钮
|
||
|
|
self.query_button = QPushButton("查询")
|
||
|
|
self.query_button.setFont(self.normal_font)
|
||
|
|
self.query_button.setStyleSheet("""
|
||
|
|
QPushButton {
|
||
|
|
padding: 8px 16px;
|
||
|
|
background-color: #1976D2;
|
||
|
|
color: white;
|
||
|
|
border-radius: 4px;
|
||
|
|
}
|
||
|
|
QPushButton:hover {
|
||
|
|
background-color: #1565C0;
|
||
|
|
}
|
||
|
|
""")
|
||
|
|
|
||
|
|
# 添加组件到筛选布局
|
||
|
|
self.filter_layout.addWidget(self.date_label)
|
||
|
|
self.filter_layout.addWidget(self.start_date)
|
||
|
|
self.filter_layout.addWidget(self.date_separator)
|
||
|
|
self.filter_layout.addWidget(self.end_date)
|
||
|
|
self.filter_layout.addSpacing(20)
|
||
|
|
self.filter_layout.addWidget(self.type_label)
|
||
|
|
self.filter_layout.addWidget(self.type_combo)
|
||
|
|
self.filter_layout.addSpacing(20)
|
||
|
|
self.filter_layout.addWidget(self.query_button)
|
||
|
|
self.filter_layout.addStretch()
|
||
|
|
|
||
|
|
# 添加到主布局
|
||
|
|
self.main_layout.addWidget(self.filter_frame)
|
||
|
|
|
||
|
|
def create_report_section(self):
|
||
|
|
"""创建报表内容区域"""
|
||
|
|
# 报表表格
|
||
|
|
self.report_table = QTableWidget()
|
||
|
|
self.report_table.setFont(self.normal_font)
|
||
|
|
|
||
|
|
# 设置列
|
||
|
|
self.report_table.setColumnCount(8)
|
||
|
|
self.report_table.setHorizontalHeaderLabels([
|
||
|
|
"日期", "工程号", "品名", "规格",
|
||
|
|
"生产数量", "合格数量", "不合格数量", "合格率"
|
||
|
|
])
|
||
|
|
|
||
|
|
# 设置表格样式
|
||
|
|
self.report_table.setStyleSheet("""
|
||
|
|
QTableWidget {
|
||
|
|
border: 1px solid #ddd;
|
||
|
|
gridline-color: #ddd;
|
||
|
|
}
|
||
|
|
QHeaderView::section {
|
||
|
|
background-color: #f5f5f5;
|
||
|
|
padding: 5px;
|
||
|
|
border: 1px solid #ddd;
|
||
|
|
font-weight: bold;
|
||
|
|
}
|
||
|
|
""")
|
||
|
|
|
||
|
|
# 调整列宽
|
||
|
|
header = self.report_table.horizontalHeader()
|
||
|
|
for i in range(8):
|
||
|
|
header.setSectionResizeMode(i, QHeaderView.Stretch)
|
||
|
|
|
||
|
|
# 添加到主布局
|
||
|
|
self.main_layout.addWidget(self.report_table)
|
||
|
|
|
||
|
|
def create_button_section(self):
|
||
|
|
"""创建按钮区域"""
|
||
|
|
# 按钮容器
|
||
|
|
self.button_frame = QFrame()
|
||
|
|
self.button_layout = QHBoxLayout(self.button_frame)
|
||
|
|
|
||
|
|
# 导出按钮
|
||
|
|
self.export_button = QPushButton("导出Excel")
|
||
|
|
self.export_button.setFont(self.normal_font)
|
||
|
|
self.export_button.setStyleSheet("""
|
||
|
|
QPushButton {
|
||
|
|
padding: 8px 16px;
|
||
|
|
background-color: #4CAF50;
|
||
|
|
color: white;
|
||
|
|
border-radius: 4px;
|
||
|
|
}
|
||
|
|
QPushButton:hover {
|
||
|
|
background-color: #43A047;
|
||
|
|
}
|
||
|
|
""")
|
||
|
|
|
||
|
|
# 关闭按钮
|
||
|
|
self.close_button = QPushButton("关闭")
|
||
|
|
self.close_button.setFont(self.normal_font)
|
||
|
|
self.close_button.setStyleSheet("""
|
||
|
|
QPushButton {
|
||
|
|
padding: 8px 16px;
|
||
|
|
background-color: #FF5722;
|
||
|
|
color: white;
|
||
|
|
border-radius: 4px;
|
||
|
|
}
|
||
|
|
QPushButton:hover {
|
||
|
|
background-color: #F4511E;
|
||
|
|
}
|
||
|
|
""")
|
||
|
|
|
||
|
|
# 添加按钮到布局
|
||
|
|
self.button_layout.addStretch()
|
||
|
|
self.button_layout.addWidget(self.export_button)
|
||
|
|
self.button_layout.addWidget(self.close_button)
|
||
|
|
|
||
|
|
# 添加到主布局
|
||
|
|
self.main_layout.addWidget(self.button_frame)
|