此主题相关图片如下:微信图片_20230320142443.png
老师您好,当数据发生改变时,只有这段代码
Select Case e.DataCol.Name
Case "编号","入库数量","出库数量","入库件数","出库件数"
Dim dr As DataRow
Dim mr As DataRow = e.DataRow
Dim drs As List(of DataRow)
Dim jk As Double
Dim ck As Double
Dim jk1 As Double
Dim ck1 As Double
dr = e.DataTable.Find("[_Identify] < " & mr("_Identify") & " And [编号] = '" & mr("编号") & "'", "[_Identify] Desc")
If dr Is Nothing Then
jk = DataTables("库存表").SQLCompute("Sum(入库数量)","[_Identify] < " & mr("_Identify") & " And 编号 = '" & mr("编号") & "'")
jk1 = DataTables("库存表").SQLCompute("Sum(入库件数)","[_Identify] < " & mr("_Identify") & " And 编号 = '" & mr("编号") & "'")
ck = DataTables("库存表").SQLCompute("Sum(出库数量)","[_Identify] < " & mr("_Identify") & " And 编号 = '" & mr("编号") & "'")
ck1 = DataTables("库存表").SQLCompute("Sum(出库件数)","[_Identify] < " & mr("_Identify") & " And 编号 = '" & mr("编号") & "'")
mr("库存数量") = e.DataRow("入库数量") - e.DataRow("出库数量") + jk - ck
mr("库存件数") = e.DataRow("入库件数") - e.DataRow("出库件数") + jk1 - ck1
dr = mr
End If
drs = e.DataTable.Select("[_Identify] >= " & dr("_Identify") & " And [编号] = '" & dr("编号") & "'", "[_Identify]")
For i As Integer = 1 To drs.Count - 1
drs(i)("库存数量") = drs(i-1)("库存数量") + drs(i)("入库数量") - drs(i)("出库数量")
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("[_Identify] < " & mr("_Identify") & " And [编号] = '" & e.OldValue & "'", "[_Identify] Desc") '找出旧产品的上一行
If dr Is Nothing Then '如果不存在上一行,那么本行就是旧产品的第一行,由于已经被修改为新产品,需要找出旧产品现在的第一行
dr = e.DataTable.Find("[编号] = '" & e.OldValue & "'", "[_Identify]") '找出旧产品现在的第一行
If dr IsNot Nothing Then '如果找到,计算库存
jk = DataTables("库存表").SQLCompute("Sum(入库数量)","[_Identify] < " & mr("_Identify") & " And 编号 = '" & e.OldValue & "'")
jk1 = DataTables("库存表").SQLCompute("Sum(入库件数)","[_Identify] < " & mr("_Identify") & " And 编号 = '" & e.OldValue & "'")
ck = DataTables("库存表").SQLCompute("Sum(出库数量)","[_Identify] < " & mr("_Identify") & " And 编号 = '" & e.OldValue & "'")
ck1 = DataTables("库存表").SQLCompute("Sum(出库件数)","[_Identify] < " & mr("_Identify") & " And 编号 = '" & e.OldValue & "'")
dr("库存数量") = dr("入库数量") - dr("出库数量") + jk - ck
dr("库存件数") = dr("入库件数") - dr("出库件数") + jk1 - ck1
End If
End If
If dr IsNot Nothing Then
drs = e.DataTable.Select("[_Identify] >= " & dr("_Identify") & " And [编号] = '" & dr("编号") & "'", "[_Identify]")
For i As Integer = 1 To drs.Count - 1
drs(i)("库存数量") = drs(i-1)("库存数量") + drs(i)("入库数量") - drs(i)("出库数量")
drs(i)("库存件数") = drs(i-1)("库存件数") + drs(i)("入库件数") - drs(i)("出库件数")
Next
End If
End If
End Select
然后当删除记录时就会出现
此主题相关图片如下:微信图片_20230320142452.png
(不能通过已删除行访问该行信息)。我之前还不会,后来不知怎么出现这情况。