<?php
require_once '../phpbean/StudentSelectCourseInfo.class.php';
require_once '../service/StudentSelectCourseInfoService.class.php';

//创建了StudentSelectCourseInfoService实例
$studentSelectCourseInfoService = new StudentSelectCourseInfoService();

//根据action参数决定用户要执行什么样的操作
if(!empty($_REQUEST['action'])) {
	//接收action值
	$action = $_REQUEST['action'];
	if($action == "add") {
		//说明用户希望执行添加选课信息信息
		$studentSelectCourseInfo = new StudentSelectCourseInfo();
		$array_studentSelectCourseInfo = $_POST["studentSelectCourseInfo"];
		$studentSelectCourseInfo->setSelectId($array_studentSelectCourseInfo['selectId']);
		$studentSelectCourseInfo->setStudentNumber($array_studentSelectCourseInfo['studentNumber']);
		$studentSelectCourseInfo->setCourseNumber($array_studentSelectCourseInfo['courseNumber']);
		//完成添加->数据库
		$res = $studentSelectCourseInfoService->AddStudentSelectCourseInfo($studentSelectCourseInfo);
		if($res==1) {
			header("Location: /ok.php");
			exit();
		} else {
			//失败
			header("Location: /error.php");
			exit();
		}
	} else if($action == "query") {
		//查询选课信息信息
		require_once '../service/StudentSelectCourseInfoService.class.php';
		require_once '../service/FenyePage.class.php';
		//获取查询参数
		$studentNumber = !empty($_POST['studentNumber']) ? $_POST['studentNumber'] : "";
		$courseNumber = !empty($_POST['courseNumber']) ? $_POST['courseNumber'] : "";
		//创建StudentSelectCourseInfoService实例
		$studentSelectCourseInfoService = new StudentSelectCourseInfoService();

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

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

		//调用getFenyePage，该方法可以把fenyePage完成
		$studentSelectCourseInfoService->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 '../StudentSelectCourseInfo/studentSelectCourseInfoManage.php';
	} else if($action == "frontQuery") {
		//查询选课信息信息
		require_once '../service/StudentSelectCourseInfoService.class.php';
		require_once '../service/FenyePage.class.php';
		//获取查询参数
		$studentNumber = !empty($_POST['studentNumber']) ? $_POST['studentNumber'] : "";
		$courseNumber = !empty($_POST['courseNumber']) ? $_POST['courseNumber'] : "";
		//创建StudentSelectCourseInfoService实例
		$studentSelectCourseInfoService = new StudentSelectCourseInfoService();

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

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

		//调用getFenyePage，该方法可以把fenyePage完成
		$studentSelectCourseInfoService->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 '../StudentSelectCourseInfo/studentSelectCourseInfoFrontQuery.php';
	} else if($action == "update") {
		//说明用户希望执行更新选课信息信息
		$array_studentSelectCourseInfo = $_POST["studentSelectCourseInfo"];
		$studentSelectCourseInfo = $studentSelectCourseInfoService->GetStudentSelectCourseInfo($array_studentSelectCourseInfo['selectId']);
		$studentSelectCourseInfo->setSelectId($array_studentSelectCourseInfo['selectId']);
		$studentSelectCourseInfo->setStudentNumber($array_studentSelectCourseInfo['studentNumber']);
		$studentSelectCourseInfo->setCourseNumber($array_studentSelectCourseInfo['courseNumber']);
		//完成修改->数据库
		$res = $studentSelectCourseInfoService->UpdateStudentSelectCourseInfo($studentSelectCourseInfo);
		if($res != 0) {
			header("Location: /ok.php");
			exit();
		} else {
			//失败
			header("Location: /error.php");
			exit();
		}
	} else if($action == "del") {
		//这时我们知道要删除选课信息信息
		$selectId = $_GET['selectId'];
		if($studentSelectCourseInfoService->DeleteStudentSelectCourseInfo($selectId) == 1) {
			//成功
			header("Location: /ok.php");
			exit();
		} else {
			//失败
			header("Location: /error.php");
			exit();
		}
	}
}
?>
