以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  查找最大编码  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=129854)

--  作者:有点甜
--  发布时间:2019/1/7 19:06:00
--  

代码改成这样测试

 

If e.DataCol.Name = "申请日期"  Then
    If e.DataRow.IsNull("申请日期")  Then
        e.DataRow("采购申请号") = Nothing
    Else

        e.datarow.save
        Dim dr As DataRow = e.DataTable.SQLFind("申请日期 = \'" & e.DataRow("申请日期") & "\' and [_Identify] <> " & e.DataRow("_Identify"))
        If dr IsNot Nothing Then
            e.DataRow("采购申请号") = dr("采购申请号")
        Else
            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")) \'取得该天的最大编号

msgbox(max)
                If max > "" Then \'如果存在最大编号
                    idx = CInt(max.Substring(10,3)) + 1 \'获得最大编号的后三位顺序号,并加1
                Else
                    idx = 1 \'否则顺序号等于1
                End If

msgbox(idx)
               e.DataRow("采购申请号") = "CGSQ"& bh  & Format(idx,"000")
               e.DataRow.save         
          End If
        End If
    End If
End If


--  作者:有点甜
--  发布时间:2019/1/8 9:23:00
--  

Dim bh As String = Format(e.DataRow("申请日期"),"yyMMDD") \'取得编号的8位前缀

 

改成

 

Dim bh As String  =  Format(e.DataRow("申请日期"),"yyMMdd")  \' 取得编号的8位前缀

[此贴子已经被作者于2019/1/8 9:23:57编辑过]

--  作者:有点甜
--  发布时间:2019/1/8 10:02:00
--  

1、你在afterLoad事件,把所有行删除了啊

 

DataTables("窗口2_总表").DataRows.Clear
DataTables("窗口2_总表").addnew
DataTables("窗口2_总表").AutoAddNew = True
Tables("窗口2_总表").current("工作日期") = Date.Today

 

如果你是不想显示任何数据,请修改sql语句

 

select * from {管理层杂工总表} where 1=2

 

2、datacolchanged事件代码没问题,你在表格里面再新增行,都可以得到正确的编号。


--  作者:有点甜
--  发布时间:2019/1/8 12:29:00
--  
以下是引用nuoyan88在2019/1/8 11:33:00的发言:
老师,是可以得到正确的编码,但是问题是我的管理层杂工总表中之前就有一个号:CGSQ190108007,然后我在窗口表中生成的号却不是按照CGSQ190108008这样来的,反而是按照窗口表中自己的顺序增加

 

认认真真看6楼好不好?


--  作者:有点甜
--  发布时间:2019/1/16 12:35:00
--  

如果是之前那个问题。

 

你在afterLoad事件,把红色代码删除

 

\'DataTables("窗口2_总表").DataRows.Clear
DataTables("窗口2_总表").addnew
DataTables("窗口2_总表").AutoAddNew = True
Tables("窗口2_总表").current("工作日期") = Date.Today


--  作者:有点甜
--  发布时间:2019/1/16 12:41:00
--  

1、直接在表格里面,而不是窗口里面新增测试,是否正常?

 

2、如果不正常,加入msgbox弹出条件、值,看一下,是否正常。

 

3、不会做,实例发上来测试。


--  作者:有点甜
--  发布时间:2019/1/16 14:50: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("申请日期"),"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")) \'取得该天的最大编号
            msgbox(max)
            If max > "" Then \'如果存在最大编号
                idx = CInt(max.Substring(10,3)) + 1 \'获得最大编号的后三位顺序号,并加1
            Else
                idx = 1 \'否则顺序号等于1
            End If
            msgbox(idx)
            e.DataRow("采购申请号") = "CGSQ"& bh  & Format(idx,"000")
            e.DataRow.save
        End If
    End If
End If