<?php
require_once '../database/SqlHelper.class.php';
require_once '../phpbean/StudentSelectCourseInfo.class.php';

/*选课信息管理业务层类*/
class StudentSelectCourseInfoService {
	/*添加选课信息*/
	function AddStudentSelectCourseInfo(StudentSelectCourseInfo $studentSelectCourseInfo) {
		$studentSelectCourseInfo_studentNumber = $studentSelectCourseInfo->getStudentNumber();
		$studentSelectCourseInfo_courseNumber = $studentSelectCourseInfo->getCourseNumber();

		// 构建sql语句
		$sql = "insert into t_StudentSelectCourseInfo(studentNumber,courseNumber) values ('$studentSelectCourseInfo_studentNumber','$studentSelectCourseInfo_courseNumber')";
		//调用数据层执行添加
		$sqlHelper = new SqlHelper ();
		$res = $sqlHelper->execute_dml ( $sql );
		$sqlHelper->close_connect ();
		return $res;
	}

	/*更新选课信息信息*/
	function UpdateStudentSelectCourseInfo(StudentSelectCourseInfo $studentSelectCourseInfo) {
		$studentSelectCourseInfo_selectId = $studentSelectCourseInfo->getSelectId();
		$studentSelectCourseInfo_studentNumber = $studentSelectCourseInfo->getStudentNumber();
		$studentSelectCourseInfo_courseNumber = $studentSelectCourseInfo->getCourseNumber();
		$sql = "update t_StudentSelectCourseInfo set ";
		$sql = $sql."studentNumber='$studentSelectCourseInfo_studentNumber'";
		$sql = $sql.",courseNumber='$studentSelectCourseInfo_courseNumber'";
		$sql = $sql." where selectId=$studentSelectCourseInfo_selectId";
		//调用数据层执行更新操作
		$sqlHelper = new SqlHelper (); 
		$res = $sqlHelper->execute_dml ( $sql );
		$sqlHelper->close_connect ();
		return $res;
	}

	// 根据记录编号获取选课信息
	function GetStudentSelectCourseInfo($selectId) {
		$sql = "select * from t_StudentSelectCourseInfo where selectId=$selectId";
		$sqlHelper = new SqlHelper ();
		$arr = $sqlHelper->execute_dql2 ( $sql );
		$sqlHelper->close_connect ();
		// 二次封装,$arr=>StudentSelectCourseInfo对象实例
		$studentSelectCourseInfo = new StudentSelectCourseInfo();
		if(count($arr)>0) {
			$studentSelectCourseInfo->setSelectId($arr [0] ['selectId']);
			$studentSelectCourseInfo->setStudentNumber($arr [0] ['studentNumber']);
			$studentSelectCourseInfo->setCourseNumber($arr [0] ['courseNumber']);
		}
		return $studentSelectCourseInfo;
	}

	/*用封装的方式完成分页查询*/
	function getFenyePage($fenyePage,$studentNumber,$courseNumber) {
		// 创建一个SqlHelper对象实例
		$sqlHelper = new SqlHelper ();
		//根据查询条件构造sql语句
		$sql1 = "select * from t_StudentSelectCourseInfo where 1=1";
		$sql2 = "select count(selectId) from t_StudentSelectCourseInfo where 1=1";
		$condition = "";
		if($studentNumber != "") $condition = $condition." and studentNumber='$studentNumber'";
		if($courseNumber != "") $condition = $condition." and courseNumber='$courseNumber'";
		$sql1 = $sql1.$condition." limit ". ($fenyePage->pageNow - 1) * $fenyePage->pageSize . "," . $fenyePage->pageSize;
		$sql2 = $sql2.$condition;
		//调用数据层执行查询操作
		$sqlHelper->execute_dql_fenye ( $sql1, $sql2, $fenyePage );
		$sqlHelper->close_connect ();
	}

	// 根据记录编号删除某个选课信息
	function DeleteStudentSelectCourseInfo($selectId) {
		$sql = "delete from t_StudentSelectCourseInfo where selectId=$selectId";
		// 创建SqlHelper对象实例执行删除
		$sqlHelper = new SqlHelper ();
		return $sqlHelper->execute_dml ( $sql );
	}

	/*查询所有的选课信息*/
	function QueryAllStudentSelectCourseInfo() {
		$sql = "select selectId,selectId from t_StudentSelectCourseInfo";
		$sqlHelper = new SqlHelper ();
		$res = $sqlHelper->execute_dql2 ( $sql );
		// 关闭连接
		$sqlHelper->close_connect ();
		return $res;
	}
}

?>
