Example #1
0
 /// <summary>
 /// 更新组织机构隶属组织机构
 /// </summary>
 /// <param name="organizationUnitId"></param>
 /// <param name="parentOUId"></param>
 /// <returns></returns>
 public AuthorizationDS.OrganizationUnitRow SetOrganizationUnitParentOU(int organizationUnitId, int?parentOUId)
 {
     if (parentOUId != null)
     {
         if (!this.DS.OrganizationUnit.FindByOrganizationUnitId(parentOUId.GetValueOrDefault()).IsActive)
         {
             throw new ApplicationException("组织机构处于非激活状态,不能迁移");
         }
     }
     AuthorizationDS.OrganizationUnitRow ou = this.DS.OrganizationUnit.FindByOrganizationUnitId(organizationUnitId);
     if (parentOUId == null)
     {
         ou.SetParentOrganizationUnitIdNull();
         ou.OrganizationLevel = 0;
     }
     else
     {
         ou.ParentOrganizationUnitId = parentOUId.GetValueOrDefault();
         AuthorizationDS.OrganizationUnitRow parentOR = OrganizationUnitTA.GetDataById(parentOUId.GetValueOrDefault())[0];
         ou.OrganizationLevel = parentOR.OrganizationLevel + 1;
     }
     this.OrganizationUnitTA.Update(ou);
     this.BuildOUOrganizationTreePath(ou);
     return(ou);
 }
Example #2
0
 /// <summary>
 /// 添加组织机构
 /// </summary>
 /// <param name="organizationUnitName"></param>
 /// <param name="organizationUnitCode"></param>
 /// <param name="parentUnitId"></param>
 /// <param name="organizationUnitTypeId"></param>
 /// <returns></returns>
 public AuthorizationDS.OrganizationUnitRow AddOrganizationUnit(string organizationUnitName, string organizationUnitCode, int?parentUnitId, int?organizationUnitTypeId, int?CostCenterID)
 {
     AuthorizationDS.OrganizationUnitRow result = this.DS.OrganizationUnit.NewOrganizationUnitRow();
     result.OrganizationUnitName = organizationUnitName;
     result.OrganizationUnitCode = organizationUnitCode;
     result.IsActive             = true;
     if (parentUnitId != null)
     {
         result.ParentOrganizationUnitId = parentUnitId.GetValueOrDefault();
         AuthorizationDS.OrganizationUnitRow parentOR = OrganizationUnitTA.GetDataById(parentUnitId.GetValueOrDefault())[0];
         result.OrganizationLevel = parentOR.OrganizationLevel + 1;
     }
     else
     {
         result.OrganizationLevel = 0;
     }
     if (organizationUnitTypeId != null)
     {
         result.OrganizationUnitTypeId = organizationUnitTypeId.GetValueOrDefault();
     }
     if (CostCenterID != null)
     {
         result.CostCenterID = CostCenterID.GetValueOrDefault();
     }
     this.DS.OrganizationUnit.AddOrganizationUnitRow(result);
     this.OrganizationUnitTA.Update(result);
     this.BuildOUOrganizationTreePath(result);
     return(result);
 }
Example #3
0
 /// <summary>
 /// 设置组织机构的激活状态,激活时只激活该组织机构,冻结时冻结该组织机构以及下属机构和职务
 /// </summary>
 /// <param name="organizationUnitId"></param>
 /// <param name="isActive"></param>
 /// <returns></returns>
 /// <exception cref="System.ApplicationException">如果该组织结构的上级机构没激活,激活该组织机构抛出异常</exception>
 public AuthorizationDS.OrganizationUnitRow ActiveOrganizationUnit(int organizationUnitId, bool isActive)
 {
     AuthorizationDS.OrganizationUnitRow ou = this.DS.OrganizationUnit.FindByOrganizationUnitId(organizationUnitId);
     if (isActive && !ou.IsActive)
     {
         if (ou.IsParentOrganizationUnitIdNull() || ou.OrganizationUnitRowParent.IsActive)
         {
             ou.IsActive = true;
             this.OrganizationUnitTA.Update(ou);
         }
         else
         {
             throw new ApplicationException("请先启用上级组织机构");
         }
     }
     else if (ou.IsActive && !isActive)
     {
         foreach (AuthorizationDS.OrganizationUnitRow childOU in GetDepFirstChildren(ou))
         {
             foreach (AuthorizationDS.PositionRow position in childOU.GetPositionRows())
             {
                 position.IsActive = false;
             }
             childOU.IsActive = false;
         }
         this.OrganizationUnitTA.Update(this.DS.OrganizationUnit);
         this.PositionTA.Update(this.DS.Position);
     }
     return(ou);
 }
Example #4
0
        /// <summary>
        /// 深度优先获取子组织结构
        /// </summary>
        /// <param name="ou"></param>
        /// <returns></returns>
        private AuthorizationDS.OrganizationUnitRow[] GetDepFirstChildren(AuthorizationDS.OrganizationUnitRow ou)
        {
            List <AuthorizationDS.OrganizationUnitRow> result = new List <AuthorizationDS.OrganizationUnitRow>();

            foreach (AuthorizationDS.OrganizationUnitRow childOu in ou.GetChildren())
            {
                result.AddRange(GetDepFirstChildren(childOu));
            }
            result.Add(ou);
            return(result.ToArray());
        }
Example #5
0
        /// <summary>
        /// 获取从根开始的上级机构链
        /// </summary>
        /// <param name="ouId"></param>
        /// <returns></returns>
        public List <BusinessObjects.AuthorizationDS.OrganizationUnitRow> GetParentOUsOfOU(int ouId)
        {
            List <AuthorizationDS.OrganizationUnitRow> result = new List <AuthorizationDS.OrganizationUnitRow>();

            AuthorizationDS.OrganizationUnitRow ou = this.DS.OrganizationUnit.FindByOrganizationUnitId(ouId);
            ou = ou.OrganizationUnitRowParent;
            while (ou != null)
            {
                result.Add(ou);
                ou = ou.OrganizationUnitRowParent;
            }
            return(result);
        }
Example #6
0
        /// <summary>
        /// 构建机构的机构路径
        /// </summary>
        /// <param name="ou"></param>
        public void BuildOUOrganizationTreePath(BusinessObjects.AuthorizationDS.OrganizationUnitRow ou)
        {
            StringBuilder path = new StringBuilder();

            AuthorizationDS.OrganizationUnitRow parent = ou.OrganizationUnitRowParent;
            if (parent != null)
            {
                path.Append(parent.OrganizationTreePath);
                path.Append("P" + parent.OrganizationUnitId + "P ");
            }
            ou.OrganizationTreePath = path.ToString();
            this.OrganizationUnitTA.Update(ou);

            foreach (BusinessObjects.AuthorizationDS.PositionRow position in ou.GetPositionRows())
            {
                BuildPositionOrganizationTreePath(position);
            }

            foreach (AuthorizationDS.OrganizationUnitRow childOU in ou.GetOrganizationUnitRows())
            {
                BuildOUOrganizationTreePath(childOU);
            }
        }
Example #7
0
 /// <summary>
 /// 更新组织机构基本信息
 /// </summary>
 /// <param name="organizationUnitId"></param>
 /// <param name="ouName"></param>
 /// <param name="ouCode"></param>
 /// <param name="organizationUnitTypeId"></param>
 /// <returns></returns>
 public AuthorizationDS.OrganizationUnitRow UpdateOrganizationUnit(int organizationUnitId, string ouName, string ouCode, int?organizationUnitTypeId, int?CostCenterID)
 {
     AuthorizationDS.OrganizationUnitRow ou = this.DS.OrganizationUnit.FindByOrganizationUnitId(organizationUnitId);
     ou.OrganizationUnitName = ouName;
     ou.OrganizationUnitCode = ouCode;
     if (organizationUnitTypeId == null)
     {
         ou.SetOrganizationUnitTypeIdNull();
     }
     else
     {
         ou.OrganizationUnitTypeId = organizationUnitTypeId.GetValueOrDefault();
     }
     if (CostCenterID == null)
     {
         ou.SetCostCenterIDNull();
     }
     else
     {
         ou.CostCenterID = CostCenterID.GetValueOrDefault();
     }
     this.OrganizationUnitTA.Update(ou);
     return(ou);
 }
