IT评测·应用市场-qidao123.com技术社区

标题: 基于javaswing和mysql实现的员工工资管理系统 [打印本页]

作者: 王國慶    时间: 2024-7-14 10:16
标题: 基于javaswing和mysql实现的员工工资管理系统
项目上传到了github,下载EPMS文件夹即可,源码都在里面,记得给我一个star
https://github.com/XK-coding/projects.git
  

  
工资管理系统EPMS

这个项目是基于javaswing和mysql数据库所开发的
java编译器是eclipse,版本是2020-12-R
mysql管理工具是navicat,版本是8.1
1.功能模块计划

1.1java语言连接数据库jdbc

我们要通过java来操作数据库,起首就要把他们连接起来
代码实现逻辑:
四参五步:我们需要四个参数和五个步调来成功连接数据库,在这之前,我们需要创建一个lib文件夹,然后再导入我们所需要的mysql-connector的jar包
四参:
五步:
代码如下:
  1. package com.jdbc;
  2. import java.sql.Connection;
  3. import java.sql.DriverManager;
  4. import java.sql.PreparedStatement;
  5. import java.sql.ResultSet;
  6. import java.sql.SQLException;
  7. public class DBConnection {
  8.         //1.加载jdbc连接mysql的驱动
  9.         public final static String driver = "com.mysql.cj.jdbc.Driver";
  10.        
  11.         //2.连接mysql数据库的地址
  12.         public final static String url = "jdbc:mysql://localhost:3306/wages";
  13.        
  14.         //3.连接mysql的用户名
  15.         public final static String user = "root";
  16.        
  17.         //4.连接mysql的密码
  18.         public final static String pwd = "txk0x7d2";
  19.        
  20.         //static静态代码块加载jdbc的驱动
  21.         static {
  22.                 try {
  23.                         Class.forName(driver);
  24.                 } catch (ClassNotFoundException e) {
  25.                         // TODO Auto-generated catch block
  26.                         e.printStackTrace();
  27.                 }
  28.         }
  29.        
  30.         //连接mysql的连接对象
  31.         public static Connection getConn() {
  32.                 try {
  33.                         return DriverManager.getConnection(url, user, pwd);
  34.                 } catch (SQLException e) {
  35.                         // TODO Auto-generated catch block
  36.                         e.printStackTrace();
  37.                 }
  38.                 return null;
  39.         }
  40.        
  41.         //关闭连接,保证mysql资源的释放,能够充分使用资源
  42.         public static void close(ResultSet rs, PreparedStatement ps, Connection conn) {
  43.                 try {
  44.                         if (rs != null) {
  45.                                 rs.close();
  46.                         }
  47.                         if (ps != null) {
  48.                                 ps.close();
  49.                         }
  50.                         if (conn != null) {
  51.                                 conn.close();
  52.                         }
  53.                 } catch (Exception e) {
  54.                         // TODO Auto-generated catch block
  55.                         e.printStackTrace();
  56.                 }
  57.         }
  58.        
  59.         //验证jdbc的使用
  60.         public static void main(String[] args) {
  61.                 System.out.println(getConn()+"数据库连接成功!");
  62.         }
  63. }
复制代码
1.2系统登录Login

系统登录界面如图所示:

代码实现逻辑:

