//------------------------------------------------------------
        public sc2i.common.CResultAErreur GetValue(object objet, string strPropriete)
        {
            CResultAErreur result = CResultAErreur.True;
            DataRow        row    = objet as DataRow;

            if (row == null)
            {
                try
                {
                    row = C2iConvert.ChangeType <DataRow>(objet);
                }
                catch { }
            }
            if (row == null)
            {
                return(result);
            }
            if (row.Table.Columns.Contains(strPropriete))
            {
                result.Data = row[strPropriete];
            }
            return(result);
        }
Exemplo n.º 2
0
        //-----------------------------------------------------------
        public void SetValeurDynamiqueDeportee(string strPropriete, object valeur)
        {
            if (m_controleWnd != null && m_controleWnd.Control != null)
            {
                for (int nPasse = 0; nPasse < 2; nPasse++)
                {
                    object objDest = nPasse == 0 ? (object)m_controleWnd.Control : (object)m_controleWnd;
                    Type   tp      = objDest.GetType();
                    List <PropertyInfo> lstInfos = new List <PropertyInfo>();
                    try
                    {
                        PropertyInfo info = tp.GetProperty(strPropriete);
                        if (info != null)
                        {
                            lstInfos.Add(info);
                        }
                    }
                    catch
                    {
                        //Erreur, peut être plusieurs candidats
                        foreach (PropertyInfo info in tp.GetProperties())
                        {
                            if (info.Name == strPropriete)
                            {
                                lstInfos.Add(info);
                            }
                        }
                    }
                    foreach (PropertyInfo info in lstInfos)
                    {
                        if (info != null)
                        {
                            MethodInfo infoMeth = info.GetSetMethod();
                            if (infoMeth != null)
                            {
                                try
                                {
                                    infoMeth.Invoke(objDest, new object[] { valeur });
                                    return;
                                }
                                catch (Exception e1)
                                {
                                    try
                                    {
                                        infoMeth.Invoke(objDest, new object[] { C2iConvert.ChangeType(valeur, info.PropertyType) });
                                        return;
                                    }
                                    catch (Exception e2)
                                    {
                                        //On n'y arrive pas
                                    }
                                }
                            }
                        }
                    }
                }

                //Implémentation de méthode communes;
                Control ctrl = m_controleWnd.Control;
                if (strPropriete == "X" && valeur is int)
                {
                    ctrl.Location = new System.Drawing.Point((int)valeur, ctrl.Location.Y);
                    return;
                }
                if (strPropriete == "HelpText")
                {
                    if (m_controleWnd.Tooltip != null && m_controleWnd.Control != null)
                    {
                        m_controleWnd.Tooltip.SetToolTip(m_controleWnd.Control, valeur == null?"":valeur.ToString());
                    }
                }

                if (strPropriete == "Y" && valeur is int)
                {
                    ctrl.Location = new System.Drawing.Point(ctrl.Location.X, (int)valeur);
                    return;
                }
                if (strPropriete.IndexOf("Font") == 0)
                {
                    bool   bBold      = ctrl.Font.Bold;
                    bool   bItalic    = ctrl.Font.Italic;
                    bool   bStrikeOut = ctrl.Font.Strikeout;
                    bool   bUnderline = ctrl.Font.Underline;
                    string strName    = ctrl.Font.Name;
                    double fSize      = ctrl.Font.Size;
                    if (strPropriete == "FontBold" && valeur is bool)
                    {
                        bBold = (bool)valeur;
                    }
                    if (strPropriete == "FontItalic" && valeur is bool)
                    {
                        bItalic = (bool)valeur;
                    }
                    if (strPropriete == "FontStrikeOut" && valeur is bool)
                    {
                        bStrikeOut = (bool)valeur;
                    }
                    if (strPropriete == "FontUnderline" && valeur is bool)
                    {
                        bUnderline = (bool)valeur;
                    }
                    if (strPropriete == "FontName" && valeur is string)
                    {
                        strName = valeur.ToString();
                    }
                    if (strPropriete == "FontSize" && (valeur is int || valeur is double))
                    {
                        fSize = Convert.ToDouble(valeur);
                    }
                    FontStyle style = FontStyle.Regular;
                    if (bBold)
                    {
                        style |= FontStyle.Bold;
                    }
                    if (bItalic)
                    {
                        style |= FontStyle.Italic;
                    }
                    if (bStrikeOut)
                    {
                        style |= FontStyle.Strikeout;
                    }
                    if (bUnderline)
                    {
                        style |= FontStyle.Underline;
                    }
                    ctrl.Font = new Font(strName, (float)fSize, style);
                    return;
                }
                //On n'a toujours pas trouvé !
                if (m_controleWnd is IElementAProprietesDynamiquesDeportees)
                {
                    ((IElementAProprietesDynamiquesDeportees)m_controleWnd).SetValeurDynamiqueDeportee(strPropriete, valeur);
                }
            }
        }