//------------------------------------------------------------------------------------- public void AppliqueRestrictions( CListeRestrictionsUtilisateurSurType lstRestrictions, CGestionnaireReadOnlySysteme gestionnaire) { if (SourceType == null) { return; } CRestrictionUtilisateurSurType restriction = lstRestrictions.GetRestriction(SourceType); if (restriction != null) { foreach (KeyValuePair <object, CInfoControle> kv in m_dicControleToInfo) { CInfoControle info = kv.Value; if (info.Field.Length > 0) { ERestriction rest = restriction.GetRestriction(info.Field); Control ctrl = kv.Key as Control; if (ctrl != null) { if ((rest & ERestriction.ReadOnly) == ERestriction.ReadOnly) { gestionnaire.SetReadOnly(ctrl, true); } else { gestionnaire.SetReadOnly(ctrl, false); } } } } } }
//------------------------------------------------------------------------- public virtual bool GetLinkFieldAutoUpdate(object extendee) { CInfoControle info = GetInfo(extendee, false); if (info != null) { return(info.AutoUpdate); } return(true); }
public virtual string GetLinkField(object extendee) { CInfoControle info = GetInfo(extendee, false); if (info != null) { return(info.Field); } return(""); }
//------------------------------------------------------------------------- private CInfoControle GetInfo(object extendee, bool bCreate) { CInfoControle info = null; if (!m_dicControleToInfo.TryGetValue(extendee, out info) && bCreate) { info = new CInfoControle(); m_dicControleToInfo[extendee] = info; } return(info); }
//------------------------------------------------------------------------- public virtual void SetLinkField(object extendee, string strField) { CInfoControle info = GetInfo(extendee, true); info.Field = strField; if (extendee is Control && strField.Trim() != "" && DesignMode) { if (!(extendee is CheckBox) && !(extendee is RadioButton) && !(extendee is NumericUpDown) ) { try { ((Control)extendee).Text = "[" + strField + "]"; } catch { } } } }
//------------------------------------------------------------------------- public virtual CResultAErreur FillObjetFromDialog(object obj) { CResultAErreur result = CResultAErreur.True; Type tp = obj.GetType(); foreach (Control ctrl in m_dicControleToInfo.Keys) { if (!(ctrl is Label)) { 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) { strProp = strProp.Substring(0, strProp.LastIndexOf(".")); } if (strProp.IndexOf('.') < 0)//Uniquement les propriétés directes de l'objet { PropertyInfo prop = tp.GetProperty(strProp); if (prop != null) { MethodInfo method = prop.GetSetMethod(); if (method != null) { /* * object objValue = method.Invoke(obj, null); * if ( objValue != null ) * objValue = (object) ctrl.Text; */ object[] valeur; if (ctrl is DateTimePicker) { valeur = new object[] { ((DateTimePicker)ctrl).Value }; } else if (ctrl is C2iDateTimeExPicker) { valeur = new object[] { ((C2iDateTimeExPicker)ctrl).Value }; } else { if (ctrl is NumericUpDown) { if (((NumericUpDown)ctrl).DecimalPlaces == 0) { valeur = new object[] { (int)((NumericUpDown)ctrl).Value } } ; else { valeur = new object[] { (double)((NumericUpDown)ctrl).Value } }; } else if (ctrl is C2iTextBoxNumerique) { if (!((C2iTextBoxNumerique)ctrl).DecimalAutorise) { valeur = new object[] { ((C2iTextBoxNumerique)ctrl).IntValue } } ; else { valeur = new object[] { (double)((C2iTextBoxNumerique)ctrl).DoubleValue } }; } else { if (ctrl is CheckBox) { valeur = new object[] { ((CheckBox)ctrl).Checked } } ; else { if (ctrl is ComboBox) { valeur = new object[] { ((ComboBox)ctrl).SelectedValue }; if (valeur[0] == System.DBNull.Value) { valeur[0] = null; } } else if (ctrl is I2iControlEditObject) { valeur = new object[] { ((I2iControlEditObject)ctrl).ObjetEdite }; } else { valeur = new object[] { ctrl.Text } }; } } } method.Invoke(obj, valeur); if (OnValideChamp != null) { OnValideChamp(strProp, valeur[0]); } } } } } } catch (Exception e) { result.EmpileErreur(new CErreurException(e)); result.EmpileErreur(I.T("Error while filling the object @1 with @2|30047", obj.ToString(), ctrl.Name.ToString())); } } } return(result); }
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); }
//------------------------------------------------------------------------- public virtual void SetLinkFieldAutoUpdate(object extendee, bool bAutoUpdate) { CInfoControle info = GetInfo(extendee, true); info.AutoUpdate = bAutoUpdate; }