private static void GetOrSetProperties(HtmlTable tblABM, object entidad, eGetOrSet getOrSet) { ASPxTextBox tx; ucComboBox uc; PropertyInfo myPropInfo; Type entityType; PropertyInfo[] myPropertyInfo; //Recorro las properties de la entidad... //Por cada prop, busco en la tabla, un control tx[PROP], o uc[PROP] que coincida. //Si lo encuentro, lo cargo (Text o SelectedValue) con el valor de la propiedad. //Itero entre las propiedades de la entidad. entityType = entidad.GetType(); myPropertyInfo = entityType.GetProperties((BindingFlags.Public | BindingFlags.Instance)); for (int i = 0; i < myPropertyInfo.Length; i++) { tx = null; uc = null; myPropInfo = ((PropertyInfo)myPropertyInfo[i]); if (myPropInfo.CanRead) { tx = FindTextBoxByName(myPropInfo.Name, tblABM); if (tx != null) { if (getOrSet == eGetOrSet.GetFromProperty) tx.Text = Convert.ToString(myPropInfo.GetValue(entidad, null)); else if (getOrSet == eGetOrSet.SetToProperty) myPropInfo.SetValue(entidad, tx.Text, null); else if (getOrSet == eGetOrSet.ClearControls) tx.Text = string.Empty; } uc = FindComboBoxByName(myPropInfo.Name, tblABM); if (uc != null) { if (getOrSet == eGetOrSet.GetFromProperty) uc.SelectedValue = Convert.ToString(myPropInfo.GetValue(entidad, null)); else if (getOrSet == eGetOrSet.SetToProperty) myPropInfo.SetValue(entidad, uc.SelectedValue, null); else if (getOrSet == eGetOrSet.ClearControls) uc.SelectedValue = string.Empty; } ASPxSpinEdit sp = (ASPxSpinEdit)FindControlByName("sp" + myPropInfo.Name, tblABM); if (sp != null) { if (getOrSet == eGetOrSet.GetFromProperty) if (myPropInfo.GetValue(entidad, null) != null) sp.Value = Convert.ToDecimal(myPropInfo.GetValue(entidad, null)); else sp.Value = null; else if (getOrSet == eGetOrSet.SetToProperty) myPropInfo.SetValue(entidad, sp.Value, null); else if (getOrSet == eGetOrSet.ClearControls) sp.Value = null; } ASPxCheckBox cb = (ASPxCheckBox)FindControlByName("cb" + myPropInfo.Name, tblABM); if (cb != null) { if (getOrSet == eGetOrSet.GetFromProperty) cb.Checked = Convert.ToBoolean(myPropInfo.GetValue(entidad, null)); else if (getOrSet == eGetOrSet.SetToProperty) myPropInfo.SetValue(entidad, cb.Checked, null); else if (getOrSet == eGetOrSet.ClearControls) cb.Checked = false; } ASPxRadioButtonList rb = (ASPxRadioButtonList)FindControlByName("rb" + myPropInfo.Name, tblABM); if (rb != null) { if (getOrSet == eGetOrSet.GetFromProperty) rb.SelectedItem = rb.Items.FindByValue(Convert.ToString(myPropInfo.GetValue(entidad, null)).Trim()); else if (getOrSet == eGetOrSet.SetToProperty) if (rb.SelectedItem != null) myPropInfo.SetValue(entidad, rb.SelectedItem.Value, null); else myPropInfo.SetValue(entidad, null, null); else if (getOrSet == eGetOrSet.ClearControls) rb.SelectedIndex = -1; } ASPxTimeEdit te = (ASPxTimeEdit)FindControlByName("te" + myPropInfo.Name, tblABM); if (te != null) { if (getOrSet == eGetOrSet.GetFromProperty) if (myPropInfo.GetValue(entidad, null) != null) te.DateTime = ConvertToDateTime((TimeSpan)myPropInfo.GetValue(entidad, null)); else te.DateTime = DateTime.MinValue; else if (getOrSet == eGetOrSet.SetToProperty) myPropInfo.SetValue(entidad, ConvertToTimeSpan(te.DateTime), null); else if (getOrSet == eGetOrSet.ClearControls) te.DateTime = DateTime.MinValue; } ASPxDateEdit de = (ASPxDateEdit)FindControlByName("de" + myPropInfo.Name, tblABM); if (de != null) { if (getOrSet == eGetOrSet.GetFromProperty) if (myPropInfo.GetValue(entidad, null) != null) de.Date = Convert.ToDateTime(myPropInfo.GetValue(entidad, null)); else de.Value = null; else if (getOrSet == eGetOrSet.SetToProperty) myPropInfo.SetValue(entidad, de.Date, null); else if (getOrSet == eGetOrSet.ClearControls) de.Value = null; } } } }
private static void GetOrSetProperties(HtmlTable tblABM, object entidad, eGetOrSet getOrSet) { ASPxTextBox tx; ucComboBox uc; PropertyInfo myPropInfo; Type entityType; PropertyInfo[] myPropertyInfo; //Recorro las properties de la entidad... //Por cada prop, busco en la tabla, un control tx[PROP], o uc[PROP] que coincida. //Si lo encuentro, lo cargo (Text o SelectedValue) con el valor de la propiedad. //Itero entre las propiedades de la entidad. entityType = entidad.GetType(); myPropertyInfo = entityType.GetProperties((BindingFlags.Public | BindingFlags.Instance)); for (int i = 0; i < myPropertyInfo.Length; i++) { tx = null; uc = null; myPropInfo = ((PropertyInfo)myPropertyInfo[i]); if (myPropInfo.CanRead) { tx = FindTextBoxByName(myPropInfo.Name, tblABM); if (tx != null) { if (getOrSet == eGetOrSet.GetFromProperty) { tx.Text = Convert.ToString(myPropInfo.GetValue(entidad, null)); } else if (getOrSet == eGetOrSet.SetToProperty) { myPropInfo.SetValue(entidad, tx.Text, null); } else if (getOrSet == eGetOrSet.ClearControls) { tx.Text = string.Empty; } } uc = FindComboBoxByName(myPropInfo.Name, tblABM); if (uc != null) { if (getOrSet == eGetOrSet.GetFromProperty) { uc.SelectedValue = Convert.ToString(myPropInfo.GetValue(entidad, null)); } else if (getOrSet == eGetOrSet.SetToProperty) { myPropInfo.SetValue(entidad, uc.SelectedValue, null); } else if (getOrSet == eGetOrSet.ClearControls) { uc.SelectedValue = string.Empty; } } ASPxSpinEdit sp = (ASPxSpinEdit)FindControlByName("sp" + myPropInfo.Name, tblABM); if (sp != null) { if (getOrSet == eGetOrSet.GetFromProperty) { if (myPropInfo.GetValue(entidad, null) != null) { sp.Value = Convert.ToDecimal(myPropInfo.GetValue(entidad, null)); } else { sp.Value = null; } } else if (getOrSet == eGetOrSet.SetToProperty) { myPropInfo.SetValue(entidad, sp.Value, null); } else if (getOrSet == eGetOrSet.ClearControls) { sp.Value = null; } } ASPxCheckBox cb = (ASPxCheckBox)FindControlByName("cb" + myPropInfo.Name, tblABM); if (cb != null) { if (getOrSet == eGetOrSet.GetFromProperty) { cb.Checked = Convert.ToBoolean(myPropInfo.GetValue(entidad, null)); } else if (getOrSet == eGetOrSet.SetToProperty) { myPropInfo.SetValue(entidad, cb.Checked, null); } else if (getOrSet == eGetOrSet.ClearControls) { cb.Checked = false; } } ASPxRadioButtonList rb = (ASPxRadioButtonList)FindControlByName("rb" + myPropInfo.Name, tblABM); if (rb != null) { if (getOrSet == eGetOrSet.GetFromProperty) { rb.SelectedItem = rb.Items.FindByValue(Convert.ToString(myPropInfo.GetValue(entidad, null)).Trim()); } else if (getOrSet == eGetOrSet.SetToProperty) { if (rb.SelectedItem != null) { myPropInfo.SetValue(entidad, rb.SelectedItem.Value, null); } else { myPropInfo.SetValue(entidad, null, null); } } else if (getOrSet == eGetOrSet.ClearControls) { rb.SelectedIndex = -1; } } ASPxTimeEdit te = (ASPxTimeEdit)FindControlByName("te" + myPropInfo.Name, tblABM); if (te != null) { if (getOrSet == eGetOrSet.GetFromProperty) { if (myPropInfo.GetValue(entidad, null) != null) { te.DateTime = ConvertToDateTime((TimeSpan)myPropInfo.GetValue(entidad, null)); } else { te.DateTime = DateTime.MinValue; } } else if (getOrSet == eGetOrSet.SetToProperty) { myPropInfo.SetValue(entidad, ConvertToTimeSpan(te.DateTime), null); } else if (getOrSet == eGetOrSet.ClearControls) { te.DateTime = DateTime.MinValue; } } ASPxDateEdit de = (ASPxDateEdit)FindControlByName("de" + myPropInfo.Name, tblABM); if (de != null) { if (getOrSet == eGetOrSet.GetFromProperty) { if (myPropInfo.GetValue(entidad, null) != null) { de.Date = Convert.ToDateTime(myPropInfo.GetValue(entidad, null)); } else { de.Value = null; } } else if (getOrSet == eGetOrSet.SetToProperty) { myPropInfo.SetValue(entidad, de.Date, null); } else if (getOrSet == eGetOrSet.ClearControls) { de.Value = null; } } } } }