代码实现:
  1. package com.ui;
  2. import java.awt.EventQueue;
  3. import javax.swing.JFrame;
  4. import javax.swing.JPanel;
  5. import javax.swing.border.EmptyBorder;
  6. import com.dao.AccountDAO;
  7. import com.entity.Account;
  8. import com.entity.UserType;
  9. import com.util.StringUtil;
  10. import javax.swing.JLabel;
  11. import javax.swing.JOptionPane;
  12. import java.awt.Font;
  13. import javax.swing.JTextField;
  14. import javax.swing.JPasswordField;
  15. import javax.swing.JComboBox;
  16. import javax.swing.DefaultComboBoxModel;
  17. import javax.swing.JButton;
  18. import java.awt.event.ActionListener;
  19. import java.awt.event.ActionEvent;
  20. public class Login extends JFrame {
  21.         private JPanel contentPane;
  22.         private JTextField userNameTextField;
  23.         private JComboBox userTypeComboBox;
  24.         private JTextField passwordField;
  25.         /**
  26.          * Launch the application.
  27.          */
  28.         public static void main(String[] args) {
  29.                 EventQueue.invokeLater(new Runnable() {
  30.                         public void run() {
  31.                                 try {
  32.                                         Login frame = new Login();
  33.                                         frame.setVisible(true);
  34.                                 } catch (Exception e) {
  35.                                         e.printStackTrace();
  36.                                 }
  37.                         }
  38.                 });
  39.         }
  40.         /**
  41.          * Create the frame.
  42.          */
  43.         public Login() {
  44.                 setResizable(false);
  45.                 setTitle("\u767B\u5F55");
  46.                 setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  47.                 setBounds(100, 100, 330, 311);
  48.                 contentPane = new JPanel();
  49.                 contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
  50.                 setContentPane(contentPane);
  51.                 contentPane.setLayout(null);
  52.                
  53.                 JLabel lblNewLabel = new JLabel("\u8D26\u53F7\uFF1A");
  54.                 lblNewLabel.setFont(new Font("宋体", Font.PLAIN, 18));
  55.                 lblNewLabel.setBounds(26, 51, 70, 25);
  56.                 contentPane.add(lblNewLabel);
  57.                
  58.                 userNameTextField = new JTextField();
  59.                 userNameTextField.setBounds(85, 53, 150, 24);
  60.                 contentPane.add(userNameTextField);
  61.                 userNameTextField.setColumns(10);
  62.                
  63.                 JLabel lblNewLabel_1 = new JLabel("\u5BC6\u7801\uFF1A");
  64.                 lblNewLabel_1.setFont(new Font("宋体", Font.PLAIN, 18));
  65.                 lblNewLabel_1.setBounds(26, 104, 70, 25);
  66.                 contentPane.add(lblNewLabel_1);
  67.                
  68.                 userTypeComboBox = new JComboBox();
  69.                 userTypeComboBox.setModel(new DefaultComboBoxModel(new UserType[] {UserType.ADMIN, UserType.EMPLOYEE}));
  70.                 userTypeComboBox.setBounds(122, 157, 113, 23);
  71.                 contentPane.add(userTypeComboBox);
  72.                
  73.                 JButton loginButton = new JButton("\u767B\u5F55");
  74.                 loginButton.addActionListener(new ActionListener() {
  75.                         public void actionPerformed(ActionEvent ae) {
  76.                                 //登录按钮绑定事件
  77.                                 loginAct(ae);
  78.                         }
  79.                 });
  80.                 loginButton.setBounds(26, 198, 93, 23);
  81.                 contentPane.add(loginButton);
  82.                
  83.                 JButton disposeButton = new JButton("\u9000\u51FA");
  84.                 disposeButton.addActionListener(new ActionListener() {
  85.                         public void actionPerformed(ActionEvent e) {
  86.                                 //退出
  87.                                 dispose();
  88.                         }
  89.                 });
  90.                 disposeButton.setBounds(214, 238, 93, 23);
  91.                 contentPane.add(disposeButton);
  92.                
  93.                 JLabel lblNewLabel_2 = new JLabel("\u5DE5\u8D44\u7BA1\u7406\u7CFB\u7EDF\u767B\u5F55");
  94.                 lblNewLabel_2.setFont(new Font("宋体", Font.PLAIN, 24));
  95.                 lblNewLabel_2.setBounds(61, 10, 206, 31);
  96.                 contentPane.add(lblNewLabel_2);
  97.                
  98.                 JButton registerButton = new JButton("\u6CE8\u518C");
  99.                 registerButton.setBounds(161, 198, 93, 23);
  100.                 contentPane.add(registerButton);
  101.                
  102.                 passwordField = new JTextField();
  103.                 passwordField.setColumns(10);
  104.                 passwordField.setBounds(85, 107, 150, 24);
  105.                 contentPane.add(passwordField);
  106.         }
  107.         protected void loginAct(ActionEvent ae) {
  108.                 // TODO Auto-generated method stub
  109.                 String userName = userNameTextField.getText().toString();
  110.                 String password = passwordField.getText().toString();
  111.                 UserType selectedItem = (UserType)userTypeComboBox.getSelectedItem();
  112.                 //判断用户名是否为空
  113.                 if (StringUtil.isEmpty(userName)) {
  114.                         JOptionPane.showMessageDialog(this, "用户名不能为空!");
  115.                         return;
  116.                 }
  117.                 //判断密码是否为空
  118.                 if (StringUtil.isEmpty(password)) {
  119.                         JOptionPane.showMessageDialog(this, "密码不能为空!");
  120.                         return;
  121.                 }
  122.                
  123.                 if ("系统管理员".equals(selectedItem.getName())) {
  124.                         //系统管理员登录
  125.                         AccountDAO accountDAO = new AccountDAO();
  126.                         Account accountTmp = new Account();
  127.                         accountTmp.setZhanghao(userName);
  128.                         accountTmp.setPassword(password);
  129.                         Account account = accountDAO.login(accountTmp);
  130.                         if (account == null) {
  131.                                 JOptionPane.showMessageDialog(this, "用户名或密码错误!");
  132.                                 return;
  133.                         } else {
  134.                                 JOptionPane.showMessageDialog(this, "登录成功!");
  135.                                 AdminSystem frame = new AdminSystem();
  136.                                 frame.setVisible(true);
  137.                                 dispose();
  138.                         }
  139.                 } else {
  140.                         //员工登录
  141.                 }
  142.         }
  143. }
复制代码
1.3实体类计划entity

我们要通过java来操作数据库中表里面的数据,那么数据库中的每一张表就对应着java里面的一个实体类,所以我们在这里创建账号表account所对应的实体类Account
代码实现逻辑:

代码如下:
  1. package com.entity;
  2. public class Account {
  3.         private int id;
  4.         private String zhanghao;
  5.         private String password;
  6.         public int getId() {
  7.                 return id;
  8.         }
  9.         public void setId(int id) {
  10.                 this.id = id;
  11.         }
  12.         public String getZhanghao() {
  13.                 return zhanghao;
  14.         }
  15.         public void setZhanghao(String zhanghao) {
  16.                 this.zhanghao = zhanghao;
  17.         }
  18.         public String getPassword() {
  19.                 return password;
  20.         }
  21.         public void setPassword(String password) {
  22.                 this.password = password;
  23.         }
  24. }
复制代码
1.4管理员系统AdminSystem

通过管理员选项登录成功后我们会创建一个管理员系统的界面,如图所示

