<?php
require_once '../phpbean/ScoreInfo.class.php';
require_once '../service/ScoreInfoService.class.php';

//创建了ScoreInfoService实例
$scoreInfoService = new ScoreInfoService();

//根据action参数决定用户要执行什么样的操作
if(!empty($_REQUEST['action'])) {
	//接收action值
	$action = $_REQUEST['action'];
	if($action == "add") {
		//说明用户希望执行添加成绩信息信息
		$scoreInfo = new ScoreInfo();
		$array_scoreInfo = $_POST["scoreInfo"];
		$scoreInfo->setScoreId($array_scoreInfo['scoreId']);
		$scoreInfo->setStudentNumber($array_scoreInfo['studentNumber']);
		$scoreInfo->setCourseNumber($array_scoreInfo['courseNumber']);
		$scoreInfo->setScoreValue($array_scoreInfo['scoreValue']);
		$scoreInfo->setStudentEvaluate($array_scoreInfo['studentEvaluate']);
		//完成添加->数据库
		$res = $scoreInfoService->AddScoreInfo($scoreInfo);
		if($res==1) {
			header("Location: /ok.php");
			exit();
		} else {
			//失败
			header("Location: /error.php");
			exit();
		}
	} else if($action == "query") {
		//查询成绩信息信息
		require_once '../service/ScoreInfoService.class.php';
		require_once '../service/FenyePage.class.php';
		//获取查询参数
		$studentNumber = !empty($_POST['studentNumber']) ? $_POST['studentNumber'] : "";
		$courseNumber = !empty($_POST['courseNumber']) ? $_POST['courseNumber'] : "";
		//创建ScoreInfoService实例
		$scoreInfoService = new ScoreInfoService();

		//创建一个FenyePage对象实例
		$fenyePage = new FenyePage();
		//给fenyePage指定必须的参数
		$fenyePage->pageNow = 1;
		$fenyePage->pageSize = 5;
		$fenyePage->gotoUrl = "ScoreInfoAction.php";

		//在此我们需要根据用户的点击来修改pageNow的值，不要判断是否有这个pageNow发送
		if(!empty($_REQUEST['pageNow'])){
			$fenyePage->pageNow=$_REQUEST['pageNow'];
		}

		//调用getFenyePage，该方法可以把fenyePage完成
		$scoreInfoService->getFenyePage($fenyePage,$studentNumber,$courseNumber);
		require_once '../service/StudentService.class.php';
		$studentService = new StudentService();
		$student_res = $studentService->QueryAllStudent();

		require_once '../service/CourseInfoService.class.php';
		$courseInfoService = new CourseInfoService();
		$courseInfo_res = $courseInfoService->QueryAllCourseInfo();

		include '../ScoreInfo/scoreInfoManage.php';
	} else if($action == "frontQuery") {
		//查询成绩信息信息
		require_once '../service/ScoreInfoService.class.php';
		require_once '../service/FenyePage.class.php';
		//获取查询参数
		$studentNumber = !empty($_POST['studentNumber']) ? $_POST['studentNumber'] : "";
		$courseNumber = !empty($_POST['courseNumber']) ? $_POST['courseNumber'] : "";
		//创建ScoreInfoService实例
		$scoreInfoService = new ScoreInfoService();

		//创建一个FenyePage对象实例
		$fenyePage = new FenyePage();
		//给fenyePage指定必须的参数
		$fenyePage->pageNow = 1;
		$fenyePage->pageSize = 5;
		$fenyePage->gotoUrl = "ScoreInfoAction.php";

		//在此我们需要根据用户的点击来修改pageNow的值，不要判断是否有这个pageNow发送
		if(!empty($_REQUEST['pageNow'])){
			$fenyePage->pageNow=$_REQUEST['pageNow'];
		}

		//调用getFenyePage，该方法可以把fenyePage完成
		$scoreInfoService->getFenyePage($fenyePage,$studentNumber,$courseNumber);
		require_once '../service/StudentService.class.php';
		$studentService = new StudentService();
		$student_res = $studentService->QueryAllStudent();

		require_once '../service/CourseInfoService.class.php';
		$courseInfoService = new CourseInfoService();
		$courseInfo_res = $courseInfoService->QueryAllCourseInfo();

		include '../ScoreInfo/scoreInfoFrontQuery.php';
	} else if($action == "update") {
		//说明用户希望执行更新成绩信息信息
		$array_scoreInfo = $_POST["scoreInfo"];
		$scoreInfo = $scoreInfoService->GetScoreInfo($array_scoreInfo['scoreId']);
		$scoreInfo->setScoreId($array_scoreInfo['scoreId']);
		$scoreInfo->setStudentNumber($array_scoreInfo['studentNumber']);
		$scoreInfo->setCourseNumber($array_scoreInfo['courseNumber']);
		$scoreInfo->setScoreValue($array_scoreInfo['scoreValue']);
		$scoreInfo->setStudentEvaluate($array_scoreInfo['studentEvaluate']);
		//完成修改->数据库
		$res = $scoreInfoService->UpdateScoreInfo($scoreInfo);
		if($res != 0) {
			header("Location: /ok.php");
			exit();
		} else {
			//失败
			header("Location: /error.php");
			exit();
		}
	} else if($action == "del") {
		//这时我们知道要删除成绩信息信息
		$scoreId = $_GET['scoreId'];
		if($scoreInfoService->DeleteScoreInfo($scoreId) == 1) {
			//成功
			header("Location: /ok.php");
			exit();
		} else {
			//失败
			header("Location: /error.php");
			exit();
		}
	}
}
?>
