⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 constructdao.java

📁 只是一个宽带的收费管理系统 很值得大家学习
💻 JAVA
字号:
package cn.handson.dao;

import java.util.Date;
import java.util.Iterator;
import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;

import cn.handson.base.*;
import cn.handson.utils.*;

public class ConstructDao {
	
	/*
	 * 此方法用来得到所有的施工表对象。。。
	 * 
	 * 
	 */
	
	public List getAllConstruct() {
		// TODO Auto-generated method stub
		Session session=HibernateUtil.currentSession();
		Transaction tx=session.beginTransaction();//定义一个事务 
		String sql="select b from Construct as b";
		Query query=session.createQuery(sql);
		List list=query.list();
		tx.commit();//提交事务
		//HibernateUtil.closeSession();
		return list;
		
	}
	
	/*
	 * 此方法用来得到所有constover=1的施工对象。。。。
	 * 
	 */
	
	public List getAll() {
		// TODO Auto-generated method stub
		Session session=HibernateUtil.currentSession();
		Transaction tx=session.beginTransaction();//定义一个事务 
		String sql="select b from Construct as b where b.constOver=1";
		Query query=session.createQuery(sql);
		List list=query.list();
		tx.commit();//提交事务 
		//HibernateUtil.closeSession();
		return list;
		
	}
	
	
	/*
	 * 此方法用来得到所有Emplyee=null的施工对象。。。。
	 * 
	 */
	
	public List getAllByemplyee() {
		// TODO Auto-generated method stub
		Session session=HibernateUtil.currentSession();
		Transaction tx=session.beginTransaction();//定义一个事务 
		String sql="select b from Construct as b where b.employee is null";
		Query query=session.createQuery(sql);
		List list=query.list();
		tx.commit();//提交事务 
		//HibernateUtil.closeSession();
		return list;
		
	}
	
	
	/*
	 * 此方法用来得到登陆用户的所有任务。。包括故障,停机,施工。。。
	 * 
	 */
	
	public List getAllByEmployee(Employee user) {
		// TODO Auto-generated method stub
		Session session=HibernateUtil.currentSession();
		Transaction tx=session.beginTransaction();//定义一个事务 
		String sql="select b from Construct as b where b.constOver=1 and b.employee.employeeId="+user.getEmployeeId();
		Query query=session.createQuery(sql);
		List list=query.list();
		tx.commit();//提交事务 
		//HibernateUtil.closeSession();
		return list;
		
	}
	
	/*
	 * 此方法通过Userid来得到一个故障表的对象。。。
	 * 
	 */
	
	
	public List getAllbyuserid() {
		// TODO Auto-generated method stub
		Session session=HibernateUtil.currentSession();
		Transaction tx=session.beginTransaction();//定义一个事务 
		String sql="select b from Construct as b where b.user1.userId=1";
		Query query=session.createQuery(sql);
		List list=query.list();
		tx.commit();//提交事务 
		//HibernateUtil.closeSession();
		return list;
		
	}
	
	/*
	 * 此方法用来删除施工表对象.....
	 * 
	 */
	public boolean deleteConstruct(Construct ct){
		Session session=HibernateUtil.currentSession();
		Transaction tx=session.beginTransaction();//定义一个事务 
		session.delete(ct);
		tx.commit();//提交事务
		//HibernateUtil.closeSession();
		return true;
	}
	
	/*
	 * 此方法用来通过施工表ID来得到一个施工表的对象。。。
	 * 
	 * 
	 */
	
	public Construct getConstructById(Integer id) {
		// TODO Auto-generated method stub
		Session session=HibernateUtil.currentSession();
        Transaction tx=session.beginTransaction();//定义一个事务 
        Construct ct=(Construct)session.get(Construct.class, id);
		tx.commit();//提交事务
		//HibernateUtil.closeSession();
		return ct;
	}
    
	/*
	 * 此方法用来更新数据库中的施工表。。。
	 * 
	 */
	
	public void updateConstruct(Construct ct,Date wu) {
		// TODO Auto-generated method stub
		User1 hai=new User1();
		hai=ct.getUser1();
		hai.setUserType(new Integer(0));
		Session session=HibernateUtil.currentSession();
        Transaction tx=session.beginTransaction();//定义一个事务 
        Construct us=(Construct)session.get(Construct.class, ct.getConstId());
		us.setUser1(hai);
		us.setEmployee(ct.getEmployee());
		us.setType1(ct.getType1());
		us.setConstCause(ct.getConstCause());
		us.setConstDate(ct.getConstDate());
		us.setConstOverDate(wu);
		us.setConstFeedback(ct.getConstFeedback());
		us.setConstOver(new Integer(0));
		us.setConstRemark(ct.getConstRemark());
		session.save(us);
		tx.commit();//提交事务
		//HibernateUtil.closeSession();
	}
	
	
	/*
	 * 此方法用来更新数据库中的施工表。。。
	 * 
	 */
	
	public void update(Construct ct) {
		// TODO Auto-generated method stub
		Session session=HibernateUtil.currentSession();
        Transaction tx=session.beginTransaction();//定义一个事务 
        Construct us=(Construct)session.get(Construct.class, ct.getConstId());
		us.setUser1(ct.getUser1());
		us.setEmployee(ct.getEmployee());
		us.setType1(ct.getType1());
		us.setConstCause(ct.getConstCause());
		us.setConstDate(ct.getConstDate());
		us.setConstOverDate(ct.getConstOverDate());
		us.setConstFeedback(ct.getConstFeedback());
		us.setConstOver(ct.getConstOver());
		us.setConstRemark(ct.getConstRemark());
		session.save(us);
		tx.commit();//提交事务
		//HibernateUtil.closeSession();
	}
	
	
	/*
	 * 此方法用来添加施工表。。。。
	 * 
	 * 
	 */
	
	public void addConstruct(Construct ct) {
		// TODO Auto-generated method stub
		Session session=HibernateUtil.currentSession();
        Transaction tx=session.beginTransaction();//定义一个事务 
		session.save(ct);
		tx.commit();//提交事务
	//	HibernateUtil.closeSession();
		
	}
	
	

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
		List list=new ConstructDao().getAllByemplyee();
		Iterator iter=list.iterator();
		while(iter.hasNext()){
			Construct aa=(Construct)iter.next();
			System.out.println(aa.getConstId());
			
		}
		/*
		Construct us=new Construct();
		us.setUser1(ct.getUser1());
		us.setType1(ct.getType1());
		us.setConstCause(ct.getConstCause());
		us.setConstDate(ct.getConstDate());
		us.setConstOver(ct.getConstOver());
		*/
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -