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

/*班级信息管理业务层类*/
class ClassInfoService {
	/*添加班级信息*/
	function AddClassInfo(ClassInfo $classInfo) {
		$classInfo_classNumber = $classInfo->getClassNumber();
		$classInfo_className = $classInfo->getClassName();
		$classInfo_classSpecialFieldNumber = $classInfo->getClassSpecialFieldNumber();
		$classInfo_classBirthDate = $classInfo->getClassBirthDate();
		$classInfo_classTeacherCharge = $classInfo->getClassTeacherCharge();
		$classInfo_classTelephone = $classInfo->getClassTelephone();
		$classInfo_classMemo = $classInfo->getClassMemo();

		// 构建sql语句
		$sql = "insert into t_ClassInfo(classNumber,className,classSpecialFieldNumber,classBirthDate,classTeacherCharge,classTelephone,classMemo) values ('$classInfo_classNumber','$classInfo_className','$classInfo_classSpecialFieldNumber','$classInfo_classBirthDate','$classInfo_classTeacherCharge','$classInfo_classTelephone','$classInfo_classMemo')";
		//调用数据层执行添加
		$sqlHelper = new SqlHelper ();
		$res = $sqlHelper->execute_dml ( $sql );
		$sqlHelper->close_connect ();
		return $res;
	}

	/*更新班级信息信息*/
	function UpdateClassInfo(ClassInfo $classInfo) {
		$classInfo_classNumber = $classInfo->getClassNumber();
		$classInfo_className = $classInfo->getClassName();
		$classInfo_classSpecialFieldNumber = $classInfo->getClassSpecialFieldNumber();
		$classInfo_classBirthDate = $classInfo->getClassBirthDate();
		$classInfo_classTeacherCharge = $classInfo->getClassTeacherCharge();
		$classInfo_classTelephone = $classInfo->getClassTelephone();
		$classInfo_classMemo = $classInfo->getClassMemo();
		$sql = "update t_ClassInfo set ";
		$sql = $sql."className='$classInfo_className'";
		$sql = $sql.",classSpecialFieldNumber='$classInfo_classSpecialFieldNumber'";
		$sql = $sql.",classBirthDate='$classInfo_classBirthDate'";
		$sql = $sql.",classTeacherCharge='$classInfo_classTeacherCharge'";
		$sql = $sql.",classTelephone='$classInfo_classTelephone'";
		$sql = $sql.",classMemo='$classInfo_classMemo'";
		$sql = $sql." where classNumber='$classInfo_classNumber'";
		//调用数据层执行更新操作
		$sqlHelper = new SqlHelper (); 
		$res = $sqlHelper->execute_dml ( $sql );
		$sqlHelper->close_connect ();
		return $res;
	}

	// 根据班级编号获取班级信息
	function GetClassInfo($classNumber) {
		$sql = "select * from t_ClassInfo where classNumber='$classNumber'";
		$sqlHelper = new SqlHelper ();
		$arr = $sqlHelper->execute_dql2 ( $sql );
		$sqlHelper->close_connect ();
		// 二次封装,$arr=>ClassInfo对象实例
		$classInfo = new ClassInfo();
		if(count($arr)>0) {
			$classInfo->setClassNumber($arr [0] ['classNumber']);
			$classInfo->setClassName($arr [0] ['className']);
			$classInfo->setClassSpecialFieldNumber($arr [0] ['classSpecialFieldNumber']);
			$classInfo->setClassBirthDate($arr [0] ['classBirthDate']);
			$classInfo->setClassTeacherCharge($arr [0] ['classTeacherCharge']);
			$classInfo->setClassTelephone($arr [0] ['classTelephone']);
			$classInfo->setClassMemo($arr [0] ['classMemo']);
		}
		return $classInfo;
	}

	/*用封装的方式完成分页查询*/
	function getFenyePage($fenyePage,$classNumber,$className,$classSpecialFieldNumber,$classBirthDate) {
		// 创建一个SqlHelper对象实例
		$sqlHelper = new SqlHelper ();
		//根据查询条件构造sql语句
		$sql1 = "select * from t_ClassInfo where 1=1";
		$sql2 = "select count(classNumber) from t_ClassInfo where 1=1";
		$condition = "";
		if($classNumber != "") $condition = $condition." and classNumber like '%$classNumber%'";
		if($className != "") $condition = $condition." and className like '%$className%'";
		if($classSpecialFieldNumber != "") $condition = $condition." and classSpecialFieldNumber='$classSpecialFieldNumber'";
		if($classBirthDate != "") $condition = $condition." and classBirthDate='$classBirthDate'";
		$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 DeleteClassInfo($classNumber) {
		$sql = "delete from t_ClassInfo where classNumber='$classNumber'";
		// 创建SqlHelper对象实例执行删除
		$sqlHelper = new SqlHelper ();
		return $sqlHelper->execute_dml ( $sql );
	}

	/*查询所有的班级信息*/
	function QueryAllClassInfo() {
		$sql = "select classNumber,className from t_ClassInfo";
		$sqlHelper = new SqlHelper ();
		$res = $sqlHelper->execute_dql2 ( $sql );
		// 关闭连接
		$sqlHelper->close_connect ();
		return $res;
	}
}

?>
