//---------------------------------------------------------------
        public object GetValeur(CVersionDonneesObjetOperation version)
        {
            IChampPourVersion champ = GetChamp(version);

            if (champ is CChampCustomPourVersion)
            {
                CChampCustom champCustom = ((CChampCustomPourVersion)champ).ChampCustom;
                object       valeur      = version.GetValeurStd();
                if (champCustom.TypeDonneeChamp.TypeDonnee == TypeDonnee.tObjetDonneeAIdNumeriqueAuto)
                {
                    Type tp = champCustom.TypeObjetDonnee;
                    if (tp != null && valeur is int)
                    {
                        CObjetDonneeAIdNumerique objet = (CObjetDonneeAIdNumerique)Activator.CreateInstance(tp, new object[] { version.ContexteDonnee });
                        if (objet != null && objet.ReadIfExists((int)valeur))
                        {
                            return(objet);
                        }
                    }
                    return(null);
                }
                return(valeur);
            }
            return(null);
        }
        //---------------------------------------------------------------
        public CResultAErreur AppliqueValeur(int?nIdVersion, IChampPourVersion champ, CObjetDonneeAIdNumerique objet, object valeur)
        {
            CResultAErreur result = CResultAErreur.True;

            if (!(champ is CChampCustomPourVersion))
            {
                result.EmpileErreur(I.T("Cannot apply value for field @1 (bad type)|243", champ.NomConvivial));
                return(result);
            }
            CChampCustom champCustom = ((CChampCustomPourVersion)champ).ChampCustom;

            try
            {
                if (objet is IElementAVariables)
                {
                    ((IElementAVariables)objet).SetValeurChamp(champCustom.DbKey.StringValue, valeur);
                    return(result);
                }
            }
            catch (Exception e)
            {
                result.EmpileErreur(new CErreurException(e));
            }
            result.EmpileErreur(I.T("Cannot apply value for field @1 (bad destination)|244", champ.NomConvivial));
            return(result);
        }
示例#3
0
        /// ////////////////////////////////////////
        public override CResultAErreur Serialize(C2iSerializer serializer)
        {
            int            nVersion = GetNumVersion();
            CResultAErreur result   = serializer.TraiteVersion(ref nVersion);

            if (!result)
            {
                return(result);
            }
            result = base.Serialize(serializer);
            if (!result)
            {
                return(result);
            }
            if (nVersion < 1)
            {
                //TESTDBKEYOK
                serializer.ReadDbKeyFromOldId(ref m_dbKeyChamp, typeof(CChampCustom));
                CChampCustom champ = new CChampCustom(CContexteDonneeSysteme.GetInstance());
                if (champ.ReadIfExists(m_dbKeyChamp))
                {
                    //Convertit le nom de propriété avec les DbKey
                    //ne pas appeller SetNomProprieteSansCleTypeChamp(GetKeyChamp()) car pour les filtres,
                    //le nom de propriété peut contenir un chemin
                    ConvertNomProprieteFromIdToDbKey();
                }
            }
            else
            {
                //TESTDBKEYOK
                serializer.TraiteDbKey(ref m_dbKeyChamp);
            }
            return(result);
        }
示例#4
0
        /// ///////////////////////////////////////////////////////////
        public virtual bool HasSubProperties(Type tp)
        {
            if (tp.IsSubclassOf(typeof(CObjetDonnee)))
            {
                return(true);
            }
            foreach (PropertyInfo info in tp.GetProperties())
            {
                object[] attribs = info.GetCustomAttributes(typeof(DynamicFieldAttribute), true);
                if (attribs.Length == 1)
                {
                    return(true);
                }
            }
            CRoleChampCustom role = CRoleChampCustom.GetRoleForType(tp);

            if (role != null)
            {
                CListeObjetsDonnees listeChamps = CChampCustom.GetListeChampsForRole(ContexteDonneeCache, role.CodeRole);
                if (listeChamps.Count > 0)
                {
                    return(true);
                }
            }
            return(false);
        }
        public static CChampCustom[] GetTousLesChampsAssociesA(IDefinisseurChampCustom definisseur)
        {
            Hashtable tableChamps = new Hashtable();

            foreach (IRelationDefinisseurChamp_ChampCustom relation in definisseur.RelationsChampsCustomDefinis)
            {
                tableChamps[relation.ChampCustom.Id] = relation.ChampCustom;
            }

            foreach (IRelationDefinisseurChamp_Formulaire relation in definisseur.RelationsFormulaires)
            {
                foreach (CRelationFormulaireChampCustom relFor in relation.Formulaire.RelationsChamps)
                {
                    tableChamps[relFor.Champ.Id] = relFor.Champ;
                }
            }
            CChampCustom[] liste  = new CChampCustom[tableChamps.Count];
            int            nChamp = 0;

            foreach (CChampCustom champ in tableChamps.Values)
            {
                liste[nChamp++] = champ;
            }
            return(liste);
        }
 /// //////////////////////////////////////////////////////
 private static string GetKeyChamp(CChampCustom champ)
 {
     //TESTDBKEYOK
     return(CInfoRelationComposantFiltreEntiteToChampEntite.GetKeyChamp(champ, true) + "." +
            CDefinitionProprieteDynamique.c_strCaractereStartCleType + c_strCleType +
            CDefinitionProprieteDynamique.c_strCaractereEndCleType +
            CInfoRelationEValeurChampCustomToDisplay.GetKeyChamp(champ));
 }
示例#7
0
        //-----------------------------------------------------
        public CResultAErreur Serialize(C2iSerializer serializer)
        {
            int            nVersion = GetNumVersion();
            CResultAErreur result   = serializer.TraiteVersion(ref nVersion);

            if (!result)
            {
                return(result);
            }
            switch (serializer.Mode)
            {
            case ModeSerialisation.Ecriture:
                //TESTDBKEYTODO : remplacer IdChamp par DbKey
                CDbKey dbKeyChampWrite = ChampCustom != null ? ChampCustom.DbKey : null;
                if (nVersion < 1)
                {
                    serializer.ReadDbKeyFromOldId(ref dbKeyChampWrite, typeof(CChampCustom));
                }
                else
                {
                    serializer.TraiteDbKey(ref dbKeyChampWrite);
                }
                break;

            case ModeSerialisation.Lecture:
                CContexteDonnee contexte = serializer.GetObjetAttache(typeof(CContexteDonnee)) as CContexteDonnee;
                if (contexte == null)
                {
                    contexte = CContexteDonneeSysteme.GetInstance();
                }
                //TESTDBKEYTODO : remplacer IdChamp par DbKey
                CDbKey dbKeyChampRead = null;
                if (nVersion < 1)
                {
                    serializer.ReadDbKeyFromOldId(ref dbKeyChampRead, typeof(CChampCustom));
                }
                else
                {
                    serializer.TraiteDbKey(ref dbKeyChampRead);
                }
                if (dbKeyChampRead == null)
                {
                    m_champ = null;
                }
                else
                {
                    m_champ = new CChampCustom(contexte);
                    if (!m_champ.ReadIfExists(dbKeyChampRead))
                    {
                        m_champ = null;
                    }
                }
                break;
            }
            return(result);
        }
示例#8
0
 /// //////////////////////////////////////////////////////
 public CDefinitionProprieteDynamiqueChampCustomFils(CChampCustom champ)
     : base(
         champ.LibellePourObjetParent.Replace(" ", "_"),
         GetKeyChamp(champ),
         new CTypeResultatExpression(champ.Role.TypeAssocie, true),
         true,
         true)
 {
     m_dbKeyChamp = champ.DbKey;
 }
示例#9
0
        //---------------------------------------------------------------------------------
        public static object GetValeurChamp(IObjetDonneeAChamps objet, string strIdChamp)
        {
            CChampCustom champ = new CChampCustom(objet.ContexteDonnee);

            if (champ.ReadIfExists(CDbKey.CreateFromStringValue(strIdChamp)))
            {
                return(GetValeurChamp(objet, champ.Id, DataRowVersion.Default));
            }
            return(null);
        }
示例#10
0
        public static int GetIdFromDbKey(CDbKey dbKey)
        {
            CChampCustom champ = new CChampCustom(CContexteDonneeSysteme.GetInstance());

            if (champ.ReadIfExists(dbKey))
            {
                return(champ.Id);
            }

            return(-1);
        }
