Eclipse+Java+Swing实现企业人事管理系统

Java+Swing实现企业人事管理系统

  • 一、系统介绍
  • 二、系统展示
    • 1.登录页
    • 2.主页面
    • 3.添加员工信息
    • 4.修改员工信息
    • 5.计算器
    • 6.记事本
    • 7.导出Execl
  • 三、系统实现
    • AccountDao.java
    • DeptDao.java
    • PersonDao.java
    • JDBCUtils.java
    • LoginFrame.java
  • 四、其他
    • 1.其他系统实现
    • 2.获取源码
    • 3.备注

一、系统介绍

本系统实现的功能:用户登录、员工信息的增删改查、导出Execl、计算器、记事本、信息排序。采用AES加密算法,数据库使用Mysql8.0.13,界面良好。

二、系统展示

1.登录页

Eclipse+Java+Swing实现企业人事管理系统_第1张图片

2.主页面

Eclipse+Java+Swing实现企业人事管理系统_第2张图片

3.添加员工信息

Eclipse+Java+Swing实现企业人事管理系统_第3张图片

4.修改员工信息

Eclipse+Java+Swing实现企业人事管理系统_第4张图片

5.计算器

Eclipse+Java+Swing实现企业人事管理系统_第5张图片

6.记事本

Eclipse+Java+Swing实现企业人事管理系统_第6张图片

7.导出Execl

Eclipse+Java+Swing实现企业人事管理系统_第7张图片

三、系统实现

AccountDao.java

package com.sjsq.dao;

import java.util.List;

import com.sjsq.model.TbAccount;
import com.sjsq.model.TbDept;
import com.sjsq.model.TbPerson;

import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;

import com.sjsq.tools.JDBCUtils;

public class AccountDao {
     
	private static JdbcTemplate template = new JdbcTemplate(JDBCUtils.getDataSource());

	public static List<TbAccount> findAllAccount() {
     
		try {
     
			String sql = "select * from tb_account";
			List<TbAccount> a = template.query(sql, new BeanPropertyRowMapper<TbAccount>(TbAccount.class));
			return a;
		} catch (DataAccessException e) {
     
			e.printStackTrace();
			return null;
		}
	}

	public static String findAccountMoneyById(int i) {
     
		try {
     
			String sql = "select * from tb_account where timecard_id=?";
			TbAccount tbAccount = template.queryForObject(sql, new BeanPropertyRowMapper<TbAccount>(TbAccount.class),
					i);
			return tbAccount.getMoney();
		} catch (DataAccessException e) {
     
			e.printStackTrace();
			return null;
		}
	}
}

DeptDao.java

package com.sjsq.dao;

import java.util.List;

import com.sjsq.model.TbDept;

import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;

import com.sjsq.tools.JDBCUtils;

public class DeptDao {
     
	private static JdbcTemplate template = new JdbcTemplate(JDBCUtils.getDataSource());

	public static TbDept findDeptById(int deptId) {
     
		String sql = "select * from tb_dept where id=?";
		TbDept dept = template.queryForObject(sql, new BeanPropertyRowMapper<TbDept>(TbDept.class), deptId);
		return dept;

	}

	public static List<TbDept> findAllDept() {
     
		try {
     
			String sql = "select * from tb_dept";
			List<TbDept> tbDept = template.query(sql, new BeanPropertyRowMapper<TbDept>(TbDept.class));
			return tbDept;
		} catch (DataAccessException e) {
     
			e.printStackTrace();
			return null;
		}
	}

	public static int findDeptIdByName(String item) {
     
		String sql = "select * from tb_dept where name=?";
		TbDept dept = template.queryForObject(sql, new BeanPropertyRowMapper<TbDept>(TbDept.class), item);
		return dept.getId();
	}

	public static List<TbDept> findAllDeptExceptZero() {
     
		try {
     
			String sql = "select * from tb_dept where id<>0";
			List<TbDept> tbDept = template.query(sql, new BeanPropertyRowMapper<TbDept>(TbDept.class));
			return tbDept;
		} catch (DataAccessException e) {
     
			e.printStackTrace();
			return null;
		}
	}

	public static TbDept findDeptByName(String name) {
     
		try {
     
			String sql = "select * from tb_dept where name=?";
			TbDept dept = template.queryForObject(sql, new BeanPropertyRowMapper<TbDept>(TbDept.class), name);
			return dept;
		} catch (DataAccessException e) {
     
			e.printStackTrace();
			return null;
		}
	}

