package cn.jack.service;

import java.util.List;

import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import cn.jack.hibernate.Manager;

public class LoginsDaoImp extends HibernateDaoSupport implements LoginsDao {

	public boolean login(Manager mr) {
		String hql="from Manager m where m.username=? and userpass=?";
		String[] login = new String[2];
		login[0]=mr.getUsername().trim();
		login[1]=mr.getUserpass().trim();
		List logins = this.getHibernateTemplate().find(hql,login);
		if(logins.size()>0){
			return true;
		}
		return false;
	}

	public boolean exite(String username) {
		String hql="from Manager m where m.username=?";
		List ls = this.getHibernateTemplate().find(hql,(Object)username);
		if(ls.size()>0){
			return true;
		}
		return false;
	}

	public void adduser(Manager mr) {
		this.getHibernateTemplate().save(mr);
		
	}

	/*
	 * (non-Javadoc)
	 * @see cn.jack.service.LoginsDao#editpass(java.lang.String, java.lang.String)
	 */
	public void editpass(String userpass,String id){
		Manager ma = new Manager();
		Manager mat = (Manager)this.getHibernateTemplate().get(Manager.class,id);
		ma.setUsername(mat.getUsername());
		ma.setUserpass(userpass);
		ma.setId(mat.getId());
		this.getHibernateTemplate().update(ma);
		
	}

	/*
	 * (non-Javadoc)
	 * @see cn.jack.service.LoginsDao#userid(java.lang.String)
	 */
	public List userid(String username) {
		String hql="from Manager m where m.username=?";
		List list = this.getHibernateTemplate().find(hql,(Object)username);
		return list;
	}

}
