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; }
//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; }
protected void btnAdd_ServerClick(Object sender, EventArgs e) { String clientFunc = "HideWait();"; try { ModelBOMInfoDef item = new ModelBOMInfoDef(); item.Component = this.dPartNo.Text.ToUpper().Trim(); item.ID = "0"; item.Priority = this.dPriority.Text.Trim(); item.Editor = this.HiddenUserName.Value.Trim(); item.Quantity = this.dQty.Text.Trim(); //找树 string value = this.dSelectedTreeNodeId.Value.Trim(); myTreeNode itemNode = findTreeNode(value); if (itemNode == null) { ScriptManager.RegisterStartupScript(this.updatePanelAll, typeof(System.Object), "saveUpdate", "HideWait();", true); return; } ChangeNodeInfoDef parent = new ChangeNodeInfoDef(); parent.NodeName = itemNode.Current; //父节点新取得的信息 myTreeNode parentNodeFromDatabase; TreeNodeDef addNodeInfo; // 檢查配對是否已經存在; BOMNodeRelation if (!CheckExistPair(itemNode.Current, item.Component)) return; addNodeInfo = iModelBOM.AddModelBOM(item, parent); item.ID = addNodeInfo.id; //取得新保存节点父节点的树信息 //父节点的信息,itemNode.Current parentNodeFromDatabase = GetTreeNodeByData(itemNode.Current); //CacheUpdate for BOM iModelBOM.CacheUpdate_ForBOM(parent.NodeName); //update tree //找到树中所有与当前父节点PartNo同名的节点 List<myTreeNode> findResult = findTreeNodeByPartNo(itemNode.Current); for (int i = 0; i < findResult.Count; i++) { //将父节点新的信息深拷贝到其中 CloneTreeNode(findResult[i], parentNodeFromDatabase); } //选择当前的展开节点,展开那个节点 this.dTree.ExpandAll(); itemNode.Select(); //判断新改的节点是否在显示中 Boolean isNewNodeInShow = false; List<string> idList = new List<string>(); for (int i = 0; i < itemNode.ChildNodes.Count; i++) { string id = ((myTreeNode)itemNode.ChildNodes[i]).Id; idList.Add(id); /////// //如果当前的子节点没被加到原来的父节点上,说明不符合显示条件 if (item.ID == id) { isNewNodeInShow = true; } ////// } ShowListByTreeNode(idList); SaveTreeIdIndex(); string treeNodeValue = itemNode.Value; clientFunc =clientFunc+ " HighLightTreeNode('" + treeNodeValue + "');AddUpdateComplete('" + item.ID + "');"; if (isNewNodeInShow == false) { //15 //clientFunc = clientFunc + "alert('" + pmtMessage15 + "');"; //clientFunc = clientFunc + "alert('" + "已经成功添加节点,新改的数据不在可被显示的范围内" + "');"; } clientFunc = clientFunc + "showSelectedNode();"; ScriptManager.RegisterStartupScript(this.updatePanelAll, typeof(System.Object), "saveUpdate", clientFunc, true); this.updatePanel.Update(); this.updatePanel1.Update(); this.updatePanel2.Update(); } catch (FisException ex) { showErrorMessage(ex.mErrmsg); return; } catch (Exception ex) { //show error showErrorMessage(ex.Message); return; } }