以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  复杂编号  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=95457)

--  作者:jamhuton
--  发布时间:2017/1/20 10:33:00
--  复杂编号
Select e.DataCol.Name
    Case "进库日期","发票号码"
        If e.DataRow.IsNull("进库日期") OrElse e.DataRow.IsNull("发票号码") Then
            e.DataRow("托盘编号") = Nothing
        Else
            Dim d As Date = e.DataRow("进库日期")
            Dim y As Integer = d.Year
            Dim m As Integer = d.Month
            Dim r As Integer = d.day
            Dim bh As String = & "TS-" & Format(d,"yyyyMMrr") &"-"&  
            Dim fd As Date = New Date(y,m,1) \'获得该月的第一天
            Dim ld As Date = New Date(y,m,Days) \'获得该月的最后一天
             If e.DataRow("托盘编号").StartsWith(bh) = False \'如果托盘编号前缀不符
                Dim max As String
                Dim idx As Integer
                Dim flt As String
                flt = 进库日期 >= #" & fd & "# And 进库日期 <= #" & ld & "# And [_Identify] <> " & e.DataRow("_Identify")
                max = e.DataTable.Compute("Max(托盘编号)",flt) \'取得该月的相同发票号码的最大托盘编号
                If max > "" Then \'如果存在最大托盘编号
                    idx = CInt(max.Substring(20,4)) + 1 \'获得最大托盘编号的后四位顺序号,并加1
                Else
                    idx = 1 \'否则顺序号等于1
                End If
                e.DataRow("托盘编号") = bh & Format(idx,"0000") & "-" & e.Daterow(发票号码)
            End If
        End If
End Select


我要得到的编码:TS-YYMMRR-000x-发票号码

--  作者:有点色
--  发布时间:2017/1/20 10:52:00
--  
Select e.DataCol.Name
    Case "进库日期","发票号码"
        If e.DataRow.IsNull("进库日期") OrElse e.DataRow.IsNull("发票号码") Then
            e.DataRow("托盘编号") = Nothing
        Else
            Dim d As Date = e.DataRow("进库日期")
            Dim y As Integer = d.Year
            Dim m As Integer = d.Month
            Dim bh As String = "TS-" & Format(d,"yyMMdd") & "-"
            Dim fd As Date = New Date(y,m,1) \'获得该月的第一天
            Dim ld As Date = fd.AddMonths(1)
             If e.DataRow("托盘编号").StartsWith(bh) = False \'如果托盘编号前缀不符
                Dim max As String
                Dim idx As Integer
                Dim flt As String
                flt = "进库日期 >= #" & fd & "# And 进库日期 < #" & ld & "# And substring(托盘编号,16," & e.DataRow("发票号码").length & ") = \'" & e.DataRow("发票号码") & "\' And [_Identify] <> " & e.DataRow("_Identify")
                max = e.DataTable.Compute("Max(托盘编号)",flt) \'取得该月的相同发票号码的最大托盘编号
                If max > "" Then \'如果存在最大托盘编号
                    idx = CInt(max.Substring(bh.length,4)) + 1 \'获得最大托盘编号的后四位顺序号,并加1
                Else
                    idx = 1 \'否则顺序号等于1
                End If
                e.DataRow("托盘编号") = bh & Format(idx,"0000") & "-" & e.Datarow("发票号码")
            End If
        End If
End Select
[此贴子已经被作者于2017/1/20 11:07:42编辑过]

--  作者:jamhuton
--  发布时间:2017/1/20 10:59:00
--  
2016/1/1 0:00:00 555 TS-160101-0001-098765 0 201601-001 098765
2016/1/1 0:00:00 555 TS-160101-0001-098765 0 201601-001 098765
2016/1/1 0:00:00 555 TS-160101-0001-098765 0 201601-001 098765

老师产生的编号不递增

--  作者:有点色
--  发布时间:2017/1/20 11:07:00
--  

哦,想复杂了。

 

Select e.DataCol.Name
    Case "进库日期","发票号码"
        If e.DataRow.IsNull("进库日期") OrElse e.DataRow.IsNull("发票号码") Then
            e.DataRow("托盘编号") = Nothing
        Else
            Dim d As Date = e.DataRow("进库日期")
            Dim y As Integer = d.Year
            Dim m As Integer = d.Month
            Dim bh As String = "TS-" & Format(d,"yyMMdd") & "-"
            Dim fd As Date = New Date(y,m,1) \'获得该月的第一天
            Dim ld As Date = fd.AddMonths(1)
            Dim max As String
            Dim idx As Integer
            Dim flt As String
            flt = "进库日期 >= #" & fd & "# And 进库日期 < #" & ld & "# And 发票号码 = \'" & e.DataRow("发票号码") & "\' And [_Identify] <> " & e.DataRow("_Identify")
            max = e.DataTable.Compute("Max(托盘编号)",flt) \'取得该月的相同发票号码的最大托盘编号
            msgbox(max)
            If max > "" Then \'如果存在最大托盘编号
                idx = CInt(max.Substring(bh.length,4)) + 1 \'获得最大托盘编号的后四位顺序号,并加1
            Else
                idx = 1 \'否则顺序号等于1
            End If
            e.DataRow("托盘编号") = bh & Format(idx,"0000") & "-" & e.DataRow("发票号码")
           
        End If
End Select


--  作者:jamhuton
--  发布时间:2017/1/20 11:11:00
--  
图片点击可在新窗口打开查看谢谢老师


--  作者:jamhuton
--  发布时间:2017/1/20 11:19:00
--  
老师,为什么这编号生成的时候有个确认框,我增加关联表的子表行,然后会出来一个确认框,确认之后才显示这新增行。

生成这编码的2个列都来自母表的。
[此贴子已经被作者于2017/1/20 11:23:08编辑过]

--  作者:有点色
--  发布时间:2017/1/20 11:24:00
--  
 把这句代码去掉 msgbox(max)
--  作者:jamhuton
--  发布时间:2017/1/20 11:27:00
--  
搞定了