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

/*学院信息管理业务层类*/
class CollegeInfoService {
	/*添加学院信息*/
	function AddCollegeInfo(CollegeInfo $collegeInfo) {
		$collegeInfo_collegeNumber = $collegeInfo->getCollegeNumber();
		$collegeInfo_collegeName = $collegeInfo->getCollegeName();
		$collegeInfo_collegeBirthDate = $collegeInfo->getCollegeBirthDate();
		$collegeInfo_collegeMan = $collegeInfo->getCollegeMan();
		$collegeInfo_collegeTelephone = $collegeInfo->getCollegeTelephone();
		$collegeInfo_collegeMemo = $collegeInfo->getCollegeMemo();

		// 构建sql语句
		$sql = "insert into t_CollegeInfo(collegeNumber,collegeName,collegeBirthDate,collegeMan,collegeTelephone,collegeMemo) values ('$collegeInfo_collegeNumber','$collegeInfo_collegeName','$collegeInfo_collegeBirthDate','$collegeInfo_collegeMan','$collegeInfo_collegeTelephone','$collegeInfo_collegeMemo')";
		//调用数据层执行添加
		$sqlHelper = new SqlHelper ();
		$res = $sqlHelper->execute_dml ( $sql );
		$sqlHelper->close_connect ();
		return $res;
	}

	/*更新学院信息信息*/
	function UpdateCollegeInfo(CollegeInfo $collegeInfo) {
		$collegeInfo_collegeNumber = $collegeInfo->getCollegeNumber();
		$collegeInfo_collegeName = $collegeInfo->getCollegeName();
		$collegeInfo_collegeBirthDate = $collegeInfo->getCollegeBirthDate();
		$collegeInfo_collegeMan = $collegeInfo->getCollegeMan();
		$collegeInfo_collegeTelephone = $collegeInfo->getCollegeTelephone();
		$collegeInfo_collegeMemo = $collegeInfo->getCollegeMemo();
		$sql = "update t_CollegeInfo set ";
		$sql = $sql."collegeName='$collegeInfo_collegeName'";
		$sql = $sql.",collegeBirthDate='$collegeInfo_collegeBirthDate'";
		$sql = $sql.",collegeMan='$collegeInfo_collegeMan'";
		$sql = $sql.",collegeTelephone='$collegeInfo_collegeTelephone'";
		$sql = $sql.",collegeMemo='$collegeInfo_collegeMemo'";
		$sql = $sql." where collegeNumber='$collegeInfo_collegeNumber'";
		//调用数据层执行更新操作
		$sqlHelper = new SqlHelper (); 
		$res = $sqlHelper->execute_dml ( $sql );
		$sqlHelper->close_connect ();
		return $res;
	}

	// 根据学院编号获取学院信息
	function GetCollegeInfo($collegeNumber) {
		$sql = "select * from t_CollegeInfo where collegeNumber='$collegeNumber'";
		$sqlHelper = new SqlHelper ();
		$arr = $sqlHelper->execute_dql2 ( $sql );
		$sqlHelper->close_connect ();
		// 二次封装,$arr=>CollegeInfo对象实例
		$collegeInfo = new CollegeInfo();
		if(count($arr)>0) {
			$collegeInfo->setCollegeNumber($arr [0] ['collegeNumber']);
			$collegeInfo->setCollegeName($arr [0] ['collegeName']);
			$collegeInfo->setCollegeBirthDate($arr [0] ['collegeBirthDate']);
			$collegeInfo->setCollegeMan($arr [0] ['collegeMan']);
			$collegeInfo->setCollegeTelephone($arr [0] ['collegeTelephone']);
			$collegeInfo->setCollegeMemo($arr [0] ['collegeMemo']);
		}
		return $collegeInfo;
	}

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

	/*查询所有的学院信息*/
	function QueryAllCollegeInfo() {
		$sql = "select collegeNumber,collegeName from t_CollegeInfo";
		$sqlHelper = new SqlHelper ();
		$res = $sqlHelper->execute_dql2 ( $sql );
		// 关闭连接
		$sqlHelper->close_connect ();
		return $res;
	}
}

?>
