基于JavaSwing+MySQL+Eclipse【合同管理系统源代码】

1.项目源代码结构:

2.项目运行截图

登录界面运行截图:

登陆成功操作截图如果输入管理员正确账号和密码,进入主界面则出现以下截图

查看员工的所有数据

查询

添加员工

删除员工:

岗位界面截图

岗位查询:

岗位修改:

岗位添加:

3.系统功能介绍

4.SQL文件

/*
SQLyog Ultimate v12.08 (32 bit)
MySQL - 5.5.15 : Database - office
*********************************************************************
*/

/*!40101 SET NAMES utf8 */;

/*!40101 SET SQL_MODE=''*/;

/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
CREATE DATABASE /*!32312 IF NOT EXISTS*/`office` /*!40100 DEFAULT CHARACTER SET utf8 */;

USE `office`;

/*Table structure for table `t_contract` */

DROP TABLE IF EXISTS `t_contract`;

CREATE TABLE `t_contract` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `contractno` varchar(100) DEFAULT NULL,
  `contractdate` datetime DEFAULT NULL,
  `state` varchar(10) DEFAULT NULL,
  `staffid` int(11) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8;

/*Data for the table `t_contract` */

insert  into `t_contract`(`id`,`contractno`,`contractdate`,`state`,`staffid`) values (1,'0001','2022-08-10 00:00:00','变更',1),(2,'0002','2022-01-15 00:00:00','解除',2);

/*Table structure for table `t_deptype` */

DROP TABLE IF EXISTS `t_deptype`;

CREATE TABLE `t_deptype` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `depname` varchar(50) DEFAULT NULL,
  `depdesc` varchar(200) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;

/*Data for the table `t_deptype` */

insert  into `t_deptype`(`id`,`depname`,`depdesc`) values (1,'人事部','人事管工作'),(2,'仓储部','仓库物品及物流管理部门'),(3,'研发部','研发部');

/*Table structure for table `t_posttype` */

DROP TABLE IF EXISTS `t_posttype`;

CREATE TABLE `t_posttype` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `postname` varchar(50) DEFAULT NULL,
  `postdesc` varchar(50) DEFAULT NULL,
  `postlevel` varchar(50) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8;

/*Data for the table `t_posttype` */

insert  into `t_posttype`(`id`,`postname`,`postdesc`,`postlevel`) values (1,'人事副部长','人事副部长','1'),(2,'仓储物管','仓库物管负责人','组长');

/*Table structure for table `t_staff` */

DROP TABLE IF EXISTS `t_staff`;

CREATE TABLE `t_staff` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `staffname` varchar(100) DEFAULT NULL,
  `identify` varchar(100) DEFAULT NULL,
  `sex` varchar(10) DEFAULT NULL,
  `postid` int(11) DEFAULT NULL,
  `depid` int(11) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;

/*Data for the table `t_staff` */

insert  into `t_staff`(`id`,`staffname`,`identify`,`sex`,`postid`,`depid`) values (1,'陈老板','430621199904250539','男',1,1),(2,'张工','4320554120524112','男',2,2),(3,'刘老哥','430918851255420','男',2,2);

/*Table structure for table `t_user` */

DROP TABLE IF EXISTS `t_user`;

CREATE TABLE `t_user` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `username` varchar(50) DEFAULT NULL,
  `password` varchar(50) DEFAULT NULL,
  `userid` int(11) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;

/*Data for the table `t_user` */

insert  into `t_user`(`id`,`username`,`password`,`userid`) values (1,'wenber','123',1);

/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;

5.部分代码展示

Staff.java

package com.wenber.entity;

/**
 * 员工对象
 * @author Code人生
 *
 */
public class Staff {
	
	int id; 
	String staffname; 
	String identify;
 	String sex; 
	DeptType dept;
 	PostType post;
 	
