谢谢老师,这是我中秋收到的最好礼物。我的项目基本做完了。现在我将这次全代码上传如下,适合这个表的需求。
If e.DataCol.Name = "物料号码" Then ‘如果物料码发生变化
If e.DataRow.IsNull("物料号码") Then '判断物料码是否为空
e.DataRow("最早日期") = Nothing ’最早日期为空
e.DataRow("最晚日期") = Nothing ‘最晚日期为空时不做运算。
Else '如果上述列不为空
e.DataRow("最早日期") = DataTables("AA").Compute("min(日期)","物料号码='" & e.DataRow("物料号码") & "'") 列:最早日期对于AA表里查找日期最早的。"物料号码='" & e.DataRow("物料号码)是指所有的物料号码。
e.DataRow("最晚日期") = DataTables("AA").Compute("max(日期)","物料号码='" & e.DataRow("物料号码") & "'")
End If
End If
Select Case e.DataCol.Name
Case "最早日期","最晚日期"
Dim dr As DataRow = e.DataRow
If dr.IsNull("最早日期") OrElse dr.IsNull("最晚日期") Then
dr("天数") = Nothing
Else
Dim tp As TimeSpan = dr("最晚日期") - dr("最早日期")
dr("天数") = tp.TotalDays
End If
End Select