Example #1
0
        virtual public CResultAErreur CreateTable(CStructureTable structure)
        {
            CResultAErreur result = CResultAErreur.True;

            //Verification des noms
            result = CheckNomsStructureTable(structure);

            //Creation de la table
            result = result ? Connection.RunStatement(GetRequeteCreateTable(structure)) : result;
            AfterChangeChamps(structure.NomTableInDb);

            //Création des indexs
            result = result ? CreateTable_Indexs(structure) : result;

            //Creation Clé primaire
            result = result ? CreateTable_ClePrimaire(structure) : result;

            //Creation des contraintes de clés étrangères
            result = result ? CreateTable_ClesEtrangeres(structure) : result;

            if (!result)
            {
                result.EmpileErreur(I.T("Error while creating table @1|125", structure.NomTableInDb));
            }

            return(result);
        }
Example #2
0
        //----------------------------------------------------------------
        private static int GetNbUsedInDbForType(Type tp)
        {
            MethodInfo info = tp.GetMethod(c_MethodeCompteElementsInBase);

            if (info != null)
            {
                return((int)info.Invoke(null, new object[0]));
            }
            C2iRequeteAvancee requete   = new C2iRequeteAvancee();
            CStructureTable   structure = CStructureTable.GetStructure(tp);

            requete.TableInterrogee = structure.NomTable;
            C2iChampDeRequete champ = new C2iChampDeRequete(structure.ChampsId[0].NomChamp,
                                                            new CSourceDeChampDeRequete(structure.ChampsId[0].NomChamp),
                                                            typeof(int),
                                                            OperationsAgregation.Number,
                                                            false);

            requete.ListeChamps.Add(champ);
            requete.FiltreAAppliquer = new CFiltreData(CSc2iDataConst.c_champIdVersion + " is null");
            requete.FiltreAAppliquer.IgnorerVersionDeContexte     = true;
            requete.FiltreAAppliquer.IntegrerLesElementsSupprimes = false;
            CResultAErreur result = requete.ExecuteRequete(0);

            if (!result)
            {
                return(0);
            }
            DataTable table = result.Data as DataTable;

            return((int)table.Rows[0][0]);
        }
        ////////////////////////////////////////////////////
        public override IDbCommand GetSelectCommand(CStructureTable structure)
        {
            string strReq   = "";
            bool   bHasBlob = false;

            foreach (CInfoChampTable info in structure.Champs)
            {
                if (info.TypeDonnee == typeof(CDonneeBinaireInRow) || info.TypeDonnee.IsSubclassOf(typeof(CDonneeBinaireInRow)))
                {
                    bHasBlob = true;
                }
                else
                {
                    strReq += info.NomChamp + ",";
                }
            }

            if (bHasBlob && strReq.Length > 0)
            {
                strReq = "select " + strReq.Substring(0, strReq.Length - 1) + " from " + structure.NomTableInDb;
            }
            else
            {
                strReq = "select * from " + structure.NomTableInDb;
            }
            IDbCommand command = m_connexion.GetConnexion().CreateCommand();

            command.CommandText = strReq;
            command.Transaction = m_connexion.Transaction;
            return(command);
        }
Example #4
0
        public override sc2i.common.CResultAErreur ExecuterOperation(IDatabaseConnexion connection, sc2i.common.IIndicateurProgression indicateur)
        {
            CResultAErreur             result = CResultAErreur.True;
            CAccess97DatabaseConnexion cnx    = connection as CAccess97DatabaseConnexion;

            if (cnx == null)
            {
                return(result);
            }
            CAccessDataBaseCreator creator = cnx.GetDataBaseCreator() as CAccessDataBaseCreator;

            if (creator == null)
            {
                return(result);
            }
            foreach (Type tp in CContexteDonnee.GetAllTypes())
            {
                CStructureTable structure = CStructureTable.GetStructure(tp);
                if (structure != null && creator.TableExists(structure.NomTable))
                {
                    foreach (CInfoChampTable info in structure.Champs)
                    {
                        if (!info.NullAuthorized && !structure.ChampsId.Contains(info))
                        {
                            result = creator.SetValeursParDefautAuxDonneesNulles(structure.NomTable, info);
                            if (!result)
                            {
                                return(result);
                            }
                        }
                    }
                }
            }
            return(result);
        }
