⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 updatetest_free.jsp

📁 在线考试软件。 在线考试软件详细设计说明书:说明在线测试这一模块各部分的功能和结构
💻 JSP
📖 第 1 页 / 共 2 页
字号:
<%@ page contentType="text/html; charset=gb2312" language="java"  errorPage="" %>
<%@ page import="java.sql.*"%>
<%@ page import="jinghua.*"%>
<%@ page import="java.text.*"%>
<%@ page import="java.util.*"%>
<script language="javascript">

</script>
<jsp:useBean id="DBCon" class="jinghua.JinghuaConn" scope="session">
</jsp:useBean>
<jsp:useBean id="transString" class="jinghua.TransformString" scope="page">
</jsp:useBean>
<%!
String questTypeID=null;

boolean debug=true;

int subjectID=-1;
String gradeID=null;
String JH_Tools=null;
String difficulty=null;
String knowPointID1=null;
String knowPointID2=null;
String knowPointID3=null;
String answer=null;
StringBuffer msgsb=new StringBuffer("OK");
Statement stmt=null;
String sql="";
String temp="";
int teaID=-1;
int ID=-1;//新提交试题或试卷的ID
Connection con=null;

//生成试题分类编号
public String QuestClassCode(Connection con,int SubjectID,String gradeID,
        String KnowPointID,String testpoint,String QuestType,  String PostHard){
  int num=0;
  StringBuffer bs=new StringBuffer();
  String sql="";
  try{
  Statement stmt=con.createStatement();
  sql="select count(*) as num from question where subjectid="+SubjectID+
            " and knowpointid1="+KnowPointID+
            " and questtype="+ QuestType+
            " and prehard='" +PostHard+"'";
  ResultSet rs=stmt.executeQuery(sql);
  if(rs.next()){
    num=rs.getInt(1);
  }
  num++;
  //格式化第几道题

  DecimalFormat df=new DecimalFormat("00000");
  String numNF=df.format(num);
  //NumberFormat nf = NumberFormat.getNumberInstance ();
 // nf.
  //nf.setMinimumIntegerDigits(5);//整数部分最小的长度不能少于2,如果少了则补另.
  //String numNF=nf.format(num);

  rs.close();
  stmt.close();
  sql="select subject.note as sn, knowpoint.note as kn,grade.note as gn "+
    " from subject,knowpoint,grade "+
      "  where subject.id="+SubjectID+
      " and knowpoint.id="+KnowPointID+" and grade.id="+"'"+gradeID+"'";
  stmt=con.createStatement();

  rs=stmt.executeQuery(sql);
  if (rs.next()){
    String temp;
    temp=rs.getString("sn");
    bs.append(temp);
    bs.append(rs.getString("gn") );
	df=new DecimalFormat("00");
	temp=df.format(Integer.valueOf(testpoint));
    bs.append(temp);
    bs.append(QuestType);
    bs.append(PostHard);
    bs.append(numNF);
    temp=rs.getString("kn");
    bs.append(temp);
    rs.close();
    stmt.close();
  }
  }catch(Exception se){

    msgsb.append(se.toString());
	msgsb.append("<br>"+"SQL="+sql);
  }
  return bs.toString();

}


