' ========================================
' 类模块: clsCategory
' 用途: 表示物料类别及其层级关系
' ========================================
Option Explicit

Public categoryName As String
Public ParentCategoryName As String
Public Materials As Collection      ' 存储 clsMaterialItem 对象
Public SubCategories As Collection  ' 存储子类别 clsCategory 对象
Public IsLeafCategory As Boolean    ' 是否叶子类别(无子类别)

Private Sub Class_Initialize()
    Set Materials = New Collection
    Set SubCategories = New Collection
    IsLeafCategory = True
End Sub

' 添加物料
Public Sub AddMaterial(mat As clsMaterialItem)
    Materials.Add mat, mat.code
End Sub

' 添加子类别
Public Sub AddSubCategory(cat As clsCategory)
    SubCategories.Add cat, cat.categoryName
    IsLeafCategory = False
End Sub

' 获取物料(按代号)
Public Function GetMaterial(code As String) As clsMaterialItem
    On Error Resume Next
    Set GetMaterial = Materials(code)
    On Error GoTo 0
End Function

' 检查是否有子类别
Public Function HasSubCategories() As Boolean
    HasSubCategories = (SubCategories.Count > 0)
End Function