//------------------------------------------------------------------------------
        private Control GetControl(TypeDonnee tp, int nPrecision, string strText)
        {
            Control tempControle = null;

            if (tp == TypeDonnee.tString)
            {
                //Champ libre
                tempControle        = m_textbox;
                m_textbox.MaxLength = 1024;
            }
            else if (tp == TypeDonnee.tDate)
            {
                tempControle = m_datetimePicker;
            }
            else if (tp == TypeDonnee.tEntier)
            {
                tempControle                  = m_numericUpDown;
                m_numericUpDown.Maximum       = 1000000;
                m_numericUpDown.DecimalPlaces = 0;
            }
            else if (tp == TypeDonnee.tDouble)
            {
                tempControle                  = m_numericUpDown;
                m_numericUpDown.Maximum       = 1000000;
                m_numericUpDown.DecimalPlaces = nPrecision;
            }
            else if (tp == TypeDonnee.tBool)
            {
                tempControle    = m_checkBox;
                m_checkBox.Text = strText;
            }

            return(tempControle);
        }
        //--------------------------------------
        private void InitChamps()
        {
            m_txtNomChamp.Text       = m_champEdite.NomChamp;
            m_txtDescription.Text    = m_champEdite.Description;
            m_lblDataType.Text       = new CTypeChampBasique(m_champEdite.TypeChamp).Libelle;
            m_chkNoUpdate.Checked    = m_champEdite.NoUpdateFromSnmp;
            m_chkNoWriteSNMP.Checked = m_champEdite.IsReadOnly;
            m_lblAcces.Text          = m_champEdite.IsReadOnly ? I.T("Read only|20296") : I.T("Read/write|20297");

            CFournisseurGeneriqueProprietesDynamiques fournisseur = new CFournisseurGeneriqueProprietesDynamiques();
            CEntiteSnmpPourSupervision entiteTest = m_typeEntite.GetEntiteDeTest();

            m_txtFormuleIndex.Init(fournisseur,
                                   new CObjetPourSousProprietes(entiteTest));
            m_txtFormuleIndex.Formule = m_champEdite.FormuleIndex;

            TypeDonnee typeChampMap = TypeDonnee.tString;

            switch (m_champEdite.TypeChamp)
            {
            case ETypeChampBasique.Bool:
                typeChampMap = TypeDonnee.tBool;
                break;

            case ETypeChampBasique.Date:
                typeChampMap = TypeDonnee.tDate;
                break;

            case ETypeChampBasique.Decimal:
                typeChampMap = TypeDonnee.tDouble;
                break;

            case ETypeChampBasique.Int:
                typeChampMap = TypeDonnee.tEntier;
                break;

            case ETypeChampBasique.String:
                typeChampMap = TypeDonnee.tString;
                break;

            default:
                break;
            }
            m_txtSelectChampCustom.InitAvecFiltreDeBase(typeof(CChampCustom),
                                                        "Nom",
                                                        CFiltreData.GetAndFiltre(CChampCustom.GetFiltreChampsForRole(CEntiteSnmp.c_roleChampCustom),
                                                                                 new CFiltreData(CChampCustom.c_champType + "=@1",
                                                                                                 (int)typeChampMap)),
                                                        false);
            CChampCustom champ = new CChampCustom(m_contexteDonnee);

            if (m_champToCustom.IdChampCustom != null && champ.ReadIfExists(m_champToCustom.IdChampCustom.Value))
            {
                m_txtSelectChampCustom.ElementSelectionne = champ;
            }
            else
            {
                m_txtSelectChampCustom.ElementSelectionne = null;
            }
        }
Example #3
0
        /// //////////////////////////////////////////////////////
        private void m_btnTester_Click(object sender, System.EventArgs e)
        {
            C2iExpression expression = GetExpression();

            if (expression == null)
            {
                return;
            }
            if (m_cmbType.SelectedItem == null || !(m_cmbType.SelectedItem is C2iTypeDonnee))
            {
                CFormAlerte.Afficher(I.T("Select a data type|30026"), EFormAlerteType.Exclamation);
                return;
            }
            TypeDonnee tp  = ((C2iTypeDonnee)m_cmbType.SelectedItem).TypeDonnee;
            object     obj = CObjetForTestValeurChampCustom.GetNewForTypeDonnee(tp,
                                                                                null, m_txtTest.Text);
            CContexteEvaluationExpression ctx = new CContexteEvaluationExpression(obj);
            CResultAErreur result             = expression.Eval(ctx);

            if (!result)
            {
                result.EmpileErreur(I.T("Error during validation formula evaluation|30027"));
                CFormAlerte.Afficher(result);
                return;
            }
            if ((result.Data is bool && (bool)result.Data) || result.Data.ToString() == "1")
            {
                CFormAlerte.Afficher(I.T("Accepted value|30028"));
            }
            else
            {
                CFormAlerte.Afficher(I.T("Rejected value|30029"), EFormAlerteType.Erreur);
            }
        }