在这里,我们先介绍员工工资管理,点进去后我们会跳转到员工工资管理界面
代码实现逻辑:
这一个主要是ui的计划,而我是通过javaswing来计划的,用eclipse里面扩展的功能WindowBuilder来图形化创建界面,最后给按钮绑定点击事件即可。
代码实现如下:
  1. package com.ui;
  2. import java.awt.EventQueue;
  3. import javax.swing.JFrame;
  4. import javax.swing.JPanel;
  5. import javax.swing.border.EmptyBorder;
  6. import javax.swing.JButton;
  7. import java.awt.event.ActionListener;
  8. import java.awt.event.ActionEvent;
  9. public class AdminSystem extends JFrame {
  10.         private JPanel contentPane;
  11.         /**
  12.          * Launch the application.
  13.          */
  14.         public static void main(String[] args) {
  15.                 EventQueue.invokeLater(new Runnable() {
  16.                         public void run() {
  17.                                 try {
  18.                                         AdminSystem frame = new AdminSystem();
  19.                                         frame.setVisible(true);
  20.                                 } catch (Exception e) {
  21.                                         e.printStackTrace();
  22.                                 }
  23.                         }
  24.                 });
  25.         }
  26.         /**
  27.          * Create the frame.
  28.          */
  29.         public AdminSystem() {
  30.                 setResizable(false);
  31.                 setTitle("\u7BA1\u7406\u5458\u7CFB\u7EDF");
  32.                 setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  33.                 setBounds(100, 100, 323, 207);
  34.                 contentPane = new JPanel();
  35.                 contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
  36.                 setContentPane(contentPane);
  37.                 contentPane.setLayout(null);
  38.                
  39.                 JButton btnNewButton = new JButton("\u5458\u5DE5\u4FE1\u606F\u7BA1\u7406");
  40.                 btnNewButton.addActionListener(new ActionListener() {
  41.                         public void actionPerformed(ActionEvent e) {
  42.                         }
  43.                 });
  44.                 btnNewButton.setBounds(10, 26, 121, 23);
  45.                 contentPane.add(btnNewButton);
  46.                
  47.                 JButton btnNewButton_1 = new JButton("\u5458\u5DE5\u5DE5\u8D44\u7BA1\u7406");
  48.                 btnNewButton_1.addActionListener(new ActionListener() {
  49.                         public void actionPerformed(ActionEvent e) {
  50.                                 AdminWages frame = new AdminWages();
  51.                                 frame.setVisible(true);
  52.                         }
  53.                 });
  54.                 btnNewButton_1.setBounds(157, 26, 121, 23);
  55.                 contentPane.add(btnNewButton_1);
  56.                
  57.                 JButton btnNewButton_2 = new JButton("\u5458\u5DE5\u8003\u52E4\u7BA1\u7406");
  58.                 btnNewButton_2.setBounds(10, 76, 121, 23);
  59.                 contentPane.add(btnNewButton_2);
  60.                
  61.                 JButton btnNewButton_3 = new JButton("\u5458\u5DE5\u6D25\u8D34\u7BA1\u7406");
  62.                 btnNewButton_3.setBounds(157, 76, 121, 23);
  63.                 contentPane.add(btnNewButton_3);
  64.                
  65.                 JButton btnNewButton_3_1 = new JButton("\u9000\u51FA\u7CFB\u7EDF");
  66.                 btnNewButton_3_1.addActionListener(new ActionListener() {
  67.                         public void actionPerformed(ActionEvent e) {
  68.                                 dispose();
  69.                         }
  70.                 });
  71.                 btnNewButton_3_1.setBounds(100, 124, 95, 29);
  72.                 contentPane.add(btnNewButton_3_1);
  73.         }
  74. }
复制代码
2.员工工资管理AdminWages

员工工资管理功能则包含了对员工工资信息的增编削查,下面会分别介绍这几个功能
2.1员工工资添加功能

代码实现逻辑:

  1.         //增加功能
  2.         public boolean add(Wages wages) {
  3.                
  4.                 //1.连接mysql
  5.                 Connection conn = DBConnection.getConn();
  6.                
  7.                 //2.预编译sql执行
  8.                 String sql = "insert into wages values(?,?,?,?,?,?,?)";
  9.                 try {
  10.                         PreparedStatement ps = conn.prepareCall(sql);
  11.                         ps.setInt(1, wages.getCode());
  12.                         ps.setInt(2, wages.getBaseWages());
  13.                         ps.setInt(3, wages.getPostWages());
  14.                         ps.setFloat(4, (float) wages.getMoney());
  15.                         ps.setInt(5, wages.getSubsidy());
  16.                         ps.setInt(6, wages.getDeduction());
  17.                         ps.setFloat(7, (float) wages.getFact());
  18.                         //执行操作更改
  19.                         boolean result = ps.executeUpdate() > 0;
  20.                         //关闭数据库
  21.                         DBConnection.close(null, ps, conn);
  22.                         return result;
  23.                 } catch (SQLException e) {
  24.                         // TODO Auto-generated catch block
  25.                         e.printStackTrace();
  26.                 }
  27.                 return false;
  28.         }
复制代码
2.2员工工资修改功能

和添加功能差不多,只是sql语句不一样
  1. //修改功能
  2.         public boolean update(Wages wages) {
  3.                
  4.                 //1.连接mysql
  5.                 Connection conn = DBConnection.getConn();
  6.                
  7.                 //2.预编译sql执行
  8.                 String sql = "update wages set baseWages=?,postWages=?,money=?,subsidy=?,deduction=?,fact=? where code=?";
  9.                 try {
  10.                         PreparedStatement ps = conn.prepareCall(sql);
  11.                        
  12.                         ps.setInt(1, wages.getBaseWages());
  13.                         ps.setInt(2, wages.getPostWages());
  14.                         ps.setFloat(3, (float) wages.getMoney());
  15.                         ps.setInt(4, wages.getSubsidy());
  16.                         ps.setInt(5, wages.getDeduction());
  17.                         ps.setFloat(6, (float) wages.getFact());
  18.                         ps.setInt(7, wages.getCode());
  19.                         //执行操作更改
  20.                         boolean result = ps.executeUpdate() > 0;
  21.                         //关闭数据库
  22.                         DBConnection.close(null, ps, conn);
  23.                         return result;
  24.                 } catch (SQLException e) {
  25.                         // TODO Auto-generated catch block
  26.                         e.printStackTrace();
  27.                 }
  28.                 return false;
  29.         }