示例#11
0
        /// //////////////////////////////////////////////////////
        private static string GetKeyChamp(CChampCustom champ)
        {
            if (champ.TypeDonneeChamp.TypeDonnee == sc2i.data.dynamic.TypeDonnee.tObjetDonneeAIdNumeriqueAuto)
            {
                return(CInfoRelationComposantFiltreChampToEntite.GetKeyChamp(champ, true) + "." +
                       CDefinitionProprieteDynamique.c_strCaractereStartCleType + c_strCleType +
                       CDefinitionProprieteDynamique.c_strCaractereEndCleType +
                       CInfoRelationComposantFiltreEntiteToChampEntite.GetKeyChamp(champ, false));
            }

            return(champ.Nom.Replace(" ", "_"));
        }
        //------------------------------------------------------------
        public override CResultAErreur GetValue(object objet, string strPropriete)
        {
            CResultAErreur result = CResultAErreur.True;

            result.Data = null;
            string strIdChamp     = null;
            bool   bEntiteToChamp = false;

            if (

                /*Pour compatibilité, avant modifs de décembre 2015, le nom du champ était en fait le même qu'une propriété champ custom.
                 * En décembre 2015, ajout de la possiblité de retourner les valeurs display de champ custom dans les requêtes,
                 * ce qui a changé le nom de la propriétés
                 * */
                CInfoRelationEntiteToValeurChampCustom.DecomposeNomPropriete(strPropriete, ref strIdChamp) ||
                /*fin pour compatiblité*/
                CInfoRelationComposantFiltreEntiteToChampEntite.DecomposeNomPropriete(strPropriete, ref strIdChamp, ref bEntiteToChamp))
            {
                IElementAChamps eltAChamps = objet as IElementAChamps;
                if (eltAChamps == null)
                {
                    return(result);
                }
                result.Data = eltAChamps.GetValeurChamp(strIdChamp);
                CChampCustom champ = new CChampCustom(CContexteDonneeSysteme.GetInstance());
                if (result.Data != null && champ.ReadIfExists(CDbKey.CreateFromStringValue(strIdChamp)))
                {
                    if (!champ.IsChoixParmis())
                    {
                        result.Data = result.Data.ToString();
                    }
                    else
                    {
                        foreach (CValeurChampCustom valeur in champ.ListeValeurs)
                        {
                            if (valeur.Value.Equals(result.Data))
                            {
                                result.Data = valeur.Display;
                                return(result);
                            }
                        }
                    }
                }
            }
            else if (CInfoRelationEValeurChampCustomToDisplay.DecomposeNomPropriete(strPropriete, ref strIdChamp))
            {
                //Rien de spécial, il s'agit de la navigation vers la valeur du champ qui a déjà été reprise par le composant filtre to champ entité
                //car la propriété complète d'un definitionDisplayValue est donnée par GetKeyChamp qui ajoute un composant Element->ValeurChamp + ValeurChamp->Display value
                result.Data = objet;
            }

            return(result);
        }
示例#13
0
 public static object GetValeurChamp(this IElementAChamps elt, CDbKey key, DataRowVersion version)
 {
     if (key != null)
     {
         CChampCustom champ = new CChampCustom(CContexteDonneeSysteme.GetInstance());
         if (champ.ReadIfExists(key))
         {
             return(elt.GetValeurChamp(champ.Id, version));
         }
     }
     return(null);
 }
示例#14
0
        //---------------------------------------------------------------------------------
        public static CResultAErreur SetValeurChamp(IObjetDonneeAChamps objet, string strIdChamp, object valeur)
        {
            CResultAErreur result = CResultAErreur.True;

            CChampCustom champ = new CChampCustom(objet.ContexteDonnee);

            if (champ.ReadIfExists(CDbKey.CreateFromStringValue(strIdChamp)))
            {
                return(SetValeurChamp(objet, champ.Id, valeur));
            }

            result.EmpileErreur("Invalid Custom Field Id in SetValeurChamps (Line 179)");
            return(result);
        }
示例#15
0
        //----------------------------------------------------------------
        public CDefinitionProprieteDynamique GetProprieteInverse(Type typePortantLaPropriete, CDefinitionProprieteDynamique def)
        {
            CDefinitionProprieteDynamiqueChampCustomFils defFils = def as CDefinitionProprieteDynamiqueChampCustomFils;

            if (defFils == null)
            {
                return(null);
            }
            CChampCustom champ = new CChampCustom(CContexteDonneeSysteme.GetInstance());

            if (champ.ReadIfExists(defFils.KeyChamp))
            {
                return(new CDefinitionProprieteDynamiqueChampCustom(champ));
            }
            return(null);
        }
        public COptimiseurProprieteDynamiqueChampCustomDisplayValue(CDbKey keyChamp)
        {
            m_dbKeyChamp = keyChamp;
            CChampCustom champ = new CChampCustom(CContexteDonneeSysteme.GetInstance());

            if (champ.ReadIfExists(keyChamp))
            {
                if (champ.IsChoixParmis())
                {
                    foreach (CValeurChampCustom valeur in champ.ListeValeurs)
                    {
                        m_dicValeurs[valeur.Value] = valeur.Display;
                    }
                }
            }
        }
