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

/*成绩信息管理业务层类*/
class ScoreInfoService {
	/*添加成绩信息*/
	function AddScoreInfo(ScoreInfo $scoreInfo) {
		$scoreInfo_studentNumber = $scoreInfo->getStudentNumber();
		$scoreInfo_courseNumber = $scoreInfo->getCourseNumber();
		$scoreInfo_scoreValue = $scoreInfo->getScoreValue();
		$scoreInfo_studentEvaluate = $scoreInfo->getStudentEvaluate();

		// 构建sql语句
		$sql = "insert into t_ScoreInfo(studentNumber,courseNumber,scoreValue,studentEvaluate) values ('$scoreInfo_studentNumber','$scoreInfo_courseNumber',$scoreInfo_scoreValue,'$scoreInfo_studentEvaluate')";
		//调用数据层执行添加
		$sqlHelper = new SqlHelper ();
		$res = $sqlHelper->execute_dml ( $sql );
		$sqlHelper->close_connect ();
		return $res;
	}

	/*更新成绩信息信息*/
	function UpdateScoreInfo(ScoreInfo $scoreInfo) {
		$scoreInfo_scoreId = $scoreInfo->getScoreId();
		$scoreInfo_studentNumber = $scoreInfo->getStudentNumber();
		$scoreInfo_courseNumber = $scoreInfo->getCourseNumber();
		$scoreInfo_scoreValue = $scoreInfo->getScoreValue();
		$scoreInfo_studentEvaluate = $scoreInfo->getStudentEvaluate();
		$sql = "update t_ScoreInfo set ";
		$sql = $sql."studentNumber='$scoreInfo_studentNumber'";
		$sql = $sql.",courseNumber='$scoreInfo_courseNumber'";
		$sql = $sql.",scoreValue=$scoreInfo_scoreValue";
		$sql = $sql.",studentEvaluate='$scoreInfo_studentEvaluate'";
		$sql = $sql." where scoreId=$scoreInfo_scoreId";
		//调用数据层执行更新操作
		$sqlHelper = new SqlHelper (); 
		$res = $sqlHelper->execute_dml ( $sql );
		$sqlHelper->close_connect ();
		return $res;
	}

	// 根据记录编号获取成绩信息
	function GetScoreInfo($scoreId) {
		$sql = "select * from t_ScoreInfo where scoreId=$scoreId";
		$sqlHelper = new SqlHelper ();
		$arr = $sqlHelper->execute_dql2 ( $sql );
		$sqlHelper->close_connect ();
		// 二次封装,$arr=>ScoreInfo对象实例
		$scoreInfo = new ScoreInfo();
		if(count($arr)>0) {
			$scoreInfo->setScoreId($arr [0] ['scoreId']);
			$scoreInfo->setStudentNumber($arr [0] ['studentNumber']);
			$scoreInfo->setCourseNumber($arr [0] ['courseNumber']);
			$scoreInfo->setScoreValue($arr [0] ['scoreValue']);
			$scoreInfo->setStudentEvaluate($arr [0] ['studentEvaluate']);
		}
		return $scoreInfo;
	}

	/*用封装的方式完成分页查询*/
	function getFenyePage($fenyePage,$studentNumber,$courseNumber) {
		// 创建一个SqlHelper对象实例
		$sqlHelper = new SqlHelper ();
		//根据查询条件构造sql语句
		$sql1 = "select * from t_ScoreInfo where 1=1";
		$sql2 = "select count(scoreId) from t_ScoreInfo 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 DeleteScoreInfo($scoreId) {
		$sql = "delete from t_ScoreInfo where scoreId=$scoreId";
		// 创建SqlHelper对象实例执行删除
		$sqlHelper = new SqlHelper ();
		return $sqlHelper->execute_dml ( $sql );
	}

	/*查询所有的成绩信息*/
	function QueryAllScoreInfo() {
		$sql = "select scoreId,scoreId from t_ScoreInfo";
		$sqlHelper = new SqlHelper ();
		$res = $sqlHelper->execute_dql2 ( $sql );
		// 关闭连接
		$sqlHelper->close_connect ();
		return $res;
	}
}

?>
