Exemple #1
0
        //----------------------------------
        public CResultAErreur Serialize(C2iSerializer serializer)
        {
            int            nVersion = GetNumVersion();
            CResultAErreur result   = serializer.TraiteVersion(ref nVersion);

            if (!result)
            {
                return(result);
            }
            serializer.TraiteString(ref m_strDesignationObjet);
            serializer.TraiteType(ref m_typeObjet);
            int nIdObjet = m_nIdObjet == null ? -1 : m_nIdObjet.Value;

            serializer.TraiteInt(ref nIdObjet);
            if (serializer.Mode == ModeSerialisation.Lecture)
            {
                m_nIdObjet = nIdObjet == -1 ? (int?)null : nIdObjet;
            }

            int nVal = m_typeOperation != null?m_typeOperation.CodeInt:0;

            serializer.TraiteInt(ref nVal);
            if (serializer.Mode == ModeSerialisation.Lecture)
            {
                m_typeOperation = new CTypeOperationSurObjet((CTypeOperationSurObjet.TypeOperation)nVal);
            }

            if (nVersion < 1 && serializer.Mode == ModeSerialisation.Lecture)
            {
                int nIdTemp = -1;
                serializer.TraiteInt(ref nIdTemp);
                m_strIdVariableAssociee = nIdTemp.ToString();
            }
            else
            {
                serializer.TraiteString(ref m_strIdVariableAssociee);
            }

            result = serializer.TraiteObject <C2iExpression>(ref m_formuleCondition);
            if (result)
            {
                result = serializer.TraiteObject <C2iExpression>(ref m_formuleSelectionObjet);
            }
            if (result)
            {
                result = serializer.TraiteListe <CMacroObjetValeur>(m_listeValeursObjet, new object[] { this });
            }
            return(result);
        }
Exemple #2
0
 private void SetLabel(CTypeOperationSurObjet typeOp)
 {
 }
Exemple #3
0
 public CControlTypeOperationAuditVersion(CTypeOperationSurObjet typeOp)
 {
     InitializeComponent();
     DoubleBuffered = true;
     SetLabel(typeOp);
 }
