employeemanagerserviceimpl.java
来自「生产管理系统 使用SSH」· Java 代码 · 共 411 行
JAVA
411 行
package task.business;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import task.domain.Admin;
import task.domain.Employee;
/**a
* @author liuu
* @date Apr 25, 2008
*/
public class EmployeeManagerServiceImpl implements EmployeeManagerService{
public static final String sql_addEmployee = "insert into temployee (employee_name ,clerk_id,password ,sex,birthday , join_time, position ,experience,degree,major) values(?,?,?,?,?,?,?,?,?,?)";
public static final String sql_getAllEmployee = "select * from temployee ";
public static final String sql_getAllClerk = "select * from temployee where position ='clerk'";
public static final String sql_getAllManager ="select * from temployee where position ='manager'";
public static final String sql_deleteAnEmployee="delete from temployee where id=?";
public static final String sql_employeeIsInTask="select id from ttask where state='i' and(clerk_id=? or manager_id=?)";
public static final String sql_dispatchEmployee="update temployee set manager_id=? where id=?";
public static final String sql_showEmployeeInfo="select * from temployee where id=?";
public static final String sql_addAdmin="insert into tadmin (id,name,password) values(?,?,?)";
public static final String sql_checkIsAdmin="select * from tadmin where id=? and password=?";
public static final String sql_checkIsEmployee="select * from temployee where clerk_id=? and password=? and position=? ";
public boolean addEmployee(Employee employee) throws Exception {
Connection conn=ConnectionFactory.getConnection();
PreparedStatement stmt=null;
boolean temp=true;
try {
stmt=conn.prepareStatement(sql_addEmployee);
stmt.setString(1,employee.getName());
stmt.setString(2,employee.getEmployeeId());
stmt.setString(3,employee.getPassword());
stmt.setString(4,employee.getSex());
stmt.setDate(5, employee.getBirthday());
stmt.setDate(6,employee.getJoinTime());
stmt.setString(7,employee.getPosition());
stmt.setString(8,employee.getExperience());
stmt.setString(9,employee.getDegree());
stmt.setString(10,employee.getMajor());
int result=stmt.executeUpdate();
System.out.println(result);
if(result!=1)
temp=false;
} catch (SQLException e) {
System.out.println(e);
temp=false;
}
finally
{
ConnectionFactory.close(stmt);
ConnectionFactory.close(conn);
}
return temp;
}
public boolean deleteEmployee(int employeeId) throws Exception {
Connection conn=ConnectionFactory.getConnection();
PreparedStatement stmt=null;
boolean temp=true;
try {
stmt=conn.prepareStatement(sql_deleteAnEmployee);
stmt.setInt(1,employeeId);
int result=stmt.executeUpdate();
if(result!=1)
temp=false;
} catch (SQLException e) {
System.out.println(e);
temp=false;
}
finally
{
ConnectionFactory.close(stmt);
ConnectionFactory.close(conn);
}
return temp;
}
public boolean dispatchEmployee(int employeeId, int managerId)throws Exception {
Connection conn=ConnectionFactory.getConnection();
PreparedStatement stmt=null;
boolean temp=true;
try {
stmt=conn.prepareStatement(sql_dispatchEmployee);
stmt.setInt(1,managerId);
stmt.setInt(2,employeeId);
int result=stmt.executeUpdate();
if(result!=1)
temp=false;
} catch (SQLException e) {
temp=false;
System.out.println(e);
}
finally
{
ConnectionFactory.close(stmt);
ConnectionFactory.close(conn);
}
return temp;
}
public List<Employee> getAllEmployee() throws Exception {
Connection conn=ConnectionFactory.getConnection();
Statement stmt = conn.createStatement();
List<Employee> list=new ArrayList();
try {
ResultSet rs = stmt.executeQuery(sql_getAllEmployee);
while(rs.next())
{ Employee employee=new Employee();
employee.setId(rs.getInt(1));
employee.setEmployeeId(rs.getString(2));
employee.setPassword(rs.getString(3));
employee.setName(rs.getString(4));
employee.setSex(rs.getString(5));
employee.setBirthday(rs.getDate(6)) ;
employee.setJoinTime(rs.getDate(7)) ;
employee.setPosition(rs.getString(8));
employee.setManagerId(rs.getInt(9));
employee.setExperience(rs.getString(10));
employee.setMajor(rs.getString(11));
employee.setDegree(rs.getString(12));
list.add(employee);
}
} catch (SQLException e) {
System.out.println(e);
}
finally
{
stmt.close();
ConnectionFactory.close(conn);
}
return list;
}
public List<Employee> getAllManager() throws Exception {
Connection conn=ConnectionFactory.getConnection();
Statement stmt = conn.createStatement();
List<Employee> list=new ArrayList();
try {
ResultSet rs = stmt.executeQuery(sql_getAllManager);
while(rs.next())
{ Employee employee=new Employee();
employee.setId(rs.getInt(1));
employee.setEmployeeId(rs.getString(2));
employee.setPassword(rs.getString(3));
employee.setName(rs.getString(4));
employee.setSex(rs.getString(5));
employee.setBirthday(rs.getDate(6)) ;
employee.setJoinTime(rs.getDate(7)) ;
employee.setPosition(rs.getString(8));
employee.setManagerId(rs.getInt(9));
employee.setExperience(rs.getString(10));
employee.setMajor(rs.getString(11));
employee.setDegree(rs.getString(12));
list.add(employee);
}
} catch (SQLException e) {
System.out.println(e);
}
finally
{
stmt.close();
ConnectionFactory.close(conn);
}
return list;
}
public List<Employee> getAllClerk() throws Exception {
Connection conn=ConnectionFactory.getConnection();
Statement stmt = conn.createStatement();
List<Employee> list=new ArrayList();
try {
ResultSet rs = stmt.executeQuery(sql_getAllClerk);
while(rs.next())
{ Employee employee=new Employee();
employee.setId(rs.getInt(1));
employee.setEmployeeId(rs.getString(2));
employee.setPassword(rs.getString(3));
employee.setName(rs.getString(4));
employee.setSex(rs.getString(5));
employee.setBirthday(rs.getDate(6)) ;
employee.setJoinTime(rs.getDate(7)) ;
employee.setPosition(rs.getString(8));
employee.setManagerId(rs.getInt(9));
employee.setExperience(rs.getString(10));
employee.setMajor(rs.getString(11));
employee.setDegree(rs.getString(12));
list.add(employee);
}
} catch (SQLException e) {
System.out.println(e);
}
finally
{
stmt.close();
ConnectionFactory.close(conn);
}
return list;
}
public boolean employeeIsInTask(int employeeId) throws Exception {
Connection conn=ConnectionFactory.getConnection();
PreparedStatement stmt=null;
boolean result =true;
try {
stmt=conn.prepareStatement(sql_employeeIsInTask);
stmt.setInt(1,employeeId);
stmt.setInt(2,employeeId);
ResultSet rs = stmt.executeQuery();
result =rs.next();
} catch (SQLException e) {
System.out.println(e);
}
finally
{
ConnectionFactory.close(stmt);
ConnectionFactory.close(conn);
}
return result;
}
/* (non-Javadoc)
* @see task.business.EmployeeManagerService#showInfoEmployee(int)
*/
public Employee showInfoEmployee(int employeeId) throws Exception {
Connection conn=ConnectionFactory.getConnection();
PreparedStatement stmt=null;
Employee employee=new Employee();
try {
stmt=conn.prepareStatement(sql_showEmployeeInfo);
stmt.setInt(1,employeeId);
ResultSet rs = stmt.executeQuery();
while(rs.next())
{
employee.setId(rs.getInt(1));
employee.setEmployeeId(rs.getString(2));
employee.setPassword(rs.getString(3));
employee.setName(rs.getString(4));
if(rs.getString(5).startsWith("m"))
employee.setSex("男性");
else employee.setSex("女性");
employee.setBirthday(rs.getDate(6)) ;
employee.setJoinTime(rs.getDate(7)) ;
if(rs.getString(8).startsWith("c"))
employee.setPosition("员工");
else employee.setPosition("经理");
employee.setManagerId(rs.getInt(9));
if(rs.getString(10).equals("y"))
employee.setExperience("有");
else employee.setExperience("无");
employee.setMajor(rs.getString(11));
employee.setDegree(rs.getString(12));
}
} catch (SQLException e) {
System.out.println(e);
}
finally
{
ConnectionFactory.close(stmt);
ConnectionFactory.close(conn);
}
return employee;
}
/* (non-Javadoc)
* @see task.business.EmployeeManagerService#addAdmin(task.domain.Admin)
*/
public boolean addAdmin(Admin admin) throws Exception
{
Connection conn=ConnectionFactory.getConnection();
PreparedStatement stmt=null;
boolean result=true;
try {
stmt=conn.prepareStatement(sql_addAdmin);
stmt.setString(1,admin.getId());
stmt.setString(2,admin.getName());
stmt.setString(3,admin.getPassword());
int temp=stmt.executeUpdate();
if(temp!=1)
result=false;
} catch (SQLException e)
{
System.out.println(e);
result=false;
}
finally
{
ConnectionFactory.close(stmt);
ConnectionFactory.close(conn);
}
return result;
}
public boolean checkIsAdimin(String adminId, String password) throws Exception {
Connection conn=ConnectionFactory.getConnection();
PreparedStatement stmt=null;
boolean result =false;
try {
stmt=conn.prepareStatement(sql_checkIsAdmin);
stmt.setString(1,adminId);
stmt.setString(2,password);
ResultSet rs = stmt.executeQuery();
result =rs.next();
} catch (SQLException e) {
System.out.println(e);
}
finally
{
ConnectionFactory.close(stmt);
ConnectionFactory.close(conn);
}
return result;
}
public boolean checkIsEmployee(String id, String password, String position) throws Exception {
Connection conn=ConnectionFactory.getConnection();
PreparedStatement stmt=null;
boolean result =false;
try {
stmt=conn.prepareStatement(sql_checkIsAdmin);
stmt.setString(1,id);
stmt.setString(2,password);
stmt.setString(3,position);
ResultSet rs = stmt.executeQuery();
result =rs.next();
} catch (SQLException e) {
System.out.println(e);
}
finally
{
ConnectionFactory.close(stmt);
ConnectionFactory.close(conn);
}
return result;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?