docs: expand AutoBOM architecture and implementation details

Refine project overview to include specific business context (Blaidy Company) and the main workbook file. Restructure the architecture section into a layered object-oriented design (Data, Processing, Application layers) and define the responsibilities of core VBA classes.

Add new technical documentation sections covering:
- Model number format parsing structure
- Condition expression language syntax
- Category hierarchy logic and picking strategies
- Material matching pipeline flow

Include VBA code examples for key methods such as CollectAllMaterials and GetMaterialsByCategoryAndModel to illustrate recursive traversal and material retrieval logic. Clarify the structure of key Excel configuration sheets.
This commit is contained in:
Misaka_Company
2026-01-20 13:42:03 +08:00
parent bc5ea92c52
commit a1347017e3
13 changed files with 2682 additions and 828 deletions

View File

@@ -1,6 +1,6 @@
' ========================================
' 模块: modBOMTest
' 用途: 测试和使用BOM数据结构-同步测试2
' 用途: 测试和使用BOM数据结构
' ========================================
Option Explicit
@@ -19,19 +19,19 @@ Sub TestBOMStructure()
bomMgr.LoadData wsConfig, 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结构"
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 cats As collection
Dim i As Integer
Set cats = bomMgr.GetRootCategories()
For i = 1 To cats.Count
@@ -40,7 +40,7 @@ Sub TestBOMStructure()
'MsgBox "BOM数据结构加载完成!" & vbCrLf & _
MsgBox "BOM数据结构加载完成!" & vbCrLf & _
"请查看 'BOM结构' 工作表", vbInformation
End Sub
@@ -55,19 +55,19 @@ Sub GetCategoryMaterials()
bomMgr.LoadData wsConfig, wsPlatform
' 获取"部件"类别的物料(使用父类别)
Dim Materials As Collection
Set Materials = bomMgr.GetMaterialsForPicking("部件", True)
Dim materials As collection
Set materials = bomMgr.GetMaterialsForPicking("部件", True)
Debug.Print "部件类别物料数量(父类别): " & Materials.Count
Debug.Print "部件类别物料数量(父类别): " & materials.Count
' 获取"部件"类别的物料(使用子类别)
Set Materials = bomMgr.GetMaterialsForPicking("部件", False)
Set materials = bomMgr.GetMaterialsForPicking("部件", False)
Debug.Print "部件类别物料数量(子类别展开): " & Materials.Count
Debug.Print "部件类别物料数量(子类别展开): " & materials.Count
' 遍历物料
Dim mat As clsMaterialItem
For Each mat In Materials
For Each mat In materials
Debug.Print mat.code & " - " & mat.Name & _
" | 数量:" & mat.Quantity & _
" | 条件:" & mat.Condition
@@ -98,36 +98,36 @@ Sub GeneratePickingList()
' 写入表头
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 = "领料方式"
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
Dim rootCats As collection
Set rootCats = bomMgr.GetRootCategories
Dim cat As clsCategory
Dim Materials As Collection
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)
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 = "父类别"
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
@@ -139,64 +139,6 @@ Sub GeneratePickingList()
MsgBox "领料清单生成完成!", vbInformation
End Sub
' 示例: 在立即窗口打印领料清单
Sub PrintPickingList()
Dim bomMgr As New clsBOMManager
Dim wsConfig As Worksheet, wsPlatform As Worksheet
Set wsConfig = ThisWorkbook.Worksheets("领料配置")
Set wsPlatform = ThisWorkbook.Worksheets("平台配置清单")
bomMgr.LoadData wsConfig, wsPlatform
' 打印表头
Debug.Print String(80, "=")
Debug.Print "领料清单"
Debug.Print String(80, "=")
' 遍历所有根类别
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
Dim totalCount As Long
totalCount = 0
For i = 1 To rootCats.Count
Set cat = rootCats(i)
' 打印类别分隔符
Debug.Print ""
Debug.Print "【类别: " & cat.categoryName & "】"
Debug.Print String(40, "-")
' 默认使用父类别物料
Set Materials = bomMgr.GetMaterialsForPicking(cat.categoryName, True)
For j = 1 To Materials.Count
Set mat = Materials(j)
Debug.Print " " & mat.code & _
String(20 - Len(mat.code), " ") & _
mat.Name & _
" | 数量:" & mat.Quantity & _
" | 条件:" & IIf(mat.Condition = "", "(无)", mat.Condition)
totalCount = totalCount + 1
Next j
Debug.Print " 小计: " & Materials.Count & " 项"
Next i
' 打印汇总
Debug.Print ""
Debug.Print String(80, "=")
Debug.Print "总计: " & totalCount & " 项物料"
Debug.Print String(80, "=")
End Sub
' 示例: 查询特定物料信息
Sub QueryMaterialInfo()
Dim bomMgr As New clsBOMManager
@@ -214,15 +156,15 @@ Sub QueryMaterialInfo()
If Not cat Is Nothing Then
Debug.Print "类别: " & cat.categoryName
Debug.Print "父类别: " & cat.ParentCategoryName
Debug.Print "物料数: " & cat.Materials.Count
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)
For i = 1 To cat.materials.Count
Set mat = cat.materials(i)
Debug.Print " - " & mat.code & ": " & mat.Name
Next i
@@ -232,7 +174,7 @@ Sub QueryMaterialInfo()
For j = 1 To cat.SubCategories.Count
Set subCat = cat.SubCategories(j)
Debug.Print " 子类别: " & subCat.categoryName & _
" (物料数:" & subCat.Materials.Count & ")"
" (物料数:" & subCat.materials.Count & ")"
Next j
End If
End Sub