老师好

此主题相关图片如下:2025-02-19 22 00 49.png

If e.DataCol.Name = "项目" Then
If e.DataRow.IsNull("项目") = False AndAlso e.DataRow.IsNull("抄表日期") = False Then
Dim dr1 As DataRow = e.DataTable.Find("项目='" & e.NewValue & "' and 抄表日期 is not null and _sortkey <" & e.DataRow("_sortkey"),"_sortkey desc")
If dr1 IsNot Nothing Then
e.DataRow("总表_上期读数") = dr1("总表_本期读数")
End If
Dim idx As Integer = Tables(e.DataTable.name).findrow(e.DataRow)
If idx > 0 Then
Dim r As Row = Tables(e.DataTable.name).rows(idx-1)
If r.isnull("购气_日期")=False
e.DataRow("总表_上期读数") = e.DataRow("总表_上期读数") + r("购气_数量")
End If
End If
End If
End If
dim dr as datarow =
e.DataTable.find("购气_数量 is not null and _sortkey <" & e.DataRow("_sortkey"),"_sortkey desc")if dr isnot nothing then
e.DataRow("总表_上期读数") = e.DataRow("总表_上期读数") + r("购气_数量")
end if
老师好

此主题相关图片如下:2025-02-19 22 00 49.png
不要动不动就重置列。没有上一期,期初为0是正常的。如果要保留,自己加代码判断,如果没有上一期,就保留不更改数据
老师,下面代码用黄色标出的代码怎样合并到用红色标出的代码中。
If e.DataCol.Name = "项目" Then
If e.DataRow.IsNull("项目") = False AndAlso e.DataRow.IsNull("抄表日期") = False Then
Dim dr1 As DataRow = e.DataTable.Find("项目='" & e.NewValue & "' and 抄表日期 is not null and _sortkey <" & e.DataRow("_sortkey"), "_sortkey desc")
Dim sl As Double
If dr1 IsNot Nothing Then
sl = dr1("总表_本期读数")
End If
e.DataRow("总表_上期读数") = sl
Dim dr2 As DataRow = e.DataTable.find("项目='" & e.NewValue & "' and 购气_数量 is not null and _sortkey <" & e.DataRow("_sortkey"), "_sortkey desc")
If dr2 IsNot Nothing Then
e.DataRow("总表_上期读数") = sl + dr2("购气_数量")
End If
End If
End If
If e.DataCol.Name = "项目" Then
If e.DataRow.IsNull("项目") = False AndAlso e.DataRow.IsNull("抄表日期") = False Then
Dim dr1 As DataRow = e.DataTable.Find("项目='" & e.NewValue & "' and 抄表日期 is not null and _sortkey <" & e.DataRow("_sortkey"),"_sortkey desc")
If dr1 IsNot Nothing Then
e.DataRow("一号楼_分表上期") = dr1("一号楼_分表本期")
e.DataRow("二号楼_分表上期") = dr1("二号楼_分表本期")
e.DataRow("三号楼_分表上期") = dr1("三号楼_分表本期")
End If
Dim idx As Integer = Tables(e.DataTable.name).findrow(e.DataRow)
If idx > 0 Then
Dim r As Row = Tables(e.DataTable.name).rows(idx-1)
' If r.isnull("购气_日期")=False
'e.DataRow("总表_上期读数") = e.DataRow("总表_上期读数") + r("购气_数量")
'End If
End If
End If
End If
If dr1 IsNot Nothing Then
sl = dr1("总表_本期读数")
e.DataRow("总表_上期读数") = sl
End If
老师,这样设置只显示三号楼的数据。
If e.DataCol.Name = "项目" Then
If e.DataRow.IsNull("项目") = False AndAlso e.DataRow.IsNull("抄表日期") = False Then
Dim dr1 As DataRow = e.DataTable.Find("项目='" & e.NewValue & "' and 抄表日期 is not null and _sortkey <" & e.DataRow("_sortkey"), "_sortkey desc")
Dim sl As Double
If dr1 IsNot Nothing Then
sl = dr1("总表_本期读数")
sl = dr1("一号楼_分表本期")
sl = dr1("二号楼_分表本期")
sl = dr1("三号楼_分表本期")
End If
e.DataRow("总表_上期读数") = sl
e.DataRow("一号楼_分表上期") = sl
e.DataRow("二号楼_分表上期") = sl
e.DataRow("三号楼_分表上期") = sl
Dim dr2 As DataRow = e.DataTable.find("项目='" & e.NewValue & "' and 购气_数量 is not null and _sortkey <" & e.DataRow("_sortkey"), "_sortkey desc")
If dr2 IsNot Nothing Then
e.DataRow("总表_上期读数") = sl + dr2("购气_数量")
End If
End If
End If