?? stipenddao.java
字號:
package com.bOS.bPRO_PersonManage.service;
import java.util.List;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;
import com.bOS.bPRO_PersonManage.en.Stipend;
import com.bOS.bUtil.db.HibSessionFactory;
/**
* @author BWeiMing
*
*/
public class StipendDao {
/**
* 計算工資總數
**/
private Stipend getCountTotalize(Stipend e){
float count=0;
count=count+e.getBasic().longValue();
count=count+e.getDuty().longValue();
count=count+e.getEat().longValue();
count=count+e.getHouse().longValue();
count=count+e.getOther().longValue();
count=count-e.getPunishment().longValue();
count=count-e.getScot().longValue();
e.setTotalize(new Float(count));
return e;
}
public void addStipend(Stipend e) throws HibernateException{
e=getCountTotalize(e);
Session session = HibSessionFactory.currentSession();
Transaction tx = session.beginTransaction();
session.save(e);
tx.commit();
HibSessionFactory.closeSession();
}
public void deleteStipend(Stipend e) throws HibernateException{
Session session = HibSessionFactory.currentSession();
Transaction tx = session.beginTransaction();
session.delete(e);
tx.commit();
HibSessionFactory.closeSession();
}
public Stipend loadStipend(long id) throws HibernateException{
Session session = HibSessionFactory.currentSession();
Transaction tx = session.beginTransaction();
Stipend e=(Stipend)session.load(Stipend.class,new Long(id));
tx.commit();
HibSessionFactory.closeSession();
return e;
}
public List listStipend() throws HibernateException{
Session session = HibSessionFactory.currentSession();
Transaction tx = session.beginTransaction();
Query query = session.createQuery("select e from Stipend as e order by e.granttime");
List list = query.list();
tx.commit();
HibSessionFactory.closeSession();
return list;
}
public void updateStipend(Stipend stipend) throws HibernateException{
Stipend e =this.loadStipend(stipend.getId().longValue());
if (stipend.getBasic()!=null){
e.setBasic(stipend.getBasic());
}
if(stipend.getDuty()!=null){
e.setDuty(stipend.getDuty());
}
if (stipend.getEat()!= null) {
e.setEat(stipend.getEat());
}
if (stipend.getHouse()!= null) {
e.setHouse(stipend.getHouse());
}
if(stipend.getGranttime()!=null){
e.setGranttime(stipend.getGranttime());
}
if(stipend.getName()!=null){
e.setName(stipend.getName());
}
if(stipend.getOther()!=null){
e.setOther(stipend.getOther());
}
if(stipend.getPunishment()!=null){
e.setPunishment(stipend.getPunishment());
}
if(stipend.getScot()!=null){
e.setScot(stipend.getScot());
}
e=getCountTotalize(e);
Session session = HibSessionFactory.currentSession();
Transaction tx = session.beginTransaction();
session.update(e);
tx.commit();
HibSessionFactory.closeSession();
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -