////////////////////////////////////////////////////////// public CArbreTable IntegreRelation(CInfoRelationComposantFiltre relation, bool bIsLeftOuter, int nIdGroupeRelation) { foreach (CArbreTableFille arbre in m_listeTablesLiees) { if (arbre.Relation.RelationKey == relation.RelationKey && arbre.Relation.IsRelationFille == relation.IsRelationFille && arbre.IdGroupeRelation == nIdGroupeRelation) { if (bIsLeftOuter && !arbre.IsLeftOuter) { arbre.IsLeftOuter = bIsLeftOuter; } return(arbre); } } //la table dépendante n'existe pas string strIdAlias = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; string strNumAlias = strIdAlias[m_listeTablesLiees.Count] + ""; CArbreTableFille arbreNew = new CArbreTableFille(this, relation, RacineAliasFils + strNumAlias); arbreNew.IsLeftOuter = bIsLeftOuter; arbreNew.IdGroupeRelation = nIdGroupeRelation; m_listeTablesLiees.Add(arbreNew); return(arbreNew); }
/// //////////////////////////////////////////////////////////////// public static void FindRelation(string strTable, Type type, ref CInfoRelationComposantFiltre relationTrouvee) { //TESTDBKEYTODO if (relationTrouvee != null) { return; } string strKeyChamp = ""; if (DecomposeNomPropriete(strTable, ref strKeyChamp)) { string strTableEntite = CContexteDonnee.GetNomTableForType(type); //Si strKeyChamp est un int, il s'agit d'un id de champ custom //ce cas peut se présenter lors de la relecture d'un filtre sous forme de //test par exemple dans une fonction ObjectList relationTrouvee = new CInfoRelationEValeurChampCustomToDisplay(CDbKey.CreateFromStringValue(strKeyChamp), strTableEntite); } //relationTrouvee = new CInfoRelationEValeurChampCustomToDisplay(relToChamp.DbKeyChamp, relToChamp.TableFille); }
/// //////////////////////////////////////////////////////////////// public static void FindRelation(string strTable, Type type, ref CInfoRelationComposantFiltre relationTrouvee) { if (relationTrouvee != null) //déjà trouvée { return; } string[] strZones = strTable.Split('_'); if (strZones[0] != c_cleDonnee) { return; } //Oui, c'en est une try { int nIdTypeDonnee = Int32.Parse(strZones[1]); int nNumeroCle = Int32.Parse(strZones[2]); relationTrouvee = new CInfoRelationComposantFiltreDonneeCumulee(nIdTypeDonnee, nNumeroCle, CContexteDonnee.GetNomTableForType(type)); } catch {} }
/// //////////////////////////////////////////////////////////////// public static void FindRelation(string strTable, Type type, ref CInfoRelationComposantFiltre relationTrouvee) { if (relationTrouvee != null) { return; } string strPropDef = ""; string strCleDef = ""; if (CDefinitionProprieteDynamique.DecomposeNomProprieteUnique(strTable, ref strCleDef, ref strPropDef)) { if (strCleDef != c_strCleType) { return; } CStructureTable structure = CStructureTable.GetStructure(type); foreach (CInfoRelation relation in structure.RelationsFilles) { if (relation.Propriete == strPropDef) { relationTrouvee = new CInfoRelationComposantFiltreStd( relation, true, 0); return; } } foreach (CInfoRelation relation in structure.RelationsParentes) { if (relation.Propriete == strPropDef) { relationTrouvee = new CInfoRelationComposantFiltreStd( relation, false, 0); return; } } } }
///////////////////////////////////////////////////////////////////////////////////// public override void CreateJoinPourLiens( CFiltreData filtre, CArbreTable arbreTables, CComposantFiltre composantFiltre, ref bool bDistinct, ref string strJoin, ref string strWhere, ref string strPrefixeFrom) { strJoin = ""; arbreTables.SortTablesLiees(); foreach (CArbreTableFille arbreFils in arbreTables.TablesLiees) { strPrefixeFrom += "("; if (arbreFils.IsLeftOuter) { strJoin += " LEFT OUTER JOIN "; } else { strJoin += " INNER JOIN "; } if (arbreFils.Relation.IsRelationFille) { bDistinct = true; } string strTable; strTable = CContexteDonnee.GetNomTableInDbForNomTable(arbreFils.NomTable) + GetSqlForAliasDecl(arbreFils.Alias); string strSuiteFrom = ""; string strSuiteWhere = ""; string strPrefixe = ""; CreateJoinPourLiens(filtre, arbreFils, composantFiltre, ref bDistinct, ref strSuiteFrom, ref strSuiteWhere, ref strPrefixe); strJoin += strPrefixe; if (strSuiteFrom.Trim() != "") { strTable = "(" + strTable; } strTable += strSuiteFrom; if (strSuiteFrom.Trim() != "") { strTable += ")"; } strJoin += strTable; strJoin += " ON ("; CInfoRelationComposantFiltre relation = arbreFils.Relation; string strAliasParent, strAliasFille; string strTableDependante = ""; if (relation.IsRelationFille) { strAliasParent = arbreTables.Alias; strAliasFille = arbreFils.Alias; strTableDependante = arbreFils.NomTable; } else { strAliasParent = arbreFils.Alias; strAliasFille = arbreTables.Alias; strTableDependante = arbreTables.NomTable; } string strJointure = relation.GetJoinClause(strAliasParent, "", strAliasFille, ""); string strComplementVersion = ""; if (EstCeQueLaTableGereLesVersions(strTableDependante) && !filtre.IntegrerLesElementsSupprimes) { strComplementVersion = "(" + strAliasFille + "." + CSc2iDataConst.c_champIsDeleted + "=0 or " + strAliasFille + "." + CSc2iDataConst.c_champIsDeleted + " is null)"; } string strIdsVersionsALire = filtre.GetStringListeIdsVersionsALire(','); if (EstCeQueLaTableGereLesVersions(strTableDependante)) { if (strComplementVersion != "") { strComplementVersion += " and "; } if (strIdsVersionsALire == null) { strComplementVersion += strAliasFille + "." + CSc2iDataConst.c_champIdVersion + " is null"; } else { strComplementVersion += "(" + strAliasFille + "." + CSc2iDataConst.c_champIdVersion + " in (" + strIdsVersionsALire + ") or " + strAliasFille + "." + CSc2iDataConst.c_champIdVersion + " is null)"; } } if (strComplementVersion != "") { if (strWhere != "") { strWhere += " and (" + strComplementVersion + ") and ("; } else { strWhere += "("; } strWhere += strComplementVersion + ")"; } strJoin += strJointure + "))"; if (composantFiltre != null) { composantFiltre.DefinitAlias(arbreFils.CheminRelations, arbreFils.Alias); } if (filtre is CFiltreDataAvance) { foreach (CComposantFiltreChamp champ in ((CFiltreDataAvance)filtre).ChampsAAjouterAArbreTable) { champ.DefinitAlias(arbreFils.CheminRelations, arbreFils.Alias); } } } }
/// ///////////////////////////////////////////////////// public override void CreateJoinPourLiens( CFiltreData filtre, CArbreTable arbreTables, CComposantFiltre composantFiltre, ref bool bDistinct, ref string strFrom, ref string strWhere) { strFrom = ""; strWhere = ""; foreach (CArbreTableFille arbreFils in arbreTables.TablesLiees) { if (arbreFils.Relation.IsRelationFille) { bDistinct = true; } string strNomTableFils = CContexteDonnee.GetNomTableInDbForNomTable(arbreFils.NomTable); strNomTableFils = GetPrefixeForTable(arbreFils.NomTable) + strNomTableFils; strFrom += "," + strNomTableFils + GetSqlForAliasDecl(arbreFils.Alias); string strSuiteFrom = ""; string strSuiteWhere = ""; CreateJoinPourLiens(filtre, arbreFils, composantFiltre, ref bDistinct, ref strSuiteFrom, ref strSuiteWhere); if (strSuiteFrom != "") { strFrom += strSuiteFrom; } if (strWhere.Trim() != "" && strSuiteWhere.Trim() != "") { strWhere += " and (" + strSuiteWhere + ")"; } if (strWhere.Trim() == "" && strSuiteWhere.Trim() != "") { strWhere = strSuiteWhere; } //Equivalence WHERE ( MACOL = MACOL (+)) CInfoRelationComposantFiltre relation = arbreFils.Relation; string strAliasParent, strAliasFille; string strSuffixeParent = ""; string strSuffixeFils = ""; string strTableDependante = ""; if (relation.IsRelationFille) { strAliasParent = arbreTables.Alias; strAliasFille = arbreFils.Alias; strTableDependante = arbreFils.NomTable; if (arbreFils.IsLeftOuter) { strSuffixeFils = "(+)"; } } else { strAliasParent = arbreFils.Alias; strAliasFille = arbreTables.Alias; strTableDependante = arbreTables.Alias; if (arbreFils.IsLeftOuter) { strSuffixeParent = "(+)"; } } string strTmp = relation.GetJoinClause(strAliasParent, strSuffixeParent, strAliasFille, strSuffixeFils); string strComplementVersion = ""; if (EstCeQueLaTableGereLesVersions(strTableDependante) && !filtre.IntegrerLesElementsSupprimes) { strComplementVersion = "(" + strAliasFille + "." + CSc2iDataConst.c_champIsDeleted + "=0 or " + strAliasFille + "." + CSc2iDataConst.c_champIsDeleted + " is null)"; } string strIdsVersionsALire = filtre.GetStringListeIdsVersionsALire(','); if (EstCeQueLaTableGereLesVersions(strTableDependante)) { if (strComplementVersion != "") { strComplementVersion += " and "; } if (strIdsVersionsALire == null) { strComplementVersion += strAliasFille + "." + CSc2iDataConst.c_champIdVersion + " is null"; } else { strComplementVersion += "(" + strAliasFille + "." + CSc2iDataConst.c_champIdVersion + " in (" + strIdsVersionsALire + ") or " + strAliasFille + "." + CSc2iDataConst.c_champIdVersion + " is null)"; } } if (strComplementVersion != "") { if (strTmp != "") { strTmp = "((" + strTmp + ") and "; } else { strAliasFille += "("; } strTmp += strComplementVersion + ")"; } if (strWhere.Trim() != "") { strWhere = "(" + strTmp + ") and (" + strWhere + ")"; } else { strWhere = strTmp; } if (composantFiltre != null) { composantFiltre.DefinitAlias(arbreFils.CheminRelations, arbreFils.Alias); } } }
/// /////////////////////////////////////////////////////// public CArbreTableFille(CArbreTable parent, CInfoRelationComposantFiltre relation, string strAlias) { m_infoRelation = relation; Alias = strAlias; m_parent = parent; }