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

/*专业信息管理业务层类*/
class SpecialFieldInfoService {
	/*添加专业信息*/
	function AddSpecialFieldInfo(SpecialFieldInfo $specialFieldInfo) {
		$specialFieldInfo_specialFieldNumber = $specialFieldInfo->getSpecialFieldNumber();
		$specialFieldInfo_specialFieldName = $specialFieldInfo->getSpecialFieldName();
		$specialFieldInfo_specialCollegeNumber = $specialFieldInfo->getSpecialCollegeNumber();
		$specialFieldInfo_specialBirthDate = $specialFieldInfo->getSpecialBirthDate();
		$specialFieldInfo_specialMan = $specialFieldInfo->getSpecialMan();
		$specialFieldInfo_specialTelephone = $specialFieldInfo->getSpecialTelephone();
		$specialFieldInfo_specialMemo = $specialFieldInfo->getSpecialMemo();

		// 构建sql语句
		$sql = "insert into t_SpecialFieldInfo(specialFieldNumber,specialFieldName,specialCollegeNumber,specialBirthDate,specialMan,specialTelephone,specialMemo) values ('$specialFieldInfo_specialFieldNumber','$specialFieldInfo_specialFieldName','$specialFieldInfo_specialCollegeNumber','$specialFieldInfo_specialBirthDate','$specialFieldInfo_specialMan','$specialFieldInfo_specialTelephone','$specialFieldInfo_specialMemo')";
		//调用数据层执行添加
		$sqlHelper = new SqlHelper ();
		$res = $sqlHelper->execute_dml ( $sql );
		$sqlHelper->close_connect ();
		return $res;
	}

	/*更新专业信息信息*/
	function UpdateSpecialFieldInfo(SpecialFieldInfo $specialFieldInfo) {
		$specialFieldInfo_specialFieldNumber = $specialFieldInfo->getSpecialFieldNumber();
		$specialFieldInfo_specialFieldName = $specialFieldInfo->getSpecialFieldName();
		$specialFieldInfo_specialCollegeNumber = $specialFieldInfo->getSpecialCollegeNumber();
		$specialFieldInfo_specialBirthDate = $specialFieldInfo->getSpecialBirthDate();
		$specialFieldInfo_specialMan = $specialFieldInfo->getSpecialMan();
		$specialFieldInfo_specialTelephone = $specialFieldInfo->getSpecialTelephone();
		$specialFieldInfo_specialMemo = $specialFieldInfo->getSpecialMemo();
		$sql = "update t_SpecialFieldInfo set ";
		$sql = $sql."specialFieldName='$specialFieldInfo_specialFieldName'";
		$sql = $sql.",specialCollegeNumber='$specialFieldInfo_specialCollegeNumber'";
		$sql = $sql.",specialBirthDate='$specialFieldInfo_specialBirthDate'";
		$sql = $sql.",specialMan='$specialFieldInfo_specialMan'";
		$sql = $sql.",specialTelephone='$specialFieldInfo_specialTelephone'";
		$sql = $sql.",specialMemo='$specialFieldInfo_specialMemo'";
		$sql = $sql." where specialFieldNumber='$specialFieldInfo_specialFieldNumber'";
		//调用数据层执行更新操作
		$sqlHelper = new SqlHelper (); 
		$res = $sqlHelper->execute_dml ( $sql );
		$sqlHelper->close_connect ();
		return $res;
	}

	// 根据专业编号获取专业信息
	function GetSpecialFieldInfo($specialFieldNumber) {
		$sql = "select * from t_SpecialFieldInfo where specialFieldNumber='$specialFieldNumber'";
		$sqlHelper = new SqlHelper ();
		$arr = $sqlHelper->execute_dql2 ( $sql );
		$sqlHelper->close_connect ();
		// 二次封装,$arr=>SpecialFieldInfo对象实例
		$specialFieldInfo = new SpecialFieldInfo();
		if(count($arr)>0) {
			$specialFieldInfo->setSpecialFieldNumber($arr [0] ['specialFieldNumber']);
			$specialFieldInfo->setSpecialFieldName($arr [0] ['specialFieldName']);
			$specialFieldInfo->setSpecialCollegeNumber($arr [0] ['specialCollegeNumber']);
			$specialFieldInfo->setSpecialBirthDate($arr [0] ['specialBirthDate']);
			$specialFieldInfo->setSpecialMan($arr [0] ['specialMan']);
			$specialFieldInfo->setSpecialTelephone($arr [0] ['specialTelephone']);
			$specialFieldInfo->setSpecialMemo($arr [0] ['specialMemo']);
		}
		return $specialFieldInfo;
	}

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

	/*查询所有的专业信息*/
	function QueryAllSpecialFieldInfo() {
		$sql = "select specialFieldNumber,specialFieldName from t_SpecialFieldInfo";
		$sqlHelper = new SqlHelper ();
		$res = $sqlHelper->execute_dql2 ( $sql );
		// 关闭连接
		$sqlHelper->close_connect ();
		return $res;
	}
}

?>
