If e.DataCol.name = "科目代码" Then
If e.DataRow.IsNull("科目代码") Then
e.DataRow("会计科目_一级科目") = ""
e.DataRow("会计科目_明细科目") = ""
Else
Dim str As String = e.DataRow("科目代码")
If str.Length = 4 Then
Dim dr As DataRow = DataTables("会计科目").find("科目代码 = '"& e.datarow("科目代码") & "'")
e.DataRow("会计科目_一级科目") = dr("科目名称")
e.DataRow("会计科目_明细科目") = ""
Else
Dim str1 As String = str.SubString(0,4)
Dim dr1 As DataRow = DataTables("会计科目").find("科目代码 = '"& str1 & "'")
e.DataRow("会计科目_一级科目") = dr1("科目名称")
Dim dr2 As DataRow = DataTables("会计科目").find("科目代码 = '"& str & "'")
e.DataRow("会计科目_明细科目") = dr2("科目名称")
End If
End If
End If
在窗口的按钮中写了如下代码:
Dim t As Table = Tables("凭证.凭证明细")
t.AddNew(2)
t.Rows(0)("科目代码") = "1211001"
t.Rows(1)("科目代码") = "217100101"
Dim str As String = Forms("凭证录入").Controls("lb凭证ID").text
Dim dt As DataTable = Tables("进项piao_table1").DataTable
For Each id As String In dt.GetValues("科目代码","凭证ID = '"& str & "'")
Dim r As Row = Tables("凭证.凭证明细").AddNew()
r("科目代码") = id
r("贷方金额") = dt.Compute("sum(fa piao金额)","科目代码= '"& id & "'and 凭证ID = '"& str & "'")
Dim dr As DataRow = dt.find("科目代码= '"& id & "'and 凭证ID = '"& str & "'")
r("摘要") = dr("销方名称").Substring(0,6) & "购:" & dr("fa piao摘要")
Next
t.Rows(0)("借方金额") = dt.Compute("sum(金额)","凭证ID = '"& str & "'")
t.Rows(1)("借方金额") = dt.Compute("sum(税额)","凭证ID = '"& str & "'")
Dim s As String = dt.GetComboListString("fa piao摘要","凭证ID = '"& str & "'")
s = s.Replace("|"," ")
t.Rows(0)("摘要") = "购:" & s
t.Rows(1)("摘要") = "进项税:" & s