复制代码
2.3员工工资删除功能


  1. //删除功能
  2.         public boolean delete(String val) {
  3.                
  4.                 //1.连接mysql
  5.                 Connection conn = DBConnection.getConn();
  6.                
  7.                 //2.预编译sql执行
  8.                 String sql = "delete from wages where code=?";
  9.                 try {
  10.                         PreparedStatement ps = conn.prepareCall(sql);
  11.                        
  12.                         ps.setString(1,val);
  13.                        
  14.                         //执行操作更改
  15.                         boolean result = ps.executeUpdate() > 0;
  16.                         //关闭数据库
  17.                         DBConnection.close(null, ps, conn);
  18.                         return result;
  19.                 } catch (SQLException e) {
  20.                         // TODO Auto-generated catch block
  21.                         e.printStackTrace();
  22.                 }
  23.                 return false;
  24.         }
复制代码
2.4员工工资查询单个员工工资功能

大部分步调和添加功能差不多,
区别在于:
  1. //查询指定员工
  2.                 public Wages query(int code) {
  3.                        
  4.                         //1.连接mysql
  5.                         Connection conn = DBConnection.getConn();
  6.                        
  7.                         //2.预编译sql执行
  8.                         String sql = "select * from wages where code=?";
  9.                         try {
  10.                                 PreparedStatement ps = conn.prepareCall(sql);
  11.                                
  12.                                 ps.setInt(1,code);
  13.                                
  14.                                 //执行操作更改
  15.                                 ResultSet rs = ps.executeQuery();
  16.                                 //创建一份工资对象返回
  17.                                 Wages w = new Wages();
  18.                                 while (rs.next()) {
  19.                                         w.setCode(rs.getInt(1));
  20.                                         w.setBaseWages(rs.getInt(2));
  21.                                         w.setPostWages(rs.getInt(3));
  22.                                         w.setMoney(rs.getDouble(4));
  23.                                         w.setSubsidy(rs.getInt(5));
  24.                                         w.setDeduction(rs.getInt(6));
  25.                                         w.setMoney(rs.getDouble(7));
  26.                                 }
  27.                                
  28.                                
  29.                                 //关闭数据库
  30.                                 DBConnection.close(rs, ps, conn);
  31.                                 return w;
  32.                         } catch (SQLException e) {
  33.                                 // TODO Auto-generated catch block
  34.                                 e.printStackTrace();
  35.                         }
  36.                         return null;
  37.                 }
复制代码
2.5员工工资查询全部员工工资功能

查询全部列和查询指定列大部分一样
区别在于:
  1. //查询所有员工工资信息 keyword用于搜索模糊查询
  2.         public Vector<Vector<String>> getAll(String keyword) {
  3.                 //1.连接mysql
  4.                 Connection conn = DBConnection.getConn();
  5.                
  6.                 //2.预编译sql执行
  7.                 String sql = "select * from wages";
  8.                 //如果有关键字,则把它拼接到查询语句当中作限制条件
  9.                 if (keyword != null) {
  10.                         sql += " where code like '%"+keyword+"%'";
  11.                 }
  12.                 try {
  13.                         PreparedStatement ps = conn.prepareStatement(sql);
  14.                        
  15.                         //执行操作更改
  16.                         ResultSet rs = ps.executeQuery();
  17.                         //创建一个二维数组返回
  18.                         Vector<Vector<String>> list = new Vector<Vector<String>>();
  19.                        
  20.                         while (rs.next()) {
  21.                                 Vector<String> w = new Vector<String>();
  22.                                 w.add(rs.getString(1));
  23.                                 w.add(rs.getString(2));
  24.                                 w.add(rs.getString(3));
  25.                                 w.add(rs.getString(4));
  26.                                 w.add(rs.getString(5));
  27.                                 w.add(rs.getString(6));
  28.                                 w.add(rs.getString(7));
  29.                                
  30.                                 //把当前对象存储到list集合中
  31.                                 list.add(w);
  32.                         }
  33.                         //关闭数据库
  34.                         DBConnection.close(rs, ps, conn);
  35.                         return list;
  36.                
  37.                 } catch (SQLException e) {
  38.                         // TODO Auto-generated catch block
  39.                         e.printStackTrace();
  40.                 }
  41.                 return null;
  42.         }
复制代码
3.员工工资管理AdminWages的界面计划

这是我们AdminWages的界面图:

3.1员工工资查询功能

