您的位置: 首页 > 技术文档 > 网络编程 > 用数据库生成不重复的流水号
遭遇ASP类的事件设计 回到列表 ajax代理程序自动判断字符编码
用户名:
密 码: 忘记密码
注册会员 游客参观 论坛帮助
 用数据库生成不重复的流水号

作者:tane274 时间: 2006-03-16 文档类型:原创 来自:蓝色理想
浏览统计 total:885 | year:885 | Quarter:885 | Month:885 | Week:489 | today:23

'*************************************************
'函数名:getMaxOrder
'作  用:得到最大序列号
'参  数:fieldName   ----在序列号表中的字段名
'        tableName   ----序列号所在表名
'        fieldName   ----在表中的字段名
'返回值:字段的最大值
'调用函数:idAdd:作用见上
'*************************************************
function getMaxOrder(fieldName,tableName,tableFileName)
 dim orderNO,orderRS,testRS
 set testRS=Server.CreateObject("ADODB.recordset")
 set orderRS=Server.CreateObject("ADODB.recordset")
 firstNO=year(date)&right(("0"&month(date)),2)
 orderSQL="select * from fieldMaxValue where fieldName='"&fieldName&"'"
 orderRS.open orderSQL,conn,3,2
 if not orderRS.eof then
  orderRS("fieldMaxValue")=orderRS("fieldMaxValue")
  orderNO=orderRS("fieldMaxValue")
  if left(orderNO,6)=firstNO then
   orderNO=idAdd(orderNO)
  else
   orderNO=firstNO&"00001"
  end if
 else
  orderRS.addnew
  orderRS("fieldName")=fieldName
  orderNO=firstNO&"00001"
 end if
 testRS.open "select max("&tableFileName&") from "&tableName&" where "&tableFileName&" like '"&firstNO&"%'",conn,1,2
 if (not testRS.eof) and testRS(0).value>orderNO then
  orderNO=idAdd(testRS(0).value)
 end if
 testRS.close
 set testRS=nothing
 orderRS("fieldMaxValue")=orderNO
 orderRS.update
 orderRS.close
 set orderRS=nothing
 getMaxOrder=orderNO
end function


'*************************************************
'函数名:idAdd
'作  用:用来增加一:比如idAdd("5")="6",idAdd("L99")="M00",idAdd("!")="!1"
'                如果是数字就到9后进位,如果是小写字母到期z后进位
'                如果是大写字母到Z后进位,其它在后面加一个1
'参  数:id   ----需来增加的数
'返回值:增加后的数
'调用函数:addOne 一个数增加一 AddOne("5")="6",Add(9)="0",AddOne("a")="b",
'                              AddOne("z")="a",AddOne("A")="B",AddOne("Z")="A"
'*************************************************
Function AddOne(first)
Dim tempfirst
AddOne = first
intfirst = Asc(first)
If (intfirst >= 48 And intfirst < 57) Or (intfirst >= 65 And intfirst < 90) Or (intfirst >= 97 And intfirst < 122) Then
    AddOne = Chr(intfirst + 1)
    Exit Function
End If
If (intfirst = 57) Then
    AddOne = "0"
    Exit Function
End If
If (intfirst = 90) Then
    AddOne = "A"
    Exit Function
End If
If (intfirst = 122) Then
    AddOne = "a"
    Exit Function
End If
End Function

Function idAdd(id)
Dim fornt, back, strFind, strBackFind, idLen, tempid
if id="" or isNull(id) then
 iddAdd=1
 exit Function
end if
tempid = id
idLen = Len(id)
For i = 1 To idLen
    fornt = Left(id, idLen - i)
    back = Right(id, i - 1)
    strFind = Mid(id, idLen + 1 - i, 1)
    strBackFind = AddOne(strFind)
    id = fornt & strBackFind & back
    If strFind < strBackFind Then
        Exit For
    End If
    If strFind > strBackFind Then
        If i = idLen Then
            id = id & "1"
        Else
            If Mid(id, idLen - i, 1) = AddOne(Mid(id, idLen - i, 1)) Then
                id = fornt & strBackFind & back & "1"
                Exit For
            End If
        End If
    End If
Next
If id = tempid Then
    id = id & "1"
End If
idAdd = id
End Function


'调用示例
serviceNO=getMaxOrder("serviceNO","service","serviceNO")


'其中保存所有字段流水号最大值的表的结构为:
表名:fieldMaxValue
字段
id    fieldName     fieldMaxValue

经典讨论帖:
http://www.blueidea.com/bbs/NewsDetail.asp?id=2496432

出处:蓝色理想
责任编辑:moby

◎进入论坛网络编程版块参加讨论

相关文章 更多相关链接
[php]配置,链接access数据库
走近数据恢复
动网论坛代码分析之嵌套查询
包含文件对数据库链接的影响
[ASP]向数据库读写image文件
全网 本站 论坛
热门搜索:CSS Fireworks 设计比赛 网页制作 Dreamweaver Studio8 Flash
站点最新 站点最新列表
无组件生成验证码
谈PHP生成静态页面
缓存技术详谈—php
目录,文件操作详谈—php
用php读取xml数据
模板用xml的思路
多表查询技巧
手绘苹果教程
中国插画网新版发布
说鸥
栏目最新 栏目最新列表
无组件生成验证码
谈PHP生成静态页面
缓存技术详谈—php
目录,文件操作详谈—php
用php读取xml数据
模板用xml的思路
多表查询技巧
如何用CSS定义表格与模拟表格
div下图片自适应解决方法
[css]IE5/IE5.5/IE6/FF兼容性

蓝色理想版权申明:除部分特别声明不要转载,或者授权我站独家播发的文章外,大家可以自由转载我站点的原创文章,但原作者和来自我站的链接必须保留(非我站原创的,按照原来自一节,自行链接)。文章版权归我站和作者共有。

转载要求:转载之图片、文件,链接请不要盗链到本站,且不准打上各自站点的水印,亦不能抹去我站点水印。

特别注意:本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

本文暂时没有评论和评分

您的评论
用户名:  口令:
说明:输入正确的用户名和密码才能参与评论。如果您不是本站会员,你可以注册 为本站会员。
注意:文章中的链接、内容等需要修改的错误,请用报告错误,以利文档及时修改。
不评分 1 2 3 4 5
注意:请不要在评论中含与内容无关的广告链接,违者封ID
请您注意:
·不良评论请用报告管理员,以利管理员及时删除。
·尊重网上道德,遵守中华人民共和国的各项有关法律法规
·承担一切因您的行为而直接或间接导致的民事或刑事法律责任
·本站评论管理人员有权保留或删除其管辖评论中的任意内容
·您在本站发表的作品,本站有权在网站内转载或引用
·参与本评论即表明您已经阅读并接受上述条款
推荐文档 | 打印文档 | 评论文档 | 报告错误