Example #5
0
        ////////////////////////////////////////////
        private void OnChangeExpression(string strTexte, ref C2iExpression expToSet, CComboboxAutoFilled combo)
        {
            CContexteAnalyse2iExpression ctx = new CContexteAnalyse2iExpression(ActionSynchronisme.Process, typeof(CProcess));
            CResultAErreur result            = new CAnalyseurSyntaxiqueExpression(ctx).AnalyseChaine(strTexte);

            if (result)
            {
                ArrayList lstChamps = new ArrayList();
                expToSet = (C2iExpression)result.Data;
                Type            tp        = expToSet.TypeDonnee.TypeDotNetNatif;
                CStructureTable structure = null;
                try
                {
                    structure = CStructureTable.GetStructure(tp);
                    ArrayList lst = new ArrayList();
                    foreach (CInfoChampTable champ in structure.Champs)
                    {
                        if (champ.TypeDonnee == typeof(DateTime) || champ.TypeDonnee == typeof(DateTime?))
                        {
                            lst.Add(champ);
                        }
                    }
                    //Cherche les champs custom
                    if (typeof(CElementAChamp).IsAssignableFrom(tp))
                    {
                        //Crée les infos champ custom pour le type
                        using (CContexteDonnee contexte = new CContexteDonnee(
                                   CSessionClient.GetSessionUnique().IdSession,
                                   true, false))
                        {
                            string strCodeRole = CRoleChampCustom.GetRoleForType(tp).CodeRole;
                            CListeObjetsDonnees listeChamps = CChampCustom.GetListeChampsForRole(
                                contexte, strCodeRole);
                            new CListeObjetsDonnees(contexte, typeof(CChampCustom));
                            listeChamps.Filtre = new CFiltreData(
                                CChampCustom.c_champType + "=@1",
                                (int)TypeDonnee.tDate);
                            foreach (CChampCustom champ in listeChamps)
                            {
                                CInfoChampTable info = new CInfoChampTable(
                                    CSynchronismeDonnees.c_idChampCustom + champ.Id.ToString(),
                                    typeof(DateTime),
                                    0,
                                    false,
                                    false,
                                    true,
                                    false,
                                    true);
                                info.NomConvivial = champ.Nom;
                                lst.Add(info);
                            }
                        }
                    }
                    combo.ListDonnees = lst;
                }
                catch
                {
                }
            }
        }
        //--------------------------------------------------------------
        private void m_btnAddFieldId_Click(object sender, EventArgs e)
        {
            IODEQTableFromFramework source = m_tableFromFramework.ElementsSource[0] as IODEQTableFromFramework;

            if (source != null)
            {
                CStructureTable structure            = CStructureTable.GetStructure(source.TypeElements);
                CColumnDeEasyQueryChampDeRequete col = new CColumnDeEasyQueryChampDeRequete("ID",
                                                                                            new CSourceDeChampDeRequete(structure.ChampsId[0].NomChamp),
                                                                                            typeof(int),
                                                                                            OperationsAgregation.None,
                                                                                            true);
                source.AddColonneDeRequete(col);
                CResultAErreur result = m_tableFromFramework.GetErreurIncompatibilitéTableParente();
                if (!result)
                {
                    m_panelSourceIncompatible.Visible = true;
                    m_lblImpossible.Text = result.Erreur.ToString();
                }
                else
                {
                    m_panelSourceIncompatible.Visible = false;
                }
            }
        }
        /// ///////////////////////////////////////////////////////
        public override string GetRequeteSelectForRead(IDatabaseConnexion connexion, params string[] strChampsARetourner)
        {
            CStructureTable structure   = CStructureTable.GetStructure(GetTypeObjets());
            string          strReq      = "";
            ArrayList       lstBlobs    = new ArrayList();
            string          strNomTable = structure.NomTableInDb;

            foreach (CInfoChampTable info in structure.Champs)
            {
                if (info.TypeDonnee != typeof(CDonneeBinaireInRow))
                {
                    strReq += strNomTable + "." + info.NomChamp + ",";
                }
                else
                {
                    lstBlobs.Add(info.NomChamp);
                }
            }
            lock (m_listeChampsBlobs)
            {
                m_listeChampsBlobs = lstBlobs;
            }
            if (strReq.Length > 0)
            {
                strReq = strReq.Substring(0, strReq.Length - 1);
            }
            strReq = "select " + strReq + " from " + GetNomTableInDb();
            return(strReq);
        }
Example #8
0
        //-------------------------------------------------------------------------------
        private void GereMetaProjetAsynchrone(DataRow row)
        {
            if (row.RowState == DataRowState.Modified && (bool)row[CMetaProjet.c_champAsynchronousUpdate])
            {
                List <string> lstChampsAAnnuler = new List <string>();
                lstChampsAAnnuler.Add(CMetaProjet.c_champDateDebutPlanifiee);
                lstChampsAAnnuler.Add(CMetaProjet.c_champDateFinPlanifiee);
                lstChampsAAnnuler.Add(CMetaProjet.c_champPctAvancement);
                lstChampsAAnnuler.Add(CMetaProjet.c_champPoidsFils);

                foreach (string strChamp in lstChampsAAnnuler)
                {
                    row[strChamp] = row[strChamp, DataRowVersion.Original];
                }
                //Vérifie que la ligne est toujours en état modifié
                CStructureTable structure   = CStructureTable.GetStructure(typeof(CMetaProjet));
                bool            bIsModified = false;
                foreach (CInfoChampTable champ in structure.Champs)
                {
                    if (champ.m_bIsInDB && row[champ.NomChamp] != row[champ.NomChamp, DataRowVersion.Original])
                    {
                        bIsModified = true;
                        break;
                    }
                }
                if (!bIsModified)
                {
                    row.RejectChanges();
                }
            }
            return;
        }
