自定义每次添加的记录数,包含客户端的数据检查
类别: ASP教程
当我们有时在添加新记录时,一次添加一条的操作很不方便,尤其是在录入大批量的数据时,比如:学生成绩。
下面是我给一个客户做的自定义添加记录数(即:用户可以自己选择当前一次添加多少条记录),并用vb函数对每个需要输入的文本框做了检查。
下面是源程序:
<%@ Language=VBScript %>
<%
\'文件名:dd_product_price.asp
\'功能:添加商品价格详细资料
\'说明:后台程序
\'程序:小白
\'时间:2002-5-15
\'更新:
\'更新说明:
\'公司:坐标公司
\'主页:www.zbhn.com
%>
<HTML>
<HEAD>
<title> <%=application("web_name")%> --->添加商品价格资料</title>
<META NAME="GENERATOR" Content="Microsoft FrontPage 4.0">
<style type="text/css"> <!-- a:link {color:darkslateblue;text-decoration:none}
a:visited {color:darkslateblue;text-decoration:无}
a:hover {color:brown;text-decoration:底线}
input.radio {background: navyblue; color:#000000}
font { font-size: 9pt; line-height: 13pt; FONT-FAMILY:MS Shell Dlg,Tahoma}
td { font-size: 9pt; line-height: 13pt; FONT-FAMILY:MS Shell Dlg,Tahoma}
textarea { BACKGROUND-COLOR: #e8e8e8; BORDER-BOTTOM: 1px double; BORDER-LEFT: 1px double; BORDER-RIGHT: 1px double; BORDER-TOP: 1px double; COLOR: #000000;; font-size: 9pt ;FONT-FAMILY:MS Shell Dlg,Tahoma}
input { BACKGROUND-COLOR: #e8e8e8; BORDER-BOTTOM: 1px double; BORDER-LEFT: 1px double; BORDER-RIGHT: 1px double; BORDER-TOP: 1px double; COLOR: #000000;; font-size: 9pt; FONT-FAMILY:"MS Shell Dlg", "Tahoma"; background-position: center}
--></style>
<SCRIPT LANGUAGE="javascript" src="js/refuse_visit.js"></SCRIPT>
<SCRIPT LANGUAGE="javascript" src="js/max_window.js"></SCRIPT>
</HEAD>
<body>
<!--#include file="sjkpzwj/ytxx_conn.inc"-->
<p align="center">
<%
dim url
url=request.ServerVariables("SCRIPT_NAME")
on error resume next
record=request.QueryString("record")
if record="" then
record=1
end if
record=cint(record)
if Err.number <> 0 then
record=1
Response.Write "操作不当,请下次小心点"
end if
if Request.ServerVariables ("Request_Method")="POST" then
\'如果提交过来的是post方法,则添加记录到数据库
dim text1(20),text2(20),text3(20),text4(20)
\'______________________
sub gave_value(text,xx)
on error resume next
count=0
for each item in Request.Form(text)
xx(count)=item
count=count+1
next
if Err.number <> 0 then
response.Write "sub err:"& Err.Description
end if
end sub
on error resume next
\'____________________
call gave_value("text1",text1)
call gave_value("text2",text2)
call gave_value("text3",text3)
call gave_value("text4",text4)
if Err.number <> 0 then
response.Write "call sub err:"&Err.Description
end if
\'%%%%%%%%%%%%%%%%%%%%%%%%
on error resume next
if Err.number <> 0 then
response.Write "show text1 err:"&Err.Description
Response.End
end if
\'%%%%%%%%%%%%%%%%%%
%>
<center>添加商品价格资料 </center>
<%
set Rs=server.CreateObject ("ADODB.Recordset")
on error resume next
Rs.Open "select * from price where 1=2",str_connection,1,3
\'************************************
if Err.number <> 0 then
Response.Write "Error---><br>"&Err.Description &"<br><font color=red>;Please contact with the <font color=red> web master</font>!</font>"
Rs.Close
set Rs=nothing
Response.End
end if
\'**************************************
\'连接数据库、打开数据表成功后
\'______使用addnew方法添加记录________
on error resume next
for jj=0 to record-1
Rs.AddNew
rs(1)=text1(jj)
rs(2)=text2(jj)
rs(3)=text3(jj)
rs(4)=text4(jj)
Rs.Update
next
Rs.Close
set Rs=nothing
if Err.number <> 0 then
\'如果提交失败
Response.Write "Error---><br>"&Err.Description &"<br><font color=red>;Please contact our administrators!</font>"
Response.End
end if
\'______________________________________
dim pass
pass=true
if pass=true then
%>
<SCRIPT LANGUAGE=javascript>
<!--
window.alert ("提交成功,请返回")
if(window.opener !=null){
window.opener.location.reload()
}
self.location ="<%=url%>?record=<%=record%>"
//-->
</SCRIPT>
<%
end if
Response.End
end if \'end of // if ....="post" then
%>
<font size="3" color="#ff0000"><b>添加<font color="#ff8844" size="9">→产品价目←</font>的资料</b></font>
<form name=form1 ID="Form1">
<TABLE style="BORDER-COLLAPSE: collapse" cellSpacing="1" cellPadding="1" width="100%" border="0" ID="Table1">
<TBODY>
<TR bgColor="#9a007b">
<TD class="unnamed1" width="14%" height="22">
<DIV align="center"><font color="#ffffff">产品名称</font></DIV>
</TD>
<TD class="unnamed1" width="14%" height="22">
<DIV align="center"><font color="#ffffff">单位</font></DIV>
</TD>
<TD class="unnamed1" width="14%" height="22">
<DIV align="center"><font color="#ffffff">出厂价(元)</font></DIV>
</TD>
<TD class="unnamed1" width="14%" height="22">
<DIV align="center"><font color="#ffffff">包装形式</font></DIV>
</TD>
</TR>
<% for i=0 to record-1%>
<TR bgColor="#fdd2f4">
<TD class="unnamed1" width="14%" height="22">
<div align="center">
<INPUT type="text" tabIndex=<%=i * record +1%> name="Text1" size="20" ID="Text1">
</div>
</TD>
<TD class="unnamed1" width="14%" height="22">
<div align="center">
<INPUT type="text" tabIndex=<%=i * record + 2%> name="text2" size="20" ID="Text2">
</div>
</TD>
<TD class="unnamed1" width="14%" height="22">
<div align="center">
<INPUT type="text" tabIndex=<%=i * record + 3%> name="text3" size="20" ID="Text3">
</div>
</TD>
<TD class="unnamed1" width="14%" height="22" >
<div align="center">
<INPUT tabIndex=<%=i * record + 4%> type="text" name="text4" size="20" ID="Text4">
</div>
</TD>
</TR>
<%next%>
<TR bgColor="#fdd2f4">
<TD class="unnamed1" width="100%" height="22" colspan="4">请选择:一次添加
<SELECT id="Select1" name="Select1" size="1"
onchange="javascript:self.location=this.options[this.selectedIndex].value" >
<OPTION selected value="<%=url%>?record=1">1</OPTION>
<OPTION value="<%=url%>?record=1">1</OPTION>
<option value="<%=url%>?record=2">2</option>
<option value="<%=url%>?record=3">3</option>
<option value="<%=url%>?record=4">4</option>
<option value="<%=url%>?record=5">5</option>
<option value="<%=url%>?record=6">6</option>
<option value="<%=url%>?record=7">7</option>
<option value="<%=url%>?record=8">8</option>
<option value="<%=url%>?record=9">9</option>
<option value="<%=url%>?record=10">10</option>
<option value="<%=url%>?record=15">15</option>
<option value="<%=url%>?record=20">20</option>
</SELECT>
条记录
<INPUT id="Submit1" type="button" onclick="notcheck()" value="提交" name="Submit1">
<INPUT type="reset" value="Reset" ID="Reset1" NAME="Reset1">
当前操作:添加<font color=red><%=record%></font>条记录 </TD>
</TR>
</TBODY>
</TABLE>
</form>
<SCRIPT LANGUAGE=vbscript >
<!--
\'此段代码由小白源创
\'如有转载,请勿删除此行代码,谢谢
\'对于只熟悉js的朋友
\'做相应的代码转换,就可以转换为js函数
\'我在这里就略过了
\'email:xiaobai@17560.net
\'********************************************
\'
function notcheck() \'1
dim pass
pass=true
on error resume next \'2
for k=0 to document.all.length-1
if UCase(document.all (k).tagName) ="INPUT" then \'444
\'判断是否为input元素
set input1=document.all (k)
If UCase(input1.Type) = "TEXT" Then \'如果是可输入的文本框
if input1.value="" then \'6
msgbox "请在光标处输入资料"
input1.focus()
pass=false
exit for
end if \'/66
end if
end if \'/444
next
if Err.number > 0 then
pass=false
\'表示异常发生
\'alert("异常发生")
end if
if pass=true then
form1.action="<%=url%>?record=<%=record%>"
form1.method="post"
form1.submit()
end if
end function \'11111
//-->
</SCRIPT>
</body>
</HTML>
下面是我给一个客户做的自定义添加记录数(即:用户可以自己选择当前一次添加多少条记录),并用vb函数对每个需要输入的文本框做了检查。
下面是源程序:
<%@ Language=VBScript %>
<%
\'文件名:dd_product_price.asp
\'功能:添加商品价格详细资料
\'说明:后台程序
\'程序:小白
\'时间:2002-5-15
\'更新:
\'更新说明:
\'公司:坐标公司
\'主页:www.zbhn.com
%>
<HTML>
<HEAD>
<title> <%=application("web_name")%> --->添加商品价格资料</title>
<META NAME="GENERATOR" Content="Microsoft FrontPage 4.0">
<style type="text/css"> <!-- a:link {color:darkslateblue;text-decoration:none}
a:visited {color:darkslateblue;text-decoration:无}
a:hover {color:brown;text-decoration:底线}
input.radio {background: navyblue; color:#000000}
font { font-size: 9pt; line-height: 13pt; FONT-FAMILY:MS Shell Dlg,Tahoma}
td { font-size: 9pt; line-height: 13pt; FONT-FAMILY:MS Shell Dlg,Tahoma}
textarea { BACKGROUND-COLOR: #e8e8e8; BORDER-BOTTOM: 1px double; BORDER-LEFT: 1px double; BORDER-RIGHT: 1px double; BORDER-TOP: 1px double; COLOR: #000000;; font-size: 9pt ;FONT-FAMILY:MS Shell Dlg,Tahoma}
input { BACKGROUND-COLOR: #e8e8e8; BORDER-BOTTOM: 1px double; BORDER-LEFT: 1px double; BORDER-RIGHT: 1px double; BORDER-TOP: 1px double; COLOR: #000000;; font-size: 9pt; FONT-FAMILY:"MS Shell Dlg", "Tahoma"; background-position: center}
--></style>
<SCRIPT LANGUAGE="javascript" src="js/refuse_visit.js"></SCRIPT>
<SCRIPT LANGUAGE="javascript" src="js/max_window.js"></SCRIPT>
</HEAD>
<body>
<!--#include file="sjkpzwj/ytxx_conn.inc"-->
<p align="center">
<%
dim url
url=request.ServerVariables("SCRIPT_NAME")
on error resume next
record=request.QueryString("record")
if record="" then
record=1
end if
record=cint(record)
if Err.number <> 0 then
record=1
Response.Write "操作不当,请下次小心点"
end if
if Request.ServerVariables ("Request_Method")="POST" then
\'如果提交过来的是post方法,则添加记录到数据库
dim text1(20),text2(20),text3(20),text4(20)
\'______________________
sub gave_value(text,xx)
on error resume next
count=0
for each item in Request.Form(text)
xx(count)=item
count=count+1
next
if Err.number <> 0 then
response.Write "sub err:"& Err.Description
end if
end sub
on error resume next
\'____________________
call gave_value("text1",text1)
call gave_value("text2",text2)
call gave_value("text3",text3)
call gave_value("text4",text4)
if Err.number <> 0 then
response.Write "call sub err:"&Err.Description
end if
\'%%%%%%%%%%%%%%%%%%%%%%%%
on error resume next
if Err.number <> 0 then
response.Write "show text1 err:"&Err.Description
Response.End
end if
\'%%%%%%%%%%%%%%%%%%
%>
<center>添加商品价格资料 </center>
<%
set Rs=server.CreateObject ("ADODB.Recordset")
on error resume next
Rs.Open "select * from price where 1=2",str_connection,1,3
\'************************************
if Err.number <> 0 then
Response.Write "Error---><br>"&Err.Description &"<br><font color=red>;Please contact with the <font color=red> web master</font>!</font>"
Rs.Close
set Rs=nothing
Response.End
end if
\'**************************************
\'连接数据库、打开数据表成功后
\'______使用addnew方法添加记录________
on error resume next
for jj=0 to record-1
Rs.AddNew
rs(1)=text1(jj)
rs(2)=text2(jj)
rs(3)=text3(jj)
rs(4)=text4(jj)
Rs.Update
next
Rs.Close
set Rs=nothing
if Err.number <> 0 then
\'如果提交失败
Response.Write "Error---><br>"&Err.Description &"<br><font color=red>;Please contact our administrators!</font>"
Response.End
end if
\'______________________________________
dim pass
pass=true
if pass=true then
%>
<SCRIPT LANGUAGE=javascript>
<!--
window.alert ("提交成功,请返回")
if(window.opener !=null){
window.opener.location.reload()
}
self.location ="<%=url%>?record=<%=record%>"
//-->
</SCRIPT>
<%
end if
Response.End
end if \'end of // if ....="post" then
%>
<font size="3" color="#ff0000"><b>添加<font color="#ff8844" size="9">→产品价目←</font>的资料</b></font>
<form name=form1 ID="Form1">
<TABLE style="BORDER-COLLAPSE: collapse" cellSpacing="1" cellPadding="1" width="100%" border="0" ID="Table1">
<TBODY>
<TR bgColor="#9a007b">
<TD class="unnamed1" width="14%" height="22">
<DIV align="center"><font color="#ffffff">产品名称</font></DIV>
</TD>
<TD class="unnamed1" width="14%" height="22">
<DIV align="center"><font color="#ffffff">单位</font></DIV>
</TD>
<TD class="unnamed1" width="14%" height="22">
<DIV align="center"><font color="#ffffff">出厂价(元)</font></DIV>
</TD>
<TD class="unnamed1" width="14%" height="22">
<DIV align="center"><font color="#ffffff">包装形式</font></DIV>
</TD>
</TR>
<% for i=0 to record-1%>
<TR bgColor="#fdd2f4">
<TD class="unnamed1" width="14%" height="22">
<div align="center">
<INPUT type="text" tabIndex=<%=i * record +1%> name="Text1" size="20" ID="Text1">
</div>
</TD>
<TD class="unnamed1" width="14%" height="22">
<div align="center">
<INPUT type="text" tabIndex=<%=i * record + 2%> name="text2" size="20" ID="Text2">
</div>
</TD>
<TD class="unnamed1" width="14%" height="22">
<div align="center">
<INPUT type="text" tabIndex=<%=i * record + 3%> name="text3" size="20" ID="Text3">
</div>
</TD>
<TD class="unnamed1" width="14%" height="22" >
<div align="center">
<INPUT tabIndex=<%=i * record + 4%> type="text" name="text4" size="20" ID="Text4">
</div>
</TD>
</TR>
<%next%>
<TR bgColor="#fdd2f4">
<TD class="unnamed1" width="100%" height="22" colspan="4">请选择:一次添加
<SELECT id="Select1" name="Select1" size="1"
onchange="javascript:self.location=this.options[this.selectedIndex].value" >
<OPTION selected value="<%=url%>?record=1">1</OPTION>
<OPTION value="<%=url%>?record=1">1</OPTION>
<option value="<%=url%>?record=2">2</option>
<option value="<%=url%>?record=3">3</option>
<option value="<%=url%>?record=4">4</option>
<option value="<%=url%>?record=5">5</option>
<option value="<%=url%>?record=6">6</option>
<option value="<%=url%>?record=7">7</option>
<option value="<%=url%>?record=8">8</option>
<option value="<%=url%>?record=9">9</option>
<option value="<%=url%>?record=10">10</option>
<option value="<%=url%>?record=15">15</option>
<option value="<%=url%>?record=20">20</option>
</SELECT>
条记录
<INPUT id="Submit1" type="button" onclick="notcheck()" value="提交" name="Submit1">
<INPUT type="reset" value="Reset" ID="Reset1" NAME="Reset1">
当前操作:添加<font color=red><%=record%></font>条记录 </TD>
</TR>
</TBODY>
</TABLE>
</form>
<SCRIPT LANGUAGE=vbscript >
<!--
\'此段代码由小白源创
\'如有转载,请勿删除此行代码,谢谢
\'对于只熟悉js的朋友
\'做相应的代码转换,就可以转换为js函数
\'我在这里就略过了
\'email:xiaobai@17560.net
\'********************************************
\'
function notcheck() \'1
dim pass
pass=true
on error resume next \'2
for k=0 to document.all.length-1
if UCase(document.all (k).tagName) ="INPUT" then \'444
\'判断是否为input元素
set input1=document.all (k)
If UCase(input1.Type) = "TEXT" Then \'如果是可输入的文本框
if input1.value="" then \'6
msgbox "请在光标处输入资料"
input1.focus()
pass=false
exit for
end if \'/66
end if
end if \'/444
next
if Err.number > 0 then
pass=false
\'表示异常发生
\'alert("异常发生")
end if
if pass=true then
form1.action="<%=url%>?record=<%=record%>"
form1.method="post"
form1.submit()
end if
end function \'11111
//-->
</SCRIPT>
</body>
</HTML>
- 上一篇: 操作INI文件的COM
- 下一篇: 怎样才能实现随机广告
-= 资 源 教 程 =-
文 章 搜 索