/// <summary>绑定数据源
 /// </summary>
 /// <param name="source"></param>
 /// <param name="e"></param>
 protected void RGGoodsOrder_NeedDataSource(object source, GridNeedDataSourceEventArgs e)
 {
     if (string.IsNullOrEmpty(RCB_Goods.SelectedValue) || string.IsNullOrEmpty(RCB_Warehouse.SelectedValue))
     {
         RGGoodsOrder.DataSource = new List <GoodsDemandSearchInfo>();
     }
     else
     {
         var goodsId     = new Guid(RCB_Goods.SelectedValue);
         var warehouseId = new Guid(RCB_Warehouse.SelectedValue);
         var goods       = _goodsCenterSao.GetGoodsBaseInfoById(goodsId);
         var goodsList   = _goodsCenterSao.GetRealGoodsListByGoodsId(new List <Guid> {
             goodsId
         }).ToList();
         List <Guid> realGoodsIdList             = goodsList.Select(p => p.RealGoodsId).Distinct().ToList();
         var         result                      = WMSSao.GetRequireSearchDtos(warehouseId, realGoodsIdList, HostingFilialeId);
         List <GoodsDemandSearchInfo> datasource = new List <GoodsDemandSearchInfo>();
         if (result != null)
         {
             if (result.Count > 1)
             {
                 List <RealGoodsTotal> total = result.Select(filiale => new RealGoodsTotal
                 {
                     HostingFilialeId = filiale.HostingFilialeId, HostingFilialeName = filiale.HostingFilialeName, StockQuantity = filiale.StockQuantity, RequiresDics = filiale.RequiresDics,
                 }).ToList();
                 RealGoodsTotals = total;
                 FilialeDics     = total.ToDictionary(k => k.HostingFilialeId, v => v.HostingFilialeName);
                 datasource      = (from item in goodsList where total.Any(ent => ent.RequiresDics.ContainsKey(item.RealGoodsId))
                                    select new GoodsDemandSearchInfo
                 {
                     GoodsId = goodsId,
                     GoodsName = goods.GoodsName,
                     RealGoodsId = item.RealGoodsId,
                     Specification = item.Specification,
                     EffictiveRequire = 0,
                     CanUseGoodsStock = 0,
                 }).ToList();
             }
             else
             {
                 var filialeStock = result.FirstOrDefault();
                 var dics         = filialeStock != null && filialeStock.RequiresDics != null? filialeStock.RequiresDics : new Dictionary <Guid, int>();
                 var canUseDics   = filialeStock != null ? filialeStock.StockQuantity : new Dictionary <Guid, int>();
                 datasource = (from item in goodsList
                               let goodsStock = canUseDics == null ? 0 : canUseDics.ContainsKey(item.RealGoodsId) ? canUseDics[item.RealGoodsId] : 0
                                                let require = dics == null ? 0 : dics.ContainsKey(item.RealGoodsId) ? dics[item.RealGoodsId] : 0
                                                              where require > 0
                                                              select new GoodsDemandSearchInfo
                 {
                     GoodsId = goodsId,
                     GoodsName = goods.GoodsName,
                     RealGoodsId = item.RealGoodsId,
                     Specification = item.Specification,
                     EffictiveRequire = require,
                     CanUseGoodsStock = goodsStock
                 }).ToList();
                 RealGoodsTotals = new List <RealGoodsTotal>();
             }
         }
         RGGoodsOrder.DataSource = datasource.Count > 0? datasource.OrderBy(p => p.Specification).ToList() : datasource;
     }
     RGGoodsOrder.MasterTableView.Columns[2].Display = !IsPostBack || RealGoodsTotals.Count < 1;
     RGGoodsOrder.MasterTableView.Columns[3].Display = !IsPostBack || RealGoodsTotals.Count < 1;
     RGGoodsOrder.MasterTableView.Columns[4].Display = IsPostBack && RealGoodsTotals.Count > 1;
 }