编辑款式下拉框修复
This commit is contained in:
@@ -246,7 +246,7 @@ class RawMaterialLibraryDialog(QDialog):
|
||||
"""加载主类目"""
|
||||
try:
|
||||
with self.get_conn() as conn:
|
||||
cursor = conn.execute("SELECT DISTINCT CASE WHEN category LIKE '%-%' THEN SUBSTR(category, 1, INSTR(category, '-') - 1) ELSE category END FROM fabrics")
|
||||
cursor = conn.execute("SELECT DISTINCT category FROM fabrics WHERE category IS NOT NULL AND category != ''")
|
||||
majors = set(row[0] for row in cursor.fetchall() if row[0])
|
||||
majors.update({"布料", "辅料", "其他"})
|
||||
|
||||
@@ -263,7 +263,7 @@ class RawMaterialLibraryDialog(QDialog):
|
||||
"""加载添加界面的主类目"""
|
||||
try:
|
||||
with self.get_conn() as conn:
|
||||
cursor = conn.execute("SELECT DISTINCT CASE WHEN category LIKE '%-%' THEN SUBSTR(category, 1, INSTR(category, '-') - 1) ELSE category END FROM fabrics")
|
||||
cursor = conn.execute("SELECT DISTINCT category FROM fabrics WHERE category IS NOT NULL AND category != ''")
|
||||
majors = set(row[0] for row in cursor.fetchall() if row[0])
|
||||
majors.update({"布料", "辅料", "其他"})
|
||||
|
||||
@@ -292,20 +292,12 @@ class RawMaterialLibraryDialog(QDialog):
|
||||
try:
|
||||
with self.get_conn() as conn:
|
||||
if major in ("全部类目", ""):
|
||||
cursor = conn.execute("SELECT DISTINCT category FROM fabrics WHERE category LIKE '%-%'")
|
||||
subs = set()
|
||||
for row in cursor.fetchall():
|
||||
cat = row[0]
|
||||
if '-' in cat:
|
||||
subs.add(cat.split('-', 1)[1])
|
||||
cursor = conn.execute("SELECT DISTINCT fabric_type FROM fabrics WHERE fabric_type IS NOT NULL AND fabric_type != ''")
|
||||
subs = [row[0] for row in cursor.fetchall() if row[0]]
|
||||
self.sub_combo.addItems(sorted(subs))
|
||||
else:
|
||||
cursor = conn.execute("SELECT category FROM fabrics WHERE category LIKE ? OR category = ?", (major + "-%", major))
|
||||
subs = set()
|
||||
for row in cursor.fetchall():
|
||||
cat = row[0]
|
||||
if '-' in cat:
|
||||
subs.add(cat.split('-', 1)[1])
|
||||
cursor = conn.execute("SELECT DISTINCT fabric_type FROM fabrics WHERE category = ? AND fabric_type IS NOT NULL AND fabric_type != ''", (major,))
|
||||
subs = [row[0] for row in cursor.fetchall() if row[0]]
|
||||
self.sub_combo.addItems(sorted(subs))
|
||||
except:
|
||||
pass
|
||||
@@ -337,7 +329,7 @@ class RawMaterialLibraryDialog(QDialog):
|
||||
"""加载原料表格数据"""
|
||||
try:
|
||||
with self.get_conn() as conn:
|
||||
query = "SELECT category, model, supplier, color, width, gsm, unit, retail_price, bulk_price FROM fabrics"
|
||||
query = "SELECT category, fabric_type, model, supplier, color, width, gsm, unit, retail_price, bulk_price FROM fabrics"
|
||||
params = []
|
||||
conditions = []
|
||||
|
||||
@@ -346,11 +338,11 @@ class RawMaterialLibraryDialog(QDialog):
|
||||
sub = self.sub_combo.currentText()
|
||||
if major != "全部类目" and major:
|
||||
if sub != "全部类型" and sub:
|
||||
conditions.append("category = ?")
|
||||
params.append(major + "-" + sub)
|
||||
conditions.append("category = ? AND fabric_type = ?")
|
||||
params.append(major)
|
||||
params.append(sub)
|
||||
else:
|
||||
conditions.append("(category LIKE ? OR category = ?)")
|
||||
params.append(major + "-%")
|
||||
conditions.append("category = ?")
|
||||
params.append(major)
|
||||
|
||||
# 供应商过滤
|
||||
@@ -377,9 +369,9 @@ class RawMaterialLibraryDialog(QDialog):
|
||||
self.table.setRowCount(len(rows))
|
||||
self.table.clearContents()
|
||||
|
||||
for row_idx, (category, model, supplier, color, width, gsm, unit, retail, bulk) in enumerate(rows):
|
||||
major = category.split('-', 1)[0] if '-' in category else category
|
||||
sub = category.split('-', 1)[1] if '-' in category else ""
|
||||
for row_idx, (category, fabric_type, model, supplier, color, width, gsm, unit, retail, bulk) in enumerate(rows):
|
||||
major = category or ""
|
||||
sub = fabric_type or ""
|
||||
|
||||
self.table.setItem(row_idx, 0, QTableWidgetItem(major))
|
||||
self.table.setItem(row_idx, 1, QTableWidgetItem(sub))
|
||||
@@ -433,16 +425,16 @@ class RawMaterialLibraryDialog(QDialog):
|
||||
"""编辑原料"""
|
||||
try:
|
||||
with self.get_conn() as conn:
|
||||
cursor = conn.execute("SELECT category, supplier, color, width, gsm, unit, retail_price, bulk_price FROM fabrics WHERE model = ?", (model,))
|
||||
cursor = conn.execute("SELECT category, fabric_type, supplier, color, width, gsm, unit, retail_price, bulk_price FROM fabrics WHERE model = ?", (model,))
|
||||
row = cursor.fetchone()
|
||||
if not row:
|
||||
QMessageBox.warning(self, "提示", "原料不存在或已被删除")
|
||||
return
|
||||
|
||||
category, supplier, color, width, gsm, unit, retail, bulk = row
|
||||
category, fabric_type, supplier, color, width, gsm, unit, retail, bulk = row
|
||||
|
||||
major = category.split('-', 1)[0] if '-' in category else category
|
||||
sub = category.split('-', 1)[1] if '-' in category else ""
|
||||
major = category or ""
|
||||
sub = fabric_type or ""
|
||||
|
||||
self.add_major_category.setCurrentText(major)
|
||||
self.add_sub_category.setText(sub)
|
||||
@@ -493,10 +485,8 @@ class RawMaterialLibraryDialog(QDialog):
|
||||
if "胸杯" in sub:
|
||||
major = "辅料"
|
||||
|
||||
if major and sub:
|
||||
category = major + "-" + sub
|
||||
else:
|
||||
category = sub or major
|
||||
category = major or ""
|
||||
fabric_type = sub or ""
|
||||
|
||||
supplier = self.add_supplier.currentText().strip()
|
||||
color = self.add_color.text().strip()
|
||||
@@ -506,9 +496,9 @@ class RawMaterialLibraryDialog(QDialog):
|
||||
with self.get_conn() as conn:
|
||||
conn.execute('''
|
||||
INSERT OR REPLACE INTO fabrics
|
||||
(model, category, supplier, color, width, gsm, retail_price, bulk_price, unit, timestamp)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
''', (model, category, supplier, color,
|
||||
(model, category, fabric_type, supplier, color, width, gsm, retail_price, bulk_price, unit, timestamp)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
''', (model, category, fabric_type, supplier, color,
|
||||
self.add_width.value() or None, self.add_gsm.value() or None,
|
||||
self.add_retail.value() or None, self.add_bulk.value() or None,
|
||||
unit, datetime.now().strftime('%Y-%m-%d %H:%M:%S')))
|
||||
|
||||
Reference in New Issue
Block a user