⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dviewteachplan.cs

📁 这是一个自动排课软件(包含源码,需求分析,详细设计).希望对你有所帮助.
💻 CS
字号:
using System;
using System.Data;
using System.Data.SqlClient;
using System.Collections;
using Entities;
using Search;

namespace DAL.SqlServer
{
    public class DViewTeachPlan : IDViewTeachPlan
    {
        #region 查询实体集合
        /// <summary>
        /// 根据查询对象构建过滤条件查询
        /// </summary>
        /// <param name="searcher">查询对象</param>
        /// <returns>实体类对象列表</returns>
        public ArrayList Select(ViewTeachPlanSearcher searcher)
        {
            ArrayList entities = new ArrayList();
            string connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
            using (SqlConnection conn = new SqlConnection(connectionString))
            {
                conn.Open();
                using (SqlCommand cmd = conn.CreateCommand())
                {
                    entities = Select(cmd, searcher);
                }
            }
            return entities;
        }
        /// <summary>
        /// 使用事务并且依据查询对象构建过滤条件查询
        /// </summary>
        /// <param name="connection">实现共享Command的对象</param>
        /// <param name="searcher">查询对象</param>
        /// <returns>实体类对象列表</returns>
        public ArrayList Select(IConnection connection, ViewTeachPlanSearcher searcher)
        {
            SqlCommand cmd = connection.Command as SqlCommand;
            return Select(cmd, searcher);
        }
        public ArrayList Select(SqlCommand command, ViewTeachPlanSearcher searcher)
        {
            string condition = string.Empty;
            command.Parameters.Clear();
            ArrayList entities = new ArrayList();
            if (searcher.ClassIDIsValid)
            {
                condition += " and Class_ID=@Class_ID_C";
                command.Parameters.Add(new SqlParameter("@Class_ID_C", searcher.ClassID));
            }
            if (searcher.TeachPlanIDIsValid)
            {
                condition += " and TeachPlan_ID=@TeachPlan_ID_C";
                command.Parameters.Add(new SqlParameter("@TeachPlan_ID_C", searcher.TeachPlanID));
            }
            if (searcher.CourseIDIsValid)
            {
                condition += " and Course_ID=@Course_ID_C";
                command.Parameters.Add(new SqlParameter("@Course_ID_C", searcher.CourseID));
            }
            if (searcher.TeacherIDIsValid)
            {
                condition += " and Teacher_ID=@Teacher_ID_C";
                command.Parameters.Add(new SqlParameter("@Teacher_ID_C", searcher.TeacherID));
            }
            if (searcher.BeginDateIsValid)
            {
                condition += " and begin_date=@begin_date_C";
                command.Parameters.Add(new SqlParameter("@begin_date_C", searcher.BeginDate));
            }
            if (searcher.EndDateIsValid)
            {
                condition += " and end_date=@end_date_C";
                command.Parameters.Add(new SqlParameter("@end_date_C", searcher.EndDate));
            }
            if (searcher.TimeplanIdIsValid)
            {
                condition += " and timeplan_id=@timeplan_id_C";
                command.Parameters.Add(new SqlParameter("@timeplan_id_C", searcher.TimeplanId));
            }
            if (searcher.ClassNameIsValid)
            {
                condition += " and Class_Name=@Class_Name_C";
                command.Parameters.Add(new SqlParameter("@Class_Name_C", searcher.ClassName));
            }
            if (searcher.CourseNameIsValid)
            {
                condition += " and Course_Name=@Course_Name_C";
                command.Parameters.Add(new SqlParameter("@Course_Name_C", searcher.CourseName));
            }
            if (searcher.CourseColorIsValid)
            {
                condition += " and Course_Color=@Course_Color_C";
                command.Parameters.Add(new SqlParameter("@Course_Color_C", searcher.CourseColor));
            }
            if (searcher.EmployeeNameIsValid)
            {
                condition += " and Employee_Name=@Employee_Name_C";
                command.Parameters.Add(new SqlParameter("@Employee_Name_C", searcher.EmployeeName));
            }
            if (searcher.TimePlanNameIsValid)
            {
                condition += " and TimePlan_Name=@TimePlan_Name_C";
                command.Parameters.Add(new SqlParameter("@TimePlan_Name_C", searcher.TimePlanName));
            }
            if (searcher.SundayAmIsValid)
            {
                condition += " and Sunday_Am=@Sunday_Am_C";
                command.Parameters.Add(new SqlParameter("@Sunday_Am_C", searcher.SundayAm));
            }
            if (searcher.SundayPmIsValid)
            {
                condition += " and Sunday_Pm=@Sunday_Pm_C";
                command.Parameters.Add(new SqlParameter("@Sunday_Pm_C", searcher.SundayPm));
            }
            if (searcher.MondayAmIsValid)
            {
                condition += " and Monday_Am=@Monday_Am_C";
                command.Parameters.Add(new SqlParameter("@Monday_Am_C", searcher.MondayAm));
            }
            if (searcher.MondayPmIsValid)
            {
                condition += " and Monday_Pm=@Monday_Pm_C";
                command.Parameters.Add(new SqlParameter("@Monday_Pm_C", searcher.MondayPm));
            }
            if (searcher.TuesdayAmIsValid)
            {
                condition += " and Tuesday_Am=@Tuesday_Am_C";
                command.Parameters.Add(new SqlParameter("@Tuesday_Am_C", searcher.TuesdayAm));
            }
            if (searcher.TuesdayPmIsValid)
            {
                condition += " and Tuesday_Pm=@Tuesday_Pm_C";
                command.Parameters.Add(new SqlParameter("@Tuesday_Pm_C", searcher.TuesdayPm));
            }
            if (searcher.WednesdayAmIsValid)
            {
                condition += " and Wednesday_Am=@Wednesday_Am_C";
                command.Parameters.Add(new SqlParameter("@Wednesday_Am_C", searcher.WednesdayAm));
            }
            if (searcher.WednesdayPmIsValid)
            {
                condition += " and Wednesday_Pm=@Wednesday_Pm_C";
                command.Parameters.Add(new SqlParameter("@Wednesday_Pm_C", searcher.WednesdayPm));
            }
            if (searcher.ThursdayAmIsValid)
            {
                condition += " and Thursday_Am=@Thursday_Am_C";
                command.Parameters.Add(new SqlParameter("@Thursday_Am_C", searcher.ThursdayAm));
            }
            if (searcher.ThursdayPmIsValid)
            {
                condition += " and Thursday_Pm=@Thursday_Pm_C";
                command.Parameters.Add(new SqlParameter("@Thursday_Pm_C", searcher.ThursdayPm));
            }
            if (searcher.FridayAmIsValid)
            {
                condition += " and Friday_Am=@Friday_Am_C";
                command.Parameters.Add(new SqlParameter("@Friday_Am_C", searcher.FridayAm));
            }
            if (searcher.FridayPmIsValid)
            {
                condition += " and Friday_Pm=@Friday_Pm_C";
                command.Parameters.Add(new SqlParameter("@Friday_Pm_C", searcher.FridayPm));
            }
            if (searcher.SaturdayAmIsValid)
            {
                condition += " and Saturday_Am=@Saturday_Am_C";
                command.Parameters.Add(new SqlParameter("@Saturday_Am_C", searcher.SaturdayAm));
            }
            if (searcher.SaturdayPmIsValid)
            {
                condition += " and Saturday_Pm=@Saturday_Pm_C";
                command.Parameters.Add(new SqlParameter("@Saturday_Pm_C", searcher.SaturdayPm));
            }
            if (condition != string.Empty)
            {
                condition = " where" + condition.Substring(4);
            }

            command.CommandText = "select * from ViewTeachPlan" + condition;
            return ExcuteSelectCommand(command);
        }
        /// <summary>
        /// 执行Command获取对象列表
        /// </summary>
        /// <param name="cmd">Command对象</param>
        /// <returns>实体类对象列表</returns>
        private ArrayList ExcuteSelectCommand(SqlCommand cmd)
        {
            ArrayList entities = new ArrayList();
            using (SqlDataReader dr = cmd.ExecuteReader())
            {
                while (dr.Read())
                {
                    ViewTeachPlan entity = DataReaderToEntity(dr);
                    entities.Add(entity);
                }
            }
            return entities;
        }
        /// <summary>
        /// 查询所有实体
        /// </summary>
        /// <returns>实体类对象列表</returns>
        public System.Collections.ArrayList Select()
        {
            ArrayList entities = new ArrayList();
            string connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
            using (SqlConnection conn = new SqlConnection(connectionString))
            {
                conn.Open();
                using (SqlCommand cmd = conn.CreateCommand())
                {
                    cmd.CommandText = "select * from ViewTeachPlan";
                    entities = ExcuteSelectCommand(cmd);
                }
                return entities;
            }
        }
        /// <summary>
        /// 使用事务查询查询所有实体
        /// </summary>
        /// <param name="connection">实现共享Command的对象</param>
        /// <param name="searcher">查询对象</param>
        /// <returns>实体类对象列表</returns>
        public ArrayList Select(IConnection connection)
        {
            ArrayList entities = new ArrayList();
            SqlCommand cmd = connection.Command as SqlCommand;
            cmd.Parameters.Clear();
            cmd.CommandText = "select * from ViewTeachPlan";
            return ExcuteSelectCommand(cmd);
        }
        #endregion


