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

📄 studentdao.java

📁 这是一个学校老师和学生的管理系统,程序比较简单,但是几乎所有功能都可以实现,如果想要用,只要再添加一些东西就可以了.
💻 JAVA
字号:
/**
 *******************************************************************************
 * StudentDao.java
 *
 * (c) Copyright 2008 Hewlett-Packard Development Company, L.P.
 *
 *<Program Content>
 *  System Name : Students Management System
 *<Summarize>
 *  The file includes a class and the class main function is to operate data in database.
 *<Update Record>
 *  2009-5-6    1.00    zhangliy
 *******************************************************************************
 */
package com.hp.eds.zhangliyuan.stuMan.dao;

import java.util.ArrayList;
import java.util.List;

import org.hibernate.Session;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.hp.eds.zhangliyuan.stuMan.dao.interf.StudentDaoInt;
import com.hp.eds.zhangliyuan.stuMan.dto.CourseDto;
import com.hp.eds.zhangliyuan.stuMan.dto.ScoreDto;
import com.hp.eds.zhangliyuan.stuMan.entity.Enrol;
import com.hp.eds.zhangliyuan.stuMan.entity.UserInfo;

/**
 * The class main function is to operate data in database
 * 
 * @author zhangliy
 * @version 1.0
 */
public class StudentDao extends HibernateDaoSupport implements StudentDaoInt {
	private HibernateTemplate hiTem = this.getHibernateTemplate();

	/**
	 * get student information from the table tb_student_zhangliyuan
	 * 
	 * @param userID
	 *            -user's id
	 * @return UserInfo if the student exists,return the information fo the
	 *         student,else return null
	 */

	@SuppressWarnings("unchecked")
	public UserInfo getUserInfo(String userID) {
		UserInfo user = (UserInfo) hiTem.get(UserInfo.class, userID);
		if (user != null) {
			return user;
		}
		return null;
	}

	/**
	 * query how many courses current student can select from the
	 * tb_course_zhangliyuan
	 * 
	 * @param userID
	 *            -the user's ID
	 * @return List the courses information that the student can select
	 */
	@SuppressWarnings("unchecked")
	public List<CourseDto> getCourseList(String userID) {
		List<CourseDto> list = new ArrayList<CourseDto>();
		List result = null;
		Session session = hiTem.getSessionFactory().getCurrentSession();
		StringBuilder hqlBu = new StringBuilder();
		hqlBu.append(" SELECT ");
		hqlBu.append("     cour.id, ");
		hqlBu.append("     cour.name, ");
		hqlBu.append("     cour.prepare, ");
		hqlBu.append("     cour.department, ");
		hqlBu.append("     classes.id, ");
		hqlBu.append("     classes.roomID, ");
		hqlBu.append("     classes.time, ");
		hqlBu.append("     tea.name ");
		hqlBu.append(" FROM ");
		hqlBu.append("     Course cour, ");
		hqlBu.append("     Teacher tea, ");
		hqlBu.append("     Classes classes ");
		hqlBu.append(" WHERE ");
		hqlBu.append("     classes.teaID ");
		hqlBu.append("     = ");
		hqlBu.append("     tea.id ");
		hqlBu.append(" AND ");
		hqlBu.append("     classes.courID ");
		hqlBu.append("     = ");
		hqlBu.append("     cour.id ");
		hqlBu.append(" AND ");
		hqlBu.append("     classes.id ");
		hqlBu.append(" NOT IN ");
		hqlBu.append("       ( ");
		hqlBu.append("         SELECT ");
		hqlBu.append("             classID ");
		hqlBu.append("         FROM ");
		hqlBu.append("             Enrol ");
		hqlBu.append("         WHERE ");
		hqlBu.append("             stuId = '" + userID + "' ");
		hqlBu.append("       ) ");
		session.beginTransaction();
		result = session.createQuery(hqlBu.toString()).list();
		if (result.size() == 0) {
			return null;
		}
		for (int i = 0; i < result.size(); i++) {
			CourseDto courseDto = new CourseDto();
			courseDto.getCourse().setId((String) ((Object[]) result.get(i))[0]);
			courseDto.getCourse().setName(
					(String) ((Object[]) result.get(i))[1]);
			courseDto.getCourse().setPrepare(
					(String) ((Object[]) result.get(i))[2]);
			courseDto.getCourse().setDepartment(
					(String) ((Object[]) result.get(i))[3]);
			courseDto.getClassInfo().setId(
					(String) ((Object[]) result.get(i))[4]);
			courseDto.getClassInfo().setRoomID(
					(String) ((Object[]) result.get(i))[5]);
			courseDto.getClassInfo().setTime(
					(String) ((Object[]) result.get(i))[6]);
			courseDto.getTeacher().setName(
					(String) ((Object[]) result.get(i))[7]);
			list.add(courseDto);
		}
		if (list.size() != 0) {
			return list;
		}
		return null;
	}

