Exemple #1
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();
            }
        }
Exemple #2
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();
            }
        }