<SCRIPT language="javascript">
function backward()
{
      history.back();
}
function teacher()
{
window.location="UntitledFrameset-5.htm";
}
</SCRIPT>
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>添加成功</title>
</head>

<body>
<%!
void randomNum(int a[],int i,int j)
{
 a[i]=1+(int)(Math.random()*j);
for(int c=i-1;c>=0;c--)
    {
	if(a[i]==a[c])
	randomNum(a,i,j);
	}
}
%>
<%
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
String driver = "jdbc:microsoft:sqlserver://localhost:1433";
String user="jsp";
String password="820728";
Connection conn = DriverManager.getConnection(driver,"","");
Statement stmt = conn.createStatement();
//读取表单内容
int shijuanbianhao=Integer.parseInt(request.getParameter("shijuanbianhao"));
String sql="SELECT * FROM shijuan where shijuanbianhao="+shijuanbianhao;

ResultSet rs=stmt.executeQuery(sql);
if(rs.next())
{%>
<p>本试卷编号已经存在，请重新选择填写编号。</p>
<p><input type="button" name="fafa" value="返回上一步" onclick="backward()"></p>
<%}
else{
int xuanzeshumu=Integer.parseInt(request.getParameter("xuanzeshumu"));
int xuanzefenzhi=Integer.parseInt(request.getParameter("xuanzefenzhi"));
int panduanshumu=Integer.parseInt(request.getParameter("panduanshumu"));
int panduanfenzhi=Integer.parseInt(request.getParameter("panduanfenzhi"));
int zhuguanshumu=Integer.parseInt(request.getParameter("zhuguanshumu"));
int zhuguanfenzhi=0;
int kaoshishijian=Integer.parseInt(request.getParameter("kaoshishijian"));
int i=0;
int j[]=new int [30];

for(i=0;i<xuanzeshumu;i++)
{
  randomNum(j,i,30);
  sql="SELECT * from xuanzeti where id="+j[i];
  rs=stmt.executeQuery(sql);
//  while(rs.next()){
rs.next();
int id=Integer.parseInt(rs.getString("id"));
String timu=rs.getString("tigan");
String timuleixing="xuanzeti";
String sql1="insert into shijuan values('"+shijuanbianhao+"','"+timu+"','"+xuanzefenzhi+"','"+timuleixing+"','"+id+"','"+kaoshishijian+"')";
stmt.executeUpdate(sql1);
//}
}

for(i=0;i<panduanshumu;i++)
{
randomNum(j,i,20);
 sql="SELECT * from panduanti where id="+j[i];
 rs=stmt.executeQuery(sql);
rs.next();
int id=Integer.parseInt(rs.getString("id"));
String timu=rs.getString("tigan");
String timuleixing="panduanti";
String sql1="insert into shijuan values('"+shijuanbianhao+"','"+timu+"','"+panduanfenzhi+"','"+timuleixing+"','"+id+"','"+kaoshishijian+"')";
stmt.executeUpdate(sql1);
}

for(i=0;i<zhuguanshumu;i++)
{
randomNum(j,i,20);
  sql="SELECT * from panduanti where id="+j[i];
  rs=stmt.executeQuery(sql);
//  while(rs.next()){
rs.next();
int id=Integer.parseInt(rs.getString("id"));
String timu=rs.getString("tigan");
String timuleixing="zhuguanti";
zhuguanfenzhi=(100-xuanzefenzhi*xuanzeshumu-panduanfenzhi*panduanshumu)/zhuguanshumu;
String sql1="insert into shijuan values('"+shijuanbianhao+"','"+timu+"','"+zhuguanfenzhi+"','"+timuleixing+"','"+id+"','"+kaoshishijian+"')";
stmt.executeUpdate(sql1);
}
rs.close();
stmt.close();
conn.close();
}
%>
<h1>试卷添加成功</h1>
<p></p>
</body>
</html>
