Refactor data source to use dedicated parameter configuration worksheet
- Add mParamWorksheet variable for parameter configuration worksheet - Load material names from dedicated [参数配置] worksheet instead of extracting from BOM data - Implement validation for parameter configuration worksheet existence - Add header row logic (row 2) with data starting from row 3 - Improve code comments for better clarity - Remove debug output for cleaner production code - Implement proper error handling for parameter worksheet access This architectural improvement separates configuration data from operational data, following the single responsibility principle. The [参数配置] worksheet serves as a centralized configuration source for target material names, making the system more maintainable and allowing business users to manage target materials without touching the main BOM data. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -8,7 +8,8 @@ Option Explicit
|
||||
' --- 模块级变量 ---
|
||||
Private mGlobalBOMs As Collection ' 内存中的 BOM 总库
|
||||
Private mDynamicCheckboxes As Collection ' 保存动态生成的复选框和事件对象
|
||||
Private mTargetWorksheet As Worksheet ' 目标工作表
|
||||
Private mTargetWorksheet As Worksheet ' 目标工作表 (平台配置清单)
|
||||
Private mParamWorksheet As Worksheet ' 参数配置工作表 (新增)
|
||||
|
||||
' ==============================================================================
|
||||
' 1. 窗体初始化 (加载数据、动态生成控件)
|
||||
@@ -17,6 +18,7 @@ Private Sub UserForm_Initialize()
|
||||
' 尝试绑定数据源工作表
|
||||
On Error Resume Next
|
||||
Set mTargetWorksheet = ThisWorkbook.Worksheets("平台配置清单")
|
||||
Set mParamWorksheet = ThisWorkbook.Worksheets("参数配置") ' 绑定参数表
|
||||
On Error GoTo 0
|
||||
|
||||
If mTargetWorksheet Is Nothing Then
|
||||
@@ -24,6 +26,11 @@ Private Sub UserForm_Initialize()
|
||||
Exit Sub
|
||||
End If
|
||||
|
||||
If mParamWorksheet Is Nothing Then
|
||||
MsgBox "未找到名为 [参数配置] 的工作表,无法加载物料名称列表!", vbCritical
|
||||
Exit Sub
|
||||
End If
|
||||
|
||||
' 初始化策略下拉框
|
||||
With Me.cboStrategy
|
||||
.Clear
|
||||
@@ -56,21 +63,31 @@ End Sub
|
||||
' 2. 核心加载逻辑与动态渲染
|
||||
' ==============================================================================
|
||||
Private Sub LoadDataAndRender()
|
||||
' 通过主控大脑加载所有数据
|
||||
' 通过主控大脑加载所有数据 (用于明细刷新和执行手术)
|
||||
Set mGlobalBOMs = mSpecAdditionManager.LoadData(mTargetWorksheet)
|
||||
|
||||
' 提取不重复的 ItemName
|
||||
' 从 [参数配置] 工作表获取目标物料名称 (新逻辑)
|
||||
Dim dictNames As Object
|
||||
Set dictNames = CreateObject("Scripting.Dictionary")
|
||||
|
||||
Dim rowObj As cBOMRow
|
||||
For Each rowObj In mGlobalBOMs
|
||||
If rowObj.ItemName <> "" Then
|
||||
If Not dictNames.Exists(rowObj.ItemName) Then
|
||||
dictNames.Add rowObj.ItemName, 1
|
||||
End If
|
||||
Dim lastRow As Long
|
||||
Dim i As Long
|
||||
Dim itemNameStr As String
|
||||
|
||||
' 表头在第2行,数据在A列,实际数据从第3行开始
|
||||
If Not mParamWorksheet Is Nothing Then
|
||||
lastRow = mParamWorksheet.Cells(mParamWorksheet.Rows.count, "A").End(xlUp).row
|
||||
If lastRow >= 3 Then
|
||||
For i = 3 To lastRow
|
||||
itemNameStr = Trim(mParamWorksheet.Cells(i, 1).value)
|
||||
If itemNameStr <> "" Then
|
||||
If Not dictNames.Exists(itemNameStr) Then
|
||||
dictNames.Add itemNameStr, 1 ' 顺便利用字典去重
|
||||
End If
|
||||
End If
|
||||
Next i
|
||||
End If
|
||||
Next rowObj
|
||||
End If
|
||||
|
||||
' 清空已有的动态控件
|
||||
Dim ctrl As Control
|
||||
@@ -185,7 +202,8 @@ End Sub
|
||||
' 新增:处理列表框点击事件,将超长的选择条件发送到预览框自动换行显示
|
||||
' ==============================================================================
|
||||
Private Sub lstDetails_Change()
|
||||
' ListIndex 在多选模式下代表当前具有虚线焦点框的行
|
||||
' 在 MultiSelect 模式下,Click 事件不生效,必须使用 Change 事件
|
||||
' ListIndex 代表当前具有虚线焦点框的行(即刚刚被点击的行)
|
||||
If Me.lstDetails.ListIndex >= 0 Then
|
||||
On Error Resume Next
|
||||
' 获取隐藏列中的物理行号
|
||||
@@ -197,7 +215,6 @@ Private Sub lstDetails_Change()
|
||||
For Each rowObj In mGlobalBOMs
|
||||
If rowObj.ExcelRowIndex = targetId Then
|
||||
Me.txtConditionPreview.Text = rowObj.Condition
|
||||
Debug.Print rowObj.Condition
|
||||
Exit For
|
||||
End If
|
||||
Next rowObj
|
||||
|
||||
Reference in New Issue
Block a user