 using System;
using System.Data;
using System.Configuration;
using core.BusinessObject;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Collections;
/// <summary>
/// courseNameDataAccess 的摘要说明
/// </summary>

namespace core.DataAccessLayer
{
    public class courseNameDataAccess
    {
        private static readonly string _connectionString = ConfigurationManager.AppSettings["GlobalConnectionString"];

        public courseNameDataAccess()
        {
            //
            // TODO: 在此处添加构造函数逻辑
            //
        }
       

        public static List<Course> selectTeacherName()
        {
            List<Course> objcourse = new List<Course>();
            SqlConnection con = new SqlConnection(_connectionString);

            SqlCommand cmd = new SqlCommand();
            cmd.Connection = con;
            cmd.CommandText = "select teacherName from teacher";

            using (con)
            {
                con.Open();
                SqlDataReader reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    objcourse.Add(new Course((string)reader["teacherName"],1));
                }

            }
            return objcourse;
        }

        public static List<Course> selectDifficultFactor()
        {
            List<Course> objcourse = new List<Course>();
            SqlConnection con = new SqlConnection(_connectionString);

            SqlCommand cmd = new SqlCommand();
            cmd.Connection = con;
            cmd.CommandText = "select difficultFactor from subjectStoreRoom";

            using (con)
            {
                con.Open();
                SqlDataReader reader = cmd.ExecuteReader();

                while (reader.Read())
                {
                    int i = 0;
                    for (; i < objcourse.Count; i++)
                    {
                        if (objcourse[i].difficultFactor.ToString().Equals(reader["difficultFactor"].ToString()))
                            break;
                    }
                    if (i < objcourse.Count)
                    {
                        continue;
                    }
                    else
                    {
                        if (reader["difficultFactor"].ToString() == null || reader["difficultFactor"].ToString().Equals(""))
                        {
                            continue;
                        }
                        else
                        {
                            objcourse.Add(new Course((string)reader["difficultFactor"], 3));
                        }
                    }
                }
                while (reader.Read())
                {
                    //if(objcourse.)
                    //{
                    //    continue;
                    //}
                    //else
                    {
                    
                    }
                }

            }
            return objcourse;
        }

        public static List<Course> selectThemeType()
        {
            List<Course> objcourse = new List<Course>();
            SqlConnection con = new SqlConnection(_connectionString);

            SqlCommand cmd = new SqlCommand();
            cmd.Connection = con;
            cmd.CommandText = "select themeType from theme";

            using (con)
            {
                con.Open();
                SqlDataReader reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    objcourse.Add(new Course((string)reader["themeType"],2));
                }

            }
            return objcourse;
        }

        public static List<Course> selectCourseChapter()
        {
            List<Course> objcourse = new List<Course>();
            SqlConnection con = new SqlConnection(_connectionString);

            SqlCommand cmd = new SqlCommand();
            cmd.Connection = con;
            cmd.CommandText = "SELECT DISTINCT courseChapter FROM subjectStoreRoom";

            using (con)
            {
                con.Open();
                SqlDataReader reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    objcourse.Add(new Course((int)reader["courseChapter"]));
                }
            }
            return objcourse;
        }

        public static List<Course> selectCourseName()
        {
            List<Course> objcourse = new List<Course>();
            SqlConnection con = new SqlConnection(_connectionString);

            SqlCommand cmd = new SqlCommand();
            cmd.Connection = con;
            cmd.CommandText = "SELECT courseName FROM course";

            using (con)
            {
                con.Open();
                SqlDataReader reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    objcourse.Add(new Course((string)reader["courseName"],0));
                }

            }
            return objcourse;
        }

    }
}
