主要运用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:"<iframe frameborder='0' sarolling='auto' width='100%' height='100%'src='"+ tab_href +"'></iframe>" }); } }); })
这里主要是用inframe来获取href,避免多个标签页同时打开产生冲突。
2.然后就是生成工资条的弹窗,
这里是根据考勤表里的状态来获取月份的,(0表示未生成工资条)
注意下拉框是通过URL、valueFeild、textFeild 把value的值传递的,参考:省市区三级联动
3.点击生成按钮后,需要加载数据,需要一段时间,所以加了个进度条
<!-- 生成工资条弹窗 --> <div class="easyui-dialog" id="gz" style="400px; height:200px" title="生成工资条" data-options="{ closed:true, modal:true, buttons:[{ text:'生成', iconCls:'icon-ok', handler:function(){ $('#form1').form('submit',{ url:'PayDateServlet',//把定义的默认值是add的添加的方法传给Servlet然后判断 onSubmit:function(){ var isValid = $(this).form('validate'); if(!isValid) { $.messager.show({ title:'消息', msg:'数据验证未通过' }); } else { //进度对话框 $.messager.progress( { title:'进度条', msg:'工资加载中。。。', text:'请稍后。。。', interval:1000 } ); } return isValid; // }, success:function(data){ var msg = eval('('+ data +')');//eval是js的方法 if(!msg.success) { alert(msg.message); } else { $.messager.progress('close'); $.messager.show({ title:'消息', msg:'数据验证通过,保存成功' }); $('#gz').dialog('close'); } } }); } }, { text:'取消', iconCls:'icon-cancel', handler:function(){$('#gz').dialog('close')}, }] }" >
页面层
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Insert title here</title> <!-- 顺序不可以乱 --> <!-- 1.jQuery的js包 --> <script type="text/javascript" src="jquery-easyui-1.4.4/jquery.min.js"></script> <!-- 2.css资源 --> <link rel="stylesheet" type="text/css" href="jquery-easyui-1.4.4/themes/default/easyui.css"> <!-- 3. 图标资源 --> <link rel="stylesheet" type="text/css" href="jquery-easyui-1.4.4/themes/icon.css"> <!-- 4.easyui的js包 --> <script type="text/javascript" src="jquery-easyui-1.4.4/jquery.easyui.min.js"></script> <!-- 5.本地语言 --> <script type="text/javascript" src="jquery-easyui-1.4.4/locale/easyui-lang-zh_CN.js"></script> <style type="text/css"> .caidan { 120px; height:40px; position:relative; float: left; margin-left: 40px; margin-top: 5px; color:white; text-align: center; line-height: 40px; font-size: 1.2em; } .caidan:hover { background-color:#595959; border-radius: 3px; } </style> <script type="text/javascript"> function getDate(date) { //得到日期对象 var d = new Date(date); //得到年 月 日 var year = d.getFullYear(); var month = (d.getMonth()+1); var day = d.getDate(); //拼装 var rtn = year+"-"+(month<10 ? "0"+month : month) + "-"+(day<10 ? "0"+day : day); return rtn; } $(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:"<iframe frameborder='0' sarolling='auto' width='100%' height='100%'src='"+ tab_href +"'></iframe>" }); } }); }) </script> </head> <body class="easyui-layout"> <div data-options="region:'north',split:false" style="height:152px;"> <div style="100%;height:100px;margin-top:0px;"> <img alt="" src="images/head.jpg" width="1360px"> </div> <div style="background-color:#393755;100%;height:50px;margin-top:0px;"> <a href="#"><div class="caidan">人事管理模块</div></a> <a href="#"><div class="caidan">考勤管理模块</div></a> <a href="#"><div class="caidan">招聘管理模块</div></a> <a href="#"><div class="caidan">培训管理模块</div></a> <a href="#"><div class="caidan">薪酬管理模块</div></a> </div> </div> <div data-options="region:'south',split:false" style="height:50px;"></div> <!-- <div data-options="region:'east',iconCls:'icon-reload',title:'工具',split:true" style="100px;"></div> --> <!-- ********************菜单********************************8 --> <div data-options="region:'west',title:'菜单',split:false" style="200px;"> <div id="ac" class="easyui-accordion" data-options="fit:true"> <div title="查询工资"data-options="selected:false"> <a id="" href="#" class="easyui-linkbutton" title="SelectPay.html" style="100%"data-options="iconCls:'icon-search'">查询工资</a> <a id="dd" href="#" class="easyui-linkbutton" title="" style="100%"data-options="iconCls:'icon-search'">设置工资</a> </div> <div title="税率标准" > <a id="" href="#" class="easyui-linkbutton" title="SelectRate.html" style="100%"data-options="iconCls:'icon-search'">查询税率</a> <a id="" href="#"class="easyui-linkbutton" title="ShezhiRate.html"style="100%" data-options="iconCls:'icon-shezhi'">设置税率</a> </div> <div title="奖惩标准"> <a href="#" title="ShezhiDeal.html"class="easyui-linkbutton"style="100%" data-options="iconCls:'icon-shezhi'" >奖惩设置</a> <a href="#" title="SelectDeal.html"class="easyui-linkbutton"style="100%" data-options="iconCls:'icon-search'" >奖惩查询</a> </div> <div title="工资标准"> <a href="#" title="ShezhiRank.html"class="easyui-linkbutton"style="100%" data-options="iconCls:'icon-shezhi'" >工资标准设置</a> <a href="#" title="SelectRank.html"class="easyui-linkbutton"style="100%" data-options="iconCls:'icon-search'">查询工资标准</a> </div> </div> </div> <div data-options="region:'center',title:'主窗口'" style="padding:5px;background:#eee;"> <div id="img" class="easyui-panel"><img alt="" src="images/2.jpg" width="100%" heigth="440px"></div> <div id="tt" class="easyui-tabs" data-options="fit:true,justified:false"></div> </div> </div> <!-- 生成工资条弹窗 --> <div class="easyui-dialog" id="gz" style="400px; height:200px" title="生成工资条" data-options="{ closed:true, modal:true, buttons:[{ text:'生成', iconCls:'icon-ok', handler:function(){ $('#form1').form('submit',{ url:'PayDateServlet',//把定义的默认值是add的添加的方法传给Servlet然后判断 onSubmit:function(){ var isValid = $(this).form('validate'); if(!isValid) { $.messager.show({ title:'消息', msg:'数据验证未通过' }); } else { //进度对话框 $.messager.progress( { title:'进度条', msg:'工资加载中。。。', text:'请稍后。。。', interval:1000 } ); } return isValid; // }, success:function(data){ var msg = eval('('+ data +')');//eval是js的方法 if(!msg.success) { alert(msg.message); } else { $.messager.progress('close'); $.messager.show({ title:'消息', msg:'数据验证通过,保存成功' }); $('#gz').dialog('close'); } } }); } }, { text:'取消', iconCls:'icon-cancel', handler:function(){$('#gz').dialog('close')}, }] }" > <form action="" id="form1" method="post"><br><br> 生成工资条:<input id="date" class="easyui-combobox" style="100px" name="date" data-options=" url:'PayServlet', valueField:'payID', textField:'payMonth', onSelect:function(r){$('#date').combobox('setValue',r.payMonth.toString());}"> </form> </div> </body> </html>
获取下拉框月份的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<Object> lss = sp.getMonth(); //System.out.println(lss); List<Month> ls = new ArrayList<Month>(); for(int i=0;i<lss.size();i++) { Month m = new Month(); m.setPayID(i); m.setPayMonth(lss.get(i).toString()); ls.add(m); } String json = JSONArray.toJSONString(ls); response.getWriter().println(json); }
提交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> rate = getRate(); init(); System.out.println("uwef="+date); List<KqMonthkaoqin> 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<rate.size();i++) { double qzd = rate.get(i).getStartpay(); double money = rate.get(i).getMoney(); double tax = rate.get(i).getTax(); double kouchu = rate.get(i).getKouchu(); if(yingfa-qzd<money) { nashui=((yingfa-qzd)*tax-kouchu); System.out.println("起征点="+qzd); System.out.println("应纳税所得额="+money); System.out.println("税率="+tax); System.out.println("扣除数="+kouchu); break; } } sp.setNashui(nashui); } //实发工资 sp.setShifa((jb+z-(jb*0.1+jb*0.08))-nashui); sp.setZhuangtai('0'); sp.setHedui('0'); getSave(sp); getzhuangtai(k.getId());//调用更改考勤表状态的方法 } destroy(); } //提交保存SPay public void getSave(SPay spay) { init(); se.save(spay); destroy(); } //改变考勤表的状态 public void getzhuangtai(String id) { init(); KqMonthkaoqin kaoqin = (KqMonthkaoqin)se.get(KqMonthkaoqin.class, id); kaoqin.setZhuangtai(1); destroy(); } //查询Rate税率表 public List<Rate> getRate() { init(); List<Rate> rtn = new ArrayList<Rate>(); rtn=se.createQuery("from Rate order by money asc").list(); destroy(); return rtn; } //查询考勤表里状态是0 的月份 public List<Object> getMonth() { init(); List<Object> li = new ArrayList<Object>(); li = se.createQuery("select distinct to_char(kaoqinmonth,'yyyy-MM') from KqMonthkaoqin where zhuangtai='0' ").list(); destroy(); return li; } //根据考勤表的员工id查询员工表的姓名 public String getName(String yuangongid) { init(); String rtn = ""; List<Object> li = new ArrayList<Object>(); li = se.createQuery("select name from Basic where yuangongid = ? ") .setString(0, yuangongid) .list() ; if(li.size()>0) { rtn = li.get(0).toString(); } destroy(); destroy(); return rtn; } //根据员工编号查询员工等级 public String getLevels(String yuangongid) { init(); String rtn = ""; List<Object> li = new ArrayList<Object>(); li = se.createQuery("select jibie from Basic where yuangongid = ? and zhuangtai = '在职'") .setString(0, yuangongid) .list() ; if(li.size()>0) { rtn = li.get(0).toString(); } destroy(); return rtn; } //根据等级查询员工基本工资 public int getSalary(int levels) { init(); int rtn =0; List<Object> li = new ArrayList<Object>(); li = se.createQuery("select salary from Rank where levels = ?") .setLong(0, levels).list(); if(li.size()>0) { rtn = Integer.parseInt(li.get(0).toString()); } destroy(); return rtn; } //查询全勤奖励 public int getquanqin() { int rtn =0; init(); List<Object> li = new ArrayList<Object>(); li = se.createQuery("select quanqin from Deal where state='1'") .list(); System.out.println("list.size = " + li.size()); if(li.size()>0) { rtn = (Integer.parseInt(li.get(0).toString())); } destroy(); return rtn; } //获取Deal表的正常加班单价 public int getZhengchangJiaban() { int rtn =0; init(); List<Object> li = new ArrayList<Object>(); //查询启用状态下正常加班的金额 li = se.createQuery("select zhengban from Deal where state='1'") .list(); if(li.size()>0) { rtn = (Integer.parseInt(li.get(0).toString())); } destroy(); return rtn; } //获取周末加班单价 public int getzhoumo() { int rtn =0; init(); List<Object> li = new ArrayList<Object>(); //查询启用状态下周末加班的金额 li = se.createQuery("select zhouban from Deal where state='1'") .list(); if(li.size()>0) { rtn = (Integer.parseInt(li.get(0).toString())); } destroy(); return rtn; } //获取节假日加班 public int getJiaqi() { int rtn =0; init(); List<Object> li = new ArrayList<Object>(); //查询启用状态下节假日加班的金额 li = se.createQuery("select jieban from Deal where state='1'") .list(); if(li.size()>0) { rtn = (Integer.parseInt(li.get(0).toString())); } destroy(); return rtn; } //获取迟到金额 public int getChidao () { int rtn =0; init(); List<Object> li = new ArrayList<Object>(); //查询启用状态下迟到一次的金额 li = se.createQuery("select chidao from Deal where state='1'") .list(); if(li.size()>0) { rtn = (Integer.parseInt(li.get(0).toString())); } destroy(); return rtn; } //获取早退 public int getZaotui() { int rtn =0; init(); List<Object> li = new ArrayList<Object>(); //查询启用状态下迟到一次的金额 li = se.createQuery("select zaotui from Deal where state='1'") .list(); if(li.size()>0) { rtn = (Integer.parseInt(li.get(0).toString())); } destroy(); return rtn; } //获取旷工 public int getKuanggong() { int rtn =0; init(); List<Object> li = new ArrayList<Object>(); //查询启用状态下旷工一次的金额 li = se.createQuery("select kuanggong from Deal where state='1'") .list(); if(li.size()>0) { rtn = (Integer.parseInt(li.get(0).toString())); } destroy(); return rtn; } //获取分页数据集合列表 public List<SPay> getPageList(int page , int rows,String sort,Map<String,String> where) { init(); //创建基础HQL语句 String sql = "from SPay where 1=1"; //判断传递的的参数 String yuangongid = where.get("yuangongid_s"); if(yuangongid != null && !yuangongid.equals("")) { sql += " and yuangongid "; } //排序 if(sort != null && !sort.equals("")) { sql += " order by " + sort; } //得到HQL //并判断查询条件 Query q = se.createQuery(sql); if(yuangongid != null && !yuangongid.equals("") ) { q.setString("yuangongid", yuangongid);//引号的内容必须跟上面引号后的别名一致 } System.out.println("yuangongid="+yuangongid); List<SPay> rtn = new ArrayList<SPay>(); rtn = q.setMaxResults(rows)//每页行数 .setFirstResult((page-1)*rows).list();//其实页码 destroy(); return rtn; } //获取数据条数 public int getTotal(Map<String,String> where) { int rtn= 0; init(); //创建基础HQL语句 String sql = "select count(1) from SPay where 1=1"; //判断传递的的参数 String yuangongid_s = where.get("yuangongid_s"); if(yuangongid_s != null && !yuangongid_s.equals("")) { sql += " and yuangongid )";//and前面加空格 } //得到HQL //并判断查询条件 Query q = se.createQuery(sql); if(yuangongid_s != null && !yuangongid_s.equals("") ) { q.setString("yuangongid", yuangongid_s); //引号的内容必须跟上面引号后的别名一致 } //获取Query对对象,定义集合并实例化 List<Object> lo = q.list(); if(lo != null && lo.size() > 0) { rtn = Integer.parseInt(lo.get(0).toString());//转换成int并赋值 } destroy(); return rtn; } }
DAO层主要是围绕着联合查询这个方法来的,通过给中小方法,获取其他表的数据,生成工资表SPay中的各个字段,然后添加,也就是一个添加的过程。
这个项目所遇到的一些问题:代码优化,逻辑还不够严谨。