/// <summary> /// 批量删除损益细单 /// </summary> /// <param name="profitLossBillMaster">损益主单</param> public void DeleteProfitLossBillDetail(ProfitLossBillMaster profitLossBillMaster) { if (profitLossBillMaster != null) { foreach (var detail in profitLossBillMaster.ProfitLossBillDetails) { var Storage = Locker.LockStorage(detail.Storage, detail.Product); if (Storage != null) { if (detail.Quantity > 0) { Storage.InFrozenQuantity -= detail.Quantity; } else { Storage.OutFrozenQuantity -= Math.Abs(detail.Quantity); } Storage.LockTag = string.Empty; detail.Quantity = 0; } } var details = profitLossBillMaster.ProfitLossBillDetails.Where(d => d.Quantity == 0) .Select(d => d); ProfitLossBillDetailRepository.Delete(details.ToArray()); ProfitLossBillDetailRepository.SaveChanges(); } }
/// <summary> /// 删除损益细单 /// </summary> /// <param name="ID">损益单细单ID</param> /// <returns></returns> public bool Delete(string ID, out string strResult) { strResult = string.Empty; bool result = false; try { IQueryable <ProfitLossBillDetail> profitLossBillDetailQuery = ProfitLossBillDetailRepository.GetQueryable(); int intID = Convert.ToInt32(ID); var pbd = profitLossBillDetailQuery.FirstOrDefault(i => i.ID == intID); var unit = UnitRepository.GetQueryable().FirstOrDefault(u => u.UnitCode == pbd.UnitCode); var product = ProductRepository.GetQueryable().FirstOrDefault(p => p.ProductCode == pbd.ProductCode); var storage = StorageRepository.GetQueryable().FirstOrDefault(s => s.StorageCode == pbd.StorageCode); if (pbd != null) { if (Locker.LockStorage(storage, product) != null) { if (pbd.Quantity > 0) { storage.InFrozenQuantity -= pbd.Quantity; } else { storage.OutFrozenQuantity -= Math.Abs(pbd.Quantity); } storage.LockTag = string.Empty; StorageRepository.SaveChanges(); ProfitLossBillDetailRepository.Delete(pbd); ProfitLossBillDetailRepository.SaveChanges(); result = true; } else { strResult = "库存加锁失败!"; result = false; } } else { strResult = "删除失败,找不到该条单据!"; result = false; } } catch (Exception ex) { strResult = "删除失败,原因:" + ex.Message; } return(result); }