Example #1
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"]));
        }
        /// ///////////////////////////////////////////////////////
        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 #3
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;
        }
        //--------------------------------------------------------------
        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;
                }
            }
        }
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 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 #7
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 #8
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]);
        }
Example #9
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));
        }
        /// ///////////////////////////////////////////////////////////
        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 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);
        }
        ////////////////////////////////////////////////////
        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 #13
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;
     }
 }
        //---------------------------------------------------------------------------------
        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);
                        }
                    }
                }
            }
        }
        /// ////////////////////////////////////////////////
        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 override bool ChampExists(string strTableName, string strChampName)
        {
            Type tp = CContexteDonnee.GetTypeForTable(strTableName);

            if (tp == null)
            {
                return(true);
            }
            CStructureTable structure = CStructureTable.GetStructure(tp);
            DataTable       dt        = GetDataTableForUpdateTable(structure);

            return(dt.Columns.Contains(strChampName));
        }
Example #17
0
        /////////////////////////////////////////////////////////////////////////////////////
        public override int CountRecords(string strNomTableInDb, CFiltreData filtre)
        {
            filtre.SortOrder = "";
            string strNomTableInContexte = GetNomTableInContexteFromNomTableInDb(strNomTableInDb);
            Type   tp         = CContexteDonnee.GetTypeForTable(strNomTableInContexte);
            string strRequete = "";

            if (strRequete == "")
            {
                strRequete = "select count (*) as COMBIEN from " + GetNomTableForRequete(strNomTableInDb);
            }

            IDataAdapter adapter = GetSimpleReadAdapter(strRequete, filtre);

            if (tp != null && adapter is IDbDataAdapter)
            {
                CStructureTable structure = CStructureTable.GetStructure(tp);
                strRequete = ((IDbDataAdapter)adapter).SelectCommand.CommandText.Replace("distinct", "");
                strRequete = "select count(*) as COMBIEN from (\n" +
                             strRequete + " group by \n";
                foreach (CInfoChampTable info in structure.ChampsId)
                {
                    strRequete += strNomTableInDb + "." + info.NomChamp + ",";
                }
                strRequete  = strRequete.Substring(0, strRequete.Length - 1);
                strRequete += ")";
                ((IDbDataAdapter)adapter).SelectCommand.CommandText = strRequete;
            }
            DataSet ds = new DataSet();

            try
            {
                this.FillAdapter(adapter, ds);
            }
            catch (Exception e)
            {
                Console.WriteLine(I.T("Error in 'CountRecords' : @1|182", e.ToString()));
                throw e;
            }
            finally
            {
                CUtilDataAdapter.DisposeAdapter(adapter);
            }
            return((int)ds.Tables["Table"].Rows[0]["COMBIEN"]);
        }
        /////////////////////////////////////////////////////////////////////////////////////
        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 + ") as COMBIEN from " + strNomTableInDb;
                }
            }
            if (strRequete == "")
            {
                strRequete = "select count (*) as COMBIEN from " + strNomTableInDb;
            }

            IDataAdapter adapter = GetSimpleReadAdapter(strRequete, filtre);

            DataSet ds = new DataSet();

            try
            {
                /*SqlCommand cmd = ((SqlDataAdapter)adapter).SelectCommand;
                 * cmd.Connection = (SqlConnection)GetConnexion(true);
                 * cmd.Transaction = (SqlTransaction)Transaction;
                 * object val = ((SqlDataAdapter)adapter).SelectCommand.ExecuteScalar();*/
                this.FillAdapter(adapter, ds);
            }
            catch (Exception e)
            {
                string strTmp = e.ToString();
                return(0);
            }
            finally
            {
                CUtilDataAdapter.DisposeAdapter(adapter);
            }
            return((int)ds.Tables["Table"].Rows[0]["COMBIEN"]);
        }
        /// ////////////////////////////////////////////////
        private void DisplayElement(DataRow row, DataGrid grid)
        {
            if (row == null)
            {
                grid.DataSource = null;
                grid.Refresh();
                return;
            }
            DataTable tablePresentation = new DataTable("Presentation");

            tablePresentation.Columns.Add("NOM", typeof(string));
            tablePresentation.Columns.Add("VALEUR", typeof(string));
            Type            tp        = CContexteDonnee.GetTypeForTable(row.Table.TableName);
            CStructureTable structure = CStructureTable.GetStructure(tp);

            foreach (CInfoChampTable champ in  structure.Champs)
            {
                DataRow rowPres = tablePresentation.NewRow();
                rowPres["NOM"] = champ.NomConvivial;
                object val = row[champ.NomChamp];
                rowPres["VALEUR"] = val == null?"NULL":val.ToString();
                tablePresentation.Rows.Add(rowPres);
            }
            grid.DataSource = tablePresentation;
            DataGridTableStyle style = grid.TableStyles[tablePresentation.TableName];

            if (style == null)
            {
                style             = new DataGridTableStyle();
                style.MappingName = tablePresentation.TableName;
                DataGridColumnStyle col = new DataGridTextBoxColumn();
                col.MappingName = "NOM";
                col.Width       = grid.Width / 3;
                style.GridColumnStyles.Add(col);
                col             = new DataGridTextBoxColumn();
                col.MappingName = "VALEUR";
                col.Width       = grid.Width * 2 / 3;
                style.GridColumnStyles.Add(col);
                grid.TableStyles.Add(style);
            }
            grid.Refresh();
        }
        //------------------------------------------------------
        private CResultAErreur GetIdsFilles(
            Type typeFils,
            CFiltreData filtre,
            out int[] lstIdsSortie)
        {
            lstIdsSortie = new int[0];
            CResultAErreur result = CResultAErreur.True;

            result = TestTypePurgeable(typeFils);
            if (!result)
            {
                return(result);
            }
            CStructureTable structureFille = CStructureTable.GetStructure(typeFils);
            //Sélectionne tous les éléments
            C2iRequeteAvancee requete = new C2iRequeteAvancee(-1);

            requete.TableInterrogee = structureFille.NomTable;
            string strChampIdFille = structureFille.ChampsId[0].NomChamp;

            requete.ListeChamps.Add(new C2iChampDeRequete(
                                        strChampIdFille,
                                        new CSourceDeChampDeRequete(strChampIdFille),
                                        typeof(int),
                                        OperationsAgregation.None,
                                        false));
            requete.FiltreAAppliquer = filtre;
            result = requete.ExecuteRequete(IdSession);
            if (!result)
            {
                return(result);
            }
            DataTable  table       = result.Data as DataTable;
            List <int> lstIdsFille = new List <int>();

            foreach (DataRow row in table.Rows)
            {
                lstIdsFille.Add((int)row[strChampIdFille]);
            }
            lstIdsSortie = lstIdsFille.ToArray();
            return(result);
        }
Example #21
0
 /// //////////////////////////////////////////////////////////
 private void item_Liste_Click(object sender, EventArgs e)
 {
     if (sender is CMenuItemListe)
     {
         CListeEntites liste = ((CMenuItemListe)sender).Liste;
         if (liste == null)
         {
             m_panelListe.ListeObjets.Filtre = null;
             m_panelListe.RemplirGrille();
         }
         else
         {
             if (liste.IsDynamique)
             {
                 CFiltreDynamique filtre = liste.FiltreDynamique;
                 CResultAErreur   result = filtre.GetFiltreData();
                 if (result.Data is CFiltreData)
                 {
                     m_panelListe.ListeObjets.Filtre = (CFiltreData)result.Data;
                     m_panelListe.RemplirGrille();
                 }
             }
             else
             {
                 string strFiltre = "";
                 foreach (CObjetDonneeAIdNumerique objet in liste.ElementsLies)
                 {
                     strFiltre += objet.Id.ToString() + ",";
                 }
                 if (strFiltre.Length > 0)
                 {
                     strFiltre = strFiltre.Substring(0, strFiltre.Length - 1);
                 }
                 CStructureTable structure = CStructureTable.GetStructure(liste.TypeElements);
                 m_panelListe.ListeObjets.Filtre = new CFiltreData(
                     structure.ChampsId[0].NomChamp + " in (" +
                     strFiltre + ")");
                 m_panelListe.RemplirGrille();
             }
         }
     }
 }
