变量 vote_user 的值已经在其它文件中定义为数据表的名字 vote_user
变量 objConn 是数据库链接,已经成功链接了数据库
dim objRs 'ADODB.RecordSet 实例
dim objCmd 'ADODB.Command 实例
dim objPm 'ADODB.Parameter 实例
dim strSubmit '表单 提交按钮 变量
dim strUname '表单 姓名 变量
dim strUcardno '表单 身份证号码 变量
dim strUgender '表单 性别 变量
dim strUparty '表单 政治面貌 变量
dim blnCanreg '是否可以注册标志
dim strSql 'SQL语句
dim strUsertype '1=选民 2=候选人 3=管理员
dim intMaxuid '已经注册用户的最大编号
dim intRegFailed '是否注册成功
dim intUid '注册成功后的id
strSubmit=Trim(Request.Form("submit"))
Set objRs=server.createObject("ADODB.RecordSet")
strSql="select id from sysobjects where name='" & vote_user & "'"
objRs.open strSql,objConn,1,1
'If Err.number<>0 Then '表存在
If objRs.bof or objRs.eof then '表不存在
Response.Write("数据表 " & vote_user & " 不存在,请检查数据库 " & Chr(13) )
Err.clear
objRs.close
set objRs=nothing
Else
blnCanreg=false
If strSubmit<>"" Then '提交表单
'/********************************************************************/
strUname=Replace(Trim(Request.Form("username")),"'","")
strUcardno=Replace(Trim(Request.Form("idcard")),"'","")
strUgender=Replace(Trim(Request.Form("gender")),"'","")
strUparty=Replace(Trim(Request.Form("party")),"'","")
'用户重复性判断
Set objRs=server.createObject("ADODB.RecordSet")
strSql="select uname,ucardno from " & vote_user & " where uname='" & strUname & "'"
strSql= strSql & " and ucardno='" & strUcardno & "'"
objRs.open strSql,objConn,1,1
'Response.Write(strSql)
'姓名和身份证号码判断
If strUname="" Then
Response.Write("姓名不能为空 ")
ElseIf strUcardno="" Then
Response.Write("身份证号码不能为空 ")
Elseif Not (objRs.eof or objRs.bof) Then
Response.Write("您已经注册过了,请直接登录。")
blnCanreg=false
ElseIf not ( Len(strUcardno)=15 or Len(strUcardno)=18 ) Then
Response.Write("身份证号码有误 ")
ElseIf strUgender="" Then
Response.Write("请选择您的性别 ")
ElseIf strUparty="" Then
Response.Write("请选择您的政治面貌 ")
else
blnCanreg=true
'Response.Write( uname & "可以注册")
End If
objRs.close
set objRs=nothing
'注册开始
strUsertype=1
intRegFailed=1
intUid=0
if blnCanreg then
Response.Write("注册中,请等待... <br /><br />")
'strSql=strSql & "insert into " & vote_user & "(tid,uname,ucardno,ugender,party,uifvote,uifvote) "
strSql=strSql & "values('" & strUsertype & "','" & strUname & "',"
strSql=strSql & "'" & strUcardno & "','" & strUgender & "','" & strUparty & "',"
strSql=strSql & "0,0)"
'Response.Write(strSql)
'objConn.execute strSql
'strSql=strSql & "insert into " & vote_user & "(tid,uname,ucardno,ugender,party,uifvote,uifvote) "
'strSql=strSql & "values('" & strUsertype & "','?,?,?,?,"
'strSql=strSql & "'0','0')"
Set objRs=server.createObject("ADODB.RecordSet")
strSql="select max(uid) as mid from " & vote_user
objRs.open strSql,objConn,1,1
if Not (objRs.eof or objRs.bof) Then
intMaxuid=objRs("mid")+1
end if
objRs.close
set objRs=nothing
'Response.Write(strSql)
'Response.Write(intMaxuid)
Set objCmd=server.createObject("ADODB.Command")
with objCmd
.ActiveConnection=objConn
.CommandText = "vote_pcd_adduser"
.CommandType = adCmdStoredProc
.Parameters.Append .CreateParameter("Return_Value",adInteger,adParamReturnValue)
.Parameters.Append .CreateParameter("@uid",adInteger,adParamInput)
.Parameters.Append .CreateParameter("@tid",adInteger,adParamInput)
.Parameters.Append .CreateParameter("@uname",adVarChar,adParamInput,20)
.Parameters.Append .CreateParameter("@ucardno",adVarChar,adParamInput,18)
.Parameters.Append .CreateParameter("@ugender",adChar,adParamInput)
.Parameters.Append .CreateParameter("@uparty",adVarChar,adParamInput,10)
.Parameters.Append .CreateParameter("@uifvote",adInteger,adParamInput)
.Parameters.Append .CreateParameter("@uifreg",adInteger,adParamInput)
.Parameters.Append .CreateParameter("@userid",adInteger,adParamOutput)
.Parameters("@uid") = intMaxuid
.Parameters("@tid") = strUsertype
.Parameters("@uname") = strUname
.Parameters("@ucardno") = strUcardno
.Parameters("@ugender") = strUgender
.Parameters("@uparty") = strUparty
.Parameters("@uifvote") = 0
.Parameters("@uifreg") = 0
.Execute
intRegFailed= .Parameters("Return_Value")
intUid = .Parameters("@userid")
Response.Write(.Parameters("@uid")) & "<br />"
Response.Write(.Parameters("@tid")) & "<br />"
Response.Write(.Parameters("@ucardno")) & "<br />"
Response.Write(.Parameters("@ugender")) & "<br />"
Response.Write(.Parameters("@uparty")) & "<br />"
Response.Write(.Parameters("@uifvote")) & "<br />"
Response.Write(.Parameters("@uifreg")) & "<br />"
Response.Write(.Parameters("@userid")) & "<br />"
Response.Write("返回值: " & intRegFailed ) & "<br />"
Response.Write("返回的新用户id: " & intUid) & "<br />"
end with
if intRegFailed=0 then
Response.Write("恭喜您: " & objCmd.Parameters("@uname") & ", 注册成功,您的编号是" & intUid)
else
Response.Write("您已经注册了")
end if
end if 'blnCanreg
End If ' submit
End If 'vote_user exists
%>