Exemple #4
0
        //----------------------------------
        public CResultAErreur FillFromVersion(CVersionDonneesObjet vo, CContexteDonnee contexteEnVersion, Dictionary <CObjetDonneeAIdNumerique, CMacroObjet> dicObjetToMacro)
        {
            CStructureTable structure = CStructureTable.GetStructure(vo.TypeElement);

            List <CDefinitionProprieteDynamique> lstChampsDotNet = new List <CDefinitionProprieteDynamique>();

            lstChampsDotNet.AddRange(new CFournisseurProprietesDynamiqueDynamicField().GetDefinitionsChamps(vo.TypeElement, null));
            List <CDefinitionProprieteDynamique> lstChampsCustom = new List <CDefinitionProprieteDynamique>();

            lstChampsCustom.AddRange(new CFournisseurProprietesDynamiqueChampCustom().GetDefinitionsChamps(vo.TypeElement, null));
            CResultAErreur           result = CResultAErreur.True;
            CObjetDonneeAIdNumerique objet  = Activator.CreateInstance(vo.TypeElement, new object[] { contexteEnVersion }) as CObjetDonneeAIdNumerique;

            if (!objet.ReadIfExists(vo.IdElement))
            {
                objet = null;
            }
            else
            {
                DesignationObjet = objet.DescriptionElement;
            }
            switch (vo.TypeOperation.Code)
            {
            case CTypeOperationSurObjet.TypeOperation.Ajout:
                if (objet != null && objet.IsValide())
                {
                    foreach (CDefinitionProprieteDynamique def in lstChampsDotNet)
                    {
                        string strNom = def.NomProprieteSansCleTypeChamp;
                        if (strNom != "IsDeleted" && strNom != "Id" &&
                            strNom != "ContexteDeModification" && strNom != "IdVersionDatabase")
                        {
                            bool bAdd = !def.IsReadOnly;
                            if (def.IsReadOnly)
                            {
                                //Si readonly mais a l'attribut ForceSetOnMacro, on l'ajoute quand même
                                PropertyInfo info = vo.TypeElement.GetProperty(strNom);
                                if (info != null && info.GetCustomAttributes(typeof(TiagRelationAttribute), true).Length != 0)
                                {
                                    bAdd = true;
                                }
                            }
                            if (bAdd)
                            {
                                CResultAErreur resultVal = CInterpreteurProprieteDynamique.GetValue(objet, def);
                                if (resultVal)
                                {
                                    object            data = resultVal.Data;
                                    CMacroObjetValeur mv   = new CMacroObjetValeur(this);
                                    mv.Champ = def;
                                    if (FillMacroValeurWithValue(mv, data, dicObjetToMacro))
                                    {
                                        AddValeur(mv);
                                    }
                                    else
                                    {
                                        result.EmpileErreur(new CErreurValidation(I.T("#Can not use field @1 of type @2 in macro", def.Nom,
                                                                                      DynamicClassAttribute.GetNomConvivial(vo.TypeElement)), true));
                                    }
                                }
                            }
                        }
                    }
                    if (objet is IObjetDonneeAChamps)
                    {
                        foreach (CRelationElementAChamp_ChampCustom rel in ((IObjetDonneeAChamps)objet).RelationsChampsCustom)
                        {
                            object data = rel.Valeur;
                            if (data != null)
                            {
                                CDefinitionProprieteDynamique defCust = lstChampsCustom.FirstOrDefault(c => ((CDefinitionProprieteDynamiqueChampCustom)c).DbKeyChamp == rel.ChampCustom.DbKey);
                                if (defCust != null)
                                {
                                    CMacroObjetValeur mv = new CMacroObjetValeur(this);
                                    mv.Champ = defCust;
                                    mv.Champ = defCust;
                                    if (FillMacroValeurWithValue(mv, data, dicObjetToMacro))
                                    {
                                        this.AddValeur(mv);
                                    }
                                    else
                                    {
                                        result.EmpileErreur(new CErreurValidation(I.T("#Can not use field @1 of type @2 in macro", rel.ChampCustom.Nom,
                                                                                      DynamicClassAttribute.GetNomConvivial(vo.TypeElement)), true));
                                    }
                                }
                            }
                        }
                    }
                }

                break;

            case CTypeOperationSurObjet.TypeOperation.Suppression:
                break;

            case CTypeOperationSurObjet.TypeOperation.Modification:
                CStructureTable structureObjet = CStructureTable.GetStructure(vo.TypeElement);
                foreach (CVersionDonneesObjetOperation valeur in vo.ToutesLesOperations)
                {
                    CDefinitionProprieteDynamique def   = null;
                    IChampPourVersion             champ = valeur.Champ;
                    if (champ is CChampPourVersionInDb)
                    {
                        string          strNomChamp = ((CChampPourVersionInDb)champ).NomPropriete;
                        CInfoChampTable infoChamp   = structureObjet.Champs.FirstOrDefault(c => c.NomChamp == strNomChamp);
                        if (infoChamp != null && infoChamp.NomChamp != CSc2iDataConst.c_champIdVersion &&
                            infoChamp.NomChamp != CSc2iDataConst.c_champIsDeleted &&
                            infoChamp.NomChamp != CObjetDonnee.c_champContexteModification)
                        {
                            string strNomPropriete = infoChamp.Propriete;
                            def = lstChampsDotNet.FirstOrDefault(c => c.NomProprieteSansCleTypeChamp == strNomPropriete);
                        }
                        if (def == null)
                        {
                            CInfoRelation relation = structureObjet.RelationsParentes.FirstOrDefault(i => i.ChampsFille.Length == 1 && i.ChampsFille[0] == strNomChamp);
                            if (relation != null)
                            {
                                def = lstChampsDotNet.FirstOrDefault(c => c.NomProprieteSansCleTypeChamp == relation.Propriete);
                            }
                        }
                    }
                    else if (champ is CChampCustomPourVersion)
                    {
                        CChampCustom champCustom = ((CChampCustomPourVersion)champ).ChampCustom;
                        if (champCustom != null)
                        {
                            def = lstChampsCustom.FirstOrDefault(c => c is CDefinitionProprieteDynamiqueChampCustom &&
                                                                 ((CDefinitionProprieteDynamiqueChampCustom)c).DbKeyChamp == champCustom.DbKey);
                        }
                    }
                    if (def != null)
                    {
                        bool bAdd = !def.IsReadOnly;
                        if (def.IsReadOnly)
                        {
                            //Si readonly mais a l'attribut TiagRelation, on l'ajoute quand même
                            PropertyInfo info = vo.TypeElement.GetProperty(def.NomProprieteSansCleTypeChamp);
                            if (info != null && info.GetCustomAttributes(typeof(TiagRelationAttribute), true).Length > 0)
                            {
                                bAdd = true;
                            }
                        }
                        if (bAdd)
                        {
                            CMacroObjetValeur mv = new CMacroObjetValeur(this);
                            mv.Champ = def;
                            object val = valeur.GetValeur();
                            if (val != null && typeof(CObjetDonneeAIdNumerique).IsAssignableFrom(def.TypeDonnee.TypeDotNetNatif) && valeur.TypeValeur == typeof(int))
                            {
                                CObjetDonneeAIdNumerique objetParent = Activator.CreateInstance(def.TypeDonnee.TypeDotNetNatif, new object[] { objet.ContexteDonnee }) as CObjetDonneeAIdNumerique;
                                if (objetParent.ReadIfExists((int)valeur.GetValeur()))
                                {
                                    val = objetParent;
                                }
                                else
                                {
                                    val = null;
                                }
                            }

                            if (!FillMacroValeurWithValue(mv, val, dicObjetToMacro))
                            {
                                result.EmpileErreur(new CErreurValidation(I.T("#Can not use field @1 of @2 in macro", valeur.NomChampConvivial,
                                                                              DynamicClassAttribute.GetNomConvivial(vo.TypeElement)), true));
                            }
                            else
                            {
                                AddValeur(mv);
                            }
                        }
                    }
                }
                break;
            }
            if (Valeurs.Count() == 0)
            {
                TypeOperation = new CTypeOperationSurObjet(CTypeOperationSurObjet.TypeOperation.Aucune);
            }
            return(result);
        }