Example #22
0
        //--------------------------------------------------
        public CResultAErreurType <CColumnDeEasyQueryChampDeRequete> GetColonneIdSource()
        {
            CResultAErreurType <CColumnDeEasyQueryChampDeRequete> result = new CResultAErreurType <CColumnDeEasyQueryChampDeRequete>();
            IODEQTableFromFramework tableSource = ElementsSource[0] as IODEQTableFromFramework;

            if (tableSource == null)
            {
                result.EmpileErreur(I.T("Incompatible source table|20074"));
                return(result);
            }
            Type tp = tableSource.TypeElements;

            if (!typeof(IObjetDonneeAIdNumerique).IsAssignableFrom(tp))
            {
                result.EmpileErreur(I.T("Incompatible source table|20074"));
                return(result);
            }
            CStructureTable  structure = CStructureTable.GetStructure(tp);
            HashSet <string> setIds    = new HashSet <string>();

            setIds.Add("#PP|" + structure.ChampsId[0].Propriete);
            if (structure.ChampsId.Length == 1)
            {
                setIds.Add(structure.ChampsId[0].NomChamp);
            }

            foreach (CColumnDeEasyQueryChampDeRequete col in tableSource.ChampsDeRequete)
            {
                if (col.Sources.Length == 1)
                {
                    if (setIds.Contains(col.Sources[0].Source) &&
                        col.OperationAgregation == OperationsAgregation.None)
                    {
                        result.Data = col;
                        return(result);
                    }
                }
            }
            result.EmpileErreur(I.T("Source table must reference 'Id' field with 'None' operation|20075"));
            return(result);
        }
