数据库系统课设--人事管理系统

avatar
作者
筋斗云
阅读量:2

目录

前言

一,课程设计的目的

二,总体设计

1 系统需求分析

1.1 系统功能分析

1.2 系统功能模块设计(划分)

1.3 与其它系统的关系

1.4 数据流程图

2 数据库设计

2.1 数据库需求分析

2.2 数据库概念结构设计

2.3 数据库逻辑结构设计

2.4 数据库的建立

2.4.1 数据库的建立

2.4.2 初始数据的输入

3 各功能模块的设计与实现

3.1 功能说明

3.2 用户界面设计

3.3 各功能模块的实现

4 系统实现

4.2 加密模块

4.3 登陆模块

4.4 管理模块

4.5 新员工档案录入模块

4.6 人事变更模块

4.7 管理员员工档案查询修改模块

4.8 员工自身信息查询修改模块

4.9 数据库代码

4.10 数据库表结构

5 界面图预览

5.1 登录界面

5.2 管理界面

5.3 新员工档案录入界面

5.4 人事变更界面

5.5 管理员员工档案查询修改界面

5.6 员工自身信息查询修改界面


前言

        2023.7.30,鉴于大家都要数据库代码,所以重新更新了4.9数据库代码部分。

        2023.11.18,鉴于许多人问数据库部分,新增数据库表结构部分4.10数据库表结构

        本博客内容为课设内容,在这里仅提供思路和代码给大家参考,请不要轻易抄袭,最好理解代码并自己实现题目的要求,锻炼自己的编程和逻辑能力。另外,本次的课程设计我是用命令行操作mysql数据库,使用IDEA编写java程序的。

一,课程设计的目的

数据库系统课程设计是为了配合学习数据库系统原理及应用开发而设置的,是计算机科

学与技术、大数据、信息安全、物联网工程、软件工程、智能制造等专业集中实践的教学环

节,是将关系数据库理论知识转化为解决实际问题能力的重要环节。数据库系统课程设计目

的在于加深对关系数据库理论知识的理解,通过使用具体的 DBMS,掌握一种实际的数据

库管理系统并掌握其操作技术,熟练掌握使用数据库前端开发工具(如 VB、C++、Java、

JSP、Delphi、PowerBuilder 等),进一步提高同学们运用数据库技术解决实际问题的能力。

二,总体设计

企业人事管理系统主要用于员工个人资料的录入、职务变动的记录和管理。使用人事管理系统,便于公司领导掌握人员的动向,及时调整人才的分配。

1 系统需求分析

1.1 系统功能分析

人事管理系统主要有以下几项功能要求:

  • 新员工资料的输入。

  • 自动分配员工号,并且设置初始的用户密码。

  • 人事变动的详细记录,包括岗位和部门的调整。

  • 员工信息的查询和修改,包括员工个人信息和密码等。

1.2 系统功能模块设计(划分)

根据系统功能要求,可以将系统分解成几个模块来

分别设计应用程序界面,如图1 所示。

1.3 与其它系统的关系

本系统是公司管理信息系统的基础部分。为其他子系统,如考勤管理系统、工资管理系统和员工培训系统,提供员工的基本信息。同时为其它系统提供了员工登录的密码认证和权限分配功能。

1.4 数据流程图

人事信息管理系统的数据流程如图2 所示,所有数据由人事科管理人员输入。

2 数据库设计

2.1 数据库需求分析

根据数据流程图,可以列出以下数据项和数据结构:

  • 员工信息:员工号、密码、权限、姓名、性别、生日、专业、通讯地址、 电话、email、当前状态、其他。

  • 人事变动:记录号、员工、变动、详细描述。

  • 所需的外部数据支持:

  • 部门设置:部门编号、名称......

2.2 数据库概念结构设计

图3 是本系统所需数据的 E-R 模型图。

2.3 数据库逻辑结构设计

根据系统E—R 图,本系统需要有 2 个数据表分别来存放员工个人信息和人事变动记录。并且需要 1 个外部数据表(部门信息)的支持。同时部分记录字段需要用代码来表示,因此需要 3 个代码表来分别记录教育程度、职务和人事变更的代码。这 6 个数据表的结构如表 1 到表 6 所示。

2.4 数据库的建立

2.4.1 数据库的建立

创建需要一个数据库即可

2.4.2 初始数据的输入

本系统中需要输入的初始数据包括:部门信息、受教育程度代码、职务代码和人事变动代码。受教育程度代码和人事变动代码如表7 到表 8 所示,部门信息代码和职务代码的设置如图4 所示。

图4、部门信息代码和职务代码

3 各功能模块的设计与实现

3.1 功能说明

1、增加新员工

2、人事变动

3、员工信息查询修改

4、加密模块

5、员工登录

3.2 用户界面设计

完成数据库创建和功能说明以后,我们可以进行下一步工作,即设计用户界面。我们把人事信息管理系统的窗体分以下成 6 个主要部分。

1、主窗口的创建

2、增加新员工窗体的创建

3、人事变动窗体的创建

4、员工信息查询修改窗体的创建

5、加密模块的创建

6、登录窗口的创建

3.3 各功能模块的实现

1、增加新员工的实现

2、人事变动的实现

3、员工信息查询修改的实现

4、加密模块的实现

5、员工登录的实现

4 系统实现

