栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

Eclipse+Java+Swing+Mysql实现员工工资管理系统

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Eclipse+Java+Swing+Mysql实现员工工资管理系统

目录

一、系统介绍

1.运行环境

2.技术说明

3.系统功能

4.数据库 

二、系统实现

1.登录系统

2.管理员界面

3.员工模块

4.部门模块

​编辑 

5.工资模块 

6.普通员工 

三、部分代码

DepartmentDao.java

DepartmentDaoImpl.java 

EmployeeDao.java 

EmployeeDaoImpl.java 


一、系统介绍

1.运行环境

开发工具:Eclipse/IDEA

JDK版本:jdk1.8

Mysql版本:8.0.13

2.技术说明

Java+Swing+Mysql

3.系统功能

功能:两种角色管理员和员工
普通员工无需登录:查询某个月工资;
管理员可以管理员工、部门、工资等基本信息。
员工模块:增加、删除、修改、查看
部门模块:增加、删除、修改、查看
管理员模块:增加、删除、修改、查看
工资模块:录入工资,查询工资,发放工资,工资一览表

4.数据库 

SET FOREIGN_KEY_CHECKS=0;

-- ----------------------------
-- Table structure for department
-- ----------------------------
DROp TABLE IF EXISTS `department`;
CREATE TABLE `department` (
  `id` varchar(255) NOT NULL,
  `name` varchar(255) NOT NULL,
  `director` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;

-- ----------------------------
-- Records of department
-- ----------------------------
INSERT INTO `department` VALUES ('DE001', '财务部', '小李');
INSERT INTO `department` VALUES ('DE002', '经理部', '小黑');

-- ----------------------------
-- Table structure for employee
-- ----------------------------
DROP TABLE IF EXISTS `employee`;
CREATE TABLE `employee` (
  `id` varchar(255) NOT NULL,
  `name` varchar(255) NOT NULL,
  `sex` varchar(255) NOT NULL,
  `age` int NOT NULL,
  `department_id` varchar(255) NOT NULL,
  `position` varchar(255) NOT NULL,
  `phone` varchar(255) NOT NULL,
  `time` date NOT NULL,
  `address` varchar(255) NOT NULL,
  PRIMARY KEY (`id`,`department_id`),
  KEY `ed_dept_id` (`department_id`),
  KEY `id` (`id`),
  CONSTRAINT `ed_dept_id` FOREIGN KEY (`department_id`) REFERENCES `department` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;

-- ----------------------------
-- Records of employee
-- ----------------------------
INSERT INTO `employee` VALUES ('1001', '王一', '男', '25', 'DE002', '会计', '18474588569', '2021-07-20', '山东曹县');
INSERT INTO `employee` VALUES ('1002', '王二3', '女', '36', 'DE002', '工程师', '15478453654', '2021-08-23', '山东日照');
INSERT INTO `employee` VALUES ('1003', '1', '1', '1', 'DE002', '1', '1', '2021-06-12', '1');

-- ----------------------------
-- Table structure for salary
-- ----------------------------
DROP TABLE IF EXISTS `salary`;
CREATE TABLE `salary` (
  `id` int NOT NULL AUTO_INCREMENT,
  `emp_id` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
  `basepay` int DEFAULT NULL,
  `welfare` int DEFAULT NULL,
  `reward` int DEFAULT NULL,
  `insurance` int DEFAULT NULL,
  `funds` int DEFAULT NULL,
  `month` varchar(25) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `remark` varchar(25) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  PRIMARY KEY (`id`,`emp_id`),
  KEY `se_name` (`emp_id`),
  CONSTRAINT `se_name` FOREIGN KEY (`emp_id`) REFERENCES `employee` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=17 DEFAULT CHARSET=utf8mb3 COLLATE=utf8_unicode_ci;

-- ----------------------------
-- Records of salary
-- ----------------------------
INSERT INTO `salary` VALUES ('1', '1001', '3000', '100', '100', '100', '500', '1月', '已发放');
INSERT INTO `salary` VALUES ('13', '1002', '3000', '200', '100', '100', '400', '1月', '未结算');
INSERT INTO `salary` VALUES ('15', '1003', '2500', '100', '200', '100', '300', '1月', '未结算');

-- ----------------------------
-- Table structure for user
-- ----------------------------
DROP TABLE IF EXISTS `user`;
CREATE TABLE `user` (
  `id` int NOT NULL AUTO_INCREMENT,
  `username` varchar(255) NOT NULL,
  `password` varchar(255) NOT NULL,
  `status` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL DEFAULT '管理员',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8mb3;

-- ----------------------------
-- Records of user
-- ----------------------------
INSERT INTO `user` VALUES ('1', 'admin', '123456', '管理员');
INSERT INTO `user` VALUES ('3', 'test', '123456', '管理员');

二、系统实现

1.登录系统

2.管理员界面

 

 

3.员工模块

 

 

 

 

4.部门模块


 

 

 

 

5.工资模块 

 

6.普通员工 

 

 

 

三、部分代码

DepartmentDao.java
package com.system.dao;

import java.util.List;

import com.system.entity.Department;

public interface DepartmentDao {

	
	List selectAll();

	
	int addDepartment(String id, String name, String director);

	
	int updateDepartment(String id, String name, String director);

	
	int delete(String id);

	
	Department selectDepartmentOneById(String id);

	
	Department selectDepartmentOneByName(String name);

}

DepartmentDaoImpl.java 
package com.system.dao;

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

import com.system.entity.Department;
import com.system.utils.DB;

public class DepartmentDaoImpl implements DepartmentDao {

	private DB db;
	private Connection connection;
	private PreparedStatement ps;
	private ResultSet rs;

	@Override
	public List selectAll() {
		String sql = "select * from department";
		connection = new DB().getConnection();
		List list = new ArrayList();
		try {
			ps = connection.prepareStatement(sql);
			rs = ps.executeQuery();
			while (rs.next()) {
				Department department = new Department();
				department.setId(rs.getString("id"));
				department.setName(rs.getString("name"));
				department.setDirector(rs.getString("director"));
				list.add(department);
			}
			connection.close();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return list;
	}

	@Override
	public Department selectDepartmentOneById(String id) {
		String sql = "select * from department where id = ?";
		connection = new DB().getConnection();
		Department department = null;
		try {
			ps = connection.prepareStatement(sql);
			ps.setString(1, id);
			rs = ps.executeQuery();
			while (rs.next()) {
				department = new Department();
				department.setId(rs.getString("id"));
				department.setName(rs.getString("name"));
				department.setDirector(rs.getString("director"));
			}
			connection.close();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return department;
	}

	@Override
	public int addDepartment(String id, String name, String director) {
		String sql = "insert into department(id,name,director) values(?,?,?)";
		connection = new DB().getConnection();
		int flag = 0;
		try {
			ps = connection.prepareStatement(sql);
			ps.setString(1, id);
			ps.setString(2, name);
			ps.setString(3, director);
			flag = ps.executeUpdate();
			connection.close();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return flag;
	}

	@Override
	public int updateDepartment(String id, String name, String director) {
		String sql = "update department set name = ?,director = ? where id = ?";
		connection = new DB().getConnection();
		int flag = 0;
		try {
			ps = connection.prepareStatement(sql);
			ps.setString(1, name);
			ps.setString(2, director);
			ps.setString(3, id);
			flag = ps.executeUpdate();
			connection.close();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return flag;
	}

	@Override
	public int delete(String id) {
		String sql = "delete from department where id = ?";
		connection = new DB().getConnection();
		int flag = 0;
		try {
			ps = connection.prepareStatement(sql);
			ps.setString(1, id);
			flag = ps.executeUpdate();
			connection.close();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return flag;
	}

	@Override
	public Department selectDepartmentOneByName(String name) {
		String sql = "select * from department where name = ?";
		connection = new DB().getConnection();
		Department department = null;
		try {
			ps = connection.prepareStatement(sql);
			ps.setString(1, name);
			rs = ps.executeQuery();
			while (rs.next()) {
				department = new Department();
				department.setId(rs.getString("id"));
				department.setName(rs.getString("name"));
				department.setDirector(rs.getString("director"));
			}
			connection.close();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return department;
	}

}

EmployeeDao.java 
package com.system.dao;

import java.util.List;

import com.system.entity.Employee;

public interface EmployeeDao {

	
	List selectAll();

	
	Employee selectOneById(String id);

	
	int addEmployee(Employee employee);

	
	int updateEmployeeById(Employee employee);

	
	int deleteEmployeeById(String id);

}

EmployeeDaoImpl.java 
package com.system.dao;

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

import com.system.entity.Employee;
import com.system.utils.DB;

public class EmployeeDaoImpl implements EmployeeDao {

	private DB db;
	private Connection connection;
	private PreparedStatement ps;
	private ResultSet rs;

	@Override
	public List selectAll() {
		String sql = "select e.id,e.name,e.sex,e.age,d.name as department,e.position,e.phone,e.time,e.address "
				+ "from employee e,department d where e.department_id = d.id";
		connection = new DB().getConnection();
		List list = new ArrayList();
		try {
			ps = connection.prepareStatement(sql);
			rs = ps.executeQuery();
			while (rs.next()) {
				Employee employee = new Employee();
				employee.setId(rs.getString("e.id"));
				employee.setName(rs.getString("e.name"));
				employee.setSex(rs.getString("e.sex"));
				employee.setAge(rs.getInt("e.age"));
				employee.setDepartmentName(rs.getString("department"));
				employee.setPosition(rs.getString("e.position"));
				employee.setPhone(rs.getString("e.phone"));
				employee.setTime(rs.getString("e.time"));
				employee.setAddress(rs.getString("e.address"));
				list.add(employee);
			}
			connection.close();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return list;
	}

	@Override
	public Employee selectOneById(String id) {
		String sql = "select e.id,e.name,e.sex,e.age,d.name as department,e.position,e.phone,e.time,e.address "
				+ "from employee e,department d where e.department_id = d.id and e.id = " + id;
		connection = new DB().getConnection();
		Employee employee = null;
		try {
			ps = connection.prepareStatement(sql);
			rs = ps.executeQuery();
			while (rs.next()) {
				employee = new Employee();
				employee.setId(rs.getString("e.id"));
				employee.setName(rs.getString("e.name"));
				employee.setSex(rs.getString("e.sex"));
				employee.setAge(rs.getInt("e.age"));
				employee.setDepartmentName(rs.getString("department"));
				employee.setPosition(rs.getString("e.position"));
				employee.setPhone(rs.getString("e.phone"));
				employee.setTime(rs.getString("e.time"));
				employee.setAddress(rs.getString("e.address"));
			}
			connection.close();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return employee;
	}

	@Override
	public int addEmployee(Employee employee) {
		String sql = "insert into employee(id,name,sex,age,department_id,position,phone,time,address) values(?,?,?,?,?,?,?,?,?)";
		 connection = new DB().getConnection();
		 int flag = 0;
		 try {
			 ps = connection.prepareStatement(sql);
			 ps.setString(1, employee.getId());
			 ps.setString(2, employee.getName());
			 ps.setString(3, employee.getSex());
			 ps.setInt(4, employee.getAge());
			 ps.setString(5, employee.getDepartmentName());
			 ps.setString(6, employee.getPosition());
			 ps.setString(7, employee.getPhone());
			 ps.setString(8, employee.getTime());
			 ps.setString(9, employee.getAddress());
			flag = ps.executeUpdate();
			connection.close();
		 } catch (SQLException e) {
			e.printStackTrace();
		 }
		return flag;
	}

	@Override
	public int updateEmployeeById(Employee employee) {
		String sql = "update employee set name = ?,sex = ?, age = ?,department_id = ?,position=?,phone=?,time=?,address=?  where id= ?";
		connection = new DB().getConnection();
		int flag = 0;
		try {
			ps = connection.prepareStatement(sql);
			ps.setString(1, employee.getName());
			ps.setString(2, employee.getSex());
			ps.setInt(3, employee.getAge());
			ps.setString(4, employee.getDepartmentName());
			ps.setString(5, employee.getPosition());
			ps.setString(6, employee.getPhone());
			ps.setString(7, employee.getTime());
			ps.setString(8, employee.getAddress());
			ps.setString(9, employee.getId());
			flag = ps.executeUpdate();
			connection.close();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return flag;
	}

	@Override
	public int deleteEmployeeById(String id) {
		String sql = "delete from employee where id= ?";
		connection = new DB().getConnection();
		int flag = 0;
		try {
			ps = connection.prepareStatement(sql);
			ps.setString(1, id);
			flag = ps.executeUpdate();
			connection.close();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return flag;
	}

}

 

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/978628.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号