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

📄 userinfodaoimpl.java

📁 酒店管理系统 用sh编写的酒店管理系统 毕业设计用的
💻 JAVA
字号:
package com.chen.interFace.InterFaceDAO;

import java.sql.Date;
import java.util.List;

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

import com.chen.hibernate.hsf.HibernateSessionFactory;
import com.chen.interFace.UserinfoDAO;
import com.chen.modle.discountinfoDAO.Discountinfo;
import com.chen.modle.roomreserveinfoDAO.Roomreserveinfo;
import com.chen.modle.userDAO.Userinfo;
import com.chen.modle.userDAO.Userinfo;

public class UserinfoDAOImpl implements UserinfoDAO {
	
	Transaction ts = null;

	public List checkUserinfo(String username) {
		try{
			Session session = HibernateSessionFactory.getSession();
			String str = "from Userinfo a where a.username='"+username+"'";
			Query query = session.createQuery(str);
			return query.list();
		}catch (HibernateException e) {
     	   e.printStackTrace();
		} finally {
		HibernateSessionFactory.closeSession();
		}
		return null;
	}

	public Integer getUserGrade(String username) {
		try{
			Session session = HibernateSessionFactory.getSession();
			String str = "from Userinfo u where u.username='"+username+"'";
			Query query = session.createQuery(str);
			List a = query.list();
			Userinfo user = (Userinfo)a.get(0);
			return user.getGrade();
		}catch (HibernateException e) {
	        	   e.printStackTrace();
	} finally {
		HibernateSessionFactory.closeSession();
		}
	return 0;
	}

	public boolean reserveRoom(int roomId) {
		// TODO Auto-generated method stub
		return false;
	}

	public List seleteRooms() {
		try{
			Session session = HibernateSessionFactory.getSession();
			String str  = "from Allroominfo a where a.roomreservestate='无' and a.roomnowstate='无' and a.roomtype='净房'";
			Query query = session.createQuery(str);
			return query.list();
		}catch (HibernateException e) {
     	   e.printStackTrace();
		} finally {
		HibernateSessionFactory.closeSession();
		}
		return null;
	}

	public boolean userLogin(String username, String password) {
		try{
			Session session = HibernateSessionFactory.getSession();
			String str = "from Userinfo a where a.username='"+username+"' and a.userpassword='"+password+"'";
			Query query = null;
			if(session.createQuery(str)==null) System.out.println("dfd");
			query = session.createQuery(str);
			if(query.list()!=null&&query.list().size()>0)
			{return true;}
		}catch (HibernateException e) {
     	   e.printStackTrace();
		} finally {
		HibernateSessionFactory.closeSession();
		}
		return false;
	}

	public boolean userRegist(Userinfo userinfo) {
		try{
			Session session = HibernateSessionFactory.getSession();
			ts = session.beginTransaction();
			session.save(userinfo);
			ts.commit();
			return true;
		}catch (Exception e) {
			if (ts != null) {
	        	   ts.rollback();
			}
	} finally {
		HibernateSessionFactory.closeSession();
		}
		return false;
	}

	public boolean userUpdate() {
		// TODO Auto-generated method stub
		return false;
	}

	public boolean validateusername(String username) {
		try{
			Session session = HibernateSessionFactory.getSession();
			String str = "from Userinfo w where w.username='"+username+"'";
			Query query = session.createQuery(str);
			if(query.list()!=null&&query.list().size()>0)
			{return true;}
		}catch (HibernateException e) {
     	   e.printStackTrace();
		} finally {
		HibernateSessionFactory.closeSession();
		}
		return false;
	}

	public List selectreservedRooms(Date begindate, Date enddate) {
		try{
			Session session = HibernateSessionFactory.getSession();
			String str  = "from Allroominfo a ,Roomreserveinfo r where a.roomreservestate='有' and a.roomnowstate='无' and r.roomnumber=a.roomnumber" +
					" and r.reservetimebegin >= '"+begindate+"' ";
			Query query = session.createQuery(str);
			return query.list();
		}catch (HibernateException e) {
     	   e.printStackTrace();
		} finally {
		HibernateSessionFactory.closeSession();
		}
		return null;
	}

	public List selectreserved_stayedRooms(Date begindate, Date enddate) {
		// TODO Auto-generated method stub
		return null;
	}

	public List selectstayedRooms(Date begindate, Date enddate) {
		// TODO Auto-generated method stub
		return null;
	}

	public Integer getRoomreserveid(int roomnumber) {
		try{
			Session session = HibernateSessionFactory.getSession();
			String str= "from Roomreserveinfo r where r.roomnumber='"+roomnumber+"'";
			Query query = session.createQuery(str);
			List a = query.list();
			Roomreserveinfo roomreserveinfo = (Roomreserveinfo)a.get(0);
			return roomreserveinfo.getRoomid();
		}catch (HibernateException e) {
     	   e.printStackTrace();
		} finally {
		HibernateSessionFactory.closeSession();
		}
		return null;
	}

	public Integer getRoomstayedid(int roomnumber) {
		// TODO Auto-generated method stub
		return null;
	}

	public List showAllroom() {
		try{
			Session session = HibernateSessionFactory.getSession();
			String str = "from Allroominfo a";
			Query query = session.createQuery(str);
			return query.list();
		}catch (HibernateException e) {
     	   e.printStackTrace();
		}
		return null;
	}

	public List getSelectroom(int number) {
		
		try{
			Session session = HibernateSessionFactory.getSession();
			String str = "from Allroominfo a where a.roomnumber='"+number+"'";
			Query query = session.createQuery(str);
			return query.list();
		}catch (HibernateException e) {
     	   e.printStackTrace();
		}
		
		return null;
	}

	public List showMymenu(String name) {
		try{
			Session session = HibernateSessionFactory.getSession();
			String str = "from Roomreserveinfo r where r.reservername='"+name+"'";
			Query query = session.createQuery(str);
			return query.list();
		}catch (HibernateException e) {
     	   e.printStackTrace();
		}
		return null;
	}

	public int getUserpoint(String name) {
		try{
			Session session = HibernateSessionFactory.getSession();
			String str = "from Userinfo u where u.username='"+name+"'";
			Query query = session.createQuery(str);
			Userinfo userinfo = (Userinfo) query.list().get(0);
			return userinfo.getUserpoint();
		}catch (HibernateException e) {
     	   e.printStackTrace();
		}
		return 0;
	}

	public float getUserdiscount(int point) {
		try{
			Session session = HibernateSessionFactory.getSession();
			String str = "from Discountinfo d where d.maxpoint>='"+point+"' and d.minpoint<='"+point+"'";
			Query query = session.createQuery(str);
			Discountinfo discountinfo = (Discountinfo) query.list().get(0);
			return discountinfo.getDiscount();
		}catch (HibernateException e) {
     	   e.printStackTrace();
		}
		return 0;
	}

}

⌨️ 快捷键说明

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