	/**
	 * update the table tb_enrol_zhangliyuan
	 * 
	 * @param userID
	 *            -user's ID
	 * @param classID
	 *            -class's ID
	 * @return boolean insert successfully,return true;else return false
	 */
	public boolean txInsertCourse(String userID, String classID) {
		Enrol en = new Enrol();
		en.setStuID(userID);
		en.setClassID(classID);
		en.setAccept("yes");
		en.setScore("0");
		hiTem.saveOrUpdate(en);
		return true;
	}

	/**
	 * query the score that current student have got from the table
	 * tb_enrol_zhangliyuan
	 * 
	 * @param userID
	 *            -the user's ID
	 * @return List the course score information
	 */
	@SuppressWarnings("unchecked")
	public List<ScoreDto> getScoreList(String userID) {
		List<ScoreDto> list = new ArrayList<ScoreDto>();
		List result = null;
		Session session = hiTem.getSessionFactory().getCurrentSession();
		StringBuilder hqlBu = new StringBuilder();
		hqlBu.append(" SELECT ");
		hqlBu.append("    cour.name, ");
		hqlBu.append("    cour.mark, ");
		hqlBu.append("    en.score, ");
		hqlBu.append(" FROM ");
		hqlBu.append("     Course cour, ");
		hqlBu.append("     Enrol en, ");
		hqlBu.append("     Classes class ");
		hqlBu.append(" WHERE ");
		hqlBu.append("     en.stuID = '" + userID + "' ");
		hqlBu.append(" AND ");
		hqlBu.append("     en.classID ");
		hqlBu.append("     = ");
		hqlBu.append("     class.id ");
		hqlBu.append(" AND ");
		hqlBu.append("     class.courID ");
		hqlBu.append("     = ");
		hqlBu.append("     cour.id ");
		session.beginTransaction();
		result = session.createQuery(hqlBu.toString()).list();
		if (result.size() == 0) {
			return null;
		}
		for (int i = 0; i < result.size(); i++) {
			ScoreDto scoreDto = new ScoreDto();
			scoreDto.getCourse()
					.setName((String) ((Object[]) result.get(i))[0]);
			scoreDto.getCourse()
					.setMark((String) ((Object[]) result.get(i))[1]);
			scoreDto.getEnrol()
					.setScore((String) ((Object[]) result.get(i))[2]);
			list.add(scoreDto);
		}
		if (list.size() != 0) {
			return list;
		}
		return null;
	}

	/**
	 * update the user's password in table tb_student_zhangliyuan
	 * 
	 * @param userID
	 *            -the user's id
	 * @param password
	 *            -the update password
	 */
	public void txUpdatePas(String userID, String password) {
		StringBuilder hql = new StringBuilder();
		hql.append(" UPDATE ");
		hql.append("     UserInfo ");
		hql.append(" SET ");
		hql.append("     password = '" + password + "' ");
		hql.append(" WHERE ");
		hql.append("     id= ?");
		hiTem.update(hql.toString(), userID);
	}

	/**
	 * update the user's telephone in table tb_student_zhangliyuan
	 * 
	 * @param userID
	 *            -the user's id
	 * @param telephone
	 *            -the update telephone number
	 */
	public void txUpdateTel(String userID, String telephone) {
		StringBuilder hql = new StringBuilder();
		hql.append(" UPDATE ");
		hql.append("     UserInfo ");
		hql.append(" SET ");
		hql.append("     tel = '" + telephone + "' ");
		hql.append(" WHERE ");
		hql.append("     id= ?");
		hiTem.update(hql.toString(), userID);
	}

	/**
	 * update the user's email in table tb_student_zhangliyuan
	 * 
	 * @param userID
	 *            -the user's id
	 * @param email
	 *            -the update email
	 */
	public void txUpdateEmail(String userID, String email) {
		StringBuilder hql = new StringBuilder();
		hql.append(" UPDATE ");
		hql.append("     UserInfo ");
		hql.append(" SET ");
		hql.append("     email = '" + email + "' ");
		hql.append(" WHERE ");
		hql.append("     id= ?");
		hiTem.update(hql.toString(), userID);
	}
}

⌨️ 快捷键说明

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