示例#17
0
        //----------------------------------------------------------------------------------
        public CResultAErreur CreateChampInTable(IChampDeTable champExport, DataTable table)
        {
            CResultAErreur result = CResultAErreur.True;

            if (champExport is C2iChampExport && ((C2iChampExport)champExport).Origine is C2iOrigineChampExportChampCustom)
            {
                C2iOrigineChampExportChampCustom origineCustom = (C2iOrigineChampExportChampCustom)((C2iChampExport)champExport).Origine;
                //Récupère les noms et les types des champs custom
                CContexteDonnee ctx = null;
                if (table.DataSet is CContexteDonnee)
                {
                    ctx = (CContexteDonnee)table.DataSet;
                }
                else
                {
                    ctx = new CContexteDonnee(0, true, false);
                }
                //Lit les champs custom
                CListeObjetsDonnees listeChamps = new CListeObjetsDonnees(ctx, typeof(CChampCustom));
                listeChamps.AssureLectureFaite();

                foreach (int nIdChamp in origineCustom.IdsChampCustom)
                {
                    CChampCustom champ = new CChampCustom(ctx);
                    if (champ.ReadIfExists(nIdChamp))
                    {
                        if (champ.TypeDonneeChamp.TypeDonnee != TypeDonnee.tObjetDonneeAIdNumeriqueAuto)
                        {
                            DataColumn colChamp = new DataColumn(c_strPrefixeChampCustom + champ.Nom, champ.TypeDonnee.TypeDotNetNatif);
                            colChamp.AllowDBNull = true;
                            table.Columns.Add(colChamp);
                        }
                    }
                }
                return(result);
            }

            if (table.Columns.Contains(champExport.NomChamp))
            {
                return(result);
            }
            DataColumn col = new DataColumn(champExport.NomChamp, champExport.TypeDonnee);

            table.Columns.Add(col);
            return(result);
        }
 //---------------------------------------------------------------
 public IChampPourVersion GetChamp(IElementAChampPourVersion element)
 {
     if (element.TypeChamp == CChampCustomPourVersion.c_typeChamp)
     {
         try
         {
             int          nIdChamp = Int32.Parse(element.FieldKey);
             CChampCustom champ    = new CChampCustom(element.ContexteDonnee);
             if (champ.ReadIfExists(nIdChamp))
             {
                 return(new CChampCustomPourVersion(champ));
             }
         }
         catch { }
     }
     return(null);
 }
示例#19
0
        /// /////////////////////////////////////////////////////////////
        private void UpdateLiensChampsCustom(C2iWnd fenetre)
        {
            CListeObjetsDonnees listeRelations = RelationsChamps;
            Hashtable           tableRelations = new Hashtable();
            Hashtable           tableToDelete  = new Hashtable();

            foreach (CRelationFormulaireChampCustom rel in listeRelations)
            {
                tableRelations[rel.Champ.Id] = rel;
                tableToDelete[rel.Champ.Id]  = rel;
            }

            if (fenetre != null)
            {
                ArrayList lst = fenetre.AllChilds();
                foreach (object obj in lst)
                {
                    if (obj is C2iWndChampCustom)
                    {
                        C2iWndChampCustom fenChamp = (C2iWndChampCustom)obj;
                        CChampCustom      champ    = fenChamp.ChampCustom;
                        if (champ != null)
                        {
                            CRelationFormulaireChampCustom rel = (CRelationFormulaireChampCustom)tableRelations[champ.Id];
                            if (rel == null)
                            {
                                rel = new CRelationFormulaireChampCustom(ContexteDonnee);
                                rel.CreateNewInCurrentContexte();
                                rel.Champ                = champ;
                                rel.Formulaire           = this;
                                tableRelations[champ.Id] = rel;
                            }
                            tableToDelete.Remove(champ.Id);
                            rel.NumWeb     = fenChamp.WebNumOrder;
                            rel.LibelleWeb = fenChamp.WebLabel;
                        }
                    }
                }
            }
            foreach (CRelationFormulaireChampCustom rel in tableToDelete.Values)
            {
                rel.Delete();
            }
        }
        /// ////////////////////////////////////////////////////////////////
        //Retourne le texte de la clause join à mettre dans SQL
        public override string GetJoinClause(
            string strAliasTableParente,
            string strSuffixeParent,
            string strAliasTableFille,
            string strSuffixeFils)
        {
            string strAliasTableValeursChampCustom = strAliasTableFille;
            string strAliasTableValeurDuChamp      = strAliasTableParente;
            string strSuffixeValeursChampsCustom   = strSuffixeFils;
            string strSuffixeValeurDuChamp         = strSuffixeParent;

            string strJoin        = "";
            int    nIdChamp       = CChampCustom.GetIdFromDbKey(m_dbKeyChamp);
            string strChampValeur = CRelationElementAChamp_ChampCustom.c_champValeurString;

            strJoin = strAliasTableParente + "." + strChampValeur + strSuffixeValeurDuChamp + "=" +
                      strAliasTableValeursChampCustom + "." + CValeurChampCustom.c_champValue + strSuffixeValeursChampsCustom + " and " +
                      strAliasTableValeursChampCustom + "." + CChampCustom.c_champId + strSuffixeValeursChampsCustom + "=" + nIdChamp.ToString();
            return(strJoin);
        }
示例#21
0
        //-------------------------------------------------------------------
        //S'il n'y a pas de paramètres, lit tous les champs custom
        public static void ReadChampsCustom(CListeObjetsDonnees lstObjets, params int[] idsChamps)
        {
            if (lstObjets.Count == 0)
            {
                return;
            }
            IObjetDonneeAChamps eltAChamps = lstObjets[0] as IObjetDonneeAChamps;

            if (eltAChamps == null)
            {
                return;
            }
            if (idsChamps.Length == 0)
            {
                lstObjets.ReadDependances("RelationsChampsCustom");
                foreach (IObjetDonneeAChamps eltAChamp in lstObjets)
                {
                    SetTousChampsLus(eltAChamp);
                }
                return;
            }
            List <string> lstChamps = new List <string>();

            foreach (int nIdChamp in idsChamps)
            {
                CChampCustom champ = new CChampCustom(eltAChamps.ContexteDonnee);
                if (champ.ReadIfExists(nIdChamp))
                {
                    CDefinitionProprieteDynamiqueChampCustom def = new CDefinitionProprieteDynamiqueChampCustom(champ);
                    lstChamps.Add(def.NomPropriete);
                }
            }
            lstObjets.ReadDependances(lstChamps.ToArray());
            foreach (IObjetDonneeAChamps eltAChamp in lstObjets)
            {
                foreach (int nIdChamp in idsChamps)
                {
                    SetChampsLus(eltAChamp, nIdChamp);
                }
            }
        }
示例#22
0
        //-------------------------------------------------------------------
        public virtual IRelationDefinisseurChamp_ChampCustom[] GetRelationsChampsHorsFormulaire()
        {
            ArrayList listeRelations = new ArrayList();
            Hashtable tableChamps    = new Hashtable();

            foreach (IDefinisseurChampCustom definisseur in DefinisseursDeChamps)
            {
                foreach (IRelationDefinisseurChamp_ChampCustom relChamp in definisseur.RelationsChampsCustomDefinis)
                {
                    CChampCustom champ = relChamp.ChampCustom;
                    if (tableChamps[champ] == null)
                    {
                        tableChamps[champ] = champ;
                        listeRelations.Add(relChamp);
                    }
                }
            }
            listeRelations.Sort( );

            return((IRelationDefinisseurChamp_ChampCustom[])listeRelations.ToArray(typeof(IRelationDefinisseurChamp_ChampCustom)));
        }
示例#23
0
        public string GetCleRestrictionCompatible(string strAncienneCleRestriction)
        {
            if (strAncienneCleRestriction.Length > CChampCustom.c_prefixeCleRestriction.Length &&
                strAncienneCleRestriction.Substring(
                    0, CChampCustom.c_prefixeCleRestriction.Length) == CChampCustom.c_prefixeCleRestriction)
            {
                // Lire l'Id du Champ Custom
                int    nIdChamp          = -1;
                string strExtractIdChamp = strAncienneCleRestriction.Substring(CChampCustom.c_prefixeCleRestriction.Length);
                try
                {
                    nIdChamp = Int32.Parse(strExtractIdChamp);
                    CChampCustom champ = new CChampCustom(CContexteDonneeSysteme.GetInstance());
                    if (champ.ReadIfExists(nIdChamp))
                    {
                        return(champ.CleRestriction);
                    }
                }
                catch { }
            }

            return(strAncienneCleRestriction);
        }
 /// ///////////////////////////////////////////////////////////////////////////////////////
 public static object GetNewFor(CChampCustom champ, object valeur)
 {
     return(GetNewForTypeDonnee(champ.TypeDonnee, valeur));
 }