synchronized public int submitOne(String strHtml,String answer,float mark,String difficulty,Connection con,boolean commit){
//commit=true则需要在一道题提交完后,使用commit


    strHtml=strHtml.trim();
    int tipPos=-1;
    String tip="";
    //检查格式:
    if(strHtml.startsWith("@@")){
        msgsb.append("<BR>单个试题的数据格式错误,请检查!");
        return -1;
    }else{
	//检查是否包含了文件
		
    }
    //检查答案:
    if(answer.trim()==""){
        msgsb.append("<BR>试题答案为空,请检查!"+"原试题为:<br>"+strHtml);
        return -1;
    }else if (answer.trim().length()!=1){
        msgsb.append("<BR>试题答案长度不为1,请检查!"+"原试题为:<br>"+strHtml);
        return -1;
    }else{
        String strAnswer="ABCDEFGH";
        if(strAnswer.indexOf(answer)<0){
            msgsb.append("<BR>单选试题的答案长度不为“ABCDEFGH”中的字符,请检查!"+"原试题为:<br>"+strHtml);
            return -1;
        }
    }
    //检查难易度
    if(difficulty.trim()==""){
        msgsb.append("<BR>试题难易度为空,请检查!"+"原试题为:<br>"+strHtml);
        return -1;
    }else if (difficulty.trim().length()!=1){
        msgsb.append("<BR>试题难易度长度不为1,请检查!"+"原试题为:<br>"+strHtml);
        return -1;
    }else{
        String strAnswer="ABCDE";
        if(strAnswer.indexOf(difficulty)<0){
            msgsb.append("<BR>单选难易度的答案长度不为“ABCDE”中的字符,请检查!"+"原试题为:<br>"+strHtml);
            return -1;
        }
    }

    tipPos=strHtml.indexOf("#tip");
    if(tipPos>0){
        tip=strHtml.substring(tipPos+4);//取提示
        strHtml=strHtml.substring(0,tipPos);
        tip=Tools.toSql(tip);
        strHtml=Tools.toSql(strHtml);
    }


	SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	String now=df.format(new java.util.Date());
	answer=answer.toUpperCase();
        int newID=-1;
        if(!strHtml.equals("")){
	try{
        answer.toUpperCase();
        difficulty.toUpperCase();
		//String QuestClassType=QuestClassCode(con,subjectID, gradeID, knowPointID1,1,
        //        questTypeID,   difficulty);
        String QuestClassType="";

	    if(QuestClassType==null){
		    msgsb.append(" Error:试题编号生成错误\n"+""+QuestClassType+strHtml);
	    }
		else
	    {
            //source=1为自由测试
		    sql="insert into question(QuestID,Mark,Answer,TeacherID, `question`.`Source`,"+
		        "PubDate,QuestType,SubjectID,gradenote, "+
				"KnowPointID1,KnowPointID2,KnowPointID3,PreHard,Tip) "+ "values("+
			    "'"+QuestClassType+"',"+mark+",'"+answer+"',"+teaID+",1,'"+now+"',"+
				questTypeID+","+subjectID+","+"'"+gradeID+"'"+","+knowPointID1+","+knowPointID2+","+knowPointID3+
				",'"+difficulty+"','"+tip+"'"+")";


		    con.setAutoCommit(!commit);
			stmt=con.createStatement();
			stmt.executeUpdate(sql);
		    stmt.close();

		    stmt=con.createStatement();
		    ResultSet rs=stmt.executeQuery("select LAST_INSERT_ID() as newid from question");
		    if(rs.next()){
			    newID=rs.getInt("newID");
                rs.close();
			    stmt.close();
		    }
		}
	}//end try
	catch(SQLException se){
	    System.out.print(se);
            System.out.print(sql);
            msgsb.append("试题入库出错:SQL="+sql+"\n"+se.toString());
	}catch(Exception e){
            msgsb.append("试题格式可能出错 strHtml=:"+strHtml);
	}
	if(newID!=-1 && msgsb.toString().equals("OK")  ) {
		try{//修改题干
			temp=jinghua.TransformString.TransformSelction(strHtml,newID);
			temp=Tools.toSql(temp);
            if(temp==null)
                throw new Exception("题目没有数据");

			stmt=con.createStatement();
			sql="update question set QuestText='"+temp+"' where ID="+newID;
			stmt.executeUpdate(sql);
            stmt.close();

		}
		catch(SQLException se){
		    System.out.print(se);
			msgsb.append("试题入库出错:SQL="+sql+"\n"+se.toString());

	    }
        catch(Exception se){
		    System.out.print(se);
			msgsb.append("试题入库出错:"+se.toString());
        }

	}//end if
    }else{
        msgsb.append("提交试题出错:试题为空");
    }
    return newID;
}//end submitOne

//@@2. My pain _____apparent the moment I walked into the room. for the first man I met asked
//sympathetically: "Are you feeling all right?"
// A. must be  B. had  C. must have been  D. had to be
//##A ##B  ##C  ##D
//@A@5@E@ :@答案@分数@难度@
synchronized public int submitAll(String strHtml,String Title,Connection con,javax.servlet.jsp.JspWriter out){
        if(debug){
            try{
            out.print("<br> submitAll input:<BR>"+ strHtml);
            }catch(Exception e){}
        }
	String [] strArray=strHtml.split("@@");
	String [] ansMark;
	String temp=null;
	StringBuffer bs=new StringBuffer();//试题ID#答案A#分数;
	int newID=-1,bin=-1,end=0;
	int newtestID=-1;
        int i=-1;
	String ans="";
	SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	String now=df.format(new java.util.Date());
	//先将所有试题提交
	//debug
	//out.println(now);
//        out.print("strArray.length="+String.valueOf(strArray.length));
//        if (debug){
//            for(i=0;i<strArray.length;i++){
//                Tools.debugmsg("<br>strArray["+i+"]="+strArray[i]+"<br>",out);
//            }
//        }

	try{
            con.setAutoCommit(false);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -