コード例 #1
0
ファイル: CategoryBL.cs プロジェクト: yoorke/pinshop
 public DataTable GetCategories()
 {
     CategoryDL categoryDL = new CategoryDL();
     return categoryDL.GetCategories();
 }
コード例 #2
0
ファイル: CategoryBL.cs プロジェクト: yoorke/pinshop
        /*public List<Category> GetNestedCategoriesList()
        {
            CategoryDL categoryDL = new CategoryDL();
            DataTable categoriesDT = categoryDL.GetCategories();

            List<Category> list = new List<Category>();
            list.Add(new Category((int)categoriesDT.Rows[0]["categoryID"], categoriesDT.Rows[0]["name"].ToString(), 0, categoriesDT.Rows[0]["url"].ToString(), categoriesDT.Rows[0]["imageUrl"].ToString()));
            Category temp = list[0];

            for (int i = 1; i < categoriesDT.Rows.Count; i++)
            {
                //while ((int)categoriesDT.Rows[i]["parentID"] == temp.CategoryID)
                if ((int)categoriesDT.Rows[i]["parentID"] == temp.CategoryID)
                {
                    if (temp.SubCategory == null)
                        temp.SubCategory = new List<Category>();

                    temp.SubCategory.Add(new Category((int)categoriesDT.Rows[i]["categoryID"], categoriesDT.Rows[i]["name"].ToString(), temp.CategoryID, categoriesDT.Rows[i]["url"].ToString(), categoriesDT.Rows[i]["imageUrl"].ToString()));

                }
                else
                {
                    if ((int)categoriesDT.Rows[i]["parentID"] > temp.CategoryID)
                    {

                        temp = temp.SubCategory[temp.SubCategory.Count - 1];
                        i--;
                    }
                    else
                    {
                        temp = list[0];
                        i--;
                    }
                }

            }

            return list[0].SubCategory;
        }*/
        /*public DataTable GetNestedCategoriesDataTable()
        {
            CategoryDL categoryDL = new CategoryDL();
            DataTable categoriesDT = categoryDL.GetCategories();
            int tempCategoryID = int.Parse(categoriesDT.Rows[0]["categoryID"].ToString());
            string baseString = "--";

            for (int i = 1; i < categoriesDT.Rows.Count; i++)
            {
                if (int.Parse(categoriesDT.Rows[i]["parentID"].ToString()) == tempCategoryID)
                    categoriesDT.Rows[i]["name"] = baseString + categoriesDT.Rows[i]["name"].ToString();
                else
                    if (int.Parse(categoriesDT.Rows[i]["parentID"].ToString()) > tempCategoryID)
                    {
                        tempCategoryID = int.Parse(categoriesDT.Rows[i-1]["categoryID"].ToString());
                        baseString += "--";
                        i--;
                    }
                    else
                    {
                        tempCategoryID = int.Parse(categoriesDT.Rows[0]["categoryID"].ToString());
                        baseString = "--";
                        i--;
                    }
            }

            return categoriesDT;
        }*/
        /*public List<Category> GetCategories2()
        {
            CategoryDL categoryDL = new CategoryDL();
            DataTable categoriesDT = categoryDL.GetCategories();
            int level = 1;

            List<Category> list = new List<Category>();
            list.Add(new Category((int)categoriesDT.Rows[0]["categoryID"], categoriesDT.Rows[0]["name"].ToString(), (int)categoriesDT.Rows[0]["parentID"], categoriesDT.Rows[0]["url"].ToString(), categoriesDT.Rows[0]["imageUrl"].ToString()));
            Category temp = list[0];

            for (int i = 1; i < categoriesDT.Rows.Count; i++)
            {
                for (int j = 0; j < categoriesDT.Rows.Count; j++)
                {
                    if ((int)categoriesDT.Rows[j]["parentID"] == temp.CategoryID)
                    {
                        if (temp.SubCategory == null)
                            temp.SubCategory = new List<Category>();
                        temp.SubCategory.Add(new Category((int)categoriesDT.Rows[j]["categoryID"], categoriesDT.Rows[j]["name"].ToString(), (int)categoriesDT.Rows[j]["parentID"], categoriesDT.Rows[j]["url"].ToString(), categoriesDT.Rows[j]["imageUrl"].ToString()));
                    }
                }
                if (level < 2)
                {
                    temp = temp.SubCategory[i - 1];
                    level++;
                }
                else
                {
                    if (i < 10)
                        temp = list[0].SubCategory[i - 1];
                    //level--;
                }
            }

            return list[0].SubCategory;
        }*/
        /*public List<Category> GetCategories3()
        {
            CategoryDL categoryDL = new CategoryDL();
            DataTable categoriesDT = categoryDL.GetCategories();

            List<Category> list = new List<Category>();

            for (int i = 0; i < categoriesDT.Rows.Count; i++)
            {
                if ((int)categoriesDT.Rows[i]["parentID"] == 2)
                    list.Add(new Category((int)categoriesDT.Rows[i]["categoryID"], categoriesDT.Rows[i]["name"].ToString(), (int)categoriesDT.Rows[i]["parentID"], categoriesDT.Rows[i]["url"].ToString(), categoriesDT.Rows[i]["imageUrl"].ToString()));
            }

            for (int i = 0; i < list.Count; i++)
                for (int j = 0; j < categoriesDT.Rows.Count; j++)
                    if (list[i].CategoryID == (int)categoriesDT.Rows[j]["parentID"])
                    {
                        if (list[i].SubCategory == null)
                            list[i].SubCategory = new List<Category>();
                        list[i].SubCategory.Add(new Category((int)categoriesDT.Rows[j]["categoryID"], categoriesDT.Rows[j]["name"].ToString(), (int)categoriesDT.Rows[j]["parentID"], categoriesDT.Rows[j]["url"].ToString(), categoriesDT.Rows[j]["imageUrl"].ToString()));
                    }

            return list;
        }*/
        public List<Category> GetNestedCategoriesList()
        {
            CategoryDL categoryDL = new CategoryDL();
            DataTable categoriesDT = categoryDL.GetCategories("sortOrder");

            return GetCategoriesList(categoriesDT, 1);
        }