	public static void addDept(TbDept d2) {
     
		try {
     
			String sql = "insert into tb_dept(name) values (?)";
			template.update(sql, d2.getName());
		} catch (DataAccessException e) {
     
			e.printStackTrace();
		}

	}

	public static void deleteDeptById(int id) {
     
		try {
     
			String sql = "delete from tb_dept where id=?";
			template.update(sql, id);
		} catch (DataAccessException e) {
     
			e.printStackTrace();
		}

	}

	public static void updateDept(int id, String input) {
     
		try {
     
			String sql = "update tb_dept set name = ? where id = ?";
			template.update(sql, input, id);
		} catch (Exception e) {
     
			e.printStackTrace();
		}

	}
}

PersonDao.java

package com.sjsq.dao;

import java.util.List;

import com.sjsq.model.TbPerson;

import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;

import com.sjsq.tools.JDBCUtils;
import com.sjsq.tools.PwEncryption;

public class PersonDao {
     
	private static JdbcTemplate template = new JdbcTemplate(JDBCUtils.getDataSource());

	public static TbPerson queryRecordByNum(String num) {
     
		try {
     
			String sql = "select * from tb_person where record_number=?";
			TbPerson tbRecord = template.queryForObject(sql, new BeanPropertyRowMapper<TbPerson>(TbPerson.class), num);
			return tbRecord;
		} catch (DataAccessException e) {
     
			e.printStackTrace();
			return null;
		}
	}

	public static List<TbPerson> findAllPerson() {
     
		try {
     
			String sql = "select * from tb_person";
			List<TbPerson> tbPerson = template.query(sql, new BeanPropertyRowMapper<TbPerson>(TbPerson.class));
			return tbPerson;
		} catch (DataAccessException e) {
     
			e.printStackTrace();
			return null;
		}
	}

	public static List<TbPerson> likePersonByRecordNumber(String recordNumber) {
     
		try {
     
			String sql = "select * from tb_person where record_number like '%' ? '%'";
			List<TbPerson> tbPerson = template.query(sql, new BeanPropertyRowMapper<TbPerson>(TbPerson.class),
					recordNumber);
			return tbPerson;
		} catch (DataAccessException e) {
     
			e.printStackTrace();
			return null;
		}
	}

	public static List<TbPerson> findPersonByDeptId(int i) {
     
		try {
     
			String sql = "select * from tb_person where dept_id=?";
			List<TbPerson> tbPerson = template.query(sql, new BeanPropertyRowMapper<TbPerson>(TbPerson.class), i);
			return tbPerson;
		} catch (DataAccessException e) {
     
			e.printStackTrace();
			return null;
		}
	}

	public static TbPerson findPersonByRecordNumber(String recordNumber) {
     
		try {
     
			String sql = "select * from tb_person where record_number=?";
			TbPerson tbPerson = template.queryForObject(sql, new BeanPropertyRowMapper<TbPerson>(TbPerson.class),
					recordNumber);
			return tbPerson;
		} catch (DataAccessException e) {
     
			System.out.println("查找员工为空数据");
			e.printStackTrace();
			return null;
		}
	}

	public static void updatePerson(TbPerson person) {
     
		try {
     
			String sql = "update tb_person set dept_id=?,duty_id=?,name=?,sex=?,"
					+ "birthday=?,photo=?,id_card=?,marriaged=?,native_place_id=?,"
					+ "party_member=?,school_age=?,specialty=?,foreign_language=?,"
					+ "grade=?,state=?,role_id=? where record_number=?";
			template.update(sql, person.getDeptId(), person.getDutyId(), person.getName(), person.getSex(),
					person.getBirthday(), person.getPhoto(), person.getIdCard(), person.getMarriaged(),
					person.getNativePlaceId(), person.getPartyMember(), person.getSchoolAge(), person.getSpecialty(),
					person.getForeignLanguage(), person.getGrade(), person.getState(), person.getRoleId(),
					person.getRecordNumber());
		} catch (Exception e) {
     
			e.printStackTrace();
		}
	}

