“材料库入库出库明细表”中事件代码为;
If e.DataCol.Name = "配件信息_配件名称" OrElse e.DataCol.name = "配件信息_配件批号" OrElse e.DataCol.Name = "配件信息_规格" Then
If e.DataRow.isnull("配件信息_配件名称") OrElse e.DataRow.isnull("配件信息_配件批号") OrElse e.DataRow.Isnull("配件信息_型号") Then
e.DataRow("配件信息_配件库存编码") = Nothing
Else
e.DataRow("配件信息_配件库存编码") = e.DataRow("配件信息_配件批号") & GetPy(e.DataRow("配件信息_配件名称"), 1).ToUpper & "-" & e.DataRow("配件信息_型号") & "-" & e.DataRow("配件信息_配件规格") & "-" & e.DataRow("配件信息_备注").replace("*", "").Replace("/", "")
End If
End If
Select Case e.DataCol.Name
Case "配件信息_配件库存编码","出入库信息_入库数量","出入库信息_出库数量"
Dim bh As String = e.DataRow("配件信息_配件库存编码")
If e.DataCol.Name = "配件信息_配件库存编码" Then bh = e.NewValue
Dim drs As List(of DataRow)
Dim Filter As String
Filter = "[_SortKey] >= " & e.DataRow("_SortKey") & " And [配件信息_配件库存编码] = '" & bh & "'"
drs = e.DataTable.Select(Filter,"[_SortKey]")
For Each dr As DataRow In drs
Filter = "[_SortKey] <= " & dr("_SortKey") & " And [配件信息_配件库存编码] = '" & dr("配件信息_配件库存编码") & "'"
Dim Val1 As Double = e.DataTable.Compute("Sum(出入库信息_入库数量)",Filter)
Dim Val2 As Double = e.DataTable.Compute("Sum(出入库信息_出库数量)",Filter)
Dim Val3 As Double = e.DataTable.Compute("Sum(库存结余)",Filter & " And 出入库信息_入库数量 Is null And 出入库信息_出库数量 Is null")
dr("库存结余") = Val1 - Val2 + val3
Next
Dim dr2 As DataRow = DataTables("材料库库存动态表").Find("配件信息_配件库存编码 = '" & bh & "'" )
Dim fdr As DataRow
If drs.Count >0 Then
fdr = drs(drs.Count - 1)
Else
fdr = e.DataRow
End If
If dr2 Is Nothing Then
dr2 = DataTables("材料库库存动态表").AddNew()
dr2("配件信息_配件名称") = e.DataRow("配件信息_配件名称")
dr2("配件信息_型号") = e.DataRow("配件信息_型号")
dr2("配件信息_配件规格") = e.DataRow("配件信息_配件规格")
dr2("配件信息_备注") = e.DataRow("配件信息_备注")
dr2("配件信息_配件库存编码") = fdr("配件信息_配件库存编码")
dr2("配件信息_配件批号") = fdr("配件信息_配件批号")
End If
dr2("库存结余") = fdr("库存结余")
If e.DataCol.Name = "配件信息_配件库存编码" AndAlso e.OldValue IsNot Nothing AndAlso e.OldValue <> e.NewValue Then
Filter = "[_SortKey] > " & e.DataRow("_SortKey") & " And [配件信息_配件库存编码] = '" & e.OldValue & "'"
drs = e.DataTable.Select(Filter,"[_SortKey]")
For Each dr As DataRow In drs
Filter = "[_SortKey] <= " & dr("_SortKey") & " And [配件信息_配件库存编码] = '" & dr("配件信息_配件库存编码") & "'"
Dim Val1 As Double = e.DataTable.Compute("Sum(出入库信息_入库数量)",Filter)
Dim Val2 As Double = e.DataTable.Compute("Sum(出入库信息_出库数量)",Filter)
Dim Val3 As Double = e.DataTable.Compute("Sum(库存结余)",Filter & " And 出入库信息_入库数量 Is null And 出入库信息_出库数量 Is null")
dr("库存结余") = Val1 - Val2 + val3
Next
fdr = Nothing
If drs.Count >0 Then
fdr = drs(drs.Count - 1)
Else
fdr = e.DataTable.Find("[配件信息_配件库存编码] = '" & e.OldValue & "'","[_SortKey] desc")
End If
If fdr IsNot Nothing
dr2 = DataTables("材料库库存动态表").Find("配件信息_配件库存编码 = '" & e.OldValue & "'" )
If dr2 Is Nothing Then
dr2 = DataTables("材料库存动态表").AddNew()
dr2("配件信息_配件名称") = e.DataRow("配件信息_配件名称")
dr2("配件信息_型号") = e.DataRow("配件信息_型号")
dr2("配件信息_配件规格") = e.DataRow("配件信息_配件规格")
dr2("配件信息_备注") = e.DataRow("配件信息_备注")
dr2("配件信息_配件库存编码") = fdr("配件信息_配件库存编码")
dr2("配件信息_配件批号") = fdr("配件信息_配件批号")
End If
dr2("库存结余") = fdr("库存结余")
Else
DataTables("材料库库存动态表").DeleteFor("配件信息_配件库存编码 = '" & e.OldValue & "'" )
End If
End If
End Select