//---------------------------------------------------- public static string GetIdUniverselFromId(Type typeElement, int nId) { string strNomTable = CContexteDonnee.GetNomTableForType(typeElement); CStructureTable structure = CStructureTable.GetStructure(typeElement); C2iRequeteAvancee rq = new C2iRequeteAvancee(); rq.TableInterrogee = strNomTable; rq.FiltreAAppliquer = new CFiltreData( structure.ChampsId[0].NomChamp + "=@1", nId); rq.ListeChamps.Add(new C2iChampDeRequete( "UniversalId", new CSourceDeChampDeRequete(CObjetDonnee.c_champIdUniversel), typeof(string), OperationsAgregation.None, true)); CResultAErreur result = rq.ExecuteRequete(0); if (result && result.Data is DataTable) { DataTable table = result.Data as DataTable; if (table.Rows.Count > 0) { return((string)table.Rows[0][0]); } } return(""); }
//Journalise les données d'un élement public CVersionDonneesObjet JournaliseDonnees(System.Data.DataRow row, CVersionDonnees version) { CVersionDonneesObjet versionObjet = null; if (row.RowState != DataRowState.Added && row.RowState != DataRowState.Modified && row.RowState != DataRowState.Deleted) { return(null); } Type typeElement = CContexteDonnee.GetTypeForTable(row.Table.TableName); versionObjet = version.GetVersionObjetAvecCreation(row); if (versionObjet == null) { return(null); } if (row.HasVersion(DataRowVersion.Original)) { CStructureTable structure = CStructureTable.GetStructure(typeElement); foreach (CInfoChampTable info in structure.Champs) { if (info.m_bIsInDB) { new CJournaliseurChampDb().JournaliseDonneeInContexte(versionObjet, info.NomChamp, row); } } } return(versionObjet); }
/// ///////////////////////////////////// ////////////////////////////////// public CContexteDonnee CreateStructureFromTypes(params Type[] lesTypes) { ArrayList lstStructures = new ArrayList(); foreach (Type tp in lesTypes) { CStructureTable structure = CStructureTable.GetStructure(tp); lstStructures.Add(structure); } //Création des tables foreach (CStructureTable structure in lstStructures) { DataTable table = new DataTable(structure.NomTable); foreach (CInfoChampTable champ in structure.Champs) { DataColumn col = new DataColumn(champ.NomChamp); col.DataType = champ.TypeDonnee; if (champ.Longueur > 0) { col.MaxLength = champ.Longueur; } table.Columns.Add(col); } DataColumn[] cols = new DataColumn[structure.ChampsId.Length]; for (int nChamp = 0; nChamp < structure.ChampsId.Length; nChamp++) { cols[nChamp] = table.Columns[structure.ChampsId[nChamp].NomChamp]; } table.PrimaryKey = cols; m_contexte.Tables.Add(table); } //Les relations se créent toutes seules par le contexte de données return(m_contexte); }
public static CStructureTable GetStructure(Type leType) { CStructureTable structure = null; if (leType != null && m_tableTypeToStructure.ContainsKey(leType)) { structure = (CStructureTable)m_tableTypeToStructure[leType]; } if (structure != null) { return(structure); } structure = new CStructureTable(); structure.m_typeObjet = leType; m_tableTypeToStructure[leType] = structure; structure.FillFromType(leType); return(structure); }
public static List <CInfoTypeElementInDb> GetInfosInDatabase(int nIdSession) { List <CInfoTypeElementInDb> lst = new List <CInfoTypeElementInDb>(); foreach (Type tp in CContexteDonnee.GetAllTypes()) { CStructureTable structure = CStructureTable.GetStructure(tp); C2iRequeteAvancee requete = new C2iRequeteAvancee(); requete.TableInterrogee = CContexteDonnee.GetNomTableForType(tp); requete.ListeChamps.Add(new C2iChampDeRequete("NBELEMENTS", new CSourceDeChampDeRequete(structure.Champs[0].NomChamp), typeof(int), OperationsAgregation.Number, false)); CInfoTypeElementInDb info = new CInfoTypeElementInDb(tp); CResultAErreur result = requete.ExecuteRequete(nIdSession); if (result && result.Data is DataTable) { info.NbElements = (int)((DataTable)result.Data).Rows[0][0]; } if (!typeof(IObjetSansVersion).IsAssignableFrom(tp)) { requete.FiltreAAppliquer = new CFiltreData(CSc2iDataConst.c_champIdVersion + " is not null and " + CSc2iDataConst.c_champIsDeleted + "=@1", false); requete.FiltreAAppliquer.IgnorerVersionDeContexte = true; result = requete.ExecuteRequete(nIdSession); if (result && result.Data is DataTable) { info.NbElementsPrevisionnels = (int)((DataTable)result.Data).Rows[0][0]; } requete.FiltreAAppliquer = new CFiltreData(CSc2iDataConst.c_champIsDeleted + "=@1", true); requete.FiltreAAppliquer.IgnorerVersionDeContexte = true; result = requete.ExecuteRequete(nIdSession); if (result && result.Data is DataTable) { info.NbElementsSupprimes = (int)((DataTable)result.Data).Rows[0][0]; } } lst.Add(info); } return(lst); }
public List <IChampPourVersion> GetChampsJournalisables(CObjetDonneeAIdNumerique objet) { List <IChampPourVersion> champs = null; if (!m_dicTypeToChamps.TryGetValue(objet.GetType(), out champs)) { champs = new List <IChampPourVersion>(); CStructureTable structure = CStructureTable.GetStructure(objet.GetType()); CInfoChampTable[] allchamps = structure.Champs; List <string> lstChampsSys = CSc2iDataConst.GetNomsChampsSysteme(); foreach (CInfoChampTable c in allchamps) { if (c.m_bIsInDB && !lstChampsSys.Contains(c.NomChamp)) { champs.Add(new CChampPourVersionInDb(c.NomChamp, c.NomConvivial)); } } m_dicTypeToChamps[objet.GetType()] = champs; } return(champs); }
//----------------------------------------------------------------- public void AddFiltreSynchroPourTable(string strTable, IFiltreSynchronisation filtre, bool bAvecCompositions) { List <IFiltreSynchronisation> lstFiltres = null; if (!m_dicTableToFiltre.TryGetValue(strTable, out lstFiltres)) { lstFiltres = new List <IFiltreSynchronisation>(); m_dicTableToFiltre[strTable] = lstFiltres; } lstFiltres.Add(filtre); if (bAvecCompositions) { //trouve les compositions de la table et les filtre ! foreach (Type tp in CContexteDonnee.GetAllTypes()) { CStructureTable structure = CStructureTable.GetStructure(tp); if (structure != null) { foreach (CInfoRelation relParente in structure.RelationsParentes) { Type tpFils = CContexteDonnee.GetTypeForTable(relParente.TableFille); if (tpFils == null || tpFils.GetCustomAttributes(typeof(FullTableSyncAttribute), true).Length == 0) { if (relParente.Composition && relParente.TableParente == strTable && relParente.TableFille != strTable) { AddFiltreSynchroPourTable(structure.NomTable, new CFiltreSynchronisationFilsCompositions(structure.NomTable, strTable), true); } else if (relParente.TableFille == strTable && relParente.TableParente == strTable) { AddFiltreSynchroPourTable(structure.NomTable, new CFiltreSynchroFilsAutoreference(relParente.ChampsFille[0]), false); } } } } } } }
public void ReadArbre( CListeObjetsDonnees listeSource, CListeObjetsDonnees.CArbreProps arbre, List <string> lstPaquetsALire) { string strCle = ""; string strPropriete = ""; if (!CDefinitionProprieteDynamique.DecomposeNomProprieteUnique(arbre.ProprietePrincipale, ref strCle, ref strPropriete)) { strPropriete = arbre.ProprietePrincipale;//Mode sans DefinitionProprieteDynamique } Type typeObjets = listeSource.TypeObjets; Hashtable sousArbresToRemove = new Hashtable(); PropertyInfo info = typeObjets.GetProperty(strPropriete); if (info != null) { object[] attribs = info.GetCustomAttributes(typeof(OptimiseReadDependanceAttribute), true); if (attribs.Length != 0) { string strProp = ((OptimiseReadDependanceAttribute)attribs[0]).ProprieteALire; if (strProp.IndexOf('.') > 0) { string strSuite = strProp.Substring(strProp.IndexOf('.') + 1); strProp = strProp.Substring(0, strProp.IndexOf('.')); arbre.GetArbreSousProp(strSuite, true); } strPropriete = strProp; } } CStructureTable structure = CStructureTable.GetStructure(typeObjets); //Cherche la relation liée à la propriete bool bRelationTrouvee = false; foreach (CInfoRelation relation in structure.RelationsFilles) { if (relation.Propriete == strPropriete) { ReadDependanceFille( strPropriete, listeSource, arbre, relation, lstPaquetsALire); lstPaquetsALire = null; bRelationTrouvee = true; break; } } if (!bRelationTrouvee) { foreach (CInfoRelation relation in structure.RelationsParentes) { if (relation.Propriete == strPropriete) { ReadDependanceParente(strPropriete, listeSource, arbre, relation); bRelationTrouvee = true; } } } if (!bRelationTrouvee) { sousArbresToRemove[arbre] = true; } foreach (CListeObjetsDonnees.CArbreProps arbreTmp in sousArbresToRemove.Keys) { arbre.SousArbres.Remove(arbreTmp); } }
///////////////////////////////////////////////////////////// private void AddFields(Type leType, Hashtable tableIdsDefinisDansTableAttribute, Hashtable tableIds, bool bRelationsOnly) { if (leType == null) { return; } if (!bRelationsOnly) { //Relation vers la table Versions #region Relation vers la table versions if (!typeof(IObjetSansVersion).IsAssignableFrom(leType)) { CInfoChampTable champVersion = new CInfoChampTable(CSc2iDataConst.c_champIdVersion, typeof(int), 0, false, false, true, false, true); //Stef 06 10 2009 : le champ version n'est plus indexé seul, il est indexé //avec le champ deleted champVersion.IsIndex = true; champVersion.Propriete = "IdVersionDatabase"; m_listeChamps.Add(champVersion); m_tableChamps[champVersion.NomChamp] = champVersion; //Stef 29/08/2008 : suppression du lien à la version, trop lent ! /*CInfoRelation relationVersion = new CInfoRelation( * CVersionDonnees.c_nomTable, * NomTable, * new string[] { CVersionDonnees.c_champId }, * new string[] { champVersion.NomChamp }, * false, * true, * true, * false); * relationVersion.NomConvivial = "Version"; * m_listeRelationsParentes.Add(relationVersion);*/ CInfoChampTable champIdOriginal = new CInfoChampTable(CSc2iDataConst.c_champOriginalId, typeof(int), 0, false, false, true, false, true); champIdOriginal.IsIndex = true; m_listeChamps.Add(champIdOriginal); CInfoChampTable champIsDeleted = new CInfoChampTable(CSc2iDataConst.c_champIsDeleted, typeof(bool), 0, false, false, false, false, true); champIsDeleted.Propriete = "IsDeleted"; m_listeChamps.Add(champIsDeleted); //Stef 06 10 2009 : le champ version n'est plus indexé seul, il est indexé //avec le champ deleted /*CInfoIndexTable infoIndex = new CInfoIndexTable( * CSc2iDataConst.c_champIdVersion, CSc2iDataConst.c_champIsDeleted); * m_listeIndexsSupplementaires.Add(infoIndex);*/ } } #endregion foreach (PropertyInfo property in leType.GetProperties()) { string strNomConvivial = ""; object[] attribs; attribs = property.GetCustomAttributes(typeof(DynamicFieldAttribute), true); //si le champ a l'attribut dynamique, il a un nom convivial if (attribs.Length != 0) { strNomConvivial = ((DynamicFieldAttribute)attribs[0]).NomConvivial; } //Attribut TableField attribs = property.GetCustomAttributes(typeof(TableFieldPropertyAttribute), true); if (attribs.Length == 1 && !bRelationsOnly) { TableFieldPropertyAttribute attrib = (TableFieldPropertyAttribute)attribs[0]; if (attrib.IsInDb) //Ne prend que les champs qui sont dans la base de données { if (property.Name != "IdUniversel" || leType.GetCustomAttributes(typeof(NoIdUniverselAttribute), true).Length == 0) { if (property.PropertyType == typeof(string) && attrib.Longueur < 1) { throw (new Exception(I.T("The field attribute @1 of class @2 doesn't define a length|168", property.Name, leType.Name))); } bool bIsId = tableIdsDefinisDansTableAttribute[attrib.NomChamp] != null; CInfoChampTable info = new CInfoChampTable( attrib.NomChamp, property.PropertyType, attrib.Longueur, attrib.IsLongString, bIsId, attrib.NullAutorise && !bIsId, attrib.ExclureUpdateStandard, attrib.IsInDb); info.Propriete = property.Name; info.NomConvivial = strNomConvivial; if (property.GetCustomAttributes(typeof(IndexFieldAttribute), true).Length > 0) { info.IsIndex = true; } if (m_tableChamps[info.NomChamp] == null) { m_listeChamps.Add(info); m_tableChamps[info.NomChamp] = info; } if (bIsId) { tableIds[info.NomChamp] = info; } } } } //Attribut Relation if (bRelationsOnly) { m_bIsRelationsInitialisees = true; attribs = property.GetCustomAttributes(typeof(RelationAttribute), true); if (attribs.Length != 0) { RelationAttribute relAttrib = (RelationAttribute)attribs[0]; CStructureTable structureParente = GetStructure(CContexteDonnee.GetTypeForTable(relAttrib.TableMere)); if (relAttrib.TableMere == NomTable) //Pour les tables autoliées { structureParente = this; } //Si la structure parente est moi-même, les champs Id n'ont pas encore //été renseignés. Il y a donc un contrôle en moins sur les tables à lien récursif if (structureParente.ChampsId != null && relAttrib.ChampsFils.Length != relAttrib.ChampsParent.Length) { throw new Exception(I.T("The relation between the table @1 and the parental table @2 doesn't have the right number of link fields|169", NomTable, relAttrib.TableMere)); } int nIndexCle = 0; foreach (string strChamp in relAttrib.ChampsFils) { bool bIsId = tableIdsDefinisDansTableAttribute[strChamp] != null; CInfoChampTable info = new CInfoChampTable( strChamp, structureParente.GetChamp(relAttrib.ChampsParent[nIndexCle]).TypeDonnee, structureParente.GetChamp(relAttrib.ChampsParent[nIndexCle]).Longueur, false, bIsId, !relAttrib.Obligatoire, false, true); info.IsIndex = relAttrib.Index; //13/3/2005 : les deux lignes suivants avaient été enlevées. Pourquoi ? //En tout cas, moi j'en ai besoin pour pouvoir tester //Les attributs de la propriété //20/4/2005 //Ca avait été enlevé car le champ pointe sur le type de donnée //de la clé (un entier en général), c'est un champ qui ne doit pas être affiché //dans les listes de propriétés , c'est juste un champ de la table /*info.Propriete = property.Name; * info.NomConvivial = strNomConvivial;*/ /* 9/5/2005, si on souhaite trouver la propriété correspondantes, * il faut parcourir les relations et regarder les propriétés des relations * */ nIndexCle++; if (m_tableChamps[info.NomChamp] == null) { m_listeChamps.Add(info); m_tableChamps[info.NomChamp] = info; } if (tableIdsDefinisDansTableAttribute[strChamp] != null) { //Ce champ fait partie de la clé de l'objet tableIds[info.NomChamp] = info; } } CInfoRelation infoRelation = new CInfoRelation( relAttrib.TableMere, NomTable, relAttrib.ChampsParent, relAttrib.ChampsFils, relAttrib.Obligatoire, relAttrib.Composition, relAttrib.Index, relAttrib.PasserLesFilsANullLorsDeLaSuppression, relAttrib.DeleteEnCascadeManuel); infoRelation.IsInDb = relAttrib.IsInDb; infoRelation.IsClustered = relAttrib.IsCluster; infoRelation.NomConvivial = strNomConvivial; infoRelation.Propriete = property.Name; infoRelation.NePasClonerLesFils = relAttrib.NePasClonerLesFils; m_listeRelationsParentes.Add(infoRelation); } //Attribut RelationFille attribs = property.GetCustomAttributes(typeof(RelationFilleAttribute), true); if (attribs.Length != 0) { RelationFilleAttribute relFille = (RelationFilleAttribute)attribs[0]; PropertyInfo propParenteDansFille = relFille.TypeFille.GetProperty(relFille.ProprieteFille); if (propParenteDansFille == null) { throw new Exception(I.T("The @1 type defines a child relation on the child property @2.@3 which doesn't exist|170", leType.Name, relFille.TypeFille.Name, relFille.ProprieteFille)); } //Récupère les infos de la relation attribs = propParenteDansFille.GetCustomAttributes(typeof(RelationAttribute), true); if (attribs.Length != 1) { throw new Exception(I.T("The @1 type defines a child relation on the child property @2.@3 which doesn't define a parental relation|171", leType.Name, relFille.TypeFille.Name, relFille.ProprieteFille)); } RelationAttribute relInfo = (RelationAttribute)attribs[0]; //Récupère le nom de la table fille attribs = relFille.TypeFille.GetCustomAttributes(typeof(TableAttribute), true); if (attribs.Length != 1) { throw new Exception(I.T("The @1 type define a child relation on the @2 type which doesn't define a table|172", leType.Name, relFille.TypeFille.Name)); } object[] attr = property.GetCustomAttributes(typeof(DynamicChildsAttribute), false); if (attr.Length > 0) { strNomConvivial = ((DynamicChildsAttribute)attr[0]).NomConvivial; } CInfoRelation infoRelation = new CInfoRelation( NomTable, ((TableAttribute)attribs[0]).NomTable, relInfo.ChampsParent, relInfo.ChampsFils, relInfo.Obligatoire, relInfo.Composition, relInfo.Index, relInfo.PasserLesFilsANullLorsDeLaSuppression, relInfo.DeleteEnCascadeManuel); infoRelation.NomConvivial = strNomConvivial; infoRelation.Propriete = property.Name; infoRelation.NePasClonerLesFils = relInfo.NePasClonerLesFils; m_listeRelationsFilles.Add(infoRelation); } } } ///Relations TypeID foreach (RelationTypeIdAttribute relTypeId in CContexteDonnee.RelationsTypeIds) { if (relTypeId.IsAppliqueToType(leType)) { m_listeRelationsFillesTypeId.Add(relTypeId); } } //AddFields ( leType.BaseType, tableIdsDefinisDansTableAttribute, tableIds ); }