Ejemplo n.º 1
0
        public static TaxCategorySelectionState[] GetSelectedCategoriesByParentCategoryId(int catId, string taxID)
        {
            var res = new List <TaxCategorySelectionState>();

            using (var db = new SQLDataAccess())
            {
                db.cmd.CommandText =
                    @"SELECT [Catalog].[Category].[CategoryId] 
                        FROM  [Catalog].[Category] 
                            inner join [Catalog].[TaxSelectedCategories] 
                                on [Category].[ID] = [TaxSelectedCategories].[CategoryID] 
                        WHERE [Catalog].[Category].[ParentCategory] = @catID AND [Catalog].[Category].[CategoryId] <> @catId and [TaxID] = @TaxID";
                db.cmd.CommandType = CommandType.Text;
                db.cmd.Parameters.Clear();
                db.cmd.Parameters.AddWithValue("@catID", catId);
                db.cmd.Parameters.AddWithValue("@TaxID", taxID);

                db.cnOpen();

                using (var reader = db.cmd.ExecuteReader())
                    while (reader.Read())
                    {
                        var c = new Category {
                            CategoryId = SQLDataHelper.GetInt(reader, "CategoryId"), ParentCategoryId = catId
                        };

                        var cs = new TaxCategorySelectionState {
                            Category = c, Full = false
                        };

                        TaxCategorySelectionState[] subCats = GetSelectedCategoriesByParentCategoryId(c.CategoryId, taxID);

                        res.Add(cs);
                        res.AddRange(subCats);
                    }

                db.cnClose();
            }


            return(res.ToArray());
        }
Ejemplo n.º 2
0
        public static TaxCategorySelectionState[] GetSelectedCategoriesByParentCategoryId(int catId, string taxID)
        {
            var res = new List<TaxCategorySelectionState>();

            using (var db = new SQLDataAccess())
            {
                db.cmd.CommandText =
                    @"SELECT [Catalog].[Category].[CategoryId]
                        FROM  [Catalog].[Category]
                            inner join [Catalog].[TaxSelectedCategories]
                                on [Category].[ID] = [TaxSelectedCategories].[CategoryID]
                        WHERE [Catalog].[Category].[ParentCategory] = @catID AND [Catalog].[Category].[CategoryId] <> @catId and [TaxID] = @TaxID";
                db.cmd.CommandType = CommandType.Text;
                db.cmd.Parameters.Clear();
                db.cmd.Parameters.AddWithValue("@catID", catId);
                db.cmd.Parameters.AddWithValue("@TaxID", taxID);

                db.cnOpen();

                using (var reader = db.cmd.ExecuteReader())
                    while (reader.Read())
                    {
                        var c = new Category { CategoryId = SQLDataHelper.GetInt(reader, "CategoryId"), ParentCategoryId = catId };

                        var cs = new TaxCategorySelectionState { Category = c, Full = false };

                        TaxCategorySelectionState[] subCats = GetSelectedCategoriesByParentCategoryId(c.CategoryId, taxID);

                        res.Add(cs);
                        res.AddRange(subCats);
                    }

                db.cnClose();
            }

            return res.ToArray();
        }