第一段代码:
Select e.DataCol.Name
Case "生产通知单"
If e.DataRow.IsNull("生产通知单") Then
e.DataRow("车次") = Nothing
Else
Dim lb As String = e.DataRow("生产通知单")
If e.DataRow("车次").StartsWith(lb) = False '如果单据编号前缀不符
Dim max As String
Dim idx As Integer
max = e.DataTable.Compute("Max(车次)","生产通知单 = '" & lb & "' And [_Identify] <> " &e.DataRow("_Identify")) '取得该类别的最大编号
If max > "" Then '如果存在最大编号
idx = CInt(max.Substring(2,3)) + 1 '获得最大编号的后三位顺序号,并加1
Else
idx = 1 '否则顺序号等于1
End If
e.DataRow("车次") = lb & Format(idx,"000")
End If
End If
End Select
第二段代码:
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
End Select
这两段代码在DataColChanged里可以单独运行,加到一起就出现问题了
请老师帮我合并优化一下。谢谢!!
[此贴子已经被作者于2013-7-30 13:08:48编辑过]