	public static void addPerson(TbPerson person) {
     
		try {
     
			String sql = "insert into tb_person(record_number,dept_id,duty_id,name,sex,"
					+ "birthday,photo,id_card,marriaged,native_place_id,"
					+ "party_member,school_age,specialty,foreign_language,"
					+ "grade,state,role_id) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
			template.update(sql, person.getRecordNumber(), person.getDeptId(), person.getDutyId(), person.getName(),
					person.getSex(), person.getBirthday(), person.getPhoto(), person.getIdCard(), person.getMarriaged(),
					person.getNativePlaceId(), person.getPartyMember(), person.getSchoolAge(), person.getSpecialty(),
					person.getForeignLanguage(), person.getGrade(), person.getState(), person.getRoleId());
		} catch (DataAccessException e) {
     
			e.printStackTrace();
		}

	}

	public static void deletePersonByrecordNumber(String recordNumber) {
     
		try {
     
			String sql = "delete from tb_person where record_number=?";
			template.update(sql, recordNumber);
		} catch (DataAccessException e) {
     
			e.printStackTrace();
		}
	}

	public static TbPerson login(TbPerson person) {
     
		try {
     
			String sql = "select * from tb_person where record_number=? and password=?";
			TbPerson tbPerson = template.queryForObject(sql, new BeanPropertyRowMapper<TbPerson>(TbPerson.class),
					person.getRecordNumber(), person.getPassword());
			return tbPerson;
		} catch (DataAccessException e) {
     
			System.out.println("空结果数据访问异常");
			e.printStackTrace();
			return null;
		}
	}

	public static void updatePersonPassword(TbPerson person) {
     
		try {
     
			String sql = "update tb_person set password = ? where record_number= ?";
			template.update(sql, person.getPassword(), person.getRecordNumber());
		} catch (Exception e) {
     
			e.printStackTrace();
		}
	}

	public static List<TbPerson> likePersonByName(String name) {
     
		try {
     
			String sql = "select * from tb_person where name like '%' ? '%'";
			List<TbPerson> tbPerson = template.query(sql, new BeanPropertyRowMapper<TbPerson>(TbPerson.class), name);
			return tbPerson;
		} catch (DataAccessException e) {
     
			e.printStackTrace();
			return null;
		}
	}

	public static void main(String args[]) {
     
		String userName = "T00001";
		String password = "123456";
		TbPerson person = new TbPerson(userName, PwEncryption.encrypt(password, "key"));
		login(person);
	}
}

JDBCUtils.java

package com.sjsq.tools;

import com.alibaba.druid.pool.DruidDataSourceFactory;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Properties;

/**
 * Druid连接池工具类,将来dao层调用
 */
public class JDBCUtils {
     
	private static DataSource dataSource; // 定义成员变量DataSource
	static {
     
		try {
     
			// 加载配置文件
			Properties properties = new Properties();
			properties.load(JDBCUtils.class.getClassLoader().getResourceAsStream("druid.properties"));

			// 获取DataSource
			dataSource = DruidDataSourceFactory.createDataSource(properties);
		} catch (Exception e) {
     
			e.printStackTrace();
		}
	}

	/**
	 * 获取连接
	 */
	public static Connection getConnection() throws SQLException {
     
		return dataSource.getConnection();
	}

	/**
	 * 释放资源
	 */
	public static void close(Statement statement, Connection connection) {
     
		close(null, statement, connection);
	}

	public static void close(ResultSet resultSet, Statement statement, Connection connection) {
     
		if (resultSet != null) {
     
			try {
     
				resultSet.close();
			} catch (SQLException e) {
     
				e.printStackTrace();
			}
		}

		if (statement != null) {
     
			try {
     
				statement.close();
			} catch (SQLException e) {
     
				e.printStackTrace();
			}
		}

		if (connection != null) {
     
			try {
     
				connection.close();// 归还连接
			} catch (SQLException e) {
     
				e.printStackTrace();
			}
		}
	}

	/**
	 * 获取连接池方法
	 */
	public static DataSource getDataSource() {
     
		return dataSource;
	}
}

LoginFrame.java

package com.sjsq.view;

import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.Toolkit;
import java.io.IOException;
import java.sql.Connection;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import javax.swing.UIManager;
import javax.swing.border.EmptyBorder;
import javax.swing.SwingConstants;

import com.sjsq.model.TbPerson;

import org.jb2011.lnf.beautyeye.BeautyEyeLNFHelper;

import com.sjsq.dao.PersonDao;
import com.sjsq.tools.PwEncryption;
import com.sjsq.tools.StringUtil;
import com.sjsq.tools.TxtExport;

/**
 * 登陆窗体类,为用户第一窗体
 * 
 * @author 22219
 *
 */
public class LoginFrame extends JFrame {
     

	/**
	 * 串行版本标识serialVersionUID
	 */
	private static final long serialVersionUID = 1L;

	private JPanel contentPane;
	public static JTextField userNameTxt;
	private JPasswordField passwordTxt;
	public static String time;
	public static String userId;

	/**
	 * 登陆窗体类的构造函数
	 */
	public LoginFrame() {
     

		this.setBounds(0, 0, 500, 400);
		this.setLocationRelativeTo(null);
		setResizable(false);
		//setIconImage(Toolkit.getDefaultToolkit().getImage(LoginFrame.class.getResource("/images/storage_128px.png")));
		setTitle("登录");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);

		JLabel lblNewLabel = new JLabel("企业人事管理系统");
		lblNewLabel.setBounds(96, 29, 300, 48);
		lblNewLabel.setFont(new Font("方正粗黑宋简体", Font.BOLD, 27));
		lblNewLabel.setIcon(new ImageIcon(LoginFrame.class.getResource("/images/hrm.png")));

		JLabel lblNewLabel_1 = new JLabel("账号");
		lblNewLabel_1.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 15));
		lblNewLabel_1.setBounds(34, 126, 80, 18);
		lblNewLabel_1.setIcon(new ImageIcon(LoginFrame.class.getResource("/images/userName.png")));

		JLabel lblNewLabel_2 = new JLabel("密码");
		lblNewLabel_2.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 15));
		lblNewLabel_2.setBounds(34, 185, 65, 18);
		lblNewLabel_2.setIcon(new ImageIcon(LoginFrame.class.getResource("/images/password.png")));

		userNameTxt = new JTextField();
		userNameTxt.setHorizontalAlignment(SwingConstants.CENTER);
		userNameTxt.setBounds(96, 110, 308, 46);
		userNameTxt.setFont(new Font("微软雅黑", Font.BOLD, 20));
		userNameTxt.setToolTipText("输入用户名");
		userNameTxt.setColumns(10);

		passwordTxt = new JPasswordField();
		passwordTxt.setHorizontalAlignment(SwingConstants.CENTER);
		passwordTxt.setBounds(96, 169, 308, 46);
		passwordTxt.setFont(new Font("微软雅黑", Font.BOLD, 20));
		passwordTxt.setToolTipText("输入密码");

		JButton btnNewButton = new JButton("登录");
		btnNewButton.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 15));
		btnNewButton.setBounds(120, 252, 90, 40);
		this.getRootPane().setDefaultButton(btnNewButton);
		btnNewButton.setIcon(new ImageIcon(LoginFrame.class.getResource("/images/login.png")));
		btnNewButton.addActionListener(new ActionListener() {
     
			public void actionPerformed(ActionEvent e) {
     
				loginActionPerformed(e);
			}
		});

		JButton btnNewButton_1 = new JButton("重置");
		btnNewButton_1.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 15));
		btnNewButton_1.setBounds(280, 252, 90, 40);
		btnNewButton_1.setIcon(new ImageIcon(LoginFrame.class.getResource("/images/reset.png")));
		btnNewButton_1.addActionListener(new ActionListener() {
     
			public void actionPerformed(ActionEvent e) {
     
				resetValueActionPerformed(e);
			}
		});

		JButton btnNewButton_2 = new JButton("注/改");
		btnNewButton_2.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 15));
		btnNewButton_2.setBounds(305, 252, 90, 40);
		btnNewButton_2.setIcon(new ImageIcon(LoginFrame.class.getResource("/images/add.png")));
		btnNewButton_2.addActionListener(new ActionListener() {
     
			public void actionPerformed(ActionEvent e) {
     
				enrollValueActionPerformed(e);
			}
		});

		contentPane.add(lblNewLabel);
		contentPane.add(lblNewLabel_1);
		contentPane.add(lblNewLabel_2);
		contentPane.add(passwordTxt);
		contentPane.add(userNameTxt);
		contentPane.add(btnNewButton);
		contentPane.add(btnNewButton_1);
		//contentPane.add(btnNewButton_2);

		this.setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
		this.addWindowListener(new WindowAdapter() {
     
			public void windowClosing(WindowEvent e) {
     
				if (JOptionPane.showConfirmDialog(null, "确认退出?", "提示", JOptionPane.YES_NO_OPTION) == 0) {
     
					System.exit(0);
				}
			}
		});

		// bg------------------------------------------------
		JLabel lbBg = new JLabel(new ImageIcon(this.getClass().getResource("/images/timg.png")));
		lbBg.setBounds(0, 0, 500, 400);
		this.getContentPane().add(lbBg);
		// bg------------------------------------------------

		// sj------------------------------------------------
		JLabel timeLabel = new JLabel();
		timeLabel.setBounds(260, 319, 220, 18);
		contentPane.add(timeLabel);

		TimerTask task = new TimerTask() {
     
			public void run() {
     
				String sdate = (new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")).format(new Date());
				timeLabel.setText(sdate);
			}
		};
		Timer t = new Timer();
		t.scheduleAtFixedRate(task, new Date(), 1000);
		// sj-------------------------------------------------
	}

	/**
	 * 登陆事件处理
	 * 
	 * @param e
	 */
	private void loginActionPerformed(ActionEvent e) {
     
		String userName = this.userNameTxt.getText();
		String password = new String(this.passwordTxt.getPassword());
		if (StringUtil.isEmpty(userName)) {
     
			JOptionPane.showMessageDialog(this, "用户名不能为空!");
			return;
		}
		if (StringUtil.isEmpty(password)) {
     
			JOptionPane.showMessageDialog(this, "密码不能为空!");
			return;
		}

		TbPerson person = new TbPerson(userName, PwEncryption.encrypt(password, "key"));
		// TbPerson person = new TbPerson(userName,password);
		TbPerson personNew = PersonDao.login(person);
		if (personNew != null) {
     
			JOptionPane.showMessageDialog(this, "登陆成功!");
			MainFrame mainFrame = new MainFrame(userNameTxt.getText());
			mainFrame.frame.setVisible(true);

			// 导出登陆日志(用户id+时间)
			SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			time = df.format(new Date());
			System.out.println("用户Id:" + userNameTxt.getText() + "\t登陆时间:" + time);

			try {
     
				TxtExport.creatTxtFile("Enterprise Personnel Management System");
				TxtExport.writeTxtFile("员工Id:" + userNameTxt.getText() + "\t登陆时间:" + time);
			} catch (IOException e1) {
     
				e1.printStackTrace();
			}

			dispose();// 销毁窗体
		} else {
     
			JOptionPane.showMessageDialog(this, "用户名或密码错误!");
		}
	}

	/**
	 * 重置事件处理
	 * 
	 * @param e
	 */
	private void resetValueActionPerformed(ActionEvent evt) {
     
		this.userNameTxt.setText("");
		this.passwordTxt.setText("");
		userNameTxt.requestFocus();

	}

	/**
	 * 注册事件处理
	 * 
	 * @param e
	 */
	private void enrollValueActionPerformed(ActionEvent e) {
     

		String str = JOptionPane.showInputDialog(this, "输入超级管理员密码", "KEY", 2);
		TbPerson p = PersonDao.findPersonByRecordNumber("T00001");
		if (str == null) {
     
			return;
		} else if ("".equals(str)) {
     
			JOptionPane.showMessageDialog(this, "请至少输入一个字符", "", 1);
		} else if (p.getPassword().equals(PwEncryption.encrypt(str, "key"))) {
     
			// }else if (str.equals(p.getPassword())) {
     
			this.setVisible(false);
			dispose();
			EnrolmentFrame enrollFrame = new EnrolmentFrame();
			enrollFrame.setVisible(true);
		} else {
     
			JOptionPane.showMessageDialog(this, "密码错误", "", 0);
		}

	}

	/**
	 * 登陆窗口
	 */
	public static void main(String[] args) {
     

		LoginFrame frame = new LoginFrame();
		frame.setVisible(true);
	}

}

四、其他

1.其他系统实现

Java+Swing实现仓库管理系统
Java+Swing实现学生信息管理系统
Java+Swing实现学生宿舍管理系统
Java+Swing实现学生选课管理系统
Java+Swing实现电子相册管理系统
Java+Swing实现图书管理系统
Java+Swing实现斗地主游戏
Java+Swing实现宠物商店管理系统
Java+Swing实现学生成绩管理系统

2.获取源码

请联系QQ:3079118617

3.备注

如有侵权请联系我删除。

你可能感兴趣的:(Java,mysql,jdbc,erp)