以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  自动编号问题?  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=137039)

--  作者:fengwenliuyan
--  发布时间:2019/6/26 23:28:00
--  自动编号问题?
Select Case User.Group
    Case "财务"
        If e.DataCol.Name = "订单日期" Then
            If e.DataRow.IsNull("订单日期") Then
                e.DataRow("订单编号") = Nothing
            Else
                Dim bh1 As String = "DT" & Format(e.DataRow("订单日期"),"yyMMdd") \'取得订单编号的8位前缀
                If e.DataRow("订单编号").StartsWith(bh1) = False \'如果订单编号的前8位不符
                    Dim max1 As String
                    Dim idx1 As Integer
                    Dim d1 As Date = e.DataRow("订单日期").Date
                    max1 = e.DataTable.Compute("Max(订单编号)","订单日期 >= #" & d1 & "# And 订单日期 < #" & d1.adddays(1) & "# And [_Identify] <> " & e.DataRow("_Identify")) \'取得该月的最大编号
                    If max1 > "" Then \'如果存在最大订单编号
                        idx1 = CInt(max1.Substring(max1.length-3,3)) + 1 \'获得最大过磅编号的后三位顺序号,并加1
                    Else
                        idx1 = 1 \'否则顺序号等于1
                    End If
                    e.DataRow("订单编号") = bh1 & Format(idx1,"000")
                End If
            End If
        End If
    Case Else
        If e.DataCol.Name = "订单日期" Then
            If e.DataRow.IsNull("订单日期") Then
                e.DataRow("订单编号") = Nothing
            Else
                Dim bh2 As String = "DY" & Format(e.DataRow("订单日期"),"yyMMdd") \'取得订单编号的8位前缀
                If e.DataRow("订单编号").StartsWith(bh2) = False \'如果订单编号的前8位不符
                    Dim max2 As String
                    Dim idx2 As Integer
                    Dim d2 As Date = e.DataRow("订单日期").Date
                    max2 = e.DataTable.Compute("Max(订单编号)","订单日期 >= #" & d2 & "# And 订单日期 < #" & d2.adddays(1) & "# And [_Identify] <> " & e.DataRow("_Identify")) \'取得该月的最大编号
                    If max2 > "" Then \'如果存在最大订单编号
                        idx2 = CInt(max2.Substring(max2.length-3,3)) + 1 \'获得最大过磅编号的后三位顺序号,并加1
                    Else
                        idx2 = 1 \'否则顺序号等于1
                    End If
                    e.DataRow("订单编号") = bh2 & Format(idx2,"000")
                End If
            End If
        End If
End Select

问题:
当用户名的所在组为“财务”时,只能得到与上一条订单相同的自动编号,代码中的逻辑应该是顺序编号,下一行是上一行的编号尾数+1,求指正?

测试操作:
以用户名为“小王”,即User.Group为“财务”的用户名登录,编号不会新增了?

 下载信息  [文件大小:   下载次数: ]
图片点击可在新窗口打开查看点击浏览该文件:管理项目1.rar



--  作者:fengwenliuyan
--  发布时间:2019/6/27 8:45:00
--  
求帮助!
--  作者:有点甜
--  发布时间:2019/6/27 9:11:00
--  
\'已知订单日期,自动得出订单编号,年月日编号:
Select Case User.Group
    Case "财务"
        If e.DataCol.Name = "订单日期" Then
            If e.DataRow.IsNull("订单日期") Then
                e.DataRow("订单编号") = Nothing
            Else
                Dim bh1 As String = "DT" & Format(e.DataRow("订单日期"),"yyMMdd") \'取得订单编号的8位前缀
                If e.DataRow("订单编号").StartsWith(bh1) = False \'如果订单编号的前8位不符
                    Dim max1 As String
                    Dim idx1 As Integer
                    Dim d1 As Date = e.DataRow("订单日期").Date
                    max1 = e.DataTable.Compute("Max(订单编号)","订单编号 like \'" & bh1 & "%\' and 订单日期 >= #" & d1 & "# And 订单日期 < #" & d1.adddays(1) & "# And [_Identify] <> " & e.DataRow("_Identify")) \'取得该月的最大编号
                    If max1 > "" Then \'如果存在最大订单编号
                        idx1 = CInt(max1.Substring(max1.length-3,3)) + 1 \'获得最大过磅编号的后三位顺序号,并加1
                    Else
                        idx1 = 1 \'否则顺序号等于1
                    End If
                    e.DataRow("订单编号") = bh1 & Format(idx1,"000")
                End If
            End If
        End If
    Case Else
        If e.DataCol.Name = "订单日期" Then
            If e.DataRow.IsNull("订单日期") Then
                e.DataRow("订单编号") = Nothing
            Else
                Dim bh2 As String = "DY" & Format(e.DataRow("订单日期"),"yyMMdd") \'取得订单编号的8位前缀
                If e.DataRow("订单编号").StartsWith(bh2) = False \'如果订单编号的前8位不符
                    Dim max2 As String
                    Dim idx2 As Integer
                    Dim d2 As Date = e.DataRow("订单日期").Date
                    max2 = e.DataTable.Compute("Max(订单编号)","订单编号 like \'" & bh2 & "%\' and 订单日期 >= #" & d2 & "# And 订单日期 < #" & d2.adddays(1) & "# And [_Identify] <> " & e.DataRow("_Identify")) \'取得该月的最大编号
                    If max2 > "" Then \'如果存在最大订单编号
                        idx2 = CInt(max2.Substring(max2.length-3,3)) + 1 \'获得最大过磅编号的后三位顺序号,并加1
                    Else
                        idx2 = 1 \'否则顺序号等于1
                    End If
                    e.DataRow("订单编号") = bh2 & Format(idx2,"000")
                End If
            End If
        End If
End Select