1221暂存
This commit is contained in:
@@ -1014,18 +1014,23 @@ class GarmentEditDialog(QDialog):
|
|||||||
def load_materials(self):
|
def load_materials(self):
|
||||||
try:
|
try:
|
||||||
with self.get_conn() as conn:
|
with self.get_conn() as conn:
|
||||||
cursor = conn.execute("SELECT category, usage_per_piece, unit FROM garment_materials WHERE style_number = ? ORDER BY id", (self.style_number,))
|
cursor = conn.execute("SELECT category, fabric_type, usage_per_piece, unit FROM garment_materials WHERE style_number = ? ORDER BY id", (self.style_number,))
|
||||||
for category, usage, unit in cursor.fetchall():
|
for category, fabric_type, usage, unit in cursor.fetchall():
|
||||||
self.add_material_row(category, usage or 0, unit or "米")
|
# 如果是旧数据(category包含"-"),需要拆分
|
||||||
|
if category and "-" in category and not fabric_type:
|
||||||
|
parts = category.split("-", 1)
|
||||||
|
category = parts[0]
|
||||||
|
fabric_type = parts[1] if len(parts) > 1 else ""
|
||||||
|
self.add_material_row(category or "", fabric_type or "", usage or 0, unit or "米")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
QMessageBox.critical(self, "错误", "加载材料失败: " + str(e))
|
QMessageBox.critical(self, "错误", "加载材料失败: " + str(e))
|
||||||
|
|
||||||
def add_default_categories(self):
|
def add_default_categories(self):
|
||||||
defaults = [("A料", "米"), ("B料", "米"), ("C料", "米"), ("D料", "米"), ("花边", "码"), ("胸杯", "一对"), ("拉链", "个"), ("辅料", "个")]
|
defaults = [("A料", "", "米"), ("B料", "", "米"), ("C料", "", "米"), ("D料", "", "米"), ("花边", "", "码"), ("胸杯", "", "一对"), ("拉链", "", "个"), ("辅料", "", "个")]
|
||||||
for cat, unit in defaults:
|
for cat, fabric_type, unit in defaults:
|
||||||
self.add_material_row(cat, 0, unit)
|
self.add_material_row(cat, fabric_type, 0, unit)
|
||||||
|
|
||||||
def add_material_row(self, category="", usage=0.0, unit="米"):
|
def add_material_row(self, category="", fabric_type="", usage=0.0, unit="米"):
|
||||||
row = self.material_table.rowCount()
|
row = self.material_table.rowCount()
|
||||||
self.material_table.insertRow(row)
|
self.material_table.insertRow(row)
|
||||||
|
|
||||||
@@ -1036,12 +1041,32 @@ class GarmentEditDialog(QDialog):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
with self.get_conn() as conn:
|
with self.get_conn() as conn:
|
||||||
cursor = conn.execute("SELECT DISTINCT category FROM fabrics WHERE category IS NOT NULL AND category != '' ORDER BY category")
|
# 只获取纯类目(提取"-"前面的部分)
|
||||||
categories = cursor.fetchall()
|
cursor = conn.execute("""
|
||||||
for cat_row in categories:
|
SELECT DISTINCT
|
||||||
cat_combo.addItem(cat_row[0])
|
CASE
|
||||||
|
WHEN category LIKE '%-%' THEN SUBSTR(category, 1, INSTR(category, '-') - 1)
|
||||||
|
ELSE category
|
||||||
|
END as major_category
|
||||||
|
FROM fabrics
|
||||||
|
WHERE category IS NOT NULL AND category != ''
|
||||||
|
ORDER BY major_category
|
||||||
|
""")
|
||||||
|
categories = set()
|
||||||
|
for cat_row in cursor.fetchall():
|
||||||
|
if cat_row[0] and cat_row[0].strip():
|
||||||
|
categories.add(cat_row[0])
|
||||||
|
|
||||||
|
# 添加默认类目
|
||||||
|
categories.update(["布料", "辅料", "其他"])
|
||||||
|
|
||||||
|
for cat in sorted(categories):
|
||||||
|
cat_combo.addItem(cat)
|
||||||
except:
|
except:
|
||||||
pass
|
# 如果查询失败,使用默认类目
|
||||||
|
cat_combo.addItem("布料")
|
||||||
|
cat_combo.addItem("辅料")
|
||||||
|
cat_combo.addItem("其他")
|
||||||
|
|
||||||
if category:
|
if category:
|
||||||
cat_combo.setCurrentText(category)
|
cat_combo.setCurrentText(category)
|
||||||
@@ -1053,6 +1078,9 @@ class GarmentEditDialog(QDialog):
|
|||||||
type_combo = QComboBox()
|
type_combo = QComboBox()
|
||||||
type_combo.setEditable(True)
|
type_combo.setEditable(True)
|
||||||
type_combo.addItem("—— 选择类型 ——")
|
type_combo.addItem("—— 选择类型 ——")
|
||||||
|
if fabric_type:
|
||||||
|
type_combo.setCurrentText(fabric_type)
|
||||||
|
type_combo.currentTextChanged.connect(lambda text, r=row: self.on_type_changed(text, r))
|
||||||
self.material_table.setCellWidget(row, 1, type_combo)
|
self.material_table.setCellWidget(row, 1, type_combo)
|
||||||
|
|
||||||
# 列2: 型号下拉框
|
# 列2: 型号下拉框
|
||||||
@@ -1137,20 +1165,21 @@ class GarmentEditDialog(QDialog):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
with self.get_conn() as conn:
|
with self.get_conn() as conn:
|
||||||
# 根据类目和类型获取对应的型号
|
# 根据类目和类型获取对应的型号,现在需要匹配分开的字段或组合的旧格式
|
||||||
cursor = conn.execute("""
|
cursor = conn.execute("""
|
||||||
SELECT model, color, unit
|
SELECT model, color, unit
|
||||||
FROM fabrics
|
FROM fabrics
|
||||||
WHERE category = ? OR category LIKE ?
|
WHERE category = ? OR category = ? OR category LIKE ?
|
||||||
ORDER BY model
|
ORDER BY model
|
||||||
""", (f"{category_text}-{type_text}", f"{category_text}-{type_text}-%"))
|
""", (category_text, f"{category_text}-{type_text}", f"{category_text}-{type_text}-%"))
|
||||||
|
|
||||||
models = cursor.fetchall()
|
models = cursor.fetchall()
|
||||||
for model_row in models:
|
for model_row in models:
|
||||||
model, color, unit = model_row
|
model, color, unit = model_row
|
||||||
display_text = f"{model}"
|
# 显示格式:型号-颜色(如果有颜色的话)
|
||||||
if color:
|
display_text = model
|
||||||
display_text += f"-{color}"
|
if color and color.strip():
|
||||||
|
display_text = f"{model}-{color}"
|
||||||
model_combo.addItem(display_text, model)
|
model_combo.addItem(display_text, model)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
pass
|
pass
|
||||||
@@ -1203,26 +1232,30 @@ class GarmentEditDialog(QDialog):
|
|||||||
fabric_type = type_widget.currentText().strip()
|
fabric_type = type_widget.currentText().strip()
|
||||||
model = model_widget.currentText().strip()
|
model = model_widget.currentText().strip()
|
||||||
|
|
||||||
# 构建完整的材料标识
|
# 处理类目和类型
|
||||||
if model and model != "—— 选择型号 ——":
|
if category == "—— 自定义类目 ——":
|
||||||
# 如果选择了具体型号,使用型号作为category存储
|
category = ""
|
||||||
model_data = model_widget.itemData(model_widget.currentIndex())
|
if fabric_type == "—— 选择类型 ——":
|
||||||
final_category = model_data if model_data else model
|
fabric_type = ""
|
||||||
elif fabric_type and fabric_type != "—— 选择类型 ——":
|
|
||||||
# 如果只选择了类型,组合类目和类型
|
|
||||||
final_category = f"{category}-{fabric_type}"
|
|
||||||
else:
|
|
||||||
# 只有类目
|
|
||||||
final_category = category
|
|
||||||
|
|
||||||
if not final_category or final_category == "—— 自定义类目 ——":
|
# 如果选择了具体型号,获取型号的实际值
|
||||||
|
final_model = ""
|
||||||
|
if model and model != "—— 选择型号 ——":
|
||||||
|
model_data = model_widget.itemData(model_widget.currentIndex())
|
||||||
|
final_model = model_data if model_data else model
|
||||||
|
|
||||||
|
# 至少需要有类目或型号
|
||||||
|
if not category and not final_model:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
usage = usage_widget.value()
|
usage = usage_widget.value()
|
||||||
unit = unit_widget.currentText().strip() or "米"
|
unit = unit_widget.currentText().strip() or "米"
|
||||||
|
|
||||||
conn.execute("INSERT INTO garment_materials (style_number, category, usage_per_piece, unit) VALUES (?, ?, ?, ?)",
|
# 分别存储类目、类型和型号信息
|
||||||
(style_number, final_category, usage, unit))
|
material_identifier = final_model if final_model else (f"{category}-{fabric_type}" if fabric_type else category)
|
||||||
|
|
||||||
|
conn.execute("INSERT INTO garment_materials (style_number, category, fabric_type, usage_per_piece, unit) VALUES (?, ?, ?, ?, ?)",
|
||||||
|
(style_number, material_identifier, fabric_type, usage, unit))
|
||||||
|
|
||||||
conn.commit()
|
conn.commit()
|
||||||
QMessageBox.information(self, "成功", "保存完成")
|
QMessageBox.information(self, "成功", "保存完成")
|
||||||
@@ -1286,16 +1319,18 @@ class PurchaseOrderDialog(QDialog):
|
|||||||
try:
|
try:
|
||||||
with self.get_conn() as conn:
|
with self.get_conn() as conn:
|
||||||
cursor = conn.execute('''
|
cursor = conn.execute('''
|
||||||
SELECT category, usage_per_piece, unit
|
SELECT category, fabric_type, usage_per_piece, unit
|
||||||
FROM garment_materials
|
FROM garment_materials
|
||||||
WHERE style_number = ? AND usage_per_piece > 0
|
WHERE style_number = ? AND usage_per_piece > 0
|
||||||
ORDER BY id
|
ORDER BY id
|
||||||
''', (self.style_number,))
|
''', (self.style_number,))
|
||||||
rows = cursor.fetchall()
|
rows = cursor.fetchall()
|
||||||
|
|
||||||
for category, usage_per_piece, unit in rows:
|
for category, fabric_type, usage_per_piece, unit in rows:
|
||||||
total_usage = usage_per_piece * self.quantity * (1 + self.loss_rate)
|
total_usage = usage_per_piece * self.quantity * (1 + self.loss_rate)
|
||||||
text += f"材料:{category}\n"
|
# 显示材料名称(如果有类型则显示类目-类型,否则只显示类目)
|
||||||
|
material_name = f"{category}-{fabric_type}" if fabric_type else category
|
||||||
|
text += f"材料:{material_name}\n"
|
||||||
text += f" 单件用量:{usage_per_piece:.3f} {unit}\n"
|
text += f" 单件用量:{usage_per_piece:.3f} {unit}\n"
|
||||||
text += f" 总需采购:{total_usage:.3f} {unit}\n\n"
|
text += f" 总需采购:{total_usage:.3f} {unit}\n\n"
|
||||||
|
|
||||||
@@ -1384,13 +1419,13 @@ class FabricManager(QMainWindow):
|
|||||||
try:
|
try:
|
||||||
with self.get_conn() as conn:
|
with self.get_conn() as conn:
|
||||||
cursor = conn.execute('''
|
cursor = conn.execute('''
|
||||||
SELECT category, usage_per_piece, unit
|
SELECT category, fabric_type, usage_per_piece, unit
|
||||||
FROM garment_materials
|
FROM garment_materials
|
||||||
WHERE style_number = ?
|
WHERE style_number = ?
|
||||||
''', (style_number,))
|
''', (style_number,))
|
||||||
rows = cursor.fetchall()
|
rows = cursor.fetchall()
|
||||||
inserted = 0
|
inserted = 0
|
||||||
for category, usage_per_piece, unit in rows:
|
for category, fabric_type, usage_per_piece, unit in rows:
|
||||||
if usage_per_piece == 0:
|
if usage_per_piece == 0:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
@@ -1475,11 +1510,13 @@ class FabricManager(QMainWindow):
|
|||||||
text = f"款号: {style_number}\n生产件数: {qty}\n损耗率: {self.loss_input.value()}%\n\n"
|
text = f"款号: {style_number}\n生产件数: {qty}\n损耗率: {self.loss_input.value()}%\n\n"
|
||||||
try:
|
try:
|
||||||
with self.get_conn() as conn:
|
with self.get_conn() as conn:
|
||||||
cursor = conn.execute("SELECT category, usage_per_piece, unit FROM garment_materials WHERE style_number = ? ORDER BY id", (style_number,))
|
cursor = conn.execute("SELECT category, fabric_type, usage_per_piece, unit FROM garment_materials WHERE style_number = ? ORDER BY id", (style_number,))
|
||||||
for cat, usage, unit in cursor.fetchall():
|
for category, fabric_type, usage, unit in cursor.fetchall():
|
||||||
if usage:
|
if usage:
|
||||||
total = usage * qty * (1 + loss)
|
total = usage * qty * (1 + loss)
|
||||||
text += f"{cat}\n单件: {usage:.3f} {unit}\n总用量: {total:.3f} {unit}\n\n"
|
# 显示材料名称(如果有类型则显示类目-类型,否则只显示类目)
|
||||||
|
material_name = f"{category}-{fabric_type}" if fabric_type else category
|
||||||
|
text += f"{material_name}\n单件: {usage:.3f} {unit}\n总用量: {total:.3f} {unit}\n\n"
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
text += "计算失败: " + str(e)
|
text += "计算失败: " + str(e)
|
||||||
self.result_text.setText(text)
|
self.result_text.setText(text)
|
||||||
@@ -1651,11 +1688,18 @@ class FabricManager(QMainWindow):
|
|||||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
style_number TEXT,
|
style_number TEXT,
|
||||||
category TEXT,
|
category TEXT,
|
||||||
|
fabric_type TEXT,
|
||||||
usage_per_piece REAL,
|
usage_per_piece REAL,
|
||||||
unit TEXT DEFAULT '米'
|
unit TEXT DEFAULT '米'
|
||||||
)
|
)
|
||||||
''')
|
''')
|
||||||
|
|
||||||
|
# 添加fabric_type列(如果不存在)
|
||||||
|
try:
|
||||||
|
conn.execute("ALTER TABLE garment_materials ADD COLUMN fabric_type TEXT")
|
||||||
|
except:
|
||||||
|
pass # 列已存在
|
||||||
|
|
||||||
conn.execute('''
|
conn.execute('''
|
||||||
CREATE TABLE IF NOT EXISTS admin_settings (
|
CREATE TABLE IF NOT EXISTS admin_settings (
|
||||||
key TEXT PRIMARY KEY,
|
key TEXT PRIMARY KEY,
|
||||||
|
|||||||
Reference in New Issue
Block a user