Exemple #1
0
        public StudentClassEnrolmentRepository(string ConnectionString)
        {
            this._studentRepo     = new StudentRepository(ConnectionString);
            this._schoolClassRepo = new SchoolClassRepository(ConnectionString);

            using (SqlConnection connection = new SqlConnection(ConnectionString))
            {
                using (SqlCommand sqlCommand = new SqlCommand())
                {
                    sqlCommand.Connection  = connection;
                    sqlCommand.CommandType = CommandType.Text;
                    sqlCommand.CommandText = sql;
                    sqlCommand.Connection.Open();
                    SqlDataReader dataReader = sqlCommand.ExecuteReader();
                    if (dataReader.HasRows)
                    {
                        while (dataReader.Read())
                        {
                            StudentClassEnrolment sce = dataReaderToEnrolment(dataReader);
                            if (sce != null)
                            {
                                if ((sce.Student != null) && (sce.Class != null))
                                {
                                    // add entry by student Id
                                    if (!_enrolmentsByStudentID.ContainsKey(sce.Student.iStudentID))
                                    {
                                        _enrolmentsByStudentID.Add(sce.Student.iStudentID, new List <StudentClassEnrolment>());
                                    }
                                    _enrolmentsByStudentID[sce.Student.iStudentID].Add(sce);

                                    // add entry by class id
                                    if (!_enrolmentsByClassID.ContainsKey(sce.Class.iClassID))
                                    {
                                        _enrolmentsByClassID.Add(sce.Class.iClassID, new List <StudentClassEnrolment>());
                                    }
                                    _enrolmentsByClassID[sce.Class.iClassID].Add(sce);

                                    // add to general list
                                    _allEnrolments.Add(sce);
                                }
                            }
                        }
                    }
                    sqlCommand.Connection.Close();
                }
            }
        }
Exemple #2
0
        public TeacherAssignmentRepository(string ConnectionString)
        {
            this._staffRepo       = new StaffRepository(ConnectionString);
            this._schoolClassRepo = new SchoolClassRepository(ConnectionString);

            using (SqlConnection connection = new SqlConnection(ConnectionString))
            {
                // Class table
                using (SqlCommand sqlCommand = new SqlCommand())
                {
                    sqlCommand.Connection  = connection;
                    sqlCommand.CommandType = CommandType.Text;
                    sqlCommand.CommandText = sql_Class;
                    sqlCommand.Connection.Open();
                    SqlDataReader dataReader = sqlCommand.ExecuteReader();
                    if (dataReader.HasRows)
                    {
                        while (dataReader.Read())
                        {
                            int istaffid = Parsers.ParseInt(dataReader["iDefault_StaffID"].ToString().Trim());
                            int iclassid = Parsers.ParseInt(dataReader["iClassID"].ToString().Trim());

                            if ((istaffid > 0) && (iclassid > 0))
                            {
                                // Add the class if it doesn't already exist
                                if (!_classIdsWithAllTeachers.ContainsKey(iclassid))
                                {
                                    _classIdsWithAllTeachers.Add(iclassid, new List <int>());
                                }

                                // Add the teacher, if they don't already exist (there will be duplicates in SchoolLogic)
                                if (!_classIdsWithAllTeachers[iclassid].Contains(istaffid))
                                {
                                    _classIdsWithAllTeachers[iclassid].Add(istaffid);
                                }
                            }
                        }
                    }
                    sqlCommand.Connection.Close();
                }

                // Resources table
                using (SqlCommand sqlCommand = new SqlCommand())
                {
                    sqlCommand.Connection  = connection;
                    sqlCommand.CommandType = CommandType.Text;
                    sqlCommand.CommandText = sql_Resource;
                    sqlCommand.Connection.Open();
                    SqlDataReader dataReader = sqlCommand.ExecuteReader();
                    if (dataReader.HasRows)
                    {
                        while (dataReader.Read())
                        {
                            int istaffid = Parsers.ParseInt(dataReader["iStaffID"].ToString().Trim());
                            int iclassid = Parsers.ParseInt(dataReader["iClassID"].ToString().Trim());

                            if ((istaffid > 0) && (iclassid > 0))
                            {
                                // Add the class if it doesn't already exist
                                if (!_classIdsWithAllTeachers.ContainsKey(iclassid))
                                {
                                    _classIdsWithAllTeachers.Add(iclassid, new List <int>());
                                }

                                // Add the teacher, if they don't already exist (there will be duplicates in SchoolLogic)
                                if (!_classIdsWithAllTeachers[iclassid].Contains(istaffid))
                                {
                                    _classIdsWithAllTeachers[iclassid].Add(istaffid);
                                }
                            }
                        }
                    }
                    sqlCommand.Connection.Close();
                }
            }
        }