package com.fgkj.dao.impl; import java.sql.ResultSet; import java.sql.SQLException; import java.text.ParseException; import java.util.ArrayList; import java.util.List; import com.fgkj.dao.BaseDAO; import com.fgkj.dao.CallBack; import com.fgkj.dao.DAOHelper; import com.fgkj.db.DBUtil; import com.fgkj.db.IDatabaseName; import com.fgkj.dto.Batt_maint_inf; import com.fgkj.dto.Batt_maint_process; public class Batt_maint_processImpl implements BaseDAO,CallBack{ public List getResults(ResultSet rs) { List list=new ArrayList(); try { while(rs.next()){ Batt_maint_process bprocess=new Batt_maint_process(); bprocess.setNum(rs.getInt("num")); bprocess.setUname(rs.getString("uname")); bprocess.setBatt_maint_rec_id(rs.getInt("batt_maint_rec_id")); bprocess.setUsr_id(rs.getInt("usr_id")); bprocess.setWork_caption(rs.getString("work_caption")); bprocess.setWork_caption_time(rs.getTimestamp("work_caption_time")); list.add(bprocess); } } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } return list; } public boolean add(Object obj) { Batt_maint_process bprocess=(Batt_maint_process) obj; String sql="insert into db_battinf.tb_batt_maint_process(batt_maint_rec_id,usr_id,work_caption,work_caption_time) values(?,?,?,?) "; Boolean bl=DAOHelper.executeUpdate(DBUtil.getConn(), sql, new Object[]{bprocess.getBatt_maint_rec_id(), bprocess.getUsr_id(),bprocess.getWork_caption(),bprocess.getWork_caption_time()}); return bl; } //2.1电池维护记录查询(编辑记录)的同时向batt_maint_process表插入数据提交的方式插入数据库 public String addPro(Object obj) { Batt_maint_process bprocess=(Batt_maint_process) obj; String sql="insert into db_battinf.tb_batt_maint_process(batt_maint_rec_id,usr_id,work_caption,work_caption_time) values("+bprocess.getBatt_maint_rec_id()+","+bprocess.getUsr_id()+ ",'"+bprocess.getWork_caption()+"','"+DAOHelper.sdf.format(bprocess.getWork_caption_time())+"')"; return sql; } public boolean update(Object obj) { Batt_maint_process bprocess=(Batt_maint_process) obj; String sql="update db_battinf.tb_batt_maint_process set batt_maint_rec_id=?,usr_id=?,work_caption=?,work_caption_time=? where num=?"; Boolean bl=DAOHelper.executeUpdate(DBUtil.getConn(), sql, new Object[]{bprocess.getBatt_maint_rec_id(), bprocess.getUsr_id(),bprocess.getWork_caption(),bprocess.getWork_caption_time(),bprocess.getNum()}); return bl; } //2.1 电池维护记录查询(删除记录)时,将所有的编辑记录全删除 public boolean del(Object obj) { Batt_maint_process bprocess=(Batt_maint_process) obj; String sql="delete from db_battinf.tb_batt_maint_process where batt_maint_rec_id=?"; Boolean bl=DAOHelper.executeUpdate(DBUtil.getConn(), sql, new Object[]{bprocess.getBatt_maint_rec_id()}); return bl; } public List searchAll() { String sql="select * from db_battinf.tb_batt_maint_process"; List list=DAOHelper.executeQuery(sql, DBUtil.getConn(), null, new Batt_maint_processImpl()); return list; } //3.1根据id查所有编辑信息 public List serchByCondition(Object obj) { Batt_maint_process bprocess=(Batt_maint_process) obj; //System.out.println(bprocess); String sql="select num,batt_maint_rec_id,usr_id,work_caption,work_caption_time,uname from db_battinf.tb_batt_maint_process,db_user.tb_user_inf where batt_maint_rec_id=? and db_user.tb_user_inf.uid=usr_id ORDER BY work_caption_time desc"; List list=DAOHelper.executeQuery(sql, DBUtil.getConn(), new Object[]{bprocess.getBatt_maint_rec_id()}, new Batt_maint_processImpl()); return list; } public List serchByInfo(Object obj) { // TODO Auto-generated method stub return null; } public static void main(String[] args) { Batt_maint_processImpl bp=new Batt_maint_processImpl(); /*List list=bp.searchAll(); for(Batt_maint_process u:list){ System.out.println(u); }*/ Batt_maint_process b=new Batt_maint_process(); b.setUsr_id(1001); List list=bp.serchByCondition(b); for(Batt_maint_process u:list){ System.out.println(u); } System.out.println(list.size()); } }