欢迎光临
我们一直在努力

ASP+vbscript写的万能查询表达式生成器-ASP教程,ASP应用

建站超值云服务器,限时71元/月

<!–查询器2.0

使用方法:

在<head></head>之间加以下代码,(代码自编),以解决多库公共连接字段或有重复字段名时的处理(得到字段名的全称)

<script language="vbscript">

<!– 用于获得公共字段的全称的函数

function allfld(fld)

if fld="工具编号" then

allfld="工具请领单.工具编号"

else

allfld=fld

end if

end function</script>

在要查询的列表后面加:<!–#include file="seeker.asp"-->

在sql语句后右加:if request("s1")<>"" then sql=sql&" and "&request("s1"),这一句就是与你的程序连接上的关键。

接下来就是你的调试,轻松就ok!

作者:湖北十堰市东风有限公司刃量具厂装备管理部 肖述治

邮箱:haohia@sina.com 电话:0719-8243634

–>

<form method="post" name="exprform" action=<%=request.servervariables("document_name")%> >

<p align="right">

<input type="text" name="txtgo" size="3">

<input type="button" name="btngo" value="转到">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

第<input type="text" name="txtpage" size="3" value=<%=request("page")%>>页,

共<input type="text" name="txtmaxpage" size="3" value=<%=rs.pagecount%>>页&nbsp;

<%if page>1 then%>

<input type="button" name="firstpage" value="第一页">

<input type="button" name="prepage" value="上一页">

<%end if%>

<%if page<>rs.pagecount then%>

<input type="button" name="nextpage" value="下一页">

<input type="button" name="lastpage" value="最后一页">

<%end if%>

<table height="91" ><tr><td>

<script language="vbscript">

<!—-脚本:表达式生成器

dim f,exp

set f=document.exprform

if trim(f.txtpage.value)="" then f.txtpage.value=1 —预置页号,当第一次访问页面时用

if cint(f.txtpage.value)>cint(f.txtmaxpage.value) then f.txtpage.value=f.txtmaxpage.value—当条件改变时,由于页数可能更改,强行改变页号

sub btngo_onclick —转到指定的页面事件

if f.txtgo.value="" then msgbox "没有指定页数":exit sub

if not isnumeric(f.txtgo.value) then msgbox "不是数值":exit sub

if cint(f.txtgo.value)>cint(f.txtmaxpage.value) or cint(f.txtgo.value)<1 then msgbox "页号超出范围":exit sub

f.action=f.action&"?page="&f.txtgo.value

f.submit

end sub

sub firstpage_onclick —第一页按钮事件

f.action=f.action&"?page=1"

f.submit

end sub

sub prepage_onclick —上一页按钮事件

f.action=f.action&"?page="&(f.txtpage.value-1)

f.submit

end sub

sub nextpage_onclick —下一页按钮事件

f.action=f.action&"?page="&(f.txtpage.value+1)

f.submit

end sub

sub lastpage_onclick —最后一页按钮事件

f.action=f.action&"?page="&(f.txtmaxpage.value)

f.submit

end sub

sub fld_onchange———字段改变事件

f.sx.value=f.fld.options(f.fld.selectedindex).name—将字段的类型存入文本框sx(name里是从服务器获得的)

f.s1.value=f.fld.options(f.fld.selectedindex).value

f.opt.style.display=""

f.valu.style.display=""

f.btnand.style.display=""

f.btnor.style.display=""

f.btnend.style.display=""

end sub

sub fld_onblur

call fld_onchange

end sub

sub opt_onchange —操作符改变事件

end sub

sub valu_onblur —失去焦点事件

if f.sx.value=135 and (not isdate(f.valu.value)) then

msgbox "取值框输入的日期格式不正确,请重新输入",vbexclamation,"操作错误!!!"

end if

if (f.sx.value=2 or f.sx.value=3 or f.sx.value=4 or f.sx.value=5) and (not isnumeric(f.valu.value)) then

msgbox "取值框输入的不是数值,请重新输入",vbexclamation,"操作错误!!!"

exit sub

end if

end sub

sub s1_onchange—文本条件框改变事件

f.tj.style.display=""

end sub

sub btnand_onclick

if valid()=true then

exp=exp&exp0()&" and "

call viewexpr

end if

end sub

sub btnor_onclick

if valid()=true then

exp=exp&exp0()&" or "

call viewexpr

end if

end sub

sub btnend_onclick

if valid()=true then

exp=exp&exp0()&sortexpr()

f.fld.style.display="none"

f.opt.style.display="none"

f.valu.style.display="none"

f.btnand.style.display="none"

f.btnor.style.display="none"

f.btnend.style.display="none"

f.tj.style.display=""

call viewexpr

end if

end sub

function valid() ——-验证输入值的正确性

if f.sx.value=135 and (not isdate(f.valu.value)) then

msgbox "取值框输入的日期格式不正确,请重新输入",vbexclamation,"操作错误!!!"

valid=false

exit function

end if

if (f.sx.value=2 or f.sx.value=3 or f.sx.value=4 or f.sx.value=5) and (not isnumeric(f.valu.value)) then

msgbox "取值框输入的不是数值,请重新输入",vbexclamation,"操作错误!!!"

valid=false

exit function

end if

if trim(f.valu.value)="" then

msgbox "取值框不能为空!",vbinformation,"操作错误!!!"

valid=false