起首界面的UI计划是通过WindowBuilder直接图形化创建的,我们只是给这个“查询”按钮添加一个点击事件
代码实现逻辑:
  1. JButton btnNewButton = new JButton("\u67E5\u8BE2");
  2.                 btnNewButton.addActionListener(new ActionListener() {
  3.                         public void actionPerformed(ActionEvent e) {
  4.                                 //查询员工工资信息,如果有关键字就模糊搜索,反之查询全部
  5.                                 String keyword = textField.getText();
  6.                                 WagesDAO w = new WagesDAO();
  7.                                 Vector<Vector<String>> list = w.getAll(keyword);
  8.                                
  9.                                 Vector<String> head =  new Vector<String>();
  10.                                 head.add("员工编号");
  11.                                 head.add("基本工资");
  12.                                 head.add("岗位工资");
  13.                                 head.add("水电费");
  14.                                 head.add("津贴费");
  15.                                 head.add("扣除工资");
  16.                                 head.add("实发金额");
  17.                                
  18.                                 //3.设置值
  19.                                 table = new JTable(list,head);
  20.                                 scrollPane.setViewportView(table);
  21.                                
  22.                         }
  23.                 });
  24.                 btnNewButton.setBounds(196, 29, 93, 23);
  25.                 contentPane.add(btnNewButton);
复制代码
3.2员工工资添加功能

界面如图所示:

代码实现逻辑:
  1. //AdminInsertWages
  2. package com.ui;
  3. import java.awt.EventQueue;
  4. import javax.swing.JFrame;
  5. import javax.swing.JPanel;
  6. import javax.swing.border.EmptyBorder;
  7. import com.dao.WagesDAO;
  8. import com.entity.Wages;
  9. import javax.swing.JLabel;
  10. import javax.swing.JOptionPane;
  11. import javax.swing.JTextField;
  12. import javax.swing.JButton;
  13. import java.awt.event.ActionListener;
  14. import java.awt.event.ActionEvent;
  15. public class AdminInsertWages extends JFrame {
  16.         private JPanel contentPane;
  17.         private JTextField code;
  18.         private JTextField baseWages;
  19.         private JTextField postWages;
  20.         private JTextField money;
  21.         private JTextField subsidy;
  22.         private JTextField deduction;
  23.         private JTextField fact;
  24.         /**
  25.          * Launch the application.
  26.          */
  27.         public static void main(String[] args) {
  28.                 EventQueue.invokeLater(new Runnable() {
  29.                         public void run() {
  30.                                 try {
  31.                                         AdminInsertWages frame = new AdminInsertWages();
  32.                                         frame.setVisible(true);
  33.                                 } catch (Exception e) {
  34.                                         e.printStackTrace();
  35.                                 }
  36.                         }
  37.                 });
  38.         }
  39.         /**
  40.          * Create the frame.
  41.          */
  42.         public AdminInsertWages() {
  43.                 setTitle("\u6DFB\u52A0\u5458\u5DE5\u5DE5\u8D44\u4FE1\u606F");
  44.                 setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  45.                 setBounds(100, 100, 305, 418);
  46.                 contentPane = new JPanel();
  47.                 contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
  48.                 setContentPane(contentPane);
  49.                 contentPane.setLayout(null);
  50.                
  51.                 JLabel lblNewLabel = new JLabel("\u5458\u5DE5\u7F16\u53F7\uFF1A");
  52.                 lblNewLabel.setBounds(28, 27, 90, 27);
  53.                 contentPane.add(lblNewLabel);
  54.                
  55.                 JLabel 基本工资 = new JLabel("\u57FA\u672C\u5DE5\u8D44\uFF1A");
  56.                 基本工资.setBounds(28, 64, 90, 27);
  57.                 contentPane.add(基本工资);
  58.                
  59.                 JLabel 岗位工资 = new JLabel("\u5C97\u4F4D\u5DE5\u8D44\uFF1A");
  60.                 岗位工资.setBounds(28, 109, 90, 27);
  61.                 contentPane.add(岗位工资);
  62.                
  63.                 JLabel lblNewLabel_3 = new JLabel("\u6C34\u7535\u8D39\uFF1A");
  64.                 lblNewLabel_3.setBounds(28, 154, 90, 27);
  65.                 contentPane.add(lblNewLabel_3);
  66.                
  67.                 JLabel lblNewLabel_4 = new JLabel("\u6D25\u8D34\u5DE5\u8D44\uFF1A");
  68.                 lblNewLabel_4.setBounds(28, 197, 90, 27);
  69.                 contentPane.add(lblNewLabel_4);
  70.                
  71.                 JLabel lblNewLabel_5 = new JLabel("\u6263\u9664\u85AA\u916C\uFF1A");
  72.                 lblNewLabel_5.setBounds(28, 244, 90, 27);
  73.                 contentPane.add(lblNewLabel_5);
  74.                
  75.                 JLabel lblNewLabel_6 = new JLabel("\u5B9E\u53D1\u5DE5\u8D44\uFF1A");
  76.                 lblNewLabel_6.setBounds(28, 288, 90, 27);
  77.                 contentPane.add(lblNewLabel_6);
  78.                
  79.                 code = new JTextField();
  80.                 code.setBounds(107, 30, 108, 21);
  81.                 contentPane.add(code);
  82.                 code.setColumns(10);
  83.                
  84.                 baseWages = new JTextField();
  85.                 baseWages.setColumns(10);
  86.                 baseWages.setBounds(107, 67, 108, 21);
  87.                 contentPane.add(baseWages);
  88.                
  89.                 postWages = new JTextField();
  90.                 postWages.setColumns(10);
  91.                 postWages.setBounds(107, 112, 108, 21);
  92.                 contentPane.add(postWages);
  93.                
  94.                 money = new JTextField();
  95.                 money.setColumns(10);
  96.                 money.setBounds(107, 157, 108, 21);
  97.                 contentPane.add(money);
  98.                
  99.                 subsidy = new JTextField();
  100.                 subsidy.setColumns(10);
  101.                 subsidy.setBounds(107, 200, 108, 21);
  102.                 contentPane.add(subsidy);
  103.                
  104.                 deduction = new JTextField();
  105.                 deduction.setColumns(10);
  106.                 deduction.setBounds(107, 247, 108, 21);
  107.                 contentPane.add(deduction);
  108.                
  109.                 fact = new JTextField();
  110.                 fact.setColumns(10);
  111.                 fact.setBounds(107, 291, 108, 21);
  112.                 contentPane.add(fact);
  113.                
  114.                 JButton btnNewButton = new JButton("\u6DFB\u52A0");
  115.                 btnNewButton.addActionListener(new ActionListener() {
  116.                         public void actionPerformed(ActionEvent e) {
  117.                                 //添加信息
  118.                                 Wages wages = new Wages();
  119. //                                WagesDAO w = new WagesDAO();
  120.                                 //因为不能int直接转string所以要转换类型
  121.                                 String codes = code.getText();
  122.                                 int code = Integer.valueOf(codes);
  123.                                 wages.setCode(code);
  124.                                
  125.                                 String baseWagess = baseWages.getText();
  126.                                 int baseWages = Integer.valueOf(baseWagess);
  127.                                 wages.setBaseWages(baseWages);
  128.                                
  129.                                 String postWagess = postWages.getText();
  130.                                 int postWages = Integer.valueOf(postWagess);
  131.                                 wages.setPostWages(postWages);
  132.                                
  133.                                 String moneys = money.getText();
  134.                                 double money = Double.valueOf(moneys);
  135.                                 wages.setMoney(money);
  136.                                
  137.                                 String subsidys = subsidy.getText();
  138.                                 int subsidy = Integer.valueOf(subsidys);
  139.                                 wages.setSubsidy(subsidy);
  140.                                
  141.                                 String deductions = deduction.getText();
  142.                                 int deduction = Integer.valueOf(deductions);
  143.                                 wages.setDeduction(deduction);
  144.                                
  145.                                 String facts = fact.getText();
  146.                                 double fact = Double.valueOf(facts);
  147.                                 wages.setFact(fact);
  148.                                
  149.                                 //执行添加
  150.                                 WagesDAO w = new WagesDAO();
  151.                                 if(w.add(wages)){
  152.                     JOptionPane.showMessageDialog(null, "添加成功!");
  153.                     
  154.                 }else {
  155.                     JOptionPane.showMessageDialog(null, "添加失败!");
  156.                 }
  157.                         }
  158.                 });
  159.                 btnNewButton.setBounds(25, 346, 93, 23);
  160.                 contentPane.add(btnNewButton);
  161.                
  162.                 JButton btnNewButton_1 = new JButton("\u9000\u51FA");
  163.                 btnNewButton_1.addActionListener(new ActionListener() {
  164.                         public void actionPerformed(ActionEvent e) {
  165.                                 //退出
  166.                                 dispose();
  167.                         }
  168.                 });
  169.                 btnNewButton_1.setBounds(160, 346, 93, 23);
  170.                 contentPane.add(btnNewButton_1);
  171.         }
  172. }
  173. //AdminWages
  174. JButton btnNewButton_1 = new JButton("\u6DFB\u52A0\u4FE1\u606F");
  175.                 btnNewButton_1.addActionListener(new ActionListener() {
  176.                         public void actionPerformed(ActionEvent e) {
  177.                                 //添加信息
  178.                                 AdminInsertWages frame = new AdminInsertWages();
  179.                                 frame.setVisible(true);
  180.                         }
  181.                 });
  182.                 btnNewButton_1.setBounds(314, 29, 93, 23);
  183.                 contentPane.add(btnNewButton_1);
