日期:2014-05-17  浏览次数:20767 次

treeView递归计算总个数,求大神,在线等
数据库的大致结构是这样的
ID  Name  PID  Qty
每个都有自己的Qty 也就是下面的UnSetPriceQty ,现在我要计算每个父类下面所有子集的总个数怎么做,帮忙改下下面的代码就是ChildUnSetPriceQty 的数量。

比如
根目录(20)
    第一级目录(10)
        第二级目录(5)
        第二级目录(5)
    第一级目录(10)
           List<ProductCategoryTreeView> tvList = new List<ProductCategoryTreeView>();
                if (e.Result != null)
                {
                    foreach (ProductCategory productCategory in e.Result.Where(p => string.IsNullOrEmpty(p.ParentID)))
                    {
                        ProductCategoryTreeView treeViewInfo = new ProductCategoryTreeView();
                        treeViewInfo.ID = productCategory.ID;
                        treeViewInfo.Name = productCategory.Name;
                        treeViewInfo.ParentID = productCategory.ParentID;
                        treeViewInfo.ProductTypeID = productCategory.ProductTypeID;
                        treeViewInfo.UnSetPriceQty = productCategory.UnSetPriceQty;
                        //treeViewInfo.ChildUnSetPriceQty = e.Result.Where(x => x.ParentID == productCategory.ID).Sum(x => x.UnSetPriceQty);
                        this.AddProductCategoryItems(treeViewInfo, productCategory.ID, e.Result.ToList());