If r IsNot Nothing Then
Forms("SL_销售退货选择").Show()
If PublicJson IsNot Nothing Then
Try
' 提前获取表格引用减少重复访问
Dim tableName As String = eForm.Name & "_Table1"
Dim targetTable As Table = Tables(tableName)
Dim jsonArray As JArray = CType(PublicJson, JArray)
If jsonArray.Count = 0 Then Exit Try
' 预定义字段映射关系(可根据实际情况扩展)
Dim fieldMappings As New Dictionary(Of String, String) From {
{"产品编号", "产品编号"},
{"产品名称", "产品名称"},
{'...其他字段...', "..."} ' 实际使用时需补全
}
' 批量操作前准备
targetTable.BeginUpdate()
For Each item As JToken In jsonArray
Dim salesOrderGuid As String = CStr(item("Guid_销售订单"))
' 检查重复行
If targetTable.FindRow($"Guid_销售订单='{salesOrderGuid}'") <> -1 Then Continue For
' 添加新行
Dim newRow As Row = targetTable.AddNew()
' 关键字段赋值
newRow("编号") = r("编号")
newRow("销售退货单明细ID") = Guid.NewGuid().ToString()
' 使用循环处理相同逻辑的字段赋值
For Each mapping In fieldMappings
newRow(mapping.Key) = CStr(item(mapping.Value))
Next
' 特殊处理字段
newRow("数量") = CStr(item("实际出库数量"))
'...其他特殊字段处理...
Next
' 提交修改
targetTable.EndUpdate()
targetTable.Save()
targetTable.AutoSizeCols()
Catch ex As Exception
' 添加异常处理
MessageBox.Show($"数据加载失败:{ex.Message}")
' 记录日志
' LogError(ex)
End Try
End If
End If