复制代码
3.3员工工资修改功能

界面如图所示:

代码实现逻辑:
  1. //AdminUpdateWages
  2. package com.ui;
  3. import java.awt.EventQueue;
  4. import javax.swing.JFrame;
  5. import javax.swing.JPanel;
  6. import javax.swing.border.EmptyBorder;
  7. import com.dao.WagesDAO;
  8. import com.entity.Wages;
  9. import javax.swing.JLabel;
  10. import javax.swing.JOptionPane;
  11. import javax.swing.JTextField;
  12. import javax.swing.JButton;
  13. import java.awt.event.ActionListener;
  14. import java.awt.event.ActionEvent;
  15. public class AdminUpdateWages extends JFrame {
  16.         private JPanel contentPane;
  17.         private JTextField code;
  18.         private JTextField baseWages;
  19.         private JTextField postWages;
  20.         private JTextField money;
  21.         private JTextField subsidy;
  22.         private JTextField deduction;
  23.         private JTextField fact;
  24.         /**
  25.          * Launch the application.
  26.          */
  27.         public static void main(String[] args) {
  28.                 EventQueue.invokeLater(new Runnable() {
  29.                         public void run() {
  30.                                 try {
  31.                                         AdminUpdateWages frame = new AdminUpdateWages(5);
  32.                                         frame.setVisible(true);
  33.                                 } catch (Exception e) {
  34.                                         e.printStackTrace();
  35.                                 }
  36.                         }
  37.                 });
  38.         }
  39.         /**
  40.          * Create the frame.
  41.          */
  42.         public AdminUpdateWages(int id) {
  43.                 //查询工资信息回来
  44.                 WagesDAO w = new WagesDAO();
  45.                 Wages wages = w.query(id);
  46.                
  47.                 setTitle("修改信息");
  48.                 setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  49.                 setBounds(100, 100, 305, 418);
  50.                 contentPane = new JPanel();
  51.                 contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
  52.                 setContentPane(contentPane);
  53.                 contentPane.setLayout(null);
  54.                
  55.                 JLabel lblNewLabel = new JLabel("\u5458\u5DE5\u7F16\u53F7\uFF1A");
  56.                 lblNewLabel.setBounds(28, 27, 90, 27);
  57.                 contentPane.add(lblNewLabel);
  58.                
  59.                 JLabel 基本工资 = new JLabel("\u57FA\u672C\u5DE5\u8D44\uFF1A");
  60.                 基本工资.setBounds(28, 64, 90, 27);
  61.                 contentPane.add(基本工资);
  62.                
  63.                 JLabel 岗位工资 = new JLabel("\u5C97\u4F4D\u5DE5\u8D44\uFF1A");
  64.                 岗位工资.setBounds(28, 109, 90, 27);
  65.                 contentPane.add(岗位工资);
  66.                
  67.                 JLabel lblNewLabel_3 = new JLabel("\u6C34\u7535\u8D39\uFF1A");
  68.                 lblNewLabel_3.setBounds(28, 154, 90, 27);
  69.                 contentPane.add(lblNewLabel_3);
  70.                
  71.                 JLabel lblNewLabel_4 = new JLabel("\u6D25\u8D34\u5DE5\u8D44\uFF1A");
  72.                 lblNewLabel_4.setBounds(28, 197, 90, 27);
  73.                 contentPane.add(lblNewLabel_4);
  74.                
  75.                 JLabel lblNewLabel_5 = new JLabel("\u6263\u9664\u85AA\u916C\uFF1A");
  76.                 lblNewLabel_5.setBounds(28, 244, 90, 27);
  77.                 contentPane.add(lblNewLabel_5);
  78.                
  79.                 JLabel lblNewLabel_6 = new JLabel("\u5B9E\u53D1\u5DE5\u8D44\uFF1A");
  80.                 lblNewLabel_6.setBounds(28, 288, 90, 27);
  81.                 contentPane.add(lblNewLabel_6);
  82.                
  83.                 //员工编号
  84.                 //除了String,都要类型转换
  85.                 String codes = String.valueOf(wages.getCode());
  86.                 code = new JTextField(codes);
  87.                 code.setBounds(107, 30, 108, 21);
  88.                 contentPane.add(code);
  89.                 code.setColumns(10);
  90.                
  91.                 //基本工资
  92.                 String baseWagess = String.valueOf(wages.getBaseWages());
  93.                 baseWages = new JTextField(baseWagess);
  94.                 baseWages.setColumns(10);
  95.                 baseWages.setBounds(107, 67, 108, 21);
  96.                 contentPane.add(baseWages);
  97.                
  98.                 //岗位工资
  99.                 String postWagess = String.valueOf(wages.getPostWages());
  100.                 postWages = new JTextField(postWagess);
  101.                 postWages.setColumns(10);
  102.                 postWages.setBounds(107, 112, 108, 21);
  103.                 contentPane.add(postWages);
  104.                
  105.                 //水电费
  106.                 String moneys = String.valueOf(wages.getMoney());
  107.                 money = new JTextField(moneys);
  108.                 money.setColumns(10);
  109.                 money.setBounds(107, 157, 108, 21);
  110.                 contentPane.add(money);
  111.                
  112.                 //津贴工资
  113.                 String subsidys = String.valueOf(wages.getSubsidy());
  114.                 subsidy = new JTextField(subsidys);
  115.                 subsidy.setColumns(10);
  116.                 subsidy.setBounds(107, 200, 108, 21);
  117.                 contentPane.add(subsidy);
  118.                
  119.                 //扣除薪酬
  120.                 String deductions = String.valueOf(wages.getDeduction());
  121.                 deduction = new JTextField(deductions);
  122.                 deduction.setColumns(10);
  123.                 deduction.setBounds(107, 247, 108, 21);
  124.                 contentPane.add(deduction);
  125.                
  126.                 //实发金额
  127.                 String facts = String.valueOf(wages.getFact());
  128.                 fact = new JTextField(facts);
  129.                 fact.setColumns(10);
  130.                 fact.setBounds(107, 291, 108, 21);
  131.                 contentPane.add(fact);
  132.                
  133.                 JButton btnNewButton = new JButton("修改信息");
  134.                 btnNewButton.addActionListener(new ActionListener() {
  135.                         public void actionPerformed(ActionEvent e) {
  136.                                 //修改信息
  137.                                 Wages wages = new Wages();
  138.                                 wages.setCode(id); //修改时需要获得该修改人的ID
  139.                                 //因为不能int直接转string所以要转换类型
  140.                                 String codes = code.getText();
  141.                                 int code = Integer.valueOf(codes);
  142.                                 wages.setCode(code);
  143.                                
  144.                                 String baseWagess = baseWages.getText();
  145.                                 int baseWages = Integer.valueOf(baseWagess);
  146.                                 wages.setBaseWages(baseWages);
  147.                                
  148.                                 String postWagess = postWages.getText();
  149.                                 int postWages = Integer.valueOf(postWagess);
  150.                                 wages.setPostWages(postWages);
  151.                                
  152.                                 String moneys = money.getText();
  153.                                 double money = Double.valueOf(moneys);
  154.                                 wages.setMoney(money);
  155.                                
  156.                                 String subsidys = subsidy.getText();
  157.                                 int subsidy = Integer.valueOf(subsidys);
  158.                                 wages.setSubsidy(subsidy);
  159.                                
  160.                                 String deductions = deduction.getText();
  161.                                 int deduction = Integer.valueOf(deductions);
  162.                                 wages.setDeduction(deduction);
  163.                                
  164.                                 String facts = fact.getText();
  165.                                 double fact = Double.valueOf(facts);
  166.                                 wages.setFact(fact);
  167.                                
  168.                                 //执行修改
  169.                                 WagesDAO w = new WagesDAO();
  170.                                 if(w.update(wages)){
  171.                     JOptionPane.showMessageDialog(null, "修改成功!");
  172.                     
  173.                 }else {
  174.                     JOptionPane.showMessageDialog(null, "修改失败!");
  175.                 }
  176.                         }
  177.                 });
  178.                 btnNewButton.setBounds(25, 346, 93, 23);
  179.                 contentPane.add(btnNewButton);
  180.                
  181.                 JButton btnNewButton_1 = new JButton("\u9000\u51FA");
  182.                 btnNewButton_1.addActionListener(new ActionListener() {
  183.                         public void actionPerformed(ActionEvent e) {
  184.                                 //退出
  185.                                 dispose();
  186.                         }
  187.                 });
  188.                 btnNewButton_1.setBounds(160, 346, 93, 23);
  189.                 contentPane.add(btnNewButton_1);
  190.         }
  191. }
  192. //AdminWages
  193. JButton btnNewButton_2 = new JButton("\u4FEE\u6539\u4FE1\u606F");
  194.                 btnNewButton_2.addActionListener(new ActionListener() {
  195.                         public void actionPerformed(ActionEvent e) {
  196.                                 //修改信息
  197.                                  int rows = table.getSelectedRow();
  198.                         if(rows == -1) { //没有选中行时得到的是-1
  199.                             JOptionPane.showMessageDialog(null, "请选择行!");
  200.                             return;
  201.                         }
  202.                         //根据行和列,获取对应的数字
  203.                         int val = Integer.valueOf((String)table.getValueAt(rows, 0));
  204.                         System.out.println(table.getValueAt(rows, 0));
  205.                         AdminUpdateWages frame = new AdminUpdateWages(val);
  206.                                         frame.setVisible(true);
  207.                         }
  208.                 });
  209.                 btnNewButton_2.setBounds(423, 29, 93, 23);
  210.                 contentPane.add(btnNewButton_2);
