feat: 更新托盘类型管理功能,添加托盘类型的增删改查接口,优化UI交互,简化托盘类型配置页面
This commit is contained in:
parent
38c29de69f
commit
99bca76e08
@ -15,7 +15,7 @@
|
|||||||
"get_gc_info": "/jsjt/xcsc/tprk/getBZGCInfoToWsbz.do",
|
"get_gc_info": "/jsjt/xcsc/tprk/getBZGCInfoToWsbz.do",
|
||||||
"get_order_info": "/jsjt/xcsc/tprk/getXsddBzrkGridListToWsbz.do",
|
"get_order_info": "/jsjt/xcsc/tprk/getXsddBzrkGridListToWsbz.do",
|
||||||
"add_order_info": "/jsjt/xcsc/tprk/bzrkAdd01.do",
|
"add_order_info": "/jsjt/xcsc/tprk/bzrkAdd01.do",
|
||||||
"get_xpack":"/jsjt/xcsc/tprk/getXpackToWsbz.do"
|
"get_xpack": "/jsjt/xcsc/tprk/getXpackToWsbz.do"
|
||||||
},
|
},
|
||||||
"database": {
|
"database": {
|
||||||
"default": "sqlite",
|
"default": "sqlite",
|
||||||
|
|||||||
@ -80,255 +80,8 @@ class PalletTypeDAO:
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.error(f"获取托盘类型失败: {str(e)}")
|
logging.error(f"获取托盘类型失败: {str(e)}")
|
||||||
return None
|
return None
|
||||||
def get_pallet_types_by_operation(self, operation_type, include_disabled=False):
|
|
||||||
"""根据操作类型获取托盘类型
|
|
||||||
|
|
||||||
Args:
|
|
||||||
operation_type: 操作类型 (input/output)
|
|
||||||
include_disabled: 是否包含禁用的类型
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
list: 托盘类型列表
|
|
||||||
"""
|
|
||||||
try:
|
|
||||||
if include_disabled:
|
|
||||||
sql = """
|
|
||||||
SELECT id, type_name, operation_type, description, enabled, sort_order
|
|
||||||
FROM wsbz_pallet_types
|
|
||||||
WHERE operation_type = ? AND is_deleted = FALSE
|
|
||||||
ORDER BY sort_order
|
|
||||||
"""
|
|
||||||
params = (operation_type,)
|
|
||||||
else:
|
|
||||||
sql = """
|
|
||||||
SELECT id, type_name, operation_type, description, enabled, sort_order
|
|
||||||
FROM wsbz_pallet_types
|
|
||||||
WHERE operation_type = ? AND is_deleted = FALSE AND enabled = TRUE
|
|
||||||
ORDER BY sort_order
|
|
||||||
"""
|
|
||||||
params = (operation_type,)
|
|
||||||
|
|
||||||
self.db.cursor.execute(sql, params)
|
|
||||||
results = self.db.cursor.fetchall()
|
|
||||||
|
|
||||||
pallet_types = []
|
|
||||||
for row in results:
|
|
||||||
pallet_type = {
|
|
||||||
'id': row[0],
|
|
||||||
'type_name': row[1],
|
|
||||||
'operation_type': row[2],
|
|
||||||
'description': row[3],
|
|
||||||
'enabled': bool(row[4]),
|
|
||||||
'sort_order': row[5]
|
|
||||||
}
|
|
||||||
pallet_types.append(pallet_type)
|
|
||||||
return pallet_types
|
|
||||||
except Exception as e:
|
|
||||||
logging.error(f"获取托盘类型失败: {str(e)}")
|
|
||||||
return []
|
|
||||||
|
|
||||||
def get_pallet_type_by_id(self, pallet_type_id):
|
|
||||||
"""根据ID获取托盘类型
|
|
||||||
|
|
||||||
Args:
|
|
||||||
pallet_type_id: 托盘类型ID
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
dict: 托盘类型信息,未找到则返回None
|
|
||||||
"""
|
|
||||||
try:
|
|
||||||
sql = """
|
|
||||||
SELECT id, type_name, operation_type, description, enabled, sort_order
|
|
||||||
FROM wsbz_pallet_types
|
|
||||||
WHERE id = ? AND is_deleted = FALSE
|
|
||||||
"""
|
|
||||||
params = (pallet_type_id,)
|
|
||||||
|
|
||||||
self.db.cursor.execute(sql, params)
|
|
||||||
row = self.db.cursor.fetchone()
|
|
||||||
|
|
||||||
if row:
|
|
||||||
pallet_type = {
|
|
||||||
'id': row[0],
|
|
||||||
'type_name': row[1],
|
|
||||||
'operation_type': row[2],
|
|
||||||
'description': row[3],
|
|
||||||
'enabled': bool(row[4]),
|
|
||||||
'sort_order': row[5]
|
|
||||||
}
|
|
||||||
return pallet_type
|
|
||||||
else:
|
|
||||||
return None
|
|
||||||
except Exception as e:
|
|
||||||
logging.error(f"获取托盘类型失败: {str(e)}")
|
|
||||||
return None
|
|
||||||
def get_pallet_type_by_type(self,pallet_type):
|
|
||||||
"""根据托盘类型获取托盘信息
|
|
||||||
Args:
|
|
||||||
pallet_type: 托盘类型
|
|
||||||
Returns:
|
|
||||||
dict: 托盘类型信息,未找到则返回None
|
|
||||||
"""
|
|
||||||
try:
|
|
||||||
sql = """
|
|
||||||
SELECT id, type_name, operation_type, description, enabled, sort_order
|
|
||||||
FROM wsbz_pallet_types
|
|
||||||
WHERE type_name = ? AND is_deleted = FALSE
|
|
||||||
"""
|
|
||||||
params = (pallet_type, )
|
|
||||||
self.db.cursor.execute(sql, params)
|
|
||||||
results = self.db.cursor.fetchall()
|
|
||||||
pallet_type_dict = {row[1]:row[5] for row in results}
|
|
||||||
return pallet_type_dict
|
|
||||||
except Exception as e:
|
|
||||||
logging.error(f"获取托盘类型失败: {str(e)}")
|
|
||||||
return {}
|
|
||||||
def create_pallet_type(self, data, username='system'):
|
|
||||||
"""创建托盘类型
|
|
||||||
|
|
||||||
Args:
|
|
||||||
data: 托盘类型数据
|
|
||||||
username: 操作用户
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
int: 新创建的托盘类型ID,失败返回None
|
|
||||||
"""
|
|
||||||
try:
|
|
||||||
current_time = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
|
|
||||||
|
|
||||||
sql = """
|
|
||||||
INSERT INTO wsbz_pallet_types (
|
|
||||||
type_name, operation_type, description, enabled, sort_order,
|
|
||||||
create_time, create_by, update_time, update_by, is_deleted
|
|
||||||
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
||||||
"""
|
|
||||||
|
|
||||||
params = (
|
|
||||||
data.get('type_name'),
|
|
||||||
data.get('operation_type'),
|
|
||||||
data.get('description', ''),
|
|
||||||
data.get('enabled', True),
|
|
||||||
data.get('sort_order', 999),
|
|
||||||
current_time,
|
|
||||||
username,
|
|
||||||
current_time,
|
|
||||||
username,
|
|
||||||
False
|
|
||||||
)
|
|
||||||
|
|
||||||
self.db.execute_update(sql, params)
|
|
||||||
|
|
||||||
# 获取新插入的ID
|
|
||||||
self.db.cursor.execute("SELECT last_insert_rowid()")
|
|
||||||
new_id = self.db.cursor.fetchone()[0]
|
|
||||||
|
|
||||||
return new_id
|
|
||||||
except Exception as e:
|
|
||||||
logging.error(f"创建托盘类型失败: {str(e)}")
|
|
||||||
return None
|
|
||||||
|
|
||||||
def update_pallet_type(self, pallet_type_id, data, username='system'):
|
|
||||||
"""更新托盘类型
|
|
||||||
|
|
||||||
Args:
|
|
||||||
pallet_type_id: 托盘类型ID
|
|
||||||
data: 更新数据
|
|
||||||
username: 操作用户
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
bool: 更新是否成功
|
|
||||||
"""
|
|
||||||
try:
|
|
||||||
current_time = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
|
|
||||||
|
|
||||||
# 构建更新SQL
|
|
||||||
update_fields = []
|
|
||||||
params = []
|
|
||||||
|
|
||||||
# 可更新的字段
|
|
||||||
allowed_fields = [
|
|
||||||
'type_name', 'operation_type', 'description', 'enabled', 'sort_order'
|
|
||||||
]
|
|
||||||
|
|
||||||
for field in allowed_fields:
|
|
||||||
if field in data:
|
|
||||||
update_fields.append(f"{field} = ?")
|
|
||||||
params.append(data[field])
|
|
||||||
|
|
||||||
# 添加更新时间和更新人
|
|
||||||
update_fields.append("update_time = ?")
|
|
||||||
params.append(current_time)
|
|
||||||
update_fields.append("update_by = ?")
|
|
||||||
params.append(username)
|
|
||||||
|
|
||||||
# 添加ID到参数列表
|
|
||||||
params.append(pallet_type_id)
|
|
||||||
|
|
||||||
# 构建SQL
|
|
||||||
sql = f"""
|
|
||||||
UPDATE wsbz_pallet_types
|
|
||||||
SET {', '.join(update_fields)}
|
|
||||||
WHERE id = ?
|
|
||||||
"""
|
|
||||||
|
|
||||||
self.db.execute_update(sql, params)
|
|
||||||
return True
|
|
||||||
except Exception as e:
|
|
||||||
logging.error(f"更新托盘类型失败: {str(e)}")
|
|
||||||
return False
|
|
||||||
|
|
||||||
def delete_pallet_type(self, pallet_type_id, username='system'):
|
|
||||||
"""删除托盘类型(软删除)
|
|
||||||
|
|
||||||
Args:
|
|
||||||
pallet_type_id: 托盘类型ID
|
|
||||||
username: 操作用户
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
bool: 删除是否成功
|
|
||||||
"""
|
|
||||||
try:
|
|
||||||
current_time = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
|
|
||||||
|
|
||||||
sql = """
|
|
||||||
UPDATE wsbz_pallet_types
|
|
||||||
SET is_deleted = TRUE, update_time = ?, update_by = ?
|
|
||||||
WHERE id = ?
|
|
||||||
"""
|
|
||||||
params = (current_time, username, pallet_type_id)
|
|
||||||
|
|
||||||
self.db.execute_update(sql, params)
|
|
||||||
return True
|
|
||||||
except Exception as e:
|
|
||||||
logging.error(f"删除托盘类型失败: {str(e)}")
|
|
||||||
return False
|
|
||||||
|
|
||||||
def toggle_pallet_type(self, pallet_type_id, enabled, username='system'):
|
|
||||||
"""启用或禁用托盘类型
|
|
||||||
|
|
||||||
Args:
|
|
||||||
pallet_type_id: 托盘类型ID
|
|
||||||
enabled: 是否启用
|
|
||||||
username: 操作用户
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
bool: 操作是否成功
|
|
||||||
"""
|
|
||||||
try:
|
|
||||||
current_time = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
|
|
||||||
|
|
||||||
sql = """
|
|
||||||
UPDATE wsbz_pallet_types
|
|
||||||
SET enabled = ?, update_time = ?, update_by = ?
|
|
||||||
WHERE id = ? AND is_deleted = FALSE
|
|
||||||
"""
|
|
||||||
params = (enabled, current_time, username, pallet_type_id)
|
|
||||||
|
|
||||||
self.db.execute_update(sql, params)
|
|
||||||
return True
|
|
||||||
except Exception as e:
|
|
||||||
logging.error(f"更新托盘类型启用状态失败: {str(e)}")
|
|
||||||
return False
|
|
||||||
def save_pallet_info(self, pallet_code, pallet_info, user_id):
|
def save_pallet_info(self, pallet_code, pallet_info, user_id):
|
||||||
"""保存托盘信息
|
"""保存托盘信息
|
||||||
|
|
||||||
@ -446,6 +199,131 @@ class PalletTypeDAO:
|
|||||||
logging.error(f"获取托盘类型失败: {str(e)}")
|
logging.error(f"获取托盘类型失败: {str(e)}")
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
|
def get_all_pallet_types_list(self):
|
||||||
|
"""获取所有托盘类型列表
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
list: 包含所有托盘类型信息的列表,每个元素是一个字典,包含id和name
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
sql = """
|
||||||
|
SELECT pallet_id, pallet_name FROM wsbz_pallet_type ORDER BY pallet_id
|
||||||
|
"""
|
||||||
|
self.db.cursor.execute(sql)
|
||||||
|
results = self.db.cursor.fetchall()
|
||||||
|
|
||||||
|
pallet_types = []
|
||||||
|
for row in results:
|
||||||
|
pallet_type = {
|
||||||
|
'id': row[0],
|
||||||
|
'name': row[1]
|
||||||
|
}
|
||||||
|
pallet_types.append(pallet_type)
|
||||||
|
return pallet_types
|
||||||
|
except Exception as e:
|
||||||
|
logging.error(f"获取托盘类型列表失败: {str(e)}")
|
||||||
|
return []
|
||||||
|
|
||||||
|
def add_pallet_type(self, pallet_id, pallet_name):
|
||||||
|
"""添加托盘类型
|
||||||
|
|
||||||
|
Args:
|
||||||
|
pallet_id: 托盘ID
|
||||||
|
pallet_name: 托盘名称
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
bool: 是否添加成功
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
sql = """
|
||||||
|
INSERT INTO wsbz_pallet_type (pallet_id, pallet_name)
|
||||||
|
VALUES (?, ?)
|
||||||
|
"""
|
||||||
|
params = (pallet_id, pallet_name)
|
||||||
|
self.db.execute_update(sql, params)
|
||||||
|
logging.info(f"添加托盘类型成功: ID={pallet_id}, 名称={pallet_name}")
|
||||||
|
return True
|
||||||
|
except Exception as e:
|
||||||
|
logging.error(f"添加托盘类型失败: {str(e)}")
|
||||||
|
return False
|
||||||
|
|
||||||
|
def update_pallet_type(self, pallet_id, pallet_name):
|
||||||
|
"""更新托盘类型
|
||||||
|
|
||||||
|
Args:
|
||||||
|
pallet_id: 托盘ID
|
||||||
|
pallet_name: 托盘名称
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
bool: 是否更新成功
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
sql = """
|
||||||
|
UPDATE wsbz_pallet_type
|
||||||
|
SET pallet_name = ?
|
||||||
|
WHERE pallet_id = ?
|
||||||
|
"""
|
||||||
|
params = (pallet_name, pallet_id)
|
||||||
|
self.db.execute_update(sql, params)
|
||||||
|
logging.info(f"更新托盘类型成功: ID={pallet_id}, 名称={pallet_name}")
|
||||||
|
return True
|
||||||
|
except Exception as e:
|
||||||
|
logging.error(f"更新托盘类型失败: {str(e)}")
|
||||||
|
return False
|
||||||
|
|
||||||
|
def delete_pallet_type(self, pallet_id):
|
||||||
|
"""删除托盘类型
|
||||||
|
|
||||||
|
Args:
|
||||||
|
pallet_id: 托盘ID
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
bool: 是否删除成功
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
sql = """
|
||||||
|
DELETE FROM wsbz_pallet_type
|
||||||
|
WHERE pallet_id = ?
|
||||||
|
"""
|
||||||
|
params = (pallet_id,)
|
||||||
|
self.db.execute_update(sql, params)
|
||||||
|
logging.info(f"删除托盘类型成功: ID={pallet_id}")
|
||||||
|
return True
|
||||||
|
except Exception as e:
|
||||||
|
logging.error(f"删除托盘类型失败: {str(e)}")
|
||||||
|
return False
|
||||||
|
|
||||||
|
def get_pallet_type_by_id(self, pallet_id):
|
||||||
|
"""根据ID获取托盘类型
|
||||||
|
|
||||||
|
Args:
|
||||||
|
pallet_id: 托盘ID
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
dict: 托盘类型信息,未找到则返回None
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
sql = """
|
||||||
|
SELECT pallet_id, pallet_name
|
||||||
|
FROM wsbz_pallet_type
|
||||||
|
WHERE pallet_id = ?
|
||||||
|
"""
|
||||||
|
params = (pallet_id,)
|
||||||
|
self.db.cursor.execute(sql, params)
|
||||||
|
row = self.db.cursor.fetchone()
|
||||||
|
|
||||||
|
if row:
|
||||||
|
pallet_type = {
|
||||||
|
'id': row[0],
|
||||||
|
'name': row[1]
|
||||||
|
}
|
||||||
|
return pallet_type
|
||||||
|
else:
|
||||||
|
return None
|
||||||
|
except Exception as e:
|
||||||
|
logging.error(f"根据ID获取托盘类型失败: {str(e)}")
|
||||||
|
return None
|
||||||
|
|
||||||
def save_pallet_archives(self, pallet_code, tier, user_id, user_name):
|
def save_pallet_archives(self, pallet_code, tier, user_id, user_name):
|
||||||
"""保存托盘档案
|
"""保存托盘档案
|
||||||
|
|
||||||
|
|||||||
BIN
db/jtDB.db
BIN
db/jtDB.db
Binary file not shown.
@ -32,63 +32,13 @@ class PalletTypeSettingsUI(QWidget):
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
# 创建下料类型配置页面
|
# 创建托盘类型配置页面
|
||||||
self.output_widget = self.create_pallet_type_widget("output")
|
self.pallet_type_widget = self.create_pallet_type_widget()
|
||||||
self.main_layout.addWidget(self.output_widget, 1)
|
self.main_layout.addWidget(self.pallet_type_widget, 1)
|
||||||
|
|
||||||
# 底部按钮区域
|
def create_pallet_type_widget(self):
|
||||||
self.button_layout = QHBoxLayout()
|
|
||||||
self.button_layout.setContentsMargins(0, 10, 0, 0)
|
|
||||||
|
|
||||||
self.save_button = QPushButton("保存配置")
|
|
||||||
self.save_button.setFont(self.normal_font)
|
|
||||||
self.save_button.setFixedSize(120, 40)
|
|
||||||
self.save_button.setStyleSheet("""
|
|
||||||
QPushButton {
|
|
||||||
background-color: #4caf50;
|
|
||||||
color: white;
|
|
||||||
border: none;
|
|
||||||
border-radius: 5px;
|
|
||||||
}
|
|
||||||
QPushButton:hover {
|
|
||||||
background-color: #45a049;
|
|
||||||
}
|
|
||||||
QPushButton:pressed {
|
|
||||||
background-color: #3d8b40;
|
|
||||||
}
|
|
||||||
""")
|
|
||||||
|
|
||||||
self.reset_button = QPushButton("重置")
|
|
||||||
self.reset_button.setFont(self.normal_font)
|
|
||||||
self.reset_button.setFixedSize(120, 40)
|
|
||||||
self.reset_button.setStyleSheet("""
|
|
||||||
QPushButton {
|
|
||||||
background-color: #f44336;
|
|
||||||
color: white;
|
|
||||||
border: none;
|
|
||||||
border-radius: 5px;
|
|
||||||
}
|
|
||||||
QPushButton:hover {
|
|
||||||
background-color: #e53935;
|
|
||||||
}
|
|
||||||
QPushButton:pressed {
|
|
||||||
background-color: #d32f2f;
|
|
||||||
}
|
|
||||||
""")
|
|
||||||
|
|
||||||
self.button_layout.addStretch()
|
|
||||||
self.button_layout.addWidget(self.reset_button)
|
|
||||||
self.button_layout.addSpacing(20)
|
|
||||||
self.button_layout.addWidget(self.save_button)
|
|
||||||
|
|
||||||
self.main_layout.addLayout(self.button_layout)
|
|
||||||
|
|
||||||
def create_pallet_type_widget(self, operation_type):
|
|
||||||
"""创建托盘类型配置部件
|
"""创建托盘类型配置部件
|
||||||
|
|
||||||
Args:
|
|
||||||
operation_type: 操作类型 (input/output)
|
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
QWidget: 托盘类型配置部件
|
QWidget: 托盘类型配置部件
|
||||||
"""
|
"""
|
||||||
@ -98,19 +48,17 @@ class PalletTypeSettingsUI(QWidget):
|
|||||||
layout.setSpacing(15)
|
layout.setSpacing(15)
|
||||||
|
|
||||||
# 创建表格
|
# 创建表格
|
||||||
table = QTableWidget()
|
self.pallet_table = QTableWidget()
|
||||||
table.setFont(self.normal_font)
|
self.pallet_table.setFont(self.normal_font)
|
||||||
table.setColumnCount(4)
|
self.pallet_table.setColumnCount(2) # 只有两列:托盘ID和托盘名称
|
||||||
table.setHorizontalHeaderLabels(["类型名称", "描述", "排序", "启用"])
|
self.pallet_table.setHorizontalHeaderLabels(["托盘ID", "托盘名称"])
|
||||||
table.horizontalHeader().setSectionResizeMode(0, QHeaderView.Stretch)
|
self.pallet_table.horizontalHeader().setSectionResizeMode(0, QHeaderView.Stretch)
|
||||||
table.horizontalHeader().setSectionResizeMode(1, QHeaderView.Stretch)
|
self.pallet_table.horizontalHeader().setSectionResizeMode(1, QHeaderView.Stretch)
|
||||||
table.horizontalHeader().setSectionResizeMode(2, QHeaderView.ResizeToContents)
|
self.pallet_table.verticalHeader().setVisible(False)
|
||||||
table.horizontalHeader().setSectionResizeMode(3, QHeaderView.ResizeToContents)
|
self.pallet_table.setSelectionBehavior(QAbstractItemView.SelectRows)
|
||||||
table.verticalHeader().setVisible(False)
|
self.pallet_table.setSelectionMode(QAbstractItemView.SingleSelection)
|
||||||
table.setSelectionBehavior(QAbstractItemView.SelectRows)
|
self.pallet_table.setAlternatingRowColors(True)
|
||||||
table.setSelectionMode(QAbstractItemView.SingleSelection)
|
self.pallet_table.setStyleSheet("""
|
||||||
table.setAlternatingRowColors(True)
|
|
||||||
table.setStyleSheet("""
|
|
||||||
QTableWidget {
|
QTableWidget {
|
||||||
border: 1px solid #ddd;
|
border: 1px solid #ddd;
|
||||||
border-radius: 5px;
|
border-radius: 5px;
|
||||||
@ -124,8 +72,7 @@ class PalletTypeSettingsUI(QWidget):
|
|||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
}
|
}
|
||||||
""")
|
""")
|
||||||
table.setObjectName(f"{operation_type}_table")
|
layout.addWidget(self.pallet_table)
|
||||||
layout.addWidget(table)
|
|
||||||
|
|
||||||
# 创建表单
|
# 创建表单
|
||||||
form_group = QGroupBox("编辑托盘类型")
|
form_group = QGroupBox("编辑托盘类型")
|
||||||
@ -134,42 +81,26 @@ class PalletTypeSettingsUI(QWidget):
|
|||||||
form_layout.setContentsMargins(15, 15, 15, 15)
|
form_layout.setContentsMargins(15, 15, 15, 15)
|
||||||
form_layout.setSpacing(10)
|
form_layout.setSpacing(10)
|
||||||
|
|
||||||
# 类型名称
|
# 托盘ID
|
||||||
type_name_input = QLineEdit()
|
self.pallet_id_input = QLineEdit()
|
||||||
type_name_input.setFont(self.normal_font)
|
self.pallet_id_input.setFont(self.normal_font)
|
||||||
type_name_input.setObjectName(f"{operation_type}_type_name_input")
|
self.pallet_id_input.setPlaceholderText("请输入托盘ID")
|
||||||
form_layout.addRow("类型名称:", type_name_input)
|
form_layout.addRow("托盘ID:", self.pallet_id_input)
|
||||||
|
|
||||||
# 描述
|
# 托盘名称
|
||||||
desc_input = QLineEdit()
|
self.pallet_name_input = QLineEdit()
|
||||||
desc_input.setFont(self.normal_font)
|
self.pallet_name_input.setFont(self.normal_font)
|
||||||
desc_input.setObjectName(f"{operation_type}_desc_input")
|
self.pallet_name_input.setPlaceholderText("请输入托盘名称")
|
||||||
form_layout.addRow("描述:", desc_input)
|
form_layout.addRow("托盘名称:", self.pallet_name_input)
|
||||||
|
|
||||||
# 排序
|
|
||||||
sort_order_spin = QSpinBox()
|
|
||||||
sort_order_spin.setFont(self.normal_font)
|
|
||||||
sort_order_spin.setRange(1, 999)
|
|
||||||
sort_order_spin.setValue(100)
|
|
||||||
sort_order_spin.setObjectName(f"{operation_type}_sort_order_spin")
|
|
||||||
form_layout.addRow("排序:", sort_order_spin)
|
|
||||||
|
|
||||||
# 启用
|
|
||||||
enabled_check = QCheckBox("启用")
|
|
||||||
enabled_check.setFont(self.normal_font)
|
|
||||||
enabled_check.setChecked(True)
|
|
||||||
enabled_check.setObjectName(f"{operation_type}_enabled_check")
|
|
||||||
form_layout.addRow("", enabled_check)
|
|
||||||
|
|
||||||
layout.addWidget(form_group)
|
layout.addWidget(form_group)
|
||||||
|
|
||||||
# 创建按钮区域
|
# 创建按钮区域
|
||||||
button_layout = QHBoxLayout()
|
button_layout = QHBoxLayout()
|
||||||
|
|
||||||
add_button = QPushButton("添加")
|
self.add_button = QPushButton("添加")
|
||||||
add_button.setFont(self.normal_font)
|
self.add_button.setFont(self.normal_font)
|
||||||
add_button.setObjectName(f"{operation_type}_add_button")
|
self.add_button.setStyleSheet("""
|
||||||
add_button.setStyleSheet("""
|
|
||||||
QPushButton {
|
QPushButton {
|
||||||
background-color: #4caf50;
|
background-color: #4caf50;
|
||||||
color: white;
|
color: white;
|
||||||
@ -182,10 +113,9 @@ class PalletTypeSettingsUI(QWidget):
|
|||||||
}
|
}
|
||||||
""")
|
""")
|
||||||
|
|
||||||
update_button = QPushButton("更新")
|
self.update_button = QPushButton("更新")
|
||||||
update_button.setFont(self.normal_font)
|
self.update_button.setFont(self.normal_font)
|
||||||
update_button.setObjectName(f"{operation_type}_update_button")
|
self.update_button.setStyleSheet("""
|
||||||
update_button.setStyleSheet("""
|
|
||||||
QPushButton {
|
QPushButton {
|
||||||
background-color: #2196f3;
|
background-color: #2196f3;
|
||||||
color: white;
|
color: white;
|
||||||
@ -198,10 +128,9 @@ class PalletTypeSettingsUI(QWidget):
|
|||||||
}
|
}
|
||||||
""")
|
""")
|
||||||
|
|
||||||
delete_button = QPushButton("删除")
|
self.delete_button = QPushButton("删除")
|
||||||
delete_button.setFont(self.normal_font)
|
self.delete_button.setFont(self.normal_font)
|
||||||
delete_button.setObjectName(f"{operation_type}_delete_button")
|
self.delete_button.setStyleSheet("""
|
||||||
delete_button.setStyleSheet("""
|
|
||||||
QPushButton {
|
QPushButton {
|
||||||
background-color: #f44336;
|
background-color: #f44336;
|
||||||
color: white;
|
color: white;
|
||||||
@ -214,10 +143,9 @@ class PalletTypeSettingsUI(QWidget):
|
|||||||
}
|
}
|
||||||
""")
|
""")
|
||||||
|
|
||||||
cancel_button = QPushButton("取消")
|
self.cancel_button = QPushButton("取消")
|
||||||
cancel_button.setFont(self.normal_font)
|
self.cancel_button.setFont(self.normal_font)
|
||||||
cancel_button.setObjectName(f"{operation_type}_cancel_button")
|
self.cancel_button.setStyleSheet("""
|
||||||
cancel_button.setStyleSheet("""
|
|
||||||
QPushButton {
|
QPushButton {
|
||||||
background-color: #9e9e9e;
|
background-color: #9e9e9e;
|
||||||
color: white;
|
color: white;
|
||||||
@ -230,10 +158,10 @@ class PalletTypeSettingsUI(QWidget):
|
|||||||
}
|
}
|
||||||
""")
|
""")
|
||||||
|
|
||||||
button_layout.addWidget(add_button)
|
button_layout.addWidget(self.add_button)
|
||||||
button_layout.addWidget(update_button)
|
button_layout.addWidget(self.update_button)
|
||||||
button_layout.addWidget(delete_button)
|
button_layout.addWidget(self.delete_button)
|
||||||
button_layout.addWidget(cancel_button)
|
button_layout.addWidget(self.cancel_button)
|
||||||
|
|
||||||
layout.addLayout(button_layout)
|
layout.addLayout(button_layout)
|
||||||
|
|
||||||
|
|||||||
@ -249,3 +249,78 @@ class PalletTypeManager:
|
|||||||
bool: 是否保存成功
|
bool: 是否保存成功
|
||||||
"""
|
"""
|
||||||
return self.dao.save_pallet_archives(pallet_code, tier, user_id, user_name)
|
return self.dao.save_pallet_archives(pallet_code, tier, user_id, user_name)
|
||||||
|
|
||||||
|
def reload_pallet_types(self):
|
||||||
|
"""重新加载托盘类型数据"""
|
||||||
|
try:
|
||||||
|
self.pallet_types = self.dao.get_all_pallet_types_list()
|
||||||
|
logging.info(f"已重新加载托盘类型数据,共 {len(self.pallet_types)} 条")
|
||||||
|
return True
|
||||||
|
except Exception as e:
|
||||||
|
logging.error(f"重新加载托盘类型数据失败: {str(e)}")
|
||||||
|
return False
|
||||||
|
|
||||||
|
def get_all_pallet_types(self):
|
||||||
|
"""获取所有托盘类型
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
list: 托盘类型列表
|
||||||
|
"""
|
||||||
|
if not self.pallet_types:
|
||||||
|
self.reload_pallet_types()
|
||||||
|
return self.pallet_types
|
||||||
|
|
||||||
|
def add_pallet_type(self, pallet_id, pallet_name):
|
||||||
|
"""添加托盘类型
|
||||||
|
|
||||||
|
Args:
|
||||||
|
pallet_id: 托盘ID
|
||||||
|
pallet_name: 托盘名称
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
bool: 是否添加成功
|
||||||
|
"""
|
||||||
|
result = self.dao.add_pallet_type(pallet_id, pallet_name)
|
||||||
|
if result:
|
||||||
|
self.reload_pallet_types()
|
||||||
|
return result
|
||||||
|
|
||||||
|
def update_pallet_type(self, pallet_id, pallet_name):
|
||||||
|
"""更新托盘类型
|
||||||
|
|
||||||
|
Args:
|
||||||
|
pallet_id: 托盘ID
|
||||||
|
pallet_name: 托盘名称
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
bool: 是否更新成功
|
||||||
|
"""
|
||||||
|
result = self.dao.update_pallet_type(pallet_id, pallet_name)
|
||||||
|
if result:
|
||||||
|
self.reload_pallet_types()
|
||||||
|
return result
|
||||||
|
|
||||||
|
def delete_pallet_type_by_id(self, pallet_id):
|
||||||
|
"""删除托盘类型
|
||||||
|
|
||||||
|
Args:
|
||||||
|
pallet_id: 托盘ID
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
bool: 是否删除成功
|
||||||
|
"""
|
||||||
|
result = self.dao.delete_pallet_type(pallet_id)
|
||||||
|
if result:
|
||||||
|
self.reload_pallet_types()
|
||||||
|
return result
|
||||||
|
|
||||||
|
def get_pallet_type_by_id_new(self, pallet_id):
|
||||||
|
"""根据ID获取托盘类型(新版本)
|
||||||
|
|
||||||
|
Args:
|
||||||
|
pallet_id: 托盘ID
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
dict: 托盘类型信息,未找到则返回None
|
||||||
|
"""
|
||||||
|
return self.dao.get_pallet_type_by_id(pallet_id)
|
||||||
@ -310,7 +310,7 @@ class MainWindow(MainWindowUI):
|
|||||||
logging.info("显示主页面")
|
logging.info("显示主页面")
|
||||||
|
|
||||||
def load_pallet_codes(self):
|
def load_pallet_codes(self):
|
||||||
"""从托盘类型管理器加载托盘号并更新到tray_edit TODO:要实现动态数据源切换"""
|
"""从托盘类型管理器加载托盘号并更新到tray_edit"""
|
||||||
try:
|
try:
|
||||||
# 获取当前文本,以便保留用户选择
|
# 获取当前文本,以便保留用户选择
|
||||||
current_text = self.tray_edit.currentText()
|
current_text = self.tray_edit.currentText()
|
||||||
|
|||||||
@ -26,384 +26,200 @@ class PalletTypeSettingsWidget(PalletTypeSettingsUI):
|
|||||||
|
|
||||||
def connect_signals(self):
|
def connect_signals(self):
|
||||||
"""连接信号和槽"""
|
"""连接信号和槽"""
|
||||||
# 保存和重置按钮
|
# 保存和重置按钮 - 这些按钮已被删除,因此移除这些连接
|
||||||
self.save_button.clicked.connect(self.save_all_pallet_types)
|
# self.save_button.clicked.connect(self.save_all)
|
||||||
self.reset_button.clicked.connect(self.load_pallet_types)
|
# self.reset_button.clicked.connect(self.load_pallet_types)
|
||||||
|
|
||||||
# 下料类型表格和按钮
|
# 托盘类型操作按钮
|
||||||
output_table = self.output_widget.findChild(QTableWidget, "output_table")
|
self.add_button.clicked.connect(self.add_pallet_type)
|
||||||
output_table.itemSelectionChanged.connect(lambda: self.handle_table_selection("output"))
|
self.update_button.clicked.connect(self.update_pallet_type)
|
||||||
|
self.delete_button.clicked.connect(self.delete_pallet_type)
|
||||||
|
self.cancel_button.clicked.connect(self.cancel_edit)
|
||||||
|
|
||||||
output_add_button = self.output_widget.findChild(QPushButton, "output_add_button")
|
# 表格选择事件
|
||||||
output_add_button.clicked.connect(lambda: self.add_pallet_type("output"))
|
self.pallet_table.itemClicked.connect(self.on_table_item_clicked)
|
||||||
|
|
||||||
output_update_button = self.output_widget.findChild(QPushButton, "output_update_button")
|
|
||||||
output_update_button.clicked.connect(lambda: self.update_pallet_type("output"))
|
|
||||||
|
|
||||||
output_delete_button = self.output_widget.findChild(QPushButton, "output_delete_button")
|
|
||||||
output_delete_button.clicked.connect(lambda: self.delete_pallet_type("output"))
|
|
||||||
|
|
||||||
output_cancel_button = self.output_widget.findChild(QPushButton, "output_cancel_button")
|
|
||||||
output_cancel_button.clicked.connect(lambda: self.cancel_edit("output"))
|
|
||||||
|
|
||||||
def load_pallet_types(self):
|
def load_pallet_types(self):
|
||||||
"""加载托盘类型数据"""
|
"""加载托盘类型数据"""
|
||||||
try:
|
try:
|
||||||
# 重新加载数据
|
# 获取托盘类型数据
|
||||||
self.pallet_type_manager.reload_pallet_types()
|
pallet_types = self.pallet_type_manager.get_all_pallet_types()
|
||||||
|
|
||||||
# 加载下料类型
|
|
||||||
self.load_operation_pallet_types("output")
|
|
||||||
|
|
||||||
logging.info("托盘类型数据已加载")
|
|
||||||
except Exception as e:
|
|
||||||
logging.error(f"加载托盘类型数据失败: {str(e)}")
|
|
||||||
QMessageBox.critical(self, "错误", f"加载托盘类型数据失败: {str(e)}")
|
|
||||||
|
|
||||||
def load_operation_pallet_types(self, operation_type):
|
|
||||||
"""加载指定操作类型的托盘类型数据
|
|
||||||
|
|
||||||
Args:
|
|
||||||
operation_type: 操作类型 (output)
|
|
||||||
"""
|
|
||||||
# 获取表格
|
|
||||||
table = self.get_table_by_operation_type(operation_type)
|
|
||||||
if not table:
|
|
||||||
return
|
|
||||||
|
|
||||||
# 清空表格
|
# 清空表格
|
||||||
table.setRowCount(0)
|
self.pallet_table.setRowCount(0)
|
||||||
|
|
||||||
# 获取数据
|
|
||||||
pallet_types = self.pallet_type_manager.get_pallet_types_by_operation(operation_type, include_disabled=True)
|
|
||||||
|
|
||||||
# 填充表格
|
# 填充表格
|
||||||
for row, pallet_type in enumerate(pallet_types):
|
for pallet_type in pallet_types:
|
||||||
table.insertRow(row)
|
row = self.pallet_table.rowCount()
|
||||||
|
self.pallet_table.insertRow(row)
|
||||||
|
|
||||||
# 类型名称
|
# 设置托盘ID
|
||||||
type_name_item = QTableWidgetItem(pallet_type['type_name'])
|
id_item = QTableWidgetItem(str(pallet_type['id']))
|
||||||
type_name_item.setData(Qt.UserRole, pallet_type['id'])
|
id_item.setTextAlignment(Qt.AlignCenter)
|
||||||
table.setItem(row, 0, type_name_item)
|
self.pallet_table.setItem(row, 0, id_item)
|
||||||
|
|
||||||
# 描述
|
# 设置托盘名称
|
||||||
desc_item = QTableWidgetItem(pallet_type['description'] or "")
|
name_item = QTableWidgetItem(pallet_type['name'])
|
||||||
table.setItem(row, 1, desc_item)
|
name_item.setTextAlignment(Qt.AlignCenter)
|
||||||
|
self.pallet_table.setItem(row, 1, name_item)
|
||||||
|
|
||||||
# 排序
|
# 清空输入框
|
||||||
sort_order_item = QTableWidgetItem(str(pallet_type['sort_order']))
|
self.cancel_edit()
|
||||||
table.setItem(row, 2, sort_order_item)
|
|
||||||
|
|
||||||
# 启用状态
|
logging.info(f"已加载 {len(pallet_types)} 个托盘类型")
|
||||||
enabled_check = QCheckBox()
|
except Exception as e:
|
||||||
enabled_check.setChecked(pallet_type['enabled'])
|
logging.error(f"加载托盘类型失败: {str(e)}")
|
||||||
enabled_check.stateChanged.connect(lambda state, row=row, id=pallet_type['id']:
|
QMessageBox.critical(self, "错误", f"加载托盘类型失败: {str(e)}")
|
||||||
self.toggle_pallet_type(id, state == Qt.Checked))
|
|
||||||
table.setCellWidget(row, 3, enabled_check)
|
|
||||||
|
|
||||||
# 重置表单
|
def on_table_item_clicked(self, item):
|
||||||
self.reset_form(operation_type)
|
"""表格项点击事件
|
||||||
|
|
||||||
def get_table_by_operation_type(self, operation_type):
|
|
||||||
"""根据操作类型获取表格
|
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
operation_type: 操作类型 (output)
|
item: 点击的表格项
|
||||||
|
|
||||||
Returns:
|
|
||||||
QTableWidget: 表格部件
|
|
||||||
"""
|
"""
|
||||||
if operation_type == "output":
|
row = item.row()
|
||||||
return self.output_widget.findChild(QTableWidget, "output_table")
|
|
||||||
return None
|
|
||||||
|
|
||||||
def get_form_values(self, operation_type):
|
# 获取托盘ID和名称
|
||||||
"""获取表单值
|
pallet_id = self.pallet_table.item(row, 0).text()
|
||||||
|
pallet_name = self.pallet_table.item(row, 1).text()
|
||||||
|
|
||||||
Args:
|
# 填充输入框
|
||||||
operation_type: 操作类型 (output)
|
self.pallet_id_input.setText(pallet_id)
|
||||||
|
self.pallet_name_input.setText(pallet_name)
|
||||||
|
|
||||||
Returns:
|
def add_pallet_type(self):
|
||||||
dict: 表单值
|
"""添加托盘类型"""
|
||||||
"""
|
try:
|
||||||
widget = self.output_widget
|
# 获取输入值
|
||||||
|
pallet_id_text = self.pallet_id_input.text().strip()
|
||||||
|
pallet_name = self.pallet_name_input.text().strip()
|
||||||
|
|
||||||
type_name_input = widget.findChild(QLineEdit, f"{operation_type}_type_name_input")
|
# 验证输入
|
||||||
desc_input = widget.findChild(QLineEdit, f"{operation_type}_desc_input")
|
if not pallet_id_text or not pallet_name:
|
||||||
sort_order_spin = widget.findChild(QSpinBox, f"{operation_type}_sort_order_spin")
|
QMessageBox.warning(self, "警告", "托盘ID和托盘名称不能为空")
|
||||||
enabled_check = widget.findChild(QCheckBox, f"{operation_type}_enabled_check")
|
|
||||||
|
|
||||||
return {
|
|
||||||
'type_name': type_name_input.text().strip(),
|
|
||||||
'operation_type': operation_type,
|
|
||||||
'description': desc_input.text().strip(),
|
|
||||||
'sort_order': sort_order_spin.value(),
|
|
||||||
'enabled': enabled_check.isChecked()
|
|
||||||
}
|
|
||||||
|
|
||||||
def set_form_values(self, operation_type, values):
|
|
||||||
"""设置表单值
|
|
||||||
|
|
||||||
Args:
|
|
||||||
operation_type: 操作类型 (output)
|
|
||||||
values: 表单值
|
|
||||||
"""
|
|
||||||
widget = self.output_widget
|
|
||||||
|
|
||||||
type_name_input = widget.findChild(QLineEdit, f"{operation_type}_type_name_input")
|
|
||||||
desc_input = widget.findChild(QLineEdit, f"{operation_type}_desc_input")
|
|
||||||
sort_order_spin = widget.findChild(QSpinBox, f"{operation_type}_sort_order_spin")
|
|
||||||
enabled_check = widget.findChild(QCheckBox, f"{operation_type}_enabled_check")
|
|
||||||
|
|
||||||
type_name_input.setText(values.get('type_name', ''))
|
|
||||||
desc_input.setText(values.get('description', ''))
|
|
||||||
sort_order_spin.setValue(values.get('sort_order', 100))
|
|
||||||
enabled_check.setChecked(values.get('enabled', True))
|
|
||||||
|
|
||||||
def reset_form(self, operation_type):
|
|
||||||
"""重置表单
|
|
||||||
|
|
||||||
Args:
|
|
||||||
operation_type: 操作类型 (output)
|
|
||||||
"""
|
|
||||||
widget = self.output_widget
|
|
||||||
|
|
||||||
# 重置表单值
|
|
||||||
self.set_form_values(operation_type, {
|
|
||||||
'type_name': '',
|
|
||||||
'description': '',
|
|
||||||
'sort_order': 100,
|
|
||||||
'enabled': True
|
|
||||||
})
|
|
||||||
|
|
||||||
# 重置当前编辑ID
|
|
||||||
widget.setProperty("current_edit_id", -1)
|
|
||||||
|
|
||||||
def handle_table_selection(self, operation_type):
|
|
||||||
"""处理表格选择事件
|
|
||||||
|
|
||||||
Args:
|
|
||||||
operation_type: 操作类型 (output)
|
|
||||||
"""
|
|
||||||
# 获取表格
|
|
||||||
table = self.get_table_by_operation_type(operation_type)
|
|
||||||
if not table:
|
|
||||||
return
|
return
|
||||||
|
|
||||||
# 获取选中行
|
# 检查ID是否为数字
|
||||||
selected_items = table.selectedItems()
|
try:
|
||||||
if not selected_items:
|
pallet_id = int(pallet_id_text)
|
||||||
|
except ValueError:
|
||||||
|
QMessageBox.warning(self, "警告", "托盘ID必须为数字")
|
||||||
return
|
return
|
||||||
|
|
||||||
# 获取行数据
|
|
||||||
row = selected_items[0].row()
|
|
||||||
|
|
||||||
# 获取ID
|
|
||||||
id_item = table.item(row, 0)
|
|
||||||
if not id_item:
|
|
||||||
return
|
|
||||||
|
|
||||||
pallet_type_id = id_item.data(Qt.UserRole)
|
|
||||||
|
|
||||||
# 获取托盘类型数据
|
|
||||||
pallet_type = self.pallet_type_manager.get_pallet_type_by_id(pallet_type_id)
|
|
||||||
if not pallet_type:
|
|
||||||
return
|
|
||||||
|
|
||||||
# 设置表单值
|
|
||||||
self.set_form_values(operation_type, pallet_type)
|
|
||||||
|
|
||||||
# 设置当前编辑ID
|
|
||||||
widget = self.output_widget
|
|
||||||
widget.setProperty("current_edit_id", pallet_type_id)
|
|
||||||
|
|
||||||
def validate_form(self, operation_type):
|
|
||||||
"""验证表单
|
|
||||||
|
|
||||||
Args:
|
|
||||||
operation_type: 操作类型 (output)
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
bool: 验证是否通过
|
|
||||||
"""
|
|
||||||
values = self.get_form_values(operation_type)
|
|
||||||
|
|
||||||
if not values['type_name']:
|
|
||||||
QMessageBox.warning(self, "警告", "请输入类型名称")
|
|
||||||
return False
|
|
||||||
|
|
||||||
return True
|
|
||||||
|
|
||||||
def add_pallet_type(self, operation_type):
|
|
||||||
"""添加托盘类型
|
|
||||||
|
|
||||||
Args:
|
|
||||||
operation_type: 操作类型 (output)
|
|
||||||
"""
|
|
||||||
# 验证表单
|
|
||||||
if not self.validate_form(operation_type):
|
|
||||||
return
|
|
||||||
|
|
||||||
# 获取表单值
|
|
||||||
values = self.get_form_values(operation_type)
|
|
||||||
|
|
||||||
# 添加托盘类型
|
# 添加托盘类型
|
||||||
success = self.pallet_type_manager.add_pallet_type(values)
|
result = self.pallet_type_manager.add_pallet_type(pallet_id, pallet_name)
|
||||||
|
if not result:
|
||||||
|
QMessageBox.critical(self, "错误", "添加托盘类型失败")
|
||||||
|
return
|
||||||
|
|
||||||
if success:
|
|
||||||
# 重新加载数据
|
# 重新加载数据
|
||||||
self.load_operation_pallet_types(operation_type)
|
self.load_pallet_types()
|
||||||
|
|
||||||
# 重置表单
|
|
||||||
self.reset_form(operation_type)
|
|
||||||
|
|
||||||
# 发送信号
|
# 发送信号
|
||||||
self.signal_pallet_types_changed.emit()
|
self.signal_pallet_types_changed.emit()
|
||||||
self.settings_changed.emit() # 发送设置变更信号
|
self.settings_changed.emit()
|
||||||
|
|
||||||
logging.info(f"已添加{operation_type}托盘类型: {values['type_name']}")
|
# 提示成功
|
||||||
else:
|
QMessageBox.information(self, "成功", f"已添加托盘类型: {pallet_name}")
|
||||||
QMessageBox.critical(self, "错误", f"添加{operation_type}托盘类型失败")
|
except Exception as e:
|
||||||
logging.error(f"添加{operation_type}托盘类型失败: {values['type_name']}")
|
logging.error(f"添加托盘类型失败: {str(e)}")
|
||||||
|
QMessageBox.critical(self, "错误", f"添加托盘类型失败: {str(e)}")
|
||||||
|
|
||||||
def update_pallet_type(self, operation_type):
|
def update_pallet_type(self):
|
||||||
"""更新托盘类型
|
"""更新托盘类型"""
|
||||||
|
try:
|
||||||
|
# 获取输入值
|
||||||
|
pallet_id_text = self.pallet_id_input.text().strip()
|
||||||
|
pallet_name = self.pallet_name_input.text().strip()
|
||||||
|
|
||||||
Args:
|
# 验证输入
|
||||||
operation_type: 操作类型 (output)
|
if not pallet_id_text or not pallet_name:
|
||||||
"""
|
QMessageBox.warning(self, "警告", "托盘ID和托盘名称不能为空")
|
||||||
# 获取当前编辑ID
|
|
||||||
widget = self.output_widget
|
|
||||||
pallet_type_id = widget.property("current_edit_id")
|
|
||||||
|
|
||||||
if pallet_type_id < 0:
|
|
||||||
QMessageBox.warning(self, "警告", "请先选择要编辑的托盘类型")
|
|
||||||
return
|
return
|
||||||
|
|
||||||
# 验证表单
|
# 检查ID是否为数字
|
||||||
if not self.validate_form(operation_type):
|
try:
|
||||||
|
pallet_id = int(pallet_id_text)
|
||||||
|
except ValueError:
|
||||||
|
QMessageBox.warning(self, "警告", "托盘ID必须为数字")
|
||||||
return
|
return
|
||||||
|
|
||||||
# 获取表单值
|
|
||||||
values = self.get_form_values(operation_type)
|
|
||||||
|
|
||||||
# 更新托盘类型
|
# 更新托盘类型
|
||||||
success = self.pallet_type_manager.update_pallet_type(pallet_type_id, values)
|
result = self.pallet_type_manager.update_pallet_type(pallet_id, pallet_name)
|
||||||
|
if not result:
|
||||||
|
QMessageBox.critical(self, "错误", "更新托盘类型失败")
|
||||||
|
return
|
||||||
|
|
||||||
if success:
|
|
||||||
# 重新加载数据
|
# 重新加载数据
|
||||||
self.load_operation_pallet_types(operation_type)
|
self.load_pallet_types()
|
||||||
|
|
||||||
# 重置表单
|
|
||||||
self.reset_form(operation_type)
|
|
||||||
|
|
||||||
# 发送信号
|
# 发送信号
|
||||||
self.signal_pallet_types_changed.emit()
|
self.signal_pallet_types_changed.emit()
|
||||||
self.settings_changed.emit() # 发送设置变更信号
|
self.settings_changed.emit()
|
||||||
|
|
||||||
logging.info(f"已更新{operation_type}托盘类型: {values['type_name']}")
|
# 提示成功
|
||||||
else:
|
QMessageBox.information(self, "成功", f"已更新托盘类型: {pallet_name}")
|
||||||
QMessageBox.critical(self, "错误", f"更新{operation_type}托盘类型失败")
|
except Exception as e:
|
||||||
logging.error(f"更新{operation_type}托盘类型失败: {values['type_name']}")
|
logging.error(f"更新托盘类型失败: {str(e)}")
|
||||||
|
QMessageBox.critical(self, "错误", f"更新托盘类型失败: {str(e)}")
|
||||||
|
|
||||||
def delete_pallet_type(self, operation_type):
|
def delete_pallet_type(self):
|
||||||
"""删除托盘类型
|
"""删除托盘类型"""
|
||||||
|
try:
|
||||||
|
# 获取输入值
|
||||||
|
pallet_id_text = self.pallet_id_input.text().strip()
|
||||||
|
|
||||||
Args:
|
# 验证输入
|
||||||
operation_type: 操作类型 (output)
|
if not pallet_id_text:
|
||||||
"""
|
|
||||||
# 获取选中行
|
|
||||||
table = self.get_table_by_operation_type(operation_type)
|
|
||||||
if not table:
|
|
||||||
return
|
|
||||||
|
|
||||||
selected_items = table.selectedItems()
|
|
||||||
if not selected_items:
|
|
||||||
QMessageBox.warning(self, "警告", "请先选择要删除的托盘类型")
|
QMessageBox.warning(self, "警告", "请先选择要删除的托盘类型")
|
||||||
return
|
return
|
||||||
|
|
||||||
# 获取托盘类型ID
|
# 检查ID是否为数字
|
||||||
row = selected_items[0].row()
|
try:
|
||||||
id_item = table.item(row, 0)
|
pallet_id = int(pallet_id_text)
|
||||||
if not id_item:
|
except ValueError:
|
||||||
|
QMessageBox.warning(self, "警告", "托盘ID必须为数字")
|
||||||
return
|
return
|
||||||
|
|
||||||
pallet_type_id = id_item.data(Qt.UserRole)
|
|
||||||
type_name = id_item.text()
|
|
||||||
|
|
||||||
# 确认删除
|
# 确认删除
|
||||||
reply = QMessageBox.question(self, "确认删除", f"确定要删除{operation_type}托盘类型 [{type_name}] 吗?",
|
reply = QMessageBox.question(
|
||||||
QMessageBox.Yes | QMessageBox.No, QMessageBox.No)
|
self,
|
||||||
|
"确认删除",
|
||||||
|
f"确定要删除托盘ID为 {pallet_id} 的托盘类型吗?",
|
||||||
|
QMessageBox.Yes | QMessageBox.No,
|
||||||
|
QMessageBox.No
|
||||||
|
)
|
||||||
|
|
||||||
if reply != QMessageBox.Yes:
|
if reply != QMessageBox.Yes:
|
||||||
return
|
return
|
||||||
|
|
||||||
# 删除托盘类型
|
# 删除托盘类型
|
||||||
success = self.pallet_type_manager.delete_pallet_type(pallet_type_id)
|
result = self.pallet_type_manager.delete_pallet_type_by_id(pallet_id)
|
||||||
|
if not result:
|
||||||
|
QMessageBox.critical(self, "错误", "删除托盘类型失败")
|
||||||
|
return
|
||||||
|
|
||||||
if success:
|
|
||||||
# 重新加载数据
|
# 重新加载数据
|
||||||
self.load_operation_pallet_types(operation_type)
|
self.load_pallet_types()
|
||||||
|
|
||||||
# 重置表单
|
|
||||||
self.reset_form(operation_type)
|
|
||||||
|
|
||||||
# 发送信号
|
# 发送信号
|
||||||
self.signal_pallet_types_changed.emit()
|
self.signal_pallet_types_changed.emit()
|
||||||
self.settings_changed.emit() # 发送设置变更信号
|
self.settings_changed.emit()
|
||||||
|
|
||||||
logging.info(f"已删除{operation_type}托盘类型: {type_name}")
|
# 提示成功
|
||||||
else:
|
QMessageBox.information(self, "成功", f"已删除托盘类型: {pallet_id}")
|
||||||
QMessageBox.critical(self, "错误", f"删除{operation_type}托盘类型失败")
|
except Exception as e:
|
||||||
logging.error(f"删除{operation_type}托盘类型失败: {type_name}")
|
logging.error(f"删除托盘类型失败: {str(e)}")
|
||||||
|
QMessageBox.critical(self, "错误", f"删除托盘类型失败: {str(e)}")
|
||||||
|
|
||||||
def cancel_edit(self, operation_type):
|
def cancel_edit(self):
|
||||||
"""取消编辑
|
"""取消编辑"""
|
||||||
|
# 清空输入框
|
||||||
|
self.pallet_id_input.clear()
|
||||||
|
self.pallet_name_input.clear()
|
||||||
|
|
||||||
Args:
|
# 此方法不再需要,因为相关按钮已被删除
|
||||||
operation_type: 操作类型 (output)
|
# def save_all(self):
|
||||||
"""
|
# """保存所有配置(实际上是空操作,因为每次修改都会立即保存)"""
|
||||||
# 重置表单
|
# QMessageBox.information(self, "成功", "所有配置已保存")
|
||||||
self.reset_form(operation_type)
|
|
||||||
|
|
||||||
# 清除表格选择
|
|
||||||
table = self.get_table_by_operation_type(operation_type)
|
|
||||||
if table:
|
|
||||||
table.clearSelection()
|
|
||||||
|
|
||||||
def toggle_pallet_type(self, pallet_type_id, enabled):
|
|
||||||
"""切换托盘类型启用状态
|
|
||||||
|
|
||||||
Args:
|
|
||||||
pallet_type_id: 托盘类型ID
|
|
||||||
enabled: 是否启用
|
|
||||||
"""
|
|
||||||
# 更新托盘类型启用状态
|
|
||||||
success = self.pallet_type_manager.update_pallet_type_status(pallet_type_id, enabled)
|
|
||||||
|
|
||||||
if success:
|
|
||||||
# 发送信号
|
|
||||||
self.signal_pallet_types_changed.emit()
|
|
||||||
self.settings_changed.emit() # 发送设置变更信号
|
|
||||||
|
|
||||||
logging.info(f"已{('启用' if enabled else '禁用')}托盘类型: {pallet_type_id}")
|
|
||||||
else:
|
|
||||||
QMessageBox.critical(self, "错误", f"更新托盘类型状态失败")
|
|
||||||
logging.error(f"更新托盘类型状态失败: {pallet_type_id}")
|
|
||||||
|
|
||||||
def save_all_pallet_types(self):
|
|
||||||
"""保存所有托盘类型"""
|
|
||||||
# 保存所有托盘类型
|
|
||||||
success = self.pallet_type_manager.save_all_pallet_types()
|
|
||||||
|
|
||||||
if success:
|
|
||||||
QMessageBox.information(self, "成功", "所有托盘类型已保存")
|
|
||||||
|
|
||||||
# 发送信号
|
|
||||||
self.signal_pallet_types_changed.emit()
|
|
||||||
self.settings_changed.emit() # 发送设置变更信号
|
|
||||||
|
|
||||||
logging.info("已保存所有托盘类型")
|
|
||||||
else:
|
|
||||||
QMessageBox.critical(self, "错误", "保存托盘类型失败")
|
|
||||||
logging.error("保存托盘类型失败")
|
|
||||||
Loading…
Reference in New Issue
Block a user