示例#1
0
        public static bool isRemovable(GISADataset.NivelRow NivelRow, GISADataset.NivelRow NivelUpperRow, bool countUFs)
        {
            string filter = string.Empty;

            if (!countUFs)
            {
                filter = string.Format("rh.IDTipoNivelRelacionado != {0:d}", TipoNivelRelacionado.UF);
            }

            int  parentCount          = 0;
            int  directChildCount     = 0;
            bool moreThenOneParent    = false;
            bool notExistsDirectChild = false;
            bool connectionClose      = false;

            if (GisaDataSetHelper.GetConnection().State == ConnectionState.Closed)
            {
                connectionClose = true;
                GisaDataSetHelper.HoldOpen ho = new GisaDataSetHelper.HoldOpen(GisaDataSetHelper.GetTempConnection());
                try
                {
                    parentCount          = DBAbstractDataLayer.DataAccessRules.NivelRule.Current.getParentCount(NivelRow.ID.ToString(), ho.Connection);
                    directChildCount     = DBAbstractDataLayer.DataAccessRules.NivelRule.Current.getDirectChildCount(NivelRow.ID.ToString(), filter, ho.Connection);
                    moreThenOneParent    = parentCount > 1;
                    notExistsDirectChild = directChildCount == 0;
                }
                catch (Exception ex)
                {
                    Trace.WriteLine(ex);
                    throw;
                }
                finally
                {
                    ho.Dispose();
                }
            }

            return(!(TipoNivel.isNivelOrganico(NivelRow) && TipoNivel.isNivelOrganico(NivelUpperRow)) &&
                   (TipoNivel.isNivelOrganico(NivelRow) ||
                    (NivelRow != null && NivelRow.IDTipoNivel == TipoNivel.LOGICO && notExistsDirectChild) ||
                    (TipoNivel.isNivelOrganico(NivelUpperRow) && connectionClose && !moreThenOneParent && notExistsDirectChild) ||
                    ((NivelUpperRow == null || NivelUpperRow.IDTipoNivel == TipoNivel.DOCUMENTAL) && connectionClose && notExistsDirectChild) ||
                    (NivelUpperRow != null && NivelUpperRow.IDTipoNivel == TipoNivel.ESTRUTURAL && NivelRow.IDTipoNivel == TipoNivel.DOCUMENTAL && connectionClose && notExistsDirectChild && !moreThenOneParent) //permitir apagar séries/documentos soltos só com um produtor e sem niveis descendentes
                   ));                                                                                                                                                                                            // o estado da ligação tem de se ser fechado para que não ocorram situações de deadlock na BD
        }
示例#2
0
        // utilizado no contexto das eliminações
        public static void verifyIfCanDeleteRH(PersistencyHelper.PreConcArguments args)
        {
            PersistencyHelper.canDeleteRHRowPreConcArguments cdrhPca = null;
            cdrhPca = (PersistencyHelper.canDeleteRHRowPreConcArguments)args;

            GISADataset.NivelRow nRow      = (GISADataset.NivelRow)(GisaDataSetHelper.GetInstance().Nivel.Select("ID=" + cdrhPca.nRowID.ToString())[0]);
            GISADataset.NivelRow nUpperRow = null;
            if (GisaDataSetHelper.GetInstance().Nivel.Select("ID=" + cdrhPca.nUpperRowID.ToString()).Length > 0)
            {
                nUpperRow = (GISADataset.NivelRow)(GisaDataSetHelper.GetInstance().Nivel.Select("ID=" + cdrhPca.nUpperRowID.ToString())[0]);
            }
            GISADataset.RelacaoHierarquicaRow rhRow = null;
            if (GisaDataSetHelper.GetInstance().RelacaoHierarquica.Select(string.Format("ID={0} AND IDUpper={1}", cdrhPca.rhRowID, cdrhPca.rhRowIDUpper)).Length > 0)
            {
                rhRow = (GISADataset.RelacaoHierarquicaRow)(GisaDataSetHelper.GetInstance().RelacaoHierarquica.Select(string.Format("ID={0} AND IDUpper={1}", cdrhPca.rhRowID, cdrhPca.rhRowIDUpper))[0]);
            }

            // Permitir apenas a eliminação de folhas e de níveis cuja
            // a funcionalidade eliminação não elimina o nível propriamente
            // dito mas sim a sua relação com o nível superior
            int  parentCount          = 0;
            int  directChildCount     = 0;
            bool moreThenOneParent    = false;
            bool notExistsDirectChild = false;

            parentCount          = DBAbstractDataLayer.DataAccessRules.NivelRule.Current.getParentCount(cdrhPca.nRowID.ToString(), cdrhPca.tran);
            directChildCount     = DBAbstractDataLayer.DataAccessRules.NivelRule.Current.getDirectChildCount(cdrhPca.nRowID.ToString(), string.Empty, cdrhPca.tran);
            moreThenOneParent    = parentCount > 1;
            notExistsDirectChild = directChildCount == 0;

            Trace.WriteLine("parentCount: " + parentCount.ToString());
            Trace.WriteLine("directChildCount: " + directChildCount.ToString());

            if (!(!(TipoNivel.isNivelOrganico(nRow) && TipoNivel.isNivelOrganico(nUpperRow)) && (TipoNivel.isNivelOrganico(nRow) || (TipoNivel.isNivelOrganico(nUpperRow) && moreThenOneParent) || (notExistsDirectChild))))
            {
                string filter = string.Format("rh.IDTipoNivelRelacionado != {0:d}", TipoNivelRelacionado.UF);
                parentCount          = DBAbstractDataLayer.DataAccessRules.NivelRule.Current.getParentCount(cdrhPca.nRowID.ToString(), cdrhPca.tran);
                directChildCount     = DBAbstractDataLayer.DataAccessRules.NivelRule.Current.getDirectChildCount(cdrhPca.nRowID.ToString(), filter, cdrhPca.tran);
                moreThenOneParent    = parentCount > 1;
                notExistsDirectChild = directChildCount == 0;

                Trace.WriteLine("parentCount: " + parentCount.ToString());
                Trace.WriteLine("directChildCount: " + directChildCount.ToString());

                cdrhPca.deleteSuccessful = false;
                cdrhPca.continueSave     = false;

                if (!(!(TipoNivel.isNivelOrganico(nRow) && TipoNivel.isNivelOrganico(nUpperRow)) && (TipoNivel.isNivelOrganico(nRow) || (TipoNivel.isNivelOrganico(nUpperRow) && moreThenOneParent) || (notExistsDirectChild))))
                {
                    cdrhPca.message = "Só é possível eliminar os níveis que não tenham outros níveis directamente associados";
                }
                else
                {
                    cdrhPca.message = "Existem unidades físicas associadas a este nível não podendo por isso ser eliminado.";
                }
            }
            else
            {
                //ToDo: simplificar este IF: o facto de rhrow ser nothing indica o caso onde é necessario executar o
                // o método DeleteInDataSet
                if (rhRow != null)
                {
                    System.Data.DataSet tempgisaBackup1 = cdrhPca.gisaBackup;
                    PersistencyHelper.BackupRow(ref tempgisaBackup1, rhRow);
                    cdrhPca.gisaBackup = tempgisaBackup1;
                    rhRow.Delete();
                }
                else
                {
                    Nivel.DeleteInDataSet(nRow, false, cdrhPca.gisaBackup); // é possível que esta linha não seja já precisa uma vez que o cleandeleteddata seguinte irá limpar do DS de trabalho as linhas que já não existam
                }
            }
        }