复制代码
3.4员工工资删除功能

代码实现逻辑:
  1. JButton btnNewButton_3 = new JButton("\u5220\u9664\u4FE1\u606F");
  2.                 btnNewButton_3.addActionListener(new ActionListener() {
  3.                         public void actionPerformed(ActionEvent e) {
  4.                                 //删除功能
  5.                                 int rows = table.getSelectedRow();
  6.                                 if (rows == -1) {
  7.                                         JOptionPane.showMessageDialog(null, "请选择行");
  8.                                         return;
  9.                                 }
  10.                                 //根据行和列,获取对应的数字
  11.                                 String val = (String) table.getValueAt(rows, 0);
  12.                                 //去WagesDAO中执行删除
  13.                                 WagesDAO w = new WagesDAO();
  14.                                 boolean result = w.delete(val);
  15.                                 if (result) {
  16.                                         JOptionPane.showMessageDialog(null, "删除成功!");
  17.                                         updateAll(null);
  18.                                 } else {
  19.                                         JOptionPane.showMessageDialog(null, "删除失败!");
  20.                                 }
  21.                         }
  22.                 });
  23.                 btnNewButton_3.setBounds(533, 29, 93, 23);
  24.                 contentPane.add(btnNewButton_3);
复制代码
3.5工资表格更新功能

