diff --git a/dao/pallet_type_dao.py b/dao/pallet_type_dao.py index a8b0c3f..7d1562c 100644 --- a/dao/pallet_type_dao.py +++ b/dao/pallet_type_dao.py @@ -61,6 +61,31 @@ class PalletTypeDAO: logging.error(f"获取托盘类型失败: {str(e)}") return [] + def get_pallet_type_by_pallet_id(self, pallet_id): + """根据托盘号获取托盘类型 + + Args: + pallet_id: 托盘号 + + Returns: + dict: 托盘类型信息,未找到则返回None + """ + try: + sql = """ + SELECT DISTINCT sort_order + FROM pallet_archives t1 + LEFT JOIN pallet_types t2 ON t1.type_id = t2.id + WHERE pallet_id = ? AND t1.is_deleted = FALSE + """ + params = (pallet_id,) + self.db.cursor.execute(sql, params) + row = self.db.cursor.fetchone() + if row: + return row[0] + except Exception as e: + logging.error(f"获取托盘类型失败: {str(e)}") + return None + def get_pallet_types_by_operation(self, operation_type, include_disabled=False): """根据操作类型获取托盘类型 diff --git a/db/jtDB.db b/db/jtDB.db index a75867c..75949fa 100644 Binary files a/db/jtDB.db and b/db/jtDB.db differ diff --git a/db/schema.sql b/db/schema.sql index 29d05d2..ca8ee6b 100644 --- a/db/schema.sql +++ b/db/schema.sql @@ -102,3 +102,14 @@ INSERT OR IGNORE INTO pallet_types ( ('小型托盘', 'output', '小型下料托盘', TRUE, 5, CURRENT_TIMESTAMP, 'system'), ('大型托盘', 'output', '大型下料托盘', TRUE, 6, CURRENT_TIMESTAMP, 'system'); + +-- 创建托盘档案 +create table if not exists pallet_archives ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + pallet_id VARCHAR(50) , + type_id VARCHAR(50), + create_time TIMESTAMP , + create_by VARCHAR(50) , + update_time TIMESTAMP, + update_by VARCHAR(50) +) \ No newline at end of file diff --git a/ui/main_window_ui.py b/ui/main_window_ui.py index a2e9c90..7ec17ff 100644 --- a/ui/main_window_ui.py +++ b/ui/main_window_ui.py @@ -285,13 +285,13 @@ class MainWindowUI(QMainWindow): } """ - self.input_button = QPushButton("上料") - self.input_button.setFont(self.normal_font) - self.input_button.setStyleSheet(button_style + "background-color: #e3f2fd; border: 1px solid #2196f3;") + # self.input_button = QPushButton("上料") + # self.input_button.setFont(self.normal_font) + # self.input_button.setStyleSheet(button_style + "background-color: #e3f2fd; border: 1px solid #2196f3;") - self.output_button = QPushButton("下料") - self.output_button.setFont(self.normal_font) - self.output_button.setStyleSheet(button_style + "background-color: #fff8e1; border: 1px solid #ffc107;") + # self.output_button = QPushButton("下料") + # self.output_button.setFont(self.normal_font) + # self.output_button.setStyleSheet(button_style + "background-color: #fff8e1; border: 1px solid #ffc107;") self.start_button = QPushButton("开始") self.start_button.setFont(self.normal_font) @@ -302,10 +302,10 @@ class MainWindowUI(QMainWindow): self.stop_button.setStyleSheet(button_style + "background-color: #ffebee; border: 1px solid #f44336;") # 使用网格布局排列按钮 - self.button_layout.addWidget(self.input_button, 0, 0) - self.button_layout.addWidget(self.output_button, 0, 1) - self.button_layout.addWidget(self.start_button, 0, 2) - self.button_layout.addWidget(self.stop_button, 0, 3) + # self.button_layout.addWidget(self.input_button, 0, 0) + # self.button_layout.addWidget(self.output_button, 0, 1) + self.button_layout.addWidget(self.start_button, 0, 1) + self.button_layout.addWidget(self.stop_button, 0, 2) self.control_layout.addWidget(self.button_container) diff --git a/utils/pallet_type_manager.py b/utils/pallet_type_manager.py index be86039..4b4ee32 100644 --- a/utils/pallet_type_manager.py +++ b/utils/pallet_type_manager.py @@ -146,6 +146,17 @@ class PalletTypeManager: """ result = self.dao.get_pallet_type_by_type(pallet_type) + if result: + return result + else: + return None + def get_pallet_type_by_pallet_id(self, pallet_id): + """根据托盘号获取托盘类型 + + Args: + pallet_id: 托盘号 + """ + result = self.dao.get_pallet_type_by_pallet_id(pallet_id) if result: return result else: diff --git a/widgets/main_window.py b/widgets/main_window.py index 2be467b..6d75deb 100644 --- a/widgets/main_window.py +++ b/widgets/main_window.py @@ -179,8 +179,8 @@ class MainWindow(MainWindowUI): self.tray_edit.activated.connect(self.load_finished_inspection_data) # 当用户选择一项时触发 # 连接按钮事件 - self.input_button.clicked.connect(self.handle_input) - self.output_button.clicked.connect(self.handle_output) + # self.input_button.clicked.connect(self.handle_input) + # self.output_button.clicked.connect(self.handle_output) self.start_button.clicked.connect(self.handle_start) self.stop_button.clicked.connect(self.handle_stop) @@ -381,26 +381,93 @@ class MainWindow(MainWindowUI): modbus.close_client(client) def handle_start(self): - """处理启动按钮点击事件""" - modbus = ModbusUtils() - client = modbus.get_client() - try: - # 启动 D1 寄存器写入 1 - if not modbus.write_register_until_success(client, 1, 1): - QMessageBox.information(self, "操作提示", "启动失败") - except Exception as e: - logging.error(f"启动操作失败: {str(e)}") - QMessageBox.critical(self, "错误", f"启动操作失败: {str(e)}") - finally: - modbus.close_client(client) - + """ + 处理开始按钮点击事件 + """ + # 创建对话框 + dialog = QDialog(self) + dialog.setWindowTitle("上料操作") + dialog.setFixedSize(300, 200) + + # 对话框布局 + layout = QVBoxLayout(dialog) + + # 添加提示信息 + info_label = QLabel("请选择上料托盘类型:") + info_label.setFont(self.normal_font) + layout.addWidget(info_label) + + # 添加托盘类型选择 + pallet_combo = QComboBox() + pallet_combo.setFont(self.normal_font) + # 复制当前托盘类型选择器的内容 + for i in range(1,4): + pallet_combo.addItem(str(i)) + layout.addWidget(pallet_combo) + + # 添加按钮 + button_layout = QHBoxLayout() + confirm_button = QPushButton("确认") + confirm_button.setFont(self.normal_font) + confirm_button.setStyleSheet("background-color: #e3f2fd; border: 1px solid #2196f3; padding: 8px 16px; font-weight: bold; border-radius: 4px;") + + cancel_button = QPushButton("取消") + cancel_button.setFont(self.normal_font) + cancel_button.setStyleSheet("padding: 8px 16px; font-weight: bold; border-radius: 4px;") + + button_layout.addStretch() + button_layout.addWidget(confirm_button) + button_layout.addWidget(cancel_button) + layout.addLayout(button_layout) + + # 连接按钮信号 + confirm_button.clicked.connect(dialog.accept) + cancel_button.clicked.connect(dialog.reject) + + # 显示对话框 + result = dialog.exec() + + # 如果用户确认,则执行上料操作 + if result == QDialog.Accepted: + stow_num = pallet_combo.currentText() + + # 获取托盘号对应的托盘类型 + tray_id = self.tray_edit.currentText() + pallet_type = self.pallet_type_manager.get_pallet_type_by_pallet_id(tray_id) + if not pallet_type: + QMessageBox.warning(self, "错误", "未查到对应下料托盘类型") + return + + # 执行Modbus操作 + modbus = ModbusUtils() + client = modbus.get_client() + try: + success0 = modbus.write_register_until_success(client, 0, int(stow_num)) + success1 = modbus.write_register_until_success(client, 1, int(pallet_type)) + success2 = modbus.write_register_until_success(client, 2, 1) + success3 = modbus.write_register_until_success(client, 3, 1) + + # 上料 D2 寄存器写入 1 ,D0 寄存器写入托盘类型 + if success0 and success2 and success1 and success3 : + # 创建状态标签并显示在右上角 + self.show_operation_status("码垛层数", "input", stow_num) + else: + QMessageBox.information(self, "操作提示", "上料失败") + except Exception as e: + logging.error(f"上料操作失败: {str(e)}") + QMessageBox.critical(self, "错误", f"上料操作失败: {str(e)}") + finally: + modbus.close_client(client) + def handle_stop(self): """处理停止按钮点击事件""" modbus = ModbusUtils() client = modbus.get_client() try: - # 停止 D1 寄存器写入 0 - if not modbus.write_register_until_success(client, 1, 0): + success2 = modbus.write_register_until_success(client, 2, 0) + success3 = modbus.write_register_until_success(client, 3, 0) + # 停止 D1 寄存器2、3写入 0 + if not success2 and not success3: QMessageBox.information(self, "操作提示", "停止失败") except Exception as e: logging.error(f"停止操作失败: {str(e)}")