-- 作者:qinlao666
-- 发布时间:2015/3/21 13:07:00
-- 自动编号问题不能按顺序增加
老师请帮我看下代码,为什么不能自己增加顺序好,都是001
Select e.DataCol.Name Case "拜访_类型","拜访_人员" If e.DataRow.IsNull("拜访_类型") OrElse e.DataRow.IsNull("拜访_人员") Then e.DataRow("编号") = Nothing Else Dim bfry As String = e.DataRow("拜访_人员") If e.DataRow("拜访_人员") = "汪晓光" Then bfry = "W" ElseIf e.DataRow("拜访_人员") = "张志斌" Then bfry = "B" ElseIf e.DataRow("拜访_人员") = "巩中桂" Then bfry = "G" ElseIf e.DataRow("拜访_人员") = "汪振学" Then bfry = "X" ElseIf e.DataRow("拜访_人员") = "周荣凯" Then bfry = "Z" ElseIf e.DataRow("拜访_人员") = "张良斌" Then bfry = "L" ElseIf e.DataRow("拜访_人员") = "吴小龙" Then bfry = "I" ElseIf e.DataRow("拜访_人员") = "刘杰" Then bfry = "J" Else bfry = "P" End If Dim bflx As String = e.DataRow("拜访_类型") If e.DataRow("拜访_类型") = "电话" Then bflx = "D" Else bflx = "Z" End If Dim bf As String = "BF" Dim d As Date = e.DataRow("拜访_日期") 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 bh As String = bf & Format(d,"yyMM") \'生成编号的前6位,4位年,2位月. If e.DataRow("编号").StartsWith(bh) = False \'如果编号的前6位不符 Dim max As String Dim idx As Integer max = e.DataTable.Compute("Max(编号)","拜访_日期 >= #" & fd & "# And 拜访_日期 <= #" & ld & "# And [序号] <> " & e.DataRow("序号")) \'取得该月的最大编号 If len(max) = 14 Then \'如果存在最大编号 idx = CInt(max.Substring(11,3)) + 1 \'获得最大编号的后三位顺序号,并加1 Else idx = 1 \'否则顺序号等于1 End If e.DataRow("编号") = bh & bflx & bfry & "-" & Format(idx,"000") End If End If End Select
|
-- 作者:有点甜
-- 发布时间:2015/3/22 9:33:00
--
Select e.DataCol.Name Case "拜访_类型","拜访_人员" If e.DataRow.IsNull("拜访_类型") OrElse e.DataRow.IsNull("拜访_人员") Then e.DataRow("编号") = Nothing Else Dim bfry As String = e.DataRow("拜访_人员") If e.DataRow("拜访_人员") = "汪晓光" Then bfry = "W" ElseIf e.DataRow("拜访_人员") = "张志斌" Then bfry = "B" ElseIf e.DataRow("拜访_人员") = "巩中桂" Then bfry = "G" ElseIf e.DataRow("拜访_人员") = "汪振学" Then bfry = "X" ElseIf e.DataRow("拜访_人员") = "周荣凯" Then bfry = "Z" ElseIf e.DataRow("拜访_人员") = "张良斌" Then bfry = "L" ElseIf e.DataRow("拜访_人员") = "吴小龙" Then bfry = "I" ElseIf e.DataRow("拜访_人员") = "刘杰" Then bfry = "J" Else bfry = "P" End If Dim bflx As String = e.DataRow("拜访_类型") If e.DataRow("拜访_类型") = "电话" Then bflx = "D" Else bflx = "Z" End If Dim bf As String = "BF" Dim d As Date = e.DataRow("拜访_日期") Dim bh As String = bf & Format(d,"yyMM") & bflx & bfry & "-" Dim max As String Dim idx As Integer max = e.DataTable.Compute("Max(编号)","编号 like \'" & bh & "%\'") If len(max) = 14 Then \'如果存在最大编号 idx = CInt(max.Substring(bh.Length)) + 1 \'获得最大编号的后三位顺序号,并加1 Else idx = 1 \'否则顺序号等于1 End If e.DataRow("编号") = bh & Format(idx,"000") End If End Select
|