代码实现逻辑:
  1. //表格更新
  2.         public void updateAll(String keyword) {
  3.                 //表格
  4.                 WagesDAO w = new WagesDAO();
  5.                 Vector<Vector<String>> list = w.getAll(null);
  6.                
  7.                 //2.设置表头
  8.                 Vector<String> head =  new Vector<String>();
  9.                 head.add("员工编号");
  10.                 head.add("基本工资");
  11.                 head.add("岗位工资");
  12.                 head.add("水电费");
  13.                 head.add("津贴费");
  14.                 head.add("扣除工资");
  15.                 head.add("实发金额");
  16.                
  17.                 //3.设置值
  18.                 table = new JTable(list,head);
  19.                 scrollPane.setViewportView(table);
  20.                
  21.         }
复制代码
4.数据库计划wages

4.1账号表计划account

账号表计划三个值,id、账号和密码,其中id为自增
数据如图所示:

创建sql代码:
  1. CREATE TABLE account  (
  2.   id int PRIMARY key NOT NULL,
  3.   zhanghao varchar(20) not NULL,
  4.   password varchar(20) not NULL
  5. )
复制代码
4.2工资表计划wages

工资表创建计划七个值,员工编号、根本工资、岗位工资、水电费、补助、扣除薪酬和实发金额
数据如图所示:

创建sql代码:
  1. CREATE TABLE wages  (
  2.   code int PRIMARY key NOT NULL,
  3.   baseWages int not NULL,
  4.   postWages int not NULL,
  5.   money float(10, 0) not NULL,
  6.   subsidy int not NULL,
  7.   deduction int not NULL,
  8.   
  9.   fact int not NULL
  10. )
复制代码
5.EPMS项目搭建

5.1项目搭建如图所示


5.2项目搭建每个package的作用和相互之间的联系


免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。




欢迎光临 IT评测·应用市场-qidao123.com技术社区 (https://dis.qidao123.com/) Powered by Discuz! X3.4