⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 stipenddao.java

📁 人力资源信息管理系统!包含登录 员工管理 培训经历 用户管理 出勤管理等一系列人力资源的信息管理模块!
💻 JAVA
字号:
package com.buat.stipend;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

import com.buat.connect.Connect;
import com.buat.employee.Employee;
 
 
 

public class StipendDAO implements IStipendDAO {
	Connect manager=new Connect();
	public boolean AddStipend(Stipend stipend) {
		Connection con=manager.getConnect();
		boolean successful=false;
		StringBuffer sql=new StringBuffer();
		sql.append("insert into stipend(employeeid,basic,eat,house,duty,tax,assistance,punishment,granttime,total)");
		sql.append("             values(   ?,        ?,   ?,    ?,    ?,  ?,  ?,         ?,         ?,         ?)");
		PreparedStatement psmt=null;
		try {
			psmt=con.prepareStatement(sql.toString());
			
			psmt.setInt(1, stipend.getEmployeeid());
			psmt.setFloat(2,stipend.getBasic());
			psmt.setFloat(3,stipend.getEat());
			psmt.setFloat(4,stipend.getHouse());
			psmt.setFloat(5,stipend.getDuty());
			psmt.setFloat(6,stipend.getTax());
			psmt.setFloat(7,stipend.getAssistance());
			psmt.setFloat(8,stipend.getPunishment());
			psmt.setDate(9,stipend.getGranttime());
			psmt.setFloat(10,stipend.getTotal());
			
			int rs=psmt.executeUpdate();
			if(rs>0){
				successful=true;
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			try {
				if(psmt !=null){
				psmt.close();
				}
				if(con !=null){
					con.close();
				}
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		return successful;
	}

	public boolean DeleteStipend(int id) {
		Connection con=manager.getConnect();
		boolean successful=false;
		
		StringBuffer sql=new StringBuffer();
		sql.append("delete from stipend where id= ?");
		PreparedStatement psmt=null;
		
		try {
			psmt=con.prepareStatement(sql.toString());
			psmt.setInt(1, id);
			
			int rs=psmt.executeUpdate();
			if(rs>0){
				successful=true;
			}
		} catch (SQLException e) {
			// TODO 自动生成 catch 块
			e.printStackTrace();
		}finally{
			try {
				if(psmt !=null){
					psmt.close();
				}
				if(con !=null){
					con.close();
				}
			} catch (SQLException e) {
				// TODO 自动生成 catch 块
				e.printStackTrace();
			}
		}
		return successful;
	}

	public ArrayList QueryStipend() {
		ArrayList stipendlist=new ArrayList();
		
		Connection con=manager.getConnect();
		StringBuffer sql=new StringBuffer();
		sql.append("select * from stipend");
		
		PreparedStatement psmt=null;
		ResultSet rs=null;
		try {
			psmt=con.prepareStatement(sql.toString());
			
			rs=psmt.executeQuery();
			
			while(rs.next()){
				Stipend stipend=new Stipend();
				stipend.setId(rs.getInt("id"));
				stipend.setEmployeeid(rs.getInt("employeeid"));
				stipend.setBasic(rs.getFloat("basic"));
				stipend.setEat(rs.getFloat("eat"));
				stipend.setHouse(rs.getFloat("house"));
				stipend.setDuty(rs.getFloat("duty"));
				stipend.setTax(rs.getFloat("tax"));
				stipend.setAssistance(rs.getFloat("assistance"));
				stipend.setPunishment(rs.getFloat("punishment"));
				stipend.setGranttime(rs.getDate("granttime"));
				stipend.setTotal(rs.getFloat("total"));
				stipendlist.add(stipend);
				
			}
		} catch (SQLException e) {
			 
			e.printStackTrace();
		}finally{
			try {
				if(psmt !=null){
					psmt.close();
				}
				if(con !=null){
					con.close();
				}
			} catch (SQLException e) {
				// TODO 自动生成 catch 块
				e.printStackTrace();
			}
		}
		return stipendlist;
	}

	public boolean UpdateStipend(Stipend stipend, int id) {
		Connection con=manager.getConnect();
		boolean successful=false;
		StringBuffer sql=new StringBuffer();
		sql.append("update stipend set employeeid=?,basic=?,eat=?,house=?,duty=?,tax=?,assistance=?,punishment=?,granttime=?,total=? where id=?");
		
		PreparedStatement psmt=null;
		
		try {
			psmt=con.prepareStatement(sql.toString());
			
			psmt.setInt(1, stipend.getEmployeeid());
			psmt.setFloat(2,stipend.getBasic());
			psmt.setFloat(3,stipend.getEat());
			psmt.setFloat(4,stipend.getHouse());
			psmt.setFloat(5,stipend.getDuty());
			psmt.setFloat(6,stipend.getTax());
			psmt.setFloat(7,stipend.getAssistance());
			psmt.setFloat(8,stipend.getPunishment());
			psmt.setDate(9,stipend.getGranttime());
			psmt.setFloat(10,stipend.getTotal());
			psmt.setInt(11,id);
			int rs=psmt.executeUpdate();
			if(rs>0){
				successful=true;
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			try {
				if(psmt !=null){
				psmt.close();
				}
				if(con !=null){
					con.close();
				}
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		
		
		return successful;
	}

	public int QueryCountStipend() {
		int count=0;
		Connection con=manager.getConnect();
		StringBuffer sql=new StringBuffer();
		sql.append("select count(*) from stipend");
		PreparedStatement psmt=null;
		try {
			psmt=con.prepareStatement(sql.toString());
			ResultSet rs=null;
			rs=psmt.executeQuery();
			while(rs.next()){
				count=rs.getInt(1);
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return count;
	}

	public ArrayList QueryStipendlimit(int beginIndex, int endIndex) {
		ArrayList stipendlist=new ArrayList();
		int maxlengh= (endIndex - beginIndex) + 1;
		Connection con=manager.getConnect();
		StringBuffer sql=new StringBuffer();
		sql.append("select * from stipend order by id desc limit ?,?");
		
		PreparedStatement psmt=null;
		try {
			psmt=con.prepareStatement(sql.toString());
			
			
			psmt.setInt(1,beginIndex);
			psmt.setInt(2,maxlengh);
			
			ResultSet rs=null;
			rs=psmt.executeQuery();
			while(rs.next()){
				Stipend stipend=new Stipend();
				stipend.setId(rs.getInt("id"));
				stipend.setEmployeeid(rs.getInt("employeeid"));
				stipend.setBasic(rs.getFloat("basic"));
				stipend.setEat(rs.getFloat("eat"));
				stipend.setHouse(rs.getFloat("house"));
				stipend.setDuty(rs.getFloat("duty"));
				stipend.setTax(rs.getFloat("tax"));
				stipend.setAssistance(rs.getFloat("assistance"));
				stipend.setPunishment(rs.getFloat("punishment"));
				stipend.setGranttime(rs.getDate("granttime"));
				stipend.setTotal(rs.getFloat("total"));
				stipendlist.add(stipend);
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
		return stipendlist;
	}

	public Stipend QueryEmployeeid(Employee employee) {
		Connection con=manager.getConnect();
		
		StringBuffer sql=new StringBuffer();
		sql.append("select * from employee where employeeid=?");
		
		Stipend stipend=new  Stipend();
		
		PreparedStatement psmt=null;
		ResultSet rs=null;
		try {
			psmt=con.prepareStatement(sql.toString());
			psmt.setInt(1, employee.getEmployeeId());
			rs=psmt.executeQuery();
			
			while(rs.next()){
					
				if (rs.getInt(1)==employee.getEmployeeId()) {
					stipend.setEmployeeid(rs.getInt(1));
				} else {
					stipend.setEmployeeid(0);
				}
			}
		} catch (SQLException e) {
			 
			e.printStackTrace();
		}finally{
			try {
				if(psmt !=null){
					psmt.close();
				}
				if(con !=null){
					con.close();
				}
			} catch (SQLException e) {
				// TODO 自动生成 catch 块
				e.printStackTrace();
			}
		}
		return stipend;
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -