主要运用easyUI 、 Hibernate 、Servlet 。
1.动态生成标签页,
$(function(){
//创建打开新标签页
$(".easyui-linkbutton").click(function(){
$("#img").panel('close');
//获取组件的属性或内容
var tab_title = $(this).text();//关键在this选择当前事件
var tab_href = $(this).attr("title");
var dd = $(this).attr("id");
//alert(tab_href);
if($("#tt").tabs("exists",tab_title))
{
$("#tt").tabs("select",tab_title)
}
else if(dd=="dd")
{
$("#gz").dialog('open');
}
else
{
$("#tt").tabs('add',{
title:tab_title,
closable:true,
//href:tab_href
content:""
});
}
});
})
这里主要是用inframe来获取href,避免多个标签页同时打开产生冲突。
2.然后就是生成工资条的弹窗,
这里是根据考勤表里的状态来获取月份的,(0表示未生成工资条)
注意下拉框是通过URL、valueFeild、textFeild 把value的值传递的,参考:省市区三级联动
3.点击生成按钮后,需要加载数据,需要一段时间,所以加了个进度条
页面层
获取下拉框月份的Servlet层
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//转码
request.setCharacterEncoding("UTF-8");
response.setCharacterEncoding("UTF-8");
response.setContentType("text/html");
//调用底层查询表月份的集合
SPayDAO sp = new SPayDAO();
List
提交from表单的select层
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//转码
request.setCharacterEncoding("UTF-8");
response.setCharacterEncoding("UTF-8");
response.setContentType("text/html");
//接受月份
String date = request.getParameter("date");
System.out.println("date="+date);
String msg = "{'success':true,'message':'保存成功'}";
if(date != null)
{
try
{
SPayDAO sp = new SPayDAO();
sp.unite(date);
}
catch(Exception e)
{
msg = "{'success':false,'message':'访问失败'}";
}
response.getWriter().print(msg);
}
else
{
msg = "{'success':false,'message':'没有要生成的工资'}";
response.getWriter().print(msg);
}
}
DAO层
package com.hanqi.dao;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.Configuration;
import org.hibernate.service.ServiceRegistry;
import com.hanqi.entity.Basic;
import com.hanqi.entity.Deal;
import com.hanqi.entity.KqMonthkaoqin;
import com.hanqi.entity.Rank;
import com.hanqi.entity.Rate;
import com.hanqi.entity.SPay;
public class SPayDAO {
Configuration cfg = null;
ServiceRegistry sr = null;
SessionFactory sf = null;
Session se =null;
Transaction tr = null;
public SPayDAO()//注册服务
{
//1.加载配置文件
cfg = new Configuration().configure();
//2.注册服务
sr = new StandardServiceRegistryBuilder()
.applySettings(cfg.getProperties()).build();
}
//初始化
private void init()
{
try
{
sf= cfg.buildSessionFactory(sr);
}
catch(Exception e)
{
//1.加载配置文件
cfg = new Configuration().configure();
//2.注册服务
sr = new StandardServiceRegistryBuilder()
.applySettings(cfg.getProperties()).build();
sf= cfg.buildSessionFactory(sr);
}
se = sf.openSession();
tr = se.beginTransaction();//启动事物
}
//提交和释放
private void destroy()
{
try
{
tr.commit();//提交事务
}
catch(Exception e)
{
//1.加载配置文件
cfg = new Configuration().configure();
//2.注册服务
sr = new StandardServiceRegistryBuilder()
.applySettings(cfg.getProperties()).build();
sf= cfg.buildSessionFactory(sr);
se = sf.openSession();
tr = se.beginTransaction();
tr.commit();//提交事务
}
se.close();
sf.close();
}
//联合查询
public void unite(String date)
{
double zhengchang = getZhengchangJiaban();
double zhoumo = getzhoumo();
double jiaqi = getJiaqi();
double chidao = getChidao ();
double zaotui = getZaotui();
double kuanggong = getKuanggong();
List rate = getRate();
init();
System.out.println("uwef="+date);
List lb = se.createQuery("from KqMonthkaoqin where zhuangtai= 0 and to_char(kaoqinmonth,'yyyy-MM')=?")
.setString(0, date).list() ;
System.out.println(lb);
SPay sp = new SPay();
for(KqMonthkaoqin k : lb)
{
sp.setPayid(date+k.getStaffid());//获取并写入工资表的薪资编号
sp.setYuangongid(k.getStaffid());//获取员工id
sp.setEmployeename(getName(k.getStaffid()));;//员工姓名
//基本工资
double jb = getSalary(Integer.parseInt(getLevels(k.getStaffid())));
sp.setJibengongzi( jb);
//加班总金额
double zc = zhengchang*k.getJiaban();
double zm = zhoumo*k.getZhoumojiaban();
double jq = jiaqi*(k.getJiejiarijiaban());
double z = zc+zm+jq ;
sp.setJiaban(z);
//请假
sp.setQingjia(k.getQingjia());
//迟到
sp.setChidao(chidao*(k.getChidao()));
//早退
sp.setZaotui(zaotui*(k.getZaotui()));
//旷工
sp.setKuanggong(kuanggong*k.getKuanggong());
//五险
sp.setWuxian(jb*0.1);
//公积金
sp.setGongjijin(jb*0.08);
//全勤
if(k.getChidao()!=0 || k.getZaotui() != 0 || k.getQingjia() != 0 ||k.getKuanggong() !=0)
{
sp.setQuanqin(getquanqin());
}
else
{
sp.setQuanqin(0);
}
//应发工资
double yingfa = jb+z-(jb*0.1+jb*0.08);
sp.setYingfa(yingfa);
//纳税
double nashui = 0;
//判断是否纳税
if(yingfa-rate.get(0).getStartpay()<=0)
{
}
else
{
for(int i=0; i getRate()
{
init();
List rtn = new ArrayList();
rtn=se.createQuery("from Rate order by money asc").list();
destroy();
return rtn;
}
//查询考勤表里状态是0 的月份
public List
DAO层主要是围绕着联合查询这个方法来的,通过给中小方法,获取其他表的数据,生成工资表SPay中的各个字段,然后添加,也就是一个添加的过程。
这个项目所遇到的一些问题:代码优化,逻辑还不够严谨。