以文本方式查看主题

-  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=100316)

--  作者:xusuyang
--  发布时间:2017/5/9 15:00:00
--  编码如何生成?

If e.DataCol.Name = "产品名称" Then
    If e.DataRow.IsNull("产品名称") Then
        e.DataRow("产品编码") = Nothing
    Else
        e.DataRow("产品编码") = GetPy(e.DataRow("产品名称"))
  End If        
 Dim bh As String = Format(e.DataRow("订货日期"),"yyyyMMdd")
        If e.DataRow("订单编码").StartsWith(bh) = True
            Dim max As String
            Dim idx As Integer
            max = e.DataTable.Compute("Max(订单编码)","订货日期= #" & e.DataRow("订货日期") & "# And [_Identify] <> " & e.DataRow("_Identify"))
            If max > "" Then
                idx = CInt(max.Substring(9,3)) + 1
            Else
                idx = 1
            e.DataRow("订单编码") = bh & "-" & Format(idx,"000")
        End If
    End If
End If

请问“订货日期”自动生成“订单编码”,如“订货日期分别:20170509,20170509”自动生成“订单编码分别20170509001,20170509002”;“产品名称”自动取产品名称各字的首字母生成“产品编码”,如“麻醉包”自动生成“MZB”

--  作者:有点色
--  发布时间:2017/5/9 15:35:00
--  
If e.DataCol.Name = "产品名称" Then
    If e.DataRow.IsNull("产品名称") Then
        e.DataRow("产品编码") = Nothing
    Else
        e.DataRow("产品编码") = GetPinyin(e.DataRow("产品名称"), 1)
    End If
    Dim bh As String = e.DataRow("产品编码") & Format(e.DataRow("订货日期"),"yyyyMMdd")
    If e.DataRow("订单编码").StartsWith(bh) = True
        Dim max As String
        Dim idx As Integer
        max = e.DataTable.Compute("Max(订单编码)","产品名称 = \'" & e.DataRow("产品名称") & "\' and 订货日期= #" & e.DataRow("订货日期") & "# And [_Identify] <> " & e.DataRow("_Identify"))
        If max > "" Then
            idx = CInt(max.Substring(bh.length+1,3)) + 1
        Else
            idx = 1
            e.DataRow("订单编码") = bh & "-" & Format(idx,"000")
        End If
    End If
End If