<!--#include file="inc/config.asp"-->
<!--#include file="inc/conn.asp"-->
<!--#include file="inc/right.asp"-->
<%
action=Request("action")
cid=Request.QueryString("cid")
if cid="" or not isnumeric(cid) then
	response.write("<script>alert('参数错误!');location='index.asp';</script>")
	response.end
end if
sno=session("sno")
sname=session("sname")
if cid<>"" and sno<>"" then
if action="yes" Then

	set rsc=conn.execute("select title,xx2,xkrs from Info where id="&cid&"")
	if not (rsc.bof and rsc.eof) then 
    cname=rsc("title")
	if rsc("xx2")-rsc("xkrs")=0 then
      response.write"<script language=JavaScript>alert('该课程人数已满，不能再选！');"
      response.write"location.href='index.asp'</script>"
	response.end
	end if
	rsc.close
	Set rsc=nothing
	end if

	set rs2=conn.execute("select sno,yn from Result where sno='"&sno&"' and yn='1'")
	if not (rs2.bof and rs2.eof) then 
      response.write"<script language=JavaScript>alert('您已选择课程，不能再选！');"
      response.write"location.href='index.asp'</script>"
	rs2.close
	Set rs2=nothing
	response.end
	end if

   set rs=server.createobject("adodb.recordset")
   sql="insert into Result(sno,sname,cid,cname,yn,addtime) values('"&sno&"','"&sname&"','"&cid&"','"&cname&"','1',now())"
   conn.execute(sql)
   sql="update Info set xkrs=xkrs+1 where id="&cid
   conn.execute(sql)
   response.write"<script language=JavaScript>alert('选课成功，返回首页！');"
   response.write"location.href='index.asp'</script>"
end if
rs.close
Set rs=nothing
end if
%>