示例#1
0
        /// <summary>
        /// 新增子节点
        /// </summary>
        /// <param name="child"></param>
        public void AddChild(S_I_ProjectGroup child)
        {
            if (String.IsNullOrEmpty(child.ID))
            {
                child.ID = FormulaHelper.CreateGuid();
            }
            child.ParentID   = this.ID;
            child.FullID     = this.FullID + "." + child.ID;
            child.RootID     = this.RootID;
            child.CreateDate = DateTime.Now;
            var entities = this.GetDbContext <ProjectEntities>();

            if (entities.Entry <S_I_ProjectGroup>(child).State == EntityState.Detached)
            {
                entities.S_I_ProjectGroup.Add(child);
            }
        }
示例#2
0
        /// <summary>
        /// 绑定管理单元
        /// </summary>
        /// <param name="projectInfo">管理单元项目对象</param>
        public void BindingProject(S_I_ProjectInfo projectInfo)
        {
            var baseConfigEntities = this.GetDbContext <BaseConfigEntities>();
            var projectEntities    = this.GetDbContext <ProjectEntities>();

            if (!String.IsNullOrEmpty(projectInfo.GroupID))
            {
                var groupInfo = projectEntities.S_I_ProjectGroup.FirstOrDefault(d => d.ID == projectInfo.GroupID);
                if (groupInfo != null)
                {
                    throw new Formula.Exceptions.BusinessException("已经绑定了EPS的项目不能进行重复绑定");
                }
            }
            projectInfo.EngineeringInfoID = this.RelateID;

            var type       = EngineeringSpaceType.UnderEngineering.ToString();
            var epsDefines = baseConfigEntities.Set <S_D_EPSDef>().Where(d => d.Type == type).OrderBy(d => d.FullID).ToList();

            if (this.Children.Count == 0 || epsDefines.Count == 0)
            {
                var project = new S_I_ProjectGroup();
                project.ID             = FormulaHelper.CreateGuid();
                project.Name           = projectInfo.Name;
                project.Code           = projectInfo.Code;
                project.DeptID         = projectInfo.ChargeDeptID;
                project.DeptName       = projectInfo.ChargeDeptName;
                project.City           = this.City;
                project.ProjectClass   = string.IsNullOrEmpty(this.ProjectClass) ? projectInfo.ProjectClass : this.ProjectClass;
                project.Address        = this.Address;
                project.Country        = this.Country;
                project.Proportion     = this.Proportion;
                project.Province       = this.Province;
                project.RelateID       = this.RelateID;
                project.Type           = EngineeringSpaceType.Project.ToString();
                project.ChargeUserName = projectInfo.ChargeUserName;
                project.ChargeUser     = projectInfo.ChargeUserID;
                project.PhaseContent   = projectInfo.PhaseName;
                project.PhaseValue     = projectInfo.PhaseValue;
                project.State          = projectInfo.State;
                this.AddChild(project);
                projectInfo.GroupID     = project.ID;
                projectInfo.GroupRootID = project.RootID;
                projectInfo.GroupFullID = project.FullID;
            }
            else
            {
                var list = new List <S_I_ProjectGroup>();
                foreach (var item in epsDefines)
                {
                    #region
                    var propertyInfoValue = projectInfo.GetPropertyString(item.GroupField);
                    var eps = projectEntities.S_I_ProjectGroup.FirstOrDefault(d => d.DefineID == item.ID && d.Name == propertyInfoValue && d.FullID.StartsWith(this.FullID));
                    if (eps == null)
                    {
                        eps          = projectEntities.S_I_ProjectGroup.Create();
                        eps.Type     = EngineeringSpaceType.UnderEngineering.ToString();
                        eps.ID       = FormulaHelper.CreateGuid();
                        eps.Name     = propertyInfoValue;
                        eps.DefineID = item.ID;
                        if (item.Parent == null)
                        {
                            throw new Formula.Exceptions.BusinessException();
                        }
                        if (item.Parent.Type == EngineeringSpaceType.Engineering.ToString())
                        {
                            eps.RelateID = this.RelateID;
                            eps.Type     = EngineeringSpaceType.UnderEngineering.ToString();
                            this.AddChild(eps);
                        }
                        else
                        {
                            var parentValue = projectInfo.GetPropertyString(item.Parent.GroupField);
                            var parentEps   = list.FirstOrDefault(d => d.DefineID == item.ParentID && d.Name == parentValue);
                            if (parentEps != null)
                            {
                                parentEps.AddChild(eps);
                            }
                        }
                    }
                    list.Add(eps);
                    if (item.Children.Count == 0)
                    {
                        var project = new S_I_ProjectGroup();
                        project.ID             = FormulaHelper.CreateGuid();
                        project.Name           = projectInfo.Name;
                        project.Code           = projectInfo.Code;
                        project.DeptID         = projectInfo.ChargeDeptID;
                        project.DeptName       = projectInfo.ChargeDeptName;
                        project.City           = this.City;
                        project.ProjectClass   = this.ProjectClass;
                        project.Address        = this.Address;
                        project.Country        = this.Country;
                        project.Proportion     = this.Proportion;
                        project.Province       = this.Province;
                        project.RelateID       = this.RelateID;
                        project.Type           = EngineeringSpaceType.Project.ToString();
                        project.ChargeUserName = project.ChargeUserName;
                        project.ChargeUserName = projectInfo.ChargeUserName;
                        project.ChargeUser     = projectInfo.ChargeUserID;
                        project.PhaseValue     = projectInfo.PhaseValue;
                        project.State          = projectInfo.State;
                        eps.AddChild(project);
                        projectInfo.GroupID     = project.ID;
                        projectInfo.GroupRootID = project.RootID;
                        projectInfo.GroupFullID = project.FullID;
                    }
                    #endregion
                }
            }
        }