public void Save(ERP_M001_Product ERP_M001_Product, List <ERP_M001_Product_Material> materialList, List <ERP_M001_Product_PackInfo> packInfoList, List <ERP_M001_Product_SemiProduct> semiProdList, List <ERP_M001_Product_ProcessFlow> processList, List <ERP_M001_Product_ProdInfo> prodInfoList) { tb_Sys_User tempUser = appCacheService.GetItem("user") as tb_Sys_User; var existsProduct = this.GetById(ERP_M001_Product.Id); if (existsProduct == null) { var existPartNo = this.GetByPartNo(ERP_M001_Product.PartNo); if (existPartNo != null) { throw new AppException("产品代号已存在,请检查"); } ERP_M001_Product.CreateDt = DateTime.Now; ERP_M001_Product.CreateUser = tempUser.UserName; ERP_M001_Product.CompCode = tempUser.CompCode; ERP_M001_Product.Validate(); this.ERP_M001_ProductRepository.Add(ERP_M001_Product); } else { ERP_M001_Product.ModifyDt = DateTime.Now; ERP_M001_Product.ModifyUser = tempUser.UserName; ERP_M001_Product.Validate(); this.ERP_M001_ProductRepository.SetValues(ERP_M001_Product, existsProduct); } if (packInfoList != null) { //string sql = string.Format("Delete ERP_M001_Product_PackInfo where PartNo = '{0}'", ERP_M001_Product.PartNo); //this.packInfoRepository.GetDbContext().Database.ExecuteSqlCommand(sql); foreach (var packInfo in packInfoList) { var existsPackInfo = this.packInfoRepository.GetByID(packInfo.Id); if (existsPackInfo == null) { packInfo.CompCode = tempUser.CompCode; packInfo.CreateDt = DateTime.Now; packInfo.CreateUser = tempUser.UserName; packInfo.PartNo = ERP_M001_Product.PartNo; packInfo.Validate(); this.packInfoRepository.Add(packInfo); } else { packInfo.ModifyDt = DateTime.Now; packInfo.ModifyUser = tempUser.UserName; packInfo.Validate(); this.packInfoRepository.SetValues(packInfo, existsPackInfo); } } } if (materialList != null) { //string sql = string.Format("Delete ERP_M001_Product_Material where ProductCode = '{0}'", ERP_M001_Product.PartNo); //this.materialRepository.GetDbContext().Database.ExecuteSqlCommand(sql); foreach (var material in materialList) { var existsmaterial = this.materialRepository.GetByID(material.Id); if (existsmaterial == null) { material.CompCode = tempUser.CompCode; material.CreateDt = DateTime.Now; material.CreateUser = tempUser.UserName; material.ProductCode = ERP_M001_Product.PartNo; material.Validate(); this.materialRepository.Add(material); } else { material.ModifyDt = DateTime.Now; material.ModifyUser = tempUser.UserName; material.Validate(); this.materialRepository.SetValues(material, existsmaterial); } } } if (semiProdList != null) { //string sql = string.Format("Delete ERP_M001_Product_SemiProduct where PartNo = '{0}'", ERP_M001_Product.PartNo); //this.semiProductRepository.GetDbContext().Database.ExecuteSqlCommand(sql); foreach (var semiProd in semiProdList) { var existssemiProd = this.semiProductRepository.GetByID(semiProd.Id); if (existssemiProd == null) { semiProd.CompCode = tempUser.CompCode; semiProd.CreateDt = DateTime.Now; semiProd.CreateUser = tempUser.UserName; semiProd.PartNo = ERP_M001_Product.PartNo; semiProd.Validate(); this.semiProductRepository.Add(semiProd); } else { semiProd.ModifyDt = DateTime.Now; semiProd.ModifyUser = tempUser.UserName; semiProd.Validate(); this.semiProductRepository.SetValues(semiProd, existssemiProd); } } } if (processList != null) { string sql = string.Format("Delete ERP_M001_Product_Process where PartNo = '{0}'", ERP_M001_Product.PartNo); this.processFlowRepository.GetDbContext().Database.ExecuteSqlCommand(sql); foreach (var processDetail in processList) { processDetail.PartNo = ERP_M001_Product.PartNo; processDetail.PFCode = ERP_M001_Product.ProcessFlow; processDetail.CompCode = tempUser.CompCode; processDetail.PartNo = ERP_M001_Product.PartNo; processDetail.Validate(); this.processFlowRepository.Add(processDetail); } } if (prodInfoList != null) { string sql = string.Format("Delete ERP_M001_Product_ProdInfo where PartNo = '{0}'", ERP_M001_Product.PartNo); prodInfoReopsitory.GetDbContext().Database.ExecuteSqlCommand(sql); foreach (var prodInfo in prodInfoList) { prodInfo.CompCode = ERP_M001_Product.PartNo; prodInfo.PFCode = ERP_M001_Product.ProcessFlow; prodInfo.CompCode = tempUser.CompCode; prodInfo.PartNo = ERP_M001_Product.PartNo; prodInfo.Validate(); this.prodInfoReopsitory.Add(prodInfo); } } this.runtimeService.Commit(); }