feat: add Access data integration and total queue number column
- Add new AccessDataModule for fetching data from Access database based on total queue number - Add CommandButton3_Click handler in Sheet9 for Access data fetch - Add support for new "总排号" (Total Queue Number) column at column A - Adjust all column indices to accommodate the new column (shifted by +1) - Standardize code style: Collection, Count, Quantity, ProductModel, Description - Fix inventory check result to write to correct column (F instead of E) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -66,21 +66,21 @@ Public Sub CheckComponentInventory()
|
||||
Exit Sub
|
||||
End If
|
||||
|
||||
' 检查订单数据
|
||||
' 检查订单数据 (调整为按C列:产品型号获取最后一行)
|
||||
Dim lastRow As Long
|
||||
lastRow = orderSheet.Cells(orderSheet.Rows.Count, 2).End(xlUp).Row
|
||||
lastRow = orderSheet.Cells(orderSheet.Rows.count, 3).End(xlUp).row
|
||||
If lastRow < 2 Then
|
||||
MsgBox "[产品订单]工作表没有数据!", vbExclamation
|
||||
Exit Sub
|
||||
End If
|
||||
|
||||
' 初始化BOM提取器
|
||||
Dim bomExtractor As BomExtractor
|
||||
Set bomExtractor = New BomExtractor
|
||||
bomExtractor.SetWorksheet bomSheet
|
||||
Dim BomExtractor As BomExtractor
|
||||
Set BomExtractor = New BomExtractor
|
||||
BomExtractor.SetWorksheet bomSheet
|
||||
|
||||
If Not bomExtractor.LoadBomData Then
|
||||
MsgBox "加载BOM数据失败:" & bomExtractor.GetErrorSummary, vbCritical
|
||||
If Not BomExtractor.LoadBomData Then
|
||||
MsgBox "加载BOM数据失败:" & BomExtractor.GetErrorSummary, vbCritical
|
||||
Exit Sub
|
||||
End If
|
||||
|
||||
@@ -88,7 +88,7 @@ Public Sub CheckComponentInventory()
|
||||
Dim inventoryData As Object
|
||||
Set inventoryData = LoadInventoryData(inventorySheet)
|
||||
|
||||
If inventoryData.Count = 0 Then
|
||||
If inventoryData.count = 0 Then
|
||||
MsgBox "[现存量]工作表没有有效数据!", vbExclamation
|
||||
Exit Sub
|
||||
End If
|
||||
@@ -97,19 +97,19 @@ Public Sub CheckComponentInventory()
|
||||
Dim orders As Collection
|
||||
Set orders = LoadOrderData(orderSheet)
|
||||
|
||||
If orders.Count = 0 Then
|
||||
If orders.count = 0 Then
|
||||
MsgBox "没有有效的订单数据!", vbExclamation
|
||||
Exit Sub
|
||||
End If
|
||||
|
||||
' 解析所有订单的BOM
|
||||
ParseAllOrdersBOM orders, bomExtractor
|
||||
ParseAllOrdersBOM orders, BomExtractor
|
||||
|
||||
' 统计部件总需求
|
||||
Dim componentDemands As Object
|
||||
Set componentDemands = CalculateComponentDemand(orders)
|
||||
|
||||
If componentDemands.Count = 0 Then
|
||||
If componentDemands.count = 0 Then
|
||||
MsgBox "没有订单包含'部件'类别物料,无需处理库存!", vbInformation
|
||||
Exit Sub
|
||||
End If
|
||||
@@ -138,7 +138,7 @@ Public Sub CheckComponentInventory()
|
||||
resultMsg = resultMsg & vbCrLf & "耗时: " & Format(elapsedTime, "0.00") & "秒"
|
||||
|
||||
' 显示警告信息(如果有)
|
||||
If validationWarnings.Count > 0 Then
|
||||
If validationWarnings.count > 0 Then
|
||||
resultMsg = resultMsg & vbCrLf & vbCrLf & "警告信息:" & vbCrLf
|
||||
resultMsg = resultMsg & JoinCollection(validationWarnings, vbCrLf)
|
||||
End If
|
||||
@@ -160,16 +160,18 @@ End Sub
|
||||
Private Function LoadOrderData(ws As Worksheet) As Collection
|
||||
Set LoadOrderData = New Collection
|
||||
|
||||
' 调整为按C列获取最后一行
|
||||
Dim lastRow As Long
|
||||
lastRow = ws.Cells(ws.Rows.Count, 2).End(xlUp).Row
|
||||
lastRow = ws.Cells(ws.Rows.count, 3).End(xlUp).row
|
||||
|
||||
Dim i As Long
|
||||
For i = 2 To lastRow
|
||||
Dim model As String
|
||||
Dim qty As Variant
|
||||
|
||||
model = Trim(ws.Cells(i, 2).Value) ' B列: 产品型号
|
||||
qty = ws.Cells(i, 3).Value ' C列: 产品数量
|
||||
' --- 核心修改:列索引向右移1列 ---
|
||||
model = Trim(ws.Cells(i, 3).value) ' C列: 产品型号 (原B列)
|
||||
qty = ws.Cells(i, 4).value ' D列: 产品数量 (原C列)
|
||||
|
||||
' 跳过空行
|
||||
If model <> "" Then
|
||||
@@ -178,7 +180,7 @@ Private Function LoadOrderData(ws As Worksheet) As Collection
|
||||
|
||||
order.Add ORDER_ROW, CLng(i)
|
||||
order.Add ORDER_MODEL, CStr(model)
|
||||
order.Add ORDER_QUANTITY, CDbl(IIf(IsNull(qty), 0, qty))
|
||||
order.Add ORDER_QUANTITY, CDbl(IIf(IsNull(qty) Or IsEmpty(qty), 0, qty))
|
||||
order.Add ORDER_COMP_CODE, ""
|
||||
order.Add ORDER_COMP_QTY, 0
|
||||
order.Add ORDER_HAS_COMP, False
|
||||
@@ -200,15 +202,15 @@ Private Function LoadInventoryData(ws As Worksheet) As Object
|
||||
|
||||
' 从第4行开始读取(第3行是表头)
|
||||
Dim lastRow As Long
|
||||
lastRow = ws.Cells(ws.Rows.Count, 2).End(xlUp).Row
|
||||
lastRow = ws.Cells(ws.Rows.count, 2).End(xlUp).row
|
||||
|
||||
Dim i As Long
|
||||
For i = 4 To lastRow
|
||||
Dim code As String
|
||||
Dim qty As Variant
|
||||
|
||||
code = Trim(ws.Cells(i, 2).Value) ' B列: 物料编码
|
||||
qty = ws.Cells(i, 10).Value ' J列: 结存主数量
|
||||
code = Trim(ws.Cells(i, 2).value) ' B列: 物料编码
|
||||
qty = ws.Cells(i, 10).value ' J列: 结存主数量
|
||||
|
||||
If code <> "" And Not IsEmpty(qty) Then
|
||||
If Not LoadInventoryData.Exists(code) Then
|
||||
@@ -224,12 +226,12 @@ End Function
|
||||
' 参数: orders - 订单集合(每个元素是字典)
|
||||
' bomExtractor - BOM提取器
|
||||
'=====================================================================
|
||||
Private Sub ParseAllOrdersBOM(orders As Collection, bomExtractor As BomExtractor)
|
||||
Private Sub ParseAllOrdersBOM(orders As Collection, BomExtractor As BomExtractor)
|
||||
Dim i As Long
|
||||
For i = 1 To orders.Count
|
||||
For i = 1 To orders.count
|
||||
Dim order As Object
|
||||
Set order = orders(i)
|
||||
ParseOrderBOM order, bomExtractor
|
||||
ParseOrderBOM order, BomExtractor
|
||||
Next i
|
||||
End Sub
|
||||
|
||||
@@ -239,7 +241,7 @@ End Sub
|
||||
' 参数: orderInfo - 订单信息字典(ByRef)
|
||||
' bomExtractor - BOM提取器
|
||||
'=====================================================================
|
||||
Private Sub ParseOrderBOM(ByRef orderInfo As Object, bomExtractor As BomExtractor)
|
||||
Private Sub ParseOrderBOM(ByRef orderInfo As Object, BomExtractor As BomExtractor)
|
||||
On Error Resume Next
|
||||
|
||||
' 解析型号
|
||||
@@ -253,14 +255,14 @@ Private Sub ParseOrderBOM(ByRef orderInfo As Object, bomExtractor As BomExtracto
|
||||
|
||||
' 提取BOM
|
||||
Dim matchedItems As Collection
|
||||
Set matchedItems = bomExtractor.ExtractBom(parser.Conditions)
|
||||
Set matchedItems = BomExtractor.ExtractBom(parser.Conditions)
|
||||
|
||||
' 查找"部件"类别物料
|
||||
Dim item As BomItem
|
||||
For Each item In matchedItems
|
||||
If item.category = "部件" Then
|
||||
orderInfo(ORDER_COMP_CODE) = item.Code66
|
||||
orderInfo(ORDER_COMP_QTY) = item.quantity
|
||||
orderInfo(ORDER_COMP_QTY) = item.Quantity
|
||||
orderInfo(ORDER_HAS_COMP) = True
|
||||
Exit For
|
||||
End If
|
||||
@@ -278,7 +280,7 @@ Private Function CalculateComponentDemand(orders As Collection) As Object
|
||||
Set demands = CreateObject("Scripting.Dictionary")
|
||||
|
||||
Dim i As Long
|
||||
For i = 1 To orders.Count
|
||||
For i = 1 To orders.count
|
||||
Dim order As Object
|
||||
Set order = orders(i)
|
||||
|
||||
@@ -355,14 +357,14 @@ Private Sub AllocateInventory(orders As Collection, _
|
||||
ByRef stats As Statistics)
|
||||
|
||||
' 初始化统计
|
||||
stats.TotalOrders = orders.Count
|
||||
stats.TotalOrders = orders.count
|
||||
stats.OrdersWithComponent = 0
|
||||
stats.OrdersSufficient = 0
|
||||
stats.OrdersInsufficient = 0
|
||||
stats.OrdersSkipped = 0
|
||||
|
||||
Dim i As Long
|
||||
For i = 1 To orders.Count
|
||||
For i = 1 To orders.count
|
||||
Dim order As Object
|
||||
Set order = orders(i)
|
||||
|
||||
@@ -400,8 +402,9 @@ Private Sub AllocateInventory(orders As Collection, _
|
||||
compInv(INV_STOCK) = compInv(INV_STOCK) - requiredQty
|
||||
stats.OrdersSufficient = stats.OrdersSufficient + 1
|
||||
Else
|
||||
' --- 核心修改:回填结果写入F列(第6列) ---
|
||||
' 库存不足,标记为"否"
|
||||
orderSheet.Cells(order(ORDER_ROW), 5).Value = "否"
|
||||
orderSheet.Cells(order(ORDER_ROW), 6).value = "否"
|
||||
compInv(INV_STOCK) = compInv(INV_STOCK) - requiredQty
|
||||
stats.OrdersInsufficient = stats.OrdersInsufficient + 1
|
||||
End If
|
||||
@@ -467,4 +470,4 @@ Private Function JoinCollection(coll As Collection, separator As String) As Stri
|
||||
Next item
|
||||
|
||||
JoinCollection = result
|
||||
End Function
|
||||
End Function
|
||||
Reference in New Issue
Block a user