示例#25
0
        //-------------------------------------------------------------------
        public static CResultAErreur SetValeurChamp(IObjetDonneeAChamps objet, int nIdChamp, object valeur)
        {
            /*
             * ///Stef 18052011, passage de la recherche de l'élément sous forme de fonction
             *
             *          string strTableValeurs = objet.GetNomTableRelationToChamps();
             *          string strChampId = objet.GetChampId();
             *          object dummy = null;
             *          if (!objet.IsDependanceChargee(strTableValeurs, strChampId))
             *                  dummy = objet.RelationsChampsCustom;
             *          DataTable table = objet.ContexteDonnee.Tables[strTableValeurs];
             *
             *          string strFiltre = CChampCustom.c_champId + "=" + nIdChamp + " and " +
             *                  strChampId + "=" + ((IObjetDonneeAIdNumerique)objet).Id;
             *
             *
             * //Stef 20/07/2010 : si on fait un set avec version à -1, on modifie la version Referentiel.
             * //Le pb était que si on ne fait pas ça, on utilise CContexteDonnee.c_colIsHorsVersion = 0,
             * //ce qui peut ramener plus d'1 élément, du coup, applique version fonctionne de manière aléatoire
             * //car parfois, on modifie bien la version référentiel, d'autres fois, on modifie
             * //autre chose (suivant ce qui est dans le contexte de données).
             * if (objet.ContexteDonnee.IdVersionDeTravail == null || objet.ContexteDonnee.IdVersionDeTravail == -1)
             *          {
             *                  strFiltre += " and " + CSc2iDataConst.c_champIdVersion + " is null and " +
             *                          CSc2iDataConst.c_champIsDeleted + "=0";
             *          }
             *          else
             *          {
             *                  strFiltre += " and " + CContexteDonnee.c_colIsHorsVersion + "=0";
             *          }
             *
             *          DataRow[] rows = table.Select(strFiltre);
             *          if (rows.Length > 0)
             *          {
             *                  CRelationElementAChamp_ChampCustom rel = (CRelationElementAChamp_ChampCustom)objet.ContexteDonnee.GetNewObjetForTable(table);
             *                  rel.SetRow(rows[0]);
             *                  rel.Valeur = valeur;
             *                  return CResultAErreur.True;
             *          }*/
            CRelationElementAChamp_ChampCustom rel = GetRelationToChamp(objet, nIdChamp);

            if (rel != null)
            {
                rel.Valeur = valeur;
                return(CResultAErreur.True);
            }


            CChampCustom   champ  = new CChampCustom(objet.ContexteDonnee);
            CResultAErreur result = CResultAErreur.True;

            if (champ.ReadIfExists(nIdChamp))
            {
                CRelationElementAChamp_ChampCustom relation = objet.GetNewRelationToChamp();
                relation.CreateNewInCurrentContexte();
                relation.ElementAChamps = objet;
                relation.ChampCustom    = champ;
                relation.Valeur         = valeur;
            }
            else
            {
                result.EmpileErreur(I.T("The field n°@1 doesn't exist|234", nIdChamp.ToString()));
            }
            return(result);
        }
        /// //////////////////////////////////////////////////
        public override CResultAErreur GetComposantFiltreData(CFiltreDynamique filtre, CFiltreData filtreData)
        {
            CResultAErreur result = CResultAErreur.True;
            //Vérifie que l'expression condition est OK
            CContexteEvaluationExpression contexteEvaluation = new CContexteEvaluationExpression(filtre);

            result = ConditionApplication.Eval(contexteEvaluation);
            if (!result)
            {
                result.EmpileErreur(I.T("Error while evaluation of @1|143", ConditionApplication.GetString()));
                return(result);
            }

            if (result.Data == null || !((result.Data is bool && (bool)result.Data) || result.Data.ToString() == "1"))
            {
                result.Data = null;
                return(result);
            }


            string strNomChamp      = m_champ.NomPropriete;
            CDbKey dbKeyChampCustom = null;

            if (m_champ is CDefinitionProprieteDynamiqueChampCustom)
            {
                CComposantFiltreOperateur opPrincipal = null;
                dbKeyChampCustom = ((CDefinitionProprieteDynamiqueChampCustom)m_champ).DbKeyChamp;
                strNomChamp      = m_champ.NomPropriete;
                string strAcces = "";
                //Trouve le nom du champ et le chemin d'accès
                int nPos = strNomChamp.LastIndexOf(".");
                if (nPos != -1)
                {
                    strAcces    = strNomChamp.Substring(0, nPos + 1);
                    strNomChamp = strNomChamp.Substring(nPos + 1);
                }
                strAcces += "RelationsChampsCustom.";

                int nIdChamp = CChampCustom.GetIdFromDbKey(dbKeyChampCustom);

                CComposantFiltreOperateur operateurIdChamp = new CComposantFiltreOperateur(CComposantFiltreOperateur.c_IdOperateurEgal);
                CComposantFiltreChamp     compo1           = new CComposantFiltreChamp(strAcces + CChampCustom.c_champId, CContexteDonnee.GetNomTableForType(filtre.TypeElements));
                compo1.IdChampCustom = nIdChamp;
                operateurIdChamp.Parametres.Add(compo1);
                operateurIdChamp.Parametres.Add(new CComposantFiltreConstante(nIdChamp));
                opPrincipal = new CComposantFiltreOperateur(CComposantFiltreOperateur.c_IdOperateurEt);
                opPrincipal.Parametres.Add(operateurIdChamp);
                //Stef, 28072008 : pour tester si un champ est null, on vérifie CRelationElementAChamp_ChampCustom.c_champValeurNull
                //et non pas les valeurs suivant le type

                /*if ( typeChamp == typeof(double))
                 *      strNomChamp = CRelationElementAChamp_ChampCustom.c_champValeurDouble;
                 * else if ( typeChamp == typeof(int))
                 *      strNomChamp = CRelationElementAChamp_ChampCustom.c_champValeurInt;
                 * else if ( typeChamp == typeof(DateTime) || typeChamp == typeof(CDateTimeEx) )
                 *      strNomChamp = CRelationElementAChamp_ChampCustom.c_champValeurDate;
                 * else if ( typeChamp == typeof(bool))
                 *      strNomChamp = CRelationElementAChamp_ChampCustom.c_champValeurBool;
                 * else
                 *      strNomChamp = CRelationElementAChamp_ChampCustom.c_champValeurString;
                 */
                strNomChamp = CRelationElementAChamp_ChampCustom.c_champValeurNull;

                strNomChamp = strAcces + strNomChamp;

                CComposantFiltreChamp composantChamp = new CComposantFiltreChamp(strNomChamp, CContexteDonnee.GetNomTableForType(filtre.TypeElements));
                composantChamp.IdChampCustom = nIdChamp;
                CComposantFiltre composantOperateur = new CComposantFiltreOperateur(
                    m_bTestNull ? CComposantFiltreOperateur.c_IdOperateurDifferent : CComposantFiltreOperateur.c_IdOperateurEgal);
                composantOperateur.Parametres.Add(composantChamp);
                composantOperateur.Parametres.Add(new CComposantFiltreConstante(0));

                opPrincipal.Parametres.Add(composantOperateur);
                composantOperateur = opPrincipal;
                result.Data        = composantOperateur;
                //Stef 28072008, fin modif
            }
            else
            {
                CComposantFiltreChamp composantChamp = new CComposantFiltreChamp(strNomChamp, CContexteDonnee.GetNomTableForType(filtre.TypeElements));
                composantChamp.IdChampCustom = CChampCustom.GetIdFromDbKey(dbKeyChampCustom);
                CComposantFiltre composantOperateur;

                if (!m_bTestNull)
                {
                    composantOperateur = new CComposantFiltreHas();
                }
                else
                {
                    composantOperateur = new CComposantFiltreHasNo();
                }

                composantOperateur.Parametres.Add(composantChamp);
                result.Data = composantOperateur;
            }
            return(result);
        }