4.1 数据库连接模块

 import java.sql.*; import java.util.ArrayList; import java.util.List;   public class DbProcess{     Connection connection = null;     ResultSet rs = null;      //mysql数据库url     String userMySql="root";      String passwordMySql="xxxx";//xxxx表示自己的数据库密码     String urlMySql = "jdbc:mysql://localhost:3306/CourseDesign?user="             +userMySql+"&password="+passwordMySql + "&serverTimezone=UTC&useUnicode=true&characterEncoding=gbk";          //sqlserver数据库url     //String urlSqlServer = "jdbc:sqlserver://localhost:1433;integratedSecurity=true;DatabaseName=InfoDb";          public DbProcess() {         try {             //mysql数据库设置驱动程序类型             Class.forName("com.mysql.cj.jdbc.Driver");             System.out.println("mysql数据库驱动加载成功");                          //sqlserver数据库设置驱动程序类型         //Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");         //System.out.println("sqlserver数据库驱动加载成功");          }         catch(java.lang.ClassNotFoundException e) {             e.printStackTrace();         }     }      public void connect(){         try{             //mysql数据库             connection = DriverManager.getConnection(urlMySql);                            //sqlserver数据库             //connection = DriverManager.getConnection(urlSqlServer);                           if(connection!=null){                 System.out.println("数据库连接成功");             }         }         catch(Exception e){             e.printStackTrace();         }     }          public void disconnect(){         try{             if(connection != null){                 connection.close();                 connection = null;                 System.out.println("数据库断开成功");             }         }         catch(Exception e){             e.printStackTrace();         }     }       public ResultSet executeQuery(String sql) {         try {             System.out.println("executeQuery(). sql = " + sql);                          PreparedStatement pstm = connection.prepareStatement(sql);             // 执行查询             rs = pstm.executeQuery();         }          catch(SQLException ex) {              ex.printStackTrace();         }         return rs;     }          //插入     //executeUpdate 的返回值是一个整数,指示受影响的行数(即更新计数)。     //executeUpdate用于执行 INSERT、UPDATE 或 DELETE 语句     //以及 SQL DDL(数据定义语言)语句,例如 CREATE TABLE 和 DROP TABLE。          //执行增、删、改语句的方法     public int executeUpdate(String sql) {         int count = 0;         connect();         try {             Statement stmt = connection.createStatement();             count = stmt.executeUpdate(sql);         }          catch(SQLException ex) {              System.err.println(ex.getMessage());                 }         disconnect();         return count;     } }

4.2 加密模块

 import java.math.BigInteger; public class Md5 {     public static String md5(String str){         BigInteger bStr = new BigInteger(str);         BigInteger B = new BigInteger("654321");         System.out.println("bStr="+bStr);         System.out.println(B.xor(bStr));         return String.valueOf(B.xor(bStr));     } }

4.3 登陆模块

 import javax.swing.*; import javax.swing.table.DefaultTableModel;  import java.awt.*; import java.awt.event.*; import java.sql.ResultSet; import java.sql.SQLException;  public class Login extends JFrame implements ActionListener{     // 定义组件     JLabel jLPersonnelManagement = null;//人事管理系统     JLabel jLLoginUser = null;//登录工号     JLabel jLLoginPassword = null;//登录密码     JLabel jLLoginStatus = null;//身份      JTextField jTFLoginUser = null;//用户框     JPasswordField jPFLoginPassword = null;//密码框      JButton jBLogin = null;//登录     JButton jBExit = null;//退出      JComboBox<String> jCBSelectUser = null;//用户选择      JPanel jP1, jP2,jP3,jP4,jP5 = null;     JPanel jP= null;      JScrollPane LoginJScrollPane = null;      private static DbProcess LdbProcess;     private static Manage M;     private static Employee E;     private static Md5 md5;     String SelectUserStr = "管理员";      public Login() {         this.md5 = new Md5();         // 创建标签组件         jLPersonnelManagement = new JLabel("人事管理系统");         jLPersonnelManagement.setFont(new Font("宋体",Font.BOLD,25));         jLLoginUser = new JLabel("工号:");         jLLoginUser.setFont(new Font("宋体",Font.BOLD,15));         jLLoginPassword = new JLabel("密码:");         jLLoginPassword.setFont(new Font("宋体",Font.BOLD,15));         jLLoginStatus = new JLabel("身份:");         jLLoginStatus.setFont(new Font("宋体",Font.BOLD,15));          jTFLoginUser = new JTextField(15);//用户         jPFLoginPassword = new JPasswordField(15);//密码          jBLogin = new JButton("登录");         jBLogin.setFont(new Font("宋体",Font.BOLD,15));         jBExit = new JButton("退出");         jBExit.setFont(new Font("宋体",Font.BOLD,15));          // 设置监听         jBLogin.addActionListener(this);         jBExit.addActionListener(this);          jCBSelectUser = new JComboBox<String>();//查询字段         jCBSelectUser.setFont(new Font("宋体",Font.BOLD,15));         //添加选项         jCBSelectUser.addItem("管理员");         jCBSelectUser.addItem("普通员工");         jCBSelectUser.addItemListener(new ItemListener() {//下拉框事件监听             public void itemStateChanged(ItemEvent event) {                 switch (event.getStateChange()) {                     case ItemEvent.SELECTED:                         SelectUserStr = (String) event.getItem();                         System.out.println("选中:" + SelectUserStr);                         break;                     case ItemEvent.DESELECTED:                         System.out.println("取消选中:" + event.getItem());                         break;                 }             }         });          LoginJScrollPane = new JScrollPane();          jP1 = new JPanel();         jP2 = new JPanel();         jP3 = new JPanel();         jP4 = new JPanel();         jP5 = new JPanel();         jP = new JPanel();          jP1.add(jLPersonnelManagement);         jP1.setLayout(new FlowLayout(FlowLayout.CENTER));         jP1.setPreferredSize(new Dimension(20,85));          jP2.add(jLLoginUser);         jP2.add(jTFLoginUser);         jP2.setLayout(new FlowLayout(FlowLayout.CENTER));         jP2.setPreferredSize(new Dimension(20,85));          jP3.add(jLLoginPassword);         jP3.add(jPFLoginPassword);         jP3.setLayout(new FlowLayout(FlowLayout.CENTER));         jP3.setPreferredSize(new Dimension(20,85));          jP4.add(jLLoginStatus);         jP4.add(jCBSelectUser);         jP4.setLayout(new FlowLayout(FlowLayout.CENTER));         jP4.setPreferredSize(new Dimension(20,85));          jP5.add(jBLogin);         jP5.add(jBExit);         jP5.setLayout(new FlowLayout(FlowLayout.CENTER));         jP5.setPreferredSize(new Dimension(20,85));          jP.setLayout(new GridLayout(5, 1));         jP.add(jP1);         jP.add(jP2);         jP.add(jP3);         jP.add(jP4);         jP.add(jP5);          this.add("North",LoginJScrollPane);         this.add("South",jP);          this.setLayout(new BorderLayout());         this.add(jP,BorderLayout.SOUTH);          this.setTitle("登录界面");         this.setSize(460, 500);         this.setLocation(450, 100);         this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);         this.setVisible(true);         this.setResizable(false);          LdbProcess = new DbProcess();      }     public void actionPerformed(ActionEvent e) {         if(e.getActionCommand().equals("登录")                 &&!jTFLoginUser.getText().isEmpty()                 &&!String.valueOf(jPFLoginPassword.getPassword()).equals("")){             String sID = jTFLoginUser.getText().trim();             String sPassword = new String(jPFLoginPassword.getPassword());             System.out.println("actionPerformed(). 登录"+sPassword);             loginProcess(sID,sPassword,SelectUserStr);             jPFLoginPassword.setText("");         }else if(e.getActionCommand().equals("退出")) {             System.out.println("actionPerformed(). 退出");             System.exit(0);         }     }     public void loginProcess(String sID, String sPassword,String userStr){         try{             // 建立查询条件             String sql = "select * from staff where ";              sql = sql + "sID";             sql = sql + " = ";             sql = sql + "'" + sID + "';";              System.out.println("queryProcess(). sql = " + sql);              LdbProcess.connect();             ResultSet rs = LdbProcess.executeQuery(sql);             rs.next();             if(rs.getString(14).equals("T")){                 if(this.md5.md5(sPassword).equals(rs.getString(2))){                     if(rs.getString(3).equals("普通员工")){                         if(userStr.equals("普通员工")){                             JOptionPane.showMessageDialog(null,                                     "登录成功!","提示",JOptionPane.INFORMATION_MESSAGE);                             this.dispose();                             this.E = new Employee(rs);                         }else{                             JOptionPane.showMessageDialog(null,                                     "用户身份错误,请重新选择!","错误",JOptionPane.ERROR_MESSAGE);                         }                     }                     if(rs.getString(3).equals("管理员")){                         JOptionPane.showMessageDialog(null,                                 "登录成功!","提示",JOptionPane.INFORMATION_MESSAGE);                         this.dispose();                         if(userStr.equals("普通员工")){                             this.E = new Employee(rs);                         }else if(userStr.equals("管理员")){                             this.M = new Manage();                         }                     }                 }else{                     JOptionPane.showMessageDialog(null,                             "用户密码错误,请重新输入!","错误",JOptionPane.ERROR_MESSAGE);                 }             }else{                 JOptionPane.showMessageDialog(null,                         "你已非本公司员工!","错误",JOptionPane.ERROR_MESSAGE);             }            LdbProcess.disconnect();          }catch(SQLException sqle){             System.out.println("sqle = " + sqle);             JOptionPane.showMessageDialog(null,                     "你输入的工号不存在,请从新输入!","错误",JOptionPane.ERROR_MESSAGE);         }catch(Exception e){             System.out.println("e = " + e);             JOptionPane.showMessageDialog(null,                     "你输入的工号不存在,请从新输入!","错误",JOptionPane.ERROR_MESSAGE);         }     } }

4.4 管理模块

 import javax.swing.*;  import java.awt.*; import java.awt.event.*; import java.sql.ResultSet; import java.sql.SQLException;  public class Manage extends JFrame implements ActionListener{     // 定义组件     JButton jBInsert = null;//员工加入     JButton jBChange = null;//人事变更     JButton jBQueryUpdate = null;//查询修改     //JButton jBChangeRecord = null;//变更记录      JPanel jP1, jP2,jP3,jP4 = null;     JPanel jP = null;      JScrollPane ManageJScrollPane = null;      private static DbProcess MdbProcess;     private static PersonnelChange P;     private static NewEmployee N;     private static DatabaseCourseDesign D;      public Manage() {         MdbProcess = new DbProcess();         int pid=100000;         try{             String sql ="select max(pID) from personnel;";             MdbProcess.connect();             ResultSet rs = MdbProcess.executeQuery(sql);             if(rs.next()){                 if(pid<=rs.getInt(1)){                     pid=rs.getInt(1);                 }                 System.out.println("pid"+pid);             }             MdbProcess.disconnect();         }catch(SQLException sqle){             System.out.println("sqle = " + sqle);             JOptionPane.showMessageDialog(null,                     "空集合","错误",JOptionPane.ERROR_MESSAGE);         }finally {             System.out.println(pid);             this.P = new PersonnelChange(pid+1);         }         // 组件         jBInsert = new JButton("新员工档案的录入");         jBInsert.setFont(new Font("宋体",Font.BOLD,15));         jBChange = new JButton("  人事变更  ");         jBChange.setFont(new Font("宋体",Font.BOLD,15));         jBQueryUpdate = new JButton("员工档案查询修改");         jBQueryUpdate.setFont(new Font("宋体",Font.BOLD,15));         //jBChangeRecord = new JButton("人事变更记录");         //jBChangeRecord.setFont(new Font("宋体",Font.BOLD,15));         // 设置监听         jBInsert.addActionListener(this);         jBChange.addActionListener(this);         jBQueryUpdate.addActionListener(this);         //jBChangeRecord.addActionListener(this);          ManageJScrollPane = new JScrollPane();          jP1 = new JPanel();         jP2 = new JPanel();         jP3 = new JPanel();         jP4 = new JPanel();         jP = new JPanel();          jP1.add(jBInsert);         jP1.setLayout(new FlowLayout(FlowLayout.CENTER));         jP1.setPreferredSize(new Dimension(250,100));          jP2.add(jBChange);         jP2.setLayout(new FlowLayout(FlowLayout.CENTER));         jP2.setPreferredSize(new Dimension(250,100));          jP3.add(jBQueryUpdate);         jP3.setLayout(new FlowLayout(FlowLayout.CENTER));         jP3.setPreferredSize(new Dimension(250,100));          //jP4.add(jBChangeRecord);         //jP4.setLayout(new FlowLayout(FlowLayout.CENTER));         //jP4.setPreferredSize(new Dimension(250,100));          jP.setLayout(new GridLayout(3, 1));         jP.add(jP1);         jP.add(jP2);         jP.add(jP3);         //jP.add(jP4);          this.add("North", ManageJScrollPane);         this.add("South", jP);          this.setLayout(new BorderLayout());         this.add(jP,BorderLayout.SOUTH);          this.setTitle("管理界面");         this.setSize(350, 400);         this.setLocation(150, 150);         this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);         this.setVisible(true);         this.setResizable(false);      }     public void actionPerformed(ActionEvent e) {         if(e.getActionCommand().equals("新员工档案的录入")){             System.out.println("actionPerformed(). 新员工档案的录入");             int sid=10000;             try{                 String sql ="select max(sID) from staff;";                 MdbProcess.connect();                 ResultSet rs = MdbProcess.executeQuery(sql);                 if(rs.next()){                     if(sid<=rs.getInt(1)){                         sid=rs.getInt(1);                     }                     System.out.println("sid"+sid);                 }                 MdbProcess.disconnect();             }catch(SQLException sqle){                 System.out.println("sqle = " + sqle);                 JOptionPane.showMessageDialog(null,                         "空集合","错误",JOptionPane.ERROR_MESSAGE);             }finally {                 this.N = new NewEmployee(sid+1,P);             }         }else if(e.getActionCommand().equals("  人事变更  ")) {             System.out.println("actionPerformed(). 人事变更");             P.PersonnelVector.clear();             P.PersonnelRecordJTable.updateUI();             P.setVisible(true);         }else if(e.getActionCommand().equals("员工档案查询修改")) {             System.out.println("actionPerformed(). 员工档案查询修改");             this.D = new  DatabaseCourseDesign();          }     } }

4.5 新员工档案录入模块

 import javax.swing.*; import javax.swing.table.DefaultTableModel; import java.awt.*; import java.awt.event.*; import java.sql.ResultSet; import java.sql.SQLException;  public class NewEmployee extends JFrame implements ActionListener {     // 定义组件     JLabel jLNewEmployee = null;//新员工信息     JLabel jLText = null;//注释     JLabel jLsID = null;//工号     JLabel jLsPassword = null;//密码     JLabel jLsAuthority = null;//权限     JLabel jLsName = null;//姓名     JLabel jLsSex = null;//性别     JLabel jLsBirthday = null;//生日     JLabel jLsDepartment = null;//部门     JLabel jLsJob = null;//职务     JLabel jLsEdu_Level = null;//教育水平     JLabel jLsSpecialty = null;//专业技能     JLabel jLsAddress = null;//住址     JLabel jLsTel = null;//电话     JLabel jLsEmail = null;//邮箱     JLabel jLsState = null;//状态     JLabel jLsRemark = null;//备注      JTextField jTFsID = null;//工号     JTextField jTFsPassword = null;//密码     JTextField jTFsName = null;//姓名     JTextField jTFsSex = null;//性别     JTextField jTFsBirthday = null;//生日     JTextField jTFsSpecialty = null;//专业技能     JTextField jTFsAddress = null;//住址     JTextField jTFsTel = null;//电话     JTextField jTFsEmail = null;//邮箱     JTextField jTFsState = null;//状态     JTextField jTFsRemark = null;//备注      JComboBox<String> jCBAuthority = null;//权限     JComboBox<String> jCBDepartment = null;//部门     JComboBox<String> jCBJob = null;//职务     JComboBox<String> jCBEdu_Level = null;//教育水平     //JComboBox<String> jCBDepartment = null;//部门     String jCBAuthorityStr="普通员工";     String jCBDepartmentStr="0-生产部";     String jCBJobStr="0-员工";     String jCBEdu_LevelStr="0-小学";     JButton jBInsert = null;//返回     //JButton jBDeleteCurrentRecord = null;//删除当前记录     //JButton jBDeleteAllRecords = null;//删除所有记录      //JComboBox jCBSelectQueryField = null;      JPanel jP1, jP2,jP3, jP4, jP5 = null;     JPanel jP = null;     DefaultTableModel studentTableModel = null;      JScrollPane NewEmployeeJScrollPane = null;      private static DbProcess NdbProcess;     private static PersonnelChange P;     private static Md5 md5;     private static int sid;     // 构造函数     public NewEmployee(int id,PersonnelChange P) {         this.md5=new Md5();         this.P=P;         this.sid=id;         // 创建标签组件         jLNewEmployee = new JLabel("新员工信息");         jLNewEmployee.setFont(new Font("宋体",Font.BOLD,25));         jLText = new JLabel("注意:带*的为必填项          ");         jLText.setFont(new Font("宋体",Font.BOLD,15));         jLText.setForeground(Color.red);         jLsID = new JLabel("工号*");         jLsPassword = new JLabel("密码*");         jLsAuthority = new JLabel("权限*");         jLsName = new JLabel("姓名*");         jLsSex = new JLabel("性别*");         jLsBirthday = new JLabel("生日*");         jLsDepartment = new JLabel("部门*");         jLsJob = new JLabel("职务*");         jLsEdu_Level = new JLabel("教育水平*");         jLsSpecialty = new JLabel("专业技能*");         jLsAddress = new JLabel("住址*");         jLsTel = new JLabel("电话*");         jLsEmail = new JLabel("邮箱*");         jLsState = new JLabel("状态*");         jLsRemark = new JLabel("备注");         NdbProcess = new DbProcess();         jTFsID = new JTextField(15);//工号         jTFsID.setEditable(false);         jTFsID.setText(String.valueOf(sid));         jTFsPassword = new JTextField(15);//密码         jTFsPassword.setEditable(false);         jTFsPassword.setText(String.valueOf(sid));         jTFsName = new JTextField(15);//姓名         jTFsSex = new JTextField(15);//性别         jTFsBirthday = new JTextField(15);//生日         jTFsSpecialty = new JTextField(15);//专业技能         jTFsAddress = new JTextField(15);//住址         jTFsTel = new JTextField(15);//电话         jTFsEmail = new JTextField(15);//邮箱         jTFsState = new JTextField(15);//状态         jTFsState.setEditable(false);         jTFsState.setText("T");         jTFsRemark = new JTextField(15);//备注          jBInsert = new JButton("录入新员工");         jBInsert.setFont(new Font("宋体",Font.BOLD,20));         // 设置监听         jBInsert.addActionListener(this);          jCBAuthority = new JComboBox<String>();//权限         //jCBAuthority.set         jCBAuthority.addItem("普通员工");//添加选项         jCBAuthority.addItem("管理员");         jCBDepartment = new JComboBox<String>();//部门         jCBDepartment.addItem("0-生产部");         jCBDepartment.addItem("1-运营部");         jCBDepartment.addItem("2-行政部");         jCBDepartment.addItem("3-人事部");         jCBJob = new JComboBox<String>();//职务         jCBJob.addItem("0-员工");         jCBJob.addItem("1-组长");         jCBJob.addItem("2-主任");         jCBJob.addItem("3-经理");         jCBEdu_Level = new JComboBox<String>();//教育水平         jCBEdu_Level.addItem("0-小学");         jCBEdu_Level.addItem("1-初中");         jCBEdu_Level.addItem("2-高中");         jCBEdu_Level.addItem("3-职高");         jCBEdu_Level.addItem("4-大本");         jCBEdu_Level.addItem("5-大专");         jCBEdu_Level.addItem("6-硕士");         jCBEdu_Level.addItem("7-博士");         jCBEdu_Level.addItem("8-博士后");          jCBAuthority.addItemListener(new ItemListener() {//查询下拉框事件监听             public void itemStateChanged(ItemEvent event) {                 switch (event.getStateChange()) {                     case ItemEvent.SELECTED:                         jCBAuthorityStr = (String) event.getItem();                         System.out.println("选中:" + jCBAuthorityStr);                         break;                     case ItemEvent.DESELECTED:                         System.out.println("取消选中:" + event.getItem());                         break;                 }             }         });         jCBDepartment.addItemListener(new ItemListener() {//查询下拉框事件监听             public void itemStateChanged(ItemEvent event) {                 switch (event.getStateChange()) {                     case ItemEvent.SELECTED:                         jCBDepartmentStr = (String) event.getItem();                         System.out.println("选中:" + jCBDepartmentStr);                         break;                     case ItemEvent.DESELECTED:                         System.out.println("取消选中:" + event.getItem());                         break;                 }             }         });         jCBJob.addItemListener(new ItemListener() {//查询下拉框事件监听             public void itemStateChanged(ItemEvent event) {                 switch (event.getStateChange()) {                     case ItemEvent.SELECTED:                         jCBJobStr = (String) event.getItem();                         System.out.println("选中:" + jCBJobStr);                         break;                     case ItemEvent.DESELECTED:                         System.out.println("取消选中:" + event.getItem());                         break;                 }             }         });         jCBEdu_Level.addItemListener(new ItemListener() {//查询下拉框事件监听             public void itemStateChanged(ItemEvent event) {                 switch (event.getStateChange()) {                     case ItemEvent.SELECTED:                         jCBEdu_LevelStr = (String) event.getItem();                         System.out.println("选中:" + jCBEdu_LevelStr);                         break;                     case ItemEvent.DESELECTED:                         System.out.println("取消选中:" + event.getItem());                         break;                 }             }         });          //studentTableModel = new DefaultTableModel(tableTitle, 15);         NewEmployeeJScrollPane = new JScrollPane();          jP1 = new JPanel();         jP2 = new JPanel();         jP3 = new JPanel();         jP4 = new JPanel();         jP5 = new JPanel();         jP = new JPanel();          //jP1.add(NewEmployeeJScrollPane);          jP1.add(jLNewEmployee);         jP1.setLayout(new FlowLayout(FlowLayout.CENTER));         jP1.setPreferredSize(new Dimension(250,80));          jP2.add(jLsID);         jP2.add(jTFsID);         jP2.add(jLsPassword);         jP2.add(jTFsPassword);         jP2.add(jLsAuthority);         jP2.add(jCBAuthority);         jP2.add(jLsDepartment);         jP2.add(jCBDepartment);         jP2.add(jLsJob);         jP2.add(jCBJob);         jP2.add(jLsEdu_Level);         jP2.add(jCBEdu_Level);         jP2.setLayout(new FlowLayout(FlowLayout.CENTER));         jP2.setPreferredSize(new Dimension(250,80));          jP3.add(jLsName);         jP3.add(jTFsName);         jP3.add(jLsSex);         jP3.add(jTFsSex);         jP3.add(jLsBirthday);         jP3.add(jTFsBirthday);         jP3.add(jLsSpecialty);         jP3.add(jTFsSpecialty);         jP3.setLayout(new FlowLayout(FlowLayout.CENTER));         jP3.setPreferredSize(new Dimension(250,80));          jP4.add(jLsAddress);         jP4.add(jTFsAddress);         jP4.add(jLsTel);         jP4.add(jTFsTel);         jP4.add(jLsEmail);         jP4.add(jTFsEmail);         jP4.add(jLsState);         jP4.add(jTFsState);         jP4.add(jLsRemark);         jP4.add(jTFsRemark);         jP4.setLayout(new FlowLayout(FlowLayout.CENTER));         jP4.setPreferredSize(new Dimension(250,80));           //jP5.setLayout(new BorderLayout());         jP5.add(jLText);         jP5.add(jBInsert);         jP5.setLayout(new FlowLayout(FlowLayout.CENTER));         jP5.setPreferredSize(new Dimension(250,80));          jP.setLayout(new GridLayout(5, 1));         jP.add(jP1);         jP.add(jP2);         jP.add(jP3);         jP.add(jP4);         jP.add(jP5);          this.add("North", NewEmployeeJScrollPane);         this.add("South", jP);          this.setLayout(new BorderLayout());         this.add(jP,BorderLayout.SOUTH);          this.setTitle("新员工档案的录入");         this.setSize(970, 450);         this.setLocation(200, 150);         this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);         this.setVisible(true);         this.setResizable(false);     }     public void actionPerformed(ActionEvent e) {         if(e.getActionCommand().equals("录入新员工")             && !jTFsPassword.getText().isEmpty()             && !jTFsName.getText().isEmpty()             && !jTFsSex.getText().isEmpty()             && !jTFsBirthday.getText().isEmpty()             && !jTFsSpecialty.getText().isEmpty()             && !jTFsAddress.getText().isEmpty()             && !jTFsTel.getText().isEmpty()             && !jTFsEmail.getText().isEmpty()             && !jTFsState.getText().isEmpty()){             System.out.println("actionPerformed(). 录入新员工");             insertProcess();             sid++;             jTFsID.setText(String.valueOf(sid));             jTFsPassword.setText(String.valueOf(sid));             jTFsName.setText("");             jTFsSex.setText("");             jTFsBirthday.setText("");             jTFsSpecialty.setText("");             jTFsAddress.setText("");             jTFsTel.setText("");             jTFsEmail.setText("");             jTFsRemark.setText("");         }     }     public void insertProcess(){         String sID = jTFsID.getText().trim();         String sPassword = this.md5.md5(jTFsPassword.getText().trim());         String sAuthority = jCBAuthorityStr;         String sName = jTFsName.getText().trim();         String sSex = jTFsSex.getText().trim();         String sBirthday = jTFsBirthday.getText().trim();         String sDepartment = "";         String sJob = "";         String sEdu_Level = "";         String sSpecialty = jTFsSpecialty.getText().trim();         String sAddress = jTFsAddress.getText().trim();         String sTel = jTFsTel.getText().trim();         String sEmail = jTFsEmail.getText().trim();         String sState = jTFsState.getText().trim();         String sRemark = jTFsRemark.getText().trim();         if(jCBDepartmentStr.equals("0-生产部")){             sDepartment="生产部";         }else if(jCBDepartmentStr.equals("1-运营部")){             sDepartment="运营部";         }         else if(jCBDepartmentStr.equals("2-行政部")){             sDepartment="行政部";         }         else if(jCBDepartmentStr.equals("3-人事部")){             sDepartment="人事部";         }          if(jCBJobStr.equals("0-员工")){             sJob="员工";         }else if(jCBJobStr.equals("1-组长")){             sJob="组长";         }else if(jCBJobStr.equals("2-主任")){             sJob="主任";         }else if(jCBJobStr.equals("3-经理")){             sJob="经理";         }          if(jCBEdu_LevelStr.equals("0-小学")){             sEdu_Level="小学";         }else if(jCBEdu_LevelStr.equals("1-初中")){             sEdu_Level="初中";         }else if(jCBEdu_LevelStr.equals("2-高中")){             sEdu_Level="高中";         }else if(jCBEdu_LevelStr.equals("3-职高")){             sEdu_Level="职高";         }else if(jCBEdu_LevelStr.equals("4-大本")){             sEdu_Level="大本";         }else if(jCBEdu_LevelStr.equals("5-大专")){             sEdu_Level="大专";         }else if(jCBEdu_LevelStr.equals("6-硕士")){             sEdu_Level="硕士";         }else if(jCBEdu_LevelStr.equals("7-博士")){             sEdu_Level="博士";         }else if(jCBEdu_LevelStr.equals("8-博士后")){             sEdu_Level="博士后";         }         // 建立更新条件         String sql = "insert into staff values('";         sql = sql + sID + "','";         sql = sql + sPassword + "','";         sql = sql + sAuthority + "','";         sql = sql + sName + "','";         sql = sql + sSex + "','";         sql = sql + sBirthday + "','";         sql = sql + sDepartment + "','";         sql = sql + sJob + "','";         sql = sql + sEdu_Level + "','";         sql = sql + sSpecialty + "','";         sql = sql + sAddress + "','";         sql = sql + sTel + "','";         sql = sql + sEmail + "','";         sql = sql + sState + "','";         sql = sql + sRemark + "');";         System.out.println("updateProcess(). sql = " + sql);         try{             if (NdbProcess.executeUpdate(sql) < 1) {                 System.out.println("updateProcess(). update database failed.");             }else{                 //String sql = "insert into staff values('";                 JOptionPane.showMessageDialog(null,                         "录入新员工成功!","提示",JOptionPane.INFORMATION_MESSAGE);                 int pid=100000;                 try{                     sql ="select max(pID) from personnel;";                     System.out.println("queryProcess(). sql = " + sql);                     NdbProcess.connect();                     ResultSet rs = NdbProcess.executeQuery(sql);                     if(rs.next()){                         if(pid<=rs.getInt(1)){                             pid=rs.getInt(1);                             System.out.println("pid"+pid);                         }                     }                     NdbProcess.disconnect();                 }catch(SQLException sqle){                     System.out.println("sqle = " + sqle);                     JOptionPane.showMessageDialog(null,                             "空集合","错误",JOptionPane.ERROR_MESSAGE);                 }finally {                     System.out.println(pid);                     sql = "insert into personnel values('";                     sql = sql + (pid+1) + "','";                     sql = sql + sID + "','";                     sql = sql + "0" + "','";                     sql = sql + "新员工录入" + "');";                     if (NdbProcess.executeUpdate(sql) < 1) {                         System.out.println("updateProcess(). update database failed.");                     }else{                         P.jTFChangeID.setText(String.valueOf(pid+2));                         //this.P.setVisible(true);                         JOptionPane.showMessageDialog(null,                                 "人事变动成功!","提示",JOptionPane.INFORMATION_MESSAGE);                     }                 }              }         }catch(Exception e){             System.out.println("e = " + e);             JOptionPane.showMessageDialog(null,                     "数据操作错误","错误",JOptionPane.ERROR_MESSAGE);         }     } }

4.6 人事变更模块

 import javax.swing.*; import javax.swing.table.DefaultTableModel;  import java.awt.*; import java.awt.event.*; import java.sql.ResultSet; import java.sql.SQLException; import java.util.Vector;  class PersonnelChange extends JFrame implements ActionListener {     // 定义组件     JLabel jLPersonnelRecord = null;//人事变更记录表     JLabel jLSelectQueryField = null;//选择查询字段     JLabel jLText2 = null;//注释1     JLabel jLText1 = null;//注释2     JLabel jLEqual1 = null;//=     JLabel jLEqual2 = null;//=     JLabel jLChangeID = null;//变更编号     JLabel jLsID = null;//需要进行变更的员工工号     JLabel jLSelectChangeCode = null;//代码     JLabel jLAfter;//变之后的内容     JLabel jLChangeDescription = null;//详细描述      JTextField jTFQueryField = null;//查询字段     JTextField jTFChangeID = null;//变更编号     JTextField jTFsID = null;//需要进行变更的员工工号     JTextField jTFChangeDescription = null;//详细描述      JButton jBQuery = null;//查询     JButton jBQueryAll = null;//查询所有记录     JButton jBChange = null;//变更      //JButton jBDeleteCurrentRecord = null;//删除当前记录     //JButton jBDeleteAllRecords = null;//删除所有记录      //JComboBox jCBSelectQueryField = null;     JComboBox<String> jCBSelectQueryField = null;//查询字段     JComboBox<String> jCBChangeCode = null;//代码     JComboBox<String> jCBJob = null;//职务     JPanel jP1, jP2,jP3,jP4,jP5,jP6,jP7,jP8,jP9,jP10 = null;     JPanel jPTop, jPBottom = null;     DefaultTableModel studentTableModel = null;     JTable PersonnelRecordJTable = null;     JScrollPane PersonnelRecordJScrollPane = null;     Vector PersonnelVector = null;     Vector titleVector = null;      private static DbProcess PdbProcess;     private static int pid;     String SelectQueryFieldStr = "记录编号";     String SelectChangeCodeStr = "1-职务变动";     String jCBJobStr="0-员工";     // 构造函数     public PersonnelChange(int pid) {         this.pid=pid;         // 创建标签组件         jLPersonnelRecord = new JLabel("人事变更记录表");         jLText1 = new JLabel("注意:带*的为必填项,进行职务变动需要选择变动后的职务,辞退不需要处理");         jLText1.setFont(new Font("宋体",Font.BOLD,15));         jLText1.setForeground(Color.red);         jLText2 = new JLabel("变更代码含义:0(新员工加入),1(职务变动),2(辞退)");         jLText2.setFont(new Font("宋体",Font.BOLD,15));         jLText2.setForeground(Color.red);         jLSelectQueryField = new JLabel("选择查询字段");         jLSelectQueryField.setFont(new Font("宋体",Font.BOLD,15));         jLEqual1 = new JLabel(" = ");         jLEqual1.setFont(new Font("宋体",Font.BOLD,15));         jLEqual2 = new JLabel(" = ");         jLEqual2.setFont(new Font("宋体",Font.BOLD,15));         jLChangeID = new JLabel("记录编号*:");         jLChangeID.setFont(new Font("宋体",Font.BOLD,15));         jLsID = new JLabel("需要进行变更的员工工号*:");         jLsID.setFont(new Font("宋体",Font.BOLD,15));         jLSelectChangeCode = new JLabel("需要变更的代码*");         jLSelectChangeCode.setFont(new Font("宋体",Font.BOLD,15));         jLAfter = new JLabel("改变后的职务:");         jLAfter.setFont(new Font("宋体",Font.BOLD,15));         jLChangeDescription = new JLabel("详细描述*:");         jLChangeDescription.setFont(new Font("宋体",Font.BOLD,15));          jTFQueryField = new JTextField(15);//查询字段         jTFChangeID = new JTextField(15);         jTFChangeID.setEditable(false);         jTFChangeID.setText(String.valueOf(pid));         jTFsID = new JTextField(15);//需要进行变更的员工工号          jTFChangeDescription = new JTextField(25);          jBQuery = new JButton("查询");         jBQueryAll = new JButton("查询所有记录");         jBChange = new JButton("变更");         jBChange.setFont(new Font("宋体",Font.BOLD,20));          // 设置监听         jBQuery.addActionListener(this);         jBQueryAll.addActionListener(this);         jBChange.addActionListener(this);          jCBSelectQueryField = new JComboBox<String>();//查询字段         jCBSelectQueryField.addItem("记录编号");//添加选项         jCBSelectQueryField.addItem("员工工号");         jCBSelectQueryField.addItem("变更代码");         jCBChangeCode = new JComboBox<String>();//变更代码         jCBChangeCode.addItem("1-职务变动");         jCBChangeCode.addItem("2-辞退");         jCBJob = new JComboBox<String>();//职务         jCBJob.addItem("0-员工");         jCBJob.addItem("1-组长");         jCBJob.addItem("2-主任");         jCBJob.addItem("3-经理");          jCBSelectQueryField.addItemListener(new ItemListener() {//查询下拉框事件监听             public void itemStateChanged(ItemEvent event) {                 switch (event.getStateChange()) {                     case ItemEvent.SELECTED:                         SelectQueryFieldStr = (String) event.getItem();                         System.out.println("选中:" + SelectQueryFieldStr);                         break;                     case ItemEvent.DESELECTED:                         System.out.println("取消选中:" + event.getItem());                         break;                 }             }         });         jCBChangeCode.addItemListener(new ItemListener() {//变更代码下拉框事件监听             public void itemStateChanged(ItemEvent event) {                 switch (event.getStateChange()) {                     case ItemEvent.SELECTED:                         SelectChangeCodeStr = (String) event.getItem();                         System.out.println("选中:" + SelectChangeCodeStr);                         break;                     case ItemEvent.DESELECTED:                         System.out.println("取消选中:" + event.getItem());                         break;                 }             }         });         jCBJob.addItemListener(new ItemListener() {//职务下拉框事件监听             public void itemStateChanged(ItemEvent event) {                 switch (event.getStateChange()) {                     case ItemEvent.SELECTED:                         jCBJobStr = (String) event.getItem();                         System.out.println("选中:" + jCBJobStr);                         break;                     case ItemEvent.DESELECTED:                         System.out.println("取消选中:" + event.getItem());                         break;                 }             }         });         PersonnelVector = new Vector();         titleVector = new Vector();          // 定义表头         titleVector.add("记录编号");         titleVector.add("变更代码");         titleVector.add("员工工号");         titleVector.add("员工姓名");         titleVector.add("员工职务");         titleVector.add("员工状态");         titleVector.add("详细记录");          //studentTableModel = new DefaultTableModel(tableTitle, 15);         PersonnelRecordJTable = new JTable(PersonnelVector, titleVector);         PersonnelRecordJTable.setPreferredScrollableViewportSize(new Dimension(660,240));         PersonnelRecordJScrollPane = new JScrollPane(PersonnelRecordJTable);         //分别设置水平和垂直滚动条自动出现         PersonnelRecordJScrollPane.setHorizontalScrollBarPolicy(                 JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);         PersonnelRecordJScrollPane.setVerticalScrollBarPolicy(                 JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);          //为表格添加监听器         PersonnelRecordJTable.addMouseListener(new MouseAdapter()         {             public void mouseClicked(MouseEvent e)             {                 int row = ((JTable) e.getSource()).rowAtPoint(e.getPoint()); // 获得行位置                 System.out.println("mouseClicked(). row = " + row);             }         });          jP1 = new JPanel();         jP2 = new JPanel();         jP3 = new JPanel();         jP4 = new JPanel();         jP5 = new JPanel();         jP6 = new JPanel();         jP7 = new JPanel();         jP8 = new JPanel();         jP9 = new JPanel();         jP10 = new JPanel();         jPTop = new JPanel();         jPBottom = new JPanel();          jP1.add(jLPersonnelRecord,BorderLayout.NORTH);         jP2.add(PersonnelRecordJScrollPane);          jP10.add(jLText2);         jP10.setLayout(new FlowLayout(FlowLayout.CENTER));         jP10.setPreferredSize(new Dimension(20,20));          jP3.add(jLSelectQueryField);         jP3.add(jCBSelectQueryField);         jP3.add(jLEqual1);         jP3.add(jTFQueryField);         jP3.add(jBQuery);         jP3.add(jBQueryAll);         jP3.setLayout(new FlowLayout(FlowLayout.CENTER));         jP3.setPreferredSize(new Dimension(20,20));          jP4.add(jLChangeID);         jP4.add(jTFChangeID);         jP4.setLayout(new FlowLayout(FlowLayout.CENTER));         jP4.setPreferredSize(new Dimension(20,20));          jP5.add(jLsID);         jP5.add(jTFsID);         jP5.setLayout(new FlowLayout(FlowLayout.CENTER));         jP5.setPreferredSize(new Dimension(20,20));          jP6.add(jLSelectChangeCode);         jP6.add(jCBChangeCode);         jP6.add(jLAfter);         jP6.add(jCBJob);         jP6.setLayout(new FlowLayout(FlowLayout.CENTER));         jP6.setPreferredSize(new Dimension(20,20));          jP7.add(jLChangeDescription);         jP7.add(jTFChangeDescription);         jP7.setLayout(new FlowLayout(FlowLayout.CENTER));         jP7.setPreferredSize(new Dimension(20,20));           jP8.add(jBChange);         jP8.setLayout(new FlowLayout(FlowLayout.CENTER));         jP8.setPreferredSize(new Dimension(20,20));          jP9.add(jLText1);         //jP9.add(jLText2);         jP9.setLayout(new FlowLayout(FlowLayout.CENTER));         jP9.setPreferredSize(new Dimension(20,20));          jPTop.add(jP1);         jPTop.add(jP2);          jPBottom.setLayout(new GridLayout(8, 1));         jPBottom.add(jP10);         jPBottom.add(jP3);         jPBottom.add(jP4);         jPBottom.add(jP5);         jPBottom.add(jP6);         jPBottom.add(jP7);         jPBottom.add(jP8);         jPBottom.add(jP9);          this.add("North", jPTop);         this.add("South", jPBottom);          this.setLayout(new GridLayout(2, 1));         this.setTitle("人事变更");         this.setSize(700, 700);         this.setLocation(300, 10);         this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);         this.setVisible(false);         this.setResizable(false);         PdbProcess = new DbProcess();     }      @Override     public void actionPerformed(ActionEvent e) {         if(e.getActionCommand().equals("查询")                 && !jTFQueryField.getText().isEmpty()){             System.out.println("actionPerformed(). 查询");             String sQueryField = jTFQueryField.getText().trim();             queryProcess(sQueryField);             jTFQueryField.setText("");         }else if(e.getActionCommand().equals("查询所有记录")) {             System.out.println("actionPerformed(). 查询所有记录");             queryAllProcess();         }else if(e.getActionCommand().equals("变更")                 && !jTFsID.getText().isEmpty()                 && !jTFChangeDescription.getText().isEmpty()){             int sid=10001;             try{                 String sql ="select max(sID) from staff;";                 PdbProcess.connect();                 ResultSet rs = PdbProcess.executeQuery(sql);                 if(rs.next()){                     if(sid<=rs.getInt(1))                         sid=rs.getInt(1);                     System.out.println("sid"+sid);                 }                 PdbProcess.disconnect();             }catch(SQLException sqle){                 System.out.println("sqle = " + sqle);                 JOptionPane.showMessageDialog(null,                         "空集合","错误",JOptionPane.ERROR_MESSAGE);             }finally {                 if(sid<Integer.parseInt(jTFsID.getText().trim())||10000>=Integer.parseInt(jTFsID.getText().trim())){                     JOptionPane.showMessageDialog(null,                             "员工工号不存在","错误",JOptionPane.ERROR_MESSAGE);                 }else{                     int pid=100000;                     try{                         String sql ="select max(pID) from personnel;";                         PdbProcess.connect();                         ResultSet rs = PdbProcess.executeQuery(sql);                         if(rs.next()){                             if(pid<=rs.getInt(1)){                                 pid=rs.getInt(1);                             }                             System.out.println("pid"+pid);                         }                         PdbProcess.disconnect();                     }catch(SQLException sqle){                         System.out.println("sqle = " + sqle);                         JOptionPane.showMessageDialog(null,                                 "空集合","错误",JOptionPane.ERROR_MESSAGE);                     }finally {                         try{                             String sql ="select sState from staff where sID = '"+jTFsID.getText().trim()+"';";                             PdbProcess.connect();                             ResultSet rs = PdbProcess.executeQuery(sql);                             rs.next();                             if(rs.getString("sState").equals("T")){                                 if(SelectChangeCodeStr.equals("1-职务变动")){                                     System.out.println("actionPerformed(). 职务变动");                                     ChangeProcess(0);                                     pid++;                                     System.out.println("pid="+pid);                                     jTFChangeID.setText(String.valueOf(pid+1));                                     jTFsID.setText("");                                     jTFChangeDescription.setText("");                                 }                                 if(SelectChangeCodeStr.equals("2-辞退")){                                     System.out.println("actionPerformed(). 辞退");                                     ChangeProcess(1);                                     pid++;                                     System.out.println("pid="+pid);                                     jTFChangeID.setText(String.valueOf(pid+1));                                     jTFsID.setText("");                                     jTFChangeDescription.setText("");                                 }                             }else{                                 JOptionPane.showMessageDialog(null,                                         "该员工已被辞退,无法变更!","错误",JOptionPane.ERROR_MESSAGE);                             }                             PdbProcess.disconnect();                         }catch(SQLException sqle){                             JOptionPane.showMessageDialog(null,                                     "该员工已被辞退,无法变更!","错误",JOptionPane.ERROR_MESSAGE);                         }                     }                 }             }         }     }      public void queryProcess(String sQueryField)     {         try{             // 建立查询条件             String sql = "select pID,pChange,personnel.sID,sName,sJob,sState,pDescription from personnel,staff where ";             String queryFieldStr = jCBSelectQueryFieldTransfer(SelectQueryFieldStr);             sql = sql + queryFieldStr;             sql = sql + " = ";             sql = sql + "'" + sQueryField + "'";             sql = sql + "and personnel.sID = staff.sID ;";              System.out.println("queryProcess(). sql = " + sql);              PdbProcess.connect();             ResultSet rs = PdbProcess.executeQuery(sql);              // 将查询获得的记录数据,转换成适合生成JTable的数据形式             PersonnelVector.clear();             while(rs.next()){                 Vector v = new Vector();                 v.add(rs.getString("pID"));                 v.add(rs.getString("pChange"));                 v.add(rs.getString("sID"));                 v.add(rs.getString("sName"));                 v.add(rs.getString("sJob"));                 v.add(rs.getString("sState"));                 v.add(rs.getString("pDescription"));                 PersonnelVector.add(v);             }              PersonnelRecordJTable.updateUI();              PdbProcess.disconnect();          }catch(SQLException sqle){             System.out.println("sqle = " + sqle);             JOptionPane.showMessageDialog(null,                     "数据操作错误","错误",JOptionPane.ERROR_MESSAGE);         }catch(Exception e){             System.out.println("e = " + e);             JOptionPane.showMessageDialog(null,                     "数据操作错误","错误",JOptionPane.ERROR_MESSAGE);         }     }      public void queryAllProcess()     {         try{             // 建立查询条件             String sql = "select pID,pChange,personnel.sID,sName,sJob,sState,pDescription from personnel,staff where ";             //String queryFieldStr = jCBSelectQueryFieldTransfer(SelectQueryFieldStr);             sql = sql + "personnel.sID = staff.sID order by pID asc;";             System.out.println("queryAllProcess(). sql = " + sql);              PdbProcess.connect();             ResultSet rs = PdbProcess.executeQuery(sql);              // 将查询获得的记录数据,转换成适合生成JTable的数据形式             PersonnelVector.clear();             while(rs.next()){                 Vector v = new Vector();                 v.add(rs.getString("pID"));                 v.add(rs.getString("pChange"));                 v.add(rs.getString("sID"));                 v.add(rs.getString("sName"));                 v.add(rs.getString("sJob"));                 v.add(rs.getString("sState"));                 v.add(rs.getString("pDescription"));                 PersonnelVector.add(v);             }              PersonnelRecordJTable.updateUI();              PdbProcess.disconnect();          }catch(SQLException sqle){             System.out.println("sqle = " + sqle);             JOptionPane.showMessageDialog(null,                     "数据操作错误","错误",JOptionPane.ERROR_MESSAGE);         }     }      public void ChangeProcess(int code)     {         String pID = jTFChangeID.getText().trim();         String sID = jTFsID.getText().trim();         String pChange="";         String sJob="";         String pDescription = jTFChangeDescription.getText().trim();          if(jCBJobStr.equals("0-员工")){             sJob="员工";         }else if(jCBJobStr.equals("1-组长")){             sJob="组长";         }else if(jCBJobStr.equals("2-主任")){             sJob="主任";         }else if(jCBJobStr.equals("3-经理")){             sJob="经理";         }         String sql="";         if(code==0){             pChange="1";             sql = "update staff set sJob = '";             sql = sql + sJob+"'";             sql = sql + " WHERE sID = '"+sID+"';";         }         if(code==1){             pChange="2";             sql = "update staff set sState = 'F' WHERE sID = '"+sID+"';";         }         try{             if (PdbProcess.executeUpdate(sql) < 1) {                 System.out.println("insertProcess(). update database failed.");             }         }catch(Exception e){             System.out.println("e = " + e);             JOptionPane.showMessageDialog(null,                     "数据操作错误","错误",JOptionPane.ERROR_MESSAGE);         }finally {             // 建立插入条件             sql = "insert into personnel values('";             sql = sql + pID + "','";             sql = sql + sID + "','";             sql = sql + pChange + "','";             sql = sql + pDescription + "');";              System.out.println("insertProcess(). sql = " + sql);             try{                 if (PdbProcess.executeUpdate(sql) < 1) {                     System.out.println("insertProcess(). insert database failed.");                 }else{                     JOptionPane.showMessageDialog(null,                             "变更成功!","提示",JOptionPane.INFORMATION_MESSAGE);                 }             }catch(Exception e){                 System.out.println("e = " + e);                 JOptionPane.showMessageDialog(null,                         "数据操作错误","错误",JOptionPane.ERROR_MESSAGE);             }             queryAllProcess();         }     }     public String jCBSelectQueryFieldTransfer(String InputStr)     {         String outputStr = "";         System.out.println("jCBSelectQueryFieldTransfer(). InputStr = " + InputStr);          if(InputStr.equals("记录编号")){             outputStr = "pID";         }else if(InputStr.equals("员工工号")){             outputStr = "personnel.sID";         }else if(InputStr.equals("变更代码")){             outputStr = "pChange";         }         System.out.println("jCBSelectQueryFieldTransfer(). outputStr = " + outputStr);         return outputStr;     } }

4.7 管理员员工档案查询修改模块

 import javax.swing.*; import javax.swing.table.DefaultTableModel;  import java.awt.*; import java.awt.event.*; import java.sql.ResultSet; import java.sql.SQLException; import java.util.Vector;  class DatabaseCourseDesign extends JFrame implements ActionListener {     // 定义组件     JLabel jLStaff = null;//员工信息表     JLabel jLText = null;//注释     JLabel jLSelectQueryField = null;//选择查询字段     JLabel jLEqual = null;//=     JLabel jLsID = null;//工号     //JLabel jLsPassword = null;//密码     JLabel jLsAuthority = null;//权限     JLabel jLsName = null;//姓名     JLabel jLsSex = null;//性别     JLabel jLsBirthday = null;//生日     JLabel jLsDepartment = null;//部门     JLabel jLsJob = null;//职务     JLabel jLsEdu_Level = null;//教育水平     JLabel jLsSpecialty = null;//专业技能     JLabel jLsAddress = null;//住址     JLabel jLsTel = null;//电话     JLabel jLsEmail = null;//邮箱     JLabel jLsState = null;//状态     JLabel jLsRemark = null;//备注      JTextField jTFQueryField = null;//查询字段     JTextField jTFsID = null;//工号     //JTextField jTFsPassword = null;//密码     JTextField jTFsJob =null;//职务     JTextField jTFsName = null;//姓名     JTextField jTFsSex = null;//性别     JTextField jTFsBirthday = null;//生日     JTextField jTFsSpecialty = null;//专业技能     JTextField jTFsAddress = null;//住址     JTextField jTFsTel = null;//电话     JTextField jTFsEmail = null;//邮箱     JTextField jTFsState = null;//状态     JTextField jTFsRemark = null;//备注          JButton jBQuery = null;//查询     JButton jBQueryAll = null;//查询所有记录     JButton jBUpdate = null;//更新     JButton jBReset = null;//重置密码      JComboBox<String> jCBSelectQueryField = null;//查询字段     JComboBox<String> jCBAuthority = null;//权限     JComboBox<String> jCBDepartment = null;//部门     //JComboBox<String> jCBJob = null;//职务     JComboBox<String> jCBEdu_Level = null;//教育水平     JPanel jP1, jP2,jP3,jP4,jP5,jP6,jP7 = null;     JPanel jPTop, jPBottom = null;     DefaultTableModel studentTableModel = null;     JTable staffJTable = null;     JScrollPane staffJScrollPane = null;     Vector staffVector = null;     Vector titleVector = null;          private static DbProcess dbProcess;     private static Md5 md5;     String SelectQueryFieldStr = "工号";     String jCBAuthorityStr="普通员工";     String jCBDepartmentStr="0-生产部";     String jCBJobStr="0-员工";     String jCBEdu_LevelStr="0-小学";          // 构造函数     public DatabaseCourseDesign() {         this.md5 = new Md5();         // 创建标签组件         jLStaff = new JLabel("员工信息表");         jLText = new JLabel("注意:带*的为必填项          ");         jLText.setFont(new Font("宋体",Font.BOLD,15));         jLText.setForeground(Color.red);         jLSelectQueryField = new JLabel("选择查询字段");         jLEqual = new JLabel(" = ");         jLsID = new JLabel("工号*");         //jLsPassword = new JLabel("密码*");         jLsAuthority = new JLabel("权限*");         jLsName = new JLabel("姓名*");         jLsSex = new JLabel("性别*");         jLsBirthday = new JLabel("生日*");         jLsDepartment = new JLabel("部门*");         jLsJob = new JLabel("职务*");         jLsEdu_Level = new JLabel("教育水平*");         jLsSpecialty = new JLabel("专业技能*");         jLsAddress = new JLabel("住址*");         jLsTel = new JLabel("电话*");         jLsEmail = new JLabel("邮箱*");         jLsState = new JLabel("状态*");         jLsRemark = new JLabel("备注");          jTFQueryField = new JTextField(15);//查询字段         jTFsID = new JTextField(15);//工号         jTFsID.setEditable(false);         //jTFsPassword = new JTextField(15);//密码         jTFsJob = new JTextField(15);//职务         jTFsJob.setEditable(false);         jTFsName = new JTextField(15);//姓名         jTFsSex = new JTextField(15);//性别         jTFsBirthday = new JTextField(15);//生日         jTFsSpecialty = new JTextField(15);//专业技能         jTFsAddress = new JTextField(15);//住址         jTFsTel = new JTextField(15);//电话         jTFsEmail = new JTextField(15);//邮箱         jTFsState = new JTextField(15);//状态         jTFsState.setEditable(false);         jTFsRemark = new JTextField(15);//备注                  jBQuery = new JButton("查询");         jBQueryAll = new JButton("查询所有记录");         jBUpdate = new JButton("更新员工信息");         jBUpdate.setFont(new Font("宋体",Font.BOLD,20));         jBReset = new JButton("重置用户密码");         jBReset.setFont(new Font("宋体",Font.BOLD,20));         //jBBack = new JButton("返回");         //jBDeleteCurrentRecord = new JButton("删除当前记录");         //jBDeleteAllRecords = new JButton("删除所有记录");         // 设置监听         jBQuery.addActionListener(this);         jBQueryAll.addActionListener(this);         jBUpdate.addActionListener(this);         jBReset.addActionListener(this);         //jBDeleteCurrentRecord.addActionListener(this);         //jBDeleteAllRecords.addActionListener(this);                  jCBSelectQueryField = new JComboBox<String>();//查询字段         jCBSelectQueryField.addItem("工号");//添加选项         jCBSelectQueryField.addItem("权限");         jCBSelectQueryField.addItem("姓名");           jCBSelectQueryField.addItem("性别");         jCBSelectQueryField.addItem("生日");         jCBSelectQueryField.addItem("部门");         jCBSelectQueryField.addItem("职务");         jCBSelectQueryField.addItem("教育水平");         jCBSelectQueryField.addItem("专业技能");         jCBSelectQueryField.addItem("状态");          jCBAuthority = new JComboBox<String>();//权限         //jCBAuthority.set         jCBAuthority.addItem("普通员工");//添加选项         jCBAuthority.addItem("管理员");         jCBDepartment = new JComboBox<String>();//部门         jCBDepartment.addItem("0-生产部");         jCBDepartment.addItem("1-运营部");         jCBDepartment.addItem("2-行政部");         jCBDepartment.addItem("3-人事部");         /*jCBJob = new JComboBox<String>();//职务         jCBJob.addItem("员工");         jCBJob.addItem("组长");         jCBJob.addItem("主任");         jCBJob.addItem("经理");*/         jCBEdu_Level = new JComboBox<String>();//教育水平         jCBEdu_Level.addItem("0-小学");         jCBEdu_Level.addItem("1-初中");         jCBEdu_Level.addItem("2-高中");         jCBEdu_Level.addItem("3-职高");         jCBEdu_Level.addItem("4-大本");         jCBEdu_Level.addItem("5-大专");         jCBEdu_Level.addItem("6-硕士");         jCBEdu_Level.addItem("7-博士");         jCBEdu_Level.addItem("8-博士后");          jCBSelectQueryField.addItemListener(new ItemListener() {//下拉框事件监听               public void itemStateChanged(ItemEvent event) {                   switch (event.getStateChange()) {                   case ItemEvent.SELECTED:                       SelectQueryFieldStr = (String) event.getItem();                       System.out.println("选中:" + SelectQueryFieldStr);                       break;                   case ItemEvent.DESELECTED:                       System.out.println("取消选中:" + event.getItem());                       break;                   }             }           });         jCBAuthority.addItemListener(new ItemListener() {//查询下拉框事件监听             public void itemStateChanged(ItemEvent event) {                 switch (event.getStateChange()) {                     case ItemEvent.SELECTED:                         jCBAuthorityStr = (String) event.getItem();                         System.out.println("选中:" + jCBAuthorityStr);                         break;                     case ItemEvent.DESELECTED:                         System.out.println("取消选中:" + event.getItem());                         break;                 }             }         });         jCBDepartment.addItemListener(new ItemListener() {//查询下拉框事件监听             public void itemStateChanged(ItemEvent event) {                 switch (event.getStateChange()) {                     case ItemEvent.SELECTED:                         jCBDepartmentStr = (String) event.getItem();                         System.out.println("选中:" + jCBDepartmentStr);                         break;                     case ItemEvent.DESELECTED:                         System.out.println("取消选中:" + event.getItem());                         break;                 }             }         });         /*jCBJob.addItemListener(new ItemListener() {//查询下拉框事件监听             public void itemStateChanged(ItemEvent event) {                 switch (event.getStateChange()) {                     case ItemEvent.SELECTED:                         jCBJobStr = (String) event.getItem();                         System.out.println("选中:" + jCBJobStr);                         break;                     case ItemEvent.DESELECTED:                         System.out.println("取消选中:" + event.getItem());                         break;                 }             }         });*/         jCBEdu_Level.addItemListener(new ItemListener() {//查询下拉框事件监听             public void itemStateChanged(ItemEvent event) {                 switch (event.getStateChange()) {                     case ItemEvent.SELECTED:                         jCBEdu_LevelStr = (String) event.getItem();                         System.out.println("选中:" + jCBEdu_LevelStr);                         break;                     case ItemEvent.DESELECTED:                         System.out.println("取消选中:" + event.getItem());                         break;                 }             }         });              staffVector = new Vector();         titleVector = new Vector();          // 定义表头         titleVector.add("工号");         //titleVector.add("密码");         titleVector.add("权限");         titleVector.add("姓名");         titleVector.add("性别");         titleVector.add("生日");         titleVector.add("部门");         titleVector.add("职务");         titleVector.add("教育水平");         titleVector.add("专业技能");         titleVector.add("住址");         titleVector.add("电话");         titleVector.add("邮箱");         titleVector.add("状态");         titleVector.add("备注");          //studentTableModel = new DefaultTableModel(tableTitle, 15);         staffJTable = new JTable(staffVector, titleVector);         staffJTable.setPreferredScrollableViewportSize(new Dimension(910,220));         staffJScrollPane = new JScrollPane(staffJTable);         //分别设置水平和垂直滚动条自动出现         staffJScrollPane.setHorizontalScrollBarPolicy(                 JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);         staffJScrollPane.setVerticalScrollBarPolicy(                 JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);                  //为表格添加监听器          staffJTable.addMouseListener(new MouseAdapter()         {              public void mouseClicked(MouseEvent e)              {                  int row = ((JTable) e.getSource()).rowAtPoint(e.getPoint()); // 获得行位置                 System.out.println("mouseClicked(). row = " + row);                 Vector v = new Vector();                 v = (Vector) staffVector.get(row);                  jTFsID.setText((String) v.get(0));// 工号                 //jTFsPassword.setText((String) v.get(1));// 密码                 if(String.valueOf(v.get(1)).equals("普通员工")){                     jCBAuthority.setSelectedIndex(0);                 }else if (String.valueOf(v.get(1)).equals("管理员")){                     jCBAuthority.setSelectedIndex(1);                 }                 jTFsName.setText((String) v.get(2));// 姓名                 jTFsSex.setText((String) v.get(3));// 性别                 jTFsBirthday.setText((String) v.get(4));// 生日                 //jCBDepartmentStr=((String) v.get(6));// 部门                 if(String.valueOf(v.get(5)).equals("生产部")){                     jCBDepartment.setSelectedIndex(0);                 }else if (String.valueOf(v.get(5)).equals("运营部")){                     jCBDepartment.setSelectedIndex(1);                 }else if (String.valueOf(v.get(5)).equals("行政部")){                     jCBDepartment.setSelectedIndex(2);                 }else if (String.valueOf(v.get(5)).equals("人事部")){                     jCBDepartment.setSelectedIndex(3);                 }                 jTFsJob.setText((String) v.get(6));// 职务                 /*if(String.valueOf(v.get(7)).equals("员工")){                     jCBJob.setSelectedIndex(0);                 }else if (String.valueOf(v.get(7)).equals("组长")){                     jCBJob.setSelectedIndex(1);                 }else if (String.valueOf(v.get(7)).equals("主任")){                     jCBJob.setSelectedIndex(2);                 }else if (String.valueOf(v.get(7)).equals("经理")){                     jCBJob.setSelectedIndex(3);                 }*/                 //jTFsEdu_Level.setText((String) v.get(8));// 教育水平                 if(String.valueOf(v.get(7)).equals("小学")){                     jCBEdu_Level.setSelectedIndex(0);                 }else if (String.valueOf(v.get(7)).equals("初中")){                     jCBEdu_Level.setSelectedIndex(1);                 }else if (String.valueOf(v.get(7)).equals("高中")){                     jCBEdu_Level.setSelectedIndex(2);                 }else if (String.valueOf(v.get(7)).equals("职高")){                     jCBEdu_Level.setSelectedIndex(3);                 }else if (String.valueOf(v.get(7)).equals("大本")){                     jCBEdu_Level.setSelectedIndex(4);                 }else if (String.valueOf(v.get(7)).equals("大专")){                     jCBEdu_Level.setSelectedIndex(5);                 }else if (String.valueOf(v.get(7)).equals("硕士")){                     jCBEdu_Level.setSelectedIndex(6);                 }else if (String.valueOf(v.get(7)).equals("博士")){                     jCBEdu_Level.setSelectedIndex(7);                 }else if (String.valueOf(v.get(7)).equals("博士后")){                     jCBEdu_Level.setSelectedIndex(7);                 }                 jTFsSpecialty.setText((String) v.get(8));// 专业技能                 jTFsAddress.setText((String) v.get(9));// 住址                 jTFsTel.setText((String) v.get(10));// 电话                 jTFsEmail.setText((String) v.get(11));// 邮箱                 jTFsState.setText((String) v.get(12));//状态                 jTFsRemark.setText((String) v.get(13));// 备注             }         });          jP1 = new JPanel();         jP2 = new JPanel();         jP3 = new JPanel();         jP4 = new JPanel();         jP5 = new JPanel();         jP6 = new JPanel();         jP7 = new JPanel();         jPTop = new JPanel();         jPBottom = new JPanel();                  jP1.add(jLStaff,BorderLayout.NORTH);         jP2.add(staffJScrollPane);                  jP3.add(jLSelectQueryField);         jP3.add(jCBSelectQueryField);         jP3.add(jLEqual);         jP3.add(jTFQueryField);         jP3.add(jBQuery);         jP3.add(jBQueryAll);         jP3.setLayout(new FlowLayout(FlowLayout.CENTER));         jP3.setPreferredSize(new Dimension(20,20));                  jP4.add(jLsID);         jP4.add(jTFsID);         //jP4.add(jLsPassword);         //jP4.add(jTFsPassword);         jP4.add(jLsAuthority);         jP4.add(jCBAuthority);         jP4.add(jLsDepartment);         jP4.add(jCBDepartment);         //jP4.add(jLsJob);         //jP4.add(jCBJob);         jP4.add(jLsEdu_Level);         jP4.add(jCBEdu_Level);         jP4.setLayout(new FlowLayout(FlowLayout.CENTER));         jP4.setPreferredSize(new Dimension(20,20));          jP5.add(jLsName);         jP5.add(jTFsName);         jP5.add(jLsSex);         jP5.add(jTFsSex);         jP5.add(jLsJob);         jP5.add(jTFsJob);         jP5.add(jLsBirthday);         jP5.add(jTFsBirthday);         jP5.add(jLsSpecialty);         jP5.add(jTFsSpecialty);         jP5.setLayout(new FlowLayout(FlowLayout.CENTER));         jP5.setPreferredSize(new Dimension(20,20));          jP6.add(jLsAddress);         jP6.add(jTFsAddress);         jP6.add(jLsTel);         jP6.add(jTFsTel);         jP6.add(jLsEmail);         jP6.add(jTFsEmail);         jP6.add(jLsState);         jP6.add(jTFsState);         jP6.add(jLsRemark);         jP6.add(jTFsRemark);         jP6.setLayout(new FlowLayout(FlowLayout.CENTER));         jP6.setPreferredSize(new Dimension(20,20));          jP7.add(jLText);         jP7.add(jBUpdate);         jP7.add(jBReset);         jP7.setLayout(new FlowLayout(FlowLayout.CENTER));         jP7.setPreferredSize(new Dimension(20,20));                  jPTop.add(jP1);         jPTop.add(jP2);                  jPBottom.setLayout(new GridLayout(5, 1));         jPBottom.add(jP3);         jPBottom.add(jP4);         jPBottom.add(jP5);         jPBottom.add(jP6);         jPBottom.add(jP7);          this.add("North", jPTop);         this.add("South", jPBottom);          this.setLayout(new GridLayout(2, 1));         this.setTitle("员工档案查询修改");         this.setSize(970, 650);         this.setLocation(200, 10);         this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);         this.setVisible(true);         this.setResizable(false);         dbProcess = new DbProcess();     }      @Override     public void actionPerformed(ActionEvent e) {         if(e.getActionCommand().equals("查询")             && !jTFQueryField.getText().isEmpty()){             System.out.println("actionPerformed(). 查询");             String sQueryField = jTFQueryField.getText().trim();             jTFsID.setText("");             //jTFsPassword.setText("");             //jTFsAuthority.setText("");             jTFsName.setText("");             jTFsSex.setText("");             jTFsBirthday.setText("");             //jTFsDepartment.setText("");             //jTFsJob.setText("");             //jTFsEdu_Level.setText("");             jTFsSpecialty.setText("");             jTFsAddress.setText("");             jTFsTel.setText("");             jTFsEmail.setText("");             jTFsState.setText("");             jTFsRemark.setText("");             queryProcess(sQueryField);             jTFQueryField.setText("");         }else if(e.getActionCommand().equals("查询所有记录")) {             System.out.println("actionPerformed(). 查询所有记录");             queryAllProcess();         } else if(e.getActionCommand().equals("重置用户密码")                 && !jTFsID.getText().isEmpty()                 && !jTFsName.getText().isEmpty()                 && !jTFsSex.getText().isEmpty()                 && !jTFsJob.getText().isEmpty()                 && !jTFsBirthday.getText().isEmpty()                 && !jTFsSpecialty.getText().isEmpty()                 && !jTFsAddress.getText().isEmpty()                 && !jTFsTel.getText().isEmpty()                 && !jTFsEmail.getText().isEmpty()                 && !jTFsState.getText().isEmpty()){             System.out.println("actionPerformed(). 重置用户密码");             ResetProcess();         }else if(e.getActionCommand().equals("更新员工信息")                 && !jTFsID.getText().isEmpty()                 && !jTFsName.getText().isEmpty()                 && !jTFsSex.getText().isEmpty()                 && !jTFsJob.getText().isEmpty()                 && !jTFsBirthday.getText().isEmpty()                 && !jTFsSpecialty.getText().isEmpty()                 && !jTFsAddress.getText().isEmpty()                 && !jTFsTel.getText().isEmpty()                 && !jTFsEmail.getText().isEmpty()                 && !jTFsState.getText().isEmpty()){             try{                 String sql ="select sState from staff where sID = '"+jTFsID.getText().trim()+"';";                 dbProcess.connect();                 ResultSet rs = dbProcess.executeQuery(sql);                 rs.next();                 if(rs.getString("sState").equals("T")){                     System.out.println("actionPerformed(). 更新");                     updateProcess();                 }else {                     JOptionPane.showMessageDialog(null,                             "该员工已被辞退,无法更新!","错误",JOptionPane.ERROR_MESSAGE);                 }                 dbProcess.disconnect();             }catch(SQLException sqle){                 System.out.println("sqle = " + sqle);                 JOptionPane.showMessageDialog(null,                         "该员工已被辞退,无法更新!","错误",JOptionPane.ERROR_MESSAGE);             }         }/*else if(e.getActionCommand().equals("  返回  ")){             System.out.println("actionPerformed(). 返回");         }*//*else if(e.getActionCommand().equals("删除所有记录")){             System.out.println("actionPerformed(). 删除所有记录");             deleteAllRecordsProcess();         }*/     }      public static void main(String[] args) {         // TODO Auto-generated method stub         Login L = new Login();         //Manage M = new Manage();         //NewEmployee N = new NewEmployee();         //Employee N = new Employee();         //PersonnelChange P = new PersonnelChange();         //DatabaseCourseDesign getcon = new  DatabaseCourseDesign();     }      public void queryProcess(String sQueryField)     {         try{             // 建立查询条件             String sql = "select * from staff where ";             String queryFieldStr = jCBSelectQueryFieldTransfer(SelectQueryFieldStr);                      /*if(queryFieldStr.equals("sAge")){//int sAge.                 sql = sql + queryFieldStr;                 sql = sql + " = " + sQueryField;             }else{*/                 sql = sql + queryFieldStr;                 sql = sql + " = ";                 sql = sql + "'" + sQueryField + "';";             //}                          System.out.println("queryProcess(). sql = " + sql);                  dbProcess.connect();             ResultSet rs = dbProcess.executeQuery(sql);                  // 将查询获得的记录数据,转换成适合生成JTable的数据形式             staffVector.clear();             while(rs.next()){                 Vector v = new Vector();                 v.add(rs.getString("sID"));                 //v.add(rs.getString("sPassword"));                 v.add(rs.getString("sAuthority"));                 v.add(rs.getString("sName"));                 v.add(rs.getString("sSex"));                 v.add(rs.getString("sBirthday"));                 v.add(rs.getString("sDepartment"));                 v.add(rs.getString("sJob"));                 v.add(rs.getString("sEdu_Level"));                 v.add(rs.getString("sSpecialty"));                 v.add(rs.getString("sAddress"));                 v.add(rs.getString("sTel"));                 v.add(rs.getString("sEmail"));                 v.add(rs.getString("sState"));                 v.add(rs.getString("sRemark"));                 staffVector.add(v);             }                          staffJTable.updateUI();              dbProcess.disconnect();         }catch(SQLException sqle){             System.out.println("sqle = " + sqle);             JOptionPane.showMessageDialog(null,                 "数据操作错误","错误",JOptionPane.ERROR_MESSAGE);         }catch(Exception e){             System.out.println("e = " + e);             JOptionPane.showMessageDialog(null,                 "数据操作错误","错误",JOptionPane.ERROR_MESSAGE);         }     }          public void queryAllProcess()     {         try{             // 建立查询条件             String sql = "select * from staff;";             System.out.println("queryAllProcess(). sql = " + sql);                  dbProcess.connect();             ResultSet rs = dbProcess.executeQuery(sql);              // 将查询获得的记录数据,转换成适合生成JTable的数据形式             staffVector.clear();             while(rs.next()){                 Vector v = new Vector();                 v.add(rs.getString("sID"));                 //v.add(rs.getString("sPassword"));                 v.add(rs.getString("sAuthority"));                 v.add(rs.getString("sName"));                 v.add(rs.getString("sSex"));                 v.add(rs.getString("sBirthday"));                 v.add(rs.getString("sDepartment"));                 v.add(rs.getString("sJob"));                 v.add(rs.getString("sEdu_Level"));                 v.add(rs.getString("sSpecialty"));                 v.add(rs.getString("sAddress"));                 v.add(rs.getString("sTel"));                 v.add(rs.getString("sEmail"));                 v.add(rs.getString("sState"));                 v.add(rs.getString("sRemark"));                 staffVector.add(v);             }                          staffJTable.updateUI();              dbProcess.disconnect();         }catch(SQLException sqle){             System.out.println("sqle = " + sqle);             JOptionPane.showMessageDialog(null,                 "数据操作错误","错误",JOptionPane.ERROR_MESSAGE);         }     }      public void updateProcess()     {         String sID = jTFsID.getText().trim();         //String sPassword = jTFsPassword.getText().trim();         String sAuthority = jCBAuthorityStr;         String sName = jTFsName.getText().trim();         String sSex = jTFsSex.getText().trim();         String sBirthday = jTFsBirthday.getText().trim();         String sDepartment = "";         String sJob = jTFsJob.getText().trim();         String sEdu_Level = "";         String sSpecialty = jTFsSpecialty.getText().trim();         String sAddress = jTFsAddress.getText().trim();         String sTel = jTFsTel.getText().trim();         String sEmail = jTFsEmail.getText().trim();         String sState = jTFsState.getText().trim();         String sRemark = jTFsRemark.getText().trim();          if(jCBDepartmentStr.equals("0-生产部")){             sDepartment="生产部";         }else if(jCBDepartmentStr.equals("1-运营部")){             sDepartment="运营部";         }         else if(jCBDepartmentStr.equals("2-行政部")){             sDepartment="行政部";         }         else if(jCBDepartmentStr.equals("3-人事部")){             sDepartment="人事部";         }         /*         if(jCBJobStr.equals("0-员工")){             sJob="员工";         }else if(jCBJobStr.equals("1-组长")){             sJob="组长";         }else if(jCBJobStr.equals("2-主任")){             sJob="主任";         }else if(jCBJobStr.equals("3-经理")){             sJob="经理";         }*/          if(jCBEdu_LevelStr.equals("0-小学")){             sEdu_Level="小学";         }else if(jCBEdu_LevelStr.equals("1-初中")){             sEdu_Level="初中";         }else if(jCBEdu_LevelStr.equals("2-高中")){             sEdu_Level="高中";         }else if(jCBEdu_LevelStr.equals("3-职高")){             sEdu_Level="职高";         }else if(jCBEdu_LevelStr.equals("4-大本")){             sEdu_Level="大本";         }else if(jCBEdu_LevelStr.equals("5-大专")){             sEdu_Level="大专";         }else if(jCBEdu_LevelStr.equals("6-硕士")){             sEdu_Level="硕士";         }else if(jCBEdu_LevelStr.equals("7-博士")){             sEdu_Level="博士";         }else if(jCBEdu_LevelStr.equals("8-博士后")){             sEdu_Level="博士后";         }         // 建立更新条件         String sql = "update staff set sAuthority = '";         //sql = sql + sPassword + "', sAuthority = '";         sql = sql + sAuthority + "', sName = '";         sql = sql + sName + "', sSex = '";         sql = sql + sSex + "', sBirthday = '";         sql = sql + sBirthday + "', sDepartment = '";         sql = sql + sDepartment + "', sJob = '";         sql = sql + sJob + "', sEdu_Level = '";         sql = sql + sEdu_Level + "', sSpecialty = '";         sql = sql + sSpecialty + "', sAddress = '";         sql = sql + sAddress + "', sTel = '";         sql = sql + sTel + "', sEmail = '";         sql = sql + sEmail + "', sState = '";         sql = sql + sState + "', sRemark = '";         sql = sql + sRemark + "'";         sql = sql + " WHERE sID = '" + sID + "';";         System.out.println("updateProcess(). sql = " + sql);         try{             if (dbProcess.executeUpdate(sql) < 1) {                 System.out.println("updateProcess(). update database failed.");             }else{                 JOptionPane.showMessageDialog(null,                         "更新成功","提示",JOptionPane.INFORMATION_MESSAGE);             }         }catch(Exception e){             System.out.println("e = " + e);             JOptionPane.showMessageDialog(null,                 "数据操作错误","错误",JOptionPane.ERROR_MESSAGE);         }         queryAllProcess();     }     public void ResetProcess(){         String sPassword=this.md5.md5(jTFsID.getText().trim());         String sql = "update staff set sPassword = '";         sql = sql + sPassword + "'";         sql = sql + " WHERE sID = '" + jTFsID.getText().trim() + "';";         System.out.println("updateProcess(). sql = " + sql);         try{             if (dbProcess.executeUpdate(sql) < 1) {                 System.out.println("updateProcess(). Reset database failed.");             }else{                 JOptionPane.showMessageDialog(null,                         "重置密码成功","提示",JOptionPane.INFORMATION_MESSAGE);             }         }catch(Exception e){             System.out.println("e = " + e);             JOptionPane.showMessageDialog(null,                     "数据操作错误","错误",JOptionPane.ERROR_MESSAGE);         }     }     public String jCBSelectQueryFieldTransfer(String InputStr)     {         String outputStr = "";         System.out.println("jCBSelectQueryFieldTransfer(). InputStr = " + InputStr);                  if(InputStr.equals("工号")){             outputStr = "sID";         }else if(InputStr.equals("权限")){             outputStr = "sAuthority";         }else if(InputStr.equals("姓名")){             outputStr = "sName";         }else if(InputStr.equals("性别")){             outputStr = "sSex";         }else if(InputStr.equals("生日")){             outputStr = "sBirthday";         }else if(InputStr.equals("部门")){             outputStr = "sDepartment";         }else if(InputStr.equals("职务")){             outputStr = "sJob";         }else if(InputStr.equals("教育水平")){             outputStr = "sEdu_Level";         }else if(InputStr.equals("专业技能")){             outputStr = "sSpecialty";         }else if(InputStr.equals("状态")){             outputStr = "sState";         }         System.out.println("jCBSelectQueryFieldTransfer(). outputStr = " + outputStr);         return outputStr;     } }

4.8 员工自身信息查询修改模块

 import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.sql.ResultSet; import java.sql.SQLException;  public class Employee extends JFrame implements ActionListener {     // 定义组件     JLabel jLEmployee = null;//员工信息     JLabel jLText = null;//注释     JLabel jLsID = null;//工号     JLabel jLsPassword1 = null;//密码1     JLabel jLsPassword2 = null;//密码2     JLabel jLsAuthority = null;//权限     JLabel jLsName = null;//姓名     JLabel jLsSex = null;//性别     JLabel jLsBirthday = null;//生日     JLabel jLsDepartment = null;//部门     JLabel jLsJob = null;//职务     JLabel jLsEdu_Level = null;//教育水平     JLabel jLsSpecialty = null;//专业技能     JLabel jLsAddress = null;//住址     JLabel jLsTel = null;//电话     JLabel jLsEmail = null;//邮箱     JLabel jLsState = null;//状态     JLabel jLsRemark = null;//备注     JTextField jTFsID = null;//工号     JPasswordField jPFsPassword1 = null;//密码1     JPasswordField jPFsPassword2 = null;//密码2     JTextField jTFsAuthority = null;//权限     JTextField jTFsName = null;//姓名     JTextField jTFsSex = null;//性别     JTextField jTFsBirthday = null;//生日     JTextField jTFsDepartment = null;//部门     JTextField jTFsJob = null;//职务     JTextField jTFsEdu_Level = null;//教育水平     JTextField jTFsSpecialty = null;//专业技能     JTextField jTFsAddress = null;//住址     JTextField jTFsTel = null;//电话     JTextField jTFsEmail = null;//邮箱     JTextField jTFsState = null;//状态     JTextField jTFsRemark = null;//备注      JButton jBUpdateInfo = null;//更新信息     JButton jBUpdatePwd = null;//修改密码      //JComboBox jCBSelectQueryField = null;      JPanel jP1, jP2,jP3, jP4, jP5,jP6 = null;     JPanel jP = null;      JScrollPane EmployeeJScrollPane = null;      private static DbProcess EdbProcess;     private static Md5 md5;     // 构造函数     public Employee(ResultSet rs) {         this.md5=new Md5();         // 创建标签组件         try {             jLEmployee = new JLabel("员工信息");             jLEmployee.setFont(new Font("宋体",Font.BOLD,25));             jLText = new JLabel("注意:更新信息需要填写上方所有带*的内容,修改密码只需要输入两次新密码即可!");             jLText.setFont(new Font("宋体",Font.BOLD,15));             jLText.setForeground(Color.red);             jLsID = new JLabel("工号*");             jLsPassword1 = new JLabel("新密码*");             jLsPassword2 = new JLabel("确认新密码*");             jLsAuthority = new JLabel("权限*");             jLsName = new JLabel("姓名*");             jLsSex = new JLabel("性别*");             jLsBirthday = new JLabel("生日*");             jLsDepartment = new JLabel("部门*");             jLsJob = new JLabel("职务*");             jLsEdu_Level = new JLabel("教育水平*");             jLsSpecialty = new JLabel("专业技能*");             jLsAddress = new JLabel("住址*");             jLsTel = new JLabel("电话*");             jLsEmail = new JLabel("邮箱*");             jLsState = new JLabel("状态*");             jLsRemark = new JLabel("备注");             EdbProcess = new DbProcess();             jTFsID = new JTextField(15);//工号             jTFsID.setEditable(false);             jTFsID.setText(rs.getString(1));              jPFsPassword1 = new JPasswordField(15);//密码             //jTFsPassword1.setText(rs.getString(2));             jPFsPassword2 = new JPasswordField(15);//密码             //jTFsPassword2.setText(rs.getString(2));              jTFsAuthority = new JTextField(15);//权限             jTFsAuthority.setEditable(false);             jTFsAuthority.setText(rs.getString(3));              jTFsName = new JTextField(15);//姓名             jTFsName.setEditable(false);             jTFsName.setText(rs.getString(4));              jTFsSex = new JTextField(15);//性别             jTFsSex.setEditable(false);             jTFsSex.setText(rs.getString(5));              jTFsBirthday = new JTextField(15);//生日             jTFsBirthday.setEditable(false);             jTFsBirthday.setText(rs.getString(6));              jTFsDepartment = new JTextField(15);//部门             jTFsDepartment.setEditable(false);             jTFsDepartment.setText(rs.getString(7));              jTFsJob = new JTextField(15);//职务             jTFsJob.setEditable(false);             jTFsJob.setText(rs.getString(8));              jTFsEdu_Level = new JTextField(15);//教育水平             jTFsEdu_Level.setEditable(false);             jTFsEdu_Level.setText(rs.getString(9));              jTFsSpecialty = new JTextField(15);//专业技能             jTFsSpecialty.setText(rs.getString(10));              jTFsAddress = new JTextField(15);//住址             jTFsAddress.setText(rs.getString(11));              jTFsTel = new JTextField(15);//电话             jTFsTel.setText(rs.getString(12));              jTFsEmail = new JTextField(15);//邮箱             jTFsEmail.setText(rs.getString(13));              jTFsState = new JTextField(15);//状态             jTFsState.setEditable(false);             jTFsState.setText(rs.getString(14));              jTFsRemark = new JTextField(15);//备注             jTFsRemark.setEditable(false);             jTFsRemark.setText(rs.getString(15));              jBUpdateInfo = new JButton("更新信息");             jBUpdateInfo.setFont(new Font("宋体",Font.BOLD,20));             jBUpdatePwd = new JButton("修改密码");             jBUpdatePwd.setFont(new Font("宋体",Font.BOLD,20));             // 设置监听             jBUpdateInfo.addActionListener(this);             jBUpdatePwd.addActionListener(this);             //studentTableModel = new DefaultTableModel(tableTitle, 15);             EmployeeJScrollPane = new JScrollPane();              jP1 = new JPanel();             jP2 = new JPanel();             jP3 = new JPanel();             jP4 = new JPanel();             jP5 = new JPanel();             jP6 = new JPanel();             jP = new JPanel();              //jP1.add(NewEmployeeJScrollPane);              jP1.add(jLEmployee);             jP1.setLayout(new FlowLayout(FlowLayout.CENTER));             jP1.setPreferredSize(new Dimension(250,80));              jP2.add(jLsID);             jP2.add(jTFsID);              jP2.add(jLsAuthority);             jP2.add(jTFsAuthority);             jP2.add(jLsName);             jP2.add(jTFsName);             jP2.add(jLsSex);             jP2.add(jTFsSex);             jP2.setLayout(new FlowLayout(FlowLayout.CENTER));             jP2.setPreferredSize(new Dimension(250,80));              jP3.add(jLsBirthday);             jP3.add(jTFsBirthday);             jP3.add(jLsDepartment);             jP3.add(jTFsDepartment);             jP3.add(jLsJob);             jP3.add(jTFsJob);             jP3.add(jLsEdu_Level);             jP3.add(jTFsEdu_Level);             jP3.add(jLsSpecialty);             jP3.add(jTFsSpecialty);             jP3.setLayout(new FlowLayout(FlowLayout.CENTER));             jP3.setPreferredSize(new Dimension(250,80));              jP4.add(jLsAddress);             jP4.add(jTFsAddress);             jP4.add(jLsTel);             jP4.add(jTFsTel);             jP4.add(jLsEmail);             jP4.add(jTFsEmail);             jP4.add(jLsState);             jP4.add(jTFsState);             jP4.add(jLsRemark);             jP4.add(jTFsRemark);             jP4.setLayout(new FlowLayout(FlowLayout.CENTER));             jP4.setPreferredSize(new Dimension(250,80));              jP5.add(jLText);             jP5.add(jBUpdateInfo);             jP5.setLayout(new FlowLayout(FlowLayout.CENTER));             jP5.setPreferredSize(new Dimension(250,80));              jP6.add(jLsPassword1);             jP6.add(jPFsPassword1);             jP6.add(jLsPassword2);             jP6.add(jPFsPassword2);             jP6.add(jBUpdatePwd);             jP6.setLayout(new FlowLayout(FlowLayout.CENTER));             jP6.setPreferredSize(new Dimension(250,80));              jP.setLayout(new GridLayout(6, 1));             jP.add(jP1);             jP.add(jP2);             jP.add(jP3);             jP.add(jP4);             jP.add(jP5);             jP.add(jP6);              this.add("North", EmployeeJScrollPane);             this.add("South", jP);              this.setLayout(new BorderLayout());             this.add(jP,BorderLayout.SOUTH);              this.setTitle("员工信息查询修改");             this.setSize(970, 450);             this.setLocation(200, 150);             this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);             this.setVisible(true);             this.setResizable(false);          }catch (SQLException sqle){             System.out.println("sqle = " + sqle);             JOptionPane.showMessageDialog(null,                     "你输入的工号不存在,请从新输入!","错误",JOptionPane.ERROR_MESSAGE);         }      }     public void actionPerformed(ActionEvent e) {         if(e.getActionCommand().equals("更新信息")                 && !jTFsSpecialty.getText().isEmpty()                 && !jTFsAddress.getText().isEmpty()                 && !jTFsTel.getText().isEmpty()                 && !jTFsEmail.getText().isEmpty()){             System.out.println("actionPerformed(). 更新");             updateProcess();         }else if(e.getActionCommand().equals("修改密码")                 &&!String.valueOf(jPFsPassword1.getPassword()).equals("")                 &&!String.valueOf(jPFsPassword2.getPassword()).equals("")){             String sPassword1 = new String(jPFsPassword1.getPassword());             String sPassword2 = new String(jPFsPassword2.getPassword());             if(sPassword1.equals(sPassword2)){                 changePwdProcess(this.md5.md5(sPassword1));             }else{                 System.out.println("两次密码不一致");                 JOptionPane.showMessageDialog(null,                         "两次密码不一致,请确认后再输入!","提示",JOptionPane.INFORMATION_MESSAGE);             }             jPFsPassword1.setText("");             jPFsPassword2.setText("");         }     }     public void updateProcess(){         String sID = jTFsID.getText().trim();         //String sPassword = jPFsPassword1.getText().trim();         String sSpecialty = jTFsSpecialty.getText().trim();         String sAddress = jTFsAddress.getText().trim();         String sTel = jTFsTel.getText().trim();         String sEmail = jTFsEmail.getText().trim();          // 建立更新条件         String sql = "update staff set sSpecialty = '";         //sql = sql + sPassword + "', sSpecialty = '";         sql = sql + sSpecialty + "', sAddress = '";         sql = sql + sAddress + "', sTel = '";         sql = sql + sTel + "', sEmail = '";         sql = sql + sEmail + "'";         sql = sql + " WHERE sID = '" + sID + "';";         System.out.println("updateProcess(). sql = " + sql);         try{             if (EdbProcess.executeUpdate(sql) < 1) {                 System.out.println("updateProcess(). update database failed.");             }else{                 JOptionPane.showMessageDialog(null,                         "更新成功!","提示",JOptionPane.INFORMATION_MESSAGE);             }         }catch(Exception e){             System.out.println("e = " + e);             JOptionPane.showMessageDialog(null,                     "数据操作错误","错误",JOptionPane.ERROR_MESSAGE);         }     }     public void changePwdProcess(String sPassword){         String sql = "update staff set sPassword = '";         sql = sql + sPassword + "'";         sql = sql + " WHERE sID = '" + jTFsID.getText().trim() + "';";         System.out.println("changePwdProcess(). sql = " + sql);         try{             if (EdbProcess.executeUpdate(sql) < 1) {                 System.out.println("changePwdProcess(). update database failed.");             }else{                 JOptionPane.showMessageDialog(null,                         "修改密码成功!","提示",JOptionPane.INFORMATION_MESSAGE);             }         }catch(Exception e){             System.out.println("e = " + e);             JOptionPane.showMessageDialog(null,                     "数据操作错误","错误",JOptionPane.ERROR_MESSAGE);         }     } }

4.9 数据库代码

如果下面的代码运行不了的,可以直接参考4.10建好相应的表,然后执行insert语句就行了,再有问题我是真没办法了。

/*  Navicat Premium Data Transfer   Source Server         : test  Source Server Type    : MySQL  Source Server Version : 80030  Source Host           : localhost:3306  Source Schema         : coursedesign   Target Server Type    : MySQL  Target Server Version : 80030  File Encoding         : 65001   Date: 31/07/2023 18:00:09 */  SET NAMES utf8mb4; SET FOREIGN_KEY_CHECKS = 0;  -- ---------------------------- -- Table structure for changecode -- ---------------------------- DROP TABLE IF EXISTS `changecode`; CREATE TABLE `changecode`  (   `cCode` varchar(1) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL,   `cDescription` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL,   PRIMARY KEY (`cCode`) USING BTREE ) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci ROW_FORMAT = Dynamic;  -- ---------------------------- -- Records of changecode -- ---------------------------- INSERT INTO `changecode` VALUES ('0', '新员工加入'); INSERT INTO `changecode` VALUES ('1', '职务变动'); INSERT INTO `changecode` VALUES ('2', '辞退');  -- ---------------------------- -- Table structure for department -- ---------------------------- DROP TABLE IF EXISTS `department`; CREATE TABLE `department`  (   `dID` varchar(10) CHARACTER SET gbk COLLATE gbk_chinese_ci NOT NULL,   `dName` varchar(16) CHARACTER SET gbk COLLATE gbk_chinese_ci NOT NULL,   `sID` varchar(15) CHARACTER SET gbk COLLATE gbk_chinese_ci NOT NULL,   `dIntro` varchar(20) CHARACTER SET gbk COLLATE gbk_chinese_ci NULL DEFAULT NULL,   PRIMARY KEY (`dID`) USING BTREE,   INDEX `sID`(`sID`) USING BTREE,   CONSTRAINT `department_ibfk_1` FOREIGN KEY (`sID`) REFERENCES `staff` (`sID`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE = InnoDB CHARACTER SET = gbk COLLATE = gbk_chinese_ci ROW_FORMAT = Dynamic;  -- ---------------------------- -- Records of department -- ---------------------------- INSERT INTO `department` VALUES ('0', '生产部', '10004', '生产管理'); INSERT INTO `department` VALUES ('1', '运营部', '10003', '运营管理'); INSERT INTO `department` VALUES ('2', '行政部', '10002', '行政管理'); INSERT INTO `department` VALUES ('3', '人事部', '10001', '人事管理');  -- ---------------------------- -- Table structure for edu -- ---------------------------- DROP TABLE IF EXISTS `edu`; CREATE TABLE `edu`  (   `eCode` varchar(1) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL,   `eDescription` varchar(6) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL,   PRIMARY KEY (`eCode`) USING BTREE ) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci ROW_FORMAT = Dynamic;  -- ---------------------------- -- Records of edu -- ---------------------------- INSERT INTO `edu` VALUES ('0', '小学'); INSERT INTO `edu` VALUES ('1', '初中'); INSERT INTO `edu` VALUES ('2', '高中'); INSERT INTO `edu` VALUES ('3', '职高'); INSERT INTO `edu` VALUES ('4', '大本'); INSERT INTO `edu` VALUES ('5', '大专'); INSERT INTO `edu` VALUES ('6', '硕士'); INSERT INTO `edu` VALUES ('7', '博士'); INSERT INTO `edu` VALUES ('8', '博士后');  -- ---------------------------- -- Table structure for job -- ---------------------------- DROP TABLE IF EXISTS `job`; CREATE TABLE `job`  (   `jCode` varchar(1) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL,   `jDescription` varchar(10) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL,   PRIMARY KEY (`jCode`) USING BTREE ) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci ROW_FORMAT = Dynamic;  -- ---------------------------- -- Records of job -- ---------------------------- INSERT INTO `job` VALUES ('0', '员工'); INSERT INTO `job` VALUES ('1', '组长'); INSERT INTO `job` VALUES ('2', '主任'); INSERT INTO `job` VALUES ('3', '经理');  -- ---------------------------- -- Table structure for personnel -- ---------------------------- DROP TABLE IF EXISTS `personnel`; CREATE TABLE `personnel`  (   `pID` varchar(15) CHARACTER SET gbk COLLATE gbk_chinese_ci NOT NULL,   `sID` varchar(15) CHARACTER SET gbk COLLATE gbk_chinese_ci NOT NULL,   `pChange` varchar(1) CHARACTER SET gbk COLLATE gbk_chinese_ci NOT NULL,   `pDescription` varchar(20) CHARACTER SET gbk COLLATE gbk_chinese_ci NOT NULL,   PRIMARY KEY (`pID`) USING BTREE,   INDEX `sID`(`sID`) USING BTREE,   CONSTRAINT `personnel_ibfk_1` FOREIGN KEY (`sID`) REFERENCES `staff` (`sID`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE = InnoDB CHARACTER SET = gbk COLLATE = gbk_chinese_ci ROW_FORMAT = Dynamic;  -- ---------------------------- -- Records of personnel -- ---------------------------- INSERT INTO `personnel` VALUES ('100001', '10001', '0', '新员工录入'); INSERT INTO `personnel` VALUES ('100002', '10002', '0', '新员工录入'); INSERT INTO `personnel` VALUES ('100003', '10003', '0', '新员工录入'); INSERT INTO `personnel` VALUES ('100004', '10004', '0', '新员工录入'); INSERT INTO `personnel` VALUES ('100005', '10005', '0', '新员工录入'); INSERT INTO `personnel` VALUES ('100006', '10005', '1', '表现好'); INSERT INTO `personnel` VALUES ('100007', '10006', '0', '新员工录入'); INSERT INTO `personnel` VALUES ('100008', '10006', '1', '表现好'); INSERT INTO `personnel` VALUES ('100009', '10005', '2', '表现差');  -- ---------------------------- -- Table structure for staff -- ---------------------------- DROP TABLE IF EXISTS `staff`; CREATE TABLE `staff`  (   `sID` varchar(15) CHARACTER SET gbk COLLATE gbk_chinese_ci NOT NULL,   `sPassword` varchar(20) CHARACTER SET gbk COLLATE gbk_chinese_ci NOT NULL,   `sAuthority` varchar(8) CHARACTER SET gbk COLLATE gbk_chinese_ci NOT NULL,   `sName` varchar(20) CHARACTER SET gbk COLLATE gbk_chinese_ci NOT NULL,   `sSex` varchar(2) CHARACTER SET gbk COLLATE gbk_chinese_ci NOT NULL,   `sBirthday` varchar(8) CHARACTER SET gbk COLLATE gbk_chinese_ci NOT NULL,   `sDepartment` varchar(10) CHARACTER SET gbk COLLATE gbk_chinese_ci NOT NULL,   `sJob` varchar(16) CHARACTER SET gbk COLLATE gbk_chinese_ci NOT NULL,   `sEdu_Level` varchar(6) CHARACTER SET gbk COLLATE gbk_chinese_ci NOT NULL,   `sSpecialty` varchar(20) CHARACTER SET gbk COLLATE gbk_chinese_ci NOT NULL,   `sAddress` varchar(40) CHARACTER SET gbk COLLATE gbk_chinese_ci NOT NULL,   `sTel` varchar(11) CHARACTER SET gbk COLLATE gbk_chinese_ci NOT NULL,   `sEmail` varchar(20) CHARACTER SET gbk COLLATE gbk_chinese_ci NOT NULL,   `sState` varchar(1) CHARACTER SET gbk COLLATE gbk_chinese_ci NOT NULL,   `sRemark` varchar(20) CHARACTER SET gbk COLLATE gbk_chinese_ci NULL DEFAULT NULL,   PRIMARY KEY (`sID`) USING BTREE ) ENGINE = InnoDB CHARACTER SET = gbk COLLATE = gbk_chinese_ci ROW_FORMAT = Dynamic;  -- ---------------------------- -- Records of staff -- ---------------------------- INSERT INTO `staff` VALUES ('10001', '646368', '管理员', 'wx', '男', '20202020', '人事部', '经理', '大本', 'java', '湖南省', '13366668888', 'w@x', 'T', ''); INSERT INTO `staff` VALUES ('10002', '646371', '普通员工', 'sd', '男', '20202020', '行政部', '经理', '大本', 'c语言', '湖南省', '15566668888', 's@d', 'T', ''); INSERT INTO `staff` VALUES ('10003', '646370', '普通员工', 'nj', '男', '20202020', '运营部', '经理', '大本', 'javaspring', '湖南省', '15577778888', 'n@j', 'T', ''); INSERT INTO `staff` VALUES ('10004', '646373', '普通员工', 'cq', '男', '20202020', '生产部', '经理', '大本', 'c++', '广东省', '16699998888', 'c@q', 'T', ''); INSERT INTO `staff` VALUES ('10005', '646372', '普通员工', '张三', '女', '20202020', '生产部', '主任', '初中', 'java', '广东省', '1555', '张@s', 'F', ''); INSERT INTO `staff` VALUES ('10006', '646375', '普通员工', '李四', '男', '20192019', '生产部', '组长', '大本', '汇编语言', '广东省', '13355556666', '李@四', 'T', '');  SET FOREIGN_KEY_CHECKS = 1; 

4.10 数据库表结构

(1)员工信息表staff

(2)人事变更记录表personnel

(3)部门信息表department

(4)教育水平表edu

(5)职务表job

(6)人事变更代码表changecode

5 界面图预览

5.1 登录界面

5.2 管理界面

5.3 新员工档案录入界面

5.4 人事变更界面

5.5 管理员员工档案查询修改界面

5.6 员工自身信息查询修改界面

广告一刻

为您即时展示最新活动产品广告消息,让您随时掌握产品活动新动态!