        /// <summary>
        /// 从DataReader中取出值生成实体对象
        /// </summary>
        /// <param name="searcher">查询对象</param>
        /// <returns>过滤条件字符串</returns>
        private ViewTeachPlan DataReaderToEntity(SqlDataReader dr)
        {
            ViewTeachPlan entity = new ViewTeachPlan();
            if (dr["Class_ID"] != System.DBNull.Value)
            {
                entity.ClassID = Convert.ToInt32(dr["Class_ID"]);
            }
            if (dr["TeachPlan_ID"] != System.DBNull.Value)
            {
                entity.TeachPlanID = Convert.ToInt32(dr["TeachPlan_ID"]);
            }
            if (dr["Course_ID"] != System.DBNull.Value)
            {
                entity.CourseID = Convert.ToInt32(dr["Course_ID"]);
            }
            if (dr["Teacher_ID"] != System.DBNull.Value)
            {
                entity.TeacherID = Convert.ToInt32(dr["Teacher_ID"]);
            }
            if (dr["begin_date"] != System.DBNull.Value)
            {
                entity.BeginDate = Convert.ToDateTime(dr["begin_date"]);
            }
            if (dr["end_date"] != System.DBNull.Value)
            {
                entity.EndDate = Convert.ToDateTime(dr["end_date"]);
            }
            if (dr["timeplan_id"] != System.DBNull.Value)
            {
                entity.TimeplanId = Convert.ToInt32(dr["timeplan_id"]);
            }
            if (dr["Class_Name"] != System.DBNull.Value)
            {
                entity.ClassName = dr["Class_Name"].ToString();
            }
            if (dr["Course_Name"] != System.DBNull.Value)
            {
                entity.CourseName = dr["Course_Name"].ToString();
            }
            if (dr["Course_Color"] != System.DBNull.Value)
            {
                entity.CourseColor = dr["Course_Color"].ToString();
            }
            if (dr["Employee_Name"] != System.DBNull.Value)
            {
                entity.EmployeeName = dr["Employee_Name"].ToString();
            }
            if (dr["TimePlan_Name"] != System.DBNull.Value)
            {
                entity.TimePlanName = dr["TimePlan_Name"].ToString();
            }
            if (dr["Sunday_Am"] != System.DBNull.Value)
            {
                entity.SundayAm = Convert.ToBoolean(dr["Sunday_Am"]);
            }
            if (dr["Sunday_Pm"] != System.DBNull.Value)
            {
                entity.SundayPm = Convert.ToBoolean(dr["Sunday_Pm"]);
            }
            if (dr["Monday_Am"] != System.DBNull.Value)
            {
                entity.MondayAm = Convert.ToBoolean(dr["Monday_Am"]);
            }
            if (dr["Monday_Pm"] != System.DBNull.Value)
            {
                entity.MondayPm = Convert.ToBoolean(dr["Monday_Pm"]);
            }
            if (dr["Tuesday_Am"] != System.DBNull.Value)
            {
                entity.TuesdayAm = Convert.ToBoolean(dr["Tuesday_Am"]);
            }
            if (dr["Tuesday_Pm"] != System.DBNull.Value)
            {
                entity.TuesdayPm = Convert.ToBoolean(dr["Tuesday_Pm"]);
            }
            if (dr["Wednesday_Am"] != System.DBNull.Value)
            {
                entity.WednesdayAm = Convert.ToBoolean(dr["Wednesday_Am"]);
            }
            if (dr["Wednesday_Pm"] != System.DBNull.Value)
            {
                entity.WednesdayPm = Convert.ToBoolean(dr["Wednesday_Pm"]);
            }
            if (dr["Thursday_Am"] != System.DBNull.Value)
            {
                entity.ThursdayAm = Convert.ToBoolean(dr["Thursday_Am"]);
            }
            if (dr["Thursday_Pm"] != System.DBNull.Value)
            {
                entity.ThursdayPm = Convert.ToBoolean(dr["Thursday_Pm"]);
            }
            if (dr["Friday_Am"] != System.DBNull.Value)
            {
                entity.FridayAm = Convert.ToBoolean(dr["Friday_Am"]);
            }
            if (dr["Friday_Pm"] != System.DBNull.Value)
            {
                entity.FridayPm = Convert.ToBoolean(dr["Friday_Pm"]);
            }
            if (dr["Saturday_Am"] != System.DBNull.Value)
            {
                entity.SaturdayAm = Convert.ToBoolean(dr["Saturday_Am"]);
            }
            if (dr["Saturday_Pm"] != System.DBNull.Value)
            {
                entity.SaturdayPm = Convert.ToBoolean(dr["Saturday_Pm"]);
            }
            return entity;
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -