📄 empbusiness.java
字号:
package com.business;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Vector;
import com.bean.AdminBean;
import com.bean.EmpBean;
import com.dao.*;
import com.db.DBConnection;
import com.struts.form.EmpForm;
import com.struts.form.EmpPopedomForm;
import com.struts.form.PopedomForm;
public class EmpBusiness implements IBusiness {
/*
* 检查登录用户
* */
public boolean findByName(Object ob)
{
DBConnection dbconn=DBConnection.getDBConnection();
Connection conn=dbconn.getConn();
String sql="select * from emp where name=? and pass=?";
PreparedStatement ps=null;
ResultSet rst=null;
//EmpBean eb=(EmpBean) ob;
EmpForm eb=(EmpForm) ob;
try {
ps=conn.prepareStatement(sql);
ps.setString(1, eb.getName());
ps.setString(2, eb.getPass());
rst=ps.executeQuery();
if(rst.next())
{
return true;
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
try {
if(rst!=null)
{
rst.close();
}
if(ps!=null)
{
ps.close();
}
if(conn!=null)
{
conn.close();
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return false;
}
/*
* 查询登录用户信息
* */
public Object findByEmpName(String name) {
DBConnection dbconn = DBConnection.getDBConnection();
Connection conn = dbconn.getConn();
String sql="select * from vwemp where name=?";
PreparedStatement ps=null;
ResultSet rst=null;
//EmpBean eb=(EmpBean) ob;
EmpPopedomDao epd = new EmpPopedomDao();
try {
ps=conn.prepareStatement(sql);
ps.setString(1, name);
rst = ps.executeQuery();
if (rst.next()) {
//EmpBean eb = new EmpBean();
EmpForm eb=new EmpForm();
eb.setId(rst.getString(1));
eb.setName(rst.getString(2));
eb.setPass(rst.getString(3));
eb.setSex(rst.getString(4));
eb.setAge(rst.getString(5));
eb.setDepid(rst.getString(6));
eb.setSchool(rst.getString(7));
eb.setResume(rst.getString(8));
eb.setPicture(rst.getString(9));
eb.setDepname(rst.getString(10));
// 查此员工的权限
Vector vcp = epd.findByEid(eb.getId());
if (vcp != null) {
//设置emppopedom表中pid
String[] pid=new String[vcp.size()];
for (int i = 0; i < pid.length; i++) {
//PopedomBean pb=(PopedomBean) vcp.get(i);
PopedomForm pb=(PopedomForm) vcp.get(i);
pid[i]=pb.getId();
}
eb.setPopedomid(pid);
eb.setPopedoms(vcp);
}
return eb;
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
try {
if (rst != null) {
rst.close();
}
if (ps != null) {
ps.close();
}
if (conn != null) {
conn.close();
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return null;
}
public boolean delete(String id) {
EmpDao edao=new EmpDao();
return edao.delete(id);
}
public Object findById(String id) {
EmpDao edao=new EmpDao();
return edao.findById(id);
}
public boolean save(Object ob) {
EmpDao edao=new EmpDao();
return edao.save(ob);
}
public boolean update(Object ob) {
EmpDao edao=new EmpDao();
return edao.update(ob);
}
public boolean updateByEmp(Object ob) {
DBConnection dbconn = DBConnection.getDBConnection();
Connection conn = dbconn.getConn();
String sql = "update emp set name=?,pass=?,sex=?,age=?,depid=?,school=?,resume=?,picture=? where id=?";
//EmpBean eb = (EmpBean) ob;
EmpForm eb=(EmpForm) ob;
PreparedStatement ps = null;
EmpPopedomDao epdao = new EmpPopedomDao();
try {
ps = conn.prepareStatement(sql);
ps.setString(1, eb.getName());
ps.setString(2, eb.getPass());
ps.setString(3, eb.getSex());
ps.setString(4, eb.getAge());
ps.setString(5, eb.getDepid());
ps.setString(6, eb.getSchool());
ps.setString(7, eb.getResume());
ps.setString(8, eb.getPicture());
ps.setString(9, eb.getId());
int row = ps.executeUpdate();
if (row > 0) {
return true;
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
try {
if (ps != null) {
ps.close();
}
if (conn != null) {
conn.close();
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return false;
}
public Vector findAll() {
EmpDao edao=new EmpDao();
return edao.findAll();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -