public S_D_WBSTemplateNode AddChild(S_D_WBSTemplateNode child, bool isValidate = true) { var entities = this.GetDbContext <BaseConfigEntities>(); if (String.IsNullOrEmpty(child.WBSType)) { throw new Formula.Exceptions.BusinessException("必须指定节点的类型"); } if (entities.Entry(child).State != System.Data.EntityState.Detached && entities.Entry(child).State != System.Data.EntityState.Added) { throw new Formula.Exceptions.BusinessException("非新增状态的对象,无法调用AddChild方法"); } child.TemplateID = this.TemplateID; child.S_D_WBSTemplate = this.S_D_WBSTemplate; if (String.IsNullOrEmpty(child.ID)) { child.ID = FormulaHelper.CreateGuid(); } child.ParentID = this.ID; child.FullID = this.FullID + "." + child.ID; child.Level = this.Level + 1; if (child.SortIndex <= 0) { child.SortIndex = child.Level * 1000 + this.Children.Count * 10; } if (String.IsNullOrEmpty(child.WBSValue) && child.IsEnumNode) { throw new Formula.Exceptions.BusinessException("枚举类WBS节点,必须指定WBSValue"); } if (String.IsNullOrEmpty(child.WBSValue)) { child.WBSValue = child.Code; } if (String.IsNullOrEmpty(child.WBSValue)) { child.WBSValue = child.Name; } if (isValidate) { if (this.StructNodeInfo == null) { throw new Formula.Exceptions.BusinessException("【" + this.Name + "】未获取WBS结构定义对象,无法新增子节点"); } if (!this.StructNodeInfo.ValidateChildren(child.WBSType)) { throw new Formula.Exceptions.BusinessException("【" + EnumBaseHelper.GetEnumDescription(typeof(WBSNodeType), this.WBSType) + "】节点下不包含【" + EnumBaseHelper.GetEnumDescription(typeof(WBSNodeType), child.WBSType) + "】的子节点定义,无法新增子节点"); } if (child.StructNodeInfo == null) { throw new Formula.Exceptions.BusinessException("模板定义中未能找到【" + child.WBSType + "】定义,无法增加子节点"); } } this.Children.Add(child); this.S_D_WBSTemplate.S_D_WBSTemplateNode.Add(child); return(child); }
public void Save() { var rootNode = this.S_D_WBSTemplateNode.FirstOrDefault(d => String.IsNullOrEmpty(d.ParentID)); if (rootNode == null) { rootNode = new S_D_WBSTemplateNode(); rootNode.ID = FormulaHelper.CreateGuid(); rootNode.ParentID = ""; rootNode.FullID = rootNode.ID; rootNode.WBSType = WBSNodeType.Project.ToString(); rootNode.TemplateID = this.ID; rootNode.S_D_WBSTemplate = this; this.S_D_WBSTemplateNode.Add(rootNode); } rootNode.Name = this.Name; rootNode.WBSValue = this.Name; }