Example #9
0
        protected virtual string GetRequeteCreateTable(CStructureTable structure)
        {
            string strRequeteCreation = "CREATE TABLE " + structure.NomTableInDb + " (";

            //Déclaration du champ ID
            string strDeclarationId = GetDeclarationChampIdForCreateTable(structure);

            //Déclaration des champs
            string strDeclarationsChamps = GetDeclarationChampsForCreateTable(structure);

            if (strDeclarationId != "")
            {
                strRequeteCreation += strDeclarationId;
                if (strDeclarationsChamps != "")
                {
                    strRequeteCreation += ", " + strDeclarationsChamps;
                }
            }
            else
            {
                strRequeteCreation += strDeclarationsChamps;
            }

            return(strRequeteCreation + ")");
        }
        ////////////////////////////////////////////////////
        public virtual OleDbCommand GetSelectCommand(CStructureTable structure)
        {
            string strReq   = "";
            bool   bHasBlob = false;

            foreach (CInfoChampTable info in structure.Champs)
            {
                if (info.TypeDonnee == typeof(CDonneeBinaireInRow) || info.TypeDonnee.IsSubclassOf(typeof(CDonneeBinaireInRow)))
                {
                    bHasBlob = true;
                }
                else
                {
                    strReq += "[" + info.NomChamp + "],";
                }
            }
            if (bHasBlob && strReq.Length > 0)
            {
                strReq = "select " + strReq.Substring(0, strReq.Length - 1) + " from [" + structure.NomTableInDb + "]";
            }
            else
            {
                strReq = "select * from [" + structure.NomTableInDb + "]";
            }
            return(new OleDbCommand(strReq, (OleDbConnection)m_connexion.GetConnexion(), (OleDbTransaction)m_connexion.Transaction));
        }
        protected override string GetDeclarationChampIdForCreateTable(CStructureTable structure)
        {
            string strDeclaration = base.GetDeclarationChampIdForCreateTable(structure);

            strDeclaration = strDeclaration != ""? strDeclaration + " IDENTITY (1, 1)":"";
            return(strDeclaration);
        }
        ////////////////////////////////////////////////////////////////////////
        private void CreateFiltreForAllParents(Hashtable tableRelationsFaites)
        {
            CStructureTable structure = CStructureTable.GetStructure(CContexteDonnee.GetTypeForTable(NomTable));

            foreach (CInfoRelation relationParente in structure.RelationsParentes)
            {
                if (tableRelationsFaites[relationParente.RelationKey] == null)
                {
                    tableRelationsFaites[relationParente.RelationKey] = true;
                    CFiltreSynchronisation filtreFils = GetFilsForRelation(relationParente);
                    if (filtreFils == null)
                    {
                        filtreFils = new CFiltreSynchronisation(relationParente.TableParente);
                        filtreFils.m_bIsAutoAdd             = true;
                        filtreFils.IsLienToFullTableParente = TouteLaTable;
                        AddFils(filtreFils, relationParente);
                    }
                    filtreFils.CreateFiltreForAllParents((Hashtable)tableRelationsFaites.Clone());
                }
            }
            foreach (CFiltreSynchronisation filtreFils in m_listeFils)
            {
                if (tableRelationsFaites[filtreFils.RelationToParent.RelationKey] == null)
                {
                    tableRelationsFaites[filtreFils.RelationToParent.RelationKey] = true;
                    if (filtreFils.NomTable == filtreFils.RelationToParent.TableFille)
                    {
                        filtreFils.CreateFiltreForAllParents((Hashtable)tableRelationsFaites.Clone());
                    }
                }
            }
        }
Example #13
0
        /////////////////////////////////////////////////////////////////////////////////////
        public override int CountRecords(string strNomTableIndb, CFiltreData filtre)
        {
            filtre.SortOrder = "";
            string strNomTableInContexte = GetNomTableInContexteFromNomTableInDb(strNomTableIndb);
            Type   tp         = CContexteDonnee.GetTypeForTable(strNomTableInContexte);
            string strRequete = "";

            if (tp != null)
            {
                CStructureTable structure = CStructureTable.GetStructure(tp);
                if (structure.ChampsId.Length == 1)
                {
                    strRequete = "select count ( distinct " + strNomTableIndb + "." + structure.ChampsId[0].NomChamp + ") COMBIEN from " + strNomTableIndb;
                }
            }
            if (strRequete == "")
            {
                strRequete = "select count (*) COMBIEN from " + strNomTableIndb;
            }


            IDataAdapter adapter = GetSimpleReadAdapter(strRequete, filtre);

            DataSet ds = new DataSet();

            FillAdapter(adapter, ds);
            return(Convert.ToInt32(ds.Tables["Table"].Rows[0]["COMBIEN"]));
        }
Example #14
0
        public override CResultAErreur VerifieDonnees(bool bAuMomentDeLaSauvegarde)
        {
            CResultAErreur result = CResultAErreur.True;

            foreach (CRelationRoleActeur_GroupeActeur relRole in RelationsRoles)
            {
                if (relRole.IsNew())
                {
                    CRoleActeur     role      = (CRoleActeur)relRole.RoleActeur;
                    CStructureTable structure = CStructureTable.GetStructure(role.TypeDonneeActeur);
                    CFiltreData     filtre1   = new CFiltreData(
                        CGroupeActeur.c_champId + " = " + Id);
                    CFiltreDataAvance filtre2 = new CFiltreDataAvance(
                        structure.NomTable,
                        "Acteur.RelationsGroupes." + CGroupeActeur.c_champId + "=" + Id);
                    CListeObjetsDonnees liste = new CListeObjetsDonnees(ContexteDonnee, typeof(CRelationActeur_GroupeActeur));
                    liste.Filtre = filtre1;
                    int nb1 = liste.CountNoLoad;
                    liste        = new CListeObjetsDonnees(ContexteDonnee, relRole.RoleActeur.TypeDonneeActeur);
                    liste.Filtre = filtre2;
                    int nb2 = liste.CountNoLoad;
                    if (nb1 != nb2)
                    {
                        result.EmpileErreur(new CErreurValidation(I.T("This Group is related to '@1' Member(s) who does not have this Role. The Role will be applied to all these Members|283", (nb1 - nb2).ToString()), true));
                    }
                }
            }
            if (!result)
            {
                return(result);
            }
            return(base.VerifieDonnees(bAuMomentDeLaSauvegarde));
        }
Example #15
0
        protected virtual CResultAErreur CreateTable_ClesEtrangeres(CStructureTable structure)
        {
            CResultAErreur result = CResultAErreur.True;

            foreach (CInfoRelation rel in structure.RelationsParentes)
            {
                if (rel.IsInDb)
                {
                    string strRequeteRelation   = GetRequeteCreateCleEtrangere(rel);
                    string strNomTableFilleInDb = CContexteDonnee.GetNomTableInDbForNomTable(rel.TableFille);
                    result = Connection.RunStatement(strRequeteRelation);
                    if (result)
                    {
                        AfterChangeContraintes(strNomTableFilleInDb);
                    }
                    if (!result)
                    {
                        result.EmpileErreur(I.T("Error while creating foreign key of @1 (@2)|127", structure.NomTableInDb, strRequeteRelation));
                    }
                    else if (rel.Indexed && !IndexExists(strNomTableFilleInDb, rel.ChampsFille))
                    {
                        result = Connection.RunStatement(GetRequeteCreateIndex(strNomTableFilleInDb, rel.IsClustered, rel.ChampsFille));
                        if (!result)
                        {
                            result.EmpileErreur(I.T("Error while creating index in table @1|128", structure.NomTableInDb));
                        }
                        if (result)
                        {
                            AfterChangeIndexs(strNomTableFilleInDb);
                        }
                    }
                }
            }
            return(result);
        }
        /// ///////////////////////////////////////////////////////////
        protected virtual void GetDefinitionsChamps(Type tp, int nProfondeur, ArrayList lstProps, string strCheminConvivial, string strCheminReel, CDefinitionProprieteDynamique defParente)
        {
            if (nProfondeur < 0)
            {
                return;
            }

            CStructureTable structure = null;

            try
            {
                structure = CStructureTable.GetStructure(tp);
            }
            catch
            {
                return;
            }

            //Ajoute les relations parentes
            foreach (CInfoRelation relation in structure.RelationsParentes)
            {
                PropertyInfo propInfo = tp.GetProperty(relation.Propriete);
                if (propInfo != null)
                {
                    lstProps.Add(new CDefinitionProprieteDynamiqueRelation(
                                     strCheminConvivial + relation.NomConvivial,
                                     strCheminReel + relation.Propriete,
                                     relation,
                                     new CTypeResultatExpression(propInfo.PropertyType, false)));
                }
            }
            //Ajoute les relations filles
            foreach (CInfoRelation relation in structure.RelationsFilles)
            {
                PropertyInfo propInfo = tp.GetProperty(relation.Propriete);
                if (propInfo != null)
                {
                    object[] attribs = propInfo.GetCustomAttributes(typeof(RelationFilleAttribute), true);
                    if (attribs.Length != 0)
                    {
                        Type tpFille = ((RelationFilleAttribute)attribs[0]).TypeFille;
                        lstProps.Add(new CDefinitionProprieteDynamiqueRelation(
                                         strCheminConvivial + relation.NomConvivial,
                                         strCheminReel + relation.Propriete,
                                         relation,
                                         new CTypeResultatExpression(tpFille, true)));
                    }
                }
            }

            /*//à faire Ajoute les relations TypeId
             * foreach ( RelationTypeIdAttribute relation in CContexteDonnee.RelationsTypeIds )
             * {
             *      if ( relation.IsAppliqueToType ( tp ) )
             *      {
             *              lstProps.Add ( new CDefinitionProprieteDynamiqueRelationTypeId(relation) );
             *      }
             * }*/
        }
        ////////////////////////////////////////////////////
        public override IDbCommand GetUpdateCommand(CStructureTable structure)
        {
            IDbCommand command = m_cacheRequetes.GetCache(structure.NomTable, ETypeRequete.Update);

            if (command == null || (m_tblExclusions != null && m_tblExclusions.Count != 0))
            {
                string strReq = "update " + structure.NomTableInDb + " set ";
                List <CInfoChampTable> listeChampsForWhere = new List <CInfoChampTable>();
                List <CInfoChampTable> listeChampsUpdate   = new List <CInfoChampTable>();
                foreach (CInfoChampTable champ in structure.Champs)
                {
                    if (!champ.IsId)
                    {
                        if (m_tblExclusions[champ.NomChamp] == null && !champ.ExclureFormStandardUpdate)
                        {
                            if (champ.TypeDonnee != typeof(CDonneeBinaireInRow) && !champ.TypeDonnee.IsSubclassOf(typeof(CDonneeBinaireInRow)))
                            {
                                strReq += champ.NomChamp + "=" + GetNomParametreFor(champ, DataRowVersion.Current) + ",";
                                listeChampsUpdate.Add(champ);
                            }
                        }
                    }
                    else
                    {
                        listeChampsForWhere.Add(champ);
                    }
                }
                listeChampsForWhere.AddRange(listeChampsUpdate);
                strReq  = strReq.Substring(0, strReq.Length - 1) + " ";
                command = m_connexion.GetConnexion().CreateCommand();

                //Ajoute les paramètres nouvelle version
                foreach (CInfoChampTable champ in listeChampsUpdate)
                {
                    if (m_tblExclusions[champ.NomChamp] == null)
                    {
                        if (champ.TypeDonnee != typeof(CDonneeBinaireInRow) && !champ.TypeDonnee.IsSubclassOf(typeof(CDonneeBinaireInRow)))
                        {
                            command.Parameters.Add(GetParametreFor(command, champ, DataRowVersion.Current, ParameterDirection.Input));
                        }
                    }
                }

                //La mise à jour doit tenir compte des id !!!!
                foreach (CInfoChampTable champ in structure.ChampsId)
                {
                    listeChampsUpdate.Add(champ);
                }
                AddWhereClauseToDeleteAndUpdate(ref strReq, command, listeChampsForWhere.ToArray());
                command.CommandText = strReq;
                m_cacheRequetes.SetCache(structure.NomTable, ETypeRequete.Update, command);
            }
            command.Connection  = m_connexion.GetConnexion();
            command.Transaction = m_connexion.Transaction;
            return(command);
        }
Example #18
0
        protected virtual string GetNomClefPrimaire(CStructureTable structure)
        {
            string nom = "";

            if (structure.ChampsId.Length > 0)
            {
                nom = structure.ChampsId[0].NomChamp;
            }
            return(nom);
        }
Example #19
0
        protected virtual string GetRequeteDeleteClefPrimaire(CStructureTable structure)
        {
            string nomclepk = GetNomClefPrimaire(structure);

            if (nomclepk == "")
            {
                return("");
            }
            return("ALTER TABLE " + structure.NomTableInDb + " DROP CONSTRAINT " + nomclepk);
        }
        ////////////////////////////////////////////////////
        public virtual IDbCommand GetDeleteCommand(CStructureTable structure)
        {
            string     strReq  = "delete from " + structure.NomTableInDb;
            IDbCommand command = m_connexion.GetConnexion().CreateCommand();

            command.Transaction = m_connexion.Transaction;
            AddWhereClauseToDeleteAndUpdate(ref strReq, command, structure.Champs);
            command.CommandText = strReq;
            return(command);
        }
        ////////////////////////////////////////////////////
        public override IDbCommand GetInsertCommand(CStructureTable structure, bool bDisableIdAuto, IDbDataAdapter adapter)
        {
            bool bGestionAutoId = true;
            CMySqlDatabaseConnexion conMySql = m_connexion as CMySqlDatabaseConnexion;
            if (conMySql != null && structure.ChampsId.Length == 1 && structure.ChampsId[0].IsAutoId)
                conMySql.GetNomSequenceColAuto(structure.NomTableInDb, structure.ChampsId[0].NomChamp, ref bGestionAutoId);
            //Stef 2804 : N'exclue pas les champs exclus de l'insertion !

            IDbCommand command = m_cacheRequetes.GetCache(structure.NomTable, ETypeRequete.Insert);
            if (command == null)
            {
                string strReq = "insert into " + structure.NomTableInDb + "(";
                string strValues = "(";
                foreach (CInfoChampTable champ in structure.Champs)
                {
                    if ((!champ.IsAutoId || bDisableIdAuto || !bGestionAutoId))
                        if (champ.TypeDonnee != typeof(CDonneeBinaireInRow) && !champ.TypeDonnee.IsSubclassOf(typeof(CDonneeBinaireInRow)))
                        {
                            strReq += champ.NomChamp + ",";
                            strValues += GetNomParametreFor(champ, DataRowVersion.Current) + ",";
                        }
                }
                strReq = strReq.Substring(0, strReq.Length - 1) + ")";
                strValues = strValues.Substring(0, strValues.Length - 1) + ")";
                strReq += " values " + strValues;

                command = m_connexion.GetConnexion().CreateCommand();
                command.CommandText = strReq;
                //Ajoute les paramètres
                foreach (CInfoChampTable champ in structure.Champs)
                {
                    if ((!champ.IsAutoId || bDisableIdAuto || !bGestionAutoId))
                        if (champ.TypeDonnee != typeof(CDonneeBinaireInRow) && !champ.TypeDonnee.IsSubclassOf(typeof(CDonneeBinaireInRow)))
                        {
                            command.Parameters.Add(GetParametreFor(command, champ, DataRowVersion.Current, ParameterDirection.Input));
                        }
                }
                m_cacheRequetes.SetCache(structure.NomTable, ETypeRequete.Insert, command);
            }


            if (structure.HasChampIdAuto)
            {
                C2iMySqlDataAdapter MySqlAdapter = C2iMySqlDataAdapter.GetMySqlDataAdapter(adapter);
                if (MySqlAdapter != null && !bDisableIdAuto)
                    MySqlAdapter.PreparerInsertionLigneAvecAutoID(structure.NomTableInDb, structure.ChampsId[0].NomChamp);
            }
            command.Connection = m_connexion.GetConnexion();
            command.CommandType = CommandType.Text;
            command.Transaction = m_connexion.Transaction;
            command.UpdatedRowSource = UpdateRowSource.FirstReturnedRecord;

            return command;

        }
        ////////////////////////////////////////////////////
        public virtual IDataAdapter GetNewAdapter(DataRowState etatsAPrendreEnCompte, bool bDisableIdAuto, params string[] champsExclus)
        {
            m_etatsAPrendreEnCompte = etatsAPrendreEnCompte;
            CStructureTable structure = CStructureTable.GetStructure(m_type);

            m_tblExclusions = new Hashtable();
            foreach (string strChamp in champsExclus)
            {
                m_tblExclusions[strChamp] = strChamp;
            }
            IDbDataAdapter adapter = new OleDbDataAdapter();

            if (typeof(IObjetDonneeAutoReference).IsAssignableFrom(m_type))
            {
                adapter = new C2iDataAdapterForClasseAutoReferencee(m_type, adapter);
            }
            adapter.TableMappings.Add("Table", structure.NomTable);
            adapter.SelectCommand = GetSelectCommand(structure);

            if ((etatsAPrendreEnCompte & DataRowState.Added) != 0)
            {
                adapter.InsertCommand = GetInsertCommand(structure, bDisableIdAuto, adapter);
            }
            else
            {
                adapter.InsertCommand = new OleDbCommand("select 1", (OleDbConnection)m_connexion.GetConnexion(), (OleDbTransaction)m_connexion.Transaction);
            }

            if ((etatsAPrendreEnCompte & DataRowState.Deleted) != 0)
            {
                adapter.DeleteCommand = GetDeleteCommand(structure);
            }
            else
            {
                adapter.DeleteCommand = new OleDbCommand("select 1", (OleDbConnection)(OleDbConnection)m_connexion.GetConnexion(), (OleDbTransaction)m_connexion.Transaction);
            }


            if ((etatsAPrendreEnCompte & DataRowState.Modified) != 0)
            {
                adapter.UpdateCommand = GetUpdateCommand(structure);
            }
            else
            {
                adapter.UpdateCommand = new OleDbCommand("select 1", (OleDbConnection)m_connexion.GetConnexion(), (OleDbTransaction)m_connexion.Transaction);
            }

            if (adapter is OleDbDataAdapter)
            {
                ((OleDbDataAdapter)adapter).RowUpdating += new OleDbRowUpdatingEventHandler(OnRowUpdating);
                ((OleDbDataAdapter)adapter).RowUpdated  += new OleDbRowUpdatedEventHandler(OnRowUpdated);
            }

            return(adapter);
        }
        //Table
        protected override DataTable GetDataTableForUpdateTable(CStructureTable structure)
        {
            IDataAdapter adapter = Connection.GetSimpleReadAdapter("SELECT * FROM " + structure.NomTableInDb);
            DataSet      ds      = new DataSet();

            adapter.FillSchema(ds, SchemaType.Mapped);
            CUtilDataAdapter.DisposeAdapter(adapter);
            DataTable dt = ds.Tables["TABLE"];

            return(dt);
        }
Example #24
0
        //Tables
        protected override DataTable GetDataTableForUpdateTable(CStructureTable structure)
        {
            IDataAdapter adapter    = Connection.GetSimpleReadAdapter("SELECT * FROM " + structure.NomTableInDb);
            DataTable    dtAcharger = new DataTable(structure.NomTableInDb);
            DataSet      ds         = new DataSet();

            ds.Tables.Add(dtAcharger);
            adapter.FillSchema(ds, SchemaType.Mapped);
            ds.Tables[structure.NomTableInDb].TableName = structure.NomTable;
            return(ds.Tables[structure.NomTable]);
        }
        ////////////////////////////////////////////////////
        public virtual IDataAdapter GetNewAdapter(DataRowState etatsAPrendreEnCompte, bool bDisableIdAuto, params string[] champsExclus)
        {
            CStructureTable structure = CStructureTable.GetStructure(m_type);

            m_etatsAPrendreEnCompte = etatsAPrendreEnCompte;
            m_tblExclusions         = new Hashtable();
            foreach (string strChamp in champsExclus)
            {
                m_tblExclusions[strChamp] = strChamp;
            }
            IDbDataAdapter adapter = (IDbDataAdapter)m_connexion.GetTableAdapter(structure.NomTableInDb);

            if (typeof(IObjetDonneeAutoReference).IsAssignableFrom(m_type))
            {
                adapter = new C2iDataAdapterForClasseAutoReferencee(m_type, adapter);
            }
            adapter.TableMappings.Add("Table", structure.NomTable);
            adapter.SelectCommand = GetSelectCommand(structure);

            if ((etatsAPrendreEnCompte & DataRowState.Added) != 0)
            {
                adapter.InsertCommand = GetInsertCommand(structure, bDisableIdAuto, adapter);
            }
            else
            {
                adapter.InsertCommand             = m_connexion.GetConnexion().CreateCommand();
                adapter.InsertCommand.CommandText = GetCommandQuiFaitRien();
                adapter.InsertCommand.Transaction = m_connexion.Transaction;
            }

            if ((etatsAPrendreEnCompte & DataRowState.Deleted) != 0)
            {
                adapter.DeleteCommand = GetDeleteCommand(structure);
            }
            else
            {
                adapter.DeleteCommand             = m_connexion.GetConnexion().CreateCommand();
                adapter.DeleteCommand.CommandText = GetCommandQuiFaitRien();
                adapter.DeleteCommand.Transaction = m_connexion.Transaction;
            }

            if ((etatsAPrendreEnCompte & DataRowState.Modified) != 0)
            {
                adapter.UpdateCommand = GetUpdateCommand(structure);
            }
            else
            {
                adapter.UpdateCommand             = m_connexion.GetConnexion().CreateCommand();
                adapter.UpdateCommand.CommandText = GetCommandQuiFaitRien();
                adapter.UpdateCommand.Transaction = m_connexion.Transaction;
            }

            return(adapter);
        }
