以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  [求助]如何实现一个表里两列同时进行自动编号?  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=63931)

--  作者:wll1919
--  发布时间:2015/2/1 12:22:00
--  [求助]如何实现一个表里两列同时进行自动编号?

如题:

已实现一个表里的一行自动编号,如何根据相同的名字进行筛选后自动生成次级编号?

代码如下:

Select e.DataCol.Name

    Case "入住时间","租赁性质","承租人"

        If e.DataRow.isnull("合同编号")  Then 


            If e.DataRow.IsNull("入住时间") OrElse e.DataRow.IsNull("租赁性质") Then

                e.DataRow("合同编号") = Nothing

            Else

                Dim d As Date = e.DataRow("入住时间")

                Dim lb As String = e.DataRow("承租人")

                Dim bh As String = "" & e.DataRow("项目") & "-" & e.DataRow("租赁性质") & "-" & Format(d,"yyyy") & "-" 

                Dim max As String

                Dim idx As Integer

                Dim flt As String

                Dim fltx As String

                Dim maxx As String

                Dim idxx As Integer

                flt = "合同编号 like \'" & bh & "%\' And [_Identify] <> " & e.DataRow("_Identify")

                fltx = "承租人 = \'" & lb & "\' And [_Identify] <> " & e.DataRow("_Identify")

                max = e.DataTable.Compute("Max(合同编号)",flt) 


                maxx = e.DataTable.Compute("Max(批次)",fltx)

                If max > ""  Then 

                    idx = CInt(max.Substring(bh.Length,4)) + 1 

                Else

                    idx = 1 


                End If

                If maxx > "" Then

                    idxx = CInt(maxx.Substring(2,2)) + 1 

                Else

                    idxx = 1 

                End If

                e.DataRow("合同编号") = bh & Format(idx,"0000")

                e.DataRow("批次") = "第" & Format(idxx,"00") & "批"

            End If

        End If

End Select

<!--EndFragment-->(以前发的代码错了一点,已经修正) 

(已实现次级编号的自动递增,代码在6楼,不过只能是数字,无法在前后加字符)

如上代码已实现合同编号的自动生成,可是批次这个次级编号一直都是01,无法递增。感觉是调用字符串的问题,能解决吗?

[此贴子已经被作者于2015-2-2 13:23:27编辑过]

--  作者:黄训良
--  发布时间:2015/2/1 13:48:00
--  
同一表中同一个记录 的编号本来就是唯一一个编号,一个房间同时出租给两个人,也应是两份合同,如果是同一房间出租给同一人,要记录出租次数,那最好建一个关联表。
--  作者:wll1919
--  发布时间:2015/2/1 14:33:00
--  

我的意思是,合同编号是唯一的,逐一递增(现在已经实现),然后不同企业对应的批次最好也能自动递增,这样批次列对应的企业名称然后递增批次号,在一个表格是不能实现的?


--  作者:黄训良
--  发布时间:2015/2/1 19:22:00
--  

参考:

http://www.foxtable.com/help/topics/2191.htm

[此贴子已经被作者于2015-2-1 19:22:36编辑过]

--  作者:有点甜
--  发布时间:2015/2/2 9:45:00
--  

idxx = CInt(maxx.Substring(2,2)) + 1 

改成

 

idxx = CInt(maxx.Substring(1,2)) + 1 


--  作者:wll1919
--  发布时间:2015/2/2 13:22:00
--  

换了一个代码写法,已经实现次级编号的自动递增

 

代码如下:

 

Select e.DataCol.Name

    Case "入住时间","租赁性质","承租人"

        If e.DataRow.isnull("合同编号")  Then 

            If e.DataRow.IsNull("入住时间") OrElse e.DataRow.IsNull("租赁性质") Then

                e.DataRow("合同编号") = Nothing

            Else

                Dim d As Date = e.DataRow("入住时间")

                Dim bh As String = "" & e.DataRow("项目") & "-" & e.DataRow("租赁性质") & "-" & Format(d,"yyyy") & "-" 

                Dim max As String

                Dim idx As Integer

                Dim flt As String

                flt = "合同编号 like \'" & bh & "%\' And [_Identify] <> " & e.DataRow("_Identify")

                 max = e.DataTable.Compute("Max(合同编号)",flt) 

                   If max > ""  Then 

                    idx = CInt(max.Substring(bh.Length,4)) + 1 

                   Else

                    idx = 1 

                   End If

                e.DataRow("合同编号") = bh & Format(idx,"0000")

            End If

        End If

       If e.DataRow.IsNull("承租人") Then \'次级编号的判断语句,加入了这一句才实现次级编号

        e.DataRow("批次") = Nothing

       Else

         Dim lb As String = e.DataRow("承租人")

         If e.DataRow("批次").StartsWith(lb) = False

         Dim maxx As String

         Dim idxx As Integer

         maxx = e.DataTable.Compute("Max(批次)","承租人 = \'" & lb & "\' And [_Identify] <> " & e.DataRow("_Identify")) 

            If maxx > "" Then

            idxx = CInt(maxx.Substring(1,2)) + 1 

            Else

            idxx = 1 

            End If

         e.DataRow("批次") = "第" & Format(idxx,"00") & "批"    

          End If

       End If

End Select

 

(已实现全部功能,代码也更新了,希望这个例子对大家有帮助)

[此贴子已经被作者于2015-2-2 14:34:39编辑过]

--  作者:有点甜
--  发布时间:2015/2/2 14:17:00
--  

 一样可以啊。看5楼。

 

 如果还不会,就请上传例子。


--  作者:wll1919
--  发布时间:2015/2/2 14:31:00
--  

已经解决,当时想错了,其实只要避开第一个汉字字符就可以。学习了!