예제 #1
0
        public List <TempClassSchedule> GetAllClassSchedulesByDeparmentId(int departmentId, int courseId)
        {
            List <TempClassSchedule> scheduleList = new List <TempClassSchedule>();

            Query   = "SELECT * FROM ScheduleOfClass WHERE DepartmentId='" + departmentId + "' AND CourseId='" + courseId + "' AND AllocationStatus='" + 1 + "'";
            Command = new SqlCommand(Query, Connection);
            Connection.Open();
            Reader = Command.ExecuteReader();
            while (Reader.Read())
            {
                TempClassSchedule schedule = new TempClassSchedule
                {
                    DepartmentId = Convert.ToInt32(Reader["DepartmentId"].ToString()),
                    CourseCode   = Reader["Code"].ToString(),
                    CourseName   = Reader["Name"].ToString(),
                    RoomNo       = Reader["Room_Name"].ToString(),
                    DayName      = Reader["Day_Name"].ToString(),
                    StartTime    = Convert.ToDateTime(Reader["StartTime"].ToString()),
                    EndTime      = Convert.ToDateTime(Reader["EndTime"].ToString()),
                    Status       = Convert.ToBoolean(Reader["AllocationStatus"])
                };

                scheduleList.Add(schedule);
            }

            Reader.Close();
            Connection.Close();
            return(scheduleList);
        }
        public IEnumerable <TempClassSchedule> GetAllClassSchedulesByDeparmentId(int departmentId, int courseId)
        {
            try
            {
                List <TempClassSchedule> scheduleList = new List <TempClassSchedule>();
                CommandObj.CommandText = "SELECT * FROM ScheduleOfClass WHERE DepartmentId='" + departmentId + "' AND CourseId='" + courseId + "' AND AllocationStatus='" + 1 + "'";
                ConnectionObj.Open();
                SqlDataReader reader = CommandObj.ExecuteReader();
                while (reader.Read())
                {
                    TempClassSchedule schedule = new TempClassSchedule
                    {
                        DepartmentId = Convert.ToInt32(reader["DepartmentId"].ToString()),
                        CourseCode   = reader["Code"].ToString(),
                        CourseName   = reader["Name"].ToString(),
                        RoomName     = reader["Room_Name"].ToString(),
                        DayName      = reader["Day_Name"].ToString(),
                        StartTime    = Convert.ToDateTime(reader["StartTime"].ToString()),
                        EndTime      = Convert.ToDateTime(reader["EndTime"].ToString()),
                        Status       = Convert.ToBoolean(reader["AllocationStatus"])
                    };

                    scheduleList.Add(schedule);
                }

                reader.Close();
                //ConnectionObj.Close();
                return(scheduleList);
            }
            catch (Exception exception)
            {
                throw new Exception("Unable to collect class schedule", exception);
            }
            finally
            {
                ConnectionObj.Close();
                CommandObj.Dispose();
            }
        }