using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;

using ENTITY;

namespace DAL
{
    /*课程信息业务逻辑层实现*/
    public class dalCourseInfo_QQ254540457
    {
        /*待执行的sql语句*/
        public static string sql = "";

        /*添加课程信息实现*/
        public static bool AddCourseInfo_QQ254540457(ENTITY.CourseInfo_QQ254540457 courseInfo_QQ254540457)
        {
            string sql = "insert into CourseInfo_QQ254540457(courseNumber,courseName,courseTeacher,courseTime,coursePlace,courseScore,courseMemo) values(@courseNumber,@courseName,@courseTeacher,@courseTime,@coursePlace,@courseScore,@courseMemo)";
            /*构建sql参数*/
            SqlParameter[] parm = new SqlParameter[] {
             new SqlParameter("@courseNumber",SqlDbType.VarChar),
             new SqlParameter("@courseName",SqlDbType.VarChar),
             new SqlParameter("@courseTeacher",SqlDbType.VarChar),
             new SqlParameter("@courseTime",SqlDbType.VarChar),
             new SqlParameter("@coursePlace",SqlDbType.VarChar),
             new SqlParameter("@courseScore",SqlDbType.Float),
             new SqlParameter("@courseMemo",SqlDbType.VarChar)
            };
            /*给参数赋值*/
            parm[0].Value = courseInfo_QQ254540457.courseNumber; //课程编号
            parm[1].Value = courseInfo_QQ254540457.courseName; //课程名称
            parm[2].Value = courseInfo_QQ254540457.courseTeacher; //上课老师
            parm[3].Value = courseInfo_QQ254540457.courseTime; //上课时间
            parm[4].Value = courseInfo_QQ254540457.coursePlace; //上课地点
            parm[5].Value = courseInfo_QQ254540457.courseScore; //课程学分
            parm[6].Value = courseInfo_QQ254540457.courseMemo; //附加信息

            /*执行sql进行添加*/
            return (DBHelp.ExecuteNonQuery(sql, parm) > 0) ? true : false;
        }

        /*根据courseNumber获取某条课程信息记录*/
        public static ENTITY.CourseInfo_QQ254540457 getSomeCourseInfo_QQ254540457(string courseNumber)
        {
            /*构建查询sql*/
            string sql = "select * from CourseInfo_QQ254540457 where courseNumber='" + courseNumber + "'"; 
            SqlDataReader DataRead = DBHelp.ExecuteReader(sql, null);
            ENTITY.CourseInfo_QQ254540457 courseInfo_QQ254540457 = new ENTITY.CourseInfo_QQ254540457();
            /*如果查询存在记录，就包装到对象中返回*/
            if (DataRead.Read())
            {
                courseInfo_QQ254540457.courseNumber = DataRead["courseNumber"].ToString();
                courseInfo_QQ254540457.courseName = DataRead["courseName"].ToString();
                courseInfo_QQ254540457.courseTeacher = DataRead["courseTeacher"].ToString();
                courseInfo_QQ254540457.courseTime = DataRead["courseTime"].ToString();
                courseInfo_QQ254540457.coursePlace = DataRead["coursePlace"].ToString();
                courseInfo_QQ254540457.courseScore = float.Parse(DataRead["courseScore"].ToString());
                courseInfo_QQ254540457.courseMemo = DataRead["courseMemo"].ToString();
            }
            return courseInfo_QQ254540457;
        }

        /*更新课程信息实现*/
        public static bool EditCourseInfo_QQ254540457(ENTITY.CourseInfo_QQ254540457 courseInfo_QQ254540457)
        {
            string sql = "update CourseInfo_QQ254540457 set courseName=@courseName,courseTeacher=@courseTeacher,courseTime=@courseTime,coursePlace=@coursePlace,courseScore=@courseScore,courseMemo=@courseMemo where courseNumber=@courseNumber";
            /*构建sql参数信息*/
            SqlParameter[] parm = new SqlParameter[] {
             new SqlParameter("@courseName",SqlDbType.VarChar),
             new SqlParameter("@courseTeacher",SqlDbType.VarChar),
             new SqlParameter("@courseTime",SqlDbType.VarChar),
             new SqlParameter("@coursePlace",SqlDbType.VarChar),
             new SqlParameter("@courseScore",SqlDbType.Float),
             new SqlParameter("@courseMemo",SqlDbType.VarChar),
             new SqlParameter("@courseNumber",SqlDbType.VarChar)
            };
            /*为参数赋值*/
            parm[0].Value = courseInfo_QQ254540457.courseName;
            parm[1].Value = courseInfo_QQ254540457.courseTeacher;
            parm[2].Value = courseInfo_QQ254540457.courseTime;
            parm[3].Value = courseInfo_QQ254540457.coursePlace;
            parm[4].Value = courseInfo_QQ254540457.courseScore;
            parm[5].Value = courseInfo_QQ254540457.courseMemo;
            parm[6].Value = courseInfo_QQ254540457.courseNumber;
            /*执行更新*/
            return (DBHelp.ExecuteNonQuery(sql, parm) > 0) ? true : false;
        }


        /*删除课程信息*/
        public static bool DelCourseInfo_QQ254540457(string p)
        {
            string sql = "";
            string[] ids = p.Split(',');
            for(int i=0;i<ids.Length;i++)
            {
                if(i != ids.Length-1)
                  sql += "'" + ids[i] + "',";
                else
                  sql += "'" + ids[i] + "'";
            }
            sql = "delete from CourseInfo_QQ254540457 where courseNumber in (" + sql + ")";
            return ((DBHelp.ExecuteNonQuery(sql, null)) > 0) ? true : false;
        }


        /*查询课程信息*/
        public static System.Data.DataTable GetCourseInfo_QQ254540457(int PageIndex, int PageSize, out int PageCount, out int RecordCount, string strWhere)
        {
            try
            {
                string strSql = " select * from CourseInfo_QQ254540457";
                string strShow = "*";
                return DAL.DBHelp.ExecutePagerWhenPrimaryIsString(PageIndex, PageSize, "courseNumber", strShow, strSql, strWhere, " courseNumber asc ", out PageCount, out RecordCount);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }


        public static DataSet getAllCourseInfo_QQ254540457()
        {
            try
            {
                string strSql = "select * from CourseInfo_QQ254540457";
                return DBHelp.ExecuteDataSet(strSql, null);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }


    }
}
