//
        // Methods
        //
        /// <summary>
        /// Adds categories recursivly and correctly nested to the ComboBox.
        /// </summary>
        /// <param name="category"></param>
        /// <param name="depth"></param>
        private void AddCategoryToComboboxRecursive(Category category, int depth)
        {
            string prefix = null;
            for (int i = 0; i < depth; i++)
            {
                prefix += "   ";
            }

            ComboBoxItem item = new ComboBoxItem();
            item.Text = prefix + (depth > 0 ? "-" : null) + category.Title;
            item.Value = category;

            comboBoxCategories.Items.Add(item);

            List<Category> subcategories = category.GetSubcategories();
            foreach (Category subcategory in subcategories)
            {
                AddCategoryToComboboxRecursive(subcategory, depth + 1);
            }
        }
        private void comboBoxCategories_SelectedIndexChanged(object sender, EventArgs e)
        {
            ComboBox cb = (ComboBox) sender;
            ComboBoxItem item = (ComboBoxItem)cb.SelectedItem;

            currentCategory = item.Value as Category;
            ReloadDownloadListView();
        }
        /// <summary>
        /// Gets an category based on the given Id. Returns NULL when the category is not found.
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static Category GetById(int id)
        {
            Category category = null;

            Database db = new Database();

            try
            {
                db.CreateCommand("SELECT * FROM files_categories WHERE Id = :Id");
                db.AddParameter("Id", id);

                db.OpenConnection();
                db.ExecuteCommand();

                OracleDataReader dr = db.DataReader;

                while (dr.Read())
                {
                    string title = dr.GetValueByColumn<string>("Title");
                    int parentId = dr.GetValueByColumn<int>("files_categories_id");

                    category = new Category(id, title, parentId);
                }
            }
            finally
            {
                db.CloseConnection();
            }

            return category;
        }
        /// <summary>
        /// Correctly inserts the file into the database.
        /// </summary>
        /// <param name="filename"></param>
        /// <param name="title"></param>
        /// <param name="size"></param>
        /// <param name="description"></param>
        /// <param name="user"></param>
        /// <param name="category"></param>
        /// <param name="privacy"></param>
        /// <returns></returns>
        public static bool Insert(string filename, string title, long size, string description, User user, Category category, Privacy privacy)
        {
            Database db = new Database();
            try
            {
                db.CreateCommand(
                    "INSERT INTO files(filename, title, filesize, description, users_id, files_categories_id, private, active) VALUES(:filename, :title, :filesize, :description, :users_id, :files_categories_id, :private, 1)");
                db.AddParameter("filename", filename);
                db.AddParameter("title", title);
                db.AddParameter("filesize", size);
                db.AddParameter("description", description);
                db.AddParameter("users_id", user.Id);

                if (category != null)
                {
                    db.AddParameter("files_categories_id", category.Id);
                }
                else
                {
                    db.AddParameter("files_categories_id", DBNull.Value);
                }

                if (privacy == Privacy.@private)
                {
                    db.AddParameter("private", 1);
                }
                else
                {
                    db.AddParameter("private", DBNull.Value);
                }
                db.OpenConnection();
                db.ExecuteCommand();
            }
            finally
            {
                db.CloseConnection();
            }

            return true;
        }