以下是引用有点甜在2018/1/14 22:02:00的发言:
贴出你写的代码。
Select Case e.DataCol.Name
Case "明细账_领入张数","明细账_售出张数","明细账_废piao","明细账_上年结转张数","明细账_退piao张数","明细账_今日领入张数"
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("明细账_今日领入张数")+mr("明细账_退piao张数") - mr("明细账_售出张数") -mr("明细账_废piao")
dr = mr
End If
drs = e.DataTable.Select("[_SortKey] >= " & dr("_SortKey") & " And [姓名] = '" & dr("姓名") & "'")
For i As Integer = 1 To drs.Count - 1 '重算余下行的余额
drs(i)("明细账_结存张数") = drs(i-1)("明细账_结存张数") +drs(i)("明细账_上年结转张数") +drs(i)("明细账_今日领入张数") +drs(i)("明细账_退piao张数") - drs(i)("明细账_售出张数") -drs(i)("明细账_废piao")
Next
End Select
Select Case e.DataCol.Name
Case "明细账_售出张数","明细账_售出金额"
If e.NewValue <> e.OldValue Then
e.DataTable.DataCols("摘要_日期").RaiseDataColChanged()
End If
End Select
Select Case e.DataCol.name
Case "明细账_领入起号","明细账_领入止号","明细账_领入张数","姓名","姓名","实物账_发出起号","实物账_发出止号","实物账_发出张数","明细账_今日领入张数","明细账_退piao张数","实物账_退piao张数","年","月","日","凭证_实物号","年","月","日","凭证_号","明细账_上年结转张数","实物账_上年结转张数","实物账部分_号","实物账部分_上年结转张数"
Dim dr As DataRow = DataTables("实物账").Find("id2 = '" & e.DataRow("_Identify") & "'")
If dr Is Nothing Then
dr = DataTables("实物账").AddNew()
dr("id2") = e.DataRow("_Identify")
End If
dr("实物账_发出起号") = e.DataRow("明细账_领入起号")
dr("姓名") = e.DataRow("姓名")
dr("年") = e.DataRow("年")
dr("月") = e.DataRow("月")
dr("日") = e.DataRow("日")
dr("实物账_今日发出张数") = e.DataRow("明细账_今日领入张数")
dr("实物账_退piao张数") = e.DataRow("明细账_退piao张数")
dr("凭证_号") = e.DataRow("实物账部分_号")
dr("引用部分") = e.DataRow("摘要_内容")
End Select
If e.DataCol.Name = "明细账_售出张数" Then
If e.DataRow.IsNull("姓名") = False Then
If e.NewValue IsNot Nothing Then
Dim dr As DataRow
dr = e.DataTable.Find("姓名 = '" & e.DataRow("姓名") & "'and 明细账_售出止号 is not null","明细账_售出止号 Desc")
If dr IsNot Nothing Then
e.DataRow("明细账_售出起号") = dr("明细账_售出止号") + 1
e.DataRow("明细账_售出止号") = dr("明细账_售出止号") + e.NewValue
End If
Else
e.DataRow("明细账_售出起号") = Nothing
e.DataRow("明细账_售出止号") = Nothing
End If
End If
End If
If e.DataRow.IsNull("明细账_售出起号") = False Then
If e.DataRow.IsNull("明细账_售出张数") = False Then
e.DataRow("明细账_售出止号") = e.DataRow("明细账_售出起号") + e.DataRow("明细账_售出张数") - 1
Else
e.DataRow("明细账_售出止号") = Nothing
End If
End If
Tables("明细账表").AllowClickSort = False