Java课程设计:考勤管理系统(附源码+调试)

JAVA/JSP考勤管理系统:

一、主要功能

     1. 在登陆界面可以选择登录方式,包括员工、管理员和经理三种身份登录方式,不同的身份登录验证通过之后就会分别跳转到不同的界面,并且获得不同的权限去进行相应的操作。

     2.员工可以根据实际情况在这个界面发出各种申请,例如加班、请假、调休、出差等,将各项信息填入到对应的文本框中点击提交按钮,然后就等待经理的审批。

     3.经理登录成功之后跳转到此界面,可以对自己的信息进行修改,能够查询员工信息、考勤记录,还能够对员工提交的各种申请进行审批。

完整源码:https://pan.baidu.com/s/1vQmgdIKXXi-1uac-ZF-0Sw    提取码:9k7d

登陆界面:提供三种登陆方式(管理员、员工、经理),每一种登陆方式对应不同的操作权限,下面的展示就按管理员的来。

Java课程设计:考勤管理系统(附源码+调试)_第1张图片

考勤管理主界面:主要的功能有系统用户管理、部门信息管理、员工信息管理、经理信息管理、考勤时间管理、考勤补录管理、考勤记录管理、考勤信息统计、系统设置。(由于功能较多,我们就不一一展示了,这里我们着重介绍员工信息管理和考勤信息统计)

Java课程设计:考勤管理系统(附源码+调试)_第2张图片

员工信息管理又分为:员工信息添加、员工信息查询(可按工号、姓名查询并且支持导出EXCEL)

Java课程设计:考勤管理系统(附源码+调试)_第3张图片

Java课程设计:考勤管理系统(附源码+调试)_第4张图片

考勤信息统计(请假信息统计、休息信息统计、加班信息统计、课休信息统计、出差信息统计)

Java课程设计:考勤管理系统(附源码+调试)_第5张图片

数据库表设计:

Java课程设计:考勤管理系统(附源码+调试)_第6张图片

部分源码展示:

登录界面(login.jsp):

<%@ page language="java" import="java.util.*" pageEncoding="gb2312"%>
<%@page import="util.Info"%>
<%@page import="dao.CommDAO"%>
<%@page import="util.PageManager"%>


考勤管理系统



     

 

 

 

 

 

 

      考勤管理系统
 
用户:
密码:
权限:
 
 

 数据库连接代码:

package dao;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Properties;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import util.Info;


public class CommDAO
{
	public static String dbname = "";
	public static String dbtype = "";
	
	public static Connection conn = null;
	
	public CommDAO()
	{
		conn = this.getConn();
	}



         //给字段做加减法
	 public void jiajian(String tablename,String colname,String id,String num)
	 {
		 HashMap map = this.getmap(id, tablename);
		 String value = map.get(colname).toString();
		 if(value.equals(""))value="0";
		 int i = Integer.parseInt(value);
		 int j = Integer.parseInt(num);
		 commOper("update "+tablename+" set "+colname+" = "+(i+j)+" where id="+id);
	 }
	