Example #23
0
        /// ////////////////////////////////////////////////////////////////
        //Retourne le texte de la clause join à mettre dans SQL
        public override string GetJoinClause(
            string strAliasTableParente,
            string strSuffixeParent,
            string strAliasTableFille,
            string strSuffixeFils)
        {
            //Identifie le type parent
            Type tp = CContexteDonnee.GetTypeForTable(m_strTableParente);

            if (!tp.IsSubclassOf(typeof(CObjetDonneeAIdNumerique)))
            {
                throw new Exception(I.T("Cumulated data link on a table which isn't managed by a numerical identifier|188"));
            }
            CStructureTable structure = CStructureTable.GetStructure(tp);
            string          strJoin   = strAliasTableParente + "." + structure.ChampsId[0].NomChamp + strSuffixeParent + "=" +
                                        strAliasTableFille + "." + CDonneeCumulee.c_baseChampCle + m_nNumeroCle.ToString() + strSuffixeFils + " and " +
                                        strAliasTableFille + "." + CTypeDonneeCumulee.c_champId + strSuffixeFils + "=" +
                                        m_nIdTypeDonneeCumulee.ToString();

            return(strJoin);
        }
            //-----------------------------------------------------------
            private C2iRequeteAvancee GetRequeteChampDotNet(CParametreInspirationProprieteDeType parametre)
            {
                CStructureTable structure  = CStructureTable.GetStructure(parametre.Type);
                string          strNomProp = parametre.Champ.NomProprieteSansCleTypeChamp;

                foreach (CInfoChampTable info in structure.Champs)
                {
                    if (info.Propriete == strNomProp)
                    {
                        C2iRequeteAvancee requete = new C2iRequeteAvancee();
                        requete.TableInterrogee = CContexteDonnee.GetNomTableForType(parametre.Type);
                        requete.ListeChamps.Add(new C2iChampDeRequete("LABEL",
                                                                      new CSourceDeChampDeRequete(info.NomChamp),
                                                                      typeof(string),
                                                                      OperationsAgregation.None,
                                                                      true));
                        return(requete);
                    }
                }
                return(null);
            }
        public override CResultAErreur ExecuterOperation(IDatabaseConnexion connection, IIndicateurProgression indicateur)
        {
            IDataBaseCreator creator     = connection.GetDataBaseCreator();
            string           strNomTable = DynamicClassAttribute.GetNomConvivial(m_type);

            if (!m_bSuppression)
            {
                                #if PDA
                return(COracleTableCreator.CreationOuUpdateTableFromType(tp, m_nIdSession));
                                #else
                return(creator.CreationOuUpdateTableFromType(m_type, new ArrayList(m_strChampsAutorisesANull)));
                                #endif
            }
            else
            {
                                #if PDA
                return(CSQLCeTableCreator.SuppressionTable(strNomTable, m_nIdSession));
                                #else
                return(creator.DeleteTable(CStructureTable.GetStructure(m_type).NomTableInDb));
                                #endif
            }
        }
        //------------------------------------------------------------------------------------------------
        public static CResultAErreur CreationOuUpdateTableFromType(Type tp, IDatabaseConnexion connexion, ArrayList strChampsAutorisesANull)
        {
            CResultAErreur result = CResultAErreur.True;

            CStructureTable structure = CStructureTable.GetStructure(tp);

            if (!result)
            {
                return(result);
            }

            //S'assure que toutes les tables parentes existent
            foreach (CInfoRelation relation in structure.RelationsParentes)
            {
                if (relation.TableParente != structure.NomTable)
                {
                    string strNomTableParenteInDb = CContexteDonnee.GetNomTableInDbForNomTable(relation.TableParente);
                    if (!CAccessTableCreatorOld.TableExists(strNomTableParenteInDb, connexion))
                    {
                        result = CreationOuUpdateTableFromType(CContexteDonnee.GetTypeForTable(relation.TableParente), connexion);
                        if (!result)
                        {
                            return(result);
                        }
                    }
                }
            }

            if (CAccessTableCreatorOld.TableExists(structure.NomTableInDb, connexion))
            {
                result = CAccessTableCreatorOld.UpdateTable(structure, connexion, strChampsAutorisesANull);
            }
            else
            {
                result = CAccessTableCreatorOld.CreateTable(structure, connexion);
            }

            return(result);
        }
