//current,当前添加节点的父节点,包括它本身,和它所有的父节点,是model的都要记到 refresh model表中 //返回值需要填充的项 //public string id; //public string parent; 参数中的current //public string curent; //public string desc; //public bool isPart; //public bool isModel; //parent,当前节点父节点的信息 public TreeNodeDef AddModelBOM(ModelBOMInfoDef item, ChangeNodeInfoDef parent) { //添加时需要检查是否在part表或在model表及另一个表中存在 //然后取得该点在树上的信息(返回值) //添加数据 TreeNodeDef result = new TreeNodeDef(); try { IModelBOMRepository itemRepository = RepositoryFactory.GetInstance().GetRepository<IModelBOMRepository, BOMNodeData>(); //判断是否已经存在此父子关系 //strSql = "INSERT ModelBom (Material, Material_group, Component, Quantity) values('" + parentCode + "','" + type + "','" + oldCode + "','" + qty + "')"; IList<BOMNodeData> itemList = itemRepository.findModelBomByMaterialAndComponent(parent.NodeName, item.Component); if (itemList.Count > 0) { List<string> erpara = new List<string>(); FisException ex; //!!!need change //数据库中已经存在相同的父子的关系 ex = new FisException("DMT017", erpara); throw ex; } //判断添加的子节点是一个Part //SELECT PartNo as Code,Descr from Part where PartNo='code' AND Flag=1 AND AutoDL='Y' string partDesc = ""; DataTable existPartNos = itemRepository.GetExistPartNo(item.Component); if (existPartNos == null || existPartNos.Rows.Count == 0) { List<string> erpara = new List<string>(); FisException ex; //!!!need change //添加的子节点不是一个Part ex = new FisException("DMT018", erpara); throw ex; } partDesc = Null2String(existPartNos.Rows[0][1]); //!!!找父节点的Type(Material_group)!!!还要找part中的type //GetMaterialById string type = ""; //SELECT Material AS Code, Material_group AS PartType FROM ModelBOM where Material='code' AND Flag=1 //UNION SELECT [PartNo] AS Code ,[PartType] AS PartType // FROM [IMES_GetData_Datamaintain].[dbo].[Part] //where Flag=1 AND [PartNo]='code' //need change DataTable resultTypeInfo = itemRepository.GetPartTypeInfoByCode(parent.NodeName); if (resultTypeInfo.Rows.Count > 0) { type = Null2String(resultTypeInfo.Rows[0][1]); } Hashtable modelIds = new Hashtable(); //附带增加检查当前partNo是否存在于父节点 Dictionary<string, string> parents = new Dictionary<string, string>(); GetNeedRefreshModelIncludeCurrentList(parent, modelIds, parents); Dictionary<string, string> children = new Dictionary<string, string>(); GetAllChildren(item.Component, children); Boolean isExist = false; isExist = JudgeErrorParentChildren(parents, children, isExist); //if (isExist == true || parent.NodeName == item.Component) if (isExist == true) { List<string> erpara = new List<string>(); FisException ex; //!!!need change //添加的子节点与直接或间接父节点有嵌套 ex = new FisException("DMT019", erpara); throw ex; } UnitOfWork uow = new UnitOfWork(); foreach (String modelId in modelIds.Keys) { //Refreshmodel表 //删除原来的modelId //添加新的modelId itemRepository.DeleteRefreshModelByModelDefered(uow, modelId, item.Editor); itemRepository.AddRefreshModelDefered(uow, modelId, item.Editor); } //需在一个事物中 itemRepository.DeleteModelBomByMaterialAndComponentDefered(uow, parent.NodeName, item.Component); BOMNodeData itemNew = new BOMNodeData(); itemNew.Material = parent.NodeName; // itemNew.Material_group = type; itemNew.Component = item.Component; itemNew.Quantity = item.Quantity; itemNew.Priority = item.Priority; itemNew.Editor = item.Editor; itemNew.Cdt = DateTime.Now; itemNew.Udt = DateTime.Now; itemNew.Plant = ""; itemNew.Alternative_item_group = ""; itemRepository.AddModelBOMDefered(uow, itemNew); uow.Commit(); result.id = itemNew.ID.ToString(); result.curent = itemNew.Component; result.desc = partDesc; } catch (Exception) { throw; } return result; }
public TreeNodeDef SaveModelBOM(ModelBOMInfoDef item, ChangeNodeInfoDef parent) { //添加时需要检查是否在part表或在model表及另一个表中存在 //然后取得该点在树上的信息(返回值) TreeNodeDef result = new TreeNodeDef(); try { IModelBOMRepository itemRepository = RepositoryFactory.GetInstance().GetRepository<IModelBOMRepository, BOMNodeData>(); //判断是否已经存在此父子关系 //Select * from ModelBom where Material='" + parentCode + "' and Component='" + oldCode + "' IList<BOMNodeData> itemList = itemRepository.findModelBomByMaterialAndComponent(parent.NodeName, item.Component); if (itemList.Count > 0 && itemList[0].ID.ToString() != item.ID) { List<string> erpara = new List<string>(); FisException ex; //!!!need change //数据库中已经存在相同的父子的关系 ex = new FisException("DMT017", erpara); throw ex; } //判断修改的子节点是一个Part //SELECT PartNo as Code,Descr from Part where PartNo='code' AND Flag=1 AND AutoDL='Y' string partDesc = ""; DataTable existPartNos = itemRepository.GetExistPartNo(item.Component); if (existPartNos == null || existPartNos.Rows.Count == 0) { List<string> erpara = new List<string>(); FisException ex; //!!!need change //子节点不是一个Part ex = new FisException("DMT018", erpara); throw ex; } partDesc = Null2String(existPartNos.Rows[0][1]); //!!!找父节点的Type(Material_group)!!!还要找part中的type //GetMaterialById string type = ""; //SELECT Material AS Code, Material_group AS PartType FROM ModelBOM where Material='code' AND Flag=1 //UNION SELECT [PartNo] AS Code ,[PartType] AS PartType // FROM [IMES_GetData_Datamaintain].[dbo].[Part] //where Flag=1 AND [PartNo]='code' //父节点的Part信息 DataTable resultTypeInfo = itemRepository.GetPartTypeInfoByCode(parent.NodeName); if (resultTypeInfo.Rows.Count > 0) { type = Null2String(resultTypeInfo.Rows[0][1]); } Hashtable modelIds = new Hashtable(); Dictionary<string, string> parents = new Dictionary<string, string>(); GetNeedRefreshModelIncludeCurrentList(parent, modelIds, parents); Dictionary<string, string> children = new Dictionary<string, string>(); GetAllChildren(item.Component, children); Boolean isExist = false; isExist = JudgeErrorParentChildren(parents, children, isExist); //if (isExist == true || parent.NodeName == item.Component) if (isExist == true) { List<string> erpara = new List<string>(); FisException ex; //!!!need change //子节点与直接或间接父节点有嵌套 ex = new FisException("DMT019", erpara); throw ex; } UnitOfWork uow = new UnitOfWork(); foreach (String modelId in modelIds.Keys) { //Refreshmodel表 //删除原来的modelId //添加新的modelId itemRepository.DeleteRefreshModelByModelDefered(uow, modelId, item.Editor); itemRepository.AddRefreshModelDefered(uow, modelId, item.Editor); } //需在一个事物中 //itemRepository.DeleteModelBomByMaterialAndComponentDefered(uow, parent.NodeName, item.Component); //空的不是公用料 IMiscRepository iMiscRepository = RepositoryFactory.GetInstance().GetRepository<IMiscRepository>(); MoBOMInfo condition = new MoBOMInfo(); condition.id = Int32.Parse(item.ID); IList<MoBOMInfo> itemNew = iMiscRepository.GetData<IMES.Infrastructure.Repository._Metas.ModelBOM_NEW, MoBOMInfo>(condition); //BOMNodeData itemNew = itemRepository.GetModelBOM2(Int32.Parse(item.ID)); Boolean isNeedChangeGroupNo = false; //判断有共用料时再做,并且数据有变化时再做 if (Null2String(itemNew[0].alternative_item_group) != "" && itemNew[0].quantity != item.Quantity) { isNeedChangeGroupNo = true; } itemNew[0].material = parent.NodeName; itemNew[0].component = item.Component; itemNew[0].quantity = item.Quantity; itemNew[0].priority = item.Priority; itemNew[0].flag = int.Parse(item.Flag); itemNew[0].editor = item.Editor; itemNew[0].udt = DateTime.Now; iMiscRepository.UpdateDataByIDDefered<IMES.Infrastructure.Repository._Metas.ModelBOM_NEW, MoBOMInfo>(uow, condition, itemNew[0]); //itemRepository.UpdateModelBOMDefered(uow, itemNew); if (isNeedChangeGroupNo == true) { itemRepository.UpdateGroupQuantityDefered(uow, item.Quantity, itemNew[0].alternative_item_group, item.Editor); } uow.Commit(); result.id = item.ID.ToString(); result.curent = itemNew[0].component; result.desc = partDesc; } catch (Exception) { throw; } return result; }