package com.mobileserver.dao;

import java.sql.ResultSet;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;

import com.mobileserver.domain.CourseInfo_QQ254540457;
import com.mobileserver.util.DB;

public class CourseInfo_QQ254540457DAO {

	public List<CourseInfo_QQ254540457> QueryCourseInfo_QQ254540457(String courseNumber,String courseName,String courseTeacher) {
		List<CourseInfo_QQ254540457> courseInfo_QQ254540457List = new ArrayList<CourseInfo_QQ254540457>();
		DB db = new DB();
		String sql = "select * from CourseInfo_QQ254540457 where 1=1";
		if (!courseNumber.equals(""))
			sql += " and courseNumber like '%" + courseNumber + "%'";
		if (!courseName.equals(""))
			sql += " and courseName like '%" + courseName + "%'";
		if (!courseTeacher.equals(""))
			sql += " and courseTeacher = '" + courseTeacher + "'";
		try {
			ResultSet rs = db.executeQuery(sql);
			while (rs.next()) {
				CourseInfo_QQ254540457 courseInfo_QQ254540457 = new CourseInfo_QQ254540457();
				courseInfo_QQ254540457.setCourseNumber(rs.getString("courseNumber"));
				courseInfo_QQ254540457.setCourseName(rs.getString("courseName"));
				courseInfo_QQ254540457.setCourseTeacher(rs.getString("courseTeacher"));
				courseInfo_QQ254540457.setCourseTime(rs.getString("courseTime"));
				courseInfo_QQ254540457.setCoursePlace(rs.getString("coursePlace"));
				courseInfo_QQ254540457.setCourseScore(rs.getFloat("courseScore"));
				courseInfo_QQ254540457.setCourseMemo(rs.getString("courseMemo"));
				courseInfo_QQ254540457List.add(courseInfo_QQ254540457);
			}
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			db.all_close();
		}
		return courseInfo_QQ254540457List;
	}
	/* 传入课程信息对象，进行课程信息的添加业务 */
	public String AddCourseInfo_QQ254540457(CourseInfo_QQ254540457 courseInfo_QQ254540457) {
		DB db = new DB();
		String result = "";
		try {
			/* 构建sql执行插入新课程信息 */
			String sqlString = "insert into CourseInfo_QQ254540457(courseNumber,courseName,courseTeacher,courseTime,coursePlace,courseScore,courseMemo) values (";
			sqlString += "'" + courseInfo_QQ254540457.getCourseNumber() + "',";
			sqlString += "'" + courseInfo_QQ254540457.getCourseName() + "',";
			sqlString += "'" + courseInfo_QQ254540457.getCourseTeacher() + "',";
			sqlString += "'" + courseInfo_QQ254540457.getCourseTime() + "',";
			sqlString += "'" + courseInfo_QQ254540457.getCoursePlace() + "',";
			sqlString += courseInfo_QQ254540457.getCourseScore() + ",";
			sqlString += "'" + courseInfo_QQ254540457.getCourseMemo() + "'";
			sqlString += ")";
			db.executeUpdate(sqlString);
			result = "课程信息添加成功!";
		} catch (Exception e) {
			e.printStackTrace();
			result = "课程信息添加失败";
		} finally {
			db.all_close();
		}
		return result;
	}
	/* 删除课程信息 */
	public String DeleteCourseInfo_QQ254540457(String courseNumber) {
		DB db = new DB();
		String result = "";
		try {
			String sqlString = "delete from CourseInfo_QQ254540457 where courseNumber='" + courseNumber + "'";
			db.executeUpdate(sqlString);
			result = "课程信息删除成功!";
		} catch (Exception e) {
			e.printStackTrace();
			result = "课程信息删除失败";
		} finally {
			db.all_close();
		}
		return result;
	}

	/* 根据课程编号获取到课程信息 */
	public CourseInfo_QQ254540457 GetCourseInfo_QQ254540457(String courseNumber) {
		CourseInfo_QQ254540457 courseInfo_QQ254540457 = null;
		DB db = new DB();
		String sql = "select * from CourseInfo_QQ254540457 where courseNumber='" + courseNumber + "'";
		try {
			ResultSet rs = db.executeQuery(sql);
			if (rs.next()) {
				courseInfo_QQ254540457 = new CourseInfo_QQ254540457();
				courseInfo_QQ254540457.setCourseNumber(rs.getString("courseNumber"));
				courseInfo_QQ254540457.setCourseName(rs.getString("courseName"));
				courseInfo_QQ254540457.setCourseTeacher(rs.getString("courseTeacher"));
				courseInfo_QQ254540457.setCourseTime(rs.getString("courseTime"));
				courseInfo_QQ254540457.setCoursePlace(rs.getString("coursePlace"));
				courseInfo_QQ254540457.setCourseScore(rs.getFloat("courseScore"));
				courseInfo_QQ254540457.setCourseMemo(rs.getString("courseMemo"));
			}
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			db.all_close();
		}
		return courseInfo_QQ254540457;
	}
	/* 更新课程信息 */
	public String UpdateCourseInfo_QQ254540457(CourseInfo_QQ254540457 courseInfo_QQ254540457) {
		DB db = new DB();
		String result = "";
		try {
			String sql = "update CourseInfo_QQ254540457 set ";
			sql += "courseName='" + courseInfo_QQ254540457.getCourseName() + "',";
			sql += "courseTeacher='" + courseInfo_QQ254540457.getCourseTeacher() + "',";
			sql += "courseTime='" + courseInfo_QQ254540457.getCourseTime() + "',";
			sql += "coursePlace='" + courseInfo_QQ254540457.getCoursePlace() + "',";
			sql += "courseScore=" + courseInfo_QQ254540457.getCourseScore() + ",";
			sql += "courseMemo='" + courseInfo_QQ254540457.getCourseMemo() + "'";
			sql += " where courseNumber='" + courseInfo_QQ254540457.getCourseNumber() + "'";
			db.executeUpdate(sql);
			result = "课程信息更新成功!";
		} catch (Exception e) {
			e.printStackTrace();
			result = "课程信息更新失败";
		} finally {
			db.all_close();
		}
		return result;
	}
}
