?? unit_test_quest_add_rs.jsp
字號:
<%@ page contentType="text/html; charset=gb2312" language="java" errorPage="" %>
<%@ page import="java.sql.*"%>
<%@ page import="jinghua.*"%>
<%@ page import="java.text.*"%>
<%@ page import="java.util.*"%>
<jsp:useBean id="DBCon" class="jinghua.JinghuaConn" scope="session">
</jsp:useBean>
<%!
boolean debug=false;
String questTypeID=null;
int subjectID=-1;
String gradeID=null;
String difficulty=null;
String knowPointID1=null;
String knowPointID2=null;
String knowPointID3=null;
String answer=null;
StringBuffer msgsb=new StringBuffer("OK");
Statement stmt=null;
ResultSet rs=null;
String sql="";
String temp="";
int teaID=-1;
int ID=-1;//新提交試題或試卷的ID
Connection con=null;
class Test{
long id;
String name;
String grade;
String time;
float mark;
String paper;
int testnum;
public String toString(){
String temp="";
temp="<br> id="+id+"<br> name="+name;
return temp;
}
};
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((strHtml.indexOf("src=")>0) || (strHtml.indexOf("SRC=")>0)){
msgsb.append("<BR>單個試題的數據格式錯誤,可能包含有圖片,請檢查!");
return -1;
}
}
//檢查答案:
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);
}
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+"'"+")";
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){
try{
con.rollback();
}catch(Exception e){
System.out.print(se);
msgsb.append("試題入庫出錯:SQL="+sql+"\n"+se.toString());
}
}
catch(Exception se){
try{
con.rollback();
}catch(Exception e){
System.out.print(se);
msgsb.append("試題入庫出錯:"+se.toString());
}
}
}//end if
}else{
try{
con.rollback();
}catch(Exception se)
{
msgsb.append("試題入庫出錯:"+se.toString());
}
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@ :@答案@分數@難度@
%>
<%
try{
//UN_debug
msgsb.delete(0,msgsb.length() );
msgsb.append("OK");
try{
String TeacherID=request.getParameter("teacherID");
teaID=Integer.parseInt(TeacherID);
}catch(Exception e){
Tools.showalert("您還沒有登錄,或連接超時,請重新登錄!",out);
//response.sendRedirect("../login.jsp");
msgsb.append("teacherID Error\n");
Tools.showJS("window.open('../login.jsp','_self')",out);
//response.sendRedirect("../login.jsp");
// Tools.goback(out);
}
String testID=request.getParameter("testID");
if(debug){
out.print("<br>testID="+testID);
}
if(testID==null)
throw new Exception("調用參數不足!");
Test t=new Test();
t.id=Long.parseLong(testID);
if (msgsb.toString().equals("OK"))
{
questTypeID=""+request.getParameter("QuestType");//試題類型ID
subjectID=Integer.parseInt(request.getParameter("Subject"));//科目ID
gradeID=""+request.getParameter("Grade");//計算機等級ID
difficulty=""+request.getParameter("Difficulty");//難度
knowPointID1=""+request.getParameter("KnowPoint1");//知識點ID
knowPointID2=""+request.getParameter("KnowPoint2");//知識點ID
knowPointID3=""+request.getParameter("KnowPoint3");//知識點ID
answer=request.getParameter("Answer");//答案
answer=Tools.codestring(answer);
answer=answer.toUpperCase();
difficulty.toUpperCase();
float mark=Float.parseFloat(request.getParameter("Mark"));//分數
String strHtml=""+request.getParameter("Content");//獲取提交的試題的HTML
strHtml=Tools.codestring(strHtml);//轉換字符集
String group=request.getParameter("group");
con=DBCon.getConnection();
con.setAutoCommit(false);
if(group.equals("single")){//提交單個試題
if(debug) out.print("<br>submitone param: strHtml="+strHtml+
"<br>answer="+answer+"<br>mark="+mark+"<br>diff="+difficulty);
ID=submitOne(strHtml,answer,mark,difficulty,con,false);
}
temp=msgsb.toString();
if(debug){
out.print("<br><br><br>New Information=");
out.print(temp);
out.print("<br>New quest ID="+ID);
}
if(temp.equals("OK")){
//提交成功
sql="SELECT `test`.`paper`,`test`.`testnum`,`test`.`mark` "+
" FROM `test` WHERE (`test`.`id` = "+t.id+")";
stmt=con.createStatement();
rs=stmt.executeQuery(sql);
if(rs.next()){
t.paper=rs.getString("paper");
t.mark=rs.getFloat("mark");
t.testnum=rs.getInt("testnum");
}
rs.close();
stmt.close();
if(debug) out.print("<br>test paper="+t.paper+
"<br>testnum="+t.testnum+
"<br>mark="+t.mark);
t.testnum++;
t.mark+=mark;
//1574@A@10@A#
t.paper=t.paper+String.valueOf(ID)+"@"+answer.toUpperCase()+
"@"+mark+"@"+difficulty+"#";
sql="update test set paper='"+t.paper+"',testnum="+t.testnum+",mark="+t.mark+
" where id="+t.id;
stmt=con.createStatement();
stmt.executeUpdate(sql);
stmt.close();
con.commit();
if(debug)
out.print("<br>update test sql="+sql);
if(group.equals("single")){//提交單個試題
Tools.showalert(" 試題提交成功,新的試題ID為:"+ID,out);
Tools.goback(out);
}
}
else{
out.print("<br>"+msgsb.toString());
%>
<SCRIPT language="javascript">
alert("試題未能提交成功,請檢查提交信息或與系統管理員聯系");
//history.go(-1);
</SCRIPT>
<%
}
}
}
catch(Exception e){
out.print("<br>"+e.toString());
}
finally{
DBCon.dropConnection();
}
%>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -