예제 #1
0
        public IList <OM_ProductInfo> GetProductList(string cipher, string CardCode, string searchKey, int pageIndex)
        {
            int _currentProductListCount = 0;
            PageListParameter <OM_Product, string> parameter = new PageListParameter <OM_Product, string>();

            parameter.whereLambda = s => ((s.ItemCode.Contains(searchKey.ToUpper()) || s.ItemName.Contains(searchKey)) &&
                                          (s.ParentId == null || s.ParentId == s.ItemCode) & s.IsDel == false);

            if (!string.IsNullOrWhiteSpace(searchKey))
            {
                parameter.whereLambda = s => ((s.ItemCode.Contains(searchKey.ToUpper()) || s.ItemName.Contains(searchKey)) & s.IsDel == false);
            }

            parameter.pageIndex     = pageIndex;
            parameter.orderByLambda = s => s.ItemCode;
            parameter.pageSize      = 100;

            IList <OM_ProductInfo> result = new List <OM_ProductInfo>();
            var productList = orderManger.GetProductList(parameter, out _currentProductListCount);

            var user = userManager.GetUser(s => s.Account == CardCode);

            //减少递归读取数据库次数
            if (productList != null || productList.Count > 0)
            {
                StaticResource.UserProductPrices = orderManger.GetProducePricetList(s => user.Guid.Trim().ToLower() == s.User_Guid.Trim().ToLower());
            }

            foreach (var item in productList)
            {
                string price = null;

                List <OM_ProductInfo> children = orderManger.GetChildProductRecursion(item.CardCode, item.ItemCode, user.Guid);

                // 说明是最终产品节点
                if (children == null || children.Count == 0)
                {
                    // orderManger.GetCurrentProducePriceList(item.ItemCode, user.Guid).Select(a => a.Price.ToString("0.00")).FirstOrDefault();
                    var exist = StaticResource.UserProductPrices.Find(s => s.Product_ItemCode == item.ItemCode);
                    if (exist != null)
                    {
                        price = exist.Price.ToString("0.00");
                    }
                }
                OM_ProductInfo product = new OM_ProductInfo();
                product.ItemName    = item.ItemName;
                product.ItemCode    = item.ItemCode;
                product.Price       = price;
                product.ItemStandar = item.ItemStandard == null ? "Empty" : item.ItemStandard;
                product.ItemUnit    = item.ItemUnit == null ? "Empty" : item.ItemUnit;
                product.ChildNode   = children;
                result.Add(product);
            }

            return(result);
        }
예제 #2
0
        public List <OM_ProductInfo> GetChildProductRecursion(string cardCode, string itemCode, string userGuid)
        {
            //&& a.ParentId!=a.ItemCode 把自己排除
            var result = DbRepository.GetList <OM_Product>(a => a.CardCode == cardCode && a.ParentId == itemCode && a.ParentId != a.ItemCode && a.IsDel == false);

            if (result == null || result.Count == 0)
            {
                return(null);
            }
            else
            {
                var infos = new List <OM_ProductInfo>();
                foreach (var item in result)
                {
                    string price = null;
                    var    nodes = GetChildProductRecursion(item.CardCode, item.ItemCode, userGuid);

                    if (nodes == null || nodes.Count == 0)
                    {
                        var exist = StaticResource.UserProductPrices.Find(s => s.Product_ItemCode == item.ItemCode);  //GetCurrentProducePriceList(item.ItemCode, userGuid).Select(a => a.Price.ToString("0.00")).FirstOrDefault();
                        if (exist != null)
                        {
                            price = exist.Price.ToString("0.00");
                        }
                    }

                    OM_ProductInfo product = new OM_ProductInfo();
                    product.Price       = price;
                    product.ItemCode    = item.ItemCode;
                    product.ItemName    = item.ItemName;
                    product.ItemStandar = item.ItemStandard;
                    product.ItemUnit    = item.ItemUnit;
                    product.ChildNode   = nodes;
                    infos.Add(product);
                }
                return(infos);
            }
        }