package com.wei.action.dao.impl;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts2.ServletActionContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import com.wei.action.dao.ScoreDao;
import com.wei.entity.FinalScore;
import com.wei.entity.FinalScoreCount;
import com.wei.entity.ManyScore;
import com.wei.entity.Paper;
import com.wei.entity.Score;
import com.wei.entity.Student;
import com.wei.util.DBUtil;
import com.wei.util.ExcelFileGenerator;
public class ScoreDaoImpl extends HibernateDaoSupport implements ScoreDao{
public void saveStudentScore(Score score) throws SQLException {
System.out.println("score save succeess!");
this.getHibernateTemplate().save(score);
}
public Score findStudentScorebyStuId(String StuNumber) throws SQLException {
String hql="from Score where stuNumber=?";
Object[] params={StuNumber};
List<Score> scorelist=this.getHibernateTemplate().find(hql,params);
if(!scorelist.isEmpty()){
Score s=scorelist.get(0);
return s;
}
return null;
}
public List<FinalScore> findall() throws SQLException {
String hql="from FinalScore";
List<FinalScore> list=this.getHibernateTemplate().find(hql);
return list;
}
public void saveManyChooseScore(ManyScore manyscore) throws SQLException {
System.out.println("manyscore save succeess!");
this.getHibernateTemplate().save(manyscore);
Score single=findStudentScorebyStuId(manyscore.getStuNumber());
FinalScore finalscore=new FinalScore();
finalscore.setStuScore(single.getStuScore());
finalscore.setStuManyscore(manyscore.getStuManyscore());
finalscore.setStuName(manyscore.getStuName());
finalscore.setStuNumber(manyscore.getStuNumber());
this.getHibernateTemplate().save(finalscore);
}
public void saveFinalScore(FinalScore finalscore) throws SQLException {
System.out.println("finalscore save succeess!");
//this.getHibernateTemplate().save(finalscore);
}
public void saveFinalScoreCount(FinalScoreCount finalscorecount)
throws SQLException {
// TODO Auto-generated method stub
this.getHibernateTemplate().save(finalscorecount);
}
public List<FinalScoreCount> findallfinalcount() throws SQLException {
String hql="from FinalScoreCount f order by f.sumScore desc";
List<FinalScoreCount> list=this.getHibernateTemplate().find(hql);
return list;
}
public FinalScoreCount findfinalScorecountbyStuId(String StuNumber)
throws SQLException {
String hql="from FinalScoreCount f where f.stuNumber=?";
Object[] params={StuNumber};
List<FinalScoreCount> scorelist=this.getHibernateTemplate().find(hql,params);
if(!scorelist.isEmpty()){
FinalScoreCount s=scorelist.get(0);
return s;
}
return null;
}
public void deleteallrowsfromFinalScoreCount() throws SQLException {
Connection conn=DBUtil.getConnection();
String sql = "DROP TABLE IF EXISTS finalscorecount";
String sql2="create table `onlinexam`.`finalscorecount`(`stuNumber` VARCHAR(255) not null,`stuName` VARCHAR(255) not null,`singleScore` DOUBLE,`manyScore` DOUBLE,`sumScore` DOUBLE,primary key (`stuNumber`))";
PreparedStatement pst = conn.prepareStatement(sql);
pst.execute();
System.out.println(sql);
pst=conn.prepareStatement(sql2);
pst.execute();
System.out.println(sql2);
conn.close();
}
public void exportExcel(List<FinalScoreCount> users) throws Exception {
HttpServletResponse response=ServletActionContext.getResponse();
response.setContentType("application/vnd.ms-excel");
ArrayList<String> fieldName=new ArrayList<String>();
fieldName.add("学号");
fieldName.add("姓名");
fieldName.add("单选题");
fieldName.add("多选题");
fieldName.add("总分");
ArrayList<List<Object>> fieldData=new ArrayList<List<Object>>();
for(FinalScoreCount user:users){
ArrayList<Object> udata=new ArrayList<Object>();
udata.add(user.getStuNumber());
udata.add(user.getStuName());
udata.add(user.getSingleScore());
udata.add(user.getManyScore());
udata.add(user.getSumScore());
fieldData.add(udata);
}
ExcelFileGenerator excelFileGenerator=new ExcelFileGenerator(fieldName, fieldData);
excelFileGenerator.exportExcel(response.getOutputStream());
}
public void deleteallscoreinfo(String studentnum) throws Exception {
FinalScoreCount n1=findFinalScoreCountbyStuNumber(studentnum);
if(n1!=null){
this.getHibernateTemplate().delete(n1);
}
FinalScore n2=findFinalScorebyStuNumber(studentnum);
if(n2!=null){
this.getHibernateTemplate().delete(n2);
}
ManyScore n3=findManyScorebyStuNumber(studentnum);
if(n3!=null){
this.getHibernateTemplate().delete(n3);
}
Score n4=findScorebyStuNumber(studentnum);
if(n4!=null){
this.getHibernateTemplate().delete(n4);
}
}
public FinalScoreCount findFinalScoreCountbyStuNumber(String StuNumber)
throws SQLException {
String hql="from FinalScoreCount where stuNumber=?";
Object[] params={StuNumber};
List<FinalScoreCount> scorelist=this.getHibernateTemplate().find(hql,params);
if(!scorelist.isEmpty()){
FinalScoreCount s=scorelist.get(0);
return s;
}
return null;
}
public FinalScore findFinalScorebyStuNumber(String StuNumber)
throws SQLException {
String hql="from FinalScore where stuNumber=?";
Object[] params={StuNumber};
List<FinalScore> scorelist=this.getHibernateTemplate().find(hql,params);
if(!scorelist.isEmpty()){
FinalScore s=scorelist.get(0);
return s;
}
return null;
}
public ManyScore findManyScorebyStuNumber(String StuNumber)
throws SQLException {
String hql="from ManyScore where stuNumber=?";
Object[] params={StuNumber};
List<ManyScore> scorelist=this.getHibernateTemplate().find(hql,params);
if(!scorelist.isEmpty()){
ManyScore s=scorelist.get(0);
return s;
}
return null;
}
public Score findScorebyStuNumber(String StuNumber) throws SQLException {
String hql="from Score where stuNumber=?";
Object[] params={StuNumber};
List<Score> scorelist=this.getHibernateTemplate().find(hql,params);
if(!scorelist.isEmpty()){
Score s=scorelist.get(0);
return s;
}
return null;
}
public void examenddeleteAllscoreinfor() throws SQLException {
String hql="from Score";
List<Score> list1=this.getHibernateTemplate().find(hql);
String hql1="from ManyScore";
List<ManyScore> list2=this.getHibernateTemplate().find(hql1);
String hql2="from FinalScore";
List<FinalScore> list3=this.getHibernateTemplate().find(hql2);
String hql3="from FinalScoreCount";
List<FinalScoreCount> list4=this.getHibernateTemplate().find(hql3);
String hql4="from Student";
List<FinalScoreCount> list5=this.getHibernateTemplate().find(hql4);
this.getHibernateTemplate().deleteAll(list1);
this.getHibernateTemplate().deleteAll(list2);
this.getHibernateTemplate().deleteAll(list3);
this.getHibernateTemplate().deleteAll(list4);
this.getHibernateTemplate().deleteAll(list5);
}
public void examenddeleteAllscoreinforExceptStudentInfo()
throws SQLException {
String hql="from Score";
List<Score> list1=this.getHibernateTemplate().find(hql);
String hql1="from ManyScore";
List<ManyScore> list2=this.getHibernateTemplate().find(hql1);
String hql2="from F
技术很渣
- 粉丝: 1w+
- 资源: 39
最新资源
- 使用群晖NAS搭建虚拟机
- 基于minifly的学习源码-本人耗时五年完善的稳定源码移植于minifly上,不带操作系统,直接操作寄存器,代码简洁明了,算法基于数学公式,便于学习数学知识
- 基于motorcad设计的外转子发电机,磁钢采用FB6B铁氧体 ,不等匝绕组,输出功率2.3KW 定子外径156 3200RPM,18极27槽永磁同步发电机(PMSG)设计案例.
- 电力电子、电机驱动、数字滤波器matlab simulink仿真模型实现及相关算法的C代码实现 配置C2000 DSP ADC DAC PWM定时器 中断等模块,提供simulink与DSP的联合仿
- 视觉系统程序,新能源电池检测 1、支持4个相机 2、实现Profinet网卡通信 3、实现日志功能 4、实现图像存储功能 5、实现电芯有无判断、电芯和端板涂胶检测
- 基于51单片机的电子时钟设计
- 西门子smart200与汇川变频器 Modbus RTU控制程序 步科触摸屏程序 振捣控制系统 汇川变频器手册
- C#上位机与西门子plc通信,实现伺服控制与数字量控制 提供C#源代码,plc测试程序
- 45.<资源>番茄钟3.0 无代码 C#例子 WPF例子
- stm32f103的Bootloader IAP串口升级stm32f103的Bootloader IAP串口升级st m32固件的学习资料,成熟产品方案已经用在批量产品上,资料包括上位机(电脑端)运行
- 基于Spark的电商用户行为分析系统-源码+课设论文(本科期末课程设计).zip
- Qt C++pdf阅读器源码 上下翻页 精美工具栏 支持ofd格式 1. 仿WPS界面 2. 预览PDF文件 3. 支持PDF预览放大,缩小 4. 支持目录预览查看 5. 支持目录点击跳转页查
- RDM(radis桌面工具)
- 西门子s7 200smart与3台台达VFD-M变频器通讯目标:用触摸屏和西门子smart 控制3台台达变频器通讯 器件:西门子s7 200 smart PLC,3台台达VFD-M变频器,昆仑通态触摸
- 基于51单片机的电子密码锁设计
- Qt5工业上位机源码 工业电子称 无线扫码器 串口的使用 Qt5.14可运行 Qt5工业上位机应用! 一套完整工程! 工业电子称使用, 无线扫码枪的使用, 串口的使用 使用Qt5.14 用QtCrea
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