exit function

end if

valid=true

end function

function exp0()—生成表达式段落

select case f.sx.value —根据字段属性选择生成表达式

case 202—字符型字段

exp0=allfld(f.fld.value)&f.opt.value&""&f.valu.value&"" —allfld()为自定义函数,以获得完整字段名

case 2,3,4,5—数值型字段

exp0=allfld(f.fld.value)&f.opt.value&f.valu.value

case 135—日期型字段

exp0=allfld(f.fld.value)&f.opt.value&"#"&f.valu.value&"#"

case else

exp0=allfld(f.fld.value)&f.opt.value&""&f.valu.value&""

end select

end function

function sortexpr()—排序表达式

if trim(f.fldsort.value)<>"无" then

sortexpr=" order by "&allfld(f.fldsort.value)&" "&f.udsort.value

else

sortexpr=""

end if

end function

sub viewexpr—在条件框显示表达式

f.s1.value=exp

end sub

sub reset_onclick—清除查询条件

exp=""

f.s1.value=""

call viewexpr

f.fld.style.display=""

f.tj.style.display="none"

end sub

sub tj_onclick—提交查询条件

f.submit

end sub

sub allbtn_onclick—清除条件,显示全部记录

exp=""

f.s1.value=""

f.submit

end sub

sub btnhelp_onclick—使用说明

content="———————–使用说明———————"

content=content+vbcrlf+"  查询表达式生成器是按sql语言规范设计,用户只需按一定的操作程序即可自动生成标准的sql语句,并能被服务器接受。"

content=content+vbcrlf+"条件表达式操作步骤:"

content=content+vbcrlf+"1、从字段下拉框选取字段。这时运算符下拉框、取值框、操作符按钮显示出来;"

content=content+vbcrlf+"2、从运算符下拉框选择恰当的运算符"

content=content+vbcrlf+"3、在取值框输入要查找的字符或数字或日期"

content=content+vbcrlf+"4、若要并列条件请按“而且”,若要任选条件请按“或者”,完成了条件请按“结束”"

content=content+vbcrlf+"5、当按下“结束”按钮后,在条件文本框下部弹出“提交表达式”,若要重写请按“重置”,检查无误后即可按下提交。"

content=content+vbcrlf+"6、当生成的表达式达不到要求时可以直接对条件文本框内的表达式进行修改,改完后按“提交表达式”发送到服务器端"

content=content+vbcrlf+"排序的操作:"

content=content+vbcrlf+"1、排序表达式必须接在条件表达式的后面,但在操作时可以在条件表达式设置之前预先设置,生成器会自动将排序表达式放在条件表达式的后面"

content=content+vbcrlf+"2、如果只排序,不要查询条件时,请设一个伪条件:字段不等于一个不可能的值,按下“结束”按钮"

content=content+vbcrlf+"3、按“提交表达式”,完成排序"

content=content+vbcrlf+"4、看完“使用说明”后请按“重置”"

f.s1.value=content

end sub

–>

</script>

查询表达式生成器:</td></tr>

<tr><td>

<table border=1 name="seewin" style="display" bordercolorlight="#000000" cellspacing="1" bordercolordark="#ffffff"><tr><td bgcolor="#c0c0c0">

<select size="1" name="fld" value=<%=request.form("fld")%>>

<% if request.form("fld")<>"" then response.write "<option selected name=sel>"&request.form("fld")&"</option>"

for each opt in rs.fields

zdm=opt.name

zdlx=rs(zdm).type

response.write "<option value="&zdm&" name="&zdlx&">"&zdm&"</option>"

next

%>

</select>

<input type="text" size=5 name="sx" style="display:none">

<select size="1" name="opt" style="display:none" value=<%=request.form("opt")%>>

<option value="=" selected>等于</option>

<option value="=">等于</option>

<option value="<>">不等于</option>

<option value=">">大于</option>

<option value=">=">大于或等于</option>

<option value="<">小于</option>

<option value="<=">小于或等于</option>

<option value=" like ">匹配</option>

</select>

<input type="text" name="valu" size="26" style="display:none" onfocus="jscript:this.value=;" value=<%=request.form("valu")%> >

<input type="button" name="btnand" style="display:none" value="而且">

<input type="button" name="btnor" style="display:none" value="或者">

<input type="button" name="btnend" style="display:none" value="结束">

</td></tr>

<tr><td bgcolor="#e0e8f0"><!–表达式显示区–>

<textarea rows="3" cols="80" name="s1" style="display"><%=request.form("s1")%></textarea><br>

</td>

<tr><td>

<p align="right"><!–排序区–> 排序按<select size="1" name="fldsort">

<option value="无" selected>(无)</option>

<%

for each opt in rs.fields

zdm=opt.name

response.write "<option value="&zdm&">"&zdm&"</option>"

next

%>

</select>

<select size="1" name="udsort"><option value="" selected>从小到大</option><option value=" desc">从大到小</option></select>

</td>

<tr><td><!–提交重置区–>

<input type="button" value="使用说明" name="btnhelp">

<input type="button" value="重置" name="reset">

<input type="button" value="全部记录" name="allbtn">

<input type="button" value="提交表达式" name="tj" style="display:none"><br>

</td></tr>

</table>

</td></tr></form></table>

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » ASP+vbscript写的万能查询表达式生成器-ASP教程,ASP应用
分享到: 更多 (0)