Esempio n. 1
0
        public CResultAErreur FillControl(Control ctrl, object obj)
        {
            CResultAErreur result          = CResultAErreur.True;
            string         strPropAffichee = "";

            try
            {
                CInfoControle info = GetInfo(ctrl, false);
                if (info != null && info.AutoUpdate && info.Field.Length > 0)
                {
                    string strProp = info.Field;
                    if (strProp.LastIndexOf(".") >= 0 && ctrl is ComboBox)
                    {
                        string strTemp = strProp;
                        strProp         = strTemp.Substring(0, strTemp.LastIndexOf("."));
                        strPropAffichee = strTemp.Substring(strTemp.LastIndexOf(".") + 1);
                    }
                    if (strProp != null && strProp != "")
                    {
                        MemberInfo methodeAppellee  = null;
                        object     objetToInterroge = null;
                        object     objValue         = CInterpreteurTextePropriete.GetValue(obj, strProp, ref objetToInterroge, ref methodeAppellee);
                        if (objValue != null)
                        {
                            if (OnRemplitControle != null)
                            {
                                OnRemplitControle(strProp, objValue);
                            }

                            if (ctrl is NumericUpDown)
                            {
                                if (objValue is int)
                                {
                                    ((NumericUpDown)ctrl).Value = new Decimal((int)objValue);
                                }
                                else if (objValue is double)
                                {
                                    ((NumericUpDown)ctrl).Value = new Decimal((double)objValue);
                                }
                                else
                                {
                                    ((NumericUpDown)ctrl).Value = (decimal)objValue;
                                }
                            }
                            else if (ctrl is C2iTextBoxNumerique)
                            {
                                if (objValue is int?)
                                {
                                    ((C2iTextBoxNumerique)ctrl).IntValue = (int?)objValue;
                                }
                                else if (objValue is double?)
                                {
                                    ((C2iTextBoxNumerique)ctrl).DoubleValue = (double?)objValue;
                                }
                                else
                                {
                                    ((C2iTextBoxNumerique)ctrl).DoubleValue = Convert.ToDouble(objValue);
                                }
                            }
                            else if (ctrl is DateTimePicker)
                            {
                                ((DateTimePicker)ctrl).Value = (DateTime)objValue;
                            }
                            else if (ctrl is CheckBox)
                            {
                                ((CheckBox)ctrl).Checked = (bool)objValue;
                            }
                            else if (ctrl is C2iComboBox)
                            {
                                ((C2iComboBox)ctrl).SelectedValue = objValue;
                            }
                            else if (ctrl is ComboBox)
                            {
                                ((ComboBox)ctrl).DisplayMember = strPropAffichee;
                                try
                                { ((ComboBox)ctrl).SelectedValue = objValue; }
                                catch
                                { ((ComboBox)ctrl).SelectedValue = System.DBNull.Value; }
                            }
                            else if (ctrl is I2iControlEditObject)
                            {
                                ((I2iControlEditObject)ctrl).ObjetEdite = objValue;
                            }
                            else if (!(ctrl is CheckBox))
                            {
                                ctrl.Text = CInterpreteurTextePropriete.GetStringValueFormatee(objValue, "", methodeAppellee);
                            }
                        }
                        else
                        {
                            if (ctrl is ComboBox)
                            {
                                ((ComboBox)ctrl).SelectedValue = System.DBNull.Value;
                            }
                            else if (!(ctrl is CheckBox))
                            {
                                ctrl.Text = "";
                            }
                        }

                        if (ctrl is C2iDateTimeExPicker)
                        {
                            ((C2iDateTimeExPicker)ctrl).Value = (CDateTimeEx)objValue;
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
                result.EmpileErreur(new CErreurException(e));
                result.EmpileErreur("Error while loading control @1 by @2||30046", ctrl.Name.ToString(), obj.ToString());
                return(result);
            }
            return(result);
        }