📄 plandao.java
字号:
package com.accp.oa.dao.imple;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import com.accp.oa.bean.*;
import com.accp.oa.common.*;
import com.accp.oa.dao.inface.*;
/*
* 此类用于对
* 数据库中表出入库的一些
* 操作
*/
public class PlanDAO implements BaseDAO {
/*
* 此方法用于添加 出或入库或损耗信息
*
* @see com.accp.oa.dao.inface.BaseDAO#add(java.lang.Object)
*/
public boolean add(Object plan) {
boolean success = false;
Plan objplan = (Plan) plan;
Connection con = null;
PreparedStatement stmt = null;
try {
con = DbUtil.connectToDB();
stmt = con.prepareStatement(Constants.ADD_PLAN);
stmt.setString(1, objplan.getName());
stmt.setInt(2, objplan.getNumbers());
stmt.setString(3, objplan.getType());
stmt.setDouble(4, objplan.getMoney());
stmt.setString(5, objplan.getBoss());
stmt.setString(6, objplan.getDime());
stmt.setString(7, objplan.getPlaning());
stmt.setString(8, objplan.getUntils());
if (stmt.executeUpdate() > 0) {
success = true;
}
} catch (Exception ex) {
ex.printStackTrace();
return false;
} finally {
try {
stmt.close();
con.close();
} catch (Exception ex) {
}
}
return success;
}
public boolean delete(Object obj) {
return false;
}
/*
* 此方法用于删除出入库和损耗信息
*
* @see com.accp.oa.dao.inface.BaseDAO#delete(int)
*/
public boolean delete(int planId) {
boolean success = false;
Connection con = null;
PreparedStatement stmt = null;
try {
con = DbUtil.connectToDB();
stmt = con.prepareStatement(Constants.DELETE_PLAN);
stmt.setInt(1, planId);
if (stmt.executeUpdate() > 0) {
success = true;
}
} catch (Exception ex) {
return false;
} finally {
try {
stmt.close();
con.close();
} catch (Exception ex) {
}
}
return success;
}
public boolean delete(String ag0) {
return false;
}
/*
* 此方法用于
* 查询出要
* 统计的数据
*
* @see com.accp.oa.dao.inface.BaseDAO#search(java.lang.Object)
*/
public Object search(Object statTerm) {
StatTerm objstatTerm = (StatTerm)statTerm;
String name = objstatTerm.getName();
String type = objstatTerm.getType();
String boss = objstatTerm.getBoss();
String planing = objstatTerm.getPlaning();
String sql = Constants.STATE_PLAN;
if(name != null && !name.equals("")){
sql = sql + " AND Name ='"+name+"'";
}
if(type != null && !type.equals("")){
sql = sql + " AND Type ='"+type+"'";
}
if(boss != null && !boss.equals("")){
sql = sql + " AND Boss = '"+boss+"'";
}
if(planing != null && !planing.equals("")){
sql = sql + " AND Planing = '"+planing+"'";
}
ArrayList plans = new ArrayList();
Connection con = null;
PreparedStatement stmt = null;
ResultSet rs = null;
try {
con = DbUtil.connectToDB();
stmt = con.prepareStatement(sql);
rs = stmt.executeQuery();
while (rs.next()) {
Plan plan = new Plan();
plan.setId(rs.getInt("Id"));
plan.setName(rs.getString("Name"));
plan.setNumbers(rs.getInt("Numbers"));
plan.setType(rs.getString("Type"));
plan.setMoney(rs.getDouble("Money"));
plan.setBoss(rs.getString("Boss"));
plan.setDime(rs.getString("Dime"));
plan.setPlaning(rs.getString("Planing"));
plan.setTime(rs.getString("Times"));
plan.setUntils(rs.getString("Untils"));
plans.add(plan);
}
} catch (Exception ex) {
ex.printStackTrace();
return null;
} finally {
try {
rs.close();
stmt.close();
con.close();
} catch (Exception ex) {
}
}
return plans;
}
public int search(String ag0, String ag1) {
return 0;
}
public Object search(int id) {
return null;
}
/*
* 此方法用于 查询出所有的 出或入库损耗信息
*
* @see com.accp.oa.dao.inface.BaseDAO#search()
*/
public ArrayList search(String planing) {
ArrayList plans = new ArrayList();
Connection con = null;
PreparedStatement stmt = null;
ResultSet rs = null;
try {
con = DbUtil.connectToDB();
stmt = con.prepareStatement(Constants.SEARCH_PLAN);
stmt.setString(1, planing);
rs = stmt.executeQuery();
while (rs.next()) {
Plan plan = new Plan();
plan.setId(rs.getInt("Id"));
plan.setName(rs.getString("Name"));
plan.setNumbers(rs.getInt("Numbers"));
plan.setType(rs.getString("Type"));
plan.setMoney(rs.getDouble("Money"));
plan.setBoss(rs.getString("Boss"));
plan.setDime(rs.getString("Dime"));
plan.setPlaning(rs.getString("Planing"));
plan.setTime(rs.getString("Times"));
plan.setUntils(rs.getString("Untils"));
plans.add(plan);
}
} catch (Exception ex) {
ex.printStackTrace();
return null;
} finally {
try {
rs.close();
stmt.close();
con.close();
} catch (Exception ex) {
}
}
return plans;
}
public ArrayList search(int ag0, int age1) {
return null;
}
public ArrayList search() {
return null;
}
/*
* 在此方法中对出或入库或损耗信息编辑
*
* @see com.accp.oa.dao.inface.BaseDAO#update(java.lang.Object)
*/
public boolean update(Object plan) {
boolean success = false;
Plan objplan = (Plan) plan;
Connection con = null;
PreparedStatement stmt = null;
try {
con = DbUtil.connectToDB();
stmt = con.prepareStatement(Constants.UPDATE_PLAN);
stmt.setInt(1, objplan.getNumbers());
stmt.setDouble(2, objplan.getMoney());
stmt.setString(3, objplan.getBoss());
stmt.setString(4, objplan.getDime());
stmt.setInt(5, objplan.getId());
if (stmt.executeUpdate() > 0) {
success = true;
}
} catch (Exception ex) {
ex.printStackTrace();
return false;
} finally {
try {
stmt.close();
con.close();
} catch (Exception ex) {
}
}
return success;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -