📄 assessdao.java
字号:
package edu.yinhe.mis.model;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import edu.yinhe.mis.dto.AssessDTO;
import edu.yinhe.mis.dto.AuditingDTO;
import edu.yinhe.mis.dto.DemoDTO;
import edu.yinhe.mis.vo.AssessVO;
import edu.yinhe.mis.vo.AuditingVO;
import edu.yinhe.mis.vo.DemoVO;
import edu.yinhe.system.model.BaseDAO;
import edu.yinhe.system.model.IBaseDAO;
/**
*
* @author Administrator 陈雄
*
*/
public class AssessDAO extends BaseDAO{
public Object delete(Object arg0) throws SQLException {
return null;
}
/**
*
* 查询考场表(outline)
* @return 返回科目封装在ArrayList中
*/
public Object find() throws SQLException {
AssessVO avo=null;
PreparedStatement pstat=null;
ResultSet rst=null;
ArrayList list=null;
String SQL="SELECT DISTINCT object_name FROM check_info_table";
try {
list=new ArrayList();
pstat=conn.prepareStatement(SQL);//注意这里的conn是从BaseDAO继承的,可以直接用的
rst=pstat.executeQuery();
while(rst.next()){
avo=new AssessVO();
avo.setObject_name(rst.getString("object_name"));
list.add(avo);
}
} catch (RuntimeException e) {
}finally{
if(rst!=null)rst.close();//由于项目庞大,节约资源
if(pstat!=null)pstat.close();//由于项目庞大,节约资源
SQL=null;
}
return list;
}
/**
* @param Object obj
* 通过考场中的考试科目 查找考该科目的考场 返回考场的集合
*/
public Object find(Object obj) throws SQLException {
String SQL=null;
AssessDTO adto=null;
AssessVO avo=null;
PreparedStatement pstat=null;
ResultSet rst=null;
ArrayList list=null;
int index=1;
try {
list=new ArrayList();
adto=(AssessDTO)obj;//由于前面传参数的时候,已经向上转型,所以这里可以向下转型,即把父类的引用给 //子类的引用,只有先向上转型才可以向下转型.
SQL="SELECT check_id FROM check_info_table WHERE object_name=?";
pstat=conn.prepareStatement(SQL);
pstat.setString(index, adto.getObject_name());
rst=pstat.executeQuery();
while(rst.next()){
avo=new AssessVO();
avo.setCheck_id(rst.getInt("check_id"));
list.add(avo);
}
} catch (RuntimeException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
if(rst!=null)rst.close();
if(pstat!=null)pstat.close();
SQL=null;
adto=null;
}
return list;
}
public Object findAll() throws SQLException {
return null;
}
/**
* 根据考场编号 得到该考场里的学生编号 学生姓名 和考试科目
*/
public Object findAll(Object obj) throws SQLException {
String SQL=null;
AssessDTO adto=null;
AssessVO avo=null;
PreparedStatement pstat=null;
ResultSet rst=null;
ArrayList list=null;
int index=1;
StringBuffer buf=new StringBuffer("SELECT e.name,e.exam_no,e.object_name FROM examinee e,grade_table g WHERE e.exam_no=g.exam_no AND e.check_id=? AND e.fetle=?");
try {
adto=(AssessDTO) obj;
list=new ArrayList();
if(adto.getKeyword()!=null&&!"".equals(adto.getKeyword())&&"".equals(adto.getKeyword2())){
buf.append(" AND e.exam_no="+adto.getKeyword());
}
if("".equals(adto.getKeyword())&&adto.getKeyword2()!=null&&!"".equals(adto.getKeyword2())){
buf.append(" AND e.name='"+adto.getKeyword2()+"'");
}
if(adto.getKeyword()!=null&&!"".equals(adto.getKeyword())&&!"".equals(adto.getKeyword2())){
buf.append(" AND e.exam_no="+adto.getKeyword()+" AND e.name='"+adto.getKeyword2()+"'");
}
buf.append(" limit ?,?");
SQL=buf.toString();
pstat=conn.prepareStatement(SQL);
pstat.setInt(index++, adto.getCheck_id());
pstat.setInt(index++, 0);
pstat.setInt(index++, (Integer.parseInt((adto.getCurrentPage()))-1)*(Integer.parseInt(adto.getRowPerPage())));
pstat.setInt(index++, Integer.parseInt(adto.getRowPerPage()));
rst=pstat.executeQuery();
while(rst.next()){
avo=new AssessVO();
avo.setName(rst.getString("name"));
avo.setObject_name(rst.getString("object_name"));
avo.setExam_no(rst.getInt("exam_no"));
list.add(avo);
}
} catch (NumberFormatException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return list;
}
/**
* 通过考生的编号(exam_no) 得到该考生的答题卡
*/
public Object findById(Object obj) throws SQLException {
String SQL=null;
AssessDTO adto=null;
AssessVO avo=null;
PreparedStatement pstat=null;
ResultSet rst=null;
ArrayList list=null;
int index=1;
SQL="SELECT r.TESTPAPERQUESTION_ID,r.CONTENT,r.STUDENT_KEY,r.STANDARD_KEY,r.SCORE FROM reply_card r,grade_table g WHERE r.exam_no=g.exam_no AND r.exam_no=? AND r.QUESTION_TYPE=?";
try {
adto=(AssessDTO) obj;
list=new ArrayList();
pstat=conn.prepareStatement(SQL);
pstat.setInt(index++, adto.getExam_no());
pstat.setInt(index++, 5);
rst=pstat.executeQuery();
while(rst.next()){
avo=new AssessVO();
avo.setTestpaperquestion_id(rst.getInt("TESTPAPERQUESTION_ID"));
avo.setContent(rst.getString("CONTENT"));
avo.setStudent_key(rst.getString("STUDENT_KEY"));
avo.setStandard_key(rst.getString("STANDARD_KEY"));
avo.setScore(rst.getString("SCORE"));
list.add(avo);
}
} catch (RuntimeException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
if(rst!=null)rst.close();
if(pstat!=null)pstat.close();
SQL=null;
adto=null;
}
return list;
}
/**
* 通过学生的编号 从学生表和成绩表中得到改学生的姓名,考试科目,客观题总分
*/
public Object findByObject(Object obj) throws SQLException {
String SQL=null;
AssessDTO adto=null;
AssessVO avo=null;
PreparedStatement pstat=null;
ResultSet rst=null;
ArrayList list=null;
int index=1;
SQL="SELECT e.name,g.OBJECT_NAME,g.FOLLOW_SCORE FROM examinee e,grade_table g WHERE e.exam_no=g.exam_no AND g.exam_no=?";
try {
adto=(AssessDTO) obj;
list=new ArrayList();
pstat=conn.prepareStatement(SQL);
pstat.setInt(index, adto.getExam_no());
rst=pstat.executeQuery();
while(rst.next()){
avo=new AssessVO();
avo.setName(rst.getString("name"));
avo.setObject_name(rst.getString("OBJECT_NAME"));
avo.setFollow_score(rst.getString("FOLLOW_SCORE"));
}
} catch (RuntimeException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
if(rst!=null)rst.close();
if(pstat!=null)pstat.close();
SQL=null;
adto=null;
}
return avo;
}
/**
* 得到满足条件的数据的条数
*/
public int getCount(Object obj) throws SQLException {
String SQL=null;
AssessDTO adto=null;
AssessVO avo=null;
PreparedStatement pstat=null;
ResultSet rst=null;
Integer integer=0;
int index=1;
StringBuffer buf=new StringBuffer("SELECT COUNT(*) FROM examinee e,grade_table g WHERE e.exam_no=g.exam_no AND e.check_id=? AND fetle=?");
try {
adto=(AssessDTO) obj;
if(adto.getKeyword()!=null&&!"".equals(adto.getKeyword())&&"".equals(adto.getKeyword2())){
buf.append(" AND e.exam_no="+adto.getKeyword());
}
if("".equals(adto.getKeyword())&&adto.getKeyword2()!=null&&!"".equals(adto.getKeyword2())){
buf.append(" AND e.name='"+adto.getKeyword2()+"'");
}
if(adto.getKeyword()!=null&&!"".equals(adto.getKeyword())&&!"".equals(adto.getKeyword2())){
buf.append(" AND e.exam_no="+adto.getKeyword()+" AND e.name='"+adto.getKeyword2()+"'");
}
SQL=buf.toString();
pstat=conn.prepareStatement(SQL);
pstat.setInt(index++, adto.getCheck_id());
pstat.setInt(index++, 0);
rst=pstat.executeQuery();
while(rst.next()){
integer=new Integer(rst.getInt(1));
}
} catch (RuntimeException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finally{
if(rst!=null)rst.close();
if(pstat!=null)pstat.close();
SQL=null;
adto=null;
}
return integer;
}
// public Object getMaxId(Object obj) throws SQLException {
// String SQL=null;
// AssessDTO adto=null;
// AssessVO avo=null;
// PreparedStatement pstat=null;
// ResultSet rst=null;
// ArrayList list=null;
// int mainScore=0;
// int index=1;
// SQL="SELECT fact_score FROM reply_card WHERE exam_no=?";
//
// try {
// avo=new AssessVO();
// adto=(AssessDTO) obj;
// pstat=conn.prepareStatement(SQL);
// pstat.setInt(index, adto.getExam_no());
// rst=pstat.executeQuery();
// while(rst.next()){
// mainScore+=Integer.parseInt(rst.getString("fact_score"));
//
// }
// avo.setMain_score(String.valueOf(mainScore));
// System.out.println(avo.getMain_score());
// } catch (RuntimeException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// } finally{
// if(rst!=null)rst.close();
// if(pstat!=null)pstat.close();
// SQL=null;
// adto=null;
// }
// return avo;
// }
// public Object insert(Object obj) throws SQLException {
// AssessDTO adto=null;
// AssessVO avo=null;
// boolean flag=false;
// adto=(AssessDTO) obj;
// flag=(Boolean) this.update(adto);
// if(flag=true){
// avo=(AssessVO) this.getMaxId(adto);
// }
//
// return avo;
// }
/**
* 把老师对学生的评分写到数据库中
*/
public Object update(Object obj) throws SQLException {
PreparedStatement pstat = null;
int n=0;
boolean isOk=false;
AssessDTO adto=(AssessDTO)obj;
int examnum =adto.getExam_no();
ArrayList list = (ArrayList)adto.getList();
System.out.println(list.size());
for(int i=0; i<list.size();i++)
{
int index=1;
adto=(AssessDTO)list.get(i);
System.out.println(adto.getTestpaperquestion_id());
System.out.println(adto.getFact_socre());
String SQL = "UPDATE reply_card SET FACT_SCORE=? WHERE TESTPAPERQUESTION_ID=?";
pstat = conn.prepareStatement(SQL);
pstat.setString(index++, adto.getFact_socre());
pstat.setInt(index++,adto.getTestpaperquestion_id());
n = pstat.executeUpdate();
}
if(n!=0)
{
isOk=true;
System.out.println(examnum);
int index=1;
String SQL="UPDATE examinee SET fetle=? WHERE exam_no=?";
pstat = conn.prepareStatement(SQL);
pstat.setInt(index++, 1);
pstat.setInt(index++, examnum);
pstat.executeUpdate();
}
return isOk;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -