老师,我这里有一个例子,想实现的是:当欠交数量为0的时候,将A表的有关数据写到B表(合同明细)。我在A表的DataColChanged加了这段代码,好像不对。同时我还想将与A表关联的C表(计划编号关联)也作为B表的相应列。怎么写啊?
Select Case e.DataCol.Name
Case "计划编号","生产数量","实际交货数量"
Dim dr As DataRow
Dim mr As DataRow = e.DataRow
Dim drs As List(of DataRow)
dr = e.DataTable.Find("[_SortKey] < " & mr("_SortKey") & " And [计划编号] = '" & mr("计划编号") & "'", "[_SortKey] Desc")
If dr Is Nothing Then
mr("欠交数量") = mr("生产数量") - mr("实际交货数量")
dr = mr
End If
drs = e.DataTable.Select("[_SortKey] >= " & dr("_SortKey") & " And [计划编号] = '" & dr("计划编号") & "'", "[_SortKey]")
For i As Integer = 1 To drs.Count - 1
drs(i)("欠交数量") = drs(i-1)("欠交数量") + drs(i)("生产数量") - drs(i)("实际交货数量")
Next
If e.DataCol.Name = "计划编号" AndAlso e.OldValue IsNot Nothing AndAlso e.OldValue <> e.NewValue Then
dr = e.DataTable.Find("[_SortKey] < " & mr("_SortKey") & " And [计划编号] = '" & e.OldValue & "'", "[_SortKey] Desc")
If dr Is Nothing Then
dr = e.DataTable.Find("[计划编号] = '" & e.OldValue & "'", "[_SortKey]")
If dr IsNot Nothing Then
dr("欠交数量") = dr("生产数量") - dr("实际交货数量")
End If
End If
If dr IsNot Nothing Then
drs = e.DataTable.Select("[_SortKey] >= " & dr("_SortKey") & " And [计划编号] = '" & dr("计划编号") & "'", "[_SortKey]")
For i As Integer = 1 To drs.Count - 1
drs(i)("欠交数量") = drs(i-1)("欠交数量") + drs(i)("生产数量") - drs(i)("实际交货数量")
Next
End If
End If
Case "欠交数量"
If e.DataRow ("欠交数量") = 0 Then
Dim nma() As String = {"计划编号","车号","入库单号","实际交货数量"} 'A表数据来源列
Dim nmb() As String = {"计划编号","车号","入库单号","数量"} 'B表数据接收列
Dim dr As DataRow = DataTables("合同明细").AddNew
For i As Integer = 0 To nma.Length - 1
dr(nmb(i)) = e.DataRow(nma(i))
Next
End If
End Select