/// <summary> /// 设置共用料 /// </summary> /// <param name="idList"></param> /// <param name="current"></param> /// //SELECT a.Component as Material, b.PartType, a.Quantity, //a.Alternative_item_group, a.Priority //,a.[Editor],a.[Cdt],a.[Udt],a.ID FROM ModelBOM AS a //left outer join //(select Material AS Code, Material_group AS PartType from ModelBOM where Flag=1 // UNION SELECT [PartNo] AS Code ,[PartType] AS PartType // FROM [IMES_GetData_Datamaintain].[dbo].[Part] where Flag=1 //) AS b on a.Component=b.Code //WHERE a.Flag=1 AND a.ID IN (idList) //order by a.Component public void SetNewAlternativeGroup(List<string> idStrList, ChangeNodeInfoDef current, string editor) { Hashtable modelIds = new Hashtable(); if (idStrList.Count == 0) { return; } try { IModelBOMRepository itemRepository = RepositoryFactory.GetInstance().GetRepository<IModelBOMRepository, BOMNodeData>(); List<int> idList = new List<int>(); for (int i = 0; i < idStrList.Count; i++) { int id = int.Parse(idStrList[i]); idList.Add(id); } DataTable result = itemRepository.GetSubModelBOMByCode(idList); ////数据库中的数据已经被其他人修改 //if (idStrList.Count != result.Rows.Count) //{ // List<string> erpara = new List<string>(); // FisException ex; // //!!!need change right!!! // //数据库中的数据已经被其他人修改,建议重新输入[Model/PN],刷新界面以获取最新数据 // ex = new FisException("DMT001", erpara); // throw ex; //} string firstGroup = Null2String(result.Rows[0][2]); string firstQty = Null2String(result.Rows[0][4]); //判断Qty和Type应该一致 for (int i = 1; i < result.Rows.Count; i++) { string currentGroup = Null2String(result.Rows[i][2]); string currentQty = Null2String(result.Rows[i][4]); if (currentGroup != firstGroup || currentQty != firstQty) { //!!!check是否要细化 List<string> erpara = new List<string>(); FisException ex; //!!!need change right!!! //设置共用料的项目的Qty或Type有不相同的 ex = new FisException("DMT016", erpara); throw ex; } } GetNeedRefreshModelIncludeCurrentList(current, modelIds); //事物中存共用料,和存Refresh Model UnitOfWork uow = new UnitOfWork(); //foreach (String modelId in modelIds.Keys) //{ // //Refreshmodel表 // //删除原来的modelId // //添加新的modelId // itemRepository.DeleteRefreshModelByModelDefered(uow, modelId, editor); // itemRepository.AddRefreshModelDefered(uow, modelId, editor); //} //!!!need change //调用设置共用料UPDATE ModelBOM SET Alternative_item_group=newid() where ID in(idlist) AND Flag=1 itemRepository.SetNewAlternativeGroupDefered(uow, idList, editor); uow.Commit(); } catch (Exception) { throw; } }
//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; }
//current,当前被更改关系的父节点,包括它本身,和它所有的父节点,是approve过的model的都要记到 refresh model表中 public void Delete(List<string> idList, ChangeNodeInfoDef current, string editor) { try { Hashtable modelIds = new Hashtable(); //GetNeedRefreshModelIncludeCurrentList(current, modelIds); ////////////////////////////////////// UnitOfWork uow = new UnitOfWork(); IModelBOMRepository itemRepositoryBom = RepositoryFactory.GetInstance().GetRepository<IModelBOMRepository, BOMNodeData>(); //Refreshmodel表添加数据,找不到在添加 foreach (String modelId in modelIds.Keys) { //Refreshmodel表 //删除原来的modelId //添加新的modelId //itemRepositoryBom.DeleteRefreshModelByModelDefered(uow, modelId, editor); itemRepositoryBom.AddRefreshModelDefered(uow, modelId, editor); } for (int i = 0; i < idList.Count; i++) { int id = Int32.Parse(idList[i]); itemRepositoryBom.RemoveModelBOMByIdDefered(uow, id, editor); } uow.Commit(); } catch (Exception) { throw; } }
//取得包括当前节点在内的需要记录在refreshModel表中的记录,放在modelIds中 private void GetNeedRefreshModelIncludeCurrentList(ChangeNodeInfoDef current, Hashtable modelIds, Dictionary<string, string> parents) { //获取current是否approve过的model ChangeNodeInfoDef parent = new ChangeNodeInfoDef(); parent.NodeName = current.NodeName; parent.IsModel = false; IModelRepository itemRepository = RepositoryFactory.GetInstance().GetRepository<IModelRepository, Model>(); Model item = itemRepository.Find(parent.NodeName); if (item != null && Null2String(item.BOMApproveDate) != "") { parent.IsModel = true; } //取得需要记到数据库refreshModel中的数据 GetNeedRefreshModel(parent, modelIds, parents); }
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; }
//取得包括当前节点在内的需要记录在refreshModel表中的记录,放在modelIds中 private void GetNeedRefreshModelIncludeCurrentList(ChangeNodeInfoDef current, Hashtable modelIds) { Dictionary<string, string> parents = new Dictionary<string, string>(); GetNeedRefreshModelIncludeCurrentList(current, modelIds, parents); }
/// <summary> /// 将当前节点和其所有父节点中是model的数据,放到modelIds中 /// </summary> /// <param name="current">当前节点</param> /// <param name="modelIds">存放当前节点和其所有父节点中是model的数据</param> private void GetNeedRefreshModel(ChangeNodeInfoDef current, Hashtable modelIds, Dictionary<string, string> parents) { if (current.IsModel == true) { modelIds.Add(current.NodeName, current.NodeName); } try { parents.Add(current.NodeName, current.NodeName); } catch { //不需要处理 } DataTable allCollectResult = new DataTable(); //datatable里面排序 DealGetAllParentInfo(current.NodeName, allCollectResult); for (int i = 0; i < allCollectResult.Rows.Count; i++) { String NodeName = Null2String(allCollectResult.Rows[i][0]); string isModelStr = Null2String(allCollectResult.Rows[i][2]); string ApproveDate = Null2String(allCollectResult.Rows[i][3]); Boolean isModel = false; if (isModelStr != "") { //c.Flag,标识是否是'Model' if (isModelStr == "Model") { isModel = true; } } //需要Approve过的model才加入refreshModel的表中 if (isModel == true && NodeName != "" && ApproveDate != "" && !modelIds.ContainsKey(NodeName)) { modelIds.Add(NodeName, NodeName); } try { parents.Add(NodeName, NodeName); } catch { //不需要处理 } //if (currentPartNo!= "" && currentPartNo == NodeName) //{ // isExist = true; //} } }
protected void btnDelete_ServerClick(Object sender, EventArgs e) { List<string> idList = GetCheckedIdList(); //找树 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; try { iModelBOM.Delete(idList, parent, this.HiddenUserName.Value.Trim()); //取得新保存节点父节点的树信息 //父节点的信息,itemNode.Current parentNodeFromDatabase = GetTreeNodeByData(itemNode.Current); //CacheUpdate for BOM iModelBOM.CacheUpdate_ForBOM(parent.NodeName); } catch (FisException ex) { showErrorMessage(ex.mErrmsg); return; } catch (Exception ex) { //show error showErrorMessage(ex.Message); return; } //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(); /////// List<string> nodeIdList = new List<string>(); for (int i = 0; i < itemNode.ChildNodes.Count; i++) { string id = ((myTreeNode)itemNode.ChildNodes[i]).Id; nodeIdList.Add(id); } ShowListByTreeNode(nodeIdList); SaveTreeIdIndex(); string treeNodeValue = itemNode.Value; String clientFunc = ""; clientFunc = clientFunc + "HideWait();"; clientFunc = clientFunc + "HighLightTreeNode('" + treeNodeValue + "');DeleteComplete();"; ScriptManager.RegisterStartupScript(this.updatePanelAll, typeof(System.Object), "saveUpdate", clientFunc, true); this.updatePanel.Update(); this.updatePanel1.Update(); this.updatePanel2.Update(); }
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; } }
protected void btnGroupNo_ServerClick(Object sender, EventArgs e) { List<string> idList = GetCheckedIdList(); string itemId = idList[0]; //找树 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; try { iModelBOM.SetNewAlternativeGroup(idList, parent, this.HiddenUserName.Value.Trim()); } catch (FisException ex) { showErrorMessage(ex.mErrmsg); return; } catch (Exception ex) { //show error showErrorMessage(ex.Message); return; } List<string> nodeIdList = new List<string>(); for (int i = 0; i < itemNode.ChildNodes.Count; i++) { string id = ((myTreeNode)itemNode.ChildNodes[i]).Id; nodeIdList.Add(id); } ShowListByTreeNode(nodeIdList); String clientFunc = "HideWait();AddUpdateComplete('" + itemId + "');"; ScriptManager.RegisterStartupScript(this.updatePanelAll, typeof(System.Object), "saveUpdate", clientFunc, true); this.updatePanel1.Update(); this.updatePanel2.Update(); }