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.User_battmaint_check; import com.fgkj.dto.User_battmaint_check_process; public class User_battmaint_check_processImpl implements BaseDAO,CallBack{ public List getResults(ResultSet rs) { List list=new ArrayList(); try { while(rs.next()){ User_battmaint_check_process uprocess=new User_battmaint_check_process(); uprocess.setNum(rs.getInt("num")); uprocess.setUsr_id(rs.getInt("usr_id")); uprocess.setTask_rec_id(rs.getInt("task_rec_id")); uprocess.setWork_caption(rs.getString("work_caption")); uprocess.setWork_caption_time(rs.getTimestamp("work_caption_time")); list.add(uprocess); } } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } return list; } public boolean add(Object obj) { User_battmaint_check_process uprocess=(User_battmaint_check_process) obj; String sql="insert into db_user.tb_user_battmaint_check_process(task_rec_id,work_caption,work_caption_time) values(?,?,?)"; Boolean bl=DAOHelper.executeUpdate(DBUtil.getConn(), sql, new Object[]{uprocess.getTask_rec_id(), uprocess.getWork_caption(),uprocess.getWork_caption_time()}); return bl; } //4.10user_battmaint_check表修改时User_battmaint_check_process表就新增一条记录 public String addPro(Object obj) { User_battmaint_check_process uprocess=(User_battmaint_check_process) obj; String sql="insert into db_user.tb_user_battmaint_check_process(task_rec_id,work_caption,usr_id,work_caption_time) " + "values("+uprocess.getTask_rec_id() +",'"+uprocess.getWork_caption()+"'" +","+uprocess.getUsr_id() +",'"+DAOHelper.sdf.format(uprocess.getWork_caption_time()) +"')"; return sql; } public boolean update(Object obj) { User_battmaint_check_process uprocess=(User_battmaint_check_process) obj; String sql="update db_user.tb_user_battmaint_check_process task_rec_id=?,work_caption=?,work_caption_time=? where num=?"; Boolean bl=DAOHelper.executeUpdate(DBUtil.getConn(), sql, new Object[]{uprocess.getTask_rec_id(), uprocess.getWork_caption(),uprocess.getWork_caption_time(),uprocess.getNum()}); return bl; } public boolean del(Object obj) { User_battmaint_check_process uprocess=(User_battmaint_check_process) obj; String sql="delete from db_user.tb_user_battmaint_check_process where num=?"; Boolean bl=DAOHelper.executeUpdate(DBUtil.getConn(), sql, new Object[]{uprocess.getNum()}); return bl; } //4.10user_battmaint_check表删除一条记录时User_battmaint_check_process表就删除相关的记录 public String delPro(Object obj) { User_battmaint_check_process uprocess=(User_battmaint_check_process) obj; String sql="delete from db_user.tb_user_battmaint_check_process where task_rec_id="+uprocess.getTask_rec_id(); return sql; } public List searchAll() { String sql="select * from db_user.tb_user_battmaint_check_process"; List list=DAOHelper.executeQuery(sql, DBUtil.getConn(), null, new User_battmaint_check_processImpl()); return list; } //4.10根据User_battmaint_check的num查询User_battmaint_check_process对应的数据 public List serchByCondition(Object obj) { User_battmaint_check mcheck=(User_battmaint_check) obj; String sql="select num,usr_id,task_rec_id,work_caption,work_caption_time from db_user.tb_user_battmaint_check_process where task_rec_id=? "; List list=DAOHelper.executeQuery(sql, DBUtil.getConn(), new Object[]{mcheck.getNum()}, new User_battmaint_check_processImpl()); return list; } public List serchByInfo(Object obj) { // TODO Auto-generated method stub return null; } public static void main(String[] args) { User_battmaint_check_processImpl up=new User_battmaint_check_processImpl(); User_battmaint_check mcheck=new User_battmaint_check(); mcheck.setNum(4); List list=up.serchByCondition(mcheck); for (User_battmaint_check_process u : list) { System.out.println(u); } System.out.println(list.size()); } }