コード例 #1
0
        public Categorie[] AlleCategorienOpvragen()
        {
            List <Categorie> categorieLijst = new List <Categorie>();
            string           query;

            Connect();
            try
            {
                query = "SELECT COUNT(*) 'aantalCategorien' FROM Categorie";
                using (command = new SqlCommand(query, SQLcon))
                {
                    reader = command.ExecuteReader();

                    while (reader.Read())
                    {
                        categorieArray = new Categorie[Convert.ToInt32(reader["aantalCategorien"])];
                    }
                }
            }
            catch (SqlException e)
            {
                throw new FoutBijUitvoerenQueryException(e.Message);
            }
            Close();

            Connect();
            try
            {
                query = "SELECT * FROM Categorie";
                using (command = new SqlCommand(query, SQLcon))
                {
                    reader = command.ExecuteReader();

                    while (reader.Read())
                    {
                        Categorie cat = new Categorie();
                        cat.Naam   = reader["Naam"].ToString();
                        cat.ID     = Convert.ToInt32(reader["ID"]);
                        cat.Parent = Convert.ToInt32(reader["ParentCategorie"]);
                        categorieLijst.Add(cat);
                    }
                }
            }
            catch (SqlException e)
            {
                throw new FoutBijUitvoerenQueryException(e.Message);
            }
            Close();

            for (int i = 0; i < categorieLijst.Count; i++)
            {
                if (!categorieArray.Contains(categorieLijst[i]))
                {
                    int a = i;
Start:
                    if (categorieArray[a] == null)
                    {
                        categorieArray[a] = categorieLijst[i];
                        CheckVoorSubCategorien(categorieLijst, categorieArray, categorieArray[a]);
                    }
                    else
                    {
                        a++;
                        goto Start;
                    }
                }
            }
            return(categorieArray);
        }