private void ActDatasWhenBinding(IEnumerable items) { var bill = _dataContext.Master; List <int> pids = new List <int>(); TraverseDatas(items, p => pids.Add(p.ProductID)); if (bill.StorageIDOut != default(int)) { var stocks = StockLogic.GetStockInStorage(bill.StorageIDOut, productIDs: pids.ToArray()); TraverseDatas(items, p => { var stock = stocks.Find(s => s.ProductID == p.ProductID); p.OutStorageStock = (stock == null ? 0 : stock.Quantity); }); } if (bill.StorageIDIn != default(int)) { if (bill.StorageIDOut == bill.StorageIDIn)//出入仓库一样就直接赋值 { TraverseDatas(items, p => p.InStorageStock = p.OutStorageStock); } else { var stocks = StockLogic.GetStockInStorage(bill.StorageIDIn, productIDs: pids.ToArray()); TraverseDatas(items, p => { var stock = stocks.Find(s => s.ProductID == p.ProductID); p.InStorageStock = (stock == null ? 0 : stock.Quantity); }); } } }
void cbxStorageOut_SelectionChanged(object sender, SelectionChangedEventArgs e) { var bill = _dataContext.Master; if (bill.StorageID != default(int)) { List <int> pids = new List <int>(); SysProcessView.UIHelper.TraverseGridViewData <ProductForCannibalize>(gvDatas, p => pids.Add(p.ProductID)); var stocks = StockLogic.GetStockInStorage(bill.StorageID, productIDs: pids.ToArray()); SysProcessView.UIHelper.TraverseGridViewData <ProductForCannibalize>(gvDatas, p => { var stock = stocks.Find(s => s.ProductID == p.ProductID); p.OutStorageStock = (stock == null ? 0 : stock.Quantity); }); } }
void GridDataItems_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) { if (e.NewItems != null) { List <int> pids = new List <int>(); TraverseDatas(e.NewItems, p => pids.Add(p.ProductID)); if (Master.StorageID != default(int)) { var stocks = StockLogic.GetStockInStorage(Master.StorageID, productIDs: pids.ToArray()); TraverseDatas(e.NewItems, p => { var stock = stocks.Find(s => s.ProductID == p.ProductID); p.OutStorageStock = (stock == null ? 0 : stock.Quantity); }); } } }
private void btnUpdate_Click(object sender, RoutedEventArgs e) { if (cbxStorage.SelectedIndex == -1) { cbxStorage.Focus(); MessageBox.Show("请选择盘点仓库"); return; } if (!rbUpdateAll.IsChecked.Value && !rbUpdatePart.IsChecked.Value && !rbUpdateExact.IsChecked.Value) { MessageBox.Show("请选择更新方式."); return; } if (RadGridView1.ItemsSource == null || RadGridView1.Items.Count == 0) { var mbResult = MessageBox.Show("没有盘点数据,如果选择继续将产生如下影响,是否继续?\n全局更新将清空全部库存\n局部更新将清空局部库存\n精确更新将不影响库存", "注意", MessageBoxButton.YesNo); if (mbResult == MessageBoxResult.No) { return; } } List <DistributionCommonBillVM <BillStocktakeContrast, BillStocktakeContrastDetails> > contrasts = new List <DistributionCommonBillVM <BillStocktakeContrast, BillStocktakeContrastDetails> >(); var stocktakeDatas = RadGridView1.ItemsSource as IEnumerable <StocktakeAggregationEntityForStockUpdate>; if (stocktakeDatas == null) { stocktakeDatas = new List <StocktakeAggregationEntityForStockUpdate>(); } if (rbUpdateAll.IsChecked.Value) //全局更新 { int[] brandIDs = VMGlobal.PoweredBrands.Select(o => o.ID).ToArray(); //GetBrandIDsForUpdate(stocktakeDatas); foreach (int bid in brandIDs) { var stocks = StockLogic.GetStockInStorage((int)cbxStorage.SelectedValue, bid); var contrast = this.GenerateContrast(bid, stocks, stocktakeDatas.Where(o => o.BrandID == bid).ToList()); //contrast.SaveWithNoTran();//添加盈亏单 contrasts.Add(contrast); } } else if (rbUpdatePart.IsChecked.Value)//局部更新 { if (string.IsNullOrWhiteSpace(txtStyleCodeForPartUpdate.Text)) { txtStyleCodeForPartUpdate.Focus(); MessageBox.Show("请输入局部更新条码区间,多个区间以逗号分隔."); return; } var pcodes = txtStyleCodeForPartUpdate.Text.Trim().Split(','); pcodes = pcodes.Select(o => o.Trim()).ToArray(); stocktakeDatas = stocktakeDatas.ToList().Where(StockLogic.GenerateOrElseConditionWithArray <StocktakeAggregationEntityForStockUpdate>("ProductCode", "StartsWith", pcodes).Compile()); int[] brandIDs = GetBrandIDsForUpdate(stocktakeDatas); foreach (int bid in brandIDs) { var stocks = StockLogic.GetStockInStorage((int)cbxStorage.SelectedValue, bid, pcodes); var contrast = this.GenerateContrast(bid, stocks, stocktakeDatas.Where(o => o.BrandID == bid).ToList()); contrasts.Add(contrast); } } else if (rbUpdateExact.IsChecked.Value)//精确更新 { if (stocktakeDatas.Count() == 0) { return; } int[] brandIDs = GetBrandIDsForUpdate(stocktakeDatas); foreach (int bid in brandIDs) { var stocks = StockLogic.GetStockInStorage((int)cbxStorage.SelectedValue, bid, stocktakeDatas.Where(o => o.BrandID == bid).Select(o => o.ProductID).ToArray()); var contrast = this.GenerateContrast(bid, stocks, stocktakeDatas.Where(o => o.BrandID == bid).ToList()); contrasts.Add(contrast); } } UpdateStockWithContrast(contrasts); }