- 精品下载 | 实用查询 | 词典查询 | 桌面壁纸 | 网址 | 笑话 | FLASH频道 | 天气文章资讯 | 站长工具 | 证件办理 | 闪字生成 | 广告代码 | 在线手册 | 有问必答
您现在的位置: 蓝派网 >> 文章中心 >> 网络编程 >> ASP >> 正文
站内文章搜索:           

我在开发过程总结的一套实现常用功能的函数

作者:佚名    文章来源:网络转载    更新时间 :2007-11-26 1:05:13

<%
 Option Explicit
 '=========================================================================================================================================================
 '=========================================================================================================================================================
 '=========================================================================================================================================================
 public function MyNowNumber()
  MyNowNumber=year(now)& month(NOw) & day(NOw) & hour(NOw) & Minute(Now) & Second(Now)
 end function
 
 public function sDataGrid(SqlStr,ConnStr,PageSize,PageNum,beginField,EndField,IDField,HttpStr,PageInfo)'以表格形式显示数据

'这个函数本打算用来实现点击表头排序功能,可是后来总是随机性无故出错,所以就没在现用了,哪们高手可以看看

 
  'DataGrid功能:
  '  将数据以表格形式显出来,
  ' 根据需要可能确定显示的字段,
  ' 页号,每页显示的记录数
  ' 复选框绑定的字段
  ' 修改数据时所连接到的设定的网页,传递的参数名是Idfield
 
  '调用实例 call DataGrid("SELECT * FROM mater_bcode","Driver={SQL Server};uid=sa;pwd=passed;database=cthpdb;server=scb-web",10,20,2,50,0,"http://www.clkhome/mater_code1/tools/aaa.asp","Null")

 
  '参数说明
  'sqlstr: 将要查询的sql语句
  'connstr: 数据库连接字符串
  'PageSize: 数据集每页的记录数,PageSize="MAX"时不分页
  'PageNum: 数据集中将要显示的页号
  'beginField:在记录集中开始显示的字段位置
  'EndField: 在记录集中结束显示的字段位置
  'IDField: 用于给复选框的value赋值的字段在记录集中的位置,可以用于提交到其它页,其它页做处理的依据
  '           如果IDField<0 or IDField> rs.fields.count或不是数字 则不显示复选框
  'HttpStr 修改记录时连接到的网页,传递的是IDField的值,如果 httpstr="0"则不显示修改连接
  'PageInfo 确定是否显示"第1页,共1页"的提示,PageInfo="Null"时不显示
  '返回值, 返回的是记录集的当前页号
 
 
  on error resume next
  dim conn,rs
  'if isnumeric(pageSize)then rs.pageSize=pageSize
  set conn=server.CreateObject ("adodb.connection")
  set rs=server.CreateObject ("adodb.recordset")
  Conn.open Connstr
  rs.Open sqlstr,conn,1,3
  if err.number<>0 then
   Response.Write writeinfo("<BR>DataGrid函数在运行出现了错误!<BR>错描述:" & err.Description & "<BR>")
   DataGrid="Err"
   exit function  
  end if 
  if rs.RecordCount<1 then
   Response.Write "<font size='-1' color='#FF0000'>&nbsp;没有数据...</font>"
   DataGrid=0
   exit function
  end if
 
  '------------对参数据进行处理----------------------
   '----------确定如何显示字段-----------------
  if not Isnumeric(beginField) or beginField<0 then
    beginField=0'确保开始显示的位置在合理范围内
   else
    if beginField>rs.Fields.Count-1 then beginField=rs.Fields.Count-1'保证到少显示一个字段
    if beginField<0 then beginField=0
  end if
  if not Isnumeric(EndField) then EndField=rs.Fields.Count-1
  if EndField>rs.Fields.Count-1 then EndField=rs.Fields.Count-1
  if EndField<=beginField or EndField<0 then EndField=beginField'保证到少显示一个字段
   '----------复选框、修改链接的处理在成生表格时同步完成--------------
    
   '---------分页处理------------------
  if Ucase(Trim(PageSize))="MAX" then
    PageSize=rs.RecordCount
    rs.pageSize=rs.RecordCount
    PageNum=1
   else
    if not Isnumeric(PageSize) or PageSize<1 then PageSize=10
    if PageSize>rs.recordcount then pageSize=rs.recordcount
    rs.pageSize=pageSize
     '---------页号处理----------------
    if Trim(Ucase(pageNum))="MAX" then PageNum=rs.PageCount
    if not Isnumeric(PageNum) then PageNum=1
    if PageNum<1 then PageNum=1
    if cint(PageNum-rs.PageCount)>0 then PageNum=rs.PageCount
  end if
  Rs.AbsolutePage=PageNum
 
  if err.number<>0 then
    dbinfo="数据库连接错误"
    DataGrid=0
    exit function
   else
    if rs.RecordCount<1 then
      Response.Write "没有找到记录"
      DataGrid=0
      exit function
     else
      if Ucase(trim(PageInfo))<>"NULL" then '确定是显示页号信息
       Response.Write "<font size='-1' color='#666666'>第<font color='#FF0000'>" & PageNum & "</font>页,共<font color='#FF0000'>" & rs.PageCount & "</font>页"
      end if
      '写入表头
      Response.Write  "<table width='100%' border='0' cellspacing='1' cellpadding='0' bgcolor='#999999'>"
      Response.Write  "<tr bgcolor='#CCCCCC'>"
      Response.Write  "<td width='1%' align='center'><b><font color='#666666' size='-1'>序</font></b></td>"
      dim i
      for i=beginField to EndField
       Response.Write  "<td align='center'><b><font color='#666666' size='-1'>" & rs.Fields(i).Name & "</font></b></td>"
      next
      if Isnumeric(IDfield) then '复选框及修改链接处理
       if IDField>=0 and (IDField - rs.fields.count<=0) then
        Response.Write "<td width='1%' align='center'><b><font color='#666666' size='-1'>删</font></b></td>"
        if  trim(httpstr)<>"0" then Response.Write "<td width='1%'><b><font color='#666666' size='-1'>修</font></b></td>"
       end if
      end if
      Response.Write  "</tr>"
      '写入字段信息
      dim RecordNum,FieldNum
      for RecordNum=0 to PageSize-1 '?????????????????
       Response.Write  "<tr bgcolor='#FFFFFF'>"
       Response.Write  "<td><font size='-1'>" & RecordNum +1+(PageNum-1)*PageSize  & "</font></td>"
       for FieldNum=beginField to EndField '写入字段值
        'response.write "<input type='text' name='textfield' value='" & Trim(rs.Fields(FieldNum).Value) &  "'>"     
        'if Trim(rs.Fields(FieldNum).Value)="" or Isnull(rs.Fields(FieldNum).Value) then
        '  Response.Write "<td>&nbsp;</td>"
        ' else
          Response.Write  "<td><font size='-1'><input type='text' name='textfield'  style=' border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px' value='" & Trim(rs.Fields(FieldNum).Value) & "'></font></td>"
        'end if
       next
       if Isnumeric(IDfield) then '复选框处理
        if IDField>=0 or (IDField - rs.fields.count<=0) then
         Response.Write "<td><input type='checkbox' name='IDfield' value='"& rs.Fields(IDfield).Value &"'></td>"
         if  trim(httpstr)<>"0" then Response.Write "<td><font size='-1'><a href='" & httpstr & "?IDField="& rs.Fields(IDfield).Value &"'>改</a></font></td>"
        end if
       end if
       Response.Write  "</tr>"
       rs.MoveNext
       if rs.eof then exit for '最后不到一整页时,也跳出
      next
      Response.Write "</table>"
    end if
  end if
  rs.Close
  conn.Close
  set rs=nothing
  set conn=nothing
  Err.Clear
  DataGrid=PageNum 
 end function
 
 
 
 
 
 
 public function DataGrid(SqlStr,ConnStr,PageSize,PageNum,beginField,EndField,IDField,HttpStr,PageInfo)'以表格形式显示数据
 
  'DataGrid功能:
  '  将数据以表格形式显出来,
  ' 根据需要可能确定显示的字段,
  ' 页号,每页显示的记录数
  ' 复选框绑定的字段
  ' 修改数据时所连接到的设定的网页,传递的参数名是Idfield
 
  '调用实例 call DataGrid("SELECT * FROM mater_bcode","Driver={SQL Server};uid=sa;pwd=passed;database=cthpdb;server=scb-web",10,20,2,50,0,"http://www.clkhome/mater_code1/tools/aaa.asp","Null")

 
  '参数说明
  'sqlstr: 将要查询的sql语句
  'connstr: 数据库连接字符串
  'PageSize: 数据集每页的记录数,PageSize="MAX"时不分页
  'PageNum: 数据集中将要显示的页号
  'beginField:在记录集中开始显示的字段位置
  'EndField: 在记录集中结束显示的字段位置
  'IDField: 用于给复选框的value赋值的字段在记录集中的位置,可以用于提交到其它页,其它页做处理的依据
  '           如果IDField<0 or IDField> rs.fields.count或不是数字 则不显示复选框
  'HttpStr 修改记录时连接到的网页,传递的是IDField的值,如果 httpstr="0"则不显示修改连接
  'PageInfo 确定是否显示"第1页,共1页"的提示,PageInfo="Null"时不显示
  '返回值, 返回的是记录集的当前页号
 
 
  on error resume next
  dim conn,rs
  'if isnumeric(pageSize)then rs.pageSize=pageSize
  set conn=server.CreateObject ("adodb.connection")
  set rs=server.CreateObject ("adodb.recordset")
  Conn.open Connstr
  rs.Open sqlstr,conn,1,3
  if err.number<>0 then
   Response.Write writeinfo("<BR>DataGrid函数在运行出现了错误!<BR>错描述:" & err.Description & "<BR>")
   DataGrid="Err"
   exit function  
  end if 
  if rs.RecordCount<1 then
   Response.Write "<font size='-1' color='#FF0000'>&nbsp;没有数据...</font>"
   DataGrid=0
   exit function
  end if
 
  '------------对参数据进行处理----------------------
   '----------确定如何显示字段-----------------
  if not Isnumeric(beginField) or beginField<0 then
    beginField=0'确保开始显示的位置在合理范围内
   else
    if beginField>rs.Fields.Count-1 then beginField=rs.Fields.Count-1'保证到少显示一个字段
    if beginField<0 then beginField=0
  end if
  if not Isnumeric(EndField) then EndField=rs.Fields.Count-1
  if EndField>rs.Fields.Count-1 then EndField=rs.Fields.Count-1
  if EndField<=beginField or EndField<0 then EndField=beginField'保证到少显示一个字段
   '----------复选框、修改链接的处理在成生表格时同步完成--------------
    
   '---------分页处理------------------
  if Ucase(Trim(PageSize))="MAX" then
    PageSize=rs.RecordCount
    rs.pageSize=rs.RecordCount
    PageNum=1
   else
    if not Isnumeric(PageSize) or PageSize<1 then PageSize=10
    if PageSize>rs.recordcount then pageSize=rs.recordcount
    rs.pageSize=pageSize
     '---------页号处理----------------
    if Trim(Ucase(pageNum))="MAX" then PageNum=rs.PageCount
    if not Isnumeric(PageNum) then PageNum=1
    if PageNum<1 then PageNum=1
    if cint(PageNum-rs.PageCount)>0 then PageNum=rs.PageCount
  end if
  Rs.AbsolutePage=PageNum
 
  if err.number<>0 then
    dbinfo="数据库连接错误"
    DataGrid=0
    exit function
   else
    if rs.RecordCount<1 then
      Response.Write "没有找到记录"
      DataGrid=0
      exit function
     else
      if Ucase(trim(PageInfo))<>"NULL" then '确定是显示页号信息
       Response.Write "<font size='-1' color='#666666'>第<font color='#FF0000'>" & PageNum & "</font>页,共<font color='#FF0000'>" & rs.PageCount & "</font>页"
      end if
      '写入表头
      Response.Write  "<table width='100%' border='0' cellspacing='1' cellpadding='0' bgcolor='#999999'>"
      Response.Write  "<tr bgcolor='#CCCCCC'>"
      Response.Write  "<td width='1%' align='center' onclick='form1.submit()'><b><font color='#666666' size='-1'>序</font></b></td>"
      dim i
      for i=beginField to EndField
       Response.Write  "<td align='center'><b><font color='#666666' size='-1'>" & rs.Fields(i).Name & "</font></b></td>"
      next
      if Isnumeric(IDfield) then '复选框及修改链接处理
       if IDField>=0 and (IDField - rs.fields.count<=0) then
        Response.Write "<td width='1%' align='center'><b><font color='#666666' size='-1'>删</font></b></td>"
        if  trim(httpstr)<>"0" then Response.Write "<td width='1%'><b><font color='#666666' size='-1'>修</font></b></td>"
       end if
      end if
      Response.Write  "</tr>"
      '写入字段信息
      dim RecordNum,FieldNum
      for RecordNum=0 to PageSize-1 '?????????????????
       Response.Write  "<tr bgcolor='#FFFFFF'>"
       Response.Write  "<td><font size='-1'>" & RecordNum +1+(PageNum-1)*PageSize  & "</font></td>"
       for FieldNum=beginField to EndField '写入字段值     
        if Trim(rs.Fields(FieldNum).Value)="" or Isnull(rs.Fields(FieldNum).Value) then
          Response.Write "<td>&nbsp;</td>"
         else
          Response.Write  "<td><font size='-1'>&nbsp;" & Trim(rs.Fields(FieldNum).Value) & "</font></td>"
        end if
       next
       if Isnumeric(IDfield) then '复选框处理
        if IDField>=0 or (IDField - rs.fields.count<=0) then
         Response.Write "<td><input type='checkbox' name='IDfield' value='"& rs.Fields(IDfield).Value &"'></td>"
         if  trim(httpstr)<>"0" then Response.Write "<td><font size='-1'><a href='" & httpstr & "?IDField="& rs.Fields(IDfield).Value &"'>改</a></font></td>"
        end if
       end if
       Response.Write  "</tr>"
       rs.MoveNext
       if rs.eof then exit for '最后不到一整页时,也跳出
      next
      Response.Write "</table>"
    end if
  end if
  rs.Close
  conn.Close
  set rs=nothing
  set conn=nothing
  Err.Clear
  DataGrid=PageNum 
 end function
'=========================================================================================================================================================
public function DoubleDataGrid(SqlStr,ConnStr,PageSize,PageNum,beginField,EndField,IDField,HttpStr,SSqlStr,SbeginField,SEndField,RelationFieldStr,ForeignFieldNum,AddWhere,OrderByStr)'主从表格式显示数据
  'DoubleDataGrid功能:
  '  将数据以表格形式显出来,
  ' 根据需要可能确定显示的字段,
  ' 页号,每页显示的记录数
  ' 复选框绑定的字段
  ' 修改数据时所连接到的设定的网页,传递的参数名是Idfield
 
  '调用实例 page=DoubleDataGrid("SELECT * FROM mater_bcode","DSN=clkdb;UID=sa;PWD=passed",10,20,2,50,"Null","http://www.clkhome/mater_code1/tools/aaa.asp","SELECT  price AS 价格, Num AS 数量, MaterDate AS 日期 FROM mater_price",0,"max","mater_id",0,"y","NUll")


 
  '参数说明
  'sqlstr: 将要查询的sql语句
  'connstr: 数据库连接字符串
  'PageSize: 数据集每页的记录数
  'PageNum: 数据集中将要显示的页号
  'beginField:在记录集中开始显示的字段位置
  'EndField: 在记录集中结束显示的字段位置
  'IDField: 用于给复选框的value赋值的字段在记录集中的位置,可以用于提交到其它页,其它页做处理的依据
  '           如果IDField<0 or IDField> rs.fields.count或不是数字 则不显示复选框
  'HttpStr 修改记录时连接到的网页,传递的是IDField的值,如果 httpstr="0"则不显示修改连接
 
 
  'SSqlStr: 从表的SQl语句,不能句括Order by 子句,因为要通过类似于 "where 子表.字段=主表.字段"的方式将两个表联系起来,
  '   而where必须在ordey by子句这前使用,才能符合sql语法
  'SbeginField: 从表中在记录集中开始显示的字段位置
  'SEndField:  从表中在记录集中结束显示的字段位置
  'RelationFieldStr: 从表中,与主表的关联的字段名,使用方式如 Where RelationFieldStr= 'ABC'
  'ForeignFieldNum: 主表中,与从表关联的字段在主表记录是中的位置,
  '     之所以用以位置(index)而不直接写确定的值,是因为当主表的记录集movenext后,相应的值要变以
  '     生成对应的从表记录集,使用方式如 Where RelationFieldStr= Rs(ForeignFieldNum)
  'AddWhere: 确定将SSqlStr与生成的关联字符串("where 子表.字段=主表.字段")连接时是用 "Where "还是"And"
  '   AddWhere<>"Null"时用"where"  AddWhere="Null"时用"and"  
  'OrderByStr: 从表的SQl语句的OrderByStr子句
  '返回值, 返回的是记录集的当前页号
 
 
  on error resume next
  dim conn,rs
  set conn=server.CreateObject ("adodb

[1] [2] [3] 下一页

 
【相关文章:】
没有相关文章

发表评论】【打印此文】【关闭窗口】【点击数:
★好玩的休闲小游戏★
网友评论:
数据载入中,请稍后……