diff --git a/config/app_config.json b/config/app_config.json index 224bfde..d348eb8 100644 --- a/config/app_config.json +++ b/config/app_config.json @@ -90,6 +90,6 @@ } }, "electricity": { - "auto_start": false + "auto_start": true } } \ No newline at end of file diff --git a/dao/inspection_dao.py b/dao/inspection_dao.py index f666fe8..edc8212 100644 --- a/dao/inspection_dao.py +++ b/dao/inspection_dao.py @@ -579,20 +579,21 @@ class InspectionDAO: with SQLUtils('sqlite', database='db/jtDB.db') as db: db.conn.rollback() - def delete_inspection_data(self, order_id, tray_id): + def delete_inspection_data(self, order_id, gc_note, tray_id): """删除检验数据 Args: - order_id: 工程号 + order_id: 订单号 + gc_note: 工程号 tray_id: 托盘号 """ try: sql = """ UPDATE wsbz_inspection_data SET is_deleted = TRUE - WHERE order_id = ? AND tray_id = ? + WHERE order_id = ? AND gc_note = ? AND tray_id = ? """ - params = (order_id, tray_id) + params = (order_id, gc_note, tray_id) with SQLUtils('sqlite', database='db/jtDB.db') as db: db.cursor.execute(sql, params) db.conn.commit() diff --git a/db/jtDB.db b/db/jtDB.db index b06fd1c..a5122f1 100644 Binary files a/db/jtDB.db and b/db/jtDB.db differ diff --git a/from pymodbus.py b/from pymodbus.py index e5a97c5..e61cb9e 100644 --- a/from pymodbus.py +++ b/from pymodbus.py @@ -2,7 +2,7 @@ from pymodbus.client import ModbusTcpClient import time client = ModbusTcpClient('localhost', port=5020) client.connect() -client.write_registers(address=11, values=[2248]) +client.write_registers(address=11, values=[2247]) client.write_registers(address=3, values=[0]) # client.write_registers(address=20, values=[0]) @@ -13,9 +13,9 @@ client.write_registers(address=3, values=[0]) # client.write_registers(address=5, values=[16]) # 贴标完成 # client.write_registers(address=24, values=[1])s -# client.write_registers(address=13, values=[1]) +client.write_registers(address=13, values=[1]) -result = client.read_holding_registers(address=109, count=1) +result = client.read_holding_registers(address=11, count=1) print(result.registers[0],"123===") client.close() \ No newline at end of file diff --git a/widgets/main_window.py b/widgets/main_window.py index 11cdd48..7759c93 100644 --- a/widgets/main_window.py +++ b/widgets/main_window.py @@ -27,6 +27,7 @@ from utils.electricity_monitor import ElectricityHandler from PySide6.QtWidgets import ( QWidget, QMessageBox, QTableWidgetItem, QStackedWidget, QLabel, QTableWidget, QMenu, QComboBox, QFormLayout, QDialog, QVBoxLayout, + QFrame, QHBoxLayout, QSplitter, QPushButton ) from PySide6.QtCore import Qt, QTimer, Slot, Signal from PySide6.QtGui import QBrush, QColor @@ -257,6 +258,7 @@ class MainWindow(MainWindowUI): self.output_button.clicked.connect(self.handle_output) self.start_button.clicked.connect(self.handle_start) self.stop_button.clicked.connect(self.handle_stop) + self.delete_row_button.clicked.connect(self.handle_delete_row) # 设置表格上下文菜单 self.process_table.setContextMenuPolicy(Qt.CustomContextMenu) @@ -2031,8 +2033,10 @@ class MainWindow(MainWindowUI): self.process_table.setItem(data_row, label_col, label_item) logging.info(f"已将贴标数据 {axios_num} 写入表格单元格 [{data_row}, {label_col}]") + # 在这里添加保存贴标数据到数据库的代码 + self.save_inspection_data(self._current_order_code, gc_note, tray_id, 11, 11, str(axios_num), "pass") + logging.info(f"已将贴标数据 {axios_num} 保存到数据库") - # 调用加载到包装记录的方法 self.load_finished_record_to_package_record(self._current_order_code,gc_note, tray_id) logging.info(f"贴标完成,已将工程号 {gc_note} 的记录加载到包装记录") @@ -2041,8 +2045,6 @@ class MainWindow(MainWindowUI): self.process_table.removeRow(data_row) logging.info(f"已删除处理完成的行 {data_row}") - - # 重新连接单元格变更信号 self.process_table.cellChanged.connect(self.handle_inspection_cell_changed) @@ -2984,4 +2986,170 @@ class MainWindow(MainWindowUI): self.label_status_label.setText("故障: 正常") self.label_status_label.setStyleSheet("") except Exception as e: - logging.error(f"处理急停UI更新失败: {str(e)}") \ No newline at end of file + logging.error(f"处理急停UI更新失败: {str(e)}") + + def create_right_panel(self): + """创建右侧面板""" + # 创建右侧整体框架 + self.right_frame = QFrame() + self.right_frame.setFrameShape(QFrame.NoFrame) # 移除框架边框 + self.right_frame.setLineWidth(0) + self.right_layout.addWidget(self.right_frame) + + # 右侧整体使用垂直布局,不设置边距 + self.right_frame_layout = QVBoxLayout(self.right_frame) + self.right_frame_layout.setContentsMargins(0, 0, 0, 0) + self.right_frame_layout.setSpacing(0) + + # 创建一个垂直分割器,用于控制两个表格的高度比例 + self.right_splitter = QSplitter(Qt.Vertical) + + # 创建微丝产线表格的容器 + self.process_container = QWidget() + self.process_container_layout = QVBoxLayout(self.process_container) + self.process_container_layout.setContentsMargins(0, 0, 0, 0) + self.process_container_layout.setSpacing(0) + + # 创建包装记录表格的容器 + self.record_container = QWidget() + self.record_container_layout = QVBoxLayout(self.record_container) + self.record_container_layout.setContentsMargins(0, 0, 0, 0) + self.record_container_layout.setSpacing(0) + + # 创建微丝产线表格 + self.create_process_table() + + # 创建带删除按钮的标题行 + self.create_process_title_with_button() + + # 将微丝产线表格添加到容器中 + self.process_container_layout.addWidget(self.process_frame) + + # 创建包装记录表格 + self.create_record_table() + self.record_container_layout.addWidget(self.record_frame) + + # 将两个容器添加到分割器中 + self.right_splitter.addWidget(self.process_container) + self.right_splitter.addWidget(self.record_container) + + # 设置初始大小比例:微丝产线占1/3,包装记录占2/3 + self.right_splitter.setSizes([100, 200]) # 比例为1:2 + + # 将分割器添加到右侧布局 + self.right_frame_layout.addWidget(self.right_splitter) + + def create_process_title_with_button(self): + """创建带删除按钮的微丝产线标题行""" + # 获取原来的标题 + original_title = self.process_title.text() + + # 移除原来的标题 + self.process_layout.removeWidget(self.process_title) + self.process_title.deleteLater() + + # 创建标题容器 + title_container = QWidget() + title_layout = QHBoxLayout(title_container) + title_layout.setContentsMargins(5, 0, 5, 0) + + # 创建新的标题标签 + self.process_title = QLabel(original_title) + self.process_title.setFont(self.second_title_font) + self.process_title.setAlignment(Qt.AlignLeft | Qt.AlignVCenter) + + # 创建删除按钮 + self.delete_row_button = QPushButton("删除选中行") + self.delete_row_button.setFont(self.normal_font) + self.delete_row_button.setStyleSheet(""" + QPushButton { + padding: 5px 10px; + background-color: #ffebee; + border: 1px solid #f44336; + border-radius: 4px; + font-weight: bold; + } + QPushButton:hover { + background-color: #ffcdd2; + } + """) + self.delete_row_button.clicked.connect(self.handle_delete_row) + + # 将标题和按钮添加到布局中 + title_layout.addWidget(self.process_title) + title_layout.addStretch() + title_layout.addWidget(self.delete_row_button) + + # 设置容器样式 + title_container.setFixedHeight(40) + title_container.setStyleSheet("background-color: #f8f8f8; border-bottom: 1px solid #dddddd;") + + # 将标题容器添加到布局中 + self.process_layout.insertWidget(0, title_container) + + def handle_delete_row(self): + """处理删除按钮点击事件,删除选中的微丝产线表格行""" + try: + # 获取当前选中的行 + selected_rows = self.process_table.selectionModel().selectedRows() + if not selected_rows: + # 如果没有选中整行,则获取当前选中的单元格所在行 + current_row = self.process_table.currentRow() + if current_row >= 2: # 确保不是表头行 + selected_rows = [self.process_table.model().index(current_row, 0)] + else: + QMessageBox.warning(self, "提示", "请先选择要删除的数据行") + return + + # 确认删除 + reply = QMessageBox.question( + self, + "确认删除", + "确定要删除选中的数据吗?此操作不可恢复。", + QMessageBox.Yes | QMessageBox.No, + QMessageBox.No + ) + + if reply != QMessageBox.Yes: + return + + # 从数据库中删除数据 + from dao.inspection_dao import InspectionDAO + inspection_dao = InspectionDAO() + + # 按行号降序排序,以便从后往前删除 + rows_to_delete = sorted([index.row() for index in selected_rows], reverse=True) + + for row in rows_to_delete: + if row < 2: # 跳过表头行 + continue + + # 获取工程号 + gc_note_item = self.process_table.item(row, 1) + if not gc_note_item: + continue + + gc_note = gc_note_item.text().strip() + if not gc_note: + continue + + # 获取托盘号 + tray_id = self.tray_edit.currentText() + + # 从数据库中删除该工程号的检验数据 + inspection_dao.delete_inspection_data(self._current_order_code, gc_note, tray_id) + logging.info(f"已从数据库中删除工程号 {gc_note} 的检验数据") + + # 从表格中删除行 + self.process_table.removeRow(row) + logging.info(f"已从表格中删除第 {row} 行") + + # 重新加载数据 + self._safe_load_data() + + # 显示成功消息 + QMessageBox.information(self, "删除成功", "已成功删除选中的数据") + + except Exception as e: + logging.error(f"删除数据失败: {str(e)}") + QMessageBox.critical(self, "错误", f"删除数据失败: {str(e)}") \ No newline at end of file