Example #8
0
        /// <summary>
        /// 删除组织机构,同时上次该组织机构的下属机构和职务
        /// </summary>
        /// <param name="organizationUnitId"></param>
        /// <exception cref="System.ApplicationException">如果该组织机构或者其下属机构和职务已经被使用,被关联时抛出异常</exception>
        public void DeleteOrganizationUnit(int organizationUnitId)
        {
            SqlTransaction transaction = null;

            AuthorizationDS.OrganizationUnitRow ou = this.DS.OrganizationUnit.FindByOrganizationUnitId(organizationUnitId);
            string  ouName = ou.OrganizationUnitName;
            DataSet backDS = this.DS.Copy();

            try {
                PositionTableAdapter                positionAdapter = new PositionTableAdapter();
                OrganizationUnitTableAdapter        ouAdapter       = new OrganizationUnitTableAdapter();
                PositionAndPositionTypeTableAdapter ptAd            = new PositionAndPositionTypeTableAdapter();
                transaction = TableAdapterHelper.BeginTransaction(positionAdapter);
                TableAdapterHelper.SetTransaction(ouAdapter, transaction);
                TableAdapterHelper.SetTransaction(ptAd, transaction);

                //action on backDS and database first
                AuthorizationDS actionDS = new AuthorizationDS();
                actionDS.Merge(backDS);
                AuthorizationDS.OrganizationUnitRow   actionOU  = actionDS.OrganizationUnit.FindByOrganizationUnitId(organizationUnitId);
                AuthorizationDS.OrganizationUnitRow[] actionOUs = this.GetDepFirstChildren(actionOU);
                foreach (AuthorizationDS.OrganizationUnitRow o in actionOUs)
                {
                    foreach (AuthorizationDS.PositionRow position in o.GetPositionRows())
                    {
                        foreach (AuthorizationDS.PositionAndPositionTypeRow positionType in position.GetPositionAndPositionTypeRows())
                        {
                            positionType.Delete();
                        }
                        position.Delete();
                    }
                    o.Delete();
                    ptAd.Update(actionDS.PositionAndPositionType);
                    positionAdapter.Update(actionDS.Position);
                    ouAdapter.Update(actionDS.OrganizationUnit);
                }
                transaction.Commit();

                //if success update dataset

                AuthorizationDS.OrganizationUnitRow[] ous = this.GetDepFirstChildren(ou);
                foreach (AuthorizationDS.OrganizationUnitRow o in ous)
                {
                    foreach (AuthorizationDS.PositionRow position in o.GetPositionRows())
                    {
                        foreach (AuthorizationDS.PositionAndPositionTypeRow positionType in position.GetPositionAndPositionTypeRows())
                        {
                            positionType.Delete();
                        }
                        position.Delete();
                    }
                    o.Delete();
                    //ptAd.Update(this.DS.PositionAndPositionType);
                    //positionAdapter.Update(this.DS.Position);
                    //ouAdapter.Update(this.DS.OrganizationUnit);
                    this.DS.AcceptChanges();
                }
            } catch (Exception ex) {
                transaction.Rollback();
                //this.DS.Clear();
                //this.DS.Merge(backDS);
                throw new ApplicationException("组织机构" + ouName + "或者分支机构,职位已被使用");
            } finally {
                transaction.Dispose();
            }
        }