public int SavePurchaseReturn(TPurchaseReturn obj) { if (obj.Content.ID != null && obj.Content.ID > 0) { MMS_PurchaseReturnContent content = dao.GetInfo(obj.Content.ID); if (content.AuditFlag == true) { throw new Exception("该单据已经审核" + content.PurchaseBillCode); } } return(dao.SavePurchaseReturn(obj)); }
public bool AuditPurchaseReturn(int id, bool isAudit, string operatorCode) { using (TransactionScope ts = new TransactionScope()) //开启DTC事务 { TPurchaseReturn tPur = dao.GetPurchaseReturn(id); MMS_PurchaseReturnContent content = tPur.Content; if (content.AuditFlag == true) { throw new Exception("该单据已经审核" + content.PurchaseBillCode); } foreach (TPurchaseReturnDetail tPurDetail in tPur.Detail) { MMS_Store storeParam = new MMS_Store(); storeParam.Warehouse = tPur.Content.WareHouse; storeParam.ProductCode = tPurDetail.DetDetail.ProductCode; MMS_Store sto = null; sto = daoStore.GetStore(storeParam); if (sto == null) //库存中没有该商品 { throw new Exception("库存中没有该商品,不能退货" + tPurDetail.DetDetail.ProductCode); } else { if (tPurDetail.DetDetail.Quantity > sto.Quantity) { throw new Exception("库存数据不足,不能退货" + tPurDetail.DetDetail.ProductCode); } sto.Quantity -= tPurDetail.DetDetail.Quantity; sto.Amount -= tPurDetail.DetDetail.Quantity * tPurDetail.DetDetail.Price; if (sto.Quantity > 0) { sto.Price = sto.Amount / sto.Quantity; } daoStore.UpdateInfo(sto); } } content.AuditFlag = isAudit; content.Operator = operatorCode; content.OperateDate = DateTime.Now; dao.UpdateInfo(content); ts.Complete(); } return(true); }
/// <summary> /// 获得组合实体 /// </summary> /// <param name="id"> 实体id号 </param> /// <returns> 自定义组合实体 </returns> public TPurchaseReturn GetPurchaseReturn(int id) { TPurchaseReturn resu = new TPurchaseReturn(); resu.OprType = OperateType.otNone; resu.Content = dc.MMS_PurchaseReturnContent.Where(itm => itm.ID == id).First(); List <MMS_PurchaseReturnDetail> tempList = dc.MMS_PurchaseReturnDetail.Where(itm => itm.PurchaseBillCode == resu.Content.PurchaseBillCode).ToList(); foreach (MMS_PurchaseReturnDetail item in tempList) { TPurchaseReturnDetail TDetail = new TPurchaseReturnDetail(); TDetail.OprType = OperateType.otNone; TDetail.DetDetail = item; resu.Detail.Add(TDetail); } return(resu); }
/// <summary> /// 保存组合实体 /// </summary> /// <param name="obj"> 实体id号 </param> /// <returns> 自定义组合实体 </returns> public int SavePurchaseReturn(TPurchaseReturn obj) { if (obj.OprType == OperateType.otInsert) { dc.MMS_PurchaseReturnContent.InsertOnSubmit(obj.Content); } else if (obj.OprType == OperateType.otUpdate) { var query = from item in dc.MMS_PurchaseReturnContent where item.ID == obj.Content.ID select item; BatchEvaluate.Eval(obj.Content, query.First()); } else if (obj.OprType == OperateType.otDelete) { dc.MMS_PurchaseReturnContent.DeleteOnSubmit(obj.Content); } foreach (TPurchaseReturnDetail item in obj.Detail) { if (item.OprType == OperateType.otInsert) { dc.MMS_PurchaseReturnDetail.InsertOnSubmit(item.DetDetail); } else if (item.OprType == OperateType.otUpdate) { var query = from itm in dc.MMS_PurchaseReturnDetail where itm.ID == item.DetDetail.ID select itm; BatchEvaluate.Eval(item.DetDetail, query.First()); } else if (item.OprType == OperateType.otDelete) { dc.MMS_PurchaseReturnDetail.DeleteOnSubmit(item.DetDetail); } } dc.SubmitChanges(); return(obj.Content.ID); }