/// <summary>
 /// 获得满足条件的所有产品的库存
 /// </summary>
 /// <param name="localName"></param>
 /// <param name="localType"></param>
 /// <param name="searchKey"></param>
 /// <param name="storageNum"></param>
 /// <returns></returns>
 public int GetAllNum(string localName, string localType, string searchKey, string storageNum)
 {
     LocalProductEntity entity = new LocalProductEntity();
     if (!storageNum.IsEmpty())
     {
         entity.Where("StorageNum", ECondition.Eth, storageNum);
     }
     if (!localType.IsEmpty())
     {
         entity.Where("LocalType", ECondition.Eth, localType);
     }
     if (!localName.IsEmpty())
     {
         entity.Where("LocalName", ECondition.Like, "%" + localName + "%");
         entity.Or("LocalNum", ECondition.Like, "%" + localName + "%");
     }
     if (!searchKey.IsEmpty())
     {
         entity.Begin<LocalProductEntity>()
          .Where<LocalProductEntity>("ProductName", ECondition.Like, "%" + searchKey + "%")
          .Or<LocalProductEntity>("ProductNum", ECondition.Like, "%" + searchKey + "%")
          .Or<LocalProductEntity>("BarCode", ECondition.Like, "%" + searchKey + "%")
          .End<LocalProductEntity>();
     }
     entity.IncludeNum(true);
     int allNum = 0;
     try
     {
         allNum = this.LocalProduct.Sum<int>(entity);
     }
     catch (Exception e)
     {
         allNum = 0;
         log.Info(e.Message);
     }
     return allNum;
 }
        public ActionResult StockBillList()
        {
            string searchKey = WebUtil.GetFormValue<string>("ProductName", string.Empty);
            string localName = WebUtil.GetFormValue<string>("LocalName", string.Empty);
            string localType = WebUtil.GetFormValue<string>("LocalType", string.Empty);
            int pageIndex = WebUtil.GetFormValue<int>("pageIndex", 0);
            int pageSize = WebUtil.GetFormValue<int>("pageSize", 0);
            string storageNum = this.DefaultStore;

            LocalProductProvider provider = new LocalProductProvider();
            LocalProductEntity entity = new LocalProductEntity();

            if (!localType.IsEmpty())
            {
                entity.Where("LocalType", ECondition.Eth, localType);
            }
            if (storageNum.IsNotNull())
            {
                entity.Where("StorageNum", ECondition.Eth, storageNum);
            }
            if (!localName.IsEmpty())
            {
                entity.Where("LocalName", ECondition.Like, "%" + localName + "%");
                entity.Or("LocalNum", ECondition.Like, "%" + localName + "%");
            }
            if (!searchKey.IsEmpty())
            {
                entity.Begin<LocalProductEntity>()
                 .Where<LocalProductEntity>("ProductName", ECondition.Like, "%" + searchKey + "%")
                 .Or<LocalProductEntity>("ProductNum", ECondition.Like, "%" + searchKey + "%")
                 .Or<LocalProductEntity>("BarCode", ECondition.Like, "%" + searchKey + "%")
                 .End<LocalProductEntity>();
            }
            PageInfo pageInfo = new PageInfo() { PageIndex = pageIndex, PageSize = pageSize };
            List<LocalProductEntity> listResult = provider.GetList(entity, ref pageInfo);
            int allNum = provider.GetAllNum(localName, localType, searchKey, storageNum);
            double allTotalPrice = provider.GetAllTotalPrice(localName, localType, searchKey, storageNum);
            if (!listResult.IsNullOrEmpty())
            {
                listResult.ForEach(a =>
                {
                    a.TotalPrice = a.Num * a.AvgPrice;
                });
            }
            string json = ConvertJson.ListToJson<LocalProductEntity>(listResult, "List");
            this.ReturnJson.AddProperty("Data", new JsonObject(json));
            this.ReturnJson.AddProperty("RowCount", pageInfo.RowCount);
            this.ReturnJson.AddProperty("AllNum", allNum);
            this.ReturnJson.AddProperty("AllTotalPrice", allTotalPrice);
            return Content(this.ReturnJson.ToString());
        }
        /// <summary>
        /// 获得满足条件的所有产品的总价格
        /// </summary>
        /// <param name="localName"></param>
        /// <param name="localType"></param>
        /// <param name="searchKey"></param>
        /// <param name="storageNum"></param>
        /// <returns></returns>
        public double GetAllTotalPrice(string localName, string localType, string searchKey, string storageNum)
        {
            LocalProductEntity entity = new LocalProductEntity();
            double allTotalPrice = 0;
            if (!storageNum.IsEmpty())
            {
                entity.Where("StorageNum", ECondition.Eth, storageNum);
            }
            if (!localType.IsEmpty())
            {
                entity.Where("LocalType", ECondition.Eth, localType);
            }
            if (!localName.IsEmpty())
            {
                entity.Where("LocalName", ECondition.Like, "%" + localName + "%");
                entity.Or("LocalNum", ECondition.Like, "%" + localName + "%");
            }

            if (!searchKey.IsEmpty())
            {
                entity.Begin<LocalProductEntity>()
                 .Where<LocalProductEntity>("ProductName", ECondition.Like, "%" + searchKey + "%")
                 .Or<LocalProductEntity>("ProductNum", ECondition.Like, "%" + searchKey + "%")
                 .Or<LocalProductEntity>("BarCode", ECondition.Like, "%" + searchKey + "%")
                 .End<LocalProductEntity>();
            }
            entity.IncludeNum(true);

            ProductEntity ProEntity = new ProductEntity();
            ProEntity.Include(a => new { AvgPrice = a.AvgPrice });
            entity.Left<ProductEntity>(ProEntity, new Params<string, string>() { Item1 = "ProductNum", Item2 = "SnNum" });
            entity.OrderBy(a => a.ID, EOrderBy.DESC);

            List<LocalProductEntity> listResult = this.LocalProduct.GetList(entity);
            if (!listResult.IsNullOrEmpty())
            {
                listResult.ForEach(a =>
                {
                    a.TotalPrice = a.Num * a.AvgPrice;
                    allTotalPrice += a.TotalPrice;
                });
            }
            return allTotalPrice;
        }