Ejemplo n.º 1
0
        internal bool checkAdmin()
        {
            string     SQL = "select admin from Users where uID = @id";
            SqlCommand cmd = new SqlCommand();

            cmd.CommandText = SQL;
            cmd.Connection  = Starter.GetConnection();
            cmd.Parameters.Add(new SqlParameter("id", uID));
            SqlDataReader reader = cmd.ExecuteReader();

            reader.Read();

            try {
                return(reader.GetBoolean(0));
            } catch (Exception e) { }

            return(false);
        }
Ejemplo n.º 2
0
        //Statische Methoden, aufgerufen von der Starter-Klasse, damit alle Datenbank-Aufrufe über dieses Objekt in der
        //derselben Klasse gesammelt sind


        //bei Select * Abfrage gibt er folgende Reihenfolge aus: postID, uid, cid, date, content, tid, cid, name, tid, name, uid, username, pwHash, admin

        internal static Countries getAllCountries()
        {
            SqlCommand    cmd          = new SqlCommand("select c.cid, c.name, p.postID from Countries as c left join Posts as p on c.cid = p.cid", Starter.GetConnection());
            SqlDataReader reader       = cmd.ExecuteReader();
            Countries     allCountries = new Countries(); //initialisiere lehre Liste

            Country currentObject = new Country();

            currentObject.cID = 0;

            while (reader.Read())
            {
                if (currentObject.cID != reader.GetInt32(0))
                {
                    Country oneCountry = new Country();
                    currentObject = oneCountry;
                    allCountries.Add(currentObject);
                    currentObject.cID         = reader.GetInt32(0);
                    currentObject.countryName = reader.GetString(1);
                }

                try
                {
                    currentObject.postIDs.Add(reader.GetInt32(2));
                }
                catch (Exception e) {
                }
            }
            return(allCountries);
        }
Ejemplo n.º 3
0
        public Transport getTransport()
        {
            //Load transport from DB
            Transport  loadedTransport = new Transport();
            SqlCommand cmd             = new SqlCommand("select t.tid, t.name, p.postID from Transport as t left join Posts as p on t.tid = p.tid where t.tid = @id", Starter.GetConnection());

            cmd.Parameters.Add(new SqlParameter("id", transport.transportID));
            SqlDataReader reader = cmd.ExecuteReader();

            loadedTransport.transportID = 0;

            while (reader.Read())
            {
                if (loadedTransport.transportID != reader.GetInt32(0))
                {
                    loadedTransport.transportID   = reader.GetInt32(0);
                    loadedTransport.transportName = reader.GetString(1);
                }

                try
                {
                    loadedTransport.postIDs.Add(reader.GetInt32(2));
                }
                catch (Exception e)
                {
                }
            }
            return(loadedTransport);
        }
Ejemplo n.º 4
0
        public Country getCountry()
        {
            //Load country from DB
            Country    loadedCountry = new Country();
            SqlCommand cmd           = new SqlCommand("select c.cid, c.name, p.postID from Countries as c left join Posts as p on c.cid = p.cid where c.cid = @id", Starter.GetConnection());

            cmd.Parameters.Add(new SqlParameter("id", country.cID));
            SqlDataReader reader = cmd.ExecuteReader();

            loadedCountry.cID = 0;

            while (reader.Read())
            {
                if (loadedCountry.cID != reader.GetInt32(0))
                {
                    loadedCountry.cID         = reader.GetInt32(0);
                    loadedCountry.countryName = reader.GetString(1);
                }

                try
                {
                    loadedCountry.postIDs.Add(reader.GetInt32(2));
                }
                catch (Exception e)
                {
                }
            }
            return(loadedCountry);
        }
Ejemplo n.º 5
0
        public User getUser()
        {
            //Load user from DB
            User       loadedUser = new User();
            SqlCommand cmd        = new SqlCommand("select u.uid, u.username, p.postID from Users as u left join Posts as p on u.uid = p.uid where u.uid = @id", Starter.GetConnection());

            cmd.Parameters.Add(new SqlParameter("id", user.uID));
            SqlDataReader reader = cmd.ExecuteReader();

            loadedUser.uID = 0;

            while (reader.Read())
            {
                if (loadedUser.uID != reader.GetInt32(0))
                {
                    loadedUser.uID      = reader.GetInt32(0);
                    loadedUser.userName = reader.GetString(1);
                }

                try
                {
                    loadedUser.postIDs.Add(reader.GetInt32(2));
                }
                catch (Exception e) {
                }
            }
            return(loadedUser);
        }
Ejemplo n.º 6
0
        internal static Post getOnePost(int postID)
        {
            Post       onePost = new Post();
            SqlCommand cmd     = new SqlCommand("select * from Posts as p inner join Countries as c on p.cid = c.cid inner join Transport as t on p.tid = t.tid inner join Users as u on p.uid = u.uid where postID = @id", Starter.GetConnection());

            cmd.Parameters.Add(new SqlParameter("id", postID));
            SqlDataReader reader = cmd.ExecuteReader();

            while (reader.Read())
            {
                onePost = fillPostFromSQLDataReader(reader);
            }
            return(onePost);
        }
Ejemplo n.º 7
0
        internal static Posts getAllPosts()
        {
            SqlCommand    cmd      = new SqlCommand("select * from Posts as p inner join Countries as c on p.cid = c.cid inner join Transport as t on p.tid = t.tid inner join Users as u on p.uid = u.uid;", Starter.GetConnection());
            SqlDataReader reader   = cmd.ExecuteReader();
            Posts         allPosts = new Posts(); //initialisiere lehre Liste

            while (reader.Read())
            {
                Post onePost = fillPostFromSQLDataReader(reader);
                allPosts.Add(onePost);
            }
            return(allPosts);
        }
Ejemplo n.º 8
0
        internal static Transports getAllTransports()
        {
            SqlCommand    cmd           = new SqlCommand("select t.tid, t.name, p.postID from Transport as t left join Posts as p on t.tid = p.tid", Starter.GetConnection());
            SqlDataReader reader        = cmd.ExecuteReader();
            Transports    allTransports = new Transports(); //initialisiere lehre Liste

            Transport currentObject = new Transport();

            currentObject.transportID = 0;

            while (reader.Read())
            {
                if (currentObject.transportID != reader.GetInt32(0))
                {
                    Transport oneTransport = new Transport();
                    currentObject = oneTransport;
                    allTransports.Add(currentObject);
                    currentObject.transportID   = reader.GetInt32(0);
                    currentObject.transportName = reader.GetString(1);
                }


                try
                {
                    currentObject.postIDs.Add(reader.GetInt32(2));
                }
                catch (Exception e)
                {
                }
            }
            return(allTransports);
        }
Ejemplo n.º 9
0
        internal static Users getAllUsers()
        {
            SqlCommand    cmd      = new SqlCommand("select u.uid, u.username, p.postID from Users as u left join Posts as p on u.uid = p.uid", Starter.GetConnection());
            SqlDataReader reader   = cmd.ExecuteReader();
            Users         allUsers = new Users(); //initialisiere lehre Liste

            User currentObject = new User();

            currentObject.uID = 0;

            while (reader.Read())
            {
                if (currentObject.uID != reader.GetInt32(0))
                {
                    User oneUser = new User();
                    currentObject = oneUser;
                    allUsers.Add(currentObject);
                    currentObject.uID      = reader.GetInt32(0);
                    currentObject.userName = reader.GetString(1);
                }

                try
                {
                    currentObject.postIDs.Add(reader.GetInt32(2));
                }
                catch (Exception e) {
                }
            }
            return(allUsers);
        }