public static GetTempConnection ( ) : IDbConnection | ||
Résultat | IDbConnection |
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 }
public static void ManageDatasetConstraints(bool @switch) { IDbConnection conn = GisaDataSetHelper.GetTempConnection(); conn.Open(); try { #if DEBUG long start = DateTime.Now.Ticks; try { GisaDataSetHelper.GetInstance().EnforceConstraints = @switch; } catch (ConstraintException ex) { Trace.WriteLine("<EnforceContraints>"); Trace.WriteLine(ex.ToString()); GisaDataSetHelper.FixDataSet(GisaDataSetHelper.GetInstance(), conn); } catch (Exception e) { Trace.WriteLine(e.ToString()); throw; } if (@switch) Trace.WriteLine("EnforceContraints: " + new TimeSpan(DateTime.Now.Ticks - start).ToString()); #else if (GisaDataSetHelper.GetInstance().EnforceConstraints) { //Trace.WriteLine("RELEASE MODE: EnforceConstraints = TRUE"); GisaDataSetHelper.GetInstance().EnforceConstraints = false; } #endif } finally { conn.Close(); } }