Example #4
0
        /// /////////////////////////////////////////////////////////
        public static Type GetTypeDotNetFor(TypeDonnee tp, Type typeEntite)
        {
            switch (tp)
            {
            case TypeDonnee.tEntier:
                return(typeof(int));

            case TypeDonnee.tDouble:
                return(typeof(double));

            case TypeDonnee.tString:
                return(typeof(string));

            case TypeDonnee.tDate:
                return(typeof(DateTime));

            case TypeDonnee.tBool:
                return(typeof(bool));

            case TypeDonnee.tObjetDonneeAIdNumeriqueAuto:
                if (typeEntite != null)
                {
                    return(typeEntite);
                }
                return(typeof(CObjetDonneeAIdNumerique));
            }
            return(null);
        }
Example #5
0
        public static Control GetNewControle(TypeDonnee typeChamp)
        {
            Type tp = null;

            m_dicTypeChampToTypeControle.TryGetValue(typeChamp, out tp);
            if (tp != null)
            {
                return((Control)Activator.CreateInstance(tp, new object[0]));
            }
            return(null);
        }
Example #6
0
        //----------------------------------------------------
        public bool AssociationRapide(CContexteDonnee ctxEnEdition, bool bCreationAutomatique)
        {
            if (Champ == null)
            {
                return(false);
            }
            if (IdChampCustom != null)
            {
                return(true);
            }
            string strNomChamp         = Champ.NomChamp;
            CListeObjetsDonnees lst    = new CListeObjetsDonnees(ctxEnEdition, typeof(CChampCustom));
            CFiltreData         filtre = new CFiltreData(CChampCustom.c_champNom + " like @1",
                                                         strNomChamp);
            CChampCustom champ           = new CChampCustom(ctxEnEdition);
            TypeDonnee   typeChampCustom = GetTypeChampCustom(Champ.TypeChamp);
            int          nIndex          = 0;

            while (champ.ReadIfExists(filtre))
            {
                if (champ.CodeRole == CEntiteSnmp.c_roleChampCustom &&
                    champ.TypeDonneeChamp.TypeDonnee == typeChampCustom)
                {
                    IdChampCustom = champ.Id;
                    return(true);
                }
                nIndex++;
                strNomChamp          = Champ.NomChamp + "_" + nIndex;
                filtre.Parametres[0] = strNomChamp;
            }
            if (!bCreationAutomatique)
            {
                return(false);
            }
            champ = new CChampCustom(ctxEnEdition);
            champ.CreateNewInCurrentContexte();
            champ.Nom           = strNomChamp;
            champ.TypeDonneeInt = (int)typeChampCustom;
            champ.CodeRole      = CEntiteSnmp.c_roleChampCustom;
            IdChampCustom       = champ.Id;
            return(true);
        }
Example #7
0
        /// /////////////////////////////////////////////////////////
        public static string GetLibelleType(TypeDonnee type)
        {
            switch (type)
            {
            case TypeDonnee.tEntier:
                return(I.T("Integer|20"));

            case TypeDonnee.tDouble:
                return(I.T("Decimal number|21"));

            case TypeDonnee.tString:
                return(I.T("Text|22"));

            case TypeDonnee.tDate:
                return(I.T("Date / Hour|23"));

            case TypeDonnee.tBool:
                return(I.T("Yes / No|24"));

            case TypeDonnee.tObjetDonneeAIdNumeriqueAuto:
                return(I.T("Entity|25"));
            }
            return("");
        }
Example #8
0
        //----------------------------------------------------
        public static ETypeChampBasique GetTypeChampBasic(TypeDonnee typeChampCustom)
        {
            switch (typeChampCustom)
            {
            case TypeDonnee.tBool:
                return(ETypeChampBasique.Bool);

            case TypeDonnee.tDate:
                return(ETypeChampBasique.Date);

            case TypeDonnee.tDouble:
                return(ETypeChampBasique.Date);

            case TypeDonnee.tEntier:
                return(ETypeChampBasique.Int);

            case TypeDonnee.tObjetDonneeAIdNumeriqueAuto:
                return(ETypeChampBasique.Int);

            case TypeDonnee.tString:
                return(ETypeChampBasique.String);
            }
            return(ETypeChampBasique.String);
        }
Example #9
0
 /// /////////////////////////////////////////////////////////
 public C2iTypeDonnee(TypeDonnee type, Type typeEntite)
 {
     m_typeDonnee = type;
     m_typeEntite = typeEntite;
 }
Example #10
0
 /// /////////////////////////////////////////////////////////
 public C2iTypeDonnee(TypeDonnee type)
 {
     m_typeDonnee = type;
 }