示例#27
0
 //-----------------------------------------------------
 public CChampCustomPourVersion(CChampCustom champ)
 {
     m_champ = champ;
 }
示例#28
0
        /// //////////////////////////////////////////////////
        protected override CResultAErreur MySerialize(C2iSerializer serializer)
        {
            int            nVersion = GetNumVersion();
            CResultAErreur result   = serializer.TraiteVersion(ref nVersion);

            if (!result)
            {
                return(result);
            }
            result = base.MySerialize(serializer);
            if (!result)
            {
                return(result);
            }

            bool bHasChamp = m_champCustom != null;

            serializer.TraiteBool(ref bHasChamp);
            int nId = 0;

            if (bHasChamp)
            {
                switch (serializer.Mode)
                {
                /* TESTDBKEYOK (XL) */
                case ModeSerialisation.Ecriture:
                    CDbKey dbKeyW = m_champCustom.DbKey;
                    serializer.TraiteDbKey(ref dbKeyW);
                    break;

                case ModeSerialisation.Lecture:
                    CDbKey dbKey = null;
                    if (nVersion < 4)
                    {
                        serializer.ReadDbKeyFromOldId(ref dbKey, typeof(CChampCustom));
                    }
                    else
                    {
                        serializer.TraiteDbKey(ref dbKey);
                    }

                    CContexteDonnee ctx = (CContexteDonnee)serializer.GetObjetAttache(typeof(CContexteDonnee));
                    if (ctx == null)
                    {
                        ctx = CContexteDonneeSysteme.GetInstance();
                    }
                    m_champCustom = new CChampCustom(ctx);
                    if (!m_champCustom.ReadIfExists(dbKey))
                    {
                        m_champCustom = null;
                    }

                    break;
                }
            }
            else
            {
                m_champCustom = null;
            }

            if (nVersion > 0)
            {
                serializer.TraiteString(ref m_strLibelleWeb);
                serializer.TraiteInt(ref m_nNumWeb);
            }
            if (nVersion >= 2)
            {
                serializer.TraiteBool(ref m_bUseCombo);
            }
            else
            {
                m_bUseCombo = false;
            }
            if (nVersion >= 3)
            {
                serializer.TraiteBool(ref m_bAutoSetValue);
            }
            return(result);
        }
示例#29
0
        //---------------------------------------------------------------------------------
        public static object GetValeurChamp(IObjetDonneeAChamps objet, int nIdChamp, DataRowVersion version)
        {
            string strTableValeurs = objet.GetNomTableRelationToChamps();
            string strChampId      = objet.GetChampId();

            if (!objet.IsDependanceChargee(strTableValeurs, strChampId) && !IsChampLu(objet, nIdChamp))
            {
                object dummy;
                dummy = objet.RelationsChampsCustom;
                SetTousChampsLus(objet);
            }

            DataTable table     = objet.ContexteDonnee.Tables[strTableValeurs];
            string    strFiltre = CChampCustom.c_champId + "=" + nIdChamp + " and " +
                                  strChampId + "=" + ((IObjetDonneeAIdNumerique)objet).Id;

            //Stef 20/07/2010 : si on fait un get avec version à -1, on récupère la version Referentiel.
            //Le pb était que si on ne fait pas ça, on utilise CContexteDonnee.c_colIsHorsVersion = 0,
            //ce qui peut ramener plus d'1 élément, du coup, GetValeur champ retourne
            //n'importe quelle valeur, et pas forcement celle du référentiel
            if (table.Columns.Contains(CSc2iDataConst.c_champIdVersion))
            {
                if (objet.ContexteDonnee.IdVersionDeTravail == null || objet.ContexteDonnee.IdVersionDeTravail == -1)
                {
                    strFiltre += " and " + CSc2iDataConst.c_champIdVersion + " is null and " +
                                 CSc2iDataConst.c_champIsDeleted + "=0";
                }
                else
                {
                    strFiltre += " and " + CContexteDonnee.c_colIsHorsVersion + "=0";
                }
            }
            DataRow[] rows = table.Select(strFiltre);

            if (rows.Length > 0)
            {
                CRelationElementAChamp_ChampCustom rel = (CRelationElementAChamp_ChampCustom)objet.ContexteDonnee.GetNewObjetForTable(table);
                DataRow row = rows[0];
                if (row.HasVersion(version))
                {
                    rel.SetRow(row);
                    rel.VersionToReturn = version;
                    return(rel.Valeur);
                }
                else
                {
                    return(null);
                }
            }


            /*CListeObjetsDonnees liste = GetRelationsToChamps(nIdChamp);
             *
             * if (liste.Count > 0)
             *  return ((CRelationElementAChamp_ChampCustom) liste[0]).Valeur;*/

            //Changement le 12/10/03 :

            /*Si l'objet n'a pas la relation du champ, mais qu'elle devrait (par ses groupes),
             * retourne la valeur par défaut du champ
             * si le champ ne doit pas apparaitre dans cet élément, retourne null
             * */
            // Lecture de la valeur par défaut du champ
            /* le 3/2/04 pourquoi ? ça ralentit tout !!, annule cette modif*/
            CChampCustom champ = new CChampCustom(objet.ContexteDonnee);

            if (champ.ReadIfExists(nIdChamp))
            {
                object valeurParDefaut = champ.ValeurParDefaut;

                /*if ( valeurParDefaut == null )
                 *  return null;
                 * //La valeur par défaut n'est pas null, regarde si cet élément doit avoir ce champ
                 * foreach ( CChampCustom champNormal in TousLesChamps )
                 * {
                 *      if ( champNormal == champ )
                 *          return valeurParDefaut;
                 * }*/
                return(valeurParDefaut);
            }
            return(null);
        }
 /// //////////////////////////////////////////////////////
 public CDefinitionProprieteDynamiqueChampCustomDisplayValue(CChampCustom champ)
     : base(champ, GetKeyChamp(champ), true)
 {
 }