Exemple #5
0
        //----------------------------------
        public CResultAErreur FillFromVersion(CVersionDonneesObjet vo, CContexteDonnee contexteEnVersion, Dictionary <CObjetDonneeAIdNumerique, CMacroObjet> dicObjetToMacro)
        {
            List <CDefinitionProprieteDynamique> lstChampsDotNet = new List <CDefinitionProprieteDynamique>();

            lstChampsDotNet.AddRange(new CFournisseurProprietesDynamiqueDynamicField().GetDefinitionsChamps(vo.TypeElement, null));
            List <CDefinitionProprieteDynamique> lstChampsCustom = new List <CDefinitionProprieteDynamique>();

            lstChampsCustom.AddRange(new CFournisseurProprietesDynamiqueChampCustom().GetDefinitionsChamps(vo.TypeElement, null));
            CResultAErreur           result = CResultAErreur.True;
            CObjetDonneeAIdNumerique objet  = Activator.CreateInstance(vo.TypeElement, new object[] { contexteEnVersion }) as CObjetDonneeAIdNumerique;

            if (!objet.ReadIfExists(vo.IdElement))
            {
                objet = null;
            }
            else
            {
                DesignationObjet = objet.DescriptionElement;
            }
            switch (vo.TypeOperation.Code)
            {
            case CTypeOperationSurObjet.TypeOperation.Ajout:
                if (objet != null && objet.IsValide())
                {
                    foreach (CDefinitionProprieteDynamique def in lstChampsDotNet)
                    {
                        string strNom = def.NomProprieteSansCleTypeChamp;
                        if (!def.IsReadOnly && strNom != "IsDeleted" && strNom != "Id" &&
                            strNom != "ContexteDeModification" && strNom != "IdVersionDatabase")
                        {
                            CResultAErreur resultVal = CInterpreteurProprieteDynamique.GetValue(objet, def);
                            if (resultVal)
                            {
                                object            data = resultVal.Data;
                                CMacroObjetValeur mv   = new CMacroObjetValeur(this);
                                mv.Champ = def;
                                if (FillMacroValeurWithValue(mv, data, dicObjetToMacro))
                                {
                                    AddValeur(mv);
                                }
                                else
                                {
                                    result.EmpileErreur(new CErreurValidation(I.T("Can not use field @1 in macro|20052", def.Nom), true));
                                }
                            }
                        }
                    }
                    if (objet is CElementAChamp)
                    {
                        foreach (CRelationElementAChamp_ChampCustom rel in ((CElementAChamp)objet).RelationsChampsCustom)
                        {
                            object data = rel.Valeur;
                            if (data != null)
                            {
                                CDefinitionProprieteDynamique defCust = lstChampsCustom.FirstOrDefault(c => ((CDefinitionProprieteDynamiqueChampCustom)c).IdChamp == rel.ChampCustom.Id);
                                if (defCust != null)
                                {
                                    CMacroObjetValeur mv = new CMacroObjetValeur(this);
                                    mv.Champ = defCust;
                                    mv.Champ = defCust;
                                    this.AddValeur(mv);
                                    if (FillMacroValeurWithValue(mv, data, dicObjetToMacro))
                                    {
                                        this.AddValeur(mv);
                                    }
                                    else
                                    {
                                        result.EmpileErreur(new CErreurValidation(I.T("Can not use field @1 in macro|20052", rel.ChampCustom.Nom), true));
                                    }
                                }
                            }
                        }
                    }
                }

                break;

            case CTypeOperationSurObjet.TypeOperation.Suppression:
                break;

            case CTypeOperationSurObjet.TypeOperation.Modification:
                CStructureTable structureObjet = CStructureTable.GetStructure(vo.TypeElement);
                foreach (CVersionDonneesObjetOperation valeur in vo.ToutesLesOperations)
                {
                    CDefinitionProprieteDynamique def   = null;
                    IChampPourVersion             champ = valeur.Champ;
                    if (champ is CChampPourVersionInDb)
                    {
                        string          strNomChamp = ((CChampPourVersionInDb)champ).NomPropriete;
                        CInfoChampTable infoChamp   = structureObjet.Champs.FirstOrDefault(c => c.NomChamp == strNomChamp);
                        if (infoChamp != null && infoChamp.NomChamp != CSc2iDataConst.c_champIdVersion &&
                            infoChamp.NomChamp != CSc2iDataConst.c_champIsDeleted &&
                            infoChamp.NomChamp != CObjetDonnee.c_champContexteModification)
                        {
                            string strNomPropriete = infoChamp.Propriete;
                            def = lstChampsDotNet.FirstOrDefault(c => c.NomProprieteSansCleTypeChamp == strNomPropriete);
                        }
                    }
                    else if (champ is CChampCustomPourVersion)
                    {
                        CChampCustom champCustom = ((CChampCustomPourVersion)champ).ChampCustom;
                        if (champCustom != null)
                        {
                            def = lstChampsCustom.FirstOrDefault(c => c is CDefinitionProprieteDynamiqueChampCustom &&
                                                                 ((CDefinitionProprieteDynamiqueChampCustom)c).IdChamp == champCustom.Id);
                        }
                    }
                    if (def != null && !def.IsReadOnly)
                    {
                        CMacroObjetValeur mv = new CMacroObjetValeur(this);
                        mv.Champ = def;
                        if (!FillMacroValeurWithValue(mv, valeur.GetValeur(), dicObjetToMacro))
                        {
                            result.EmpileErreur(new CErreurValidation(I.T("Can not use field @1 in macro|20052", valeur.NomChampConvivial), true));
                        }
                        else
                        {
                            AddValeur(mv);
                        }
                    }
                }
                break;
            }
            if (Valeurs.Count() == 0)
            {
                TypeOperation = new CTypeOperationSurObjet(CTypeOperationSurObjet.TypeOperation.Aucune);
            }
            return(result);
        }