Example #26
0
 /// //////////////////////////////////////////////////
 public C2iDataAdapterForType(IDatabaseConnexion connexion, Type typeObjets, CFiltreData filtre, params string[] strExclusions)
 {
     m_connexion  = connexion;
     m_typeObjets = typeObjets;
     m_structure  = CStructureTable.GetStructure(m_typeObjets);
     m_tableMapping.Add(new DataTableMapping(m_structure.NomTableInDb, m_structure.NomTable));
     m_filtre = filtre;
     foreach (string strChamp in strExclusions)
     {
         m_tableExclusions[strChamp] = true;
     }
 }
Example #27
0
        protected virtual string GetDeclarationChampIdForCreateTable(CStructureTable structure)
        {
            string strResult = "";

            if (structure.HasChampIdAuto)
            {
                strResult += GetNewNomClefPrimaire(structure.ChampsId) + " ";
                strResult += DataBaseTypesMappeur.GetStringDBTypeFromType(structure.ChampsId[0].TypeDonnee);
                strResult += " NOT NULL";
            }
            return(strResult);
        }
        /// ////////////////////////////////////////////////
        private bool Init(DataRow row, CListeObjetsDonnees listePossibles, bool bResolutionAutomatique)
        {
            m_rowToMap       = row;
            m_listePossibles = listePossibles;

            DisplayElement(row, m_gridObjetAMapper);

            //regarde dans la liste s'il y a un élément existant avec le même id
            CFiltreData oldFiltre = m_listePossibles.Filtre;
            CFiltreData newFiltre = CFiltreData.GetAndFiltre(
                oldFiltre,
                new CFiltreData(row.Table.PrimaryKey[0].ColumnName + "=@1", row[row.Table.PrimaryKey[0]]));

            m_listePossibles.Filtre = newFiltre;
            m_listePossibles.Refresh();
            if (m_listePossibles.Count > 0)
            {
                m_objetSel = (CObjetDonneeAIdNumeriqueAuto)m_listePossibles[0];
                if (bResolutionAutomatique)
                {
                    DataRow rowObjet = m_objetSel.Row.Row;
                    //Compare toutes les valeurs, si elles sont toutes égales, on sélectionne automatique
                    //L'élément
                    bool            bAllOk    = true;
                    CStructureTable structure = CStructureTable.GetStructure(m_objetSel.GetType());
                    foreach (CInfoChampTable info in structure.Champs)
                    {
                        if (info.NomChamp != CSc2iDataConst.c_champIdSynchro && !m_rowToMap[info.NomChamp].Equals(rowObjet[info.NomChamp]))
                        {
                            bAllOk = false;
                            break;
                        }
                    }
                    if (bAllOk)
                    {
                        return(true);
                    }
                }
                DisplayElement(m_objetSel.Row.Row, m_gridObjetPropose);
            }
            else
            {
                DisplayElement(null, m_gridObjetPropose);
            }
            m_listePossibles.Filtre = oldFiltre;
            m_listePossibles.Refresh();



            m_wndListeElements.ListeSource = m_listePossibles;
            return(false);
        }
        //---------------------------------------------------------------------------------
        public void FillInventaireNonRecursif(object obj, CInventaire inventaire)
        {
            CObjetDonnee objetDonnee = obj as CObjetDonnee;

            if (objetDonnee != null)
            {
                CStructureTable structure = CStructureTable.GetStructure(objetDonnee.GetType());
                if ((m_mode & EModeInventaireObjetDonneeLies.TousLesFils) != EModeInventaireObjetDonneeLies.Aucuns)
                {
                    foreach (CInfoRelation relation in structure.RelationsFilles)
                    {
                        if (relation.Composition || (m_mode & EModeInventaireObjetDonneeLies.FilsCompositions) != EModeInventaireObjetDonneeLies.FilsCompositions)
                        {
                            CListeObjetsDonnees lst = objetDonnee.GetDependancesListe(relation.TableFille, relation.ChampsFille);
                            foreach (CObjetDonnee fille in lst)
                            {
                                inventaire.AddObject(fille);
                            }
                        }
                    }
                }
                if ((m_mode & EModeInventaireObjetDonneeLies.Parents) == EModeInventaireObjetDonneeLies.Parents)
                {
                    foreach (CInfoRelation relation in structure.RelationsParentes)
                    {
                        CObjetDonnee parent = objetDonnee.GetParent(relation.ChampsFille, CContexteDonnee.GetTypeForTable(relation.TableParente));
                        if (parent != null)
                        {
                            inventaire.AddObject(parent);
                        }
                    }
                }
                foreach (IFournisseurInventaireObjetDonneeLies fournisseur in m_listeFournisseursSupplementaires)
                {
                    fournisseur.FillInventaireNonRecursif(objetDonnee, inventaire, m_mode);
                }
            }
            else
            {
                if (obj is IUtilisateurObjetsDonnee)
                {
                    CResultAErreur result = ((IUtilisateurObjetsDonnee)obj).GetObjetsUtilises(m_contexte);
                    if (result)
                    {
                        foreach (CObjetDonnee objet in (CObjetDonnee[])result.Data)
                        {
                            inventaire.AddObject(objet);
                        }
                    }
                }
            }
        }
        ////////////////////////////////////////////////////
        public virtual OleDbCommand GetInsertCommand(CStructureTable structure, bool bDisableIdAuto, IDataAdapter adapter)
        {
            string strReq    = "insert into [" + structure.NomTableInDb + "](";
            string strValues = "(";

            foreach (CInfoChampTable champ in structure.Champs)
            {
                if ((!champ.IsAutoId || bDisableIdAuto) && m_tblExclusions[champ.NomChamp] == null)
                {
                    if (champ.TypeDonnee != typeof(CDonneeBinaireInRow) && !champ.TypeDonnee.IsSubclassOf(typeof(CDonneeBinaireInRow)))
                    {
                        strReq    += "[" + champ.NomChamp + "],";
                        strValues += "?,";                        //GetNomParametreFor(champ, DataRowVersion.Current)+",";
                    }
                }
            }
            strReq    = strReq.Substring(0, strReq.Length - 1) + ")";
            strValues = strValues.Substring(0, strValues.Length - 1) + ")";
            strReq   += " values " + strValues;

            if (structure.HasChampIdAuto && !bDisableIdAuto)
            {
                C2iDataAdapterForClasseAutoReferencee adapteurAutoRef = adapter as C2iDataAdapterForClasseAutoReferencee;
                if (adapteurAutoRef != null)
                {
                    adapteurAutoRef.RowInserted += new C2iDataAdapterForClasseAutoReferencee.RowInsertedEventHandler(OnRowAIdAutoInsertedGeneric);
                    if (m_bAvecSynchro)
                    {
                        adapteurAutoRef.RowInserted += new C2iDataAdapterForClasseAutoReferencee.RowInsertedEventHandler(OnRowAIdAutoInserted);
                    }
                }
                else
                {
                    ((OleDbDataAdapter)adapter).RowUpdated += new OleDbRowUpdatedEventHandler(OnRowAIdAutoUpdated);
                }
            }
            OleDbCommand command = new OleDbCommand(strReq, (OleDbConnection)m_connexion.GetConnexion(), (OleDbTransaction)m_connexion.Transaction);

            command.UpdatedRowSource = UpdateRowSource.FirstReturnedRecord;
            //Ajoute les paramètres
            foreach (CInfoChampTable champ in structure.Champs)
            {
                if ((!champ.IsAutoId || bDisableIdAuto) && m_tblExclusions[champ.NomChamp] == null)
                {
                    if (champ.TypeDonnee != typeof(CDonneeBinaireInRow) && !champ.TypeDonnee.IsSubclassOf(typeof(CDonneeBinaireInRow)))
                    {
                        command.Parameters.Add(GetParametreFor(champ, DataRowVersion.Current, ParameterDirection.Input));
                    }
                }
            }
            return(command);
        }