public ReturnType AddStockCheck(StockCheck stockCheck) { try { using (AladingEntities alading = new AladingEntities(AppSettings.GetConnectionString())) { alading.AddToStockCheck(stockCheck); if (alading.SaveChanges() == 1) { return(ReturnType.Success); } else { return(ReturnType.PropertyExisted); } } } catch (SqlException sex) { return(ReturnType.ConnFailed); } catch (Exception ex) { return(ReturnType.OthersError); } }
public ReturnType AddStockCheckAndDetails(StockCheck stockCheck, List <StockCheckDetail> CheckDetails) { try { using (AladingEntities alading = new AladingEntities(AppSettings.GetConnectionString())) { alading.AddToStockCheck(stockCheck); foreach (StockCheckDetail detail in CheckDetails) { alading.AddToStockCheckDetail(detail); #region StockInOut Alading.Entity.StockInOut stockInOut = new Alading.Entity.StockInOut(); stockInOut.AmountTax = 0; stockInOut.DiscountFee = 0; stockInOut.DueFee = 0; stockInOut.FreightCode = string.Empty; stockInOut.FreightCompany = string.Empty; stockInOut.InOutCode = Guid.NewGuid().ToString(); stockInOut.InOutTime = DateTime.Now; if (detail.ProfitType == (int)ProfitType.PROFIT) { stockInOut.InOutType = (int)InOutType.ProfitIn; } else { stockInOut.InOutType = (int)InOutType.LossOut; } stockInOut.TradeOrderCode = string.Empty; stockInOut.OperatorCode = stockCheck.OperatorCode; stockInOut.OperatorName = string.Empty; stockInOut.PayType = (int)PayType.CASH; stockInOut.IsSettled = true; stockInOut.PayTerm = 0; stockInOut.IncomeTime = DateTime.MinValue; stockInOut.PayThisTime = 0; #endregion #region StockDetail StockDetail stockDetailOut = new StockDetail(); stockDetailOut.ProductSkuOuterId = detail.SkuOuterID; stockDetailOut.DetailRemark = string.Empty; stockDetailOut.DetailType = (int)DetailType.AllocateOut; stockDetailOut.DurabilityDate = DateTime.Now; stockDetailOut.InOutCode = stockInOut.InOutCode; stockDetailOut.Price = 0; stockDetailOut.Quantity = detail.CheckQuantity; stockDetailOut.StockDetailCode = Guid.NewGuid().ToString(); stockDetailOut.StockHouseCode = stockCheck.StockHouseCode; stockDetailOut.StockLayOutCode = detail.LayoutCode; stockDetailOut.Tax = string.Empty; stockDetailOut.TotalFee = 0; #endregion StockProduct product = alading.StockProduct.FirstOrDefault(i => i.SkuOuterID == detail.SkuOuterID); if (product != null) { product.SkuQuantity = detail.Quantity;//归档 } alading.AddToStockInOut(stockInOut); alading.AddToStockDetail(stockDetailOut); } alading.SaveChanges(); return(ReturnType.Success); } } catch (Exception ex) { throw ex; } }