Example #11
0
        /// /////////////////////////////////////////////////////////
        public static object StringToType(TypeDonnee type, string strTexte, CContexteDonnee contexteDonnee)
        {
            if (strTexte.ToUpper() == c_ConstanteNull)
            {
                return(null);
            }
            switch (type)
            {
            case TypeDonnee.tBool:
                return(strTexte.ToString() == "1" || strTexte.ToUpper() == "TRUE");

            case TypeDonnee.tDate:
                try
                {
                    return(Convert.ChangeType(strTexte, typeof(DateTime), null));
                }
                catch
                {
                    //Tente le format sc2i de date chaine
                    try
                    {
                        return(CUtilDate.FromUniversalString(strTexte));
                    }
                    catch
                    {
                        return(null);
                    }
                }

            case TypeDonnee.tDouble:
                try
                {
                    return(CUtilDouble.DoubleFromString(strTexte));
                }
                catch
                {
                    return(null);
                }

            case TypeDonnee.tEntier:
                try
                {
                    return(Convert.ChangeType(strTexte, typeof(int), null));
                }
                catch
                {
                    return(null);
                }

            case TypeDonnee.tString:
                return(strTexte);

            case TypeDonnee.tObjetDonneeAIdNumeriqueAuto:
                try
                {
                    if (contexteDonnee == null)
                    {
                        return(null);
                    }
                    //Syntaxe : classe|id
                    int nPos = strTexte.LastIndexOf("|");
                    if (nPos < 0)
                    {
                        return(null);
                    }
                    string strClasse = strTexte.Substring(0, nPos);
                    int    nId       = Int32.Parse(strTexte.Substring(nPos + 1));
                    Type   tp        = CActivatorSurChaine.GetType(strClasse, true);
                    if (tp != null)
                    {
                        CObjetDonneeAIdNumerique objet = (CObjetDonneeAIdNumerique)Activator.CreateInstance(tp, new object[] { contexteDonnee });
                        if (objet.ReadIfExists(nId))
                        {
                            return(objet);
                        }
                    }
                    return(null);
                }
                catch
                {
                    return(null);
                }
            }
            return(null);
        }
Example #12
0
        /// <summary>
        /// ///////////////////////////////////////////////////////////////////////////////////////
        /// </summary>
        /// <param name="typeDonnee"></param>
        /// <returns></returns>
        public static object GetNewForTypeDonnee(TypeDonnee typeDonnee, Type typeObjetDonnee, object valeur)
        {
            object objTest = null;

            switch (typeDonnee)
            {
            case TypeDonnee.tBool:
                if (valeur == null)
                {
                    objTest = new CObjetForTestValeurChampCustomBool( );
                }
                else
                {
                    objTest = new CObjetForTestValeurChampCustomBool((bool)Convert.ChangeType(valeur, typeof(bool), null));
                }
                break;

            case TypeDonnee.tDate:
                if (valeur == null)
                {
                    objTest = new CObjetForTestValeurChampCustomDateTime( );
                }
                else
                {
                    objTest = new CObjetForTestValeurChampCustomDateTime((DateTime)Convert.ChangeType(valeur, typeof(DateTime), null));
                }
                break;

            case TypeDonnee.tDouble:
                if (valeur == null)
                {
                    objTest = new CObjetForTestValeurChampCustomDouble( );
                }
                else if (valeur is CValeurUnite)
                {
                    objTest = new CObjetForTestValeurChampCustomDouble(((CValeurUnite)valeur).Valeur);
                }
                else
                {
                    objTest = new CObjetForTestValeurChampCustomDouble((double)Convert.ChangeType(valeur, typeof(double), null));
                }
                break;

            case TypeDonnee.tEntier:
                if (valeur == null)
                {
                    objTest = new CObjetForTestValeurChampCustomInt( );
                }
                else
                {
                    objTest = new CObjetForTestValeurChampCustomInt((int)Convert.ChangeType(valeur, typeof(int), null));
                }

                break;

            case TypeDonnee.tString:
                if (valeur == null)
                {
                    objTest = new CObjetForTestValeurChampCustomString();
                }
                else
                {
                    objTest = new CObjetForTestValeurChampCustomString(valeur.ToString());
                }
                break;

            case TypeDonnee.tObjetDonneeAIdNumeriqueAuto:
                CElementAVariablesDynamiques element = CElementAVariablesDynamiques.GetElementAUneVariableType(typeObjetDonnee, "value");
                element.SetValeurChamp((IVariableDynamique)element.ListeVariables[0], valeur);
                objTest = element;
                break;

            default:
                throw new Exception(I.T("The type @1 isn't implemented in the value tests|185", typeDonnee.ToString()));
            }
            return(objTest);
        }
Example #13
0
 public static void RegisterControle(TypeDonnee typeChamp, Type typeControle)
 {
     m_dicTypeChampToTypeControle[typeChamp] = typeControle;
 }