	 //	该方法返回一个table 用于流动图片
	public String DynamicImage(String categoryid,int cut,int width,int height){

		StringBuffer imgStr = new StringBuffer();
		StringBuffer thePics1 = new StringBuffer();
		StringBuffer theLinks1 = new StringBuffer();
		StringBuffer theTexts1 = new StringBuffer();
	
		imgStr.append("
\n"); return imgStr.toString(); } public HashMap getmap(String id,String table) { List list = new ArrayList(); try { Statement st = conn.createStatement(); //System.out.println("select * from "+table+" where id="+id); ResultSet rs = st.executeQuery("select * from "+table+" where id="+id); ResultSetMetaData rsmd = rs.getMetaData(); while(rs.next()) { HashMap map = new HashMap(); int i = rsmd.getColumnCount(); for(int j=1;j<=i;j++) { if(!rsmd.getColumnName(j).equals("ID")) { String str = rs.getString(j)==null?"": rs.getString(j); if(str.equals("null"))str = ""; map.put(rsmd.getColumnName(j), str); } else map.put("id", rs.getString(j)); } list.add(map); } rs.close(); st.close(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } return list.get(0); } public HashMap getmaps(String nzd,String zdz,String table) { List list = new ArrayList(); try { Statement st = conn.createStatement(); //System.out.println("select * from "+table+" where "+nzd+"='"+zdz+"'"); ResultSet rs = st.executeQuery("select * from "+table+" where "+nzd+"='"+zdz+"'"); ResultSetMetaData rsmd = rs.getMetaData(); while(rs.next()) { HashMap map = new HashMap(); int i = rsmd.getColumnCount(); for(int j=1;j<=i;j++) { if(!rsmd.getColumnName(j).equals("ID")) { String str = rs.getString(j)==null?"": rs.getString(j); if(str.equals("null"))str = ""; map.put(rsmd.getColumnName(j), str); } else map.put("id", rs.getString(j)); } list.add(map); } rs.close(); st.close(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } return list.get(0); } public String insert(HttpServletRequest request,HttpServletResponse response, String tablename,HashMap extmap,boolean alert,boolean reflush,String tzurl) { extmap.put("addtime", Info.getDateStr()); if(request.getParameter("f")!=null){ HashMap typemap = new HashMap(); ArrayList collist = new ArrayList(); String sql = "insert into "+tablename+"("; Connection conn = this.getConn(); try { Statement st = conn.createStatement(); ResultSet rs = st.executeQuery("select * from "+tablename); ResultSetMetaData rsmd = rs.getMetaData(); int i = rsmd.getColumnCount(); for(int j=1;j<=i;j++) { if(rsmd.getColumnName(j).equals("id"))continue; if(rsmd.getColumnName(j).equals("ID"))continue; if(rsmd.getColumnName(j).equals("iD"))continue; if(rsmd.getColumnName(j).equals("Id"))continue; typemap.put(rsmd.getColumnName(j)+"---", rsmd.getColumnTypeName(j)); collist.add(rsmd.getColumnName(j)); sql+=rsmd.getColumnName(j)+","; } sql = sql.substring(0,sql.length()-1); sql+=") values("; rs.close(); st.close(); } catch (SQLException e) { e.printStackTrace(); } Enumeration enumeration = request.getParameterNames(); String names = ","; while(enumeration.hasMoreElements()) { names += enumeration.nextElement().toString()+","; } try { Statement st = conn.createStatement(); for(String str:collist) { if(names.indexOf(","+str+",")>-1) { String[] values = request.getParameterValues(str); String value=""; for(String vstr:values) { if(vstr==null)vstr=""; if(vstr.equals("null"))vstr=""; if(vstr.trim().equals(""))continue; if(request.getParameter(vstr)!=null&&!"".equals(request.getParameter(vstr))&&request.getParameter("dk-"+str+"-value")!=null) { String dkv = request.getParameter(vstr); String dknamevalue = request.getParameter("dk-"+str+"-value"); vstr+=" - "+dknamevalue+":"+dkv; } value+=vstr+" ~ "; } if(value==null)value=""; if(value.equals("null"))value=""; if(value.length()>0)value=value.substring(0,value.length()-3); if(typemap.get(str+"---").equals("int")) { sql+=(value.equals("")?-10:value)+","; }else{ sql+="'"+(value.equals("null")?"":value)+"',"; } }else{ if(typemap.get(str+"---").equals("int")) { sql+=(extmap.get(str)==null?"":extmap.get(str))+","; }else{ sql+="'"+(extmap.get(str)==null?"":extmap.get(str))+"',"; } } } sql=sql.substring(0,sql.length()-1)+")"; System.out.println(sql); this.commOper(sql); st.close(); } catch (SQLException e) { e.printStackTrace(); } String str = ""; if(!reflush) str += " \n"; str += ""; PrintWriter wrt = null; try { wrt = response.getWriter(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } wrt.write(str); } return ""; } public void delete(HttpServletRequest request,String tablename) { int i = 0; try { String did = request.getParameter("did"); if(did==null)did = request.getParameter("scid"); if(did!=null){ if(did.length()>0){ Statement st = conn.createStatement(); System.out.println("delete from "+tablename+" where id="+did); st.execute("delete from "+tablename+" where id="+did); st.close(); } } } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } public String getCols(String table) { String str = ""; Connection conn = this.getConn(); try { Statement st = conn.createStatement(); ResultSet rs = st.executeQuery("select * from "+table); ResultSetMetaData rsmd = rs.getMetaData(); int i = rsmd.getColumnCount(); for(int j=2;j<=i;j++) { str+=rsmd.getColumnName(j)+","; } }catch (Exception e) { e.printStackTrace(); } str = str.substring(0,str.length()-1); return str; } public String update(HttpServletRequest request,HttpServletResponse response, String tablename,HashMap extmap,boolean alert,boolean reflush,String tzurl) { if(request.getParameter("f")!=null){ Enumeration enumeration = request.getParameterNames(); String names = ","; while(enumeration.hasMoreElements()) { names += enumeration.nextElement().toString()+","; } HashMap typemap = new HashMap(); ArrayList collist = new ArrayList(); String sql = "update "+tablename+" set "; Connection conn = this.getConn(); try { Statement st = conn.createStatement(); ResultSet rs = st.executeQuery("select * from "+tablename); ResultSetMetaData rsmd = rs.getMetaData(); int i = rsmd.getColumnCount(); System.out.println(i); for(int j=1;j<=i;j++) { if(rsmd.getColumnName(j).equals("id"))continue; if(rsmd.getColumnName(j).equals("ID"))continue; if(rsmd.getColumnName(j).equals("Id"))continue; if(rsmd.getColumnName(j).equals("iD"))continue; typemap.put(rsmd.getColumnName(j)+"---", rsmd.getColumnTypeName(j)); collist.add(rsmd.getColumnName(j)); if(names.indexOf(","+rsmd.getColumnName(j)+",")>-1) { String[] values = request.getParameterValues(rsmd.getColumnName(j)); String value=""; for(String vstr:values) { if(vstr==null)vstr=""; if(vstr.equals("null"))vstr=""; if(vstr.trim().equals(""))continue; if(request.getParameter(vstr)!=null&&!"".equals(request.getParameter(vstr))&&request.getParameter("dk-"+rsmd.getColumnName(j)+"-value")!=null) { String dkv = request.getParameter(vstr); String dknamevalue = request.getParameter("dk-"+rsmd.getColumnName(j)+"-value"); vstr+=" - "+dknamevalue+":"+dkv; System.out.println(vstr); } //if(vstr.length()<) value+=vstr+" ~ "; } if(value==null)value=""; if(value.equals("null"))value=""; if(value.length()>0)value=value.substring(0,value.length()-3); if(rsmd.getColumnTypeName(j).equals("int")) { sql+=rsmd.getColumnName(j)+"="+value+","; }else{ sql+=rsmd.getColumnName(j)+"='"+value+"',"; } }else{ if(extmap.get(rsmd.getColumnName(j))!=null) { if(rsmd.getColumnTypeName(j).equals("int")) { sql+=rsmd.getColumnName(j)+"="+extmap.get(rsmd.getColumnName(j))+","; }else{ sql+=rsmd.getColumnName(j)+"='"+extmap.get(rsmd.getColumnName(j))+"',"; } } } } sql = sql.substring(0,sql.length()-1); sql+=" where id="+request.getParameter("id"); System.out.println(sql); Statement st1 = conn.createStatement(); st1.execute(sql); st1.close(); rs.close(); st.close(); } catch (SQLException e) { e.printStackTrace(); } String str = ""; if(!reflush) str += "\n" ; str += "\n"; PrintWriter wrt = null; try { //request.get wrt = response.getWriter(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } wrt.write(str); } return ""; } public Connection getConn() { try { if(conn==null||conn.isClosed()){ Class.forName("net.sourceforge.jtds.jdbc.Driver"); conn = DriverManager.getConnection("jdbc:jtds:sqlserver://127.0.0.1:1433;databaseName=jspm53178kqglxtsx", "sa", "123456"); }} catch(Exception e) { e.printStackTrace(); } return conn; } public int getInt(String sql) { int i = 0; try { Statement st = conn.createStatement(); ResultSet rs = st.executeQuery(sql); if(rs.next()) { i = rs.getInt(1); } st.close(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } return i; } public double getDouble(String sql) { double i = 0; try { Statement st = conn.createStatement(); ResultSet rs = st.executeQuery(sql); if(rs.next()) { i = rs.getDouble(1); } st.close(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } return i; } public void commOper(String sql) { System.out.println(sql); try { Statement st = conn.createStatement(); st.execute(sql); st.close(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } public void commOperSqls(ArrayList sql) { try { conn.setAutoCommit(false); for(int i=0;i select(String sql) { System.out.println(sql); List list = new ArrayList(); try { Statement st = conn.createStatement(); ResultSet rs = st.executeQuery(sql); ResultSetMetaData rsmd = rs.getMetaData(); while(rs.next()) { HashMap map = new HashMap(); int i = rsmd.getColumnCount(); for(int j=1;j<=i;j++) { if(!rsmd.getColumnName(j).equals("ID")) { String str = rs.getString(j)==null?"": rs.getString(j); if(str.equals("null"))str = ""; map.put(rsmd.getColumnName(j), str); } else map.put("id", rs.getString(j)); } list.add(map); } rs.close(); st.close(); } catch (SQLException e) { // TODO Auto-generated catch block if(sql.equals("show tables")) list = select("select table_name from INFORMATION_SCHEMA.tables"); else e.printStackTrace(); } return list; } public List selectforlist(String sql) { List list = new ArrayList(); try { Statement st = conn.createStatement(); ResultSet rs = st.executeQuery(sql); ResultSetMetaData rsmd = rs.getMetaData(); while(rs.next()) { List list2 = new ArrayList(); int i = rsmd.getColumnCount(); for(int j=1;j<=i;j++) { if(!rsmd.getColumnName(j).equals("ID")) { String str = rs.getString(j)==null?"": rs.getString(j); if(str.equals("null"))str = ""; list2.add( str); } else list2.add(rs.getString(j)); } list.add(list2); } rs.close(); st.close(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } return list; } public void close() { } /** * 执行一条查询sql,以 List 的形式返回查询的记录,记录条数,和从第几条开始,由参数决定,主要用于翻页 * pageno 页码 rowsize 每页的条数 */ public List select(String sql, int pageno, int rowsize) { List list=new ArrayList(); List mlist=new ArrayList(); try{ list=this.select(sql); int min = (pageno-1)*rowsize; int max = pageno*rowsize; for(int i=0;i(max-1))) { mlist.add(list.get(i)); } } }catch(RuntimeException re){ re.printStackTrace(); throw re; } return mlist; } public static void main(String[] args) { } }

 

 

 

 

 

你可能感兴趣的:(java,开发语言,servlet)