 	public Staff() {
	}
 	
 	
 	public Staff( String staffname, String identify, String sex) {
		super();
		this.staffname = staffname;
		this.identify = identify;
		this.sex = sex;
	}



	public Staff(String staffname, String identify, String sex, DeptType dept, PostType post) {
		super();
		this.staffname = staffname;
		this.identify = identify;
		this.sex = sex;
		this.dept = dept;
		this.post = post;
	}
 	
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public String getStaffname() {
		return staffname;
	}
	public void setStaffname(String staffname) {
		this.staffname = staffname;
	}
	public String getIdentify() {
		return identify;
	}
	public void setIdentify(String identify) {
		this.identify = identify;
	}
	public String getSex() {
		return sex;
	}
	public void setSex(String sex) {
		this.sex = sex;
	}
	
	public DeptType getDept() {
		return dept;
	}

	public void setDept(DeptType dept) {
		this.dept = dept;
	}

	public PostType getPost() {
		return post;
	}

	public void setPost(PostType post) {
		this.post = post;
	}

	@Override
	public String toString() {
		return  staffname + "=" + dept.getDepName() + "=" + post.getPostName();
	}

}

PostType.java

package com.wenber.entity;

/**
 * 岗位
 * @author Code人生
 *
 */
public class PostType {

	private int id;
	private String postName;
	private String postDesc;
	private String postLevel;
	
	public PostType() {
	}
	
	public PostType(String postName) {
		this.postName = postName;
	}



	public PostType(String postName, String postDesc, String postLevel) {
		super();
		this.postName = postName;
		this.postDesc = postDesc;
		this.postLevel = postLevel;
	}
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public String getPostName() {
		return postName;
	}
	public void setPostName(String postName) {
		this.postName = postName;
	}
	public String getPostDesc() {
		return postDesc;
	}
	public void setPostDesc(String postDesc) {
		this.postDesc = postDesc;
	}
	public String getPostLevel() {
		return postLevel;
	}
	public void setPostLevel(String postLevel) {
		this.postLevel = postLevel;
	}

	@Override
	public String toString() {
		return  postName ;
	}

	
}

StaffDao.java

package com.wenber.dao;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import com.yyw.entity.DeptType;
import com.yyw.entity.PostType;
import com.yyw.entity.Staff;
import com.yyw.utils.DBUtils;

/**
 * 员工数据处理层
 * @author Code人生
 *
 */
public class StaffDao {
	