Example #27
0
        /// /////////////////////////////////////////////////////////////
        public CFiltreData GetFiltrePourListe()
        {
            CFiltreData filtre = new CFiltreData();

            if (IsDynamique)
            {
                CFiltreDynamique filtreDyn = FiltreDynamique;
                CResultAErreur   result    = filtreDyn.GetFiltreData();
                if (result.Data is CFiltreData)
                {
                    filtre = (CFiltreData)result.Data;
                }
            }
            else
            {
                string          strChampId = "";
                StringBuilder   bl         = new StringBuilder();
                CStructureTable structure  = CStructureTable.GetStructure(TypeElements);
                strChampId = structure.ChampsId[0].NomChamp;
                foreach (CRelationListeEntites_Entite rel in RelationsEntites)
                {
                    bl.Append(rel.IdElement);
                    bl.Append(',');
                }
                if (bl.Length > 0)
                {
                    bl.Remove(bl.Length - 1, 1);
                }
                if (bl.Length > 0)
                {
                    filtre = new CFiltreData(strChampId + " in (" + bl.ToString() + ")");
                }
                else
                {
                    filtre = new CFiltreDataImpossible();
                }
            }
            return(filtre);
        }
        /// ///////////////////////////////////////////////////////

        /*public override DataTable Read ( CFiltreData filtre, int nStart, int nEnd )
         * {
         *      IDatabaseConnexion connexion = CSc2iDataServer.GetInstance().GetDatabaseConnexion (IdSession, GetType());
         *      string str
         *      IDataAdapter adapter = connexion.GetSimpleReadAdapter( strReq, filtre );
         *      DataSet ds = new DataSet();
         *      adapter.TableMappings.Add("Table",GetNomTable());
         *      adapter.FillSchema( ds, SchemaType.Mapped );
         *  adapter.Fill(ds);
         *      DataTable tbl = ds.Tables[GetNomTable()];
         *      foreach ( string strChampBlob in lstBlobs )
         *              tbl.Columns.Add ( strChampBlob, typeof(CDonneeBinaireInRow)).DefaultValue = DBNull.Value;
         *
         *      nEnd = Math.Min ( nEnd, tbl.Rows.Count );
         *      if ( nStart >= 0 && nEnd >= 0 )
         *      {
         *              DataTable tblNew = tbl.Clone();
         *
         *              for ( int n = nStart; n < nEnd; n++ )
         *                      tblNew.ImportRow ( tbl.Rows[n] );
         *              tbl = tblNew;
         *      }
         *      return tbl;
         * }*/

        //////////////////////////////////////////////////
        public override CDataTableFastSerialize FillSchema()
        {
            DataTable tbl = (DataTable)m_tableSchema[GetNomTable()];

            if (tbl != null)
            {
                return(tbl.Clone());
            }
            IDataAdapter adapter = CSc2iDataServer.GetInstance().GetDatabaseConnexion(IdSession, GetType()).GetTableAdapter(GetNomTableInDb());

            adapter.TableMappings.Add("Table", GetNomTable());
            DataSet ds = new DataSet();

            adapter.FillSchema(ds, SchemaType.Mapped);
            CUtilDataAdapter.DisposeAdapter(adapter);
            DataTable table = ds.Tables[GetNomTable()];

            if (table == null)
            {
                table = ds.Tables[GetNomTableInDb()];
                if (table != null)
                {
                    table.TableName = GetNomTable();
                }
            }
            CStructureTable structure = CStructureTable.GetStructure(GetTypeObjets());

            foreach (CInfoChampTable info in structure.Champs)
            {
                if (info.TypeDonnee == typeof(CDonneeBinaireInRow) && table.Columns[info.NomChamp] != null)
                {
                    table.Columns[info.NomChamp].DataType = typeof(CDonneeBinaireInRow);
                }
            }
            tbl = ds.Tables[GetNomTable()];
            FaitLesCorrectionsSurLeSchema(tbl);
            m_tableSchema[GetNomTable()] = tbl.Clone();
            return(tbl);
        }
        //----------------------------------------------------------------------------
        public List <CReferenceObjetDependant> GetDependances(CEntitiesManager manager, CObjetDonnee objet)
        {
            List <CReferenceObjetDependant> lst = new List <CReferenceObjetDependant>();

            if (objet == null)
            {
                return(lst);
            }
            CStructureTable structure = CStructureTable.GetStructure(objet.GetType());

            foreach (CInfoRelation relation in structure.RelationsParentes)
            {
                Type tpParent = CContexteDonnee.GetTypeForTable(relation.TableParente);
                if (manager.ConfigurationRecherche.IsIgnore(tpParent))
                {
                    return(lst);
                }
                CObjetDonnee parent          = objet.GetParent(relation.ChampsFille, tpParent);
                bool         bHasUniversalId = tpParent.GetCustomAttribute <NoIdUniverselAttribute>(true) == null;
                string       strNomProp      = relation.NomConvivial;
                if (strNomProp.Length == 0)
                {
                    strNomProp = DynamicClassAttribute.GetNomConvivial(tpParent);
                }
                if (parent != null)
                {
                    if (bHasUniversalId)
                    {
                        lst.Add(new CReferenceObjetDependant(strNomProp, tpParent, parent.DbKey));
                    }
                    else
                    {
                        lst.Add(new CReferenceObjetDependant(strNomProp, tpParent,
                                                             parent.GetValeursCles()));
                    }
                }
            }
            return(lst);
        }
Example #30
0
        /// ////////////////////////////////////////////////////////////////
        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;
                    }
                }
            }
        }