📄 knowmate_k.jsp.svn-base
字号:
<!-------------------------------------------------------------
* @ name: knowmate_k.jsp
* @ Author : ranxu
* @ date :2008-06-06
-------------------------------------------------------------->
<%@ page import='java.io.*,java.text.*,java.util.Date,java.util.Vector, java.sql.*, com.entaz.lib.db.*, com.entaz.relay.net.*' contentType='text/html;charset=euc-kr'%>
<%@ include file="../imgpath.jsp"%>
<%@ include file="../common_func.jsp"%>
<%@ include file="../makeKOR.jsp"%>
<%!
/*------------------------------------------------------------------------------------------------------
+ method:getAnswer()
action:Answer 1(db)--"O"(jsp) 0(db)--"X"(jsp)
author:ranxu 2008-06-05
-------------------------------------------------------------------------------------------------------*/
int ANSWER_O = 1;
int ANSWER_X = 0;
public String getAnswer(int key)
{
String ret = "";
if(key==ANSWER_O){
ret = "O";
}else if(key==ANSWER_X){
ret = "X";
}
return ret;
}
String STR_ANSWER_O = "1";
String STR_ANSWER_X = "0";
public String getAnswer(Object key)
{
String ret = "";
if(key==STR_ANSWER_O){
ret = "O";
}else if(key==STR_ANSWER_X){
ret = "X";
}
return ret;
}
%>
<%
/*------------------------------------------------------------------------------------------------------
parameter from last page:knowmate_s.jap
-------------------------------------------------------------------------------------------------------*/
String nickname = java.net.URLDecoder.decode(makeKOR(request.getParameter("nickname")));
String mphone = request.getParameter("mphone");
String gphone = request.getParameter("gphone");
String status = java.net.URLDecoder.decode(makeKOR(request.getParameter("status")));
String str_unansweredTitle = java.net.URLDecoder.decode(makeKOR(request.getParameter("str_unansweredTitle")));
String str_unansweredIdx = java.net.URLDecoder.decode(makeKOR(request.getParameter("str_unansweredIdx")));
String [] unansweredTitles= new String[5];
String [] unansweredIdxs = new String[5];
unansweredTitles =str_unansweredTitle.split(",");
unansweredIdxs = str_unansweredIdx.split(",");
//for(int i=0;i<unansweredTitles.length;i++){
//System.out.println(unansweredTitles[i]+"===unansweredTitles1234===");
//}
/*------------------------------------------------------------------------------------------------------
+ DB
-------------------------------------------------------------------------------------------------------*/
PreparedStatement pstmt = null;
Connection con = null;
Statement stmt = null;
ResultSet rs = null;
String sql = null;
int ret = -1;
/*------------------------------------------------------------------------------------------------------
+ init parameter of current page
-------------------------------------------------------------------------------------------------------*/
List answeredtitleList = null;
List answeredIdxList = null;
List hostAnswerList = null;
String[] guestAnswers= null;
List unansweredTitleList = null;
List unansweredIdxList = null;
double allCount = 0.0;
double answeredCount = 0.0;
double answeredRightCount = 0.0;
int unansweredCount = 0;
int matchPoint=0;
int knowPoint=0;
try
{
/*------------------------------------------------------------------------------------------------
* DB 目池记
-------------------------------------------------------------------------------------------------*/
%><%@ include file="../getConnection.jsp"%><%
/**************************************
胶鸥客 嘎苗焊绰 矾宏款技!
***************************************/
/*-------------------------------------------------------------------------------------------------------
insert multi guest's answers
-------------------------------------------------------------------------------------------------------*/
answeredtitleList = new ArrayList();
answeredIdxList = new ArrayList();
hostAnswerList = new ArrayList();
guestAnswers=new String[unansweredTitles.length-1];
if(status.equals("insertMulti")){
for(int i=0;i<unansweredTitles.length-1;i++){
String quiz_idx_unanswered = "";
guestAnswers[i]= request.getParameter("ox"+i);
//sql = "select quiz_idx from gt_lucky_quiz_mylog where title=? and phonenum=?";
//pstmt = con.prepareStatement(sql);
//pstmt.setString(1,unansweredTitles[i+1]);
//pstmt.setLong(2,Long.parseLong(gphone));
//rs = pstmt.executeQuery();
//if(rs.next()){
//quiz_idx_unanswered = rs.getString("quiz_idx");
//System.out.println(quiz_idx_unanswered+"===quiz_idx_unanswered===0612==1==");
//System.out.println(unansweredIdxs[i+1]+"===unansweredIdxs[i]===0612==1==");
//}
//rs.close();
//pstmt.close();
//System.out.println(quiz_idx_unanswered+"===quiz_idx_unanswered=======0612");
sql = "select * from gt_lucky_quiz_mylog where quiz_idx=? and phonenum=? and guest_phone=?";
pstmt = con.prepareStatement(sql);
pstmt.setString(1,unansweredIdxs[i+1]);
pstmt.setLong(2,Long.parseLong(gphone));
pstmt.setLong(3,Long.parseLong(mphone));
rs = pstmt.executeQuery();
if(rs.next()){
}else{
System.out.println((guestAnswers[i]!=null)+"---------------true?------------------");
if(guestAnswers[i]!=null){
sql="insert into gt_lucky_quiz_mylog (quiz_idx,title,answer,phonenum,guest_phone) values (?,?,?,?,?)";
System.out.println(unansweredIdxs[i+1]+"111111111111111111--idx");
System.out.println(unansweredTitles[i+1]+"111111111111111111--title");
pstmt = con.prepareStatement(sql);
pstmt.setString(1,unansweredIdxs[i+1]);
pstmt.setString(2,unansweredTitles[i+1]);
pstmt.setString(3,guestAnswers[i]);
pstmt.setString(4,gphone);
pstmt.setString(5,mphone);
ret = pstmt.executeUpdate();
System.out.println(ret+"--------------------ret1?--------------");
if(ret==-1){
//return;
}
pstmt.close();
// answered titles
answeredtitleList.add(unansweredTitles[i+1]);
answeredIdxList.add(unansweredIdxs[i+1]);
//the host's answers of the titles
sql=" select distinct a.* from gt_lucky_quiz_mylog a,gt_lucky_quiz b"+
" where a.quiz_idx = b.idx and b.flag=1 "+
" and a.phonenum =? and a.guest_phone =? and a.title=?";
pstmt = con.prepareStatement(sql);
pstmt.setLong(1,Long.parseLong(gphone));
pstmt.setLong(2,Long.parseLong(gphone));
pstmt.setString(3,unansweredTitles[i+1]);
rs=pstmt.executeQuery();
while(rs.next()){
hostAnswerList.add(rs.getString("answer"));
}
rs.close();
pstmt.close();
}
}
rs.close();
pstmt.close();
}
}
/*-------------------------------------------------------------------------------------------------------
get the unanswered title
-------------------------------------------------------------------------------------------------------*/
unansweredTitleList = new ArrayList();
unansweredIdxList = new ArrayList();
sql = " select top 5 a.* from gt_lucky_quiz_mylog a,gt_lucky_quiz b"+
" where a.quiz_idx = b.idx and b.flag=1 "+
" and a.phonenum =? and a.guest_phone= ?" +
" and a.quiz_idx not in"+
" (select distinct a.quiz_idx from gt_lucky_quiz_mylog a,gt_lucky_quiz b"+
" where a.quiz_idx = b.idx and b.flag=1 "+
" and a.phonenum =? and a.guest_phone = ?" +
" )order by a.idx desc";
pstmt = con.prepareStatement(sql);
pstmt.setLong(1,Long.parseLong(gphone));
pstmt.setLong(2,Long.parseLong(gphone));
pstmt.setLong(3,Long.parseLong(gphone));
pstmt.setLong(4,Long.parseLong(mphone));
rs=pstmt.executeQuery();
while(rs.next()){
unansweredTitleList.add(rs.getString("title"));
unansweredIdxList.add(rs.getString("quiz_idx"));
}
rs.close();
pstmt.close();
//System.out.println(unansweredTitleList+"===unansweredTitles===");
/*-------------------------------------------------------------------------------------------------------
insert guest's answers
-------------------------------------------------------------------------------------------------------*/
/*-------------------------------------------------------------------------------------------------------
get the count of all title which the host have answered
-------------------------------------------------------------------------------------------------------*/
sql = " select count(1) allcount from gt_lucky_quiz_mylog a,gt_lucky_quiz b "+
" where a.quiz_idx = b.idx and b.flag=1 "+
" and a.phonenum =? and a.guest_phone=? ";
pstmt = con.prepareStatement(sql);
pstmt.setLong(1,Long.parseLong(gphone));
pstmt.setLong(2,Long.parseLong(gphone));
rs=pstmt.executeQuery();
if(rs.next()){
allCount = rs.getDouble("allcount");
}
//System.out.println(allCount+"===allCount");
rs.close();
pstmt.close();
/*-------------------------------------------------------------------------------------------------------
get the count of guest answered title
-------------------------------------------------------------------------------------------------------*/
sql = " select count(distinct a.idx) answeredcount from gt_lucky_quiz_mylog a,gt_lucky_quiz b"+
" where a.quiz_idx = b.idx and b.flag=1 "+
" and a.phonenum =? and a.guest_phone =?";
pstmt = con.prepareStatement(sql);
pstmt.setLong(1,Long.parseLong(gphone));
pstmt.setLong(2,Long.parseLong(mphone));
rs=pstmt.executeQuery();
if(rs.next()){
answeredCount = rs.getDouble("answeredcount");
}
//System.out.println(answeredCount+"===answeredCount");
rs.close();
pstmt.close();
/*-------------------------------------------------------------------------------------------------------
get the count of guest answered right title
-------------------------------------------------------------------------------------------------------*/
sql = " select count(a.idx) answeredrightcount from gt_lucky_quiz_mylog a,gt_lucky_quiz b,gt_lucky_quiz_mylog c"+
" where a.quiz_idx = b.idx and b.flag=1 and a.quiz_idx=c.quiz_idx and a.answer = c.answer"+
" and a.phonenum =? and a.guest_phone =? " +
" and c.phonenum =? and c.guest_phone =? ";
pstmt = con.prepareStatement(sql);
pstmt.setLong(1,Long.parseLong(gphone));
pstmt.setLong(2,Long.parseLong(gphone));
pstmt.setLong(3,Long.parseLong(gphone));
pstmt.setLong(4,Long.parseLong(mphone));
rs=pstmt.executeQuery();
if(rs.next()){
answeredRightCount = rs.getDouble("answeredrightcount");
}
//System.out.println(answeredRightCount+"===answeredRightCount");
rs.close();
pstmt.close();
/*-------------------------------------------------------------------------------------------------------
get the count of guest unanswered title
-------------------------------------------------------------------------------------------------------*/
sql = " select count(a.idx) answeredcount from gt_lucky_quiz_mylog a,gt_lucky_quiz b"+
" where a.quiz_idx = b.idx and b.flag=1 "+
" and a.phonenum =? and a.guest_phone=? " +
" and a.quiz_idx not in"+
" (select distinct a.quiz_idx from gt_lucky_quiz_mylog a,gt_lucky_quiz b"+
" where a.quiz_idx = b.idx and b.flag=1 "+
" and a.phonenum =? and a.guest_phone =? )";
pstmt = con.prepareStatement(sql);
pstmt.setLong(1,Long.parseLong(gphone));
pstmt.setLong(2,Long.parseLong(gphone));
pstmt.setLong(3,Long.parseLong(gphone));
pstmt.setLong(4,Long.parseLong(mphone));
rs=pstmt.executeQuery();
if(rs.next()){
unansweredCount = rs.getInt("answeredcount");
}
//System.out.println(unansweredCount+"===unansweredCount");
rs.close();
pstmt.close();
/*-------------------------------------------------------------------------------------------------------
概莫档 捞秦档 insert,update
-------------------------------------------------------------------------------------------------------*/
matchPoint = (int)(answeredRightCount/answeredCount*100);
knowPoint = (int)(answeredRightCount/allCount*100);
if(matchPoint>100){
matchPoint = 100;
}
if(knowPoint>100){
knowPoint = 100;
}
sql = "select * from gt_lucky_match_point where phonenum=? and guest_phone=? ";
pstmt = con.prepareStatement(sql);
pstmt.setLong(1,Long.parseLong(gphone));
pstmt.setLong(2,Long.parseLong(mphone));
rs=pstmt.executeQuery();
if(rs.next()){
sql = "update gt_lucky_match_point set match_point=?,know_point = ? where phonenum=? and guest_phone=?";
pstmt = con.prepareStatement(sql);
pstmt.setLong(1,matchPoint);
pstmt.setLong(2,knowPoint);
pstmt.setLong(3,Long.parseLong(gphone));
pstmt.setLong(4,Long.parseLong(mphone));
ret = pstmt.executeUpdate();
pstmt.close();
}else{
sql = "insert into gt_lucky_match_point (phonenum,guest_phone,match_point,know_point) values (?,?,?,?)";
pstmt = con.prepareStatement(sql);
pstmt.setLong(1,Long.parseLong(gphone));
pstmt.setLong(2,Long.parseLong(mphone));
pstmt.setLong(3,matchPoint);
pstmt.setLong(4,knowPoint);
ret = pstmt.executeUpdate();
pstmt.close();
}
rs.close();
// QVGA HTML
//
if( isQVGA )
{
%><%@ include file="/html/knowmate_k.jsp"%><%
}
// QCIF HTML
//
else
{
%><%@ include file="/html/qcif/knowmate_k.jsp"%><%
}
}
catch(Exception e)
{
throw e;
}
finally
{
if ( rs != null ) { try { rs.close(); } catch ( Exception e ) { } }
if ( stmt != null ) { try { stmt.close(); } catch ( Exception e ) { } }
if ( con != null ) { try { con.close(); } catch ( Exception e ) { } }
}
%>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -