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

}

public static List findAllDept() {

try {

String sql = “select * from tb_dept”;

List tbDept = template.query(sql, new BeanPropertyRowMapper(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.class), item);

return dept.getId();

}

public static List findAllDeptExceptZero() {

try {

String sql = “select * from tb_dept where id<>0”;

List tbDept = template.query(sql, new BeanPropertyRowMapper(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.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.class), num);

return tbRecord;

} catch (DataAccessException e) {

e.printStackTrace();

return null;

}

}

public static List findAllPerson() {

try {

String sql = “select * from tb_person”;

List tbPerson = template.query(sql, new BeanPropertyRowMapper(TbPerson.class));

return tbPerson;

} catch (DataAccessException e) {

e.printStackTrace();

return null;

}

}

public static List likePersonByRecordNumber(String recordNumber) {

try {

String sql = “select * from tb_person where record_number like ‘%’ ? ‘%’”;

List tbPerson = template.query(sql, new BeanPropertyRowMapper(TbPerson.class),

recordNumber);

return tbPerson;

} catch (DataAccessException e) {

e.printStackTrace();

return null;

}

}

public static List findPersonByDeptId(int i) {

try {

String sql = “select * from tb_person where dept_id=?”;

List tbPerson = template.query(sql, new BeanPropertyRowMapper(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.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.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 likePersonByName(String name) {

try {

String sql = “select * from tb_person where name like ‘%’ ? ‘%’”;

List tbPerson = template.query(sql 《一线大厂Java面试题解析+后端开发学习笔记+最新架构讲解视频+实战项目源码讲义》无偿开源 威信搜索公众号【编程进阶路】 , new BeanPropertyRowMapper(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)) {

你可能感兴趣的:(Java,经验分享,架构,java)