Example #1
0
        public List <User> GetUsers()
        {
            DatabasePackage dbPackage = new DatabasePackage(_ConnectionString);
            List <User>     users     = new List <User>();
            SqlDataReader   reader    = null;

            try
            {
                dbPackage.CommandText = "Select ID, Name, Password From User Order By Name";
                reader = dbPackage.GetReader();

                while (reader.Read())
                {
                    User user = new User();

                    user.ID       = dbPackage.FieldToInt(reader["ID"]);
                    user.Name     = dbPackage.FieldToString(reader["Name"]);
                    user.Password = dbPackage.FieldToString(reader["Password"]);

                    users.Add(user);
                }
            }
            catch (DataAccessException ex)
            {
                throw new DataLayerException("Collection could not populated.", ex);
            }
            catch (Exception ex)
            {
                throw new DataLayerException("Collection could not populated.", ex);
            }
            finally
            {
                if (reader != null)
                {
                    reader.Close();
                }

                dbPackage.CloseConnection();
            }

            return(users);
        }
Example #2
0
        public User GeUserByID(int id)
        {
            DatabasePackage dbPackage = new DatabasePackage(_ConnectionString);
            SqlDataReader   reader    = null;

            try
            {
                dbPackage.CommandText = "Select ID, Name, Password From User Where ID = " + id;
                reader = dbPackage.GetReader();

                reader.Read();

                User user = new User
                {
                    ID       = id,
                    Name     = dbPackage.FieldToString(reader["Name"]),
                    Password = dbPackage.FieldToString(reader["Password"])
                };

                return(user);
            }
            catch (DataAccessException ex)
            {
                throw new DataLayerException("Unable to retrieve data.", ex);
            }
            catch (Exception ex)
            {
                throw new DataLayerException("Unable to retrieve data.", ex);
            }
            finally
            {
                if (reader != null)
                {
                    reader.Close();
                }
            }
        }
Example #3
0
        public List <Book> GetIssuedBooks()
        {
            DatabasePackage dbPackage = new DatabasePackage(_ConnectionString);
            List <Book>     books     = new List <Book>();
            SqlDataReader   reader    = null;

            try
            {
                dbPackage.CommandText = "Select ID, Name, IssueDate, MemberID From Book Where MemberID is Not Null Order By Name";
                reader = dbPackage.GetReader();

                while (reader.Read())
                {
                    Book book = new Book();

                    book.ID        = dbPackage.FieldToInt(reader["ID"]);
                    book.Name      = dbPackage.FieldToString(reader["Name"]);
                    book.IssueDate = dbPackage.FieldToDateTime(reader["IssueDate"]);
                    book.MemberID  = dbPackage.FieldToInt(reader["MemberID"]);

                    books.Add(book);
                }
            }
            catch (DataAccessException ex)
            {
                throw new DataLayerException("Collection could not populated.", ex);
            }
            catch (Exception ex)
            {
                throw new DataLayerException("Collection could not populated.", ex);
            }
            finally
            {
                if (reader != null)
                {
                    reader.Close();
                }

                dbPackage.CloseConnection();
            }

            return(books);
        }
Example #4
0
        public List <Member> GetNoBookIssuedMembers()
        {
            DatabasePackage dbPackage = new DatabasePackage(_ConnectionString);
            List <Member>   members   = new List <Member>();
            SqlDataReader   reader    = null;

            try
            {
                dbPackage.CommandText = "Select ID, Name From Member Where ID Not In (Select MemberID From Book Where MemberID Is Null) Order By Name";
                reader = dbPackage.GetReader();

                while (reader.Read())
                {
                    Member member = new Member();

                    member.ID   = dbPackage.FieldToInt(reader["ID"]);
                    member.Name = dbPackage.FieldToString(reader["Name"]);

                    members.Add(member);
                }
            }
            catch (DataAccessException ex)
            {
                throw new DataLayerException("Collection could not populated.", ex);
            }
            catch (Exception ex)
            {
                throw new DataLayerException("Collection could not populated.", ex);
            }
            finally
            {
                if (reader != null)
                {
                    reader.Close();
                }

                dbPackage.CloseConnection();
            }

            return(members);
        }
Example #5
0
        public Book GetBookByID(int id)
        {
            DatabasePackage dbPackage = new DatabasePackage(_ConnectionString);
            SqlDataReader   reader    = null;

            try
            {
                dbPackage.CommandText = "Select ID, Name, IssueDate, MemberID From Book Where ID = " + id;
                reader = dbPackage.GetReader();

                reader.Read();

                Book book = new Book
                {
                    ID        = id,
                    Name      = dbPackage.FieldToString(reader["Name"]),
                    IssueDate = dbPackage.FieldToDateTime(reader["IssueDate"]),
                    MemberID  = dbPackage.FieldToInt(reader["MemberID"])
                };

                return(book);
            }
            catch (DataAccessException ex)
            {
                throw new DataLayerException("Unable to retrieve data.", ex);
            }
            catch (Exception ex)
            {
                throw new DataLayerException("Unable to retrieve data.", ex);
            }
            finally
            {
                if (reader != null)
                {
                    reader.Close();
                }
            }
        }