Dim e As RequestEventArgs = args(0)
Dim dt As DataTable
Dim cmd As New SQLCommand
cmd.C
cmd.CommandText = "S elect * From {凭证序时簿} Where [_Identify] Is null" '生成空表
dt = cmd.ExecuteReader(True)
Dim je As Decimal
Dim sz As String
Dim d As Date
Dim zh As String
Dim dr As DataRow
If e.Values.Keys.ToString > "" Then
dr = dt.AddNew()
For Each key As String In e.Values.keys
If key = "日期" Then
dr("日期") = e.Values (key)
d = e.Values (key)
ElseIf key = "收支" Then
sz = e.Values (key)
ElseIf key = "金额" Then
je = e.Values (key)
ElseIf key = "科目" Then
dr("会计科目_全名") = e.Values (key)
ElseIf key = "字号" Then
dr("凭证字") = e.Values (key)
zh = e.Values (key)
ElseIf key = "附件" Then
dr("附件") = e.Values (key)
ElseIf key = "制单" Then
dr("制单") = e.Values (key)
ElseIf key = "备注" Then
dr("备注") = e.Values (key)
End If
Next
End If
If sz = "收入" Then
dr("本期发生额_借方") = je
Else
dr("本期发生额_贷方") = je
End If
Dim n As Integer = zh.Length + 1
Dim y As Integer = d.Year
Dim m As Integer = d.Month
Dim Days As Integer = Date.DaysInMonth(y, m)
Dim fd As Date = New Date(y, m, 1) '获得该月的第一天
Dim ld As Date = New Date(y, m, Days) '获得该月的最后一天
Dim max As String
Dim sqlmax As String
Dim idx As Integer
cmd.CommandText = "S elect max(凭证编号) From {凭证序时簿} Where 日期 >= #" & fd & "# And 日期 <= #" & ld & "# And 凭证编号 Like " & zh
max = cmd.ExecuteScalar()
If max > "" Then '如果存在最大编号
idx = CInt(max.Substring(n, 3))
Else
idx = 0
End If
idx = idx + 1
dr("凭证编号") = zh & "-" & Format(idx, "000")
dr.Save()
Dim s As String = "新增凭证成功,凭证编号:【" & dr("凭证编号") & "】。"
e.WriteString(s)
e.Handled = True
去掉 凭证编号 Like条件不报错