Esempio n. 1
0
        //--------------------------------------------
        /// <summary>
        /// Si succès, retourne le filtre correspondant à cet élément
        /// en tant que clé. le texte du filtre (format filtreData) est contenu dans le data du result
        /// avec le paramètre valeur = @n
        /// </summary>
        /// <param name="typeCible"></param>
        /// <returns></returns>
        public static CResultAErreur GetFiltreCle(
            Type typeCible,
            CDefinitionProprieteDynamique definition,
            int nNumeroParametre)
        {
            CResultAErreur result = CResultAErreur.True;
            CDefinitionProprieteDynamiqueDotNet def = definition as CDefinitionProprieteDynamiqueDotNet;
            PropertyInfo info = null;

            if (def != null)
            {
                info = typeCible.GetProperty(def.NomProprieteSansCleTypeChamp);
            }
            if (info != null)
            {
                object[] attribs = info.GetCustomAttributes(typeof(TableFieldPropertyAttribute), true);
                if (attribs.Length > 0)
                {
                    TableFieldPropertyAttribute attr = attribs[0] as TableFieldPropertyAttribute;
                    result.Data = attr.NomChamp + "=@" + nNumeroParametre;
                    return(result);
                }
                attribs = info.GetCustomAttributes(typeof(RelationAttribute), true);
                if (attribs.Length > 0)
                {
                    RelationAttribute attr = attribs[0] as RelationAttribute;
                    if (attr.ChampsFils.Length == 1)
                    {
                        result.Data = attr.ChampsFils[0] + "=@" + nNumeroParametre;
                        return(result);
                    }
                }
            }
            //Sinon, si ID d'un objet a id auto
            if (typeof(CObjetDonneeAIdNumerique).IsAssignableFrom(typeCible))
            {
                if (definition.NomPropriete == "#PP|Id")
                {
                    //Trouve le champ id
                    string strChampId = CObjetDonnee.GetChampsId(typeCible)[0];
                    result.Data = strChampId + "=@" + nNumeroParametre;
                    return(result);
                }
            }

            result.EmpileErreur(I.T("Can not use field @1 as key in imort|20044", definition.Nom));
            return(result);
        }
Esempio n. 2
0
        //---------------------------------------------------------------
        private bool IsChampCompatibleImport(Type typeObjet, CDefinitionProprieteDynamique def)
        {
            if (def is CDefinitionProprieteDynamiqueChampCustom)
            {
                return(true);
            }
            if (def is CDefinitionProprieteDynamiqueDotNet)
            {
                PropertyInfo info = typeObjet.GetProperty(def.NomProprieteSansCleTypeChamp);
                if (info != null)
                {
                    TableFieldPropertyAttribute attField = info.GetCustomAttribute <TableFieldPropertyAttribute>(true);
                    if (attField != null && attField.IsInDb)
                    {
                        return(true);
                    }

                    RelationAttribute attRel = info.GetCustomAttribute <RelationAttribute>(true);
                    if (attRel != null)
                    {
                        return(true);
                    }
                    RelationFilleAttribute attFille = info.GetCustomAttribute <RelationFilleAttribute>(true);
                    if (attFille != null)
                    {
                        return(true);
                    }
                }
            }
            if (def is CDefinitionProprieteDynamiqueRelationTypeId)
            {
                return(true);
            }
            if (def is CDefinitionProprieteDynamiqueRelationTypeIdToParent)
            {
                return(true);
            }
            if (def is CDefinitionProprieteDynamiqueChampCustomFils)
            {
                return(true);
            }
            return(false);
        }