	/**
	 * 查询
	 * @param id 员工
	 * @return 对象
	 */
	public Staff findStaffByID(int id){
		Connection conn=DBUtils.getConnection();
		String sql="select * from t_staff ts left join t_posttype post on post.id=ts.postid left join t_deptype dept on dept.id=ts.depid where ts.id="+id;
		Staff staff=null;
		try {
			Statement stat=conn.createStatement();
			//执行SQL 
			ResultSet rs=stat.executeQuery(sql);
			if (rs.next()) {
				String staffname=rs.getString("staffname");
				String identify=rs.getString("identify");
				String sex=rs.getString("sex");
				
				PostType post=new PostType(rs.getString("postname"));
				DeptType dept=new DeptType(rs.getString("depname"));
				//组装
				staff=new Staff(staffname, identify, sex, dept, post);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}finally{
			DBUtils.closeConn(conn);
		}
		return staff;
	}
	
	/**
	 * 修改数据
	 * @param staff
	 * @return
	 */
	public int editStaff(Staff staff){
		Connection conn=DBUtils.getConnection();
		String sql="update t_staff set staffname=?,identify=?,sex=?,depid=?,postid=? where id=?";
		int row=0;
		QueryRunner qr=new QueryRunner();
		try {
			row=qr.update(conn, sql,staff.getStaffname(),staff.getIdentify(),staff.getSex(),staff.getDept().getId(),staff.getPost().getId(),staff.getId());
		} catch (Exception e) {
			e.printStackTrace();
		}finally{
			DBUtils.closeConn(conn);
		}
		return row;
	}
	
	/**
	 * 保存数据
	 * @param staff
	 * @return
	 */
	public int saveStaff(Staff staff){
		Connection conn=DBUtils.getConnection();
		String sql="insert into t_staff(staffname,identify,sex,depid,postid) values(?,?,?,?,?)";
		int row=0;
		QueryRunner qr=new QueryRunner();
		try {
			row=qr.update(conn, sql, staff.getStaffname(),staff.getIdentify(),staff.getSex(),staff.getDept().getId(),staff.getPost().getId());
		} catch (Exception e) {
			e.printStackTrace();
		}finally{
			DBUtils.closeConn(conn);
		}
		return row;
	}
	
	/**
	 * 根据输入ID删除对象
	 * @param id 员工ID
	 * @return 删除的行数
	 */
	public int removeStaffById(int id){
		Connection conn=DBUtils.getConnection();
		String sql="delete from t_staff where id=?";
		QueryRunner qr=new QueryRunner();
		int row=0;
		try {
			row=qr.update(conn, sql, id);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return row;
	}
	
	
	/**
	 * 查询员工 没有签合同
	 * @return
	 */
	public List<Staff> findStaffListForContract(){
		Connection conn=DBUtils.getConnection();
		String sql="select * from t_staff ts left join t_posttype post on post.id=ts.postid left join t_deptype dept on dept.id=ts.depid left join t_contract tc on tc.staffid=ts.id where contractno is null";
		
		System.out.println(sql);
		//查询器
		List<Staff> staffList=new ArrayList<Staff>();
		try {
			Statement stat=conn.createStatement();
			//执行SQL 
			ResultSet rs=stat.executeQuery(sql);
			while (rs.next()) {
				String staffname=rs.getString("staffname");
				String identify=rs.getString("identify");
				String sex=rs.getString("sex");
				
				PostType post=new PostType(rs.getString("postname"));
				DeptType dept=new DeptType(rs.getString("depname"));
				//组装
				Staff staff=new Staff(staffname, identify, sex, dept, post);
				staff.setId(rs.getInt("ts.id"));
				staffList.add(staff);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}finally{
			//执行完成关闭连接
			DBUtils.closeConn(conn);
		}
		return staffList;
	}
	
	/**
	 * 重载查询方法
	 * @return
	 */
	public List<Staff> findStaffList(){
		return this.findStaffList("", "","");
	}
	
	/**
	 * 取得信息表
	 * @return 返回列表
	 */
	public List<Staff> findStaffList(String id,String name,String idcard){
		
		Connection conn=DBUtils.getConnection();
		String sql="select * from t_staff ts left join t_posttype post on post.id=ts.postid left join t_deptype dept on dept.id=ts.depid where 1=1";//拼接SQL的小技巧
		String condition="";
		if(name!=null && !name.equals("")){
			condition+=" and staffname='"+name+"'";
		}
		if(idcard!=null && !idcard.equals("")){
			condition+=" and identify='"+idcard+"'";
		}
		if(id!=null && !id.equals("")){
			condition+=" and ts.id="+Integer.parseInt(id);
		}
		//将条件拼在SQL的最后
		sql+=condition;
		System.out.println(sql);
		//查询器
		List<Staff> staffList=new ArrayList<Staff>();
		try {
			Statement stat=conn.createStatement();
			//执行SQL 
			ResultSet rs=stat.executeQuery(sql);
			while (rs.next()) {
				String staffname=rs.getString("staffname");
				String identify=rs.getString("identify");
				String sex=rs.getString("sex");
				
				PostType post=new PostType(rs.getString("postname"));
				DeptType dept=new DeptType(rs.getString("depname"));
				//组装
				Staff staff=new Staff(staffname, identify, sex, dept, post);
				staff.setId(rs.getInt("ts.id"));
				staffList.add(staff);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}finally{
			//执行完成关闭连接
			DBUtils.closeConn(conn);
		}
		return staffList;
	}
	
}

6.项目下载地址

https://download.csdn.net/download/wenber888/89488452

  • 14
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
很抱歉,我作为一名语言模型,并不具备编写完整程序的能力,我无法为您提供完整的源代码。但是我可以给您提供一些参考和思路,希望对您有所帮助。 首先您需要了解 Java SwingMySQL 数据库的基础知识,这是您编写学生成绩管理系统的基础。其次您需要掌握 JDBC(Java Database Connectivity)编程,这是 Java数据库交互的重要手段。 接下来,我为您提供一个基本的程序框架,您可以根据这个框架进行代码编写。 ```java import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.sql.*; public class StudentGradeManagementSystem extends JFrame implements ActionListener { // 用户登录界面控件 private JLabel userLabel; private JLabel passwordLabel; private JTextField userText; private JPasswordField passwordText; private JButton loginButton; private JButton registerButton; // 学生管理界面控件 // TODO // 教师管理界面控件 // TODO public StudentGradeManagementSystem() { // 用户登录界面初始化 userLabel = new JLabel("用户名"); passwordLabel = new JLabel("密码"); userText = new JTextField(20); passwordText = new JPasswordField(20); loginButton = new JButton("登录"); registerButton = new JButton("注册"); // 用户登录界面布局 JPanel loginPanel = new JPanel(new GridLayout(3, 2)); loginPanel.add(userLabel); loginPanel.add(userText); loginPanel.add(passwordLabel); loginPanel.add(passwordText); loginPanel.add(loginButton); loginPanel.add(registerButton); // 添加事件监听器 loginButton.addActionListener(this); registerButton.addActionListener(this); // TODO: 学生管理界面和教师管理界面的初始化和布局 // 设置窗口标题和大小,显示窗口 setTitle("学生成绩管理系统"); setSize(600, 400); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setLayout(new CardLayout()); add(loginPanel, "loginPanel"); // TODO: 添加学生管理界面和教师管理界面 setVisible(true); } @Override public void actionPerformed(ActionEvent e) { if (e.getSource() == loginButton) { // 用户登录逻辑 String username = userText.getText(); String password = new String(passwordText.getPassword()); if (login(username, password)) { // 登录成功,显示学生管理界面或教师管理界面 // TODO } else { JOptionPane.showMessageDialog(this, "用户名或密码错误!"); } } else if (e.getSource() == registerButton) { // 用户注册逻辑 // TODO } else { // TODO: 学生管理界面和教师管理界面的事件处理 } } private boolean login(String username, String password) { String driver = "com.mysql.jdbc.Driver"; String url = "jdbc:mysql://localhost:3306/student"; String user = "root"; String pass = "123456"; String sql = "select * from users where username=? and password=?"; try { Class.forName(driver); Connection conn = DriverManager.getConnection(url, user, pass); PreparedStatement pstmt = conn.prepareStatement(sql); pstmt.setString(1, username); pstmt.setString(2, password); ResultSet rs = pstmt.executeQuery(); if (rs.next()) { rs.close(); pstmt.close(); conn.close(); return true; } rs.close(); pstmt.close(); conn.close(); } catch (Exception e) { e.printStackTrace(); } return false; } public static void main(String[] args) { new StudentGradeManagementSystem(); } } ``` 以上是一个基本的程序框架,包括用户登录界面和学生管理界面、教师管理界面的初始化和布局,以及登录和注册的事件处理。 您需要根据这个框架,实现学生和教师管理界面的控件和事件处理,以及数据库的连接和操作。在编写过程中,您可以参考 Java SwingMySQL 的相关文档和教程,以及相关的开源项目和示例代码,提高编程效率。 希望以上内容对您有所帮助。如果您有更多问题,请随时向我提问。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Code好友

今日滴水之恩,明日“洪水”相报

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值