Changes:
1. Update all modules to use LoadData(wsPlatform) instead of LoadData(wsConfig, wsPlatform)
- modModelParserExamples.bas: Update 7 example procedures
- modBOMProcessor.bas: Update 4 procedures
- modModelParserTest.bas: Update 2 test procedures
2. Fix completeness check logic in GetValidMaterialsByModel
- Only check root categories to avoid duplicate checking of subcategories
- Previously, all required categories (including subcategories) were checked,
causing subcategories to be added to missing list multiple times
- Now only checks categories with ParentCategoryName = ""
- CheckCategoryCompleteness already recursively checks all subcategories
3. Improve completeness judgment logic for categories with subcategories
- Method 1: Parent category has 1 matching material → Complete
- Method 2: Parent category has 0 matching materials, but all subcategories are complete → Complete
- Other cases → Incomplete
Impact:
- Fixes "category missing" errors in Example9_BatchProcessOrders_WithCheck
- Eliminates duplicate entries in missing categories list
- Properly handles category hierarchy where parent categories are satisfied through subcategories
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
178 lines
5.2 KiB
QBasic
178 lines
5.2 KiB
QBasic
' ========================================
|
|
' 模块: modBOMProcessor
|
|
' 用途: BOM处理和操作示例
|
|
' ⭐ v2.0 更新:所有过程使用新的 LoadData(wsPlatform) 接口
|
|
' ========================================
|
|
Option Explicit
|
|
|
|
Sub TestBOMStructure()
|
|
' 初始化BOM管理器
|
|
Dim bomMgr As New clsBOMManager
|
|
|
|
' 加载数据
|
|
Dim wsPlatform As Worksheet
|
|
Set wsPlatform = ThisWorkbook.Worksheets("平台配置清单")
|
|
|
|
' ⭐ 使用新接口
|
|
bomMgr.LoadData wsPlatform
|
|
|
|
' 打印类别树结构到新工作表
|
|
Dim wsOutput As Worksheet
|
|
On Error Resume Next
|
|
Application.DisplayAlerts = False
|
|
ThisWorkbook.Worksheets("BOM结构").Delete
|
|
Application.DisplayAlerts = True
|
|
On Error GoTo 0
|
|
|
|
Set wsOutput = ThisWorkbook.Worksheets.Add
|
|
wsOutput.Name = "BOM结构"
|
|
|
|
'bomMgr.PrintCategoryTree wsOutput
|
|
|
|
Dim cats As collection
|
|
Dim i As Integer
|
|
Set cats = bomMgr.GetRootCategories()
|
|
For i = 1 To cats.Count
|
|
Debug.Print cats(i).categoryName
|
|
Next i
|
|
|
|
|
|
|
|
MsgBox "BOM数据结构加载完成!" & vbCrLf & _
|
|
"请查看 'BOM结构' 工作表", vbInformation
|
|
End Sub
|
|
|
|
' 示例: 获取特定类别的物料
|
|
Sub GetCategoryMaterials()
|
|
Dim bomMgr As New clsBOMManager
|
|
Dim wsPlatform As Worksheet
|
|
|
|
Set wsPlatform = ThisWorkbook.Worksheets("平台配置清单")
|
|
|
|
' ⭐ 使用新接口
|
|
bomMgr.LoadData wsPlatform
|
|
|
|
' 获取"部件"类别的物料(使用父类别)
|
|
Dim materials As collection
|
|
Set materials = bomMgr.GetMaterialsForPicking("部件", True)
|
|
|
|
Debug.Print "部件类别物料数量(父类别): " & materials.Count
|
|
|
|
' 获取"部件"类别的物料(使用子类别)
|
|
Set materials = bomMgr.GetMaterialsForPicking("部件", False)
|
|
|
|
Debug.Print "部件类别物料数量(子类别展开): " & materials.Count
|
|
|
|
' 遍历物料
|
|
Dim mat As clsMaterialItem
|
|
For Each mat In materials
|
|
Debug.Print mat.code & " - " & mat.Name & _
|
|
" | 数量:" & mat.Quantity & _
|
|
" | 条件:" & mat.Condition
|
|
Next mat
|
|
End Sub
|
|
|
|
' 示例: 根据产品型号生成领料清单
|
|
Sub GeneratePickingList()
|
|
Dim bomMgr As New clsBOMManager
|
|
Dim wsPlatform As Worksheet
|
|
|
|
Set wsPlatform = ThisWorkbook.Worksheets("平台配置清单")
|
|
|
|
' ⭐ 使用新接口
|
|
bomMgr.LoadData wsPlatform
|
|
|
|
' 创建领料清单工作表
|
|
Dim wsPickList As Worksheet
|
|
On Error Resume Next
|
|
Application.DisplayAlerts = False
|
|
ThisWorkbook.Worksheets("领料清单").Delete
|
|
Application.DisplayAlerts = True
|
|
On Error GoTo 0
|
|
|
|
Set wsPickList = ThisWorkbook.Worksheets.Add
|
|
wsPickList.Name = "领料清单"
|
|
|
|
' 写入表头
|
|
Dim row As Long
|
|
row = 1
|
|
wsPickList.Cells(row, 1).value = "代号"
|
|
wsPickList.Cells(row, 2).value = "名称"
|
|
wsPickList.Cells(row, 3).value = "类别"
|
|
wsPickList.Cells(row, 4).value = "数量"
|
|
wsPickList.Cells(row, 5).value = "选择条件"
|
|
wsPickList.Cells(row, 6).value = "领料方式"
|
|
row = row + 1
|
|
|
|
' 遍历所有根类别
|
|
Dim rootCats As collection
|
|
Set rootCats = bomMgr.GetRootCategories
|
|
|
|
Dim cat As clsCategory
|
|
Dim materials As collection
|
|
Dim mat As clsMaterialItem
|
|
Dim i As Long, j As Long
|
|
|
|
For i = 1 To rootCats.Count
|
|
Set cat = rootCats(i)
|
|
' 默认使用父类别物料
|
|
Set materials = bomMgr.GetMaterialsForPicking(cat.categoryName, True)
|
|
|
|
For j = 1 To materials.Count
|
|
Set mat = materials(j)
|
|
wsPickList.Cells(row, 1).value = mat.code
|
|
wsPickList.Cells(row, 2).value = mat.Name
|
|
wsPickList.Cells(row, 3).value = mat.Category
|
|
wsPickList.Cells(row, 4).value = mat.Quantity
|
|
wsPickList.Cells(row, 5).value = mat.Condition
|
|
wsPickList.Cells(row, 6).value = "父类别"
|
|
row = row + 1
|
|
Next j
|
|
Next i
|
|
|
|
' 格式化表格
|
|
wsPickList.Range("A1:F1").Font.Bold = True
|
|
wsPickList.Columns("A:F").AutoFit
|
|
|
|
MsgBox "领料清单生成完成!", vbInformation
|
|
End Sub
|
|
|
|
' 示例: 查询特定物料信息
|
|
Sub QueryMaterialInfo()
|
|
Dim bomMgr As New clsBOMManager
|
|
Dim wsPlatform As Worksheet
|
|
|
|
Set wsPlatform = ThisWorkbook.Worksheets("平台配置清单")
|
|
|
|
' ⭐ 使用新接口
|
|
bomMgr.LoadData wsPlatform
|
|
|
|
' 查询特定类别
|
|
Dim cat As clsCategory
|
|
Set cat = bomMgr.GetCategory("部件")
|
|
|
|
If Not cat Is Nothing Then
|
|
Debug.Print "类别: " & cat.categoryName
|
|
Debug.Print "父类别: " & cat.ParentCategoryName
|
|
Debug.Print "物料数: " & cat.materials.Count
|
|
Debug.Print "子类别数: " & cat.SubCategories.Count
|
|
Debug.Print "是否叶子类别: " & cat.IsLeafCategory
|
|
|
|
' 列出所有物料
|
|
Dim mat As clsMaterialItem
|
|
Dim i As Long
|
|
For i = 1 To cat.materials.Count
|
|
Set mat = cat.materials(i)
|
|
Debug.Print " - " & mat.code & ": " & mat.Name
|
|
Next i
|
|
|
|
' 列出所有子类别
|
|
Dim subCat As clsCategory
|
|
Dim j As Long
|
|
For j = 1 To cat.SubCategories.Count
|
|
Set subCat = cat.SubCategories(j)
|
|
Debug.Print " 子类别: " & subCat.categoryName & _
|
|
" (物料数:" & subCat.materials.Count & ")"
|
|
Next j
|
|
End If
|
|
End Sub |