Esempio n. 3
0
        /// /////////////////////////////////////////////////////////
        public static object GetValeur(CObjetDonnee objet, CDefinitionProprieteDynamique prop, DataRowVersion version)
        {
            if (prop is CDefinitionProprieteDynamiqueChampCustom)
            {
                //Evaluation d'un champ custom
                if (objet is CRelationElementAChamp_ChampCustom)
                {
                    CRelationElementAChamp_ChampCustom rel = (CRelationElementAChamp_ChampCustom)objet;
                    return(rel.GetValeur(version));
                }
                if (objet is IElementAChamps)
                {
                    return(((IElementAChamps)objet).GetValeurChamp(((CDefinitionProprieteDynamiqueChampCustom)prop).DbKeyChamp, version));
                }
            }
            else
            {
                #region Evaluation d'un champ
                PropertyInfo info    = objet.GetType().GetProperty(prop.NomProprieteSansCleTypeChamp);
                object[]     attribs = info.GetCustomAttributes(typeof(TableFieldPropertyAttribute), true);
                if (attribs.Length != 0)
                {
                    TableFieldPropertyAttribute attrTable = (TableFieldPropertyAttribute)attribs[0];
                    try
                    {
                        object val = objet.Row[attrTable.NomChamp, version];
                        if (val == DBNull.Value)
                        {
                            val = null;
                        }
                        return(val);
                    }
                    catch
                    {
                        return(null);
                    }
                }
                else
                {
                    attribs = info.GetCustomAttributes(typeof(RelationAttribute), true);
                    if (attribs.Length != 0)
                    {
                        RelationAttribute attrRel = (RelationAttribute)attribs[0];
                        try
                        {
                            object val = objet.Row[attrRel.ChampsFils[0], version];
                            if (val == DBNull.Value)
                            {
                                val = null;
                            }
                            return(val);
                        }
                        catch
                        {
                            return(null);
                        }
                    }
                }
                #endregion
            }

            return(null);
        }
Esempio n. 4
0
        /// /////////////////////////////////////////////////////////////
        ///Implémente le tri d'une liste d'objets donnée
        /// <summary>
        /// Sort a column.
        public override void SortColumn(int nColumn)
        {
            if (Count < 2)                                      // nothing to sort
            {
                return;
            }

            if (nColumn < 0 || nColumn > Columns.Count)
            {
                return;
            }

            if (!(ListeSource is CListeObjetsDonnees))
            {
                base.SortColumn(nColumn);
                return;
            }


            GLColumn            col          = Columns[nColumn];
            CListeObjetsDonnees listeDonnees = (CListeObjetsDonnees)ListeSource;

            string strProp = CInfoStructureDynamique.GetProprieteDotNet(col.Propriete);

            if (strProp.IndexOf('.') < 0)
            {
                //Trouve la propriété
                PropertyInfo info = listeDonnees.TypeObjets.GetProperty(strProp);
                if (info != null)
                {
                    //y-a-t-il un attribut TableField sur la propriété
                    object[] attribs = info.GetCustomAttributes(typeof(TableFieldPropertyAttribute), true);
                    if (attribs.Length > 0)
                    {
                        if (CheckedItems.Count != 0 && CheckBoxes)
                        {
                            if (CFormAlerte.Afficher(I.T("Warning, the sorting will uncheck all checked elements. Continue ?|139"),
                                                     EFormAlerteType.Question) == DialogResult.No)
                            {
                                return;
                            }
                        }
                        ResetCheck();
                        TableFieldPropertyAttribute fieldAttr = (TableFieldPropertyAttribute)attribs[0];
                        string strSort = fieldAttr.NomChamp;
                        if (strSort == m_strLastSort)
                        {
                            m_bSortAsc = !m_bSortAsc;
                        }
                        else
                        {
                            m_bSortAsc = true;
                        }
                        m_strLastSort = strSort;
                        if (!m_bSortAsc)
                        {
                            strSort += " desc";
                        }
                        listeDonnees.Tri = strSort;
                        listeDonnees.Refresh();
                        Refresh();
                        base.SortIndex = nColumn;
                        Columns[nColumn].LastSortState = m_bSortAsc ? ColumnSortState.SortedDown : ColumnSortState.SortedUp;
                        return;
                    }
                }
            }
            CFormAlerte.Afficher(I.T("Sort on this field is impossible|138"), EFormAlerteType.Exclamation);
        }