diff --git a/db/jtDB.db b/db/jtDB.db index 6546766..bc2709f 100644 Binary files a/db/jtDB.db and b/db/jtDB.db differ diff --git a/ui/main_window_ui.py b/ui/main_window_ui.py index 38a2501..702613a 100644 --- a/ui/main_window_ui.py +++ b/ui/main_window_ui.py @@ -323,7 +323,7 @@ class MainWindowUI(QMainWindow): # 创建值(改为QTextEdit) value = QTextEdit("") value.setFont(self.normal_font) - value.setStyleSheet("background-color: white; padding: 5px;") + value.setStyleSheet("background-color: white; padding: 5px; border: 1px solid #cccccc;") value.setFixedHeight(35) value.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff) value.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff) @@ -352,7 +352,7 @@ class MainWindowUI(QMainWindow): value = QLineEdit("") value.setFont(self.normal_font) value.setAlignment(Qt.AlignLeft | Qt.AlignVCenter) - value.setStyleSheet("background-color: white; padding: 5px; border: none;") + value.setStyleSheet("background-color: white; padding: 5px; border: 1px solid #cccccc;") value.setFrame(False) value.setContentsMargins(0, 0, 0, 0) value.setFixedHeight(35) diff --git a/widgets/main_window.py b/widgets/main_window.py index 43a809f..6a5ab13 100644 --- a/widgets/main_window.py +++ b/widgets/main_window.py @@ -75,6 +75,9 @@ class MainWindow(MainWindowUI): # 连接焦点变化信号 self.focus_tracker.focus_changed.connect(self._log_focus_widget_info) + # 添加当前处理行的跟踪 + self._current_processing_row = None # 当前正在处理的行索引 + # 初始化系统变量 self._current_weight = 0.0 # 当前重量 self._last_weight_time = 0 # 上次称重时间 @@ -1901,22 +1904,8 @@ class MainWindow(MainWindowUI): # 计算净重列索引 - 净重位置在检验列之后的第三列(称重后面) net_weight_col = 2 + len(enabled_configs) + 2 - # 基于状态查找行:优先查找状态为inspected的行 - data_row = None - from dao.inspection_dao import InspectionDAO - inspection_dao = InspectionDAO() - - # 首先查找状态为inspected的行 - for row in range(2, self.process_table.rowCount()): - gc_note_item = self.process_table.item(row, 1) - if gc_note_item: - row_gc_note = gc_note_item.text().strip() - tray_id = self.tray_edit.currentText() - status = inspection_dao.get_product_status(self._current_order_code, row_gc_note, tray_id) - if status == 'inspected': - data_row = row - logging.info(f"找到状态为inspected的行: {data_row}, 工程号: {row_gc_note}") - break + # 使用新的查找逻辑,确保顺序处理 + data_row = self._find_next_row_to_process('inspected') # 如果没有找到inspected状态的行,回退到原有逻辑 if data_row is None: @@ -1937,6 +1926,9 @@ class MainWindow(MainWindowUI): else: logging.info(f"将使用状态为inspected的行: {data_row}") + # 设置当前处理行 + self._current_processing_row = data_row + # 获取工程号 gc_note = self.process_table.item(data_row, 1) if not gc_note: @@ -2038,6 +2030,9 @@ class MainWindow(MainWindowUI): # 更新产品状态为weighed inspection_dao.update_product_status(self._current_order_code, gc_note, tray_id, 'weighed') logging.info(f"工程号 {gc_note} 的称重已完成,状态更新为weighed") + + # 清除当前处理行的跟踪,因为称重完成后需要等待贴标 + self._current_processing_row = None except Exception as e: logging.error(f"处理称重数据时发生错误: {str(e)}") @@ -2090,22 +2085,8 @@ class MainWindow(MainWindowUI): logging.warning("没有可用的数据行来写入贴标数据") return - # 基于状态查找行:优先查找状态为weighed的行 - data_row = None - from dao.inspection_dao import InspectionDAO - inspection_dao = InspectionDAO() - - # 首先查找状态为weighed的行 - for row in range(2, self.process_table.rowCount()): - gc_note_item = self.process_table.item(row, 1) - if gc_note_item: - row_gc_note = gc_note_item.text().strip() - tray_id = self.tray_edit.currentText() - status = inspection_dao.get_product_status(self._current_order_code, row_gc_note, tray_id) - if status == 'weighed': - data_row = row - logging.info(f"找到状态为weighed的行: {data_row}, 工程号: {row_gc_note}") - break + # 使用新的查找逻辑,确保顺序处理 + data_row = self._find_next_row_to_process('weighed') # 如果没有找到weighed状态的行,回退到原有逻辑 if data_row is None: @@ -2116,6 +2097,9 @@ class MainWindow(MainWindowUI): else: logging.info(f"将使用状态为weighed的行: {data_row}") + # 设置当前处理行 + self._current_processing_row = data_row + # 确保行存在 if data_row >= self.process_table.rowCount(): logging.warning(f"选中的行 {data_row} 超出了表格范围") @@ -2161,7 +2145,9 @@ class MainWindow(MainWindowUI): # 在这里添加保存贴标数据到数据库的代码 self.save_inspection_data(self._current_order_code, gc_note, tray_id, 11, 11, str(axios_num), "pass") logging.info(f"已将贴标数据 {axios_num} 保存到数据库") - + from dao.inspection_dao import InspectionDAO + from apis.gc_api import GcApi + inspection_dao = InspectionDAO() # 更新产品状态为labeled inspection_dao.update_product_status(self._current_order_code, gc_note, tray_id, 'labeled') logging.info(f"工程号 {gc_note} 的贴标已完成,状态更新为labeled") @@ -2174,6 +2160,9 @@ class MainWindow(MainWindowUI): self.process_table.removeRow(data_row) logging.info(f"已删除处理完成的行 {data_row}") + # 清除当前处理行的跟踪 + self._current_processing_row = None + # 复原寄存器 12 为 0 modbus = ModbusUtils() client = modbus.get_client() @@ -3733,6 +3722,58 @@ class MainWindow(MainWindowUI): except Exception as e: logging.error(f"记录焦点控件信息失败: {e}") + def _find_next_row_to_process(self, target_status): + """查找下一个需要处理的行 + + Args: + target_status: 目标状态(如 'inspected', 'weighed') + + Returns: + int: 行索引,如果没找到返回None + """ + try: + from dao.inspection_dao import InspectionDAO + inspection_dao = InspectionDAO() + + # 确定搜索的起始行 + start_row = 2 # 数据行从第2行开始 + + # 如果当前有正在处理的行,从该行开始搜索 + if self._current_processing_row is not None and self._current_processing_row >= 2: + start_row = self._current_processing_row + + # 从起始行开始,按顺序查找状态匹配的行 + for row in range(start_row, self.process_table.rowCount()): + gc_note_item = self.process_table.item(row, 1) + if gc_note_item: + row_gc_note = gc_note_item.text().strip() + if row_gc_note: # 确保工程号不为空 + tray_id = self.tray_edit.currentText() + status = inspection_dao.get_product_status(self._current_order_code, row_gc_note, tray_id) + if status == target_status: + logging.info(f"找到状态为{target_status}的行: {row}, 工程号: {row_gc_note}") + return row + + # 如果从当前处理行开始没找到,从头开始搜索 + if self._current_processing_row is not None and self._current_processing_row > 2: + for row in range(2, self._current_processing_row): + gc_note_item = self.process_table.item(row, 1) + if gc_note_item: + row_gc_note = gc_note_item.text().strip() + if row_gc_note: # 确保工程号不为空 + tray_id = self.tray_edit.currentText() + status = inspection_dao.get_product_status(self._current_order_code, row_gc_note, tray_id) + if status == target_status: + logging.info(f"从头开始找到状态为{target_status}的行: {row}, 工程号: {row_gc_note}") + return row + + logging.warning(f"未找到状态为{target_status}的行") + return None + + except Exception as e: + logging.error(f"查找下一个处理行时发生错误: {str(e)}") + return None + def handle_inspection_cell_changed(self, row, column): """处理检验表格单元格内容变更事件""" try: