public static Collection selEmp(String param, EmployeeSelType selType) {
// 连接数据库
Connection con = ConnectionManager.getConnection();
CallableStatement cst = null;
ResultSet rs = null;
// 建一个职员列表
Collection<Employee> empc = new ArrayList<Employee>();
try {
String proc = "{call proc_selEmp '" + param + "','" + selType
+ "'}";
// 取得职员表数据
cst = con.prepareCall(proc);
rs = cst.executeQuery();
while (rs.next()) {
Employee emp = new Employee();
emp.setId(rs.getInt("Eid"));
emp.setName(rs.getString("Ename"));
emp.setSex(rs.getString("Esex"));
emp.setAge(rs.getInt("Eage"));
emp.setPosition(rs.getString("Eposition"));
emp.setRemark(rs.getString("Eremark"));
empc.add(emp);
}
} catch (SQLException ex) {
ex.printStackTrace();
} finally {
ConnectionManager.closeResultSet(rs);
ConnectionManager.closeStatement(cst);
ConnectionManager.closeConnection(con);
}
return empc;
}
/**
* 查找大类信息
*
* @param name
* 大类名
* @param selType
* 查找类型
* @return
*/
public static Collection selCate(String name, CateSelType selType) {
// 连接数据库
Connection con = ConnectionManager.getConnection();
CallableStatement cst = null;
ResultSet rs = null;
// 建一个类别列表
Collection<Category> cc = new ArrayList<Category>();
try {
// 取得类别表数据
cst = con.prepareCall("{call proc_selCate '" + name + "','"
+ selType + "'}");
rs = cst.executeQuery();
while (rs.next()) {
Category c = new Category();
c.setId(rs.getInt("Cid"));
c.setName(rs.getString("Cname"));
cc.add(c);
}
} catch (SQLException ex) {
ex.printStackTrace();
} finally {
ConnectionManager.closeResultSet(rs);
ConnectionManager.closeStatement(cst);
ConnectionManager.closeConnection(con);
}
return cc;
}
/**
* 查找子类信息
*
* @param param
* 存储过程参数
* @param selType
* 查找类型
* @return
*/
public static Collection selSubcate(String param, SubcateSelType selType) {
// 连接数据库
Connection con = ConnectionManager.getConnection();
CallableStatement cst = null;
ResultSet rs = null;
// 建一个子类列表
Collection<Subcate> scc = new ArrayList<Subcate>();
try {
// 取得子类表数据
cst = con.prepareCall("{call proc_selSubcate '" + param + "','"
+ selType + "'}");
rs = cst.executeQuery();
while (rs.next()) {
Subcate sc = new Subcate();
sc.setId(rs.getInt("Sid"));
sc.setName(rs.getString("Sname"));
sc.setCateId(rs.getInt("SCid"));
scc.add(sc);
}
} catch (SQLException ex) {
ex.printStackTrace();
} finally {
ConnectionManager.closeResultSet(rs);
ConnectionManager.closeStatement(cst);
ConnectionManager.closeConnection(con);
}
return scc;
}
/**
* 查找资产信息
*
* @param procName
* 存储过程名
* @param param
* 存储过程参数
* @return
*/
public static Collection selAsset(String proc, String param) {
// 连接数据库
Connection con = ConnectionManager.getConnection();
CallableStatement cst = null;
ResultSet rs = null;
// 建一个资产信息列表
Collection<Asset> ac = new ArrayList<Asset>();
try {
// 取得资产信息表数据
cst = con.prepareCall("{call " + proc + " '" + param + "'}");
rs = cst.executeQuery();
while (rs.next()) {
Asset a = new Asset();
a.setId(rs.getInt(1));
a.setName(rs.getString(2));
a.setCateName(rs.getString(3));
a.setSubcateName(rs.getString(4));
a.setModel(rs.getString(5));
a.setPrice(rs.getDouble(6));
a.setPurDate(rs.getString(7));
a.setStatus(rs.getString(8));
a.setUseBy(rs.getString(9));
a.setRemark(rs.getString(10));
ac.add(a);
}
} catch (SQLException ex) {
ex.printStackTrace();
} finally {
ConnectionManager.closeResultSet(rs);
ConnectionManager.closeStatement(cst);
ConnectionManager.closeConnection(con);
}
return ac;
}
/**
* 查找借出资产信息
*
* @param param
* 存储过程参数
* @param selType
* 查找类型
* @return
*/
public static Collection selLent(String param, LentSelType selType) {
// 连接数据库
Connection con = ConnectionManager.getConnection();
CallableStatement cst = null;
ResultSet rs = null;
// 建一个借出记录列表
Collection<Lent> lc = new ArrayList<Lent>();
try {
// 取得借出记录表数据
cst = con.prepareCall("{call proc_selLent '" + param + "','"
+ selType + "'}");
rs = cst.executeQuery();
while (rs.next()) {
Lent l = new Lent();
l.setId(rs.getInt("Lid"));
l.setAssetId(rs.getInt("LAid"));
l.setEmpId(rs.getInt("LEid"));
l.setOperatorName(rs.getString("LOname"));
l.setDate(rs.getString("Ldate"));
l.setPurpose(rs.getString("Lpurpose"));
l.setRemark(rs.getString("Lremark"));
l.setAssetName(rs.getString("Aname"));
l.setModel(rs.getString("Amodel"));
l.setSubcateName(rs.getString("Sname"));
l.setUseBy(rs.getString("Ause_by"));
lc.add(l);
}
} catch (SQLException ex) {
ex.printStackTrace();
} finally {
ConnectionManager.closeResultSet(rs);
ConnectionManager.closeStatement(cst);
ConnectionManager.closeConnection(con);
}
return lc;
}
/**
* 查找归还记录
*
* @return
*/
public static Collection selReturned() {
// 连接数据库
Connection con = ConnectionManager.getConnection();
CallableStatement cst = null;
ResultSet rs = null;
// 建一个归还记录列表
Collection<Returned> rc = new ArrayList<Returned>();
try {
// 取得归还记录表数据
cst = con.prepareCall("{call proc_selReturned}");
rs = cst.executeQuery();
while (rs.next()) {
Returned r = new Returned();
r.setId(rs.getInt("Rid"));
r.setAssetId(rs.getInt("RAid"));
r.setAssetName(rs.getString("RAname"));
r.setUser(rs.getString("Ruse_by"));
r.setLentDate(rs.getString("RLdate"));
r.setReturnDate(rs.getString("Rdate"));
r.setLentOname(rs.getString("RLOname"));
r.setReturnOname(rs.getString("RROname"));
r.setRemark(rs.getString("Rremark"));
rc.add(r);
}
} catch (SQLException ex) {
ex.printStackTrace();
} finally {
ConnectionManager.closeResultSet(rs);
ConnectionManager.closeStatement(cst);
ConnectionManager.closeConnection(con);
}
return rc;
}
/**
* 修改记录:包括添加、删除、修改
*
* @param strProcInvoke
* 调用存储过程的字符串
* @return
*/
public static int modifyRecord(String strProcInvoke) {
Connection con = ConnectionManager.getConnection();
try {
return con.prepareCall("{call " + strProcInvoke + "}")
.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
return 0;
} finally {
ConnectionManager.closeConnection(con);
}
}
/**
* 子类别查找类型
*
* @author Tom
*/
public enum SubcateSelType {
BY_NAME, BY_CATE_NAME
}
/**
* 大类别查找类型
*
* @author Tom
*/
public enum CateSelType {
BY_NAME, BY_HAVE_SUBCATE, ALL
}
/**
* 管理员名查找类型
*
* @author Tom
*
*/
public enum OperatorSelType {
IN_NAME, IN_NAME_PWD
}
/**
* 借出记录查找类型
*
* @author Tom
*
*/
public enum LentSelType {
BY_OPERATOR_NAME, BY_EMPLOYEE_ID, BY_ASSET_ID, ALL
}
/**
* 职员查找类型
*
* @author Tom
*
*/
public enum EmployeeSelType {
BY_NAME, BY_POSITION, ALL
}
}
版权所有:编程辅导网 2021 All Rights Reserved 联系方式:QQ:99515681 微信:codinghelp 电子信箱:99515681@qq.com
免责声明:本站部分内容从网络整理而来,只供参考!如有版权问题可联系本站删除。