以文本方式查看主题

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

--  作者:有点甜
--  发布时间:2019/6/4 16:02:00
--  

试试

 

If e.DataCol.Name = "下达日期"  Then
    If e.DataRow.IsNull("下达日期")  Then
        e.DataRow("材料编码") = Nothing
    Else
        e.DataRow.save
        Dim bh As String  =  Format(e.DataRow("下达日期"),"yydd")  \' 取得编号的8位前缀
        If e.DataRow("材料编码").StartsWith(bh) = False \'如果编号的前8位不符
            Dim dt2 As DataTable = DataTables("采购申请明细")
            Dim max As String
            Dim idx As Integer
            max = e.DataTable.SQLCompute("Max(材料编码)","下达日期 = #" & e.DataRow("下达日期") & "#") \'取得该天的最大编号

msgbox(max)
            If max > "" Then \'如果存在最大编号
                idx = CInt(max.Substring(6,3)) + 1 \'获得最大编号的后三位顺序号,并加1
            Else
                idx = 1 \'否则顺序号等于1
            End If
            e.DataRow("材料编码") = "fl"& bh  & Format(idx,"000")
            e.DataRow.save
        End If
    End If
End If


--  作者:有点甜
--  发布时间:2019/6/5 20:16:00
--  

 

msgbox(max) 弹出什么?

 

 


--  作者:有点甜
--  发布时间:2019/6/5 20:35:00
--  

max = e.DataTable.SQLCompute("Max(材料编码)","下达日期 = \'" & e.DataRow("下达日期") & "\' and len(材料编码) = 9") \'取得该天的最大编号

msgbox(max)


--  作者:有点甜
--  发布时间:2019/6/6 9:20:00
--  

贴出你新增行的代码。

 

在代码里面加入msgbox,看是否执行到。

 

要确保你写的表名是正确的,要确保你表格里面没有筛选数据。

 


--  作者:有点甜
--  发布时间:2019/6/6 10:28:00
--  
    Case "增加行"
        Dim t As Table = Tables("销售辅料下达_采购申请明细")
        Dim cs() As String = {"申请日期","申请人", "备注", "采购申请号","申请类型","需审核人","销售订单号","订单状态","线别"}
        Dim r As Row = t.current
msgbox(123)
        If r Is Nothing Then
            Dim nr As Row = t.addnew
            Tables("销售辅料下达_采购申请明细").DataTable.DataCols("申请日期").SetDateTimeFormat(DateTimeFormatEnum.Date)
            nr("申请日期") = Date.Today
            nr("下达日期") = Date.Today
            nr("制单人") = _UserName
        Else
            Dim nr As Row = t.addnew
            Tables("销售辅料下达_采购申请明细").DataTable.DataCols("申请日期").SetDateTimeFormat(DateTimeFormatEnum.Date)
            nr("申请日期") = Date.Today
            nr("下达日期") = Date.Today
            nr("制单人") = _UserName
            For Each c As String In cs
                nr(c) = r(c)
            Next
        End If

--  作者:有点甜
--  发布时间:2019/6/6 11:48:00
--  

 

  Case "增加行"
        Dim t As Table = Tables("销售辅料下达_采购申请明细")
        Dim cs() As String = {"申请日期","申请人", "备注", "采购申请号","申请类型","需审核人","销售订单号","订单状态","线别"}
        Dim r As Row = t.current
msgbox(123)

msgbox(currentTable.name)

msgbox(currentTable.filter)

msgbox(Tables("销售辅料下达_采购申请明细").filter)

msgbox(456)
        If r Is Nothing Then
            Dim nr As Row = t.addnew
            Tables("销售辅料下达_采购申请明细").DataTable.DataCols("申请日期").SetDateTimeFormat(DateTimeFormatEnum.Date)
            nr("申请日期") = Date.Today
            nr("下达日期") = Date.Today
            nr("制单人") = _UserName
        Else
            Dim nr As Row = t.addnew
            Tables("销售辅料下达_采购申请明细").DataTable.DataCols("申请日期").SetDateTimeFormat(DateTimeFormatEnum.Date)
            nr("申请日期") = Date.Today
            nr("下达日期") = Date.Today
            nr("制单人") = _UserName
            For Each c As String In cs
                nr(c) = r(c)
            Next
        End If


--  作者:有点色
--  发布时间:2019/6/6 15:12:00
--  

 

那代码不可能有问题。上传具体实例测试。

 

 


--  作者:有点甜
--  发布时间:2019/6/6 18:27:00
--  

1、新增行代码没问题啊。

 

2、截图说明报什么错。哪里不正确。


--  作者:有点甜
--  发布时间:2019/6/6 18:28:00
--  

如果是datacolchanged事件的问题,参考

 

If e.DataCol.Name = "下达日期"  Then
    If e.DataRow.IsNull("下达日期")  Then
        e.DataRow("材料编码") = Nothing
    Else
        e.DataRow.save
        Dim bh As String  =  Format(e.DataRow("下达日期"),"yyMM")  \' 取得编号的8位前缀
        If e.DataRow("材料编码").StartsWith(bh) = False \'如果编号的前8位不符
            Dim dt2 As DataTable = DataTables("采购申请明细")
            Dim max As String
            Dim idx As Integer
            max = e.DataTable.SQLCompute("Max(材料编码)","下达日期 = #" & e.DataRow("下达日期") & "# and len(材料编码) = 9") \'取得该天的最大编号
            If max > "" Then \'如果存在最大编号
                idx = CInt(max.Substring(6,3)) + 1 \'获得最大编号的后三位顺序号,并加1
            Else
                idx = 1 \'否则顺序号等于1
            End If
            e.DataRow("材料编码") = "fl"& bh & Format(idx,"000")
            e.DataRow.save
        End If
    End If
End If
If e.DataCol.Name = "申请日期"  Then
    If e.DataRow.IsNull("申请日期")  Then
        e.DataRow("采购申请号") = Nothing
    Else
        e.DataRow.save
        Dim bh As String  =  Format(e.DataRow("申请日期"),"yyMMdd")  \' 取得编号的8位前缀
        If e.DataRow("采购申请号").StartsWith(bh) = False \'如果编号的前8位不符
            Dim dt2 As DataTable = DataTables("采购申请明细")
            Dim max As String
            Dim idx As Integer
            max = e.DataTable.SQLCompute("Max(采购申请号)","申请日期 = #" & e.DataRow("申请日期") & "# And [_Identify] <> " & e.DataRow("_Identify")) \'取得该天的最大编号
            If max > "" Then \'如果存在最大编号
                idx = CInt(max.Substring(10,3)) + 1 \'获得最大编号的后三位顺序号,并加1
            Else
                idx = 1 \'否则顺序号等于1
            End If
            e.DataRow("采购申请号") = "CGSQ"& bh  & Format(idx,"000")
            e.DataRow.save
        End If
    End If
End If


--  作者:有点蓝
--  发布时间:2019/7/4 8:59:00
--  
If Tables("采购申请明细_采购申请明细").current.IsNull("下达日期")  Then
    Tables("采购申请明细_采购申请明细").current("材料编码") = Nothing
Else
    Tables("采购申请明细_采购申请明细").current.save
    Dim bg As String  = "fl" &  Format(Tables("采购申请明细_采购申请明细").current("下达日期"),"yyMM")  \' 取得编号的8位前缀
    If  Tables("采购申请明细_采购申请明细").current("材料编码").StartsWith(bg) = False \'如果编号的前8位不符
        Dim dt2 As DataTable = DataTables("采购申请明细")
        Dim max As String
        Dim idx As Integer
        max = Tables("采购申请明细").DataTable.SQLCompute("Max(材料编码)","下达日期 = \'" & Tables("采购申请明细_采购申请明细").current("下达日期") & "\' and 材料编码 like \'" & bg & "%\'") \'取得该天的最大编号
        If max > "" Then \'如果存在最大编号
            idx = CInt(max.Substring(bg.Length - 3,3)) + 1 \'获得最大编号的后三位顺序号,并加1
        Else
            idx = 1 \'否则顺序号等于1
        End If
        Tables("采购申请明细_采购申请明细").current("材料编码") = bg & Format(idx,"000")
        Tables("采购